/* ============================================================
   PUZZLE TRAINER — SHARED LAYER (puzzle-trainer.css)
   Three-layer architecture (MODX-embeddable):

     1. SHELL — index.html / index.php: page markup + asset
        includes + the standalone site chrome (header/nav).
     2. SHARED LAYER (this file + puzzle-trainer.js): Adult /
        common trainer styling and behavior.
     3. KIDS LAYER — kids-mode.css + kids-mode.js: Kids Mode
        only. Loaded AFTER this file; it overrides the shared
        layer through specificity and order (normal cascade —
        no duplicated rules, no !important).

   Scoping contract (PGN Viewer regression rule):
     · EVERY rule in this file is scoped under the unique root
       class .tcw-puzzle-trainer — nothing leaks into the host
       theme, and the host theme cannot easily override the app.
     · Design tokens live on .tcw-puzzle-trainer (NOT :root).
     · No body / html / bare button / img / svg / heading
       selectors anywhere in this file.
     · Specificity is kept low and predictable (root class +
       one component class), so the Kids layer can override by
       adding one more class.

   Layer map (original inline order preserved):
     L0 · Foundation   — design tokens + board theme variants
     L1 · Base         — box-sizing + focus ring
     L3 · Shared chess UI primitives — board, squares, pieces,
        buttons, panels, modal, toast
     L4 · Puzzle Trainer app — layout, status row, controls,
        side panel, promo picker, self-test, responsive
   (L2 site chrome and the PAGE SHELL document rules stayed in
   the standalone shell — index.html / index.php.)
   ============================================================ */

/* ============================================================
   L0 · FOUNDATION — DESIGN TOKENS (scoped under .tcw-puzzle-trainer)
   Shared palette / spacing / board colors. Every chess app (PGN
   Viewer, Play vs Computer, Puzzle Trainer, Course Trainer) consumes
   these — keep component CSS token-based so one token change re-skins
   all apps.
   ============================================================ */
.tcw-puzzle-trainer{
  --ink:#12161c;
  --ink-2:#3d4753;
  --ink-3:#6b7683;
  --line:#e3e7ec;
  --line-2:#eef1f4;
  --bg:#ffffff;
  --panel:#ffffff;
  --soft:#f7f9fa;
  --green:#1f9d55;
  --green-dark:#178048;
  --green-soft:#eaf7ef;
  --amber:#e08a1e;
  --amber-soft:#fdf3e7;
  --red:#d64545;
  --red-soft:#fdeded;
  --blue:#2f6fd6;
  --blue-soft:#eaf1fd;
  --purple:#7b4bd6;
  --radius:12px;
  --shadow:0 1px 2px rgba(16,24,40,.05);
  --sq-light:#f3e0c1;
  --sq-dark:#c8a069;
  --sq-hl:rgba(31,157,85,.45);
  --sq-last:rgba(240,197,60,.55);
  --sq-check:rgba(214,69,69,.65);
  --sq-hint:rgba(59,130,246,.45);
  --font:"Inter",-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
}

