* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #171411;
  --frame: #25201c;
  --frame-border: #3d342c;
  --accent: #f59e0b;
  --accent-hover: #fbbf24;
  --danger: #ef4444;
  --text: #faf6f0;
  --muted: #b5aa9d;
}

html, body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: radial-gradient(circle at top, #2c2620, var(--bg));
  color: var(--text);
  font-family: "Outfit", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(8px, 2vh, 20px);
}

/* Single unified frame that always fits inside viewport */
.game-frame {
  width: min(560px, 100%);
  max-height: 100%;
  background: var(--frame);
  border: 2px solid var(--frame-border);
  border-radius: 22px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 18px;
  background: rgba(0, 0, 0, 0.22);
  border-bottom: 1px solid var(--frame-border);
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-badge {
  font-size: 20px;
}

.brand-name {
  font-family: "Fredoka", "Outfit", sans-serif;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--accent);
}

.hud-stats {
  display: flex;
  align-items: center;
  gap: clamp(14px, 4vw, 34px);
}

.hud-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 64px;
}

.hud-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
}

.hud-value {
  font-size: clamp(18px, 2.6vw, 24px);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
}

.hud-timer .hud-value.urgent {
  color: var(--danger);
  animation: pulse 0.45s infinite alternate;
}

@keyframes pulse {
  from { transform: scale(1); }
  to { transform: scale(1.08); }
}

.icon-btn {
  background: #352e28;
  border: 1px solid #4d4239;
  color: var(--text);
  border-radius: 12px;
  width: 40px;
  height: 40px;
  font-size: 18px;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background 0.15s ease, transform 0.1s ease;
  flex-shrink: 0;
}

.icon-btn:hover {
  background: #463c34;
}

.icon-btn:active {
  transform: scale(0.94);
}

.icon-btn .icon-sound-off {
  display: none;
}

.icon-btn.muted .icon-sound-on {
  display: none;
}

.icon-btn.muted .icon-sound-off {
  display: block;
}

.stage-wrap {
  position: relative;
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
  aspect-ratio: 540 / 720;
  max-height: calc(100dvh - 135px);
  background: #e9decb;
  display: flex;
  align-items: center;
  justify-content: center;
}

@media (max-width: 600px) {
  body {
    padding: 0;
  }

  .game-frame {
    width: 100%;
    height: 100dvh;
    border-radius: 0;
    border: none;
  }

  .hud {
    padding: 8px 12px;
    padding-top: max(8px, env(safe-area-inset-top));
    gap: 8px;
  }

  .brand-name {
    font-size: 17px;
  }

  .hud-stats {
    gap: 10px;
  }

  .hud-item {
    min-width: 48px;
  }

  .icon-btn {
    width: 36px;
    height: 36px;
  }

  .stage-wrap {
    max-height: none;
    aspect-ratio: auto;
    background: linear-gradient(to bottom, #f5ead6 0%, #e7d5b8 59%, #cfa476 59%, #a97b4f 100%);
  }

  .hint-bar {
    font-size: 11.5px;
    padding: 8px 10px;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
  }
}

#gameCanvas {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  cursor: pointer;
  touch-action: manipulation;
}

.overlay {
  position: absolute;
  inset: 0;
  background: rgba(20, 16, 13, 0.72);
  backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  transition: opacity 0.2s ease;
}

.overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.card {
  background: var(--frame);
  border: 2px solid #4b4038;
  border-radius: 20px;
  padding: clamp(20px, 3vw, 28px) clamp(20px, 4vw, 32px);
  max-width: 430px;
  width: 100%;
  text-align: center;
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.55);
}

.card h1 {
  font-family: "Fredoka", "Outfit", sans-serif;
  font-size: clamp(24px, 3.5vw, 30px);
  font-weight: 700;
  margin-bottom: 10px;
  color: var(--accent);
}

.card p {
  color: var(--text);
  line-height: 1.5;
  font-size: 15px;
  margin-bottom: 18px;
}

.stats {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-bottom: 18px;
}

.stats.hidden {
  display: none;
}

.stat-box {
  flex: 1;
  background: #1b1714;
  border: 1px solid #3d342c;
  border-radius: 14px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stat-box span {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.stat-box strong {
  font-size: 26px;
  font-weight: 800;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.primary-btn {
  font-family: "Outfit", sans-serif;
  background: var(--accent);
  color: #1e1508;
  border: none;
  border-radius: 14px;
  padding: 13px 28px;
  font-size: 18px;
  font-weight: 800;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
  width: 100%;
}

.primary-btn:hover {
  background: var(--accent-hover);
}

.primary-btn:active {
  transform: scale(0.97);
}

.hint-bar {
  text-align: center;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--muted);
  padding: 9px 14px;
  background: rgba(0, 0, 0, 0.22);
  border-top: 1px solid var(--frame-border);
  flex-shrink: 0;
}

kbd {
  background: #352e28;
  border: 1px solid #4d4239;
  border-radius: 6px;
  padding: 1px 6px;
  font-family: "Outfit", sans-serif;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--text);
}
