:root {
  --em-deep: #071f14;
  --em-mid: #0e3b26;
  --em-glow: #1d6b45;
  --gold: #f5c451;
  --gold-bright: #ffd76a;
  --gold-deep: #a06b1c;
  --gold-shadow: #7a4c12;
  --cream: #fdf6e3;
  --cream-dim: rgba(253, 246, 227, 0.72);
  --glass: rgba(6, 26, 17, 0.55);
  --glass-line: rgba(245, 196, 81, 0.35);
  --good-glow: #8df0b4;
  --bad-glow: #ff9b9b;
  --brass-face: #d8a64c;
  --brass-mid: #b07c2e;
  --brass-dark: #96692a;
  --brass-edge: #74521a;
  --brass-press: #5d3a0e;
  --brass-ink: #3a2508;
  --font-display: "Lilita One", "Arial Rounded MT Bold", "Outfit", system-ui, sans-serif;
}

[hidden] {
  display: none !important;
}

html {
  background: var(--em-deep);
}

body {
  color: var(--cream);
  background:
    radial-gradient(circle at 12% 16%, rgba(255, 224, 130, 0.5) 0 2px, transparent 3px),
    radial-gradient(circle at 88% 10%, rgba(255, 224, 130, 0.4) 0 2px, transparent 3px),
    radial-gradient(circle at 72% 24%, rgba(255, 224, 130, 0.45) 0 1.5px, transparent 2.5px),
    radial-gradient(circle at 26% 44%, rgba(255, 224, 130, 0.3) 0 1.5px, transparent 2.5px),
    radial-gradient(circle at 92% 56%, rgba(255, 224, 130, 0.35) 0 2px, transparent 3px),
    radial-gradient(circle at 8% 78%, rgba(255, 224, 130, 0.3) 0 1.5px, transparent 2.5px),
    radial-gradient(circle at 60% 88%, rgba(255, 224, 130, 0.3) 0 1.5px, transparent 2.5px),
    radial-gradient(ellipse at 50% 16%, var(--em-glow) 0%, var(--em-mid) 52%, var(--em-deep) 100%);
  background-repeat: no-repeat;
  background-size: cover;
}

main {
  width: min(96vw, 920px);
  margin: 1.1rem auto 2rem;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.8rem;
  margin-bottom: 0.8rem;
}

h1 {
  margin: 0;
  font-size: clamp(1.35rem, 1rem + 1.2vw, 2rem);
}

.subtitle {
  margin: 0.35rem 0 0;
  color: var(--cream-dim);
  font-weight: 700;
}

.game-title-styled {
  background: none;
  -webkit-background-clip: initial;
  -webkit-text-fill-color: initial;
  font-family: var(--font-display);
  font-weight: 400;
  letter-spacing: 0.03em;
  color: var(--gold-bright);
  text-shadow: 0 3px 0 var(--gold-shadow), 0 8px 18px rgba(0, 0, 0, 0.5);
}

.game-brand-logo {
  border-radius: 14px;
  border: 2px solid rgba(231, 180, 90, 0.55);
  box-shadow: 0 0 22px rgba(245, 196, 81, 0.35), 0 8px 16px rgba(0, 0, 0, 0.4);
}

.panel {
  background: transparent;
  border: none;
  box-shadow: none;
  padding: 0;
}

/* --- HUD --- */

.stats {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-top: 0.9rem;
}

.stats p {
  margin: 0;
}

.hud-lives {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  justify-content: flex-start;
}

.strikes {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: var(--glass);
  border: 1px solid var(--glass-line);
  border-radius: 999px;
  padding: 0.4rem 0.75rem;
}

.strike-dot {
  display: inline-block;
  line-height: 1;
}

.strike-dot::before {
  content: "\2665";
  display: inline-block;
  font-size: 1.3rem;
  color: #ff6b6b;
  text-shadow: 0 0 10px rgba(255, 107, 107, 0.55), 0 2px 3px rgba(0, 0, 0, 0.4);
  transition: color 200ms ease, text-shadow 200ms ease, transform 200ms ease;
}

.strike-dot.is-on::before {
  color: #33473c;
  text-shadow: none;
  transform: scale(0.82);
  animation: heart-lost 420ms ease;
}

