: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;
  --wood: #55381c;
  --wood-edge: #a06b1c;
  --font-display: "Lilita One", "Arial Rounded MT Bold", "Outfit", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

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

body {
  margin: 0;
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  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;
  background-attachment: fixed;
}

.app {
  width: min(96vw, 920px);
  margin: 1.1rem auto 2rem;
  padding: 0 0.45rem;
}

.top {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

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

.game-title-styled {
  /* Reset the theme.css gradient text fill so the gold shows (matches canon-or-not). */
  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;
}

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

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

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

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

.gold-btn {
  font-family: var(--font-display);
  font-weight: 400;
  letter-spacing: 0.04em;
  background: linear-gradient(180deg, var(--gold-bright) 0%, var(--gold) 55%, #e0a83c 100%);
  border: 1px solid var(--gold-deep);
  color: #4a3305;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.35);
  box-shadow: 0 4px 0 var(--gold-shadow), 0 8px 16px rgba(0, 0, 0, 0.35);
}

.gold-btn:hover:not(:disabled) {
  filter: brightness(1.05);
}

/* --- HUD --- */

.play-zone {
  margin-top: 0.9rem;
}

.play-hud {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  flex-wrap: wrap;
}

.hearts {
  font-size: 1.4rem;
  letter-spacing: 0.12em;
  color: #ff7b7b;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
}

.heart.lost {
  opacity: 0.25;
}

.hud-chip {
  background: var(--glass);
  border: 1px solid var(--glass-line);
  border-radius: 999px;
  padding: 0.32rem 0.75rem;
  font-size: 0.9rem;
}

.hud-chip strong {
  color: var(--gold-bright);
  margin-right: 0.25rem;
}

.streak-chip.hot {
  border-color: var(--gold-bright);
  box-shadow: 0 0 12px rgba(245, 196, 81, 0.45);
}

.mode-chip {
  border-color: rgba(245, 196, 81, 0.6);
}

.timer-track {
  margin-top: 0.7rem;
  height: 10px;
  border-radius: 999px;
  background: rgba(6, 26, 17, 0.65);
  border: 1px solid var(--glass-line);
  overflow: hidden;
}

.timer-fill {
  height: 100%;
  width: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--gold) 0%, var(--gold-bright) 100%);
  transition: width 90ms linear;
}

.timer-fill.low {
  background: linear-gradient(90deg, #d9534f 0%, #ff9b9b 100%);
}

/* --- Target callout --- */

.callout {
  text-align: center;
  margin-top: 0.8rem;
  min-height: 4.6rem;
}

.target-label {
  margin: 0;
  font-size: 0.78rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gold);
}

.target-book {
  margin: 0.15rem 0 0;
  font-family: var(--font-display);
  font-weight: 400;
  letter-spacing: 0.02em;
  font-size: clamp(1.6rem, 1.2rem + 2.2vw, 2.4rem);
  color: var(--gold-bright);
  text-shadow: 0 3px 0 var(--gold-shadow), 0 6px 14px rgba(0, 0, 0, 0.5);
}

.target-book.hint-earlier::before {
  content: "⬅ ";
}

.target-book.hint-later::after {
  content: " ➡";
}

/* --- Bookcase --- */

.shelf-zone {
  position: relative;
  margin-top: 0.9rem;
  padding: 0.4rem 0.2rem 0;
}

.bookcase {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  flex-wrap: wrap;
  gap: 2px;
  row-gap: 0.7rem;
  min-height: 96px;
}

.spine {
  width: 30px;
  height: 96px;
  min-height: 0;
  padding: 4px 0;
  border-radius: 5px 5px 2px 2px;
  border: 1px solid rgba(0, 0, 0, 0.4);
  border-top: 4px solid rgba(255, 255, 255, 0.22);
  border-bottom: 4px solid rgba(0, 0, 0, 0.3);
  color: var(--cream);
  display: flex;
  align-items: center;
  justify-content: center;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 0.68rem;
  letter-spacing: 0.04em;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.55);
  flex: 0 0 auto;
  overflow: hidden;
  transition: none;
}

.spine:hover:not(:disabled) {
  transform: rotate(180deg) translateY(1px);
  filter: brightness(1.15);
}

.spine:nth-child(even) {
  height: 92px;
}

