/* ============================================================
   Typeshift — game styles
   Design: dark navy shell, cream/gold letter tiles, blue highlight
   ============================================================ */

:root {
  --cell-gap: 4px;
  --col-gap: 10px;
  --reel-visible: 5;
}

/* Cell size scales with BOTH the viewport and the column count, so a
   5-column puzzle still fits a narrow phone. --cell-max (the ideal size)
   is the only thing the media queries below need to touch. */

/* ── Layout shell ─────────────────────────────────────────── */

body {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  color: var(--card);
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* header, .brand and .hud come from common.css (shared chrome). */

/* American flag accent in header */
.flag-mark {
  display: flex;
  gap: 2px;
  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);
}

/* HUD readout — tabular Oswald figures, matching the card games */
.timer-display {
  font-family: var(--mono);
  font-size: 20px;
  font-weight: 500;
  color: var(--gold-bright);
  letter-spacing: 0.04em;
  min-width: 52px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ── Main play area ───────────────────────────────────────── */

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 12px 16px 20px;
  gap: 16px;
}

/* Leave room for the install banner so it never covers the controls */
body.install-visible main {
  padding-bottom: 84px;
}

/* ── Puzzle title ─────────────────────────────────────────── */

.puzzle-title {
  font-family: var(--serif);
  font-style: italic;
  font-size: 0.9rem;
  color: var(--gold-dim);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-align: center;
}

/* ── First-run hint ───────────────────────────────────────── */

.hint {
  font-family: var(--serif);
  font-style: italic;
  font-size: 0.95rem;
  color: rgba(245, 237, 224, 0.5);
  letter-spacing: 0.03em;
  text-align: center;
  transition: opacity 0.4s ease;
  min-height: 1.2rem;
}

.hint.fade {
  opacity: 0;
  pointer-events: none;
}

/* ── Columns wrapper ──────────────────────────────────────── */

#columns {
  --num-cols: 3;
  --cell-max: 68px;
  --cell-w: min(
    var(--cell-max),
    calc((100vw - 44px - (var(--num-cols) - 1) * var(--col-gap)) / var(--num-cols))
  );
  --cell-h: var(--cell-w);
  --reel-h: calc(var(--reel-visible) * (var(--cell-h) + var(--cell-gap)) - var(--cell-gap));
  display: flex;
  gap: var(--col-gap);
  align-items: center;
  justify-content: center;
  position: relative;
  user-select: none;
  touch-action: none;
}

/* Centre-row highlight strip behind all columns — the gold outline that
   marks the target row. Sits across the whole columns area so the
   accent reads as a horizontal band, not a per-column box. */
#columns::after {
  content: '';
  position: absolute;
  left: -6px;
  right: -6px;
  height: calc(var(--cell-h) + 4px);
  top: calc((var(--reel-h) - var(--cell-h)) / 2 - 2px);
  background: var(--gold-faint);
  border: 2.5px solid var(--gold);
  border-radius: 10px;
  pointer-events: none;
  z-index: 0;
}

/* Flash feedback — green pulse when a word scores */
#columns.flash-valid::after { background: rgba(56, 180, 100, 0.30); border-color: rgba(56,180,100,0.6); }

/* ── Column frame ─────────────────────────────────────────────
   Outer wrapper: kept above the centre-row strip and unaffected by the
   column's fade mask, so the active-column tint reads cleanly. */

.col-frame {
  flex-shrink: 0;
  position: relative;
  z-index: 1;
  border-radius: 14px;
  cursor: grab;
}

.col-frame:active { cursor: grabbing; }

/* Active column — kept as a faint warm wash for keyboard navigation. The
   prominent gold outline is the horizontal target-row strip; the column
   itself only needs the lightest hint. */
.col-frame.active-col {
  background: rgba(201, 169, 97, 0.06);
  border-radius: 14px;
}

/* ── Column ───────────────────────────────────────────────── */