.hud-lives-count {
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  color: var(--cream-dim);
}

.hud-score {
  text-align: center;
  line-height: 1.02;
}

.hud-score strong {
  display: block;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  color: rgba(255, 215, 106, 0.85);
}

.hud-score #score {
  font-family: var(--font-display);
  font-size: clamp(1.9rem, 1.4rem + 1.8vw, 2.6rem);
  color: var(--gold-bright);
  text-shadow: 0 3px 0 var(--gold-shadow), 0 8px 16px rgba(0, 0, 0, 0.45);
}

.hud-side {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.hud-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--glass);
  border: 1px solid var(--glass-line);
  border-radius: 999px;
  padding: 0.42rem 0.8rem;
}

.hud-chip strong {
  font-size: 0.66rem;
  font-weight: 800;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgba(255, 215, 106, 0.85);
}

.hud-chip span {
  font-family: var(--font-display);
  font-size: 1.05rem;
  color: var(--cream);
}

.hud-chip-timer #timer {
  color: var(--gold-bright);
  text-shadow: 0 0 10px rgba(245, 196, 81, 0.4);
}

.hud-chip-timer .chip-sep {
  font-size: 0.85rem;
  color: var(--cream-dim);
}

.hud-chip-timer #time-limit {
  font-size: 0.85rem;
  color: var(--cream-dim);
}

/* --- Progress strip --- */

.progress-panel {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  margin-top: 0.8rem;
  padding: 0 0.3rem;
}

.progress-copy {
  margin: 0;
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  white-space: nowrap;
  color: var(--cream-dim);
}

.progress-track {
  flex: 1;
  height: 0.6rem;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.4);
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.progress-fill {
  width: 0%;
  height: 100%;
  border-radius: 999px;
  background: var(--gold);
  box-shadow: 0 0 10px rgba(245, 196, 81, 0.5);
  transition: width 240ms ease;
}

/* --- Play area --- */

.play-area {
  position: relative;
  overflow: hidden;
  text-align: center;
  margin-top: 0.9rem;
  padding: 1.1rem 1.1rem 1.4rem;
  background: rgba(6, 26, 17, 0.42);
  border: 1px solid var(--glass-line);
  border-radius: 20px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.35), inset 0 0 70px rgba(29, 107, 69, 0.18);
  transition: background-color 160ms ease;
}

.play-area.flash-good {
  animation: flash-good 240ms ease;
}

.play-area.flash-bad {
  animation: flash-bad 240ms ease;
}

.book-card {
  width: min(440px, 100%);
  margin: 0.2rem auto 1.2rem;
  padding: 1rem 1rem 1.25rem;
  background: linear-gradient(180deg, #fff8e4 0%, #f2e0b6 100%);
  border: 3px solid #d8a64c;
  border-radius: 18px;
  box-shadow:
    inset 0 0 0 2px rgba(122, 76, 18, 0.3),
    0 14px 28px rgba(0, 0, 0, 0.45),
    0 0 34px rgba(245, 196, 81, 0.18);
}

.label {
  margin: 0;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.38em;
  text-transform: uppercase;
  color: #8a5a1e;
}

#book-name {
  margin: 0.35rem 0 0;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(1.7rem, 1.3rem + 2vw, 2.7rem);
  line-height: 1.05;
  color: #33230e;
  text-shadow: 0 2px 0 rgba(255, 255, 255, 0.55);
}

/* --- Brass number plates --- */

.choice-grid {
  margin-top: 0.95rem;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.8rem;
  max-width: 560px;
  margin-left: auto;
  margin-right: auto;
}

.choice-btn {
  position: relative;
  min-height: 4.6rem;
  padding: 0.6rem;
  cursor: pointer;
  border-radius: 12px;
  border: 2px solid var(--brass-edge);
  background:
    linear-gradient(120deg, rgba(255, 240, 200, 0.35) 0%, rgba(255, 240, 200, 0) 45%),
    linear-gradient(170deg, var(--brass-face) 0%, var(--brass-mid) 55%, var(--brass-dark) 100%);
  color: var(--brass-ink);
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(1.5rem, 1.2rem + 1.4vw, 2rem);
  text-shadow: 0 1px 0 rgba(255, 235, 190, 0.55);
  box-shadow: 0 6px 0 var(--brass-press), 0 14px 22px rgba(0, 0, 0, 0.4);
  transition: transform 120ms ease, filter 120ms ease, box-shadow 120ms ease;
}

