@import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@400;600;700;900&display=swap');

/* ── Design tokens ──────────────────────
   Flat/geometric direction (Two Dots / Monument Valley register) — no
   gradients, no glow, no drop shadows. Ancient Egypt palette: warm
   sandstone/papyrus background, antique gold, verdigris teal, terracotta.
   To tweak colors: edit the :root tokens below. Hardcoded slot and stage
   colors appear near their respective rule blocks and are labeled. */
:root {
  --bg: #f5ead0;           /* warm sand / papyrus */
  --bg-elevated: #ead8b0;  /* slightly richer papyrus (cards, slot bg) */
  --divider: #c8b070;      /* golden tan */
  --gold: #bf7d10;         /* antique gold — main accent */
  --gold-on: #2a1200;      /* text on gold surfaces */
  --teal: #1e6e5e;         /* verdigris / malachite */
  --teal-on: #e0f5f0;      /* text on teal surfaces */
  --green: #2a6a38;        /* muted olive green (locked / correct) */
  --green-on: #f0f8f0;     /* text on green surfaces */
  --red: #b82212;          /* terracotta / hieroglyph crimson */
  --slate: #8a7050;        /* warm sandstone grey */
  --text: #1a0d04;         /* very dark warm brown */
  --text-muted: #4a3018;   /* medium warm brown — tweak */
  --text-dim: #8a6a40;     /* lighter warm brown */
  --font-display: 'Cinzel', 'Trajan Pro', 'Palatino Linotype', Georgia, serif; /* tweak */
}

* { margin: 0; padding: 0; box-sizing: border-box; }
button, select, input, textarea { font: inherit; color: inherit; }

body {
  font-family: var(--font-display);
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

#game {
  width: 100%;
  max-width: 480px;
  padding: 16px 12px 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

/* ── Top bar (shared) ─────────────────── */
.topbar {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.topbar-title {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--gold);
  text-align: center;
  flex: 1;
}
.btn-back {
  background: var(--bg-elevated);
  border: 1px solid var(--divider);
  color: var(--text);
  border-radius: 8px;
  width: 34px;
  height: 34px;
  font-size: 1rem;
  cursor: pointer;
}
.diff-select select {
  background: var(--bg-elevated);
  border: 1px solid var(--divider);
  color: var(--text);
  border-radius: 6px;
  padding: 5px 6px;
  font-size: 0.8rem;
  font-family: var(--font-display);
}

.header { text-align: center; width: 100%; }
.title {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--gold);
}
.theme-label {
  margin-top: 4px;
  font-size: 0.95rem;
  color: var(--text-muted);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  text-align: center;
}

/* ── Home screen (flat/geometric — spec 6.5) ───
   Hierarchy: two quiet icon buttons for Stats/Settings, a centered hero
   (tiered triangle emblem + wordmark), one primary CTA, one secondary
   CTA, and a lower-emphasis text-link row for How to Play / Daily
   Puzzle. Flat fills only — no gradients, no shadows, no glow. */
.home-screen {
  width: 100%;
  display: flex;
  flex-direction: column;
  min-height: calc(100dvh - 60px);
  padding-top: 4px;
}
.home-topicons {
  width: 100%;
  display: flex;
  justify-content: space-between;
}
.home-icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1.5px solid var(--divider);
  background: transparent;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.home-icon-btn:hover { border-color: var(--slate); color: var(--text); }

.home-hero {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 24px 0;
}
.home-emblem { display: block; }
.emblem-peak { fill: var(--gold); }
.emblem-mid { fill: var(--teal); }
.emblem-base { fill: var(--slate); }
.home-wordmark {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--text);
  text-align: center;
}
.home-tagline {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: center;
  margin-top: -10px;
  letter-spacing: 0.02em;
}

