/* Hiss & Spell: Snake Safari — Warm Dusk Savannah UI */

:root {
  --ink: #2c1b10;
  --ink-soft: #5c3d28;
  --cream: #fff8e7;
  --cream-card: #fff4d6;
  --amber: #ff9f43;
  --coral: #ff6b6b;
  --mint: #2ec492;
  --gold: #ffd43b;
  --teal-deep: #103240;
  --teal-mid: #1a4b5c;
  --shadow: rgba(24, 12, 5, 0.34);
  --font-stack: system-ui, "Trebuchet MS", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --chrome-h: 88px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  font-family: var(--font-stack);
  color: var(--ink);
  background: linear-gradient(180deg, #0d2b38 0%, #1d4e5e 42%, #8e4a38 82%, #3a1f18 100%);
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

/* Subtle paper-grain CSS overlay using inline SVG data URI */
.paper-grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 50;
  opacity: 0.045;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120' viewBox='0 0 120 120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='120' height='120' filter='url(%23n)' opacity='0.9'/%3E%3C/svg%3E");
}

.hidden {
  display: none !important;
}

.app-shell {
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: 10px 14px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.app-shell.has-guide {
  --chrome-h: 174px;
}

.app-shell.has-keyboard {
  --chrome-h: 248px;
}

.app-shell.has-guide.has-keyboard {
  --chrome-h: 320px;
}

/* Top HUD */
.hud-bar {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 12px;
  background: var(--cream);
  border: 3px solid var(--ink);
  border-radius: 18px;
  box-shadow: 0 5px 0 var(--ink), 0 10px 20px var(--shadow);
}

.hud-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.hud-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 11px;
  border-radius: 12px;
  border: 2.5px solid var(--ink);
  background: #fffdf6;
  font-weight: 800;
  font-size: 0.95rem;
  line-height: 1.15;
}

.wave-pill {
  background: #ffe08a;
}

.hearts-pill {
  background: #ffe9e9;
  gap: 4px;
  padding: 4px 9px;
}

.heart-svg {
  width: 20px;
  height: 20px;
  display: block;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.heart-svg.lost {
  opacity: 0.28;
  transform: scale(0.86);
}

.hud-label {
  font-size: 0.7rem;
  letter-spacing: 0.05em;
  color: var(--ink-soft);
}

.hud-val {
  font-size: 1.05rem;
}

.combo-pill {
  background: #dff8ee;
}

.combo-pill.hot {
  background: #ffd43b;
}

.combo-mult {
  background: var(--ink);
  color: #fff;
  padding: 1px 6px;
  border-radius: 8px;
  font-size: 0.82rem;
}

.slowmo-badge {
  background: linear-gradient(135deg, #ffe066, #ff922b);
  color: var(--ink);
  border: 2.5px solid var(--ink);
  border-radius: 999px;
  padding: 4px 12px;
  font-weight: 900;
  font-size: 0.84rem;
  letter-spacing: 0.04em;
  box-shadow: 0 2px 0 var(--ink);
  animation: pulseBadge 0.8s ease-in-out infinite alternate;
}

@keyframes pulseBadge {
  from { transform: scale(1); }
  to { transform: scale(1.06); }
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 36px;
  border-radius: 12px;
  border: 2.5px solid var(--ink);
  background: var(--cream-card);
  color: var(--ink);
  cursor: pointer;
  box-shadow: 0 3px 0 var(--ink);
  transition: transform 0.1s ease, background-color 0.15s ease;
}

.icon-btn:hover {
  background: #ffe8ad;
  transform: translateY(-1px);
}

.icon-btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 var(--ink);
}

.icon-btn[aria-pressed="true"] {
  background: #b8f2dc;
}

.icon-btn:focus-visible,
.btn:focus-visible,
.kb-key:focus-visible,
.hr-key:focus-visible {
  outline: 3px solid #38d9a9;
  outline-offset: 2px;
}

/* 16:9 Letterboxed Stage */
.stage-wrap {
  position: relative;
  width: min(100%, calc((100dvh - var(--chrome-h)) * 16 / 9));
  aspect-ratio: 16 / 9;
  border-radius: 22px;
  border: 4px solid var(--ink);
  overflow: hidden;
  background: #123c4d;
  box-shadow: 0 8px 0 var(--ink), 0 18px 34px var(--shadow);
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* Overlays */
.overlay-card {
  position: absolute;
  inset: 0;
  margin: auto;
  width: min(92%, 560px);
  height: fit-content;
  max-height: 92%;
  overflow-y: auto;
  padding: 20px 24px;
  background: rgba(255, 248, 231, 0.96);
  border: 4px solid var(--ink);
  border-radius: 24px;
  box-shadow: 0 8px 0 var(--ink), 0 20px 40px rgba(0, 0, 0, 0.45);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  z-index: 10;
}

.mascot-wrap {
  margin-bottom: -4px;
}

.mascot-snake {
  animation: mascotFloat 2.4s ease-in-out infinite;
}

@keyframes mascotFloat {
  0%, 100% { transform: translateY(0px) rotate(-1deg); }
  50% { transform: translateY(-6px) rotate(1.5deg); }
}

.title-badge {
  display: inline-block;
  padding: 3px 12px;
  border-radius: 999px;
  border: 2.5px solid var(--ink);
  background: #96f2d7;
  font-weight: 900;
  font-size: 0.8rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.badge-warm {
  background: #ffd8a8;
}

.game-title {
  margin: 0;
  font-size: clamp(1.7rem, 3.8vw, 2.55rem);
  line-height: 1.05;
  letter-spacing: -0.02em;
  color: var(--ink);
}

.overlay-title {
  margin: 0;
  font-size: clamp(1.4rem, 3vw, 2.05rem);
  line-height: 1.1;
}

.howto-text,
.overlay-sub {
  margin: 0;
  font-size: clamp(0.88rem, 1.7vw, 1.03rem);
  line-height: 1.4;
  color: var(--ink-soft);
  max-width: 44ch;
}

.start-stats {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.stat-chip {
  padding: 4px 12px;
  border-radius: 999px;
  border: 2px solid var(--ink);
  background: #fff;
  font-size: 0.88rem;
  font-weight: 700;
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 4px;
}

.btn {
  font-family: inherit;
  font-weight: 900;
  font-size: 1.05rem;
  padding: 10px 22px;
  border-radius: 15px;
  border: 3px solid var(--ink);
  cursor: pointer;
  color: var(--ink);
  box-shadow: 0 4px 0 var(--ink);
  transition: transform 0.1s ease, filter 0.15s ease;
}

.btn:hover {
  transform: translateY(-2px);
  filter: brightness(1.04);
}

.btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 var(--ink);
}

.btn-primary {
  background: linear-gradient(180deg, #ffbe55, #ff922b);
}

.btn-secondary {
  background: #fffdf6;
}

.shortcut-hint {
  margin: 2px 0 0;
  font-size: 0.8rem;
  color: var(--ink-soft);
}

kbd {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 6px;
  border: 1.5px solid var(--ink);
  background: #fff;
  font-family: inherit;
  font-weight: 800;
  font-size: 0.78rem;
}

.stars-row {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: center;
}

.star-svg {
  width: 40px;
  height: 40px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(64px, 1fr));
  gap: 8px;
  width: 100%;
}

.summary-box {
  background: #fff;
  border: 2.5px solid var(--ink);
  border-radius: 12px;
  padding: 6px 4px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.summary-box span {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--ink-soft);
  text-transform: uppercase;
}

.summary-box strong {
  font-size: 1.15rem;
}

/* Home-Row Hand Guide (Waves 1-2) */
.homerow-guide {
  width: 100%;
  max-width: 860px;
  background: var(--cream);
  border: 3px solid var(--ink);
  border-radius: 18px;
  padding: 8px 14px;
  box-shadow: 0 5px 0 var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  flex-wrap: wrap;
}

.hand-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.hand-label {
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
  color: var(--ink-soft);
  letter-spacing: 0.04em;
}

.hand-keys {
  display: flex;
  gap: 6px;
}

.hand-divider {
  width: 3px;
  height: 40px;
  border-radius: 2px;
  background: rgba(44, 27, 16, 0.2);
}

.hr-key {
  font-family: inherit;
  min-width: 48px;
  padding: 4px 6px;
  border-radius: 12px;
  border: 2.5px solid var(--ink);
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  box-shadow: 0 3px 0 var(--ink);
  transition: transform 0.12s ease, background-color 0.15s ease;
}

.hr-letter {
  font-size: 1.25rem;
  font-weight: 900;
  line-height: 1.05;
}

.hr-finger {
  font-size: 0.62rem;
  font-weight: 700;
  color: var(--ink-soft);
}

.hr-key.active-target {
  background: #ffd43b;
  transform: translateY(-3px) scale(1.08);
  box-shadow: 0 5px 0 var(--ink);
}

/* On-Screen Touch Keyboard */
.touch-keyboard {
  width: 100%;
  max-width: 780px;
  background: rgba(255, 248, 231, 0.94);
  border: 3px solid var(--ink);
  border-radius: 18px;
  padding: 8px 8px 10px;
  box-shadow: 0 5px 0 var(--ink);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.kb-row {
  display: flex;
  justify-content: center;
  gap: 5px;
}

.kb-key {
  font-family: inherit;
  flex: 1 1 0;
  max-width: 54px;
  min-width: 26px;
  height: 40px;
  border-radius: 10px;
  border: 2.5px solid var(--ink);
  background: #fff;
  color: var(--ink);
  font-size: 1.05rem;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 3px 0 var(--ink);
  transition: transform 0.08s ease, background-color 0.12s ease;
}

.kb-key:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 var(--ink);
}

.kb-key.active-target {
  background: #ffd43b;
  transform: translateY(-2px);
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
  .mascot-snake,
  .slowmo-badge {
    animation: none;
  }
  .btn,
  .icon-btn,
  .hr-key,
  .kb-key,
  .heart-svg {
    transition: none;
  }
}

/* Small screens down to 360px */
@media (max-width: 640px) {
  .app-shell {
    padding: 6px 8px 10px;
    gap: 6px;
  }
  .hud-bar {
    padding: 6px 8px;
    border-radius: 14px;
    gap: 6px;
  }
  .hud-pill {
    padding: 3px 8px;
    font-size: 0.82rem;
    border-width: 2px;
  }
  .heart-svg {
    width: 16px;
    height: 16px;
  }
  .icon-btn {
    width: 34px;
    height: 32px;
  }
  .stage-wrap {
    width: 100%;
    border-radius: 14px;
    border-width: 3px;
  }
  .overlay-card {
    padding: 12px 14px;
    gap: 7px;
    border-radius: 16px;
    border-width: 3px;
  }
  .mascot-wrap {
    display: none;
  }
  .summary-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .hand-divider {
    display: none;
  }
  .hr-key {
    min-width: 34px;
    padding: 3px 4px;
  }
  .hr-letter {
    font-size: 1.05rem;
  }
  .kb-key {
    height: 36px;
    font-size: 0.95rem;
    border-width: 2px;
  }
}