.choice-btn::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 10px;
  background:
    radial-gradient(circle at 0.6rem 0.6rem, rgba(58, 37, 8, 0.5) 0 2.5px, transparent 3.5px),
    radial-gradient(circle at calc(100% - 0.6rem) 0.6rem, rgba(58, 37, 8, 0.5) 0 2.5px, transparent 3.5px),
    radial-gradient(circle at 0.6rem calc(100% - 0.6rem), rgba(58, 37, 8, 0.5) 0 2.5px, transparent 3.5px),
    radial-gradient(circle at calc(100% - 0.6rem) calc(100% - 0.6rem), rgba(58, 37, 8, 0.5) 0 2.5px, transparent 3.5px);
  pointer-events: none;
}

.choice-btn::after {
  content: "";
  position: absolute;
  inset: 0.45rem;
  border: 1.5px solid rgba(58, 37, 8, 0.35);
  border-radius: 8px;
  pointer-events: none;
}

.choice-btn:hover:not(:disabled) {
  transform: translateY(-3px);
  filter: brightness(1.07);
  box-shadow: 0 9px 0 var(--brass-press), 0 18px 28px rgba(0, 0, 0, 0.45), 0 0 22px rgba(245, 196, 81, 0.3);
}

.choice-btn:active:not(:disabled) {
  transform: translateY(4px);
  box-shadow: 0 2px 0 var(--brass-press), 0 8px 14px rgba(0, 0, 0, 0.4);
}

.choice-btn:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
}

.choice-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.feedback {
  min-height: 1.4rem;
  margin: 1rem 0 0;
  font-weight: 700;
  color: var(--cream-dim);
}

.feedback.good {
  color: var(--good-glow);
  text-shadow: 0 0 12px rgba(141, 240, 180, 0.4);
}

.feedback.bad {
  color: var(--bad-glow);
  text-shadow: 0 0 12px rgba(255, 155, 155, 0.4);
}

.miss-x {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: clamp(5rem, 22vw, 10rem);
  font-weight: 900;
  color: rgba(226, 75, 74, 0.96);
  text-shadow: 0 0 1.5rem rgba(128, 14, 14, 0.55);
  opacity: 0;
  pointer-events: none;
  transform: scale(0.7);
  z-index: 3;
}

.miss-x.show {
  animation: miss-x-burst 420ms ease-out;
}

.floating-text-container {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 20;
}

.floating-text {
  position: absolute;
  font-family: var(--font-display);
  font-size: 1.6rem;
  color: var(--good-glow);
  text-shadow: 0 2px 0 #14522e, 0 5px 10px rgba(0, 0, 0, 0.55);
  animation: float-up-fade 800ms ease-out forwards;
}

.floating-text.bonus {
  color: var(--gold-bright);
  text-shadow: 0 2px 0 var(--gold-shadow), 0 5px 10px rgba(0, 0, 0, 0.55);
  font-size: 1.9rem;
}

/* --- Bottom actions --- */

.actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.7rem;
  flex-wrap: nowrap;
  overflow-x: auto;
  margin-top: 1rem;
  padding-bottom: 0.15rem;
}

.actions button {
  white-space: nowrap;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  padding: 0.62rem 0.8rem;
  min-height: 2.85rem;
  background: var(--glass);
  color: var(--cream);
  border: 1px solid var(--glass-line);
  border-radius: 999px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
  transition: transform 120ms ease, filter 120ms ease, box-shadow 120ms ease;
}

.actions button:hover:not(:disabled) {
  transform: translateY(-1px);
  filter: brightness(1.08);
}

.actions button:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
}