.column {
  height: var(--reel-h);
  width: var(--cell-w);
  overflow: hidden;
  border-radius: 14px;
  position: relative;
  /* Fade top and bottom edges */
  -webkit-mask-image: linear-gradient(
    to bottom,
    transparent 0%,
    rgba(0,0,0,0.5) 12%,
    black 28%,
    black 72%,
    rgba(0,0,0,0.5) 88%,
    transparent 100%
  );
  mask-image: linear-gradient(
    to bottom,
    transparent 0%,
    rgba(0,0,0,0.5) 12%,
    black 28%,
    black 72%,
    rgba(0,0,0,0.5) 88%,
    transparent 100%
  );
}

/* ── Reel (smooth drag wrapper inside column) ─────────────── */

.reel {
  display: flex;
  flex-direction: column;
  gap: var(--cell-gap);
  will-change: transform;
}

/* ── Cell ─────────────────────────────────────────────────── */

.cell {
  height: var(--cell-h);
  width: var(--cell-w);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--sans);
  font-weight: 700;
  font-size: calc(var(--cell-h) * 0.42);
  border-radius: 10px;
  background: var(--bg-2);
  color: var(--card);
  border: 1.5px solid var(--gold-faint);
  transition: background 0.18s ease, color 0.18s ease;
  will-change: background;
}

/* Centre row — brighter, slightly larger */
.cell.centre {
  background: #343d6e;
  color: #fff;
  border-color: rgba(201, 169, 97, 0.5);
  font-size: calc(var(--cell-h) * 0.46);
}

/* Used letter — gold fill */
.cell.used {
  background: var(--gold);
  color: var(--bg-1);
  border-color: var(--gold-bright);
}

.cell.centre.used {
  background: var(--gold-bright);
  color: var(--bg-1);
}

/* ── Word feedback ────────────────────────────────────────── */

.word-feedback {
  font-family: var(--sans);
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  color: rgba(245, 237, 224, 0.4);
  text-transform: uppercase;
  min-height: 2.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s ease, font-size 0.2s ease, letter-spacing 0.2s ease;
  text-align: center;
}

/* Valid word — brighter, larger, more emphatic */
.word-feedback.valid {
  color: #7de08a;
  font-size: 1.6rem;
  letter-spacing: 0.25em;
}

/* Found word doubles as a dictionary.com link */
.word-feedback .word-link {
  color: inherit;
  text-decoration: underline;
  text-decoration-color: rgba(125, 224, 138, 0.45);
  text-decoration-thickness: 1.5px;
  text-underline-offset: 5px;
  cursor: pointer;
  transition: text-decoration-color 0.18s ease;
}

.word-feedback .word-link:hover,
.word-feedback .word-link:focus-visible {
  text-decoration-color: #7de08a;
  outline: none;
}

/* ── Progress bar ─────────────────────────────────────────── */

.progress-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 100%;
  max-width: 340px;
}

#progress {
  font-family: var(--sans);
  font-size: 0.82rem;
  opacity: 0.6;
  letter-spacing: 0.04em;
}

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

.controls {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

/* Buttons (.btn, .btn.confirming) come from common.css — shared pill +
   shared gold confirm pulse (BL-006). */

/* ── Difficulty selector ──────────────────────────────────── */

/* Five tiers, so this stays a wrap-friendly pill row rather than the shared
   .segmented track (inline-flex / no-wrap, which would overflow on phones).
   The pills are built from shared tokens; .diff-btn doubles as a JS hook. */
.difficulty-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  flex-shrink: 0;
}

.diff-btn {
  font-family: var(--sans);
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.02em;
  padding: 8px 18px;
  min-height: var(--control-sm);   /* ≥44px touch target (BL-021) */
  border: 1px solid var(--hairline);
  border-radius: var(--r-pill);
  background: var(--surface-2);
  color: var(--text-soft);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.diff-btn:hover,
.diff-btn:focus-visible { color: var(--gold-bright); border-color: var(--gold); outline: none; }

.diff-btn.active,
.diff-btn[aria-pressed="true"] {
  background: var(--gold);
  color: var(--bg-1);
  border-color: var(--gold-bright);
}

/* ── Win overlay ──────────────────────────────────────────── */

.win-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 25, 55, 0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;        /* removes the dialog buttons from the tab order */
  pointer-events: none;
  transition: opacity 0.3s ease, visibility 0s linear 0.3s;
  z-index: 100;
}

