/* ============================================================
   Verbiforma — game-specific styles. Design tokens + .btn / .brand /
   .hud come from common.css; everything below is Verbiforma's own.
   (Verbiforma, formerly Word Forge — renamed S18 — is the standalone
   Forge half of Word Foundry; .forge-* class names keep the lineage
   per ENTRY-03.)
   ============================================================ */

/* The JS toggles some elements with the `hidden` attribute, but several
   toggled elements set `display:flex` below, which would override the UA
   `[hidden]{display:none}` rule. This makes `hidden` authoritative again. */
[hidden] { display: none !important; }

main {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 0 14px 28px;
  max-width: 560px;
  margin: 0 auto;
  width: 100%;
  /* common.css locks html/body to the viewport (overflow:hidden). The Forge
     layout is taller than a phone screen, so make main the scroll container —
     it takes the space left under the header and scrolls internally rather
     than clipping the controls off-screen. */
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}
body.install-visible main { padding-bottom: 88px; }

/* Difficulty stays pinned to the top of the scroll area so it's always
   reachable — switching tiers no longer requires scrolling back up past the
   board and controls. */
.topbar {
  position: sticky;
  top: 0;
  z-index: 6;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 12px 0 10px;
  background: rgba(26, 31, 58, 0.92);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

.flag-mark { display: flex; align-items: center; flex-shrink: 0; }
.flag-mark svg {
  width: 28px; height: 18px; border-radius: 3px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

/* ── Mode + difficulty bars ───────────────────────────────── */

/* Both pickers use the shared .segmented control (common.css); buttons keep
   their .mode-btn / .diff-btn classes purely as JS hooks. The two-tap
   mode/tier-change confirm uses the shared gold .confirming pulse. */

/* .segmented sets display:inline-flex, which outranks the UA's
   [hidden]{display:none} — restate it so hiding the difficulty picker
   (and showing the daily note) via the hidden attribute actually works. */
.topbar [hidden] { display: none !important; }

/* The daily-track label that replaces the difficulty picker while Daily is
   active (ENTRY-04): the daily has no difficulty input by design. */
.daily-note {
  font-size: 0.82rem;
  letter-spacing: 0.05em;
  color: var(--text-soft, #f5ede0);
  opacity: 0.8;
}

/* ── Daily streak (S20) ───────────────────────────────────── */

/* Played-days streak line under the scorebar, Daily-only (hidden in
   Endless via the `hidden` attribute). Warm, low-key — a reminder, not a
   nag (D7 anti-guilt). */
.daily-streak {
  width: 100%;
  text-align: center;
  font-family: var(--sans);
  font-size: 0.82rem;
  letter-spacing: 0.03em;
  color: var(--gold-bright);
}

/* ── Daily calendar (S20) ─────────────────────────────────── */

/* Compact month grid of played days, Daily-only. Renders from the
   verbiforma-daily keys — no separate log. */
.daily-cal {
  width: 100%;
  border: 1.5px solid rgba(201, 169, 97, 0.22);
  border-radius: 12px;
  padding: 12px 14px 14px;
  background: var(--slot-bg);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.cal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.cal-title {
  font-family: var(--serif);
  font-size: 1rem;
  font-weight: 600;
  color: var(--gold-bright);
  letter-spacing: 0.02em;
}
.cal-nav {
  font-size: 1.1rem;
  line-height: 1;
  min-width: 40px;
  min-height: 40px;
}
.cal-nav:disabled { opacity: 0.3; cursor: default; pointer-events: none; }
.cal-weekdays,
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}
.cal-weekdays span {
  text-align: center;
  font-family: var(--sans);
  font-size: 0.66rem;
  letter-spacing: 0.04em;
  color: var(--gold-dim);
}
.cal-cell {
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--mono);
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
  color: rgba(245, 237, 224, 0.55);
  border-radius: 8px;
  background: rgba(245, 237, 224, 0.04);
}
.cal-cell.blank { background: none; }
/* A played day: filled gold pip behind the number. */
.cal-cell.played {
  background: rgba(201, 169, 97, 0.28);
  color: var(--card);
  font-weight: 700;
}
/* Today: a gold ring, whether or not it's been played yet. */
.cal-cell.today { box-shadow: inset 0 0 0 2px var(--gold-bright); }

/* ── Scorebar ─────────────────────────────────────────────── */

.scorebar {
  position: relative;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 16px;
  border: 1.5px solid rgba(201, 169, 97, 0.3);
  border-radius: 12px;
  background: var(--slot-bg);
}
/* American-flag accent stripe down the left edge — always shown */
.scorebar.forge::before {
  content: '';
  position: absolute;
  top: 0; bottom: 0; left: 0;
  width: 7px;
  border-radius: 12px 0 0 12px;
  background: linear-gradient(180deg,
    var(--red) 0 34%, #f5ede0 34% 66%, #3c3b6e 66% 100%);
}
.score-main { display: flex; align-items: baseline; gap: 8px; }
.score-label, .timer-label {
  font-family: var(--sans);
  font-size: 0.66rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--gold-dim);
}
.score-value {
  font-family: var(--serif);
  font-size: 1.7rem;
  font-weight: 600;
  color: var(--gold);
  line-height: 1;
}
.score-aux { font-family: var(--sans); font-size: 0.8rem; color: rgba(245, 237, 224, 0.65); }

.forge-timer { display: flex; flex-direction: column; align-items: flex-end; }
/* Tabular Oswald figures, matching the card-game clocks */
.timer-value {
  font-family: var(--mono);
  font-size: 20px;
  font-weight: 500;
  color: var(--gold-bright);
  letter-spacing: 0.04em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.forge-timer.low .timer-value { color: #e8a0a0; }

/* ── Entry + feedback ─────────────────────────────────────── */

.entry {
  min-height: 2.4rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 2px;
  font-family: var(--serif);
  font-weight: 600;
  font-size: 2rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--card);
}
.entry .caret {
  width: 2px; height: 1.6rem;
  background: var(--gold);
  animation: blink 1s step-end infinite;
}
.entry.empty::after {
  content: 'Tap or type letters';
  font-family: var(--sans);
  font-size: 0.9rem;
  font-style: normal;
  font-weight: 400;
  letter-spacing: 0.04em;
  text-transform: none;
  color: var(--gold-dim);
}
@keyframes blink { 50% { opacity: 0; } }

.feedback {
  font-family: var(--sans);
  font-size: 0.9rem;
  letter-spacing: 0.03em;
  color: rgba(245, 237, 224, 0.7);
  min-height: 1.3rem;
  text-align: center;
}
.feedback.error { color: #e8a0a0; }
.feedback.good  { color: #9fd6a0; }

/* ── Tile rack ────────────────────────────────────────────── */

.forge-rack {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: clamp(4px, 1.3vw, 8px);
  max-width: 480px;
}
.tile {
  /* Sized so all 7 dealt tiles fit on one line even on a narrow phone (~360px):
     (viewport − padding − gaps) / 7, capped for larger screens. Slightly smaller
     than before so 7 letters never wrap.
     The 38px floor is a BLESSED exception to the 44px touch floor (S17
     ENTRY-07: the one-row fit was an owner request, post-S16) — recorded in
     docs/ui-glossary.md next to Tetris's 36px landscape buttons. */
  width: clamp(38px, calc((100vw - 74px) / 7), 60px);
  height: clamp(38px, calc((100vw - 74px) / 7), 60px);
  border: 1.5px solid var(--card-edge);
  border-radius: 10px;
  background: var(--card);
  color: var(--ink);
  font-family: var(--serif);
  font-weight: 600;
  font-size: clamp(1.2rem, 5.2vw, 1.8rem);
  text-transform: uppercase;
  cursor: pointer;
  transition: transform 0.08s ease, opacity 0.12s ease;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.25);
}
.tile:active { transform: scale(0.92); }
.tile.used { opacity: 0.32; pointer-events: none; }
.tile:focus-visible { outline: 2.5px solid var(--gold-bright); outline-offset: 2px; }

/* ── Controls ─────────────────────────────────────────────── */

.controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: center; }
/* Meet the >=44px touch-target minimum (common.css .btn padding alone is ~39px). */
.controls .btn { min-height: 44px; display: inline-flex; align-items: center; justify-content: center; }
.btn-primary { background: var(--gold); color: var(--bg-1); border-color: var(--gold-bright); font-weight: 700; }
.btn-primary:hover, .btn-primary:focus-visible { background: var(--gold-bright); }
.btn:disabled { opacity: 0.4; cursor: default; pointer-events: none; }

/* ── Found-words panel ────────────────────────────────────── */

.found-panel {
  width: 100%;
  border: 1.5px solid rgba(201, 169, 97, 0.22);
  border-radius: 12px;
  padding: 12px 14px;
  background: var(--slot-bg);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.found-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: var(--sans);
  font-size: 0.82rem;
  color: rgba(245, 237, 224, 0.75);
}
.round-tally { color: var(--gold-bright); font-weight: 700; }

/* ── Rank ladder (S21) ────────────────────────────────────── */

/* Per-round rank + progress bar in the found panel. Fixed min-height so the
   row never shifts the panel as the rank name or fill changes as words score
   (the progress bar is a fixed 6px; the name/next are single-line). */
.rank-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 26px;
}
.rank-name {
  font-family: var(--serif);
  font-style: italic;
  font-size: 1rem;
  color: var(--gold-bright);
  white-space: nowrap;
  flex-shrink: 0;
}
.rank-progress {
  flex: 1;
  height: 6px;
  border-radius: 3px;
  background: rgba(201, 169, 97, 0.18);
  overflow: hidden;
}
.rank-fill {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--gold-dim), var(--gold-bright));
  transition: width 0.4s ease;
}
.rank-next {
  font-family: var(--sans);
  font-size: 0.68rem;
  letter-spacing: 0.03em;
  color: var(--gold-dim);
  white-space: nowrap;
  flex-shrink: 0;
}