.actions .start-action {
  order: -1;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 1.15rem;
  letter-spacing: 0.07em;
  padding: 0.7rem 1.7rem;
  background: linear-gradient(180deg, var(--gold-bright) 0%, #efa93d 100%);
  color: #4a2a08;
  border: 2px solid var(--gold-deep);
  box-shadow: 0 5px 0 var(--gold-shadow), 0 0 26px rgba(245, 196, 81, 0.35);
}

.actions .start-action:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 7px 0 var(--gold-shadow), 0 0 32px rgba(245, 196, 81, 0.5);
}

.actions .start-action:active:not(:disabled) {
  transform: translateY(3px);
  box-shadow: 0 2px 0 var(--gold-shadow), 0 0 18px rgba(245, 196, 81, 0.35);
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* --- Modals (arcade skin via scoped theme vars) --- */

/* leaderboard.js's gear handler injects inline display:block on this overlay,
   so the layout must center the card without relying on grid/flex */
.settings-modal,
.summary-modal {
  position: fixed;
  inset: 0;
  /* Modal layers sit above the fixed .header-row and mobile .bottom-nav-bar (z-index 9999, theme.css);
  below that they opened underneath the header, hiding the card's title and close button. */
  z-index: 10000;
  background: rgba(4, 18, 12, 0.68);
  overflow-y: auto;
  padding: 1rem;
}

.summary-modal {
  z-index: 10001;
}

.settings-card,
.summary-card {
  --text: #fdf6e3;
  --muted: rgba(253, 246, 227, 0.65);
  --accent: #ffd76a;
  --accent-soft: rgba(6, 26, 17, 0.55);
  --line: rgba(245, 196, 81, 0.3);
  --panel: rgba(6, 26, 17, 0.55);
  --bg: rgba(6, 26, 17, 0.45);
  width: min(92vw, 520px);
  max-height: min(86vh, 700px);
  overflow: auto;
  margin: max(7vh, 1rem) auto;
  background: linear-gradient(180deg, #124631 0%, #0a2a1b 100%);
  border: 2px solid rgba(231, 180, 90, 0.55);
  border-radius: 14px;
  padding: 0.85rem;
  color: var(--cream);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.5);
}

.summary-card {
  width: min(92vw, 460px);
  padding: 1rem;
}

.settings-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid rgba(245, 196, 81, 0.25);
  padding-bottom: 0.5rem;
  margin-bottom: 0.5rem;
}

.settings-header h2,
.summary-card h2 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 400;
  letter-spacing: 0.04em;
  font-size: 1.25rem;
  color: var(--gold-bright);
}

.summary-card h2 {
  margin-bottom: 0.55rem;
}

.popup-close {
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--cream-dim);
  font: inherit;
  font-weight: 800;
  font-size: 1.15rem;
  width: 1.9rem;
  height: 1.9rem;
  cursor: pointer;
}

.popup-close:hover {
  color: var(--cream);
}

.settings-grid {
  margin-top: 0.6rem;
  display: grid;
  gap: 0.6rem;
}

.setting {
  display: grid;
  gap: 0.35rem;
  font-weight: 700;
  color: var(--cream);
}

.setting input[type="range"],
.setting select {
  width: 100%;
}

.setting input[type="checkbox"],
.setting input[type="range"] {
  accent-color: var(--gold);
}

.setting select {
  border: 1px solid var(--glass-line);
  border-radius: 8px;
  padding: 0.35rem 0.45rem;
  font: inherit;
  background: var(--glass);
  color: var(--cream);
}

.setting-help {
  color: var(--cream-dim);
  font-size: 0.82rem;
  font-weight: 600;
}

#daily-status,
#daily-score,
#daily-best,
#daily-streak {
  margin: 0 0 0.35rem;
}

#review-empty {
  margin: 0.6rem 0 0.4rem;
  color: var(--cream-dim);
}

.missed-list {
  margin: 0.35rem 0 0;
  padding-left: 1.2rem;
}

.missed-list li {
  margin-bottom: 0.25rem;
}

#best-score {
  margin: 0 0 0.4rem;
  font-weight: 700;
}

#high-score-list {
  margin: 0.4rem 0 0;
  padding-left: 1.4rem;
}

#high-score-list li {
  margin-bottom: 0.35rem;
  font-weight: 600;
}

.summary-card ul {
  list-style: none;
  margin: 0 0 0.8rem;
  padding: 0;
  display: grid;
  gap: 0.45rem;
}