.spine.landmark {
  color: var(--gold-bright);
  border-top-color: rgba(255, 215, 106, 0.75);
}

.spine.hit {
  background: linear-gradient(180deg, var(--gold-bright) 0%, var(--gold) 100%) !important;
  color: #4a3305;
  text-shadow: none;
  box-shadow: 0 0 0 2px var(--good-glow), 0 0 18px rgba(141, 240, 180, 0.5);
}

.spine.miss {
  background: linear-gradient(180deg, #c84f4f 0%, #8f2d2d 100%) !important;
  box-shadow: 0 0 0 2px var(--bad-glow), 0 0 14px rgba(255, 155, 155, 0.4);
}

.spine.dim {
  opacity: 0.55;
}

.spine.pop {
  animation: spine-pop 0.35s ease;
}

@keyframes spine-pop {
  0% { transform: rotate(180deg) scaleY(1); }
  40% { transform: rotate(180deg) scaleY(1.1); }
  100% { transform: rotate(180deg) scaleY(1); }
}

.spine.shake {
  animation: spine-shake 0.22s ease 2;
}

@keyframes spine-shake {
  0%, 100% { transform: rotate(180deg) translateX(0); }
  25% { transform: rotate(180deg) translateX(-3px); }
  75% { transform: rotate(180deg) translateX(3px); }
}

.shelf-rail {
  height: 12px;
  background: linear-gradient(180deg, #6a4522 0%, var(--wood) 100%);
  border-top: 2px solid var(--wood-edge);
  border-radius: 3px;
  margin: 0 0.5rem;
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.4);
}

.bookcase.shake {
  animation: bookcase-shake 0.3s ease 2;
}

@keyframes bookcase-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

.feedback {
  margin: 0.9rem 0 0;
  text-align: center;
  min-height: 1.4em;
  color: var(--cream-dim);
}

.feedback.good {
  color: var(--good-glow);
}

.feedback.bad {
  color: var(--bad-glow);
}

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

.floating-point {
  position: absolute;
  font-family: var(--font-display);
  font-weight: 400;
  color: var(--gold-bright);
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.6);
  animation: float-up 0.9s ease-out forwards;
}

@keyframes float-up {
  from { opacity: 1; transform: translateY(0); }
  to { opacity: 0; transform: translateY(-46px); }
}

/* --- Mode select --- */

.mode-select {
  margin-top: 1.2rem;
}

.mode-cards {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.7rem;
}

.mode-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  text-align: center;
  padding: 0.85rem 0.7rem;
  border-radius: 14px;
  border: 1.5px solid var(--glass-line);
  background: var(--glass);
}

.mode-card:hover:not(:disabled) {
  border-color: var(--gold-bright);
  box-shadow: 0 0 16px rgba(245, 196, 81, 0.3);
}

.mode-card .mode-icon {
  font-size: 1.6rem;
}

.mode-card .mode-title {
  font-family: var(--font-display);
  font-weight: 400;
  letter-spacing: 0.04em;
  font-size: 1.08rem;
  color: var(--gold-bright);
}

.mode-card .mode-desc {
  font-size: 0.8rem;
  font-weight: 400;
  color: var(--cream-dim);
  line-height: 1.35;
}

.mode-select.is-running .mode-card {
  opacity: 0.5;
}

.actions-row {
  display: flex;
  justify-content: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-top: 0.9rem;
}

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

.modal-overlay {
  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, 16, 11, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-overlay[hidden] {
  display: none;
}

.modal-content {
  --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);
  background: linear-gradient(180deg, #124631 0%, #0a2a1b 100%);
  color: var(--text);
  border: 1px solid rgba(245, 196, 81, 0.45);
  border-radius: 16px;
  width: min(94vw, 480px);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.6);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  padding: 0.85rem 1rem 0.4rem;
}

.modal-header h2 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 400;
  letter-spacing: 0.03em;
  color: var(--gold-bright);
}

.modal-body {
  padding: 0.4rem 1rem 0.9rem;
}

.modal-footer {
  padding: 0 1rem 0.9rem;
  display: flex;
  justify-content: flex-end;
}

.close-btn {
  width: 2.1rem;
  min-width: 2.1rem;
  height: 2.1rem;
  min-height: 2.1rem;
  padding: 0;
  border-radius: 999px;
  font-size: 1.3rem;
  line-height: 1;
}