.checklist {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.len-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-family: var(--sans);
  font-size: 0.72rem;
  padding: 4px 9px;
  border-radius: 6px;
  background: rgba(201, 169, 97, 0.12);
  color: rgba(245, 237, 224, 0.8);
}
.len-chip b { color: var(--gold-bright); font-variant-numeric: tabular-nums; }
.len-chip.done { background: rgba(159, 214, 160, 0.18); color: #bfe6bf; }

.found-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}
.found-list li {
  font-family: var(--sans);
  font-size: 0.8rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 3px 8px;
  border-radius: 5px;
  background: rgba(245, 237, 224, 0.06);
  color: var(--card);
}
.found-list li.full { background: rgba(159, 214, 160, 0.22); color: #cdebcd; }

/* ── Overlays + install banner (family-consistent) ────────── */

.win-overlay {
  position: fixed; inset: 0;
  background: rgba(20, 25, 55, 0.88);
  display: flex;
  /* Scroll rather than clip on short/landscape viewports so the "New Run"
     button is always reachable. The panel (margin:auto) centres when there's
     room and sits flush-top + scrolls when the viewport is too short. */
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 24px 16px;
  opacity: 0; visibility: hidden; pointer-events: none;
  transition: opacity 0.3s ease, visibility 0s linear 0.3s;
  z-index: 100;
}
.win-overlay.show { opacity: 1; visibility: visible; pointer-events: all; transition: opacity 0.3s ease, visibility 0s; }
.win-panel {
  background:
    radial-gradient(ellipse at top, rgba(86, 64, 138, 0.42) 0%, transparent 70%),
    var(--panel);
  border: 1px solid var(--gold);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-3);
  padding: 38px 40px 32px;
  text-align: center;
  max-width: 340px; width: 88%; margin: auto;
  display: flex; flex-direction: column; gap: 10px;
  position: relative; overflow: hidden;
}
.win-panel::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 4px;
  background: linear-gradient(90deg, var(--red) 0 34%, #f5ede0 34% 66%, #3c3b6e 66% 100%);
}
.win-title { font-family: var(--serif); font-size: 2rem; font-style: italic; font-weight: 500; color: var(--gold-bright); margin: 0; }
.run-score { font-family: var(--serif); font-size: 2.6rem; font-weight: 600; color: var(--gold-bright); line-height: 1; }
.run-detail { font-family: var(--sans); font-size: 0.86rem; color: rgba(245, 237, 224, 0.75); }
/* Per-round ranks on the run summary — best-rank headline + the sequence
   (S21-03). Collapses when empty (no ranked rounds). */
