: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);
}

h2 {
  margin: 0 0 0.5rem;
  font-size: 1.1rem;
}

.game-title-styled {
  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);
}

/* --- Map screen --- */

.map-screen {
  margin-top: 1rem;
}

.map-tagline {
  margin: 0 0 0.9rem;
  text-align: center;
  color: var(--cream-dim);
}

.daily-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.9rem;
  flex-wrap: wrap;
  background: var(--glass);
  border: 1px solid var(--glass-line);
  border-radius: 14px;
  padding: 0.8rem 1rem;
  margin-bottom: 0.9rem;
}

.daily-card h2 {
  font-family: var(--font-display);
  font-weight: 400;
  color: var(--gold-bright);
  margin: 0 0 0.2rem;
}

.daily-card p {
  margin: 0;
  color: var(--cream-dim);
  font-size: 0.92rem;
}

.stars-line {
  text-align: center;
  color: var(--cream-dim);
  margin: 0 0 0.9rem;
}

.star-glyph {
  color: var(--gold-bright);
}

.map-sections {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(255px, 1fr));
  gap: 0.7rem;
}

.section-card {
  background: var(--glass);
  border: 1px solid var(--glass-line);
  border-radius: 14px;
  padding: 0.75rem 0.85rem;
  position: relative;
}

.section-card.locked {
  opacity: 0.55;
}

.section-card .section-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
}

.section-chip {
  width: 14px;
  height: 22px;
  border-radius: 3px 3px 2px 2px;
  border: 1px solid rgba(0, 0, 0, 0.35);
  flex: 0 0 auto;
}

.section-card h3 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 400;
  letter-spacing: 0.03em;
  font-size: 1.05rem;
  color: var(--gold-bright);
  flex: 1;
}

.section-stars {
  font-size: 0.85rem;
  color: var(--gold);
  white-space: nowrap;
}

.section-blurb {
  margin: 0 0 0.55rem;
  font-size: 0.85rem;
  color: var(--cream-dim);
  min-height: 2.3em;
}

.level-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.35rem;
}

.level-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  padding: 0.45rem 0.2rem;
  min-height: 0;
  font-size: 0.78rem;
  border-radius: 9px;
}

.level-btn .level-stars {
  font-size: 0.72rem;
  color: var(--gold-bright);
  letter-spacing: 0.05em;
}

.level-btn .level-stars .off {
  opacity: 0.3;
}

.level-btn.boss {
  border-color: rgba(245, 196, 81, 0.6);
  background: rgba(122, 76, 18, 0.45);
}

.level-btn.locked {
  opacity: 0.5;
}

.section-lock-note {
  margin: 0.5rem 0 0;
  font-size: 0.78rem;
  color: var(--cream-dim);
}

.milestones-heading {
  margin: 1.1rem 0 0.55rem;
  font-family: var(--font-display);
  font-weight: 400;
  letter-spacing: 0.03em;
  color: var(--gold-bright);
  text-align: center;
}

.map-milestones {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(255px, 1fr));
  gap: 0.7rem;
}

.milestone-card {
  background: linear-gradient(180deg, rgba(122, 76, 18, 0.5) 0%, rgba(6, 26, 17, 0.6) 100%);
  border: 1px solid rgba(245, 196, 81, 0.55);
  border-radius: 14px;
  padding: 0.75rem 0.85rem;
}

.milestone-card.locked {
  opacity: 0.55;
}

.milestone-card h3 {
  margin: 0 0 0.25rem;
  font-family: var(--font-display);
  font-weight: 400;
  letter-spacing: 0.03em;
  color: var(--gold-bright);
}

.milestone-card p {
  margin: 0 0 0.55rem;
  font-size: 0.85rem;
  color: var(--cream-dim);
}

.milestone-done {
  color: var(--good-glow);
  font-weight: 700;
  font-size: 0.85rem;
}

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

/* --- Play screen --- */

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

.play-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.level-label {
  font-family: var(--font-display);
  font-weight: 400;
  letter-spacing: 0.04em;
  color: var(--gold-bright);
  background: var(--glass);
  border: 1px solid var(--glass-line);
  border-radius: 999px;
  padding: 0.4rem 1rem;
  text-align: center;
}

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

.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;
}

.hearts.infinite {
  font-size: 1rem;
  color: var(--cream-dim);
}

.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);
}

.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 0.9s linear;
}

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

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

.shelf {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  flex-wrap: wrap;
  row-gap: 0.9rem;
  min-height: 122px;
}

.spine {
  width: 52px;
  height: 118px;
  border-radius: 6px 6px 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.82rem;
  letter-spacing: 0.05em;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.55);
  flex: 0 0 auto;
  overflow: hidden;
  padding: 4px 0;
}

.spine.just-placed {
  box-shadow: 0 0 0 3px var(--good-glow), 0 0 18px rgba(141, 240, 180, 0.5);
}

