/* ============================================================
   TCW Board Editor — board-editor.css
   Every rule is scoped under .tcw-board-editor (never :root / body),
   so it is safe to load on any page and cannot leak into the host.
   Tokens and the board/piece/button/panel primitives are adapted from
   the PGN Viewer / Play vs Computer shared system (L0 + L3) so the
   tool matches the rest of the TheChessWorld chess-tool family.

   Layers, top to bottom:
     L0 · Foundation  — design tokens (scoped)
     L1 · Base        — box-sizing, type, focus ring (scoped)
     L2 · Shared chess primitives — .board .sq .piece .btn .panel .toast
     L3 · Board Editor app — layout, palette, settings, presets,
                            annotations, modal, status, responsive
   ============================================================ */

/* ============================================================
   L0 · FOUNDATION — design tokens
   ============================================================ */
.tcw-board-editor{
  --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;
  --radius:12px;
  --shadow:0 1px 2px rgba(16,24,40,.05);
  --sq-light:#f3e0c1;
  --sq-dark:#c8a069;
  --sq-last:rgba(240,197,60,.55);
  --sq-check:rgba(214,69,69,.65);
  --anno:#1f9d55;
  --font:"Inter",-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
}
.tcw-board-editor[data-board="green"]{ --sq-light:#eeeed2; --sq-dark:#769656; }
.tcw-board-editor[data-board="blue"]{ --sq-light:#dee3e6; --sq-dark:#8ca2ad; }
.tcw-board-editor[data-board="slate"]{ --sq-light:#e8e8e8; --sq-dark:#9a9a9a; }

/* ============================================================
   L1 · BASE
   ============================================================ */
.tcw-board-editor *{box-sizing:border-box}
.tcw-board-editor{
  color-scheme:light;
  color:var(--ink);
  background:var(--bg);
  font-family:var(--font);
  -webkit-font-smoothing:antialiased;
  line-height:1.45;
}
.tcw-board-editor :focus-visible{outline:3px solid #7fb8ff;outline-offset:2px}

/* ============================================================
   L2 · SHARED CHESS PRIMITIVES
   ============================================================ */
.tcw-board-editor .board{
  position:relative;
  aspect-ratio:1/1;width:100%;
  border-radius:6px;overflow:hidden;
  touch-action:manipulation;user-select:none;-webkit-user-select:none;-webkit-touch-callout:none;
}
/* The 8x8 grid of squares. Kept separate from the absolute annotation layers
   so those layers can be re-rendered without rebuilding the 64 square cells. */
.tcw-board-editor .squares{
  display:grid;
  grid-template-columns:repeat(8,1fr);
  grid-template-rows:repeat(8,1fr);
  width:100%;height:100%;
}
.tcw-board-editor .sq{position:relative;min-width:0;min-height:0;touch-action:manipulation}
.tcw-board-editor .sq.light{background-color:var(--sq-light)}
.tcw-board-editor .sq.dark{background-color:var(--sq-dark)}
.tcw-board-editor .sq.last{background-image:linear-gradient(var(--sq-last),var(--sq-last))}
.tcw-board-editor .sq.check{background-image:radial-gradient(circle,var(--sq-check) 22%,transparent 72%)}
.tcw-board-editor .sq.drop-hint{box-shadow:inset 0 0 0 4px rgba(31,157,85,.65)}
.tcw-board-editor .sq.drag-source .piece{opacity:.35}
.tcw-board-editor .sq[data-file]::before, .tcw-board-editor .sq[data-rank]::after{
  position:absolute;font-size:var(--co,11px);font-weight:700;line-height:1;pointer-events:none;z-index:5;
}
/* Coordinates live on FIXED edges in both orientations — files along the
   bottom row, ranks down the right column. Each square supplies its own
   label via data-file/data-rank, so flipping the board only changes the
   VALUES shown, never the labelled edges. Centring each label inside its
   square keeps corner labels (e.g. the "a" on a1/a8) fully inside the
   board — no clipping at the rounded corners. */
.tcw-board-editor .sq[data-file]::before{content:attr(data-file);left:50%;bottom:4%;transform:translateX(-50%)}
.tcw-board-editor .sq[data-rank]::after{content:attr(data-rank);right:4%;top:50%;transform:translateY(-50%)}
.tcw-board-editor .sq.light::before, .tcw-board-editor .sq.light::after{color:var(--sq-dark);filter:brightness(.75)}
.tcw-board-editor .sq.dark::before, .tcw-board-editor .sq.dark::after{color:var(--sq-light)}

/* ============================================================
   SAMCHESS HOST — neutralize the homepage hero-illustration rules.
   The shared site stylesheet (assets/styles.css) defines UNSCOPED
   `.board` / `.squares` / `.sq` rules for the homepage hero
   illustration (blue gradient frame, 3° rotation, 4×4 tile grid,
   tile colors). That styling belongs only to the hero and must not
   leak into this functional tool, so inside `.tcw-board-editor` we
   restore the original source geometry: a plain, front-facing,
   exactly 1:1 square 8×8 board with no frame, tilt or transforms.
   ============================================================ */
.tcw-board-editor .board{padding:0;background:none;box-shadow:none;transform:none;perspective:none}
.tcw-board-editor .squares{border-radius:0;overflow:visible}
.tcw-board-editor .sq{display:block;background:transparent}

/* SamChess header on this tool page: the corrected mark logo, sized
   for the 76px nav (the global `.logo img` width targets the wide
   wordmark PNG used elsewhere). */
.site-header .logo img{width:48px;height:48px}

.tcw-board-editor .piece{position:absolute;inset:0;z-index:4;pointer-events:none}
.tcw-board-editor .piece svg{width:100%;height:100%;display:block}
.tcw-board-editor .sprite-hidden{position:absolute;width:0;height:0;overflow:hidden}

/* Live annotation layers. Both are board-relative and pointer-transparent so
   they never steal clicks from the squares/pieces beneath them.
     .hl-layer   — highlighted squares, BELOW the pieces (z 3)
     .piece      — the chess pieces themselves (z 4)
     .anno-layer — arrows, ABOVE the pieces (z 6)
   Square backgrounds are z auto (the base layer), so the stack order is
   exactly: square bg < highlight < piece < arrow. */
.tcw-board-editor .hl-layer{position:absolute;inset:0;width:100%;height:100%;z-index:3;pointer-events:none}
.tcw-board-editor .anno-layer{position:absolute;inset:0;width:100%;height:100%;z-index:6;pointer-events:none}
.tcw-board-editor .board-wrap{position:relative}

/* Buttons */
.tcw-board-editor .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-board-editor .btn:hover{background:var(--soft)}
.tcw-board-editor .btn:disabled{opacity:.45;cursor:not-allowed}
.tcw-board-editor .btn svg{width:17px;height:17px;flex:none}
.tcw-board-editor .btn-note{font-weight:600;opacity:.85}
.tcw-board-editor .btn-grow{flex:1 1 80px}
.tcw-board-editor .btn-primary{background:var(--green);border-color:var(--green);color:#fff}
.tcw-board-editor .btn-primary:hover{background:var(--green-dark)}
.tcw-board-editor .btn-warn{color:var(--red);border-color:#f2c9c9}
.tcw-board-editor .btn-warn:hover{background:#fdf2f2}
.tcw-board-editor .btn-ghost{background:transparent}

.tcw-board-editor .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-board-editor .icon-sq-btn:hover{background:var(--soft)}
.tcw-board-editor .icon-sq-btn svg{width:19px;height:19px}

/* Panels */
.tcw-board-editor .panel{border:1px solid var(--line);border-radius:var(--radius);background:var(--panel);box-shadow:var(--shadow)}
.tcw-board-editor .panel-head{display:flex;align-items:center;justify-content:space-between;gap:10px;padding:12px 14px;border-bottom:1px solid var(--line-2)}
.tcw-board-editor .panel-head h2{margin:0;font-size:13px;font-weight:800;letter-spacing:.02em;white-space:nowrap}
.tcw-board-editor .panel-body{padding:12px 14px}
.tcw-board-editor .panel-body--flush{padding:0}

/* Modal */
.tcw-board-editor .overlay{position:fixed;inset:0;background:rgba(16,24,40,.5);display:flex;align-items:center;justify-content:center;padding:20px;z-index:1000}
.tcw-board-editor .overlay[hidden]{display:none}
.tcw-board-editor .modal{width:min(520px,100%);background:var(--panel);border-radius:14px;box-shadow:0 20px 50px rgba(16,24,40,.35);overflow:hidden}
.tcw-board-editor .modal-head{display:flex;align-items:center;justify-content:space-between;padding:14px 16px;border-bottom:1px solid var(--line-2)}
.tcw-board-editor .modal-head h3{margin:0;font-size:16px;font-weight:800}
.tcw-board-editor .modal-body{padding:16px}
.tcw-board-editor .modal-foot{display:flex;justify-content:flex-end;gap:8px;padding:12px 16px;border-top:1px solid var(--line-2)}
.tcw-board-editor .field{display:flex;flex-direction:column;gap:6px}
.tcw-board-editor .field label{font-size:13px;font-weight:600;color:var(--ink-2)}
.tcw-board-editor .field .field-error{color:var(--red);font-size:13px;min-height:0;display:none}
.tcw-board-editor .field .field-error.show{display:block}
.tcw-board-editor .modal-note{margin:12px 0 0;font-size:13px;color:var(--ink-3)}
.tcw-board-editor .icon-btn{background:none;border:0;cursor:pointer;color:var(--ink-3);padding:4px;line-height:0;border-radius:6px}
.tcw-board-editor .icon-btn:hover{color:var(--red);background:var(--soft)}
.tcw-board-editor .icon-btn svg{width:18px;height:18px}

/* Toast */
.tcw-board-editor .toast{
  position:fixed;left:50%;bottom:24px;transform:translateX(-50%) translateY(20px);
  background:#12161c;color:#fff;padding:10px 16px;border-radius:10px;font-size:14px;font-weight:600;
  box-shadow:0 8px 24px rgba(16,24,40,.35);opacity:0;pointer-events:none;transition:opacity .2s ease,transform .2s ease;z-index:1200;max-width:90vw;text-align:center;
}
.tcw-board-editor .toast.show{opacity:1;transform:translateX(-50%) translateY(0)}

/* ============================================================
   L3 · BOARD EDITOR APP
   ============================================================ */
.tcw-board-editor{max-width:1180px;margin:0 auto;padding:44px 20px 48px}

.tcw-board-editor .tcw-title{font-size:34px;line-height:1.15;font-weight:800;letter-spacing:-.02em;margin:0 0 8px}
.tcw-board-editor .tcw-sub{margin:0 0 20px;color:var(--ink-2);font-size:15px}

.tcw-board-editor .tcw-main{display:grid;grid-template-columns:minmax(0,1fr) 380px;gap:22px;align-items:start}
.tcw-board-editor .side{display:flex;flex-direction:column;gap:16px}

/* Board card + palettes */
.tcw-board-editor .board-card{border:1px solid var(--line);border-radius:var(--radius);background:var(--panel);box-shadow:var(--shadow);padding:16px}
.tcw-board-editor .board-col{
  --side-w:52px;
  --row-gap:8px;
  display:flex;flex-direction:column;gap:12px;
  max-width:660px;margin:0 auto;width:100%;
}
/* Spare rows follow the board orientation: white orientation keeps the
   black row on top / white row on the bottom; black orientation swaps
   them so each colour's spare row sits on its own side of the board.
   Pure flex `order` (no DOM moves) keeps palette drag & drop untouched.
   `data-orientation` is set on the root by renderBoard(). */
.tcw-board-editor .board-col>.palette--black{order:0}
.tcw-board-editor .board-col>.board-row{order:1}
.tcw-board-editor .board-col>.palette--white{order:2}
.tcw-board-editor .board-col>.help-row{order:3}
.tcw-board-editor .board-col>.fen-row{order:4}
.tcw-board-editor .board-col>.fen-status{order:5}
.tcw-board-editor .board-col>.cta-row{order:6}
.tcw-board-editor[data-orientation="b"] .board-col>.palette--black{order:2}
.tcw-board-editor[data-orientation="b"] .board-col>.palette--white{order:0}
.tcw-board-editor .board-wrap{width:100%;flex:1 1 auto;min-width:0}

.tcw-board-editor .palette{
  display:flex;align-items:center;gap:4px;flex-wrap:wrap;
  border:1px solid var(--line);border-radius:10px;background:var(--soft);padding:6px;
  width:calc(100% - var(--side-w) - var(--row-gap));
}
.tcw-board-editor .palette .pal-btn{
  width:52px;height:52px;display:flex;align-items:center;justify-content:center;
  border:1px solid transparent;border-radius:9px;background:transparent;cursor:pointer;padding:0;
}
.tcw-board-editor .palette .pal-btn svg{width:42px;height:42px}
.tcw-board-editor .palette .pal-btn:hover{background:#fff;border-color:var(--line)}
.tcw-board-editor .palette .pal-btn.active{background:#fff;border-color:var(--green);box-shadow:0 0 0 2px rgba(31,157,85,.25)}
.tcw-board-editor .palette .pal-tool{
  width:52px;height:52px;flex:none;display:flex;align-items:center;justify-content:center;
  border:1px solid transparent;border-radius:9px;background:transparent;cursor:pointer;padding:0;color:var(--ink-2);
}
.tcw-board-editor .palette .pal-tool svg{width:24px;height:24px}
.tcw-board-editor .palette .pal-tool:hover{color:var(--ink);background:#fff;border-color:var(--line)}
.tcw-board-editor .palette .pal-tool.active{color:var(--green-dark);background:#fff;border-color:var(--green);box-shadow:0 0 0 2px rgba(31,157,85,.25)}
.tcw-board-editor .palette .pal-tool.trash.active{color:var(--red);border-color:var(--red);box-shadow:0 0 0 2px rgba(214,69,69,.25)}
.tcw-board-editor .palette .pal-sep{width:1px;height:36px;background:var(--line);margin:0 4px}
.tcw-board-editor .palette .pal-spacer{flex:1 1 auto}
.tcw-board-editor .palette .pal-label{font-size:11px;font-weight:800;letter-spacing:.04em;color:var(--ink-3);padding:0 4px;text-transform:uppercase}

.tcw-board-editor .board-row{display:flex;gap:var(--row-gap);align-items:stretch}
.tcw-board-editor .board-side-actions{display:flex;flex-direction:column;gap:8px;flex:none;justify-content:center}


/* FEN + save row */
.tcw-board-editor .fen-row{display:flex;align-items:center;gap:8px;flex-wrap:wrap}
.tcw-board-editor .fen-row .fen-label{font-size:12px;font-weight:800;letter-spacing:.04em;color:var(--ink-3);text-transform:uppercase}
.tcw-board-editor .fen-input{
  flex:1 1 220px;min-width:0;padding:10px 12px;border:1px solid var(--line);border-radius:10px;
  font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;font-size:13px;background:var(--panel);color:var(--ink);
}
.tcw-board-editor .fen-input.invalid{border-color:var(--red);background:var(--red-soft)}
.tcw-board-editor .fen-status{font-size:12.5px;font-weight:600;min-height:18px}
.tcw-board-editor .fen-status.ok{color:var(--green-dark)}
.tcw-board-editor .fen-status.err{color:var(--red)}

/* Position settings */
.tcw-board-editor .set-row{display:flex;align-items:center;gap:10px;margin-bottom:14px}
.tcw-board-editor .set-row:last-child{margin-bottom:0}
.tcw-board-editor .set-row > .set-label{flex:0 0 118px;font-size:13px;font-weight:700;color:var(--ink-2)}
.tcw-board-editor .set-row > .set-control{flex:1 1 auto;min-width:0;display:flex;align-items:center;gap:8px;flex-wrap:wrap}
/* "Set position" — label above a full-width control (popover anchor) */
.tcw-board-editor .set-row--block{flex-direction:column;align-items:stretch;gap:8px}
.tcw-board-editor .set-row--block > .set-label{flex:none}
.tcw-board-editor .set-row--block > .set-control{width:100%}
.tcw-board-editor .set-row--block .popover-anchor{width:100%}

.tcw-board-editor .seg{display:flex;width:100%;border:1px solid var(--line);border-radius:10px;overflow:hidden;background:var(--soft)}
.tcw-board-editor .seg .seg-btn{flex:1;border:0;background:transparent;padding:10px 16px;font-family:inherit;font-size:14px;font-weight:600;cursor:pointer;color:var(--ink-2);text-align:center;transition:background .12s ease,color .12s ease}
.tcw-board-editor .seg .seg-btn + .seg-btn{border-left:1px solid var(--line)}
.tcw-board-editor .seg .seg-btn:hover{background:#fff}
.tcw-board-editor .seg .seg-btn.active{background:#fff;color:var(--ink);box-shadow:0 0 0 2px rgba(0,0,0,.03) inset}

.tcw-board-editor .check{display:inline-flex;align-items:center;gap:7px;font-size:13.5px;font-weight:600;color:var(--ink-2);cursor:pointer;user-select:none}
.tcw-board-editor .check input{width:17px;height:17px;accent-color:var(--green);margin:0}

.tcw-board-editor .select{
  padding:10px 36px 10px 13px;border:1px solid var(--line);border-radius:10px;background:var(--panel);
  font-family:inherit;font-size:13.5px;font-weight:600;color:var(--ink);
  appearance:none;-webkit-appearance:none;cursor:pointer;
  transition:border-color .15s ease,background .15s ease;
  background-image:url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='14' height='9' viewBox='0 0 14 9'><path d='M1.5 1.5l5.5 5.5 5.5-5.5' stroke='%236b7683' stroke-width='2' fill='none' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  background-repeat:no-repeat;background-position:right 13px center;background-size:14px 9px;
}
.tcw-board-editor .select:hover{border-color:var(--ink-3);background:var(--soft)}
.tcw-board-editor .select:disabled{opacity:.6;cursor:not-allowed}

/* En passant — custom dropdown (same visual system as .select / .popover) */
.tcw-board-editor .epd{position:relative;flex:0 1 132px;min-width:118px}
.tcw-board-editor .epd-trigger{
  display:inline-flex;align-items:center;gap:8px;width:100%;
  padding:10px 12px 10px 13px;border:1px solid var(--line);border-radius:10px;background:var(--panel);
  font-family:inherit;font-size:13.5px;font-weight:600;color:var(--ink);cursor:pointer;
  transition:border-color .15s ease,background .15s ease,box-shadow .15s ease;
}
.tcw-board-editor .epd-trigger:hover{border-color:var(--ink-3);background:var(--soft)}
.tcw-board-editor .epd-trigger:focus-visible{outline:none;border-color:var(--green);box-shadow:0 0 0 3px rgba(31,157,85,.18)}
.tcw-board-editor .epd-trigger.open{border-color:var(--green);background:var(--soft);box-shadow:0 0 0 3px rgba(31,157,85,.18)}
.tcw-board-editor .epd-value{flex:1 1 auto;text-align:left;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.tcw-board-editor .epd-chev{width:14px;height:9px;flex:none;color:var(--ink-3)}
.tcw-board-editor .epd-menu{
  display:none;position:absolute;top:calc(100% + 6px);left:0;right:0;z-index:50;
  background:var(--panel);border:1px solid var(--line);border-radius:12px;
  box-shadow:0 12px 32px rgba(16,24,40,.16);padding:6px;
  max-height:264px;overflow:auto;
}
.tcw-board-editor .epd-menu.open{display:block}
.tcw-board-editor .epd-opt{
  display:flex;align-items:center;gap:8px;width:100%;text-align:left;
  border:0;background:transparent;border-radius:8px;padding:8px 10px;
  font-family:inherit;font-size:13.5px;font-weight:600;color:var(--ink);cursor:pointer;
  transition:background .12s ease;
}
.tcw-board-editor .epd-opt:hover,.tcw-board-editor .epd-opt:focus-visible{background:var(--soft);outline:none}
.tcw-board-editor .epd-opt-label{flex:1 1 auto}
.tcw-board-editor .epd-opt.selected{background:var(--green-soft);color:var(--green-dark)}
.tcw-board-editor .epd-opt.selected:hover{background:var(--green-soft)}
.tcw-board-editor .epd-check{width:15px;height:15px;flex:none;color:var(--green-dark)}

/* Playability status */
.tcw-board-editor .status{display:flex;gap:8px;align-items:flex-start;border-radius:10px;padding:10px 12px;font-size:13px;line-height:1.4;margin-top:4px}
.tcw-board-editor .status .st-ico{flex:none;width:18px;height:18px;margin-top:1px}
.tcw-board-editor .status.ok{background:var(--green-soft);color:var(--green-dark)}
.tcw-board-editor .status.warn{background:var(--amber-soft);color:#8a5410}
.tcw-board-editor .status.err{background:var(--red-soft);color:#a83232}
.tcw-board-editor .status ul{margin:4px 0 0;padding-left:18px}
.tcw-board-editor .status .st-title{font-weight:800}

/* Presets */
.tcw-board-editor .preset-search{position:relative;margin-bottom:10px}
.tcw-board-editor .preset-search svg{position:absolute;left:11px;top:50%;transform:translateY(-50%);width:16px;height:16px;color:var(--ink-3)}
.tcw-board-editor .preset-search input{width:100%;padding:10px 12px 10px 34px;border:1px solid var(--line);border-radius:10px;font-family:inherit;font-size:14px;background:var(--panel);color:var(--ink)}
.tcw-board-editor .preset-tabs{display:flex;gap:6px;margin-bottom:10px}
.tcw-board-editor .preset-tabs .ptab{flex:1;border:1px solid var(--line);background:var(--soft);border-radius:9px;padding:8px 10px;font-family:inherit;font-size:13px;font-weight:700;cursor:pointer;color:var(--ink-2)}
.tcw-board-editor .preset-tabs .ptab.active{background:#fff;border-color:var(--green);color:var(--green-dark)}
.tcw-board-editor .preset-list{display:flex;flex-direction:column;gap:2px;max-height:280px;overflow:auto}
.tcw-board-editor .preset-item{display:flex;align-items:center;gap:10px;width:100%;text-align:left;border:0;background:transparent;border-radius:9px;padding:9px 10px;cursor:pointer;font-family:inherit}
.tcw-board-editor .preset-item:hover{background:var(--soft)}
.tcw-board-editor .preset-item .pi-name{font-size:13.5px;font-weight:600;color:var(--ink);min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.tcw-board-editor .preset-item .pi-eco{flex:none;font-size:11px;font-weight:800;color:var(--ink-3);background:var(--soft);border:1px solid var(--line);border-radius:6px;padding:1px 6px}
.tcw-board-editor .preset-item .pi-note{flex:none;font-size:12px;color:var(--ink-3)}
.tcw-board-editor .preset-empty{padding:18px 10px;text-align:center;color:var(--ink-3);font-size:13.5px}

/* Compact controls — collapsed popovers/dropdowns, castling grid, board-color
   swatches, panel actions, on-demand help, CTA row. Everything is scoped and
   reuses the same tokens as the rest of the tool family. */
.tcw-board-editor .popover-anchor{position:relative;flex:1 1 auto;display:flex}
.tcw-board-editor .popover{
  display:none;position:absolute;top:calc(100% + 6px);left:0;right:0;z-index:40;
  background:var(--panel);border:1px solid var(--line);border-radius:12px;
  box-shadow:0 12px 32px rgba(16,24,40,.16);padding:10px;
}
.tcw-board-editor .popover.open{display:block}

.tcw-board-editor .panel-sep{height:1px;background:var(--line-2);margin:14px 0}

.tcw-board-editor .panel-actions{display:grid;grid-template-columns:1fr 1fr;gap:8px}
.tcw-board-editor .panel-actions .btn{width:100%}
.tcw-board-editor .btn .chev{width:14px;height:14px;opacity:.55}

/* Castling — compact 2×2 toggle grid (White/Black × O-O/O-O-O) */
.tcw-board-editor .castle-grid{display:grid;grid-template-columns:auto 1fr 1fr;gap:6px;align-items:center;width:100%}
.tcw-board-editor .cg-head{font-size:11px;font-weight:800;letter-spacing:.03em;text-transform:uppercase;color:var(--ink-3);text-align:center}
.tcw-board-editor .cg-row{font-size:11px;font-weight:700;color:var(--ink-3);text-align:right;padding-right:4px;white-space:nowrap}
.tcw-board-editor .castle-btn{
  padding:8px 10px;border:1px solid var(--line);border-radius:9px;background:var(--soft);
  font-family:inherit;font-size:13px;font-weight:700;color:var(--ink-3);cursor:pointer;
  transition:background .15s ease,border-color .15s ease,color .15s ease;
}
.tcw-board-editor .castle-btn:hover{background:#fff}
.tcw-board-editor .castle-btn.active{background:var(--green-soft);border-color:var(--green);color:var(--green-dark)}

/* Board colors — a compact swatch row (deliberately small / secondary) */
.tcw-board-editor .swatches{gap:8px}
.tcw-board-editor .swatch{
  width:32px;height:26px;border-radius:7px;cursor:pointer;padding:0;
  border:1px solid var(--line);
  background:linear-gradient(135deg,var(--sw-l) 50%,var(--sw-d) 50%);
}
.tcw-board-editor .swatch:hover{border-color:var(--ink-3)}
.tcw-board-editor .swatch.active{box-shadow:0 0 0 2px var(--panel),0 0 0 4px var(--green)}

/* Save Image — one button, one small dropdown menu */
.tcw-board-editor .menu-anchor{position:relative;flex:1 1 80px;display:flex}
/* NOTE: container class is `.save-menu`, NOT `.menu` — the site-chrome nav
   uses `.menu` with a global rule set (width:100%; height:45px; z-index:100000)
   and the two used to collide, clipping the dropdown (MODX audit fix). */
.tcw-board-editor .save-menu{
  display:none;position:absolute;top:calc(100% + 4px);right:0;z-index:50;
  min-width:100%;
  background:var(--panel);border:1px solid var(--line);border-radius:12px;
  box-shadow:0 8px 24px rgba(16,24,40,.13);padding:6px;
}
.tcw-board-editor .save-menu.open{display:block}
.tcw-board-editor .menu-item{
  display:flex;align-items:center;gap:9px;width:100%;text-align:left;
  border:0;background:transparent;border-radius:9px;padding:10px;
  font-family:inherit;font-size:13.5px;font-weight:600;color:var(--ink);cursor:pointer;
}
.tcw-board-editor .menu-item:hover{background:var(--soft)}
.tcw-board-editor .menu-item svg{width:17px;height:17px;color:var(--ink-2);flex:none}

/* Help — a small "How to use" toggle; the box stays hidden until asked for */
.tcw-board-editor .help-row{width:100%}
.tcw-board-editor .help-btn{
  display:inline-flex;align-items:center;gap:7px;
  border:0;background:none;cursor:pointer;padding:6px 8px;border-radius:8px;
  font-family:inherit;font-size:13px;font-weight:700;color:var(--ink-3);
  transition:background .15s ease,color .15s ease;
}
.tcw-board-editor .help-btn:hover{background:var(--soft);color:var(--ink-2)}
.tcw-board-editor .help-btn svg{width:15px;height:15px;flex:none}
.tcw-board-editor .help-box{
  display:none;margin-top:8px;padding:10px 12px;
  border:1px solid var(--line);border-radius:10px;background:var(--soft);
  font-size:13px;color:var(--ink-2);line-height:1.55;
}
.tcw-board-editor .help-box.open{display:block}
.tcw-board-editor .help-box ul{margin:0;padding-left:18px}
.tcw-board-editor .help-box li{margin:3px 0}
.tcw-board-editor .help-box b{color:var(--ink);font-weight:700}

/* Primary handoff CTAs — one row, board-aligned, under the FEN field */
.tcw-board-editor .cta-row{display:flex;gap:10px;width:100%;flex-wrap:wrap}
.tcw-board-editor .cta-row .btn{flex:1 1 auto;justify-content:center;padding:13px 16px}

/* Action card + CTAs */
.tcw-board-editor .action-grid{display:grid;grid-template-columns:1fr 1fr;gap:8px}
.tcw-board-editor .action-grid .btn{width:100%}
.tcw-board-editor .cta{display:flex;flex-direction:column;gap:10px}
.tcw-board-editor .cta .btn{width:100%;padding:14px}
.tcw-board-editor .cta .btn svg{width:18px;height:18px}
.tcw-board-editor .cta .cta-note{font-size:12px;color:var(--ink-3);margin:0 0 2px}

/* Floating drag ghost (follows the pointer while repositioning a piece) */
.tcw-board-editor .ghost{position:fixed;z-index:1500;pointer-events:none;width:52px;height:52px;transform:translate(-50%,-50%);opacity:.92;filter:drop-shadow(0 4px 8px rgba(16,24,40,.35))}
.tcw-board-editor .ghost svg{width:100%;height:100%;display:block}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width:960px){
  .tcw-board-editor .tcw-main{grid-template-columns:minmax(0,1fr)}
}
@media (max-width:760px){
  .tcw-board-editor{padding:32px 12px 40px}
  .tcw-board-editor .tcw-title{font-size:clamp(24px,7vw,32px)}
  .tcw-board-editor .tcw-sub{font-size:14px}
  .tcw-board-editor .board-card{padding:10px}
  .tcw-board-editor .board-row{flex-direction:column}
  .tcw-board-editor .board-side-actions{flex-direction:row;justify-content:center;width:100%;margin:0 0 8px;order:-1}
  .tcw-board-editor .palette .pal-btn{width:44px;height:44px}
  .tcw-board-editor .palette .pal-btn svg{width:34px;height:34px}
  .tcw-board-editor .palette .pal-tool{width:44px;height:44px}
  .tcw-board-editor .palette .pal-tool svg{width:22px;height:22px}
  .tcw-board-editor .fen-row .fen-input{flex-basis:100%}
  .tcw-board-editor .action-grid{grid-template-columns:1fr 1fr}
  .tcw-board-editor .set-row{flex-direction:column;align-items:flex-start;gap:8px}
  .tcw-board-editor .set-row > .set-label{flex-basis:auto}
}