.run-rank { display: flex; flex-direction: column; gap: 2px; }
.run-rank:empty { display: none; }
.run-rank-best {
  font-family: var(--serif); font-style: italic; font-size: 1.05rem;
  color: var(--gold-bright); letter-spacing: 0.01em;
}
.run-rank-seq {
  font-family: var(--sans); font-size: 0.72rem; letter-spacing: 0.03em;
  color: rgba(245, 237, 224, 0.6);
}

/* Streak line on the daily run summary (blank — collapsed — in Endless). */
.run-streak { font-family: var(--sans); font-size: 0.86rem; color: var(--gold-bright); letter-spacing: 0.02em; }
.run-streak:empty { display: none; }

/* Top-10 leaderboard for the finished run's tier. */
.run-board {
  list-style: none;
  margin: 6px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
  max-height: 200px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.run-board li {
  display: grid;
  grid-template-columns: 1.4rem 1fr auto;
  align-items: baseline;
  gap: 8px;
  font-family: var(--sans);
  font-size: 0.78rem;
  padding: 4px 8px;
  border-radius: 6px;
  background: rgba(245, 237, 224, 0.05);
  color: rgba(245, 237, 224, 0.8);
  text-align: left;
}
.run-board li.is-current { background: var(--gold); color: var(--bg-1); font-weight: 700; }
.run-board .lb-rank { color: var(--gold-dim); font-variant-numeric: tabular-nums; }
.run-board li.is-current .lb-rank { color: var(--bg-1); }
.run-board .lb-score { font-weight: 700; color: var(--gold-bright); font-variant-numeric: tabular-nums; }
.run-board li.is-current .lb-score { color: var(--bg-1); }
.run-board .lb-meta { font-size: 0.7rem; color: rgba(245, 237, 224, 0.55); }
.run-board li.is-current .lb-meta { color: rgba(26, 31, 58, 0.7); }

/* Words the player never found this run, grouped by round. */
.run-missed {
  text-align: left;
  max-height: 230px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  margin-top: 4px;
}
.run-missed:empty { display: none; }
.run-missed-none { font-family: var(--sans); font-size: 0.82rem; color: var(--gold); opacity: 0.85; margin: 6px 0 0; }
.run-missed-head {
  font-family: var(--sans); font-size: 0.8rem; font-weight: 700;
  color: rgba(245, 237, 224, 0.85); text-align: center; margin-bottom: 6px;
}
.run-missed-round { margin-bottom: 8px; }
.run-missed-label {
  font-family: var(--sans); font-size: 0.72rem;
  color: rgba(245, 237, 224, 0.6); margin-bottom: 4px;
}
.found-list.missed li { background: rgba(178, 34, 52, 0.16); color: #f0cdce; }

.win-panel .btn { margin-top: 10px; align-self: center; padding: 12px 30px; font-size: 0.95rem; }
/* Share + New Run/Play Endless share a row on the run summary (S20). */
.win-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 4px; }
.win-actions .btn { margin-top: 6px; }
.win-actions .btn[hidden] { display: none; }

/* The install banner is now the shared #pwa-banner (common.css), injected by
   ../pwa-install.js; the old .install-banner toast styles were removed. (BL-022) */

/* ── Forma + personal-best celebration (S21, BL-065) ──────── */

/* The "FORMA!" burst — floats over the board on the rare full-rack word. */
.forma-burst {
  position: fixed;
  top: 40%; left: 50%;
  transform: translate(-50%, -50%) scale(0.4);
  font-family: var(--serif);
  font-style: italic;
  font-weight: 600;
  font-size: clamp(2.4rem, 12vw, 4.6rem);
  letter-spacing: 0.04em;
  color: var(--gold-bright);
  text-shadow: 0 2px 22px rgba(232, 205, 142, 0.65);
  opacity: 0;
  pointer-events: none;
  z-index: 120;
}
.forma-burst.show { animation: forma-burst 1s ease forwards; }
@keyframes forma-burst {
  0%   { opacity: 0; transform: translate(-50%, -50%) scale(0.4); }
  22%  { opacity: 1; transform: translate(-50%, -50%) scale(1.18); }
  32%  { transform: translate(-50%, -50%) scale(1.18); }   /* ~120 ms hit-stop */
  40%  { transform: translate(-50%, -50%) scale(1); }
  75%  { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1.05); }
}