.win-overlay.visible {
  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: 36px 40px;
  text-align: center;
  max-width: 320px;
  width: 88%;
  max-height: 88vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 12px;
  position: relative;
  /* Panel itself never scrolls — the close (✕) and Next-Puzzle buttons
     must stay anchored. Only the word lists inside scroll on overflow. */
}

/* Title/time/best/button never compress — only .win-words gives. */
.win-panel > :not(.win-words) {
  flex-shrink: 0;
}

/* Dismiss ✕ — lets the player close the overlay and view the solved board */
.win-dismiss {
  position: absolute;
  top: 8px;
  right: 8px;
  background: none;
  border: none;
  color: rgba(245, 237, 224, 0.5);
  font-size: 1.1rem;
  cursor: pointer;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.win-dismiss:hover,
.win-dismiss:focus-visible {
  color: var(--card);
  outline: none;
}

.win-title {
  font-family: var(--serif);
  font-size: 2rem;
  font-style: italic;
  font-weight: 500;
  color: var(--gold-bright);
  margin: 0;
}

.win-puzzle {
  font-family: var(--serif);
  font-style: italic;
  font-size: 0.95rem;
  color: var(--gold-dim);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-top: -6px;
}

.win-time {
  font-family: var(--sans);
  font-size: 2.4rem;
  font-weight: 700;
  color: var(--card);
  letter-spacing: 0.04em;
}

.win-best {
  font-family: var(--sans);
  font-size: 0.9rem;
  opacity: 0.65;
  color: var(--gold);
  min-height: 1.2em;
}

/* Word lists in the win overlay — original targets (struck if missed) plus
   any extra valid words the player landed on. flex: 1 with min-height: 0
   lets this section shrink and scroll independently when the panel hits
   max-height, so the close (✕) and Next-Puzzle buttons stay anchored. */
.win-words {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 4px;
  text-align: center;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}

.win-words-label {
  font-family: var(--sans);
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--gold-dim);
  margin-bottom: 4px;
  opacity: 0.85;
}

.win-words-list {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px 8px;
}

.win-word {
  font-family: var(--sans);
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  color: rgba(245, 237, 224, 0.4);
  text-transform: uppercase;
  font-weight: 400;
}

.win-word.found {
  color: var(--gold-bright);
  font-weight: 700;
}

/* Abandon reveal — the words left unsolved are shown prominently (the point
   of the reveal), while the "You found" recap below stays dim (.win-word). */
.win-word.miss {
  color: var(--gold-bright);
  font-weight: 700;
}

.win-panel .btn {
  margin-top: 8px;
  align-self: center;
  padding: 12px 32px;
  font-size: 1rem;
}

/* ── Install banner ───────────────────────────────────────── */

/* 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) */

/* ── Responsive ───────────────────────────────────────────── */
/* Cell size is computed by the min() formula on #columns; the queries
   below only nudge --cell-max (ideal size) and the gaps. */

@media (max-width: 380px) {
  :root { --col-gap: 7px; }
}

@media (min-width: 600px) {
  #columns { --cell-max: 76px; }
}

/* Short viewports (landscape phones) — compact cells; the page scrolls
   as a fallback rather than clipping the reels. Must come after the
   min-width rule so landscape phones (wide AND short) get the small size. */
@media (max-height: 600px) {
  :root { --cell-gap: 3px; }
  #columns { --cell-max: 44px; }
  html, body {
    height: auto;
    overflow-y: auto;
  }
  body {
    min-height: 100dvh;
    overscroll-behavior-y: contain;
  }
  header { padding: 6px 16px 4px; }
  .brand .sub { display: none; }
  main {
    flex: 0 0 auto;
    justify-content: flex-start;
    gap: 8px;
    padding: 10px 16px 16px;
  }
  .puzzle-title, .hint { display: none; }
  .word-feedback { min-height: 1.8rem; font-size: 1rem; }
  .word-feedback.valid { font-size: 1.3rem; }
  .difficulty-bar { gap: 3px; }
  .diff-btn { min-height: 34px; padding: 5px 8px; font-size: 0.66rem; }
}

@media (prefers-reduced-motion: reduce) {
  .cell, .win-overlay, #columns::after,
  #columns.flash-valid::after {
    transition: none;
  }
}
