:root { color-scheme: dark; --bg:#071011; --surface:#0d1819; --surface2:#122123; --text:#edf7f4; --muted:#a3b7b1; --line:#203335; --accent:#7fe4c4; --light-square:#b7c9bd; --dark-square:#47645c; }
* { box-sizing:border-box; }
html,body { margin:0; background:var(--bg); color:var(--text); font-family:Inter,ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif; }
a { color:var(--accent); }
button,textarea,input,select { font:inherit; }
button { border:1px solid transparent; background:var(--accent); color:#062019; border-radius:9px; padding:9px 12px; min-height:44px; cursor:pointer; font-weight:700; }
button.secondary { background:#152527; color:var(--text); border-color:var(--line); }
button:hover { filter:brightness(1.08); }
button:disabled { opacity:.45; cursor:not-allowed; }
button:focus-visible,a:focus-visible,textarea:focus-visible,input:focus-visible,select:focus-visible,[tabindex]:focus-visible { outline:2px solid var(--accent); outline-offset:2px; }
[hidden] { display:none !important; }
.topbar { flex-wrap:wrap; display:flex; align-items:center; justify-content:space-between; gap:12px; padding:6px 20px; min-height:54px; border-bottom:1px solid var(--line); }
.brand { display:flex; align-items:center; gap:8px; text-decoration:none; color:var(--text); font-weight:800; letter-spacing:-.02em; white-space:nowrap; }
.topbar nav { display:flex; align-items:center; gap:14px; font-size:.85rem; }
.topbar nav a { display:flex; align-items:center; min-height:44px; text-decoration:none; }
.text-button { background:transparent; color:var(--accent); padding:6px 2px; font-weight:400; }
/* A bounded application surface. Board sizing uses BOTH stage dimensions.
   Only the move list and dialogs scroll; no content is cropped to fake a fit. */
.app-frame { height:100vh; height:100dvh; display:flex; flex-direction:column; position:relative; z-index:1; background:var(--bg); }
.app-main { flex:1; min-height:0; width:min(1480px,100%); margin:auto; padding:12px 20px 16px; display:flex; flex-direction:column; gap:12px; }
.app-heading { display:flex; align-items:baseline; justify-content:space-between; gap:16px; }
h1 { margin:0; font-size:clamp(1.2rem,2vw,1.8rem); letter-spacing:-.04em; line-height:1.2; }
.app-heading span { color:var(--muted); font-size:.8rem; }
.workspace { flex:1; min-height:0; display:grid; grid-template-columns:minmax(0,1fr) minmax(320px,390px); gap:24px; }
.board-column { min-width:0; min-height:0; display:flex; flex-direction:column; gap:10px; }
.board-stage { flex:1; min-width:0; min-height:0; container-type:size; display:grid; place-items:center; }
.board-area { --bar:28px; height:min(100cqh,calc(100cqw - var(--bar))); width:calc(min(100cqh,calc(100cqw - var(--bar))) + var(--bar)); display:grid; grid-template-columns:20px minmax(0,1fr); gap:8px; }
.board { position:relative; width:100%; height:100%; aspect-ratio:1/1; display:grid; grid-template-columns:repeat(8,minmax(0,1fr)); grid-template-rows:repeat(8,minmax(0,1fr)); min-width:0; min-height:0; container-type:inline-size; border-radius:8px; overflow:hidden; box-shadow:0 10px 35px #0003; }
.square { position:relative; display:grid; place-items:center; border:0; border-radius:0; padding:0; min-width:0; min-height:0; font-size:0; overflow:hidden; touch-action:manipulation; }
.square.light { background:var(--light-square); }.square.dark { background:var(--dark-square); }
.square.last { box-shadow:inset 0 0 0 100px #e7d97740; }
.square.check { background:#b55a53; }
.square.selected { outline:3px solid #e2ffe9; outline-offset:-3px; }
.square:focus-visible { outline:3px dashed #08251c; outline-offset:-4px; z-index:2; }
.square.target::after { content:""; position:absolute; width:22%; aspect-ratio:1; background:#08251c65; border:1px solid #e9fff266; border-radius:50%; }
.square.capture::after { content:""; position:absolute; inset:5%; border:3px solid #edf8ddc9; box-shadow:0 0 0 1px #122820; border-radius:50%; }
.piece { position:absolute; width:91%; height:91%; pointer-events:none; overflow:visible; }
.piece g, .piece path, .piece circle { stroke-linejoin:round; stroke-linecap:round; }
.piece-boundary { fill:none; stroke:#151b1d; stroke-width:4.6; }
.piece-body { fill:var(--piece-fill); stroke:var(--piece-edge); stroke-width:2; }
.piece-detail { fill:none; stroke:var(--piece-edge); stroke-width:1.6; }
.piece.white { --piece-fill:#fff4dc; --piece-edge:#1d2528; }
.piece.black { --piece-fill:#22282d; --piece-edge:#fff4dc; }
.coord { position:absolute; font:700 clamp(8px,1.5cqw,12px)/1 system-ui; color:#18362a; pointer-events:none; }
.coord.file { bottom:3px; right:4px; }.coord.rank { top:3px; left:4px; }.square.dark .coord { color:#f4f8e9; }
.eval-wrap { height:100%; min-height:0; background:#f4efdf; border-radius:6px; overflow:hidden; position:relative; }
.eval-black { position:absolute; top:0; left:0; width:100%; height:50%; background:#202529; transition:height .18s ease; }
.eval-wrap.flipped .eval-black { top:auto; bottom:0; }
.eval-text { position:absolute; left:50%; bottom:6px; transform:translateX(-50%); z-index:2; color:#151b1d; background:#fff9; border-radius:4px; padding:4px 1px; font-size:11px; font-weight:800; writing-mode:vertical-rl; }
.best-move-overlay { position:absolute; inset:0; width:100%; height:100%; z-index:3; pointer-events:none; opacity:.85; }
.best-move-overlay line { stroke:#efb74d; stroke-width:.16; stroke-linecap:round; }.best-move-overlay polygon { fill:#efb74d; }
.panel { min-width:0; min-height:0; border:1px solid var(--line); background:var(--surface); border-radius:14px; padding:16px; display:flex; flex-direction:column; gap:10px; }
.status-row { display:flex; align-items:center; gap:9px; font-size:.9rem; }
.dot { flex:none; width:9px; height:9px; border-radius:50%; background:#d3a74b; box-shadow:0 0 0 4px #d3a74b1f; }.dot.ready { background:#65d6a8; box-shadow:0 0 0 4px #65d6a81f; }.dot.error { background:#ef7777; box-shadow:0 0 0 4px #ef77771f; }
.game-state { margin:0; font-size:.9rem; }
.history-nav { display:grid; grid-template-columns:1fr auto 1fr; align-items:center; gap:8px; }.history-nav span { color:var(--muted); font-size:.8rem; }
.primary-actions { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:8px; }
.details-home { flex:1; min-height:0; display:flex; }
.analysis-details { display:flex; flex-direction:column; gap:10px; flex:1; min-width:0; min-height:0; }
.metric-grid { display:grid; grid-template-columns:repeat(3,minmax(0,1fr)); gap:8px; }
.metric-grid>div,.line-card { background:var(--surface2); border:1px solid var(--line); border-radius:10px; padding:10px; min-width:0; }
.metric-grid span,.line-card>span { display:block; color:var(--muted); font-size:.7rem; text-transform:uppercase; letter-spacing:.07em; margin-bottom:4px; }
.metric-grid strong { font-size:1.1rem; }
.pv { font: .8rem/1.6 ui-monospace,SFMono-Regular,Menlo,monospace; overflow-wrap:anywhere; }
.move-heading { display:flex; flex-wrap:wrap; align-items:baseline; justify-content:space-between; gap:6px; font-size:.85rem; }.move-heading span { color:var(--muted); overflow-wrap:anywhere; max-width:100%; }
.move-list { min-height:48px; flex:1; overflow:auto; overscroll-behavior:contain; display:flex; flex-wrap:wrap; align-content:flex-start; gap:4px; padding:4px; border:1px solid var(--line); border-radius:8px; }
.move-list button { font-size:.85rem; font-weight:500; padding:5px 8px; background:transparent; color:var(--text); }
.move-list button[aria-current="step"] { background:#7fe4c422; color:var(--accent); border-color:var(--accent); }
.message { color:var(--muted); font-size:.8rem; line-height:1.4; margin:0; overflow-wrap:anywhere; }
.panel>.message:empty { display:none; }
.editor-ribbon { border:1px solid var(--accent); border-radius:10px; padding:8px; background:var(--surface); display:flex; gap:8px; align-items:center; justify-content:space-between; }
.editor-ribbon strong,.editor-ribbon span { display:block; font-size:.8rem; }.editor-ribbon span { color:var(--muted); }.edit-actions { display:flex; gap:6px; }
.editor-ribbon button { padding:7px 10px; }
.tools-compact .app-heading { display:none; }
.tools-compact .details-home { display:none; }
.tools-compact .panel { align-self:center; gap:8px; padding:12px; }
.tools-compact .status-row { flex-wrap:wrap; }.tools-compact #detailsOpen { margin-left:auto; font-size:.8rem; padding:6px 9px; }
.tools-compact .message { max-height:4.2em; overflow:auto; }
@media(max-width:700px) and (orientation:portrait) {
 .topbar { padding:4px 10px; gap:6px; }.topbar nav { gap:8px; font-size:.75rem; }
 .app-main { padding:8px 10px max(8px,env(safe-area-inset-bottom)); gap:8px; }
 .workspace { grid-template-columns:minmax(0,1fr); grid-template-rows:minmax(0,1fr) auto; gap:8px; }
 .panel { width:100%; }.tools-compact .panel { padding:8px; }
 .primary-actions { grid-template-columns:repeat(4,minmax(0,1fr)); gap:5px; }
 .primary-actions button { padding:6px 4px; font-size:.8rem; }
 .editor-ribbon { flex-wrap:wrap; gap:4px; }.editor-ribbon>div:first-child { display:flex; align-items:center; gap:8px; }
 .edit-actions { width:100%; }.edit-actions button { flex:1; font-size:.8rem; padding:6px; }
}
@media(orientation:landscape) and (max-height:600px) {
 .topbar { min-height:44px; padding:0 12px; }
 .app-main { padding:6px 12px; }.workspace { gap:12px; grid-template-columns:minmax(0,1fr) minmax(260px,40%); }
 .editor-ribbon { flex-wrap:wrap; padding:5px; }.edit-actions { flex:1; }.edit-actions button { font-size:.75rem; padding:5px; }
 .editor-ribbon>div:first-child { display:none; }
}
/* At large text sizes, controls wrap instead of truncating; details stay accessible. */
dialog { width:min(620px,calc(100% - 24px)); max-height:calc(100dvh - 24px); overflow:auto; overscroll-behavior:contain; padding:20px; border:1px solid var(--line); border-radius:14px; background:var(--surface); color:var(--text); }
dialog::backdrop { background:#000b; }
.dialog-heading { display:flex; align-items:center; justify-content:space-between; gap:12px; margin-bottom:16px; }
h2 { margin:0 0 12px; font-size:1.2rem; }.dialog-heading h2 { margin:0; }
dialog label { display:block; margin:8px 0; font-size:.9rem; }
textarea,input:not([type="checkbox"]),select { width:100%; background:#081213; color:var(--text); border:1px solid var(--line); border-radius:9px; padding:10px; min-height:44px; }
textarea { resize:vertical; display:block; margin:8px 0; max-height:45dvh; }
.actions,.promotion-options { display:flex; flex-wrap:wrap; gap:8px; margin:12px 0; }
.tool-tabs { display:flex; gap:8px; margin-bottom:16px; }.tool-tabs button { flex:1; }
.help { font-size:.85rem; color:var(--muted); line-height:1.6; }
.metadata-grid { display:grid; grid-template-columns:1fr 1fr; gap:8px; }
fieldset { margin:12px 0; border:1px solid var(--line); border-radius:8px; }fieldset label { display:inline-flex; align-items:center; gap:6px; margin:4px 12px 4px 0; min-height:36px; }
#detailsHost .move-list { max-height:35dvh; flex:none; }#detailsHost .analysis-details { min-height:250px; }
.shell { width:min(850px,calc(100% - 32px)); margin:32px auto 60px; line-height:1.7; }.shell h1 { font-size:2.2rem; margin-bottom:24px; }.shell h2 { margin-top:28px; }.shell p { color:var(--muted); }
/* No manual ad slots are placed in the application. Keep the AdSense loader,
   and configure Auto ads page exclusions for / and /index.html (INSTALL.txt).
   Do not conceal or reposition third-party ads with CSS. */
@media(prefers-reduced-motion:reduce) { * { transition:none !important; } }

@media(max-width:700px) {
 .large-text .topbar nav>a { display:none; }
 .large-text .topbar nav { font-size:.75rem; }
 .large-text .history-nav button span { display:none; }
 .large-text .primary-actions { grid-template-columns:repeat(2,minmax(0,1fr)); }
 .large-text .primary-actions button { overflow-wrap:anywhere; }
 .large-text .status-row { font-size:.75rem; }
}
.large-text .dialog-heading { flex-wrap:wrap; }
.large-text .tool-tabs { flex-wrap:wrap; }
.large-text .tool-tabs button { min-width:0; }
.large-text .metadata-grid { grid-template-columns:minmax(0,1fr); }
@media(orientation:landscape) and (max-height:600px) {
 .large-text .workspace { grid-template-columns:minmax(0,1fr) minmax(290px,44%); }
 .large-text .panel { gap:6px; }
 .large-text .primary-actions button { font-size:.8rem; padding:6px 4px; }
 .large-text #detailsOpen { font-size:.65rem; }
 .large-text .game-state { font-size:.75rem; }
}