/* Gold flash across the entry line. */
.entry.forma-flash { animation: forma-flash 0.7s ease; }
@keyframes forma-flash {
  0%, 100% { background: transparent; box-shadow: none; }
  30% { background: rgba(232, 205, 142, 0.28); box-shadow: 0 0 22px rgba(232, 205, 142, 0.5); }
}

/* Tile-cascade shimmer across the rack — a gold sweep, staggered per tile. */
.forge-rack.forma-cascade .tile { animation: tile-shimmer 0.6s ease; }
.forge-rack.forma-cascade .tile:nth-child(1) { animation-delay: 0s; }
.forge-rack.forma-cascade .tile:nth-child(2) { animation-delay: 0.06s; }
.forge-rack.forma-cascade .tile:nth-child(3) { animation-delay: 0.12s; }
.forge-rack.forma-cascade .tile:nth-child(4) { animation-delay: 0.18s; }
.forge-rack.forma-cascade .tile:nth-child(5) { animation-delay: 0.24s; }
.forge-rack.forma-cascade .tile:nth-child(6) { animation-delay: 0.30s; }
.forge-rack.forma-cascade .tile:nth-child(7) { animation-delay: 0.36s; }
@keyframes tile-shimmer {
  0%, 100% { box-shadow: 0 2px 4px rgba(0, 0, 0, 0.25); transform: translateY(0); }
  50% { box-shadow: 0 0 18px 3px var(--gold-bright); transform: translateY(-5px); }
}