.home-actions {
  width: 100%;
  max-width: 300px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.home-cta-primary {
  width: 100%;
  background: var(--gold);
  color: var(--gold-on);
  border: none;
  border-radius: 14px;
  padding: 14px 16px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.98rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.home-cta-sub { font-size: 0.72rem; font-weight: 500; opacity: 0.75; }
.home-cta-secondary {
  width: 100%;
  background: transparent;
  color: var(--teal);
  border: 1.5px solid var(--teal);
  border-radius: 14px;
  padding: 13px 16px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
}
.home-links {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 2px;
}
.home-link {
  background: none;
  border: none;
  color: var(--text-muted);
  font-family: var(--font-display);
  font-size: 0.8rem;
  padding: 6px;
  cursor: pointer;
}
.home-link:hover { color: var(--text); }
.home-link:disabled { color: var(--text-dim); cursor: not-allowed; }
.home-links-divider { color: var(--text-dim); font-size: 0.8rem; }

.home-streak {
  width: 100%;
  text-align: center;
  font-size: 0.78rem;
  color: var(--text-muted);
  padding-top: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

/* ── Stats screen ──────────────────────── */
.stats-grid {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.stat-card {
  background: var(--bg-elevated);
  border: 1px solid var(--divider);
  border-radius: 10px;
  padding: 16px 10px;
  text-align: center;
}
.stat-value { font-size: 1.5rem; font-weight: 700; color: var(--gold); }
.stat-label { font-size: 0.72rem; color: var(--text-muted); margin-top: 4px; }

/* ── Settings screen ───────────────────── */
.settings-list { width: 100%; display: flex; flex-direction: column; gap: 12px; }
.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-elevated);
  border: 1px solid var(--divider);
  border-radius: 8px;
  padding: 12px 14px;
}
.settings-row-label { font-size: 0.88rem; }
.settings-btn { width: 100%; }

.switch { position: relative; display: inline-block; width: 42px; height: 24px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch-slider {
  position: absolute; cursor: pointer; inset: 0;
  background: var(--divider); border-radius: 999px; transition: background 0.15s ease;
}
.switch-slider::before {
  content: "";
  position: absolute;
  width: 18px; height: 18px;
  left: 3px; top: 3px;
  background: var(--text);
  border-radius: 50%;
  transition: transform 0.15s ease;
}
.switch input:checked + .switch-slider { background: var(--gold); }
.switch input:checked + .switch-slider::before { transform: translateX(18px); background: var(--gold-on); }


/* ── Manual reduced-motion override (Settings toggle), in addition to
   the prefers-reduced-motion media query below ── */
.force-reduced-motion * { animation: none !important; transition: none !important; }


/* ── Loading screen ────────────────────── */
.loading-screen {
  width: 100%;
  min-height: 50vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
}
.loading-spinner {
  width: 34px;
  height: 34px;
  border: 3px solid var(--divider);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-label { color: var(--text-muted); font-size: 0.85rem; }

:root {
  /* Sized off the pyramid's widest row (9 letters) so it always fits the
     game container instead of clipping off-screen — the old fixed 38px/
     32px breakpoints overflowed on ~375-393px phones (iPhone SE/6/7/8,
     iPhone 12/13/14 base). 56px = 24px outer padding + 8 gaps at 4px. */
  --tile-size: clamp(30px, calc((100vw - 56px) / 9), 46px);
}

/* ── Stage pips + score bar ──────────── */
.stage-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}
.stage-pips { display: flex; gap: 8px; align-items: center; }
.stage-pip {
  width: 36px;
  height: 6px;
  border-radius: 3px;
  background: var(--divider);
  transition: background 0.4s ease;
}
.stage-pip.done { background: var(--green); }
.stage-pip.active { background: var(--gold); }
.stage-score {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.02em;
  transition: color 0.3s ease;
}
.stage-score.updated { color: var(--gold); }

/* ── Pyramid ────────────────────────── */
.pyramid {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 8px 0;
}
.pyramid-row {
  display: flex;
  gap: 4px;
  transition: opacity 0.35s ease;
}
.pyramid-row.inactive { opacity: 0.28; }

/* ── Slots ──────────────────────────── */
.slot {
  width: var(--tile-size);
  height: var(--tile-size);
  border: 2px solid var(--divider);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.05rem;
  font-weight: 700;
  background: var(--bg-elevated);
  color: var(--text);
  transition: background 0.15s ease, border-color 0.15s ease;
}

.slot.active-empty { border-color: var(--slate); cursor: pointer; }
.slot.active-empty:hover, .slot.active-empty:active { border-color: var(--text-muted); background: #dcc898; }

.slot.anchor { background: #f0e0b0; border-color: var(--gold); color: #6a4808; }

.slot.placed { background: #f0dea0; border-color: var(--gold); color: #6a4808; cursor: pointer; }
.slot.placed:hover, .slot.placed:active { border-color: #d49810; }

.slot.locked { background: #c8e0d0; border-color: var(--green); color: #1a4820; }

.slot.skipped { background: var(--bg-elevated); border-color: var(--divider); color: var(--text-dim); }

.pyramid-row.hint-target { cursor: pointer; }
.pyramid-row.hint-target .slot { border-color: var(--gold); }
.pyramid-row.hint-target:hover .slot { border-color: #d49810; background: #f0dea0; }

.slot.wrong {
  border-color: var(--red) !important;
  background: #f5d0c8 !important;
  animation: shake 0.45s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  15% { transform: translateX(-5px); }
  30% { transform: translateX(5px); }
  45% { transform: translateX(-4px); }
  60% { transform: translateX(4px); }
  75% { transform: translateX(-2px); }
  90% { transform: translateX(2px); }
}

/* ── Rack ────────────────────────────── */
.rack-area { display: flex; flex-direction: column; align-items: center; gap: 10px; min-height: 60px; width: 100%; }
.rack-label { font-size: 0.8rem; color: var(--text-dim); letter-spacing: 0.04em; text-align: center; }
.rack { display: flex; flex-wrap: wrap; justify-content: center; gap: 7px; max-width: 420px; }

.tile {
  width: var(--tile-size);
  height: var(--tile-size);
  background: #7a5000;         /* deep amber/bronze — pops against papyrus bg */
  border: 2px solid #6a4000;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  font-weight: 700;
  color: #f5e8d0;              /* light cream — 5.5:1 contrast on tile */
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.12s ease;
}
.tile.selected {
  border-color: #f5e8d0;       /* cream border lifts clearly against dark tile */
  transform: translateY(-3px);
}

/* ── Partition hint colors (rack tiles) ─ */
.tile.p-teal   { background: var(--teal);  border-color: var(--teal);  color: var(--teal-on); }
.tile.p-pink   { background: #c85030; border-color: #c85030; color: #f5ead0; } /* terracotta */
.tile.p-orange { background: #c09020; border-color: #c09020; color: #f5ead0; } /* amber */

/* ── Actions ─────────────────────────── */
.actions { display: flex; gap: 12px; min-height: 44px; align-items: center; }
.btn {
  padding: 11px 30px;
  border: none;
  border-radius: 10px;
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  cursor: pointer;
  transition: transform 0.12s ease, opacity 0.12s ease;
}
.btn-check { background: var(--green); color: var(--green-on); }
.btn-check.ready { animation: pulse-scale 1.6s ease-in-out infinite; }
@keyframes pulse-scale {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.035); }
}

.btn-next { background: var(--gold); color: var(--gold-on); }
.btn-secondary { background: transparent; color: var(--teal); border: 1.5px solid var(--teal); }
.btn-plain { background: none; border: none; color: var(--text-muted); font-weight: 700; padding: 8px; }
.btn-plain:hover { color: var(--text); }

/* ── Secondary actions (hint / skip) ──── */
.secondary-actions { display: flex; gap: 10px; align-items: center; }
.btn-hint, .btn-skip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: transparent;
  border: 1.5px solid var(--divider);
  color: var(--text-muted);
  border-radius: 8px;
  padding: 7px 14px;
  font-size: 0.82rem;
  cursor: pointer;
}
.btn-hint:hover:not(:disabled), .btn-skip:hover, .btn-shuffle:hover { border-color: var(--slate); color: var(--text); }

/* ── Shuffle button (rack area) ──── */
.btn-shuffle {
  display: inline-flex;
  align-items: center;
  background: transparent;
  border: 1.5px solid var(--divider);
  color: var(--text-dim);
  border-radius: 8px;
  padding: 5px 14px;
  font-size: 0.8rem;
  cursor: pointer;
  font-family: var(--font-display);
}
.btn-hint:disabled { opacity: 0.4; cursor: not-allowed; }
.hint-badge {
  display: inline-block;
  background: var(--text-muted);  /* warm brown — ~9.7:1 contrast at small size */
  color: var(--bg);
  border-radius: 999px;
  padding: 1px 7px;
  font-size: 0.72rem;
  font-weight: 700;
  margin-left: 4px;
}
.hint-option { text-align: left; width: 100%; padding: 10px 14px; }
.hint-option-sub { font-size: 0.72rem; color: var(--text-muted); font-weight: 400; }

/* ── Message ─────────────────────────── */
.message { font-size: 0.88rem; text-align: center; min-height: 1.3em; }
.message.success { color: var(--green); }
.message.error { color: var(--red); }
.message.info { color: var(--text-muted); }

/* ── Complete panel ───────────────────── */
.complete-panel { display: flex; flex-direction: column; align-items: center; gap: 10px; padding-top: 8px; }
.complete-heading { font-size: 1.4rem; font-weight: 700; color: var(--gold); text-align: center; }
.complete-stars { font-size: 1.6rem; color: var(--gold); letter-spacing: 4px; }
.complete-sub { color: var(--text-muted); text-align: center; font-size: 0.95rem; }
.complete-sub-small { color: var(--text-dim); text-align: center; font-size: 0.78rem; }
.complete-actions { display: flex; gap: 10px; margin-top: 6px; }

/* ── Definition popup ─────────────────── */
.popup-backdrop {
  position: fixed; inset: 0; background: rgba(26, 13, 4, 0.55);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.popup-card {
  background: var(--bg-elevated); border: 1px solid var(--divider); border-radius: 12px;
  padding: 24px; width: 85%; max-width: 320px; text-align: center;
  display: flex; flex-direction: column; gap: 12px;
}
.popup-word { font-size: 1.3rem; font-weight: 700; color: var(--gold); letter-spacing: 0.05em; }
.popup-def { font-size: 0.92rem; color: var(--text-muted); line-height: 1.4; }
.pending-tag { color: var(--text-dim); font-size: 0.78rem; }

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

/* ═══════════════════════════════════════════════════
   Phase 1 additions — level-based topbar, difficulty badge,
   achievement unlock, nav links, skip level button
   ══════════════════════════════════════════════════ */

/* ── Game topbar items ─────────────────── */
.topbar-level {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.04em;
  min-width: 60px;
}
.topbar-hints {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-muted);
  min-width: 40px;
  text-align: right;
}

/* ── Difficulty badge (inline in theme label / done panel) ── */
.diff-badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  border-radius: 4px;
  padding: 2px 7px;
  margin-left: 6px;
  vertical-align: middle;
  background: var(--divider);
  color: var(--text-muted);
}
.diff-badge.diff-beginner { background: #c8e0d0; color: #1a4820; }
.diff-badge.diff-easy     { background: #d0e8c0; color: #1e4820; }
.diff-badge.diff-medium   { background: #f5e8c0; color: #7a5008; }
.diff-badge.diff-hard     { background: #f5dece; color: #8a2010; }
.diff-badge.diff-expert   { background: #f5d0c8; color: #8a1010; }
.diff-badge.diff-master   { background: #e8d0f0; color: #500070; }

/* ── Achievement unlock box (done panel) ── */
.achievement-unlock {
  width: 100%;
  border: 1.5px solid var(--gold);
  border-radius: 10px;
  padding: 12px 16px;
  background: #f0dea0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.achievement-unlock-label {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--gold);
}
.achievement-unlock-img {
  width: 72px;
  height: 72px;
  object-fit: cover;
  border-radius: 6px;
  border: 1.5px solid var(--gold);
  display: block;
  margin: 4px 0;
}
.achievement-unlock-name {
  font-size: 1.0rem;
  font-weight: 700;
  color: var(--text);
}
.achievement-unlock-era {
  font-size: 0.76rem;
  color: var(--text-muted);
}

/* ── Nav links row (done panel bottom) ──── */
.nav-links {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 4px;
}
.nav-link {
  background: none;
  border: none;
  color: var(--text-dim);
  font-family: var(--font-display);
  font-size: 0.78rem;
  padding: 6px 8px;
  cursor: pointer;
  border-radius: 6px;
}
.nav-link:hover { color: var(--text-muted); background: var(--bg-elevated); }

/* ── Skip Level button (secondary actions row) ── */
.btn-skip-level {
  display: inline-flex;
  align-items: center;
  background: transparent;
  border: 1.5px solid var(--divider);
  color: var(--text-dim);
  border-radius: 8px;
  padding: 7px 14px;
  font-size: 0.82rem;
  cursor: pointer;
}
.btn-skip-level:hover {
  border-color: var(--red);
  color: var(--red);
}

/* ── Skip confirm warning text ────────── */
.skip-confirm-warning {
  font-size: 0.82rem;
  color: var(--gold);
  background: #f0dea0;
  border: 1px solid var(--gold);
  border-radius: 8px;
  padding: 8px 12px;
  text-align: center;
  line-height: 1.4;
}


/* ═══════════════════════════════════════════════════
   Phase 2 — splash, in-game menu, stage tile colors,
   animations (shimmer, rack entrance), section
   transition screen, endgame screen
   ══════════════════════════════════════════════════ */

/* ── Splash / branded loading screen ───────────── */
.splash-emblem {
  width: 96px;
  height: 76px;
  display: block;
}
/* .emblem-peak / .emblem-mid / .emblem-base fill tokens already defined above */
.splash-wordmark {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--text);
  text-align: center;
  margin-top: 4px;
  margin-bottom: 4px;
}

/* ── In-game menu button (topbar right) ─────────── */
.btn-menu {
  width: 34px;
  height: 34px;
  background: transparent;
  border: 1.5px solid var(--divider);
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.btn-menu:hover,
.btn-menu:active { border-color: var(--slate); color: var(--text); }

/* ── Stage tile coloring — per-stage gold / teal / slate ──
   .stage-N class is added to each .pyramid-row in render.js.
   These rules override the generic .slot.anchor / .placed / .locked above.
   Specificity: .stage-N .slot.X (0,3,0) beats .slot.X (0,2,0) always.
   ────────────────────────────────────────────────────────── */

/* Stage 0 — Apex — Gold */
.stage-0 .slot.active-empty { border-color: var(--gold); }
.stage-0 .slot.active-empty:hover,
.stage-0 .slot.active-empty:active  { border-color: #d49810; background: #eddfa0; }
.stage-0 .slot.anchor                { background: #f0e0b0; border-color: var(--gold); color: #6a4808; }
.stage-0 .slot.placed                { background: #f0dea0; border-color: var(--gold); color: #6a4808; cursor: pointer; }
.stage-0 .slot.placed:hover,
.stage-0 .slot.placed:active         { border-color: #d49810; }
.stage-0 .slot.locked                { background: #f0d070; border-color: var(--gold); color: #5a3600; }

/* Stage 1 — Middle — Teal */
.stage-1 .slot.active-empty { border-color: var(--teal); }
.stage-1 .slot.active-empty:hover,
.stage-1 .slot.active-empty:active  { border-color: #256055; background: #bcdcd4; }
.stage-1 .slot.anchor                { background: #c4e0d8; border-color: var(--teal); color: #0a3028; }
.stage-1 .slot.placed                { background: #bcdcd4; border-color: var(--teal); color: #0a3028; cursor: pointer; }
.stage-1 .slot.placed:hover,
.stage-1 .slot.placed:active         { border-color: #256055; }
.stage-1 .slot.locked                { background: #8eccc0; border-color: var(--teal); color: #0a2e26; }

/* Stage 2 — Base — Slate */
.stage-2 .slot.active-empty { border-color: var(--slate); }
.stage-2 .slot.active-empty:hover,
.stage-2 .slot.active-empty:active  { border-color: #6a5030; background: #d8ccb0; }
.stage-2 .slot.anchor                { background: #ddd0b8; border-color: var(--slate); color: #3a2810; }
.stage-2 .slot.placed                { background: #d8ccb0; border-color: var(--slate); color: #3a2810; cursor: pointer; }
.stage-2 .slot.placed:hover,
.stage-2 .slot.placed:active         { border-color: #6a5030; }
.stage-2 .slot.locked                { background: #b8a888; border-color: var(--slate); color: #3a2810; }

/* ── Correct-word shimmer (lock-in pop) ─────────── */
@keyframes lock-in {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.08); }
  75%  { transform: scale(0.97); }
  100% { transform: scale(1); }
}
.slot.just-locked { animation: lock-in 0.4s ease; }

/* ── Rack tile entrance animation ───────────────── */
@keyframes tile-drop-in {
  from { opacity: 0; transform: translateY(-10px); }
  to   { opacity: 1; transform: translateY(0); }
}
.tile.tile-new {
  animation: tile-drop-in 0.22s ease both;
  /* 'both' fills backward (opacity:0 before start) and holds the end state */
}

/* ── Section transition + endgame screen ─────────── */
.section-transition-screen {
  width: 100%;
  min-height: 80vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  text-align: center;
  padding: 24px 16px;
}
.section-complete-kicker {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gold);
  margin-top: 16px;
}
.section-complete-heading {
  font-size: 2rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.1;
}
.section-complete-sub {
  font-size: 0.9rem;
  color: var(--text-muted);
}
.section-continue-btn { margin-top: 12px; }

/* ═══════════════════════════════════════════════════
   Phase 4 — capstone, desktop responsive, drag-and-drop,
   How to Play visual refresh
   ══════════════════════════════════════════════════ */

/* ── Pyramid capstone (decorative, above apex row) ── */
.pyramid-capstone {
  display: flex;
  justify-content: center;
  margin-bottom: 2px;
}
.capstone-gem {
  width: calc(3 * var(--tile-size) + 8px); /* matches 3-tile apex row — tweak */
  height: auto;   /* proportional to viewBox (100 × 28 ratio → ~28% of width) */
  opacity: 0.9;
}

/* ── Drag-and-drop ───────────────────────────────── */
/* Source tile dims while ghost is in flight */
.tile.dragging {
  opacity: 0.28;
  transform: none !important;
  transition: none;
}

/* Ghost inherits tile styles; this just ensures no extra margin */
#drag-ghost {
  pointer-events: none;
  user-select: none;
}

/* Drop-target highlight on empty slot during drag */
.slot.active-empty.drag-over {
  border-color: var(--gold) !important;
  background:   #f0dea0 !important;
}

/* ── How to Play — visual step layout ────────────── */
.howto-steps {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.howto-step {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  background: var(--bg-elevated);
  border: 1px solid var(--divider);
  border-radius: 10px;
  padding: 14px 14px;
}

.howto-step-visual {
  flex-shrink: 0;
  width: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.howto-icon {
  width: 48px;
  height: 46px;
  display: block;
}

.howto-icon-text {
  font-size: 1.3rem;
  text-align: center;
  color: var(--gold);
  letter-spacing: 2px;
}

/* Mini pip row (stage indicator) in How to Play */
.howto-pip-row {
  display: flex;
  gap: 5px;
  align-items: center;
}
.howto-pip {
  width: 16px;
  height: 5px;
  border-radius: 3px;
  background: var(--divider);
}
.howto-pip.done   { background: var(--green); }
.howto-pip.active { background: var(--gold); }

/* Mini slot row in How to Play */
.howto-slot-row {
  display: flex;
  gap: 4px;
}
.howto-slot {
  width: 20px;
  height: 20px;
  border-radius: 4px;
  border: 1.5px solid var(--divider);
  background: var(--bg-elevated);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--text);
}
.howto-slot.anchor { background: #f0e0b0; border-color: var(--gold); color: #6a4808; }
.howto-slot.placed { background: #f0dea0; border-color: var(--gold); color: #6a4808; }
.howto-slot.empty  { border-color: var(--slate); }

/* Mini difficulty badge row in How to Play */
.howto-badge-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.howto-badge {
  display: inline-block;
  font-size: 0.58rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border-radius: 3px;
  padding: 2px 5px;
}

.howto-step-text { flex: 1; }
.howto-step-title {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 4px;
}
.howto-step-body {
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.45;
}

/* ═══════════════════════════════════════════════════
   Phase 5D — Achievement Museum screen
   ══════════════════════════════════════════════════ */

.museum-btn { width: 100%; margin-top: 8px; }

.museum-header-sub {
  font-size: 0.78rem;
  color: var(--text-muted);
  text-align: center;
  margin: -4px 0 4px;
}

.museum-grid {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.museum-card {
  background: var(--bg-elevated);
  border: 1px solid var(--divider);
  border-radius: 10px;
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  text-align: center;
}
.museum-card.unlocked:hover { border-color: var(--slate); }
.museum-card.locked { opacity: 0.55; cursor: default; }

.museum-card-img {
  width: 130px;
  height: 130px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--divider);
  display: block;
}

.museum-card-name {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}
.museum-card-era {
  font-size: 0.7rem;
  color: var(--text-muted);
}
.museum-card-cat {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: var(--bg);
  border: 1px solid var(--divider);
  border-radius: 4px;
  padding: 2px 6px;
  color: var(--text-dim);
}
.museum-card-lock {
  font-size: 1.4rem;
  color: var(--divider);
  margin: 8px 0 2px;
}
.museum-card-level {
  font-size: 0.72rem;
  color: var(--text-dim);
}

/* Museum detail popup — extends base .popup-card */
.museum-popup-img {
  width: 180px;
  height: 180px;
  object-fit: cover;
  border-radius: 8px;
  border: 1.5px solid var(--divider);
  display: block;
  margin: 0 auto 4px;
}
.museum-popup-name {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--gold);
}

/* Chip row: era · year badge · category pill */
.museum-popup-chips {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin: -2px 0 2px;
}
.museum-popup-era-chip {
  font-size: 0.72rem;
  color: var(--text-muted);
}
.museum-popup-year-chip {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  background: var(--bg);
  border: 1px solid var(--divider);
  border-radius: 10px;
  padding: 1px 8px;
  color: var(--text-dim);
}
.museum-popup-cat-chip {
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  background: var(--gold);
  color: var(--gold-on);
  border-radius: 10px;
  padding: 2px 9px;
}

/* Divider + About section */
.museum-popup-body {
  width: 100%;
  border-top: 1px solid var(--divider);
  padding-top: 12px;
  text-align: left;
}
.museum-popup-body-label {
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gold);
  margin-bottom: 6px;
}
.museum-popup-desc {
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.65;
  text-align: left;
}

/* Allow popup to scroll when description is long */
.museum-popup-card {
  max-height: 85vh;
  overflow-y: auto;
}

.museum-zoom-backdrop {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: rgba(26, 13, 4, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.museum-zoom-img {
  max-width: 90vw;
  max-height: 90vh;
  object-fit: contain;
  border-radius: 10px;
  cursor: pointer;
}

/* ── Gallery Rooms lobby (Phase 5D+) ─────────────── */
.gallery-sound-btn {
  width: 100%;
  background: transparent;
  border: 1.5px solid var(--divider);
  color: var(--text-muted);
  border-radius: 10px;
  padding: 10px 14px;
  font-family: var(--font-display);
  font-size: 0.82rem;
  cursor: pointer;
  text-align: center;
}
.gallery-sound-btn.active {
  border-color: var(--teal);
  color: var(--teal);
  background: rgba(30, 110, 94, 0.08);
}

.gallery-mini-row {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.gallery-mini-card {
  background: var(--bg-elevated);
  border: 1px solid var(--divider);
  border-radius: 10px;
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  text-align: center;
  cursor: pointer;
  min-height: 100px;
  justify-content: center;
}
.gallery-mini-card.locked { cursor: default; opacity: 0.65; }
.gallery-mini-card:not(.locked):hover { border-color: var(--gold); }

.gallery-mini-label {
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--gold);
}

.gallery-mini-img {
  width: 54px;
  height: 54px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--divider);
  display: block;
}

.gallery-mini-lock {
  font-size: 1.3rem;
  color: var(--divider);
  padding: 4px 0;
}

.gallery-mini-name {
  font-size: 0.73rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}
.gallery-mini-sub {
  font-size: 0.64rem;
  color: var(--text-dim);
}

.gallery-section-heading {
  width: 100%;
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-dim);
  text-align: left;
  padding-left: 2px;
  margin-top: 2px;
}

.gallery-room-grid {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.gallery-room-card {
  background: var(--bg-elevated);
  border: 1px solid var(--divider);
  border-radius: 10px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  text-align: center;
  overflow: hidden;
}
.gallery-room-card:hover { border-color: var(--gold); }

.gallery-room-thumb {
  width: 100%;
  height: 68px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--divider);
  display: block;
}
.gallery-room-thumb-lock {
  width: 100%;
  height: 68px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  color: var(--divider);
  background: var(--bg);
  border-radius: 6px;
  border: 1px solid var(--divider);
}

.gallery-room-label {
  display: flex;
  align-items: center;
  gap: 4px;
  justify-content: center;
}
.gallery-room-icon { font-size: 0.82rem; }
.gallery-room-name {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}
.gallery-room-count {
  font-size: 0.62rem;
  color: var(--text-dim);
}

/* ── Tutorial / Onboarding overlay ──────────────── */
.tutorial-backdrop {
  background: rgba(26, 13, 4, 0.78); /* slightly darker than standard popup-backdrop */
}

.tutorial-card {
  background: var(--bg-elevated);
  border: 1.5px solid var(--gold);
  border-radius: 14px;
  padding: 28px 22px 22px;
  width: 88%;
  max-width: 340px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  position: relative;
}

.tutorial-skip {
  position: absolute;
  top: 12px;
  right: 14px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-family: var(--font-display);
  font-size: 0.75rem;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 4px;
}
.tutorial-skip:hover { color: var(--text-muted); }

.tutorial-step-dots {
  display: flex;
  gap: 6px;
  justify-content: center;
}
.tutorial-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--divider);
  transition: background 0.2s ease;
}
.tutorial-dot.active { background: var(--gold); }

.tutorial-visual {
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tutorial-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--gold);
  letter-spacing: 0.03em;
}

.tutorial-body {
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.55;
  max-width: 270px;
}

/* ── Desktop responsive layout (≥640px) ──────────── */
@media (min-width: 640px) {
  :root {
    /* Larger tiles on wide screens — clamp keeps them sane at any width */
    --tile-size: clamp(40px, 5.5vw, 58px);
  }

  #game {
    max-width: 740px;
    padding: 28px 28px 48px;
    gap: 20px;
  }

  /* Slightly more breathing room in the pyramid */
  .pyramid { gap: 7px; padding: 10px 0; }

  /* Rack tiles slightly larger gap */
  .rack { gap: 10px; }

  /* Slot and tile text scales with tile size — bump base size a touch */
  .slot { font-size: 1.1rem; border-radius: 8px; }
  .tile { font-size: 1.15rem; border-radius: 10px; }

  /* Done panel and popup card get a bit more padding */
  .popup-card { padding: 28px; max-width: 380px; }
  .complete-panel { gap: 12px; padding-top: 12px; }
}