.gap-slot {
  width: 26px;
  height: 118px;
  min-height: 0;
  padding: 0;
  margin: 0 3px;
  border: 2px dashed rgba(245, 196, 81, 0.45);
  border-radius: 6px;
  background: transparent;
  flex: 0 0 auto;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.gap-slot:hover:not(:disabled) {
  background: rgba(245, 196, 81, 0.16);
  border-color: var(--gold-bright);
  transform: none;
}

.gap-slot.reveal {
  border-style: solid;
  border-color: var(--good-glow);
  background: rgba(141, 240, 180, 0.18);
}

.shelf.compact .spine {
  width: 30px;
  font-size: 0.7rem;
  letter-spacing: 0.03em;
}

.shelf.compact .gap-slot {
  width: 17px;
  margin: 0 2px;
}

.shelf.dense .spine {
  width: 24px;
  height: 96px;
  font-size: 0.62rem;
}

.shelf.dense .gap-slot {
  width: 14px;
  height: 96px;
  margin: 0 1px;
  border-width: 1.5px;
}

.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);
}

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

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

.deal-zone {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin-top: 1.1rem;
}

.dealt-card {
  background: linear-gradient(180deg, #fffdf4 0%, var(--cream) 60%, #f0e3c0 100%);
  border: 2px solid var(--gold-deep);
  border-radius: 12px;
  padding: 0.55rem 1.8rem;
  text-align: center;
  box-shadow: 0 6px 0 rgba(122, 76, 18, 0.55), 0 10px 22px rgba(0, 0, 0, 0.45);
}

.dealt-card.done {
  opacity: 0.35;
}

.dealt-name {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 1.45rem;
  color: #3f2c12;
  letter-spacing: 0.02em;
}

.dealt-tag {
  margin: 0.1rem 0 0;
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #8a5a2b;
}

.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);
}

.checkpoint-banner {
  margin: 0.8rem auto 0;
  width: fit-content;
  font-family: var(--font-display);
  font-weight: 400;
  letter-spacing: 0.04em;
  color: #4a3305;
  background: linear-gradient(180deg, var(--gold-bright) 0%, var(--gold) 100%);
  border: 1px solid var(--gold-deep);
  border-radius: 999px;
  padding: 0.45rem 1.2rem;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
}

.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); }
}

.peek-overlay {
  position: fixed;
  inset: 0;
  z-index: 140;
  background: rgba(4, 16, 11, 0.82);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

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

.peek-card {
  background: var(--glass);
  border: 1px solid var(--gold);
  border-radius: 14px;
  padding: 1rem 1.4rem;
  max-height: 80vh;
  overflow-y: auto;
}

.peek-card h2 {
  font-family: var(--font-display);
  font-weight: 400;
  color: var(--gold-bright);
  margin: 0 0 0.5rem;
}

.peek-list {
  margin: 0;
  padding-left: 1.4rem;
  columns: 2;
  column-gap: 2rem;
  font-size: 0.95rem;
}

.peek-list li {
  margin-bottom: 0.2rem;
}

.peek-list .current {
  color: var(--gold-bright);
  font-weight: 700;
}

/* --- Codex --- */

.codex-help {
  margin-top: 0;
  color: var(--muted, #666);
  font-size: 0.88rem;
}

.codex-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  align-items: flex-end;
}

.codex-spine {
  width: 26px;
  height: 88px;
  border-radius: 4px 4px 2px 2px;
  border: 1px solid rgba(0, 0, 0, 0.4);
  color: var(--cream);
  display: flex;
  align-items: center;
  justify-content: center;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  overflow: hidden;
}

.codex-spine.dim {
  background: #3b3f3c !important;
  color: rgba(253, 246, 227, 0.45);
}

/* --- High scores --- */

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

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

/* --- Result modal --- */

.result-stars {
  font-size: 2.3rem;
  text-align: center;
  margin: 0.2rem 0 0.4rem;
  color: var(--gold-bright);
  letter-spacing: 0.18em;
  text-shadow: 0 3px 0 var(--gold-shadow), 0 6px 14px rgba(0, 0, 0, 0.5);
}

.result-stars .off {
  opacity: 0.25;
}

.result-detail {
  text-align: center;
  margin: 0 0 0.6rem;
}

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

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

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 130;
  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-help {
  flex-basis: 100%;
  font-size: 0.78rem;
  font-weight: 400;
  color: var(--muted);
}

/* --- Responsive --- */

@media (max-width: 640px) {
  .play-hud {
    justify-content: center;
  }

  .spine {
    width: 44px;
    height: 106px;
    font-size: 0.74rem;
  }

  .gap-slot {
    width: 24px;
    height: 106px;
  }

  .shelf.compact .spine {
    width: 26px;
  }

  .shelf.dense .spine {
    width: 21px;
    height: 88px;
  }

  .shelf.dense .gap-slot {
    height: 88px;
  }

  .peek-list {
    columns: 1;
  }
}

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