.tcw-puzzle-trainer[data-board="green"]{ --sq-light:#eeeed2; --sq-dark:#769656; }

.tcw-puzzle-trainer[data-board="blue"]{ --sq-light:#dee3e6; --sq-dark:#8ca2ad; }

.tcw-puzzle-trainer[data-board="slate"]{ --sq-light:#e8e8e8; --sq-dark:#9a9a9a; }


/* ============================================================
   L1 · BASE (component) — scoped under .tcw-puzzle-trainer.
   The viewer's own box-sizing, typography, colors and focus ring.
   Self-contained: does not touch the host document's html/body
   (those live in the PAGE SHELL block above).
   ============================================================ */
.tcw-puzzle-trainer *{box-sizing:border-box}

.tcw-puzzle-trainer{
  color-scheme:light;
  color:var(--ink);
  background:var(--bg);
  font-family:var(--font);
  -webkit-font-smoothing:antialiased;
  line-height:1.45;
}

.tcw-puzzle-trainer :focus-visible{outline:3px solid #7fb8ff;outline-offset:2px}


/* ============================================================
   L3 · SHARED CHESS UI PRIMITIVES — scoped under .tcw-puzzle-trainer,
        reusable by Play vs Computer, Puzzle Trainer, and Course
        Trainer:
          .board .sq .piece    .btn .icon-sq-btn .icon-btn .chevron-btn
          .panel .panel-head .panel-body
          .tabs .tab-btn .tab-panel
          .overlay .modal .field    .theme-popover .theme-swatch
          .toast    .games-empty / .gi-empty (shared empty-state pattern)
   ============================================================ */

.tcw-puzzle-trainer .board{
  display:grid;
  grid-template-columns:repeat(8,1fr);
  grid-template-rows:repeat(8,1fr);
  aspect-ratio:1/1;width:100%;
  border-radius:6px;overflow:hidden;
  touch-action:none;user-select:none;-webkit-user-select:none;
}

.tcw-puzzle-trainer .sq{position:relative;min-width:0;min-height:0;touch-action:none}

/* MOBILE ZOOM GUARD: the trainer must behave like an app — taps, drags
   and double-taps must never zoom the page. iOS Safari ignores
   user-scalable=no (accessibility override), so these touch-action
   rules + the JS double-tap guard in the app module are the real
   defense.
   · The board grid already carries touch-action:none (JS owns every
     gesture, so piece drags keep working in all directions); the board
     WRAPS join it so the card padding / coordinate gaps can't zoom.
     (The ADULT .board-card is NOT set to none — it also contains the
     status/session/action rows, which must keep normal page scrolling.)
   · Controls: manipulation = keep pan (page scroll + chip-row scroll),
     drop double-tap zoom. Desktop mouse/keyboard are unaffected. */
.tcw-puzzle-trainer #boardWrap,
.tcw-puzzle-trainer #kidsBoardWrap,
.tcw-puzzle-trainer .pt-kids-boardcard,
.tcw-puzzle-trainer .pt-kids-boardwrap{touch-action:none}
.tcw-puzzle-trainer button,
.tcw-puzzle-trainer .dd,
.tcw-puzzle-trainer .pt-kids-levels{touch-action:manipulation}

.tcw-puzzle-trainer .sq.light{background-color:var(--sq-light)}

.tcw-puzzle-trainer .sq.dark{background-color:var(--sq-dark)}

.tcw-puzzle-trainer .sq.last{background-image:linear-gradient(var(--sq-last),var(--sq-last))}

.tcw-puzzle-trainer .sq.check{background-image:radial-gradient(circle,var(--sq-check) 22%,transparent 72%)}

.tcw-puzzle-trainer .sq[data-file]::before, .tcw-puzzle-trainer .sq[data-rank]::after{
  position:absolute;font-size:var(--co,11px);font-weight:700;line-height:1;
  pointer-events:none;z-index:5;
}

.tcw-puzzle-trainer .sq[data-file]::before{content:attr(data-file);right:6%;bottom:4%}

.tcw-puzzle-trainer .sq[data-rank]::after{content:attr(data-rank);left:6%;top:4%}

.tcw-puzzle-trainer .sq.light::before, .tcw-puzzle-trainer .sq.light::after{color:var(--sq-dark);filter:brightness(.75)}

.tcw-puzzle-trainer .sq.dark::before, .tcw-puzzle-trainer .sq.dark::after{color:var(--sq-light)}

.tcw-puzzle-trainer .piece{position:absolute;inset:0;z-index:4;pointer-events:none}

.tcw-puzzle-trainer .piece svg{width:100%;height:100%;display:block}

/* Fallback shown when chess.js can't load. */
.tcw-puzzle-trainer .board-error{grid-column:1/-1;grid-row:1/-1;display:flex;align-items:center;justify-content:center;padding:24px;text-align:center;color:var(--ink-3);font-size:14px;line-height:1.5}


.tcw-puzzle-trainer .icon-sq-btn{
  width:44px;height:44px;display:flex;align-items:center;justify-content:center;
  border:1px solid var(--line);border-radius:10px;background:var(--panel);color:var(--ink-2);
  cursor:pointer;transition:background .15s ease;position:relative;
}

.tcw-puzzle-trainer .icon-sq-btn:hover{background:var(--soft)}

.tcw-puzzle-trainer .icon-sq-btn svg{width:19px;height:19px}

.tcw-puzzle-trainer .btn{
  display:inline-flex;align-items:center;justify-content:center;gap:8px;
  padding:12px 14px;border-radius:10px;border:1px solid var(--line);
  background:var(--panel);color:var(--ink);font-family:inherit;font-size:14px;font-weight:600;
  cursor:pointer;transition:background .15s ease,border-color .15s ease;white-space:nowrap;
}

.tcw-puzzle-trainer .btn:hover{background:var(--soft)}

.tcw-puzzle-trainer .btn:disabled{opacity:.45;cursor:not-allowed}

/* Button icons — local SVG masks tinted with the button's currentColor
   (so white icons on the green primary button, dark on the rest). */
.tcw-puzzle-trainer .btn .btn-ico,
.tcw-puzzle-trainer .pt-kids-btn .btn-ico{
  display:inline-block;flex:none;width:17px;height:17px;
  background-color:currentColor;
  -webkit-mask:center/contain no-repeat;
  mask:center/contain no-repeat;
}
.tcw-puzzle-trainer .btn .btn-ico-hint,.tcw-puzzle-trainer .pt-kids-btn .btn-ico-hint{-webkit-mask-image:url('assets/icons/hint.svg');mask-image:url('assets/icons/hint.svg')}
.tcw-puzzle-trainer .btn .btn-ico-show{-webkit-mask-image:url('assets/icons/show.svg');mask-image:url('assets/icons/show.svg')}
.tcw-puzzle-trainer .btn .btn-ico-restart{-webkit-mask-image:url('assets/icons/restart.svg');mask-image:url('assets/icons/restart.svg')}
.tcw-puzzle-trainer .btn .btn-ico-flip{-webkit-mask-image:url('assets/icons/flip.svg');mask-image:url('assets/icons/flip.svg')}
.tcw-puzzle-trainer .btn .btn-ico-next,.tcw-puzzle-trainer .pt-kids-btn .btn-ico-next{-webkit-mask-image:url('assets/icons/next.svg');mask-image:url('assets/icons/next.svg')}

.tcw-puzzle-trainer .btn-note{font-weight:600;opacity:.85}

.tcw-puzzle-trainer .btn-grow{flex:1 1 80px}

.tcw-puzzle-trainer .btn-primary{background:var(--green);border-color:var(--green);color:#fff}

.tcw-puzzle-trainer .btn-primary:hover{background:var(--green-dark)}

.tcw-puzzle-trainer .btn-warn{color:var(--red);border-color:#f2c9c9}

.tcw-puzzle-trainer .btn-warn:hover{background:#fdf2f2;border-color:var(--red)}

.tcw-puzzle-trainer .panel{border:1px solid var(--line);border-radius:var(--radius);background:var(--panel);box-shadow:var(--shadow)}

.tcw-puzzle-trainer .panel-head{
  display:flex;align-items:center;justify-content:space-between;gap:10px;
  padding:12px 14px;border-bottom:1px solid var(--line-2);
}

.tcw-puzzle-trainer .panel-head-left{display:flex;align-items:center;gap:8px;min-width:0}

.tcw-puzzle-trainer .panel-head h2{margin:0;font-size:13px;font-weight:800;white-space:nowrap}

.tcw-puzzle-trainer .panel-head-actions{display:flex;align-items:center;gap:6px}

.tcw-puzzle-trainer .icon-btn{background:none;border:0;cursor:pointer;color:var(--ink-3);padding:4px;line-height:0;border-radius:6px}

.tcw-puzzle-trainer .icon-btn:hover{color:var(--green-dark);background:var(--soft)}

.tcw-puzzle-trainer .icon-btn svg{width:18px;height:18px}

.tcw-puzzle-trainer .chevron-btn{background:none;border:0;cursor:pointer;color:var(--ink-2);padding:2px;line-height:0;display:flex}

.tcw-puzzle-trainer .chevron-btn svg{width:18px;height:18px;transition:transform .15s ease}

.tcw-puzzle-trainer .panel.collapsed .chevron-btn svg{transform:rotate(-90deg)}

.tcw-puzzle-trainer .panel-body{padding:10px 12px}

.tcw-puzzle-trainer .panel-body--flush{padding:0}

.tcw-puzzle-trainer .panel.collapsed .panel-body, .tcw-puzzle-trainer .panel.collapsed .panel-search-row{display:none}

.tcw-puzzle-trainer .games-empty, .tcw-puzzle-trainer .gi-empty{text-align:center;color:var(--ink-3);font-size:13.5px}

/* ---------- Notation tabs ---------- */
.tcw-puzzle-trainer .tabs{display:flex;border-bottom:1px solid var(--line-2)}

.tcw-puzzle-trainer .tab-btn{
  flex:1;padding:11px 8px;border:0;background:none;font-family:inherit;font-size:13px;font-weight:700;
  color:var(--ink-3);cursor:pointer;border-bottom:2px solid transparent;
}

.tcw-puzzle-trainer .tab-btn:hover{color:var(--ink)}

.tcw-puzzle-trainer .tab-btn.active{color:var(--green-dark);border-bottom-color:var(--green)}

.tcw-puzzle-trainer .tab-panel{display:none}

.tcw-puzzle-trainer .tab-panel.active{display:block}

/* ---------- Modal (paste PGN) ---------- */
.tcw-puzzle-trainer .overlay{
  position:fixed;inset:0;background:rgba(16,22,28,.5);
  display:none;align-items:center;justify-content:center;padding:20px;z-index:1000;
}

.tcw-puzzle-trainer .overlay.open{display:flex}

.tcw-puzzle-trainer .modal{
  background:#fff;border-radius:16px;width:100%;max-width:520px;
  box-shadow:0 20px 50px rgba(16,24,40,.25);max-height:90vh;overflow:auto;
}

.tcw-puzzle-trainer .modal h3{margin:0;font-size:17px;font-weight:700}

.tcw-puzzle-trainer .modal-head{display:flex;align-items:center;justify-content:space-between;padding:18px 20px;border-bottom:1px solid var(--line-2)}

.tcw-puzzle-trainer .modal-body{padding:18px 20px;display:flex;flex-direction:column;gap:14px}

.tcw-puzzle-trainer .modal-foot{padding:16px 20px;border-top:1px solid var(--line-2);display:flex;gap:10px;justify-content:flex-end}

.tcw-puzzle-trainer .modal-note{margin:0;font-size:12.5px;color:var(--ink-3)}

.tcw-puzzle-trainer .field{display:flex;flex-direction:column;gap:8px}

.tcw-puzzle-trainer .field textarea{
  width:100%;min-height:220px;padding:10px 12px;border:1px solid var(--line);border-radius:9px;
  font-family:ui-monospace,Consolas,monospace;font-size:12.5px;color:var(--ink);resize:vertical;
}

.tcw-puzzle-trainer .field-error{color:var(--red);font-size:13px;display:none}

.tcw-puzzle-trainer .field-error.show{display:block}

.tcw-puzzle-trainer .theme-popover-anchor{position:relative}

.tcw-puzzle-trainer .theme-popover{
  position:absolute;top:calc(100% + 6px);right:0;background:#fff;border:1px solid var(--line);
  border-radius:10px;box-shadow:0 8px 24px rgba(16,24,40,.15);padding:10px;display:none;gap:8px;z-index:10;
}

.tcw-puzzle-trainer .theme-popover.open{display:flex}

.tcw-puzzle-trainer .theme-swatch{width:30px;height:30px;border-radius:8px;border:2px solid var(--line);cursor:pointer;overflow:hidden;display:grid;grid-template-columns:1fr 1fr;grid-template-rows:1fr 1fr}

/* Swatch checkerboard colors per theme (mirror the [data-board] tokens). */
.tcw-puzzle-trainer .theme-swatch{--swl:#f3e0c1;--swd:#c8a069}

.tcw-puzzle-trainer .theme-swatch[data-theme="green"]{--swl:#eeeed2;--swd:#769656}

.tcw-puzzle-trainer .theme-swatch[data-theme="blue"]{--swl:#dee3e6;--swd:#8ca2ad}

.tcw-puzzle-trainer .theme-swatch[data-theme="slate"]{--swl:#e8e8e8;--swd:#9a9a9a}

.tcw-puzzle-trainer .theme-swatch span{display:block}

.tcw-puzzle-trainer .theme-swatch span:nth-child(1), .tcw-puzzle-trainer .theme-swatch span:nth-child(4){background:var(--swl)}

.tcw-puzzle-trainer .theme-swatch span:nth-child(2), .tcw-puzzle-trainer .theme-swatch span:nth-child(3){background:var(--swd)}

.tcw-puzzle-trainer .theme-swatch.active{border-color:var(--green)}

.tcw-puzzle-trainer .toast{
  position:fixed;left:50%;bottom:26px;transform:translateX(-50%);
  background:var(--ink);color:#fff;padding:11px 18px;border-radius:9px;font-size:14px;
  opacity:0;pointer-events:none;transition:opacity .2s ease;z-index:2000;
}

.tcw-puzzle-trainer .toast.show{opacity:1}


/* ============================================================
   L4 · PUZZLE TRAINER APP — puzzle-specific views only, scoped
        under .tcw-puzzle-trainer (the app root element carries
        that class):
          .pt-title .pt-sub .pt-main
          .board-card .board-wrap
          .pt-status .pt-status-rating .pt-session .pt-session-stats .pt-actions .btn-next
          .pt-side .pt-rating .pt-themes .pt-turn
          .pt-progress .pdot
          .pt-banner-icon .pt-stats .pt-stats-row .pt-training
          .pt-field .dd .dd-btn .dd-menu .pt-divider .pt-divider-session
          .promo-row .pt-selftest
        Plus the shared interaction markers used by every TCW
        chess tool (.sq.sel/.sq.hint/.sq.over/.dot/.ring, drag
        ghost), defined here under the trainer root.
   ============================================================ */

/* ---------- Root container ---------- */
.tcw-puzzle-trainer{max-width:1180px;margin:0 auto;padding:24px 20px 48px}

/* ---------- Page header ---------- */
.tcw-puzzle-trainer .pt-title{font-size:34px;line-height:1.15;font-weight:800;letter-spacing:-.02em;margin:0 0 8px}

.tcw-puzzle-trainer .pt-sub{margin:0 0 20px;color:var(--ink-2);font-size:15px}

/* ---------- Layout: board left, panel right ---------- */
.tcw-puzzle-trainer .pt-main{display:grid;grid-template-columns:minmax(0,1fr) 340px;gap:22px;margin-top:20px;align-items:start}

.tcw-puzzle-trainer .board-card{border:1px solid var(--line);border-radius:var(--radius);background:var(--panel);box-shadow:var(--shadow);padding:16px}

.tcw-puzzle-trainer .board-wrap{width:100%;max-width:min(100%,600px);margin:0 auto}

/* Fallback for browsers without aspect-ratio (same as the other TCW tools). */
@supports not (aspect-ratio: 1 / 1) {
  .tcw-puzzle-trainer .board-wrap{position:relative}
  .tcw-puzzle-trainer .board-wrap::before{content:'';display:block;padding-top:100%}
  .tcw-puzzle-trainer .board{position:absolute;inset:0;width:100%;height:100%}
}

/* ---------- Selection / hint / legal-move markers ---------- */
.tcw-puzzle-trainer .sq.sel{background-image:linear-gradient(var(--sq-hl),var(--sq-hl))}

.tcw-puzzle-trainer .sq.hint{background-image:linear-gradient(var(--sq-hint),var(--sq-hint))}

.tcw-puzzle-trainer .sq .dot{
  position:absolute;top:36%;left:36%;width:28%;height:28%;border-radius:50%;
  background:rgba(20,30,20,.28);pointer-events:none;z-index:2;
}

.tcw-puzzle-trainer .sq .ring{
  position:absolute;inset:6%;border-radius:50%;
  border:5px solid rgba(20,30,20,.25);pointer-events:none;z-index:2;
}

.tcw-puzzle-trainer .sq.over{outline:3px solid rgba(31,157,85,.9);outline-offset:-3px;z-index:3}

.tcw-puzzle-trainer .piece.dragging{opacity:.25}

/* Drag ghost is appended INSIDE the app root (see JS), so it stays
   under the scoped root — no global #ghost id selector. */
.tcw-puzzle-trainer .pt-ghost{
  position:fixed;z-index:9999;pointer-events:none;
  filter:drop-shadow(0 6px 10px rgba(0,0,0,.35));
  transform:translate(-50%,-50%);
}

/* ---------- Status / feedback row ---------- */
.tcw-puzzle-trainer .pt-status{
  display:flex;align-items:center;gap:10px;flex-wrap:wrap;
  margin-top:16px;padding:12px 14px;
  border:1px solid var(--line);border-radius:10px;background:var(--soft);
}

.tcw-puzzle-trainer .pt-status .st-title{font-size:15px;font-weight:700;color:var(--ink)}

.tcw-puzzle-trainer .pt-status .st-note{font-size:13px;color:var(--ink-2)}

.tcw-puzzle-trainer .pt-status.good{background:var(--green-soft);border-color:var(--green)}

.tcw-puzzle-trainer .pt-status.good .st-title{color:var(--green-dark)}

.tcw-puzzle-trainer .pt-status.solved{background:var(--green-soft);border-color:var(--green)}

.tcw-puzzle-trainer .pt-status.solved .st-title{color:var(--green-dark);font-size:16px}

/* ---------- Action buttons ---------- */
.tcw-puzzle-trainer .pt-actions{display:flex;gap:10px;margin-top:12px;flex-wrap:wrap}

.tcw-puzzle-trainer .pt-actions .btn{flex:1 1 130px}

.tcw-puzzle-trainer .pt-actions .btn-next{flex:1 1 100%;order:5}

/* Once solved, the primary action takes over the row. */
.tcw-puzzle-trainer.pt-solved .pt-actions .btn-next{flex-basis:100%;padding:14px 18px;font-size:15px}

/* ---------- Side panel ---------- */
.tcw-puzzle-trainer .pt-side{display:flex;flex-direction:column;gap:16px}

.tcw-puzzle-trainer .pt-rating{
  display:inline-flex;align-items:center;gap:6px;
  font-size:13px;font-weight:700;color:var(--ink-2);
  background:var(--amber-soft);padding:4px 10px;border-radius:999px;white-space:nowrap;
}

/* Rating star (local SVG — replaces the ★ glyph). */
.tcw-puzzle-trainer .pt-star{display:inline-block;width:1em;height:1em;flex:none;vertical-align:-.12em;background:url('assets/icons/star.svg') center/contain no-repeat}

/* Theme list: reserve a STABLE minimum height so puzzles with longer theme
   lists (which wrap to 2–3 lines) never push "White to move", the stats, or
   the Training section downward. Longest real theme list in the 10,000-puzzle
   dataset = 11 themes / 142 chars → 3 lines at ≥361px widths (4 at ≤360px,
   see the media query below). Deterministic line-height keeps the reservation
   exact; the tag icon stays aligned with the FIRST line (flex-start + 2px
   optical centering in the 18.85px line box). No truncation, no overlap. */
.tcw-puzzle-trainer .pt-themes{display:flex;align-items:flex-start;gap:7px;font-size:13px;line-height:1.45;color:var(--ink-2);margin-top:12px;min-height:calc(3 * 1.45em)}

.tcw-puzzle-trainer .pt-tag-ico{flex:none;width:15px;height:15px;margin-top:2px;display:inline-block;background-color:var(--ink-3);-webkit-mask:url('assets/icons/tag.svg') center/contain no-repeat;mask:url('assets/icons/tag.svg') center/contain no-repeat}

.tcw-puzzle-trainer .pt-turn{font-size:14px;font-weight:600;margin-top:8px}

.tcw-puzzle-trainer .pt-progress{display:flex;gap:8px;margin-top:14px}

.tcw-puzzle-trainer .pdot{width:12px;height:12px;border-radius:50%;background:#fff;border:1px solid var(--line)}

/* Progress dot states: done = solid green · current = white center + green
   ring with a restrained pale glow · future = white + subtle gray border.
   border-box sizing keeps the 12px outer size identical across states. */
.tcw-puzzle-trainer .pdot.current{border:2px solid var(--green);background:#fff;box-shadow:0 0 0 2px var(--green-soft)}

.tcw-puzzle-trainer .pdot.done{background:var(--green);border-color:var(--green)}

/* ---------- Status banner icon (solved / solution-shown states) ---------- */
.tcw-puzzle-trainer .pt-status .st-icon{display:none;flex:none;line-height:0}

.tcw-puzzle-trainer .pt-status.solved .st-icon{display:inline-flex}

.tcw-puzzle-trainer .pt-status .st-icon{width:20px;height:20px;background:url('assets/icons/check-circle.svg') center/20px no-repeat}

/* ---------- Stats (streak + solved) ---------- */
.tcw-puzzle-trainer .pt-stats{display:flex;flex-direction:column;gap:10px;margin-top:4px}

.tcw-puzzle-trainer .pt-stats-row{display:flex;align-items:center;gap:8px;font-size:14px;color:var(--ink-2)}

.tcw-puzzle-trainer .pt-stats-row b{color:var(--ink)}

.tcw-puzzle-trainer .pt-stats-row .st-ico{display:inline-block;flex:none;width:18px;height:18px;line-height:0;vertical-align:-3px}

.tcw-puzzle-trainer .pt-stats-row .st-ico-flame{background:url('assets/icons/flame.svg') center/contain no-repeat}

.tcw-puzzle-trainer .pt-stats-row .st-ico-check{background:url('assets/icons/check-circle.svg') center/contain no-repeat}

/* ---------- Training section (theme / rating / mode filters) ---------- */
.tcw-puzzle-trainer .pt-training{display:flex;flex-direction:column;gap:14px;margin-top:2px}

.tcw-puzzle-trainer .pt-training h3{margin:0;font-size:13px;font-weight:800;letter-spacing:-.01em}

.tcw-puzzle-trainer .pt-field{display:flex;flex-direction:column;gap:6px}

.tcw-puzzle-trainer .pt-field > span{font-size:12.5px;color:var(--ink-2)}

/* ---------- Training dropdowns (custom listbox over the native select)
   The native <select> (.dd-native) stays in the DOM as the value
   store / fallback; it is visually hidden while the custom button +
   floating menu provide the user-facing control. The menu is
   left/right-anchored to the field, so it can never exceed the
   panel (or viewport) width on mobile. ---------- */
.tcw-puzzle-trainer .dd{position:relative;display:block}

.tcw-puzzle-trainer .dd-native{position:absolute;width:1px;height:1px;padding:0;margin:0;border:0;opacity:0;pointer-events:none;overflow:hidden}

.tcw-puzzle-trainer .dd-btn{
  display:flex;align-items:center;justify-content:space-between;gap:8px;
  width:100%;padding:10px 12px;font:inherit;font-size:13.5px;color:var(--ink);
  background:#fff;border:1px solid #dfe4ea;border-radius:9px;cursor:pointer;text-align:left;
}

.tcw-puzzle-trainer .dd-btn:hover{border-color:#c9d2db}

.tcw-puzzle-trainer .dd.open .dd-btn{border-color:var(--green)}

.tcw-puzzle-trainer .dd-btn:focus-visible{outline:2px solid var(--green);outline-offset:1px}

.tcw-puzzle-trainer .dd-btn .dd-value{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}

.tcw-puzzle-trainer .dd-btn .dd-ico{flex:none;width:14px;height:14px;display:inline-block;background-color:var(--ink-3);-webkit-mask:url('assets/icons/chevron.svg') center/contain no-repeat;mask:url('assets/icons/chevron.svg') center/contain no-repeat;transition:transform .15s ease}

.tcw-puzzle-trainer .dd.open .dd-btn .dd-ico{transform:rotate(180deg)}

.tcw-puzzle-trainer .dd-menu{
  position:absolute;left:0;right:0;top:calc(100% + 6px);z-index:40;
  margin:0;padding:4px;list-style:none;
  background:#fff;border:1px solid #e0e5eb;border-radius:10px;
  box-shadow:0 8px 20px rgba(16,24,40,.08);
  max-height:240px;overflow-y:auto;
}

.tcw-puzzle-trainer .dd-menu:focus{outline:none}

.tcw-puzzle-trainer .dd-menu li{
  display:flex;align-items:center;justify-content:space-between;gap:8px;
  margin:2px 0;padding:8px 10px;border-radius:7px;
  font-size:13.5px;color:var(--ink);cursor:pointer;
}

.tcw-puzzle-trainer .dd-menu li .dd-check{display:none;width:14px;height:14px;flex:none;background:url('assets/icons/check.svg') center/contain no-repeat}

.tcw-puzzle-trainer .dd-menu li.active{background:#f2f5f7}

.tcw-puzzle-trainer .dd-menu li[aria-selected="true"]{background:var(--green-soft);font-weight:600}

.tcw-puzzle-trainer .dd-menu li[aria-selected="true"] .dd-check{display:inline-block}

.tcw-puzzle-trainer .dd-menu li[aria-selected="true"].active{background:#def0e4}

/* ---------- Panel section divider ---------- */
.tcw-puzzle-trainer .pt-divider{border:0;border-top:1px solid var(--line-2);margin:14px 0}

/* ---------- Promotion picker ---------- */
.tcw-puzzle-trainer .promo-row{display:flex;gap:10px;justify-content:center}

.tcw-puzzle-trainer .promo-row button{
  position:relative;width:70px;height:70px;
  border:1px solid var(--line);border-radius:12px;background:var(--soft);cursor:pointer;
}

.tcw-puzzle-trainer .promo-row button:hover{border-color:var(--green);background:var(--green-soft)}

.tcw-puzzle-trainer .promo-row svg{width:100%;height:100%}

/* ---------- ?selftest output ---------- */
.tcw-puzzle-trainer .pt-selftest{margin-top:16px;border:1px solid var(--line);border-radius:10px;overflow-x:auto}

.tcw-puzzle-trainer .pt-selftest table{width:100%;border-collapse:collapse;font-size:13px}

.tcw-puzzle-trainer .pt-selftest th, .tcw-puzzle-trainer .pt-selftest td{
  padding:8px 12px;text-align:left;border-bottom:1px solid var(--line-2);white-space:nowrap;
}

.tcw-puzzle-trainer .pt-selftest th{background:var(--soft);font-size:11px;letter-spacing:.08em;text-transform:uppercase;color:var(--ink-2)}

.tcw-puzzle-trainer .pt-selftest tr:last-child td{border-bottom:0}

.tcw-puzzle-trainer .pt-selftest .pass{color:var(--green-dark);font-weight:700}

.tcw-puzzle-trainer .pt-selftest .fail{color:var(--red);font-weight:700}

/* ---------- Responsive ---------- */
@media (max-width:960px){
  .tcw-puzzle-trainer .pt-main{grid-template-columns:minmax(0,1fr)}
}

/* ≤360px: the panel text column narrows to ~274px and the longest theme
   list (142 chars) wraps to 4 lines there — reserve one extra line. */
@media (max-width:360px){
  .tcw-puzzle-trainer .pt-themes{min-height:calc(4 * 1.45em)}
}

/* Session feedback block: desktop shows the panel copies, so this is
   hidden by default; the 760px query below flips that. */
.tcw-puzzle-trainer .pt-session{display:none}

/* Rating badge: on desktop it lives in the side panel, so the copy that
   sits inside the status box (mobile-only, see the 760px query) is hidden
   by default to keep the desktop layout byte-for-byte the same. */
.tcw-puzzle-trainer .pt-status .pt-status-rating{display:none}

@media (max-width:760px){
  /* Mobile compactness pass: trim vertical space in the control column
     (status / stats / buttons / Next) WITHOUT shrinking the board.
     The board keeps its width/height; only padding, gaps, and text sizes
     tighten. Every rule is scoped under .tcw-puzzle-trainer. */
  .tcw-puzzle-trainer{padding:10px 10px 14px}
  .tcw-puzzle-trainer .pt-title{font-size:clamp(20px,6vw,26px);margin-bottom:4px}
  .tcw-puzzle-trainer .pt-sub{font-size:13px;margin-bottom:10px}
  /* Board card: keep the board full-width; only the top/bottom inset tightens. */
  .tcw-puzzle-trainer .board-card{padding:8px 0}
  .tcw-puzzle-trainer .board-wrap{padding:0 3px}

  /* --- Status banner: compact, and the SAME reserved height unsolved & solved.
       Two-line layout:  line 1 = [icon][title] ......... [rating badge]
                         line 2 = [note]
       `order` keeps the rating on line 1 (right) and the note on line 2.
       min-height is a floor; both states render at the same content height
       (the rating badge is visibility-hidden, not display-hidden, on solve,
       so it keeps its slot and nothing below moves). */
  .tcw-puzzle-trainer .pt-status{
    display:flex;flex-wrap:wrap;align-items:center;gap:4px 10px;
    margin:8px 8px 0;padding:8px 12px;min-height:52px
  }
  .tcw-puzzle-trainer .pt-status .st-title{font-size:14px}
  .tcw-puzzle-trainer .pt-status .st-note{font-size:12.5px}
  .tcw-puzzle-trainer .pt-status .st-icon{order:-1;flex:none}
  .tcw-puzzle-trainer .pt-status .st-title{order:0;flex:0 1 auto;min-width:0}
  .tcw-puzzle-trainer .pt-status .st-note{order:2;flex-basis:100%}
  .tcw-puzzle-trainer .pt-status .pt-status-rating{
    order:1;flex:none;margin-left:auto;
    display:inline-flex;align-items:center;gap:5px;
    font-size:12.5px;font-weight:700;color:var(--ink-2);
    background:var(--amber-soft);padding:3px 9px;border-radius:999px;white-space:nowrap
  }
  /* Solved: hide the rating but KEEP its space (visibility, not display),
     so the box height — and everything below it — does not shift. */
  .tcw-puzzle-trainer .pt-status.solved .pt-status-rating{visibility:hidden}

  /* Action buttons: 2×2 + full-width Next. Reduce gaps/container padding,
     keep tap targets comfortable (~40px+). Neutralize the desktop solved
     Next-button enlargement so Next is the SAME height solved vs unsolved. */
  .tcw-puzzle-trainer .pt-actions{gap:6px;padding:6px;margin-top:8px}
  .tcw-puzzle-trainer .pt-actions .btn{flex:1 1 calc(50% - 3px);padding:11px 8px;font-size:13px}
  .tcw-puzzle-trainer .pt-actions .btn-next{flex:1 1 100%;padding:11px 8px;font-size:14px}
  .tcw-puzzle-trainer.pt-solved .pt-actions .btn-next{padding:11px 8px;font-size:14px}

  /* Session feedback row: progress + streak/solved on one compact row, just
     under the status banner. The panel keeps its copies hidden so nothing
     duplicates (rating, side-to-move, progress, stats, and the session divider). */
  .tcw-puzzle-trainer .pt-session{
    display:flex;align-items:center;justify-content:space-between;gap:6px 12px;
    flex-wrap:wrap;margin:8px 8px 0;padding:8px 12px;
    border:1px solid var(--line,#e3e3e3);border-radius:10px;background:#fff
  }
  .tcw-puzzle-trainer .pt-session .pt-progress{margin:0;gap:6px}
  .tcw-puzzle-trainer .pt-session-stats{display:flex;align-items:center;gap:12px;flex-wrap:wrap}
  .tcw-puzzle-trainer .pt-session .pt-stats-row{margin:0;font-size:12.5px;gap:6px}
  /* Lower panel is secondary on mobile: keep it focused on themes + the
     four training filters. Drop the duplicated rating / side-to-move /
     progress / stats so the compact status + session rows are the source
     of truth up top. */
  .tcw-puzzle-trainer .panel .pt-rating{display:none}
  .tcw-puzzle-trainer .panel .pt-turn{display:none}
  .tcw-puzzle-trainer .panel .pt-progress{display:none}
  .tcw-puzzle-trainer .panel .pt-stats{display:none}
  .tcw-puzzle-trainer .pt-divider-session{display:none}
}


/* SamChess site chrome: size the header logo to match the other tool pages (the global .logo img rule is sized for the horizontal wordmark) */
.site-header .logo img{width:48px;height:48px}

/* Neutralize the homepage hero .board styling (navy frame, rotate(3deg), radius, shadow) — the functional board must stay square and level */
.tcw-puzzle-trainer .board{padding:0;background:none;box-shadow:none;transform:none;perspective:none}
