/* ============================================================================
   Crossword — focused clubhouse play screen (gamesy). Wraps the "In Other
   Words" board engine; the .th-* class names / #th* IDs are engine hooks and
   must stay. The sp-* shell mirrors the Sudoku play screen so the two games
   feel like siblings. Mode accent is injected via --c on .sp-page.
   ============================================================================ */

.sp-page { max-width: 1040px; margin: 0 auto; color: #2b2620;
  font-family: Georgia, 'Times New Roman', serif; }

/* ── Header ─────────────────────────────────────────────────────────────── */
.sp-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.sp-back { font-family: system-ui, sans-serif; font-weight: 700; font-size: 16px; letter-spacing: 1px; color: var(--c, #1f4a33); text-decoration: none; }
.sp-back:hover { filter: brightness(1.12); }
.sp-header-actions { display: flex; gap: 10px; }
.sp-iconbtn { width: 38px; height: 38px; border-radius: 10px; border: 1px solid #d8cdb2; background: #fffdf7; color: #4a443b; font-size: 15px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; box-shadow: 0 1px 2px rgba(60,50,30,.06); transition: background .12s; }
.sp-iconbtn:hover:not(:disabled) { background: #f3ecd9; }
.sp-iconbtn:disabled { opacity: .5; cursor: default; }

/* Header dropdown (Menu) */
.sp-dd { position: relative; }
.sp-dd-panel { position: absolute; top: calc(100% + 6px); right: 0; min-width: 210px; background: #fffdf7; border: 1px solid #e6ddc6; border-radius: 10px; box-shadow: 0 8px 24px rgba(40,30,15,.18); padding: 8px; z-index: 30; display: none; }
.sp-dd.open .sp-dd-panel { display: block; }
.sp-dd-item { display: flex; align-items: center; width: 100%; padding: 10px; background: none; border: 0; border-radius: 7px; font-family: system-ui, sans-serif; font-size: 14px; color: #2b2620; cursor: pointer; text-decoration: none; text-align: left; }
.sp-dd-item:hover { background: #f3ecd9; }

/* ── Stat bar ───────────────────────────────────────────────────────────── */
.sp-statbar { display: flex; align-items: center; background: linear-gradient(180deg, #fffdf8, #faf4e6); border: 1px solid #e0d4b6; border-radius: 12px; padding: 14px 18px; margin-bottom: 18px; box-shadow: inset 0 1px 0 #fff, 0 1px 2px rgba(60,50,30,.07); }
.sp-badge { font-family: system-ui, sans-serif; font-weight: 700; font-size: 12px; letter-spacing: 1px; color: #fff; padding: 7px 16px; border-radius: 8px; background: linear-gradient(180deg, color-mix(in srgb, var(--c, #4e7d3a), #fff 16%), var(--c, #4e7d3a)); margin-right: 16px; box-shadow: 0 2px 5px rgba(60,50,30,.18), inset 0 1px 0 rgba(255,255,255,.25); white-space: nowrap; }
.sp-stat { flex: 1; text-align: center; border-left: 1px solid #ece3cb; padding: 0 10px; }
.sp-stat-l { font-family: system-ui, sans-serif; font-size: 11px; letter-spacing: .6px; text-transform: uppercase; color: #7a7468; }
.sp-stat-v { font-family: Georgia, serif; font-size: 24px; font-weight: 700; color: #2b2620; margin-top: 2px; }
.sp-share { margin-left: 16px; font-family: system-ui, sans-serif; font-weight: 700; font-size: 12.5px; padding: 9px 16px; border-radius: 9px; border: 1px solid var(--c, #2f6e42); background: var(--c, #2f6e42); color: #fff; cursor: pointer; }
.sp-share:hover { filter: brightness(1.08); }

/* ── Play area ──────────────────────────────────────────────────────────── */
.th-play { position: relative; }
.th-play-board { display: grid; grid-template-columns: 1fr; gap: 26px; align-items: start; }
@media (min-width: 900px) {
  .th-play-board { grid-template-columns: clamp(300px, 44vw, 480px) 1fr; }
}
.th-play-left { position: relative; min-width: 0; }

/* Velvet gold-edged board frame — the clubhouse premium treatment. */
.th-grid-frame { padding: 12px; border-radius: 18px; background: linear-gradient(160deg, #3d342a, #241e16); box-shadow: 0 12px 28px rgba(40,30,15,.32), inset 0 0 0 1.5px #b08a35; }

/* Current-clue banner above the grid */
.th-current-clue { display: flex; align-items: baseline; gap: 12px; padding: 12px 16px; margin-bottom: 12px; min-height: 46px; background: linear-gradient(180deg, #fffdf8, #faf4e6); border: 1px solid #e0d4b6; border-radius: 10px; box-shadow: inset 0 1px 0 #fff, 0 1px 2px rgba(60,50,30,.07); }
.th-current-clue .num { font-family: system-ui, sans-serif; font-weight: 700; font-size: 14px; color: var(--c, #4e7d3a); flex: 0 0 auto; }
.th-current-clue .text { font-family: Georgia, serif; font-size: 17px; color: #2b2620; line-height: 1.3; }

/* Grid */
/* container-type lets cell type size off the GRID's real width (cqw), so a
   13×13 maxi gets proportionally smaller letters than a 7×7 mini — vw-based
   sizing gave both the same font and maxi letters overflowed their cells. */
.th-play-grid { display: grid; gap: 0; background: #2b2620; border: 0; border-radius: 9px; overflow: hidden; aspect-ratio: 1 / 1; width: 100%; user-select: none; container-type: inline-size; }
.th-play-cell { position: relative; background: #fffdf9; border: 1px solid #d4cab0; display: flex; align-items: center; justify-content: center; aspect-ratio: 1 / 1; overflow: hidden; font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-size: clamp(11px, calc(100cqw / var(--n, 7) * .52), 26px); line-height: 1; font-weight: 600; text-transform: uppercase; color: #2b2620; cursor: pointer; min-width: 0; min-height: 0; transition: background .08s; }
.th-play-cell .ltr { line-height: 1; display: block; }
.th-play-cell.is-black { background: #2b2620; cursor: default; }
.th-play-cell.is-in-word { background: #fdf1c8; }
.th-play-cell.is-selected { background: #ffe39a; box-shadow: inset 0 0 0 2px var(--c, #2f6e42); }
.th-play-cell.is-correct .ltr { color: #2f7a4a; }
.th-play-cell.is-wrong   .ltr { color: #b3261e; }
/* A hint-revealed square (blue "given" letter), distinct from solved (green). */
.th-play-cell.is-revealed { background: #dfeaf6; }
.th-play-cell.is-revealed .ltr { color: #2f6e9e; }
.th-play-cell.is-revealed.is-selected { box-shadow: inset 0 0 0 2px #2f6e9e; }
.th-play-cell .num { position: absolute; top: 2px; left: 3px; font-family: system-ui, sans-serif; font-size: clamp(6px, calc(100cqw / var(--n, 7) * .2), 10px); font-weight: 600; color: #8a8270; }

/* Solved entries lock to a soft green and can't be edited. */
.th-play-cell.is-locked { background: #d4ecd6; cursor: default; }
.th-play-cell.is-locked .ltr { color: #2f7a4a; }
.th-play-cell.is-locked.is-selected { box-shadow: inset 0 0 0 2px #2f7a4a; }
@keyframes th-solved-flash {
  0%   { background: #fff; transform: scale(1); }
  40%  { background: #ffd771; transform: scale(1.08); }
  100% { background: #d4ecd6; transform: scale(1); }
}
.th-play-cell.is-just-solved { animation: th-solved-flash .55s ease-out; }

/* Study mode after a reveal: words the solver missed are filled in red so the
   found words (green, .is-locked) stand out against what they didn't get. */
.th-play-cell.is-revealed-miss { background: #f7dad4; cursor: default; }
.th-play-cell.is-revealed-miss .ltr { color: #b3261e; }

@keyframes th-victory-wiggle {
  0%, 100% { transform: rotate(0); }
  25% { transform: rotate(-.6deg); }
  75% { transform: rotate(.6deg); }
}
.th-play-grid.is-finished { animation: th-victory-wiggle .5s ease-in-out 2; }

/* Pause — blur the grid + clues, show an overlay. */
.th-play.is-paused .th-play-grid,
.th-play.is-paused .th-clue-columns { filter: blur(6px); pointer-events: none; user-select: none; }
.th-paused-overlay { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; background: rgba(244,238,221,.7); z-index: 5; border-radius: 8px; font-family: Georgia, serif; font-size: 34px; color: var(--c, #355e3b); }
.th-play.is-paused .th-paused-overlay { display: flex; }

/* ── Clue columns ───────────────────────────────────────────────────────── */
.th-solved-toast { min-height: 0; margin-bottom: 12px; padding: 0 16px; max-height: 0; overflow: hidden; background: #2b2620; color: #fff; font-family: system-ui, sans-serif; text-transform: uppercase; letter-spacing: .12em; font-size: 12px; font-weight: 700; text-align: center; border-radius: 8px; opacity: 0; transform: translateY(-4px); transition: opacity .22s, transform .22s, max-height .22s, padding .22s; pointer-events: none; }
.th-solved-toast.show { opacity: 1; transform: translateY(0); max-height: 60px; padding: 10px 16px; margin-bottom: 12px; }
.th-solved-toast b { color: #ffd771; }

.th-clue-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; align-items: start; }
@media (max-width: 480px) { .th-clue-columns { grid-template-columns: 1fr; gap: 4px; } }
.th-clue-columns h3 { font-family: Georgia, serif; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; font-size: 15px; margin: 0 0 6px; color: #2b2620; }
.th-clue-list { list-style: none; padding: 0; margin: 0 0 18px; border-top: 2px solid #e6ddc6; }
.th-clue { display: grid; grid-template-columns: 22px 1fr auto; gap: 9px; align-items: baseline; padding: 8px 4px; border-bottom: 1px solid #efe7d3; cursor: pointer; border-radius: 5px; }
.th-clue:hover { background: #f6efdb; }
.th-clue.is-active { background: #ffe39a; }
.th-clue.is-done { pointer-events: none; background: transparent; }
.th-clue.is-done .text, .th-clue.is-done .n, .th-clue.is-done .len { color: #a79f8c; text-decoration: line-through; text-decoration-color: #c2b9a2; }
/* A clue the solver missed (revealed) — struck in red, not muted grey. */
.th-clue.is-missed .text, .th-clue.is-missed .n, .th-clue.is-missed .len { color: #b3261e; text-decoration-color: #db9a92; }
.th-clue .n { font-family: system-ui, sans-serif; font-weight: 700; font-size: 13px; color: var(--c, #4e7d3a); text-align: right; }
.th-clue .text { font-family: Georgia, serif; font-size: 14.5px; color: #2b2620; line-height: 1.35; }
.th-clue .len { font-family: system-ui, sans-serif; font-size: 11px; color: #9a9182; }

/* Toolbar under the clues */
.th-toolbar { display: flex; gap: 10px; flex-wrap: wrap; margin: 6px 0 6px; }
.th-btn { appearance: none; padding: 10px 16px; background: linear-gradient(180deg, #fffdf7, #f3ecd8); color: #4a443b; border: 1px solid #ddd0b0; border-radius: 10px; font-family: system-ui, sans-serif; text-transform: uppercase; letter-spacing: .04em; font-size: 12px; font-weight: 700; cursor: pointer; box-shadow: inset 0 1px 0 #fff, 0 1px 2px rgba(60,50,30,.1); transition: background .12s, color .12s; }
.th-btn:hover { background: linear-gradient(180deg, #fbf3df, #efe6cf); }
.th-btn.is-primary { background: var(--c, #2f6e42); border-color: var(--c, #2f6e42); color: #fff; }
.th-btn.is-primary:hover { filter: brightness(1.08); }
.th-btn:disabled { opacity: .5; cursor: not-allowed; }
.th-btn:disabled:hover { background: linear-gradient(180deg, #fffdf7, #f3ecd8); }

.th-feedback { margin-top: 10px; padding: 9px 13px; background: #fdf6e6; border: 1px solid #e6d3a6; border-radius: 8px; font-family: Georgia, serif; font-size: 14px; color: #4a443b; display: none; }
.th-feedback.show { display: block; }
.th-feedback.win { background: #eff6ec; border-color: #bcd6b2; color: #2f7a4a; }

/* Invisible, but it must stay a real focusable input: phones only raise the
   on-screen keyboard for something with actual dimensions, and 16px type stops
   iOS zooming the page when it takes focus. Fixed so focusing never scrolls. */
.th-shadow-input { position: fixed; top: 50%; left: 0; width: 1px; height: 1px; margin: 0; padding: 0; border: 0; opacity: 0; background: transparent; font-size: 16px; pointer-events: none; z-index: -1; }

/* ── Completion celebration ─────────────────────────────────────────────── */
.th-confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 9999; }
.th-confetti span { position: absolute; top: -10px; width: 8px; height: 14px; opacity: .9; animation: th-fall 2.6s linear forwards; }
@keyframes th-fall { to { transform: translateY(110vh) rotate(720deg); opacity: 0; } }

.th-done-modal { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(27,20,8,.55); z-index: 10000; padding: 16px; }
.th-done-modal.hidden { display: none; }
.th-done-modal__card { position: relative; background: #fffdf7; border: 1px solid #e6ddc6; border-radius: 16px; box-shadow: 0 20px 50px rgba(0,0,0,.4); padding: 32px 36px 26px; max-width: 460px; width: 100%; text-align: center; animation: th-pop .32s cubic-bezier(.2,.9,.3,1.18); }
@keyframes th-pop { 0% { transform: scale(.8); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
.th-done-modal__title { font-family: 'Alfa Slab One', Georgia, serif; font-weight: 400; font-size: 34px; letter-spacing: .5px; line-height: 1.1; margin: 0 0 8px; color: #2f6e42; }
.th-done-modal__sub { font-family: system-ui, sans-serif; text-transform: uppercase; letter-spacing: .12em; font-size: 11px; color: #7a7468; margin: 0 0 18px; }
.th-done-modal__stats { display: grid; grid-template-columns: repeat(3, 1fr); border-top: 1px solid #e6ddc6; border-bottom: 1px solid #e6ddc6; padding: 14px 0; margin-bottom: 18px; }
.th-done-modal__stat { padding: 0 8px; border-right: 1px solid #e6ddc6; }
.th-done-modal__stat:last-child { border-right: none; }
.th-done-modal__stat b { display: block; font-family: Georgia, serif; font-weight: 700; font-size: 24px; line-height: 1; color: #2b2620; margin-bottom: 4px; }
.th-done-modal__stat .lbl { font-family: system-ui, sans-serif; text-transform: uppercase; letter-spacing: .08em; font-size: 9.5px; color: #7a7468; }
.th-done-modal__notes { font-family: Georgia, serif; font-size: 15px; color: #2b2620; line-height: 1.45; margin: 0 0 18px; }
.th-done-modal__notes b { color: #2f6e42; }
.th-done-modal__actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.th-done-modal__actions .th-bar-btn { font-family: system-ui, sans-serif; text-transform: uppercase; letter-spacing: .04em; font-size: 12px; font-weight: 700; padding: 10px 16px; background: #fffdf7; border: 1px solid #2f6e42; border-radius: 9px; color: #2f6e42; text-decoration: none; cursor: pointer; }
.th-done-modal__actions .th-bar-btn.is-primary { background: #2f6e42; border-color: #2f6e42; color: #fff; }
.th-done-modal__actions .th-bar-btn:hover { filter: brightness(1.06); }
.th-done-sound-btn { position: absolute; top: 12px; right: 14px; background: transparent; border: none; cursor: pointer; font-size: 18px; line-height: 1; opacity: .6; }
.th-done-sound-btn:hover { opacity: 1; }

/* ── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 560px) {
  .sp-statbar { flex-wrap: wrap; gap: 8px 0; }
  .sp-badge { margin-bottom: 4px; }
  .th-grid-frame { padding: 9px; border-radius: 14px; }
}

/* ── Responsive doctrine (matches Word Cube): portrait ALWAYS stacks,
      side-by-side is reserved for wider-than-tall; the board sizes by width
      but is height-capped everywhere — with a max() floor so the calc can
      never go negative and collapse the frame. Last in file on purpose. ──── */
@media (min-width: 900px) {
  .th-grid-frame { max-width: min(480px, max(260px, calc(100vh - 340px))); }
}
@media (min-width: 1400px) {
  .sp-page { max-width: 1280px; }
  .th-play-board { grid-template-columns: clamp(340px, 42vw, 640px) 1fr; gap: 30px; }
  .th-grid-frame { max-width: min(640px, max(260px, calc(100vh - 330px))); }
}
@media (orientation: portrait) {
  .th-play-board { grid-template-columns: 1fr; }
  .th-grid-frame { max-width: min(640px, max(280px, calc(100vh - 480px))); margin: 0 auto; }
  .th-current-clue { max-width: min(640px, max(280px, calc(100vh - 480px))); margin: 0 auto 12px; }
}

/* ── Landscape phones (short + wide): same treatment as Word Cube — the
      clubhouse bar hides (this page has its own back link + menu), chrome
      trims, the board sizes from HEIGHT, and the clue lists scroll in place. */
@media (max-height: 520px) and (min-aspect-ratio: 3/2) {
  .ch-mobilebar { display: none; }
  .ch-main { padding-top: 0; }
  .ch-content { padding: 6px 12px 8px; }
  .sp-header { margin-bottom: 6px; }
  .sp-iconbtn { width: 32px; height: 32px; }
  .sp-statbar { padding: 5px 12px; margin-bottom: 8px; }
  .sp-stat-v { font-size: 16px; margin-top: 0; }
  .th-play-board { grid-template-columns: auto minmax(0, 1fr); gap: 14px; }
  .th-current-clue { padding: 6px 12px; min-height: 32px; margin-bottom: 8px; }
  .th-current-clue .text { font-size: 14px; }
  .th-grid-frame { max-width: none; width: calc(100vh - 172px); padding: 8px; }
  .th-clue-columns { max-height: calc(100vh - 205px); overflow-y: auto; scrollbar-width: thin; scrollbar-color: #cfc3a4 #f3ecd9; gap: 12px; }
  .th-toolbar { margin-top: 8px; }
}

/* ── Narrow phones: compact the stat bar so all four cells hold one line ── */
@media (max-width: 480px) {
  .sp-statbar { padding: 8px 10px; }
  .sp-badge { font-size: 10px; padding: 5px 10px; margin-right: 8px; letter-spacing: .6px; }
  .sp-stat { padding: 0 6px; }
  .sp-stat-l { font-size: 9.5px; letter-spacing: .4px; }
  .sp-stat-v { font-size: 17px; margin-top: 1px; }
}

/* ── Reduced motion ─────────────────────────────────────────────────────────
   Solving still celebrates — it just arrives without the confetti fall, the
   modal pop and the cell wiggle. Nothing here is waited on by the JS. */
@media (prefers-reduced-motion: reduce) {
  .th-confetti { display: none; }
  .th-done-modal__card,
  .th-play-cell.is-just-solved,
  .th-play-grid.is-finished { animation: none; }
  .th-solved-toast { transition: opacity .01ms; }
}