/* New-personal-best flourish on the run summary (S21-05). */
.run-best {
  font-family: var(--serif);
  font-style: italic;
  font-size: 1.05rem;
  color: var(--gold-bright);
  letter-spacing: 0.02em;
}
.run-best.celebrate { animation: pb-pulse 0.9s ease; }
@keyframes pb-pulse {
  0% { transform: scale(0.6); opacity: 0; }
  40% { transform: scale(1.14); opacity: 1; }
  70% { transform: scale(1); }
  100% { transform: scale(1); opacity: 1; }
}

/* ── Animations + reduced motion ──────────────────────────── */

@keyframes shake { 0%,100%{transform:translateX(0)} 20%{transform:translateX(-6px)} 40%{transform:translateX(6px)} 60%{transform:translateX(-4px)} 80%{transform:translateX(4px)} }
.entry.shake { animation: shake 0.4s ease; }

@keyframes pop { 0%{transform:scale(1)} 40%{transform:scale(1.18)} 100%{transform:scale(1)} }
.score-value.bump { animation: pop 0.32s ease; }

@media (prefers-reduced-motion: reduce) {
  .entry.shake, .score-value.bump, .entry .caret { animation: none !important; transition: none !important; }
  .rank-fill { transition: none !important; }
  /* Celebrations are additive — the feedback line still announces (S21-04).
     Neutralize every celebration animation and keep the burst hidden. */
  .forma-burst, .forma-burst.show,
  .entry.forma-flash,
  .forge-rack.forma-cascade .tile,
  .run-best.celebrate { animation: none !important; }
  .forma-burst.show { display: none !important; }
}
