/* ============================================================
   Word Jumbles — game styles
   Design: dark navy shell, cream/gold letter tiles, gold accents.
   Layered on common.css (shared skin + design tokens).
   ============================================================ */

:root {
  --tile-gap: 7px;
  --tile-max: 62px;
  /* --num-tiles is set per game by word-jumbles.js (renderAll). The 5 here
     is a first-paint fallback; the real value lands before the first tile
     renders. */
  --num-tiles: 5;
  /* The row never wraps — compute the largest tile that fits the available
     horizontal space. The constraint is the answer tray (which has the
     most overhead): 60px ≈ 2*16 main padding + 2*12 tray padding + ~3px
     border. */
  --tile: min(
    var(--tile-max),
    calc((100vw - 60px - (var(--num-tiles) - 1) * var(--tile-gap)) / var(--num-tiles))
  );
}

/* ── Header ───────────────────────────────────────────────── */

header {
  /* layout, brand and .hud all come from common.css (shared chrome) */
  padding: 12px 16px 8px;
}

/* HUD readouts — tabular Oswald figures, matching the card games */
.streak {
  font-family: var(--sans);
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.04em;
  color: var(--text-soft);
  white-space: nowrap;
}

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

/* American flag accent — standing design requirement */
.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);
}

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

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 14px 16px 22px;
  gap: 14px;
  position: relative;
  z-index: 1;
}

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

.prompt {
  font-family: var(--serif);
  font-style: italic;
  font-size: 0.95rem;
  color: var(--gold-dim);
  letter-spacing: 0.05em;
  text-align: center;
  min-height: 1.2rem;
}

/* ── Answer tray ──────────────────────────────────────────── */

.answer {
  display: flex;
  flex-wrap: nowrap;
  justify-content: center;
  gap: var(--tile-gap);
  padding: 12px;
  border-radius: 14px;
  background: var(--slot-bg);
  border: 1.5px solid var(--slot-line);
  max-width: 100%;
}

/* ── Letter rack ──────────────────────────────────────────── */

.rack {
  display: flex;
  flex-wrap: nowrap;
  justify-content: center;
  gap: var(--tile-gap);
  min-height: var(--tile);
  max-width: 100%;
}

/* ── Tiles & slots ────────────────────────────────────────── */

/* A rack tile and a filled answer slot share the cream "wooden tile" look. */
.tile,
.slot {
  width: var(--tile);
  height: var(--tile);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--sans);
  font-weight: 700;
  font-size: calc(var(--tile) * 0.5);
  border-radius: 9px;
  cursor: pointer;
  padding: 0;
  position: relative;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.tile,
.slot.filled {
  background: linear-gradient(180deg, #faf3e6 0%, var(--card) 55%, var(--card-edge) 100%);
  color: var(--ink);
  border: 1px solid var(--card-edge);
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.6);
}

.tile:hover,
.slot.filled:hover {
  transform: translateY(-2px);
  box-shadow: 0 5px 10px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.6);
}

.tile:active,
.slot.filled:active { transform: translateY(0) scale(0.96); }

.tile:focus-visible,
.slot:focus-visible {
  outline: 2.5px solid var(--gold-bright);
  outline-offset: 2px;
}

/* Empty answer slot — a recessed dashed frame */
.slot.empty {
  background: rgba(0, 0, 0, 0.18);
  border: 2px dashed var(--slot-line);
  color: transparent;
  cursor: default;
  box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.3);
}

/* Hint-locked slot — gold tile, pinned; a small dot marks it fixed */
.slot.locked {
  background: linear-gradient(180deg, var(--gold-bright) 0%, var(--gold) 70%, var(--gold-dim) 100%);
  color: var(--bg-1);
  border: 1px solid var(--gold-bright);
  cursor: default;
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.4);
}
.slot.locked::after {
  content: '';
  position: absolute;
  top: 4px;
  right: 4px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--bg-1);
}

/* Disabled tiles/slots keep their look (no browser dimming) — except the
   rack once the round is won, which fades back. */
.tile:disabled,
.slot:disabled { opacity: 1; }
.tile:disabled { cursor: default; }
.rack .tile:disabled { opacity: 0.45; }

/* A placed tile leaves an inert, recessed placeholder in its rack column so the
   rack never rearranges until an explicit Shuffle (S16/BL-035). Matches the
   empty answer-slot frame. */
.rack .tile.placed {
  background: rgba(0, 0, 0, 0.18);
  border: 2px dashed var(--slot-line);
  color: transparent;
  cursor: default;
  box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.3);
  opacity: 1;
}
.rack .tile.placed:hover { transform: none; box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.3); }

/* ── Feedback line ────────────────────────────────────────── */

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

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

.controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  flex-shrink: 0;
}

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

/* ── Difficulty selector ──────────────────────────────────── */
/* The picker is the shared .segmented control (common.css); the buttons keep
   their .diff-btn class purely as a JS hook. Three tiers fit the segmented
   track comfortably; main centres it. */

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

.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 panel (which
     now also lists the other words) stays fully reachable. The panel centres
     via margin:auto when there's room. */
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 24px 16px;
  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: 38px 40px 32px;
  text-align: center;
  max-width: 320px;
  width: 88%;
  margin: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  position: relative;
  overflow: hidden;
}

/* American-flag motif — a slim stars-and-stripes accent across the top */
.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-dismiss {
  position: absolute;
  top: 6px;
  right: 6px;
  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-word {
  font-family: var(--sans);
  font-weight: 700;
  font-size: 1.5rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--card);
  padding-left: 0.22em;   /* compensate for the trailing letter-spacing so the word centres optically */
}

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

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

/* Other valid words these letters spell, revealed on a win. */
.win-missed:empty { display: none; }
.win-missed-head {
  font-family: var(--sans);
  font-size: 0.78rem;
  color: rgba(245, 237, 224, 0.7);
  margin-top: 4px;
}
.win-missed-list {
  list-style: none;
  margin: 6px 0 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 5px;
  max-height: 34vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.win-missed-list li {
  font-family: var(--sans);
  font-size: 0.8rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 3px 8px;
  border-radius: 5px;
  background: rgba(245, 237, 224, 0.08);
  color: var(--card);
}

.win-panel .btn {
  margin-top: 10px;
  align-self: center;
  padding: 12px 30px;
  font-size: 0.95rem;
}

/* ── Install banner (ADR-003) ─────────────────────────────── */

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

@media (max-width: 360px) {
  :root { --tile-gap: 5px; }
  .brand .sub { display: none; }
}

@media (min-width: 640px) {
  :root { --tile-max: 64px; }
}

/* Short viewports (landscape phones) — clamp by height as well */
@media (max-height: 540px) {
  :root { --tile-max: clamp(38px, 9vh, 52px); }
  html, body { height: auto; overflow-y: auto; }
  body { min-height: 100dvh; overscroll-behavior-y: contain; }
  main { flex: 0 0 auto; justify-content: flex-start; gap: 10px; }
  .brand .sub { display: none; }
  .prompt { display: none; }
}

/* ── Reduced motion ───────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  .tile, .slot, .win-overlay { transition: none; }
  .tile:hover, .slot.filled:hover { transform: none; }
}