.done-btn {
  background: var(--glass);
}

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

.setting {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: wrap;
  font-size: 0.92rem;
  font-weight: 700;
}

.setting input[type="range"] {
  flex: 1;
  min-width: 120px;
}

.setting select {
  font: inherit;
  background: var(--accent-soft);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.3rem 0.5rem;
}

.setting-help {
  flex-basis: 100%;
  font-size: 0.78rem;
  font-weight: 400;
  color: var(--muted);
}

.progress-subpanel {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.7rem 0.85rem;
  margin-bottom: 0.7rem;
}

.progress-subpanel h3 {
  margin: 0 0 0.4rem;
  font-size: 0.95rem;
  color: rgba(255, 215, 106, 0.85);
}

.progress-subpanel p {
  margin: 0.2rem 0;
  font-size: 0.92rem;
}

.missed-list {
  margin: 0.4rem 0 0;
  padding-left: 1.25rem;
}

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

.high-score-list {
  margin: 0.4rem 0 0;
  padding-left: 1.25rem;
}

.high-score-list li {
  margin-bottom: 0.3rem;
}

.summary-list {
  margin: 0;
  padding-left: 1.25rem;
}

.summary-list li {
  margin-bottom: 0.3rem;
}

.summary-list .bonus-line {
  color: var(--gold-bright);
}

.result-actions {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  margin-top: 0.8rem;
}

.share-btn {
  background: var(--glass);
  color: var(--cream);
  border: 1px solid var(--glass-line);
}

/* --- Onboarding tour --- */

.tour-highlight {
  position: relative;
  z-index: 121;
  box-shadow: 0 0 0 3px var(--gold), 0 0.8rem 1.2rem rgba(0, 0, 0, 0.4);
  border-radius: 12px;
}

.tour-overlay {
  position: fixed;
  inset: 0;
  z-index: 120;
  background: rgba(4, 18, 12, 0.68);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 1rem 1rem calc(1rem + env(safe-area-inset-bottom));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.tour-card {
  width: min(96vw, 520px);
  background: linear-gradient(180deg, #124631 0%, #0a2a1b 100%);
  border: 2px solid rgba(231, 180, 90, 0.55);
  border-radius: 14px;
  padding: 0.85rem;
  margin-top: auto;
  flex-shrink: 0;
  color: var(--cream);
}

.tour-card h2 {
  margin: 0 0 0.35rem;
  font-family: var(--font-display);
  font-weight: 400;
  letter-spacing: 0.04em;
  color: var(--gold-bright);
}

.tour-card p {
  margin: 0 0 0.65rem;
  color: var(--cream-dim);
  line-height: 1.35;
}

.tour-actions {
  display: flex;
  gap: 0.45rem;
  flex-wrap: wrap;
  align-items: center;
}

.tour-primary {
  background: linear-gradient(180deg, var(--gold-bright) 0%, #efa93d 100%);
  color: #4a2a08;
  border: 2px solid var(--gold-deep);
  box-shadow: 0 3px 0 var(--gold-shadow);
}

.tour-toggle {
  margin-left: auto;
  font-size: 0.82rem;
  color: var(--cream-dim);
}

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

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

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

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

@keyframes screen-flash-good {
  0% { opacity: 0; }
  30% { opacity: 1; background: radial-gradient(ellipse at 50% 50%, rgba(141, 240, 180, 0.16) 0%, transparent 70%); }
  100% { opacity: 0; }
}

@keyframes screen-flash-bad {
  0% { opacity: 0; }
  30% { opacity: 1; background: radial-gradient(ellipse at 50% 50%, rgba(255, 90, 90, 0.18) 0%, transparent 70%); }
  100% { opacity: 0; }
}

/* --- Responsive --- */

@media (max-width: 640px) {
  .spine {
    width: 26px;
    height: 88px;
    font-size: 0.62rem;
  }

  .spine:nth-child(even) {
    height: 84px;
  }

  .mode-cards {
    grid-template-columns: 1fr;
  }

  .mode-card {
    flex-direction: row;
    text-align: left;
    align-items: center;
    gap: 0.7rem;
  }

  .mode-card .mode-desc {
    flex: 1;
  }
}

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