.summary-card ul li {
  background: rgba(6, 26, 17, 0.55);
  border: 1px solid rgba(245, 196, 81, 0.25);
  border-radius: 10px;
  padding: 0.5rem 0.8rem;
  font-weight: 700;
}

.summary-actions {
  display: flex;
  gap: 0.5rem;
}

.summary-actions button {
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  border-radius: 999px;
  padding: 0.55rem 1rem;
  background: var(--glass);
  color: var(--cream);
  border: 1px solid var(--glass-line);
}

.summary-actions #summary-play-again-btn {
  font-family: var(--font-display);
  font-weight: 400;
  letter-spacing: 0.05em;
  background: linear-gradient(180deg, var(--gold-bright) 0%, #efa93d 100%);
  color: #4a2a08;
  border: 2px solid var(--gold-deep);
  box-shadow: 0 4px 0 var(--gold-shadow);
}

.summary-actions #summary-play-again-btn:hover {
  filter: brightness(1.06);
}

/* --- Screen flashes --- */

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  z-index: 8;
}

body.screen-flash-good::before {
  animation: screen-flash-good 220ms ease;
}

body.screen-flash-bad::before {
  animation: screen-flash-bad 220ms ease;
}

.screen-shake {
  animation: shake 300ms ease-in-out;
}

/* --- Animations --- */

@keyframes heart-lost {
  0% {
    transform: scale(1.3) rotate(0deg);
  }
  40% {
    transform: scale(0.7) rotate(-14deg);
  }
  70% {
    transform: scale(0.95) rotate(8deg);
  }
  100% {
    transform: scale(0.82) rotate(0deg);
  }
}

@keyframes flash-good {
  0% {
    background-color: rgba(64, 158, 97, 0.3);
  }
  100% {
    background-color: transparent;
  }
}

@keyframes flash-bad {
  0% {
    background-color: rgba(191, 72, 72, 0.28);
  }
  100% {
    background-color: transparent;
  }
}

@keyframes miss-x-burst {
  0% {
    opacity: 0;
    transform: scale(0.65);
  }
  22% {
    opacity: 1;
    transform: scale(1.08);
  }
  100% {
    opacity: 0;
    transform: scale(1);
  }
}

@keyframes screen-flash-good {
  0% {
    opacity: 0.32;
    background: #44b868;
  }
  100% {
    opacity: 0;
    background: transparent;
  }
}

@keyframes screen-flash-bad {
  0% {
    opacity: 0.28;
    background: #c64545;
  }
  100% {
    opacity: 0;
    background: transparent;
  }
}

@keyframes float-up-fade {
  0% {
    opacity: 1;
    transform: translateY(0) scale(0.8);
  }
  10% {
    transform: translateY(-5px) scale(1.1);
  }
  100% {
    opacity: 0;
    transform: translateY(-40px) scale(1);
  }
}

@keyframes shake {
  0% { transform: translate(1px, 1px) rotate(0deg); }
  10% { transform: translate(-1px, -2px) rotate(-1deg); }
  20% { transform: translate(-3px, 0px) rotate(1deg); }
  30% { transform: translate(3px, 2px) rotate(0deg); }
  40% { transform: translate(1px, -1px) rotate(1deg); }
  50% { transform: translate(-1px, 2px) rotate(-1deg); }
  60% { transform: translate(-3px, 1px) rotate(0deg); }
  70% { transform: translate(3px, 1px) rotate(-1deg); }
  80% { transform: translate(-1px, -1px) rotate(1deg); }
  90% { transform: translate(1px, 2px) rotate(0deg); }
  100% { transform: translate(1px, -2px) rotate(-1deg); }
}

@media (max-width: 640px) {
  .stats {
    gap: 0.45rem;
  }

  .strikes {
    padding: 0.32rem 0.6rem;
  }

  .strike-dot::before {
    font-size: 1.1rem;
  }

  .hud-chip {
    padding: 0.34rem 0.62rem;
  }

  .hud-lives-count {
    display: none;
  }

  .choice-grid {
    gap: 0.55rem;
  }

  .choice-btn {
    min-height: 3.9rem;
  }

  .actions {
    justify-content: flex-start;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
