:root{--bg:#0b1110;--panel:#121b19;--panel2:#172320;--line:#24342f;--text:#eef7f3;--muted:#94aaa3;--brand:#68e0b3;--brand2:#36b98a;--danger:#ff7a7a;--gold:#e7c66a;--sq1:#d7e7dd;--sq2:#4d7669;--und1:#b5b2d5;--und2:#4c466e;--shadow:0 18px 50px rgba(0,0,0,.28)}*{box-sizing:border-box}html{scroll-behavior:smooth}body{margin:0;background:radial-gradient(circle at 10% 0,#13201c 0,transparent 38%),var(--bg);color:var(--text);font:15px/1.5 Inter,ui-sans-serif,system-ui,-apple-system,Segoe UI,Roboto,Arial,sans-serif;min-height:100vh}a{color:inherit;text-decoration:none}button,input{font:inherit}.topbar{position:sticky;top:0;z-index:30;display:flex;align-items:center;justify-content:space-between;padding:16px clamp(18px,4vw,56px);background:rgba(11,17,16,.84);backdrop-filter:blur(16px);border-bottom:1px solid rgba(255,255,255,.06)}.brand{display:flex;gap:10px;align-items:center;font-size:18px}.brand-mark{display:grid;place-items:center;width:34px;height:34px;border-radius:10px;background:linear-gradient(145deg,var(--brand),#26765d);color:#092018;font-size:23px;box-shadow:0 0 28px rgba(104,224,179,.2)}.topbar nav{display:flex;align-items:center;gap:18px}.topbar nav>a:not(.btn){color:var(--muted)}.topbar nav>a:hover{color:var(--text)}.user-chip{padding:8px 12px;border:1px solid var(--line);border-radius:999px;color:#cce5dc}.inline{display:inline}.link-btn{background:none;border:0;color:var(--muted);cursor:pointer}.btn{display:inline-flex;align-items:center;justify-content:center;gap:8px;border:0;border-radius:11px;padding:12px 18px;background:linear-gradient(135deg,var(--brand),var(--brand2));color:#082018;font-weight:800;cursor:pointer;box-shadow:0 9px 26px rgba(54,185,138,.18)}.btn:hover{transform:translateY(-1px)}.btn.small{padding:8px 12px;border-radius:9px;font-size:13px}.btn.ghost{background:transparent;color:var(--text);border:1px solid var(--line);box-shadow:none}.btn.danger{background:rgba(255,122,122,.12);border:1px solid rgba(255,122,122,.32);color:#ffb1b1;box-shadow:none}.btn.wide{width:100%}.hero-wrap{max-width:1220px;margin:auto;padding:52px 26px 80px}.hero{display:grid;grid-template-columns:1.05fr .95fr;gap:60px;align-items:center;min-height:560px}.eyebrow{color:var(--brand);font-size:12px;font-weight:900;letter-spacing:.16em;margin-bottom:12px}.hero h1{font-size:clamp(42px,6vw,74px);line-height:1.02;letter-spacing:-.055em;margin:0 0 24px}.hero h1 span{color:var(--brand)}.hero p{max-width:670px;font-size:18px;color:var(--muted)}.hero-actions{display:flex;gap:12px;margin-top:30px}.hero-board{height:430px;position:relative;perspective:900px}.mini-board{position:absolute;width:330px;height:330px;border-radius:18px;box-shadow:var(--shadow);background:conic-gradient(from 90deg,#50786b 25%,#d8e5dd 0 50%,#50786b 0 75%,#d8e5dd 0) 0 0/82.5px 82.5px;border:10px solid #1b2b27}.layer-a{right:80px;top:22px;transform:rotateX(58deg) rotateZ(-10deg)}.layer-b{right:15px;top:104px;opacity:.68;filter:hue-rotate(55deg);transform:rotateX(58deg) rotateZ(-10deg)}.depth-label{position:absolute;right:10px;top:40px;color:var(--brand);font-weight:900;letter-spacing:.2em}.rules-grid{display:grid;grid-template-columns:repeat(4,1fr);gap:14px}.rules-grid article,.panel,.stat{background:linear-gradient(180deg,rgba(255,255,255,.035),rgba(255,255,255,.015));border:1px solid var(--line);border-radius:16px;box-shadow:var(--shadow)}.rules-grid article{padding:24px}.rules-grid article>span{color:var(--brand);font-weight:900}.rules-grid h3{margin:18px 0 8px}.rules-grid p{color:var(--muted);margin:0}.auth-shell{min-height:calc(100vh - 140px);display:grid;place-items:center;padding:34px 18px}.auth-card{width:min(440px,100%);padding:34px;background:var(--panel);border:1px solid var(--line);border-radius:20px;box-shadow:var(--shadow)}.auth-icon{font-size:50px;color:var(--brand)}.auth-card h1{margin:6px 0}.auth-card>p{color:var(--muted)}.form-stack{display:grid;gap:15px;margin-top:24px}.form-stack label{display:grid;gap:7px;color:#cbdad5;font-weight:700}.form-stack input,.search{width:100%;border:1px solid var(--line);background:#0c1412;color:var(--text);padding:12px 13px;border-radius:10px;outline:none}.form-stack input:focus,.search:focus{border-color:var(--brand)}.switch-auth{text-align:center;margin-top:20px!important}.switch-auth a{color:var(--brand);font-weight:700}.toast,.notice{max-width:760px;margin:16px auto;padding:12px 16px;border-radius:10px;border:1px solid var(--line);background:var(--panel)}.toast.success,.notice.success{border-color:rgba(104,224,179,.35);color:#aef2d7}.toast.error,.notice.danger{border-color:rgba(255,122,122,.35);color:#ffb3b3}.app-shell{max-width:1220px;margin:auto;padding:34px 24px 70px}.welcome-row{display:flex;justify-content:space-between;align-items:flex-end;margin:12px 0 26px}.welcome-row h1{font-size:34px;margin:0}.welcome-row p{color:var(--muted);margin:5px 0}.status-card{border:1px solid var(--line);border-radius:12px;padding:10px 14px;color:#cfe2db}.dot{width:8px;height:8px;border-radius:50%;display:inline-block;margin-right:7px}.online{background:var(--brand);box-shadow:0 0 10px var(--brand)}.dashboard-grid{display:grid;grid-template-columns:1.3fr .7fr;gap:16px}.panel{padding:20px}.panel.span-2{grid-column:1/-1}.panel.compact{padding:16px}.panel-head{display:flex;justify-content:space-between;gap:20px;align-items:center;margin-bottom:15px}.panel-head h2,.panel h3{margin:0}.panel-head p{margin:4px 0 0;color:var(--muted)}.search{max-width:260px}.player-list,.invite-list,.game-list{display:grid;gap:10px}.player,.invite,.game-row{display:flex;align-items:center;justify-content:space-between;gap:14px;padding:12px 13px;background:#0d1614;border:1px solid #1c2a26;border-radius:12px}.player-main,.avatar-line{display:flex;align-items:center;gap:10px}.avatar{width:38px;height:38px;border-radius:12px;display:grid;place-items:center;background:#21362f;color:var(--brand);font-weight:900}.player small,.avatar-line small{display:block;color:var(--muted)}.badge{display:inline-flex;padding:4px 8px;border-radius:999px;background:#1c2925;color:#bdd1ca;font-size:12px}.badge.good{color:#9ff0ce;background:rgba(104,224,179,.1)}.badge.bad{color:#ffb1b1;background:rgba(255,122,122,.1)}.game-shell{max-width:1500px;margin:auto;padding:20px 22px 60px}.game-top{display:flex;align-items:center;justify-content:space-between;gap:15px;margin:4px 0 18px}.back{color:var(--muted)}.game-title{font-weight:900;font-size:18px}.game-layout{display:grid;grid-template-columns:minmax(0,1fr) 320px;gap:18px}.boards-area{display:grid;grid-template-columns:minmax(290px,1fr) 56px minmax(290px,1fr);align-items:center;gap:10px}.board-card{background:#111a18;border:1px solid var(--line);border-radius:16px;padding:14px;box-shadow:var(--shadow)}.underground-card{background:linear-gradient(180deg,#171729,#11111d)}.board-label{display:flex;align-items:center;gap:10px;margin-bottom:10px}.board-label small{display:block;color:var(--muted)}.layer-dot{width:12px;height:12px;border-radius:50%;box-shadow:0 0 12px currentColor}.layer-dot.surface{background:var(--brand);color:var(--brand)}.layer-dot.underground{background:#a9a2f2;color:#a9a2f2}.depth-connector{text-align:center;color:var(--brand)}.depth-connector span{font-size:32px;display:block}.depth-connector small{font-size:9px;letter-spacing:.12em}.chess-board{display:grid;grid-template-columns:repeat(8,1fr);width:100%;aspect-ratio:1;border-radius:8px;overflow:hidden;border:1px solid rgba(255,255,255,.1)}.square{position:relative;display:grid;place-items:center;aspect-ratio:1;cursor:pointer;user-select:none}.square.light{background:var(--sq1)}.square.dark{background:var(--sq2)}#board-underground .square.light{background:var(--und1)}#board-underground .square.dark{background:var(--und2)}.square.selected{outline:4px solid var(--gold);outline-offset:-4px}.square.linked{box-shadow:inset 0 0 0 4px rgba(231,198,106,.48)}.piece{font-size:clamp(29px,4.3vw,58px);line-height:1;filter:drop-shadow(0 4px 2px rgba(0,0,0,.35));text-shadow:0 1px 0 rgba(255,255,255,.22);transform:translateY(-1px)}.coord{position:absolute;font-size:9px;font-weight:900;opacity:.6}.coord.file{right:3px;bottom:1px}.coord.rank{left:3px;top:1px}.game-sidebar{display:grid;align-content:start;gap:12px}.player-vs{display:grid;gap:9px}.vs-row{display:flex;justify-content:space-between;align-items:center}.turn-banner{margin-top:13px;padding:10px;border-radius:10px;background:#0d1714;color:var(--brand);font-weight:800;text-align:center}.tunnel-stats{display:grid;grid-template-columns:1fr 1fr;gap:8px;margin-top:10px}.tstat{background:#0d1514;border-radius:9px;padding:9px}.tstat small{display:block;color:var(--muted)}.hint{color:var(--muted);font-size:13px}.move-log{max-height:300px;overflow:auto;display:grid;gap:5px;margin-top:10px}.move-item{display:grid;grid-template-columns:34px 1fr;gap:7px;padding:7px 8px;border-radius:8px;background:#0e1715;font-size:12px}.move-item span:first-child{color:var(--muted)}.stats-row{display:grid;grid-template-columns:repeat(3,1fr);gap:12px;margin-bottom:16px}.stat{padding:20px}.stat b{display:block;font-size:28px;color:var(--brand)}.stat span{color:var(--muted)}.admin-setting{display:flex;align-items:center;justify-content:space-between;margin-bottom:16px}.admin-setting h2{margin:0}.admin-setting p{margin:4px 0;color:var(--muted)}.switch{position:relative;width:54px;height:30px}.switch input{display:none}.switch span{position:absolute;inset:0;border-radius:999px;background:#34433e;cursor:pointer;transition:.2s}.switch span:after{content:"";position:absolute;width:22px;height:22px;left:4px;top:4px;border-radius:50%;background:white;transition:.2s}.switch input:checked+span{background:var(--brand2)}.switch input:checked+span:after{transform:translateX(24px)}.table-wrap{overflow:auto}table{width:100%;border-collapse:collapse;min-width:780px}th,td{text-align:left;padding:12px;border-bottom:1px solid var(--line)}th{color:var(--muted);font-size:12px}.actions{display:flex;gap:6px}.icon-btn{border:1px solid var(--line);background:#111c19;color:var(--text);border-radius:8px;padding:6px 9px;cursor:pointer}.danger-text{color:#ff9d9d}.skeleton-box{min-height:100px;color:var(--muted)}footer{display:flex;justify-content:space-between;gap:20px;padding:22px clamp(20px,4vw,56px);border-top:1px solid var(--line);color:var(--muted);font-size:12px}
@media(max-width:1100px){.game-layout{grid-template-columns:1fr}.game-sidebar{grid-template-columns:repeat(2,1fr)}.moves-panel{grid-column:1/-1}.boards-area{grid-template-columns:1fr 38px 1fr}.piece{font-size:clamp(27px,5vw,52px)}}@media(max-width:850px){.hero{grid-template-columns:1fr}.hero-board{display:none}.rules-grid{grid-template-columns:1fr 1fr}.dashboard-grid{grid-template-columns:1fr}.panel.span-2{grid-column:auto}.boards-area{grid-template-columns:1fr}.depth-connector{display:flex;justify-content:center;align-items:center;gap:8px}.depth-connector span{font-size:25px}.game-sidebar{grid-template-columns:1fr}.moves-panel{grid-column:auto}.topbar nav>a:not(.btn){display:none}}@media(max-width:560px){.topbar{padding:12px 14px}.brand span:last-child{display:none}.user-chip{display:none}.hero-wrap,.app-shell,.game-shell{padding-left:14px;padding-right:14px}.hero{min-height:auto;padding-top:28px}.hero h1{font-size:42px}.rules-grid{grid-template-columns:1fr}.welcome-row{align-items:flex-start;gap:18px}.status-card{display:none}.panel-head{align-items:flex-start;flex-direction:column}.search{max-width:none}.stats-row{grid-template-columns:1fr}.game-top{flex-wrap:wrap}.game-title{order:3;width:100%}.board-card{padding:8px}.piece{font-size:clamp(28px,11vw,48px)}footer{flex-direction:column}}
/* 2026 UI upgrade: reference green/cream board, clearer Staunton glyphs, replay + AI */
:root{--piece-white:#F7F4EA;--piece-black:#555351}.nav-select{border:1px solid var(--line);background:#0d1614;color:var(--text);border-radius:9px;padding:7px 9px}.wide-search{max-width:none;margin-bottom:12px}.compact-select{max-width:170px}.difficulty-cards{display:grid;grid-template-columns:repeat(3,1fr);gap:8px;margin:8px 0 14px}.difficulty{border:1px solid var(--line);background:#0d1614;color:var(--text);border-radius:12px;padding:13px 8px;cursor:pointer;display:grid;gap:3px;place-items:center}.difficulty:first-letter{font-size:24px}.difficulty.active{border-color:var(--brand);box-shadow:inset 0 0 0 1px var(--brand);background:rgba(104,224,179,.08)}.mode-pill{color:var(--brand)}.vs{color:#8ea39c}.game-top-actions{display:flex;gap:8px}.panel-head.mini{margin-bottom:8px}.replay-controls{display:grid;grid-template-columns:repeat(5,1fr);gap:6px}.replay-controls .icon-btn{padding:7px 4px}.move-item{border:1px solid transparent;color:var(--text);width:100%;text-align:left;cursor:pointer}.move-item.active{border-color:var(--brand);background:rgba(104,224,179,.09)}
#board-underground .square.light{background:color-mix(in srgb,var(--sq1) 82%,#9389c8 18%)}#board-underground .square.dark{background:color-mix(in srgb,var(--sq2) 80%,#51466f 20%)}
.piece{font-family:"DejaVu Sans","Segoe UI Symbol","Noto Sans Symbols 2",serif;font-weight:400;font-size:clamp(32px,4.8vw,64px);filter:drop-shadow(0 2px 1px rgba(0,0,0,.28));transform:translateY(-1px);-webkit-text-stroke:.7px rgba(20,20,20,.7)}.piece-w{color:var(--piece-white);text-shadow:0 1px 0 #222,1px 0 0 #222,0 -1px 0 #222,-1px 0 0 #222}.piece-b{color:var(--piece-black);-webkit-text-stroke:.45px rgba(245,245,245,.18);text-shadow:0 1px 0 rgba(255,255,255,.12)}.mini-piece{font-family:"DejaVu Sans","Segoe UI Symbol",serif;font-size:22px}.white-piece{color:var(--piece-white);text-shadow:0 1px #222,1px 0 #222}.black-piece{color:var(--piece-black);text-shadow:0 1px rgba(255,255,255,.15)}
.appearance-grid{display:grid;grid-template-columns:2fr repeat(4,1fr);gap:12px;align-items:end;margin:12px 0}.appearance-grid label{display:grid;gap:7px;color:var(--muted);font-size:12px;font-weight:700}.appearance-grid input[type=color]{width:100%;height:44px;padding:3px;border:1px solid var(--line);background:#0c1412;border-radius:9px}.theme-preview{display:flex;width:160px;height:80px;border-radius:10px;overflow:hidden;margin:8px 0 14px;border:1px solid var(--line)}.preview-sq{flex:1;display:grid;place-items:center}.light-preview{background:var(--sq1)}.dark-preview{background:var(--sq2)}.piece-demo{font:54px/1 "DejaVu Sans","Segoe UI Symbol",serif}.piece-demo.white{color:var(--piece-white);text-shadow:0 1px #222,1px 0 #222}.piece-demo.black{color:var(--piece-black)}
@media(max-width:850px){.appearance-grid{grid-template-columns:1fr 1fr}.difficulty-cards{grid-template-columns:repeat(3,1fr)}}@media(max-width:560px){.appearance-grid{grid-template-columns:1fr 1fr}.replay-controls{grid-template-columns:repeat(5,1fr)}.piece{font-size:clamp(31px,12vw,52px)}}

/* Layout stability: move history must never push or vertically recenter the boards. */
.game-layout{align-items:start}
.boards-area{align-self:start;min-width:0;position:relative;top:0}
.game-sidebar{align-self:start;min-width:0;max-height:calc(100vh - 118px);overflow:hidden}
.moves-panel{display:flex;flex-direction:column;min-height:0}
.move-log{height:260px;max-height:260px;min-height:120px;overflow-y:auto;overflow-x:hidden;overscroll-behavior:contain;scrollbar-gutter:stable;padding-right:3px}
#gameMessage{max-height:92px;overflow:auto;margin:0}
@media(max-width:1100px){.game-sidebar{max-height:none;overflow:visible}.move-log{height:220px;max-height:220px}}
@media(max-width:850px){.move-log{height:200px;max-height:200px}}

/* High-contrast custom Staunton-style piece set. SVG masks inherit admin colors. */
.piece-icon,.mini-piece-icon,.piece-preview-icon{display:block;background:currentColor;filter:drop-shadow(0 2px 1px rgba(0,0,0,.26));-webkit-mask-position:center;mask-position:center;-webkit-mask-repeat:no-repeat;mask-repeat:no-repeat;-webkit-mask-size:contain;mask-size:contain}
.piece-icon{width:78%;height:78%}.mini-piece-icon{width:26px;height:26px;display:inline-block;vertical-align:middle}.piece-preview-icon{width:58px;height:58px}
.piece-icon.piece-w,.mini-piece-icon.piece-w,.piece-preview-icon.piece-w{color:var(--piece-white);filter:drop-shadow(0 0 1px #111) drop-shadow(0 2px 1px rgba(0,0,0,.28))}
.piece-icon.piece-b,.mini-piece-icon.piece-b,.piece-preview-icon.piece-b{color:var(--piece-black);filter:drop-shadow(0 0 1px rgba(255,255,255,.34)) drop-shadow(0 2px 1px rgba(0,0,0,.28))}
.type-p{-webkit-mask-image:url('pieces/p.svg');mask-image:url('pieces/p.svg')}.type-n{-webkit-mask-image:url('pieces/n.svg');mask-image:url('pieces/n.svg')}.type-b{-webkit-mask-image:url('pieces/b.svg');mask-image:url('pieces/b.svg')}.type-r{-webkit-mask-image:url('pieces/r.svg');mask-image:url('pieces/r.svg')}.type-q{-webkit-mask-image:url('pieces/q.svg');mask-image:url('pieces/q.svg')}.type-k{-webkit-mask-image:url('pieces/k.svg');mask-image:url('pieces/k.svg')}
\n/* Legal move hints: rendered from server-validated moves on one or both layers. */
.square.legal-target{cursor:pointer}
.move-hint-dot{position:absolute;z-index:4;width:25%;height:25%;border-radius:50%;background:rgba(15,45,35,.48);box-shadow:0 0 0 2px rgba(255,255,255,.28);pointer-events:none}
.square.legal-target:has(.piece-icon) .move-hint-dot,.square.legal-capture .move-hint-dot{width:78%;height:78%;background:transparent;border:5px solid rgba(185,54,54,.72);box-shadow:0 0 0 2px rgba(255,255,255,.15) inset}
.square.legal-cross{box-shadow:inset 0 0 0 4px rgba(83,211,255,.82)}
.square.legal-cross .move-hint-dot{background:rgba(51,183,229,.68);box-shadow:0 0 12px rgba(51,183,229,.72),0 0 0 2px rgba(255,255,255,.35)}
.square.legal-cross:has(.piece-icon) .move-hint-dot{background:transparent;border-color:rgba(51,183,229,.92)}
.square.selected{z-index:5;outline:4px solid var(--gold);outline-offset:-4px}
@media(max-width:560px){.square.legal-target:has(.piece-icon) .move-hint-dot,.square.legal-capture .move-hint-dot{border-width:4px}}

/* Stable two-board stage: sidebar/history updates never reflow or recenter boards. */
@media(min-width:1101px){
  .game-layout{grid-template-columns:minmax(0,1fr) 330px;align-items:start}
  .boards-area{align-items:start;contain:layout paint;min-height:0}
  .game-sidebar{position:sticky;top:82px;align-self:start;max-height:calc(100vh - 96px);overflow:hidden}
  .moves-panel{min-height:0;max-height:340px;overflow:hidden}
  .move-log{height:250px;min-height:250px;max-height:250px;contain:layout;scrollbar-gutter:stable both-edges}
}
.player,.invite,.game-row,.move-item,.square,.difficulty,.btn{transition:transform .14s ease,border-color .14s ease,background-color .14s ease,box-shadow .14s ease,opacity .14s ease}
.move-log{scroll-behavior:smooth}
.square.legal-target:hover{box-shadow:inset 0 0 0 4px rgba(255,255,255,.42)}

/* Time controls + smooth AJAX match setup */
.match-options{display:flex;gap:10px;align-items:end;flex-wrap:wrap;justify-content:flex-end}.time-field{display:grid;gap:5px;color:var(--muted);font-size:11px;font-weight:800}.time-input{width:118px;max-width:118px}.ai-time{margin:2px 0 14px}.ai-time .time-input{max-width:none;width:100%}
.clock-grid{display:grid;grid-template-columns:1fr 1fr;gap:8px;margin-top:12px}.chess-clock{display:flex;align-items:center;justify-content:space-between;gap:8px;background:#0b1210;border:1px solid var(--line);border-radius:11px;padding:10px 11px;transition:.18s}.chess-clock b{font-variant-numeric:tabular-nums;font-size:20px;letter-spacing:.02em}.chess-clock.active-clock{border-color:var(--brand);box-shadow:inset 0 0 0 1px rgba(104,224,179,.24),0 0 18px rgba(104,224,179,.08)}.chess-clock.low-time b{color:#ff9d9d}.chess-clock.low-time.active-clock{border-color:rgba(255,122,122,.58);animation:clockPulse 1s ease-in-out infinite alternate}@keyframes clockPulse{to{box-shadow:inset 0 0 0 1px rgba(255,122,122,.24),0 0 18px rgba(255,122,122,.18)}}
@media(max-width:700px){.match-options{width:100%;justify-content:stretch}.match-options>*{flex:1}.time-input{width:100%;max-width:none}.clock-grid{grid-template-columns:1fr 1fr}.chess-clock b{font-size:18px}}

/* Profile + AJAX admin editor */
.profile-grid{display:grid;grid-template-columns:minmax(0,1.15fr) minmax(320px,.85fr);gap:18px;align-items:start}.profile-shell .form-stack{max-width:680px}.form-two{display:grid;grid-template-columns:1fr 1fr;gap:12px}.edit-dialog{width:min(620px,calc(100vw - 28px));border:1px solid var(--line);border-radius:18px;background:#111b18;color:var(--text);padding:0;box-shadow:0 28px 90px rgba(0,0,0,.5)}.edit-dialog::backdrop{background:rgba(3,8,7,.72);backdrop-filter:blur(4px)}.edit-dialog form{padding:20px}.dialog-head{display:flex;align-items:center;justify-content:space-between;gap:12px}.dialog-head h2{margin:0}.avatar{background:var(--avatar-color,#5D7C68)}
@media(max-width:850px){.profile-grid{grid-template-columns:1fr}}@media(max-width:560px){.form-two{grid-template-columns:1fr}.edit-dialog form{padding:15px}}

/* System modal: replaces native alert/confirm, animated and fully themeable. */
.ui-modal[hidden]{display:none}.ui-modal{position:fixed;inset:0;z-index:1000;display:grid;place-items:center;padding:20px;opacity:0;pointer-events:none;transition:opacity .18s ease}.ui-modal.open{opacity:1;pointer-events:auto}.ui-modal-backdrop{position:absolute;inset:0;background:rgba(4,8,7,.74);backdrop-filter:blur(8px)}.ui-modal-card{position:relative;width:min(460px,100%);padding:26px;border:1px solid rgba(255,255,255,.1);border-radius:22px;background:linear-gradient(180deg,#17231f,#0e1715);box-shadow:0 28px 90px rgba(0,0,0,.55);transform:translateY(16px) scale(.97);transition:transform .2s cubic-bezier(.2,.8,.2,1);text-align:center}.ui-modal.open .ui-modal-card{transform:none}.ui-modal-icon{margin:auto;width:48px;height:48px;display:grid;place-items:center;border-radius:15px;background:rgba(104,224,179,.11);color:var(--brand);font-size:28px}.ui-modal-card h2{margin:13px 0 7px}.ui-modal-card p{margin:0;color:var(--muted);white-space:pre-line}.ui-modal-actions{display:flex;justify-content:center;gap:9px;margin-top:22px}.result-chip{display:inline-flex;margin-top:13px;padding:6px 10px;border-radius:999px;background:#0b1311;border:1px solid var(--line);color:#b8cbc5;font-size:12px}.danger-modal .ui-modal-icon{color:#ff9f9f;background:rgba(255,122,122,.1)}

/* In-game rules stay in document flow, so they never cover the boards/clocks/history. */
.game-rules-panel{margin:0 0 16px;padding:18px;border:1px solid var(--line);border-radius:16px;background:linear-gradient(180deg,rgba(23,35,32,.98),rgba(15,23,21,.98));box-shadow:var(--shadow);animation:rulesIn .2s ease}.game-rules-panel[hidden]{display:none}.rules-panel-head{display:flex;align-items:center;justify-content:space-between;gap:12px}.rules-panel-head h2{margin:0}.rules-panel-head .eyebrow{margin:0 0 3px}.game-rules-grid{display:grid;grid-template-columns:repeat(3,1fr);gap:10px;margin-top:14px}.game-rules-grid article{padding:12px 13px;border-radius:12px;background:#0c1513;border:1px solid #20302b}.game-rules-grid h3{margin:0 0 5px;font-size:14px;color:#dff3eb}.game-rules-grid p{margin:0;color:var(--muted);font-size:12.5px}@keyframes rulesIn{from{opacity:0;transform:translateY(-8px)}to{opacity:1;transform:none}}@media(max-width:900px){.game-rules-grid{grid-template-columns:1fr 1fr}}@media(max-width:560px){.game-rules-grid{grid-template-columns:1fr}.game-top-actions{flex-wrap:wrap}}

/* Piece themes. Classic Outlined is deliberately high-contrast like a physical Staunton set. */
body[data-piece-theme="classic_outlined"] .piece-icon.piece-w,body[data-piece-theme="classic_outlined"] .mini-piece-icon.piece-w,body[data-piece-theme="classic_outlined"] .piece-preview-icon.piece-w{filter:drop-shadow(1.4px 0 0 #272625) drop-shadow(-1.4px 0 0 #272625) drop-shadow(0 1.4px 0 #272625) drop-shadow(0 -1.4px 0 #272625) drop-shadow(0 2px 1px rgba(0,0,0,.28))}
body[data-piece-theme="classic_outlined"] .piece-icon.piece-b,body[data-piece-theme="classic_outlined"] .mini-piece-icon.piece-b,body[data-piece-theme="classic_outlined"] .piece-preview-icon.piece-b{filter:drop-shadow(1px 0 0 #111) drop-shadow(-1px 0 0 #111) drop-shadow(0 1px 0 #111) drop-shadow(0 -1px 0 #111) drop-shadow(0 0 1px rgba(255,255,255,.5)) drop-shadow(0 2px 1px rgba(0,0,0,.3))}
body[data-piece-theme="modern_flat"] .piece-icon.piece-w,body[data-piece-theme="modern_flat"] .mini-piece-icon.piece-w,body[data-piece-theme="modern_flat"] .piece-preview-icon.piece-w{filter:drop-shadow(1px 0 0 #333) drop-shadow(-1px 0 0 #333) drop-shadow(0 1px 0 #333) drop-shadow(0 -1px 0 #333) drop-shadow(0 2px 2px rgba(0,0,0,.22))}
body[data-piece-theme="modern_flat"] .piece-icon.piece-b,body[data-piece-theme="modern_flat"] .mini-piece-icon.piece-b,body[data-piece-theme="modern_flat"] .piece-preview-icon.piece-b{filter:drop-shadow(0 0 1px rgba(255,255,255,.5)) drop-shadow(0 2px 2px rgba(0,0,0,.24))}
.player.is-busy{opacity:.66}.invite-btn:disabled{cursor:not-allowed;filter:saturate(.4);box-shadow:none;transform:none}
@media(min-width:901px){.hero-wrap .rules-grid{grid-template-columns:repeat(3,1fr)}}

/* Last opponent move: subtle origin/destination memory aid without competing with legal hints. */
.square.last-move-from::after,.square.last-move-to::after{content:"";position:absolute;inset:0;pointer-events:none;z-index:2}
.square.last-move-from::after{background:rgba(237,198,77,.16);box-shadow:inset 0 0 0 3px rgba(237,198,77,.28)}
.square.last-move-to::after{background:rgba(237,198,77,.22);box-shadow:inset 0 0 0 3px rgba(237,198,77,.4)}
.piece-icon.last-moved-piece{filter:drop-shadow(0 0 4px rgba(255,224,122,.75)) drop-shadow(0 2px 1px rgba(0,0,0,.32))}
body[data-piece-theme="classic_outlined"] .piece-icon.piece-w.last-moved-piece{filter:drop-shadow(1.4px 0 0 #272625) drop-shadow(-1.4px 0 0 #272625) drop-shadow(0 1.4px 0 #272625) drop-shadow(0 -1.4px 0 #272625) drop-shadow(0 0 5px rgba(255,222,105,.82)) drop-shadow(0 2px 1px rgba(0,0,0,.28))}
body[data-piece-theme="classic_outlined"] .piece-icon.piece-b.last-moved-piece{filter:drop-shadow(1px 0 0 #111) drop-shadow(-1px 0 0 #111) drop-shadow(0 1px 0 #111) drop-shadow(0 -1px 0 #111) drop-shadow(0 0 5px rgba(255,222,105,.82)) drop-shadow(0 2px 1px rgba(0,0,0,.3))}
.square.selected,.square.legal-target{z-index:5}.square.legal-target .move-hint-dot{z-index:7}

/* Captured material: compact, replay-aware and independent from board sizing. */
.captured-panel{min-height:0}.captured-pieces{display:grid;gap:9px;margin-top:10px}.captured-row{display:grid;grid-template-columns:92px minmax(0,1fr);gap:8px;align-items:center;padding:8px 9px;border:1px solid rgba(255,255,255,.055);background:#0c1513;border-radius:10px}.captured-label{font-size:12px;font-weight:800;color:#d9e8e3}.captured-label small{display:block;color:var(--muted);font-size:10px;font-weight:600}.captured-list{display:flex;align-items:center;justify-content:flex-end;gap:5px;min-height:26px;flex-wrap:wrap}.captured-token{display:inline-flex;align-items:center;gap:1px;height:28px;padding:1px 4px;border-radius:7px;background:rgba(255,255,255,.035)}.captured-token .mini-piece-icon{width:23px;height:23px}.captured-token b{font-size:10px;color:var(--muted);font-variant-numeric:tabular-nums}
@media(max-width:850px){.captured-row{grid-template-columns:105px 1fr}.captured-list{justify-content:flex-start}}
\n\n/* Unified scrollbars and controls: keep native chrome from clashing with the app theme. */
:root{scrollbar-color:#39554c #0b1311;scrollbar-width:thin}
html{scrollbar-color:#39554c #0b1311}
.move-log,.table-wrap,#gameMessage,.game-rules-panel{scrollbar-color:#42685c #0b1311;scrollbar-width:thin}
.move-log::-webkit-scrollbar,.table-wrap::-webkit-scrollbar,#gameMessage::-webkit-scrollbar,.game-rules-panel::-webkit-scrollbar,body::-webkit-scrollbar{width:10px;height:10px}
.move-log::-webkit-scrollbar-track,.table-wrap::-webkit-scrollbar-track,#gameMessage::-webkit-scrollbar-track,.game-rules-panel::-webkit-scrollbar-track,body::-webkit-scrollbar-track{background:#0b1311;border-radius:999px}
.move-log::-webkit-scrollbar-thumb,.table-wrap::-webkit-scrollbar-thumb,#gameMessage::-webkit-scrollbar-thumb,.game-rules-panel::-webkit-scrollbar-thumb,body::-webkit-scrollbar-thumb{background:linear-gradient(180deg,#3e6559,#29483f);border:2px solid #0b1311;border-radius:999px}
.move-log::-webkit-scrollbar-thumb:hover,.table-wrap::-webkit-scrollbar-thumb:hover,#gameMessage::-webkit-scrollbar-thumb:hover,.game-rules-panel::-webkit-scrollbar-thumb:hover,body::-webkit-scrollbar-thumb:hover{background:linear-gradient(180deg,#568273,#365c50)}
select.search,.nav-select{appearance:none;-webkit-appearance:none;background-image:linear-gradient(45deg,transparent 50%,#8ea39c 50%),linear-gradient(135deg,#8ea39c 50%,transparent 50%);background-position:calc(100% - 15px) 50%,calc(100% - 10px) 50%;background-size:5px 5px,5px 5px;background-repeat:no-repeat;padding-right:30px}
input,select,button,.btn,.icon-btn,.notice,.turn-banner,.badge{font-family:inherit}
.site-footer{justify-content:center;text-align:center;min-height:58px}
#gameMessage.notice.result{border-color:rgba(104,224,179,.28);background:linear-gradient(180deg,rgba(104,224,179,.07),rgba(104,224,179,.025));color:#d9f5e9}

/* v6 polish: last move is border-only so it never veils a piece or square. */
.square.last-move-from::after,.square.last-move-to::after{
  content:"";position:absolute;inset:2px;pointer-events:none;z-index:2;
  background:transparent!important;border-radius:4px;box-shadow:none!important;
}
.square.last-move-from::after{border:2px solid rgba(238,196,78,.52)}
.square.last-move-to::after{border:3px solid rgba(238,196,78,.82)}
.piece-icon.last-moved-piece{filter:inherit!important}
body[data-piece-theme="classic_outlined"] .piece-icon.piece-w.last-moved-piece,
body[data-piece-theme="classic_outlined"] .piece-icon.piece-b.last-moved-piece,
body[data-piece-theme="modern_flat"] .piece-icon.piece-w.last-moved-piece,
body[data-piece-theme="modern_flat"] .piece-icon.piece-b.last-moved-piece{filter:inherit!important}

/* Move history has a stable scroll viewport and a clearly themed scrollbar. */
.moves-panel{min-height:0;overflow:hidden}
.move-log{
  height:300px;max-height:300px;min-height:180px;overflow-y:scroll;overflow-x:hidden;
  scrollbar-gutter:stable;padding-right:5px;overscroll-behavior:contain;
}
.move-log::-webkit-scrollbar{width:11px}
.move-log::-webkit-scrollbar-track{background:#09110f;border:1px solid #1c2b27;border-radius:999px}
.move-log::-webkit-scrollbar-thumb{background:#355d50;border:2px solid #09110f;border-radius:999px;min-height:42px}
.move-log::-webkit-scrollbar-thumb:hover{background:#4d806f}

/* Rules live after the whole game layout so opening them never moves the boards. */
.game-bottom-tools{display:flex;justify-content:flex-end;align-items:center;margin:14px 0 0;padding-top:12px;border-top:1px solid rgba(255,255,255,.055)}
.game-rules-panel{margin:12px 0 0}
@media(max-width:700px){.move-log{height:250px;max-height:250px}.game-bottom-tools{justify-content:stretch}.game-bottom-tools .btn{width:100%}}

/* v6.1 result + move-history polish */
.game-result-summary{
  margin-top:10px;padding:11px 12px;border-radius:12px;
  border:1px solid rgba(104,224,179,.26);
  background:linear-gradient(180deg,rgba(104,224,179,.08),rgba(104,224,179,.025));
  color:#e6fbf3;display:grid;gap:3px;
}
.game-result-summary[hidden]{display:none}
.game-result-summary .result-main{font-weight:900;font-size:14px;letter-spacing:.01em}
.game-result-summary .result-sub{font-size:12px;color:var(--muted)}
.game-result-summary.win-white .result-main{color:#f4f0df}
.game-result-summary.win-black .result-main{color:#d5ddd9}
.game-result-summary.draw .result-main{color:#b9d8cc}

/* Custom always-visible move-history rail: consistent even on browsers that hide native scrollbars. */
.move-log-shell{position:relative;min-height:0;padding-right:16px}
.move-log{
  height:300px;max-height:300px;min-height:180px;overflow-y:auto;overflow-x:hidden;
  scrollbar-width:none!important;-ms-overflow-style:none;padding-right:2px;overscroll-behavior:contain;
}
.move-log::-webkit-scrollbar{width:0!important;height:0!important;display:none}
.move-scroll-rail{
  position:absolute;right:2px;top:0;bottom:0;width:9px;border-radius:999px;
  background:#09110f;border:1px solid #1c2b27;box-shadow:inset 0 0 0 1px rgba(255,255,255,.015);
}
.move-scroll-thumb{
  position:absolute;left:1px;right:1px;top:1px;min-height:38px;border-radius:999px;
  background:linear-gradient(180deg,#4a7668,#2f5449);border:1px solid rgba(255,255,255,.07);
  box-shadow:0 1px 4px rgba(0,0,0,.3);cursor:grab;transition:background .15s ease;
}
.move-scroll-thumb:hover{background:linear-gradient(180deg,#5d8e7d,#3c695b)}
.move-scroll-thumb.dragging{cursor:grabbing;background:linear-gradient(180deg,#6a9e8c,#477666)}
.move-scroll-rail.is-idle{opacity:.5}
@media(max-width:700px){.move-log{height:250px;max-height:250px}.move-log-shell{padding-right:14px}}

/* v7 piece rendering: a real two-layer silhouette edge instead of subtle drop-shadows.
   The outer mask is slightly larger than the fill, so even white pieces keep a crisp,
   physical-piece style outline on light squares. */
.piece-icon,.mini-piece-icon,.piece-preview-icon{
  position:relative;background:none!important;filter:none!important;
  -webkit-mask-image:none!important;mask-image:none!important;
  overflow:visible;isolation:isolate;
}
.type-p{--piece-mask:url('pieces/p.svg')}.type-n{--piece-mask:url('pieces/n.svg')}.type-b{--piece-mask:url('pieces/b.svg')}.type-r{--piece-mask:url('pieces/r.svg')}.type-q{--piece-mask:url('pieces/q.svg')}.type-k{--piece-mask:url('pieces/k.svg')}
.piece-icon::before,.piece-icon::after,
.mini-piece-icon::before,.mini-piece-icon::after,
.piece-preview-icon::before,.piece-preview-icon::after{
  content:"";position:absolute;inset:0;pointer-events:none;
  -webkit-mask-image:var(--piece-mask);mask-image:var(--piece-mask);
  -webkit-mask-position:center;mask-position:center;
  -webkit-mask-repeat:no-repeat;mask-repeat:no-repeat;
  -webkit-mask-size:contain;mask-size:contain;
}
.piece-icon::before,.mini-piece-icon::before,.piece-preview-icon::before{
  z-index:0;background:var(--piece-outline,#252422);transform:scale(var(--piece-outline-scale,1.09));transform-origin:center;
}
.piece-icon::after,.mini-piece-icon::after,.piece-preview-icon::after{
  z-index:1;background:currentColor;filter:drop-shadow(0 2px 1px rgba(0,0,0,.22));
}
.piece-icon.piece-w,.mini-piece-icon.piece-w,.piece-preview-icon.piece-w{color:var(--piece-white);--piece-outline:#2a2927}
.piece-icon.piece-b,.mini-piece-icon.piece-b,.piece-preview-icon.piece-b{color:var(--piece-black);--piece-outline:#171716}
body[data-piece-theme="classic_outlined"] .piece-icon,
body[data-piece-theme="classic_outlined"] .mini-piece-icon,
body[data-piece-theme="classic_outlined"] .piece-preview-icon{--piece-outline-scale:1.105}
body[data-piece-theme="modern_flat"] .piece-icon,
body[data-piece-theme="modern_flat"] .mini-piece-icon,
body[data-piece-theme="modern_flat"] .piece-preview-icon{--piece-outline-scale:1.06}
body[data-piece-theme="modern_flat"] .piece-icon.piece-w,
body[data-piece-theme="modern_flat"] .mini-piece-icon.piece-w,
body[data-piece-theme="modern_flat"] .piece-preview-icon.piece-w{--piece-outline:#3b3a38}
body[data-piece-theme="modern_flat"] .piece-icon.piece-b,
body[data-piece-theme="modern_flat"] .mini-piece-icon.piece-b,
body[data-piece-theme="modern_flat"] .piece-preview-icon.piece-b{--piece-outline:#1e1d1c}

/* Busy/loading feedback without freezing the whole screen. */
.btn.is-loading{cursor:progress;opacity:.76;pointer-events:none}

/* v9 — reference-like Staunton pieces with real contour strokes. */
.piece-svg{width:78%;height:78%;display:block;overflow:visible;filter:drop-shadow(0 2px 1px rgba(0,0,0,.24));pointer-events:none}
.mini-piece-svg{width:26px;height:26px;display:inline-block;vertical-align:middle}.promotion-piece{width:64px;height:64px}
.piece-svg.piece-w{color:var(--piece-white)}.piece-svg.piece-b{color:var(--piece-black)}
.piece-svg .piece-body{fill:currentColor;stroke:#242321;stroke-width:3.5;stroke-linejoin:round;stroke-linecap:round}
.piece-svg.piece-b .piece-body{stroke:#0f0f0f;stroke-width:3.1}
.piece-svg .detail{fill:none;stroke:#34322f;stroke-width:3.2}.piece-svg.piece-b .detail{stroke:#e2ddd2;stroke-width:2.2;opacity:.62}
.piece-svg .detail-fill{fill:#34322f;stroke:none}.piece-svg.piece-b .detail-fill{fill:#e2ddd2;opacity:.72}
body[data-piece-theme="modern_flat"] .piece-svg .piece-body{stroke-width:2.3}
body[data-piece-theme="modern_flat"] .piece-svg.piece-b .piece-body{stroke-width:2.1}
body[data-piece-theme="modern_flat"] .piece-svg .detail{stroke-width:2}
/* legacy mask spans remain for admin preview only; keep them readable. */
body[data-piece-theme="classic_outlined"] .piece-preview-icon{--piece-outline-scale:1.09}
body[data-piece-theme="modern_flat"] .piece-preview-icon{--piece-outline-scale:1.045}

/* Promotion chooser: custom UI, never browser prompt. */
.promotion-modal{position:fixed;inset:0;z-index:120;display:grid;place-items:center;padding:20px;opacity:0;transition:opacity .16s ease}.promotion-modal[hidden]{display:none}.promotion-modal.open{opacity:1}
.promotion-backdrop{position:absolute;inset:0;background:rgba(4,9,8,.72);backdrop-filter:blur(7px)}
.promotion-card{position:relative;width:min(520px,94vw);padding:24px;border:1px solid var(--line);border-radius:18px;background:linear-gradient(180deg,#17231f,#101816);box-shadow:0 24px 80px rgba(0,0,0,.5);transform:translateY(8px) scale(.985);transition:transform .16s ease}.promotion-modal.open .promotion-card{transform:none}.promotion-card h2{margin:0 0 16px}.promotion-choices{display:grid;grid-template-columns:repeat(4,1fr);gap:10px;margin-bottom:16px}.promotion-choices button{min-width:0;padding:12px 8px;border:1px solid var(--line);border-radius:14px;background:#0c1513;color:var(--text);display:grid;place-items:center;gap:6px;cursor:pointer;transition:.15s ease}.promotion-choices button:hover,.promotion-choices button:focus-visible{border-color:var(--brand);background:#11241e;transform:translateY(-2px)}.promotion-choices button span{font-weight:800;font-size:12px}

.lobby-rules-card{display:flex;align-items:center;justify-content:space-between;gap:22px}.lobby-rules-card h2{margin:0 0 5px}.lobby-rules-card p{margin:0;color:var(--muted);max-width:780px}.rules-page .rules-grid-full{grid-template-columns:repeat(4,1fr)}
@media(max-width:900px){.rules-page .rules-grid-full{grid-template-columns:repeat(2,1fr)}.lobby-rules-card{align-items:flex-start;flex-direction:column}}
@media(max-width:560px){.promotion-choices{grid-template-columns:repeat(2,1fr)}.rules-page .rules-grid-full{grid-template-columns:1fr}.promotion-piece{width:58px;height:58px}}

/* Smooth navigation feedback on regular browser navigation; keeps layout stable. */
main{animation:pageIn .16s ease both}@keyframes pageIn{from{opacity:.72;transform:translateY(2px)}to{opacity:1;transform:none}}

/* Cross-document navigation stays visually calm even though PHP renders each clean route. */
@view-transition{navigation:auto}
::view-transition-old(root){animation:routeOut .12s ease both}
::view-transition-new(root){animation:routeIn .16s ease both}
@keyframes routeOut{to{opacity:.72}}
@keyframes routeIn{from{opacity:.72}to{opacity:1}}
/* SPA navigation: keep the document/head alive and soften only the view transition. */
html.spa-loading body { cursor: progress; }
html.spa-loading main { opacity: .72; transition: opacity .12s ease; }
body > main { animation: spaViewIn .16s ease both; }
@keyframes spaViewIn { from { opacity: .72; transform: translateY(2px); } to { opacity: 1; transform: none; } }

/* v12: guest authentication actions must remain visible on narrow mobile headers. */
.guest-login,.guest-register{white-space:nowrap}
@media(max-width:850px){
  .topbar nav{gap:9px}
  .topbar nav .guest-login,.topbar nav .guest-register{display:inline-flex}
}
@media(max-width:560px){
  .topbar nav{gap:6px}
  .guest-login,.guest-register{padding:7px 9px;font-size:12px}
}
@media(max-width:390px){
  .topbar{padding-left:10px;padding-right:10px}
  .brand-mark{width:31px;height:31px;font-size:20px}
  .guest-login,.guest-register{padding:7px 8px;font-size:11px}
}

.footer-terms-link{color:var(--brand);font-weight:800;text-decoration:none;white-space:nowrap}.footer-terms-link:hover{text-decoration:underline}.terms-shell{max-width:900px}.terms-panel{padding:clamp(22px,4vw,40px)}.terms-copy{line-height:1.8;color:#d9e4e0;font-size:15px}.terms-admin-label{display:grid;gap:9px;color:#cbdad5;font-weight:800}.terms-editor{width:100%;resize:vertical;min-height:300px;border:1px solid var(--line);background:#0c1412;color:var(--text);padding:15px;border-radius:12px;outline:none;font:14px/1.65 ui-monospace,SFMono-Regular,Menlo,Consolas,monospace}.terms-editor:focus{border-color:var(--brand);box-shadow:0 0 0 3px rgba(104,224,179,.08)}.admin-inline-actions{display:flex;align-items:center;gap:12px;margin-top:14px}.saved-inline{color:var(--brand)}@media(max-width:560px){.site-footer{align-items:flex-start}.footer-terms-link{font-size:13px}}

/* v14 — Lobby match controls: keep mode select and minutes input visually balanced. */
.match-options{
  --match-control-height:46px;
}
.match-options #inviteMode,
.match-options #inviteMinutes{
  height:var(--match-control-height);
  min-height:var(--match-control-height);
  padding-top:0;
  padding-bottom:0;
  line-height:calc(var(--match-control-height) - 2px);
  border-radius:10px;
}
.match-options #inviteMode{
  display:block;
}
.match-options .time-field{
  align-self:flex-end;
}
.match-options .time-field #inviteMinutes{
  display:block;
}
@media(max-width:700px){
  .match-options{
    display:grid;
    grid-template-columns:minmax(0,1fr) minmax(0,1fr);
    align-items:end;
    gap:10px;
  }
  .match-options>*{min-width:0;width:100%;}
  .match-options #inviteMode,
  .match-options #inviteMinutes{
    width:100%;
    max-width:none;
    height:48px;
    min-height:48px;
    line-height:46px;
  }
}
@media(max-width:390px){
  .match-options{gap:8px;}
  .match-options #inviteMode,
  .match-options #inviteMinutes{
    height:46px;
    min-height:46px;
    line-height:44px;
    font-size:14px;
  }
}

/* v15 — iOS/Safari-safe lobby controls. Select and minutes are the same field component. */
.match-options{
  --match-control-height:50px;
  align-items:end;
}
.match-options .match-field{
  display:grid;
  grid-template-rows:20px var(--match-control-height);
  gap:7px;
  min-width:0;
  margin:0;
  color:var(--muted);
  font-size:12px;
  font-weight:800;
  line-height:20px;
}
.match-options .match-field>span{
  display:block;
  height:20px;
  line-height:20px;
  white-space:nowrap;
}
.match-options #inviteMode,
.match-options #inviteMinutes{
  box-sizing:border-box!important;
  display:block!important;
  width:100%!important;
  max-width:none!important;
  height:var(--match-control-height)!important;
  min-height:var(--match-control-height)!important;
  max-height:var(--match-control-height)!important;
  margin:0!important;
  padding:0 16px!important;
  border:1px solid var(--line)!important;
  border-radius:12px!important;
  background-color:#0c1412;
  color:var(--text);
  font-size:16px!important;
  font-weight:600;
  line-height:normal!important;
  vertical-align:middle;
  -webkit-tap-highlight-color:transparent;
}
.match-options #inviteMode{
  -webkit-appearance:none!important;
  appearance:none!important;
  padding-right:42px!important;
  background-image:linear-gradient(45deg,transparent 50%,#8ea39c 50%),linear-gradient(135deg,#8ea39c 50%,transparent 50%);
  background-position:calc(100% - 20px) 50%,calc(100% - 14px) 50%;
  background-size:6px 6px,6px 6px;
  background-repeat:no-repeat;
}
.match-options #inviteMinutes{
  -webkit-appearance:textfield!important;
  appearance:textfield!important;
}
.match-options #inviteMinutes::-webkit-inner-spin-button,
.match-options #inviteMinutes::-webkit-outer-spin-button{
  -webkit-appearance:none;
  margin:0;
}
@media(max-width:700px){
  .match-options{
    grid-template-columns:minmax(0,1fr) minmax(0,1fr);
    gap:12px;
    width:100%;
  }
  .match-options .match-field{width:100%;min-width:0}
}
@media(max-width:390px){
  .match-options{--match-control-height:48px;gap:9px}
  .match-options .match-field{grid-template-rows:19px var(--match-control-height);gap:6px;font-size:11px;line-height:19px}
  .match-options .match-field>span{height:19px;line-height:19px}
  .match-options #inviteMode,.match-options #inviteMinutes{font-size:16px!important;padding-left:13px!important;padding-right:13px!important}
  .match-options #inviteMode{padding-right:36px!important;background-position:calc(100% - 18px) 50%,calc(100% - 12px) 50%}
}

/* v16 - Terms editor: fully themed, balanced and responsive. */
.terms-admin-panel{overflow:hidden}
.terms-admin-head{margin-bottom:16px}
.terms-admin-editor{width:100%;border:1px solid var(--line);border-radius:16px;background:#0b1311;overflow:hidden;box-shadow:inset 0 1px 0 rgba(255,255,255,.02)}
.terms-editor-toolbar{display:flex;align-items:center;justify-content:space-between;gap:14px;padding:13px 14px;border-bottom:1px solid var(--line);background:#101a17}
.terms-editor-toolbar>div{display:flex;align-items:center;gap:10px;min-width:0}.terms-editor-toolbar strong{font-size:14px;color:#dce9e4;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.terms-public-badge{display:inline-flex;align-items:center;min-height:24px;padding:3px 8px;border-radius:999px;background:rgba(104,224,179,.10);border:1px solid rgba(104,224,179,.22);color:var(--brand);font-size:10px;font-weight:900;letter-spacing:.12em}
.terms-preview-btn{flex:0 0 auto}
.terms-editor{display:block;width:100%;max-width:none!important;min-width:0;box-sizing:border-box;resize:vertical;min-height:360px;margin:0;border:0!important;border-radius:0!important;background:#0b1311!important;color:#dce9e4!important;padding:18px 20px!important;outline:none;font:14px/1.7 ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono",monospace;box-shadow:none!important;caret-color:var(--brand);scrollbar-color:#315d50 #0b1311;scrollbar-width:thin}
.terms-editor:focus{background:#0d1714!important;box-shadow:inset 3px 0 0 var(--brand)!important}
.terms-editor::selection{background:rgba(104,224,179,.22)}
.terms-editor::-webkit-scrollbar{width:10px}.terms-editor::-webkit-scrollbar-track{background:#0b1311}.terms-editor::-webkit-scrollbar-thumb{background:#315d50;border:2px solid #0b1311;border-radius:999px}.terms-editor::-webkit-scrollbar-thumb:hover{background:#3d7462}
.terms-editor-footer{display:flex;align-items:center;justify-content:space-between;gap:16px;padding:13px 14px;border-top:1px solid var(--line);background:#101a17}.terms-editor-footer p{margin:0}.terms-editor-footer .admin-inline-actions{margin:0;justify-content:flex-end}.terms-editor-footer #termsSaveState{min-height:18px;text-align:right}
@media(max-width:680px){.terms-editor-toolbar,.terms-editor-footer{align-items:stretch;flex-direction:column}.terms-editor-toolbar>div{justify-content:space-between}.terms-preview-btn{width:100%;justify-content:center}.terms-editor{min-height:420px;padding:16px!important;font-size:13px}.terms-editor-footer .admin-inline-actions{width:100%;justify-content:space-between}.terms-editor-footer .btn{flex:0 0 auto}}

/* v17 - pixel-locked lobby controls + full-width Terms editor */
.match-options{
  --match-control-height:50px;
  display:grid!important;
  grid-template-columns:minmax(0,1fr) minmax(0,1fr)!important;
  gap:12px!important;
  width:min(420px,100%)!important;
  align-items:end!important;
}
.match-options .match-field{
  display:grid!important;
  grid-template-rows:20px var(--match-control-height)!important;
  gap:7px!important;
  min-width:0!important;
  margin:0!important;
}
.match-options .match-field>span:first-child{
  display:block!important;
  height:20px!important;
  min-height:20px!important;
  line-height:20px!important;
  margin:0!important;
  color:var(--muted)!important;
  font-size:12px!important;
  font-weight:800!important;
}
.match-control-wrap{
  position:relative!important;
  display:flex!important;
  align-items:stretch!important;
  width:100%!important;
  height:var(--match-control-height)!important;
  min-height:var(--match-control-height)!important;
  max-height:var(--match-control-height)!important;
  padding:0!important;
  margin:0!important;
  overflow:hidden!important;
  border:1px solid var(--line)!important;
  border-radius:12px!important;
  background:#0c1412!important;
  box-sizing:border-box!important;
}
.match-control-wrap:focus-within{border-color:var(--brand)!important;box-shadow:0 0 0 3px rgba(104,224,179,.07)!important}
.match-control-wrap #inviteMode,
.match-control-wrap #inviteMinutes{
  display:block!important;
  width:100%!important;
  height:100%!important;
  min-height:0!important;
  max-height:none!important;
  margin:0!important;
  border:0!important;
  border-radius:0!important;
  box-shadow:none!important;
  outline:0!important;
  background:transparent!important;
  color:var(--text)!important;
  box-sizing:border-box!important;
  padding:0 15px!important;
  font-family:inherit!important;
  font-size:16px!important;
  font-weight:600!important;
  line-height:1!important;
  -webkit-appearance:none!important;
  appearance:none!important;
}
.match-control-wrap #inviteMode{
  padding-right:42px!important;
  background-image:linear-gradient(45deg,transparent 50%,#8ea39c 50%),linear-gradient(135deg,#8ea39c 50%,transparent 50%)!important;
  background-position:calc(100% - 20px) 50%,calc(100% - 14px) 50%!important;
  background-size:6px 6px,6px 6px!important;
  background-repeat:no-repeat!important;
}
.match-control-wrap #inviteMinutes{-moz-appearance:textfield!important}
.match-control-wrap #inviteMinutes::-webkit-inner-spin-button,
.match-control-wrap #inviteMinutes::-webkit-outer-spin-button{-webkit-appearance:none!important;margin:0!important}

.terms-admin-panel{
  display:block!important;
  width:100%!important;
  max-width:none!important;
  min-width:0!important;
  grid-column:1 / -1!important;
}
.terms-admin-head{
  display:flex!important;
  width:100%!important;
  align-items:flex-start!important;
  justify-content:space-between!important;
  gap:18px!important;
}
.terms-admin-head>div{min-width:0!important;max-width:820px!important}
.terms-admin-editor{
  display:block!important;
  width:100%!important;
  max-width:none!important;
  min-width:0!important;
  margin:0!important;
  border:1px solid var(--line)!important;
  border-radius:16px!important;
  background:#0b1311!important;
  overflow:hidden!important;
}
.terms-editor-toolbar,.terms-public-badge{display:none!important}
.terms-editor{
  display:block!important;
  inline-size:100%!important;
  width:100%!important;
  max-width:100%!important;
  min-width:100%!important;
  min-height:430px!important;
  margin:0!important;
  padding:20px 22px!important;
  border:0!important;
  border-radius:0!important;
  background:#0b1311!important;
  color:#dce9e4!important;
  box-sizing:border-box!important;
  resize:vertical!important;
}
.terms-editor-footer{width:100%!important;box-sizing:border-box!important}
@media(max-width:700px){
  .match-options{width:100%!important;grid-template-columns:minmax(0,1fr) minmax(0,1fr)!important;gap:10px!important}
  .terms-admin-head{flex-direction:column!important;align-items:stretch!important}
  .terms-preview-btn{width:100%!important}
  .terms-editor{min-height:460px!important;padding:16px!important}
}
@media(max-width:390px){
  .match-options{--match-control-height:48px!important;gap:8px!important}
  .match-options .match-field{grid-template-rows:20px var(--match-control-height)!important;gap:6px!important}
}


/* v18 - Terms editor hard full-width override + cache-busted assets */
#termsContent.terms-editor,
.terms-admin-panel .terms-admin-editor > #termsContent,
.terms-admin-panel textarea#termsContent{
  display:block!important;
  position:relative!important;
  float:none!important;
  clear:both!important;
  width:100%!important;
  inline-size:100%!important;
  min-width:0!important;
  max-width:none!important;
  min-height:440px!important;
  height:auto!important;
  margin:0!important;
  padding:20px 22px!important;
  border:0!important;
  border-radius:0!important;
  background:#0b1311!important;
  color:#dce9e4!important;
  box-sizing:border-box!important;
  resize:vertical!important;
  overflow:auto!important;
  font:14px/1.7 ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono",monospace!important;
}
.terms-admin-panel .terms-admin-editor{
  width:100%!important;
  inline-size:100%!important;
  max-width:none!important;
  min-width:0!important;
  display:grid!important;
  grid-template-columns:minmax(0,1fr)!important;
}
.terms-admin-panel .terms-editor-footer{
  width:100%!important;
  grid-column:1/-1!important;
}
@media(max-width:700px){
  #termsContent.terms-editor{min-height:480px!important;padding:16px!important}
}
\n\n/* v19 — hard component styling for Lobby match controls.\n   Uses dedicated classes so generic select/input rules can never collapse them. */\n.match-options{\n  --lobby-control-h:52px!important;\n  display:grid!important;\n  grid-template-columns:minmax(0,1fr) minmax(0,1fr)!important;\n  gap:12px!important;\n  width:min(460px,100%)!important;\n  align-items:end!important;\n}\n.lobby-match-field{\n  display:grid!important;\n  grid-template-rows:22px var(--lobby-control-h)!important;\n  gap:7px!important;\n  width:100%!important;\n  min-width:0!important;\n  margin:0!important;\n}\n.lobby-match-field>span:first-child{\n  display:flex!important;\n  align-items:center!important;\n  height:22px!important;\n  margin:0!important;\n  color:var(--muted)!important;\n  font-size:12px!important;\n  font-weight:800!important;\n  line-height:22px!important;\n  white-space:nowrap!important;\n}\n.lobby-match-control{\n  display:block!important;\n  width:100%!important;\n  height:var(--lobby-control-h)!important;\n  min-height:var(--lobby-control-h)!important;\n  max-height:var(--lobby-control-h)!important;\n  padding:0!important;\n  margin:0!important;\n  border:1px solid var(--line)!important;\n  border-radius:14px!important;\n  background:#0c1412!important;\n  overflow:hidden!important;\n  box-sizing:border-box!important;\n}\n.lobby-match-control:focus-within{\n  border-color:var(--brand)!important;\n  box-shadow:0 0 0 3px rgba(104,224,179,.08)!important;\n}\n.lobby-match-input{\n  display:block!important;\n  width:100%!important;\n  height:100%!important;\n  min-height:100%!important;\n  max-height:100%!important;\n  margin:0!important;\n  padding:0 16px!important;\n  border:0!important;\n  border-radius:0!important;\n  outline:0!important;\n  box-shadow:none!important;\n  background:#0c1412!important;\n  color:var(--text)!important;\n  font:600 16px/1 system-ui,-apple-system,Segoe UI,Roboto,Arial,sans-serif!important;\n  box-sizing:border-box!important;\n  vertical-align:middle!important;\n  -webkit-appearance:none!important;\n  appearance:none!important;\n}\n.lobby-match-select{\n  padding-right:44px!important;\n  background-color:#0c1412!important;\n  background-image:linear-gradient(45deg,transparent 50%,#8ea39c 50%),linear-gradient(135deg,#8ea39c 50%,transparent 50%)!important;\n  background-position:calc(100% - 21px) 50%,calc(100% - 15px) 50%!important;\n  background-size:6px 6px,6px 6px!important;\n  background-repeat:no-repeat!important;\n}\n.lobby-match-number{-moz-appearance:textfield!important;background:#0c1412!important;}\n.lobby-match-number::-webkit-inner-spin-button,.lobby-match-number::-webkit-outer-spin-button{-webkit-appearance:none!important;margin:0!important;}\n@media(max-width:700px){\n  .match-options{width:100%!important;gap:10px!important;}\n}\n@media(max-width:390px){\n  .match-options{--lobby-control-h:50px!important;gap:8px!important;}\n  .lobby-match-field{grid-template-rows:21px var(--lobby-control-h)!important;gap:6px!important;}\n  .lobby-match-field>span:first-child{height:21px!important;line-height:21px!important;font-size:11px!important;}\n  .lobby-match-input{font-size:16px!important;padding-left:13px!important;padding-right:13px!important;}\n  .lobby-match-select{padding-right:38px!important;background-position:calc(100% - 19px) 50%,calc(100% - 13px) 50%!important;}\n}\n
/* v20 — breathing room between the hero actions and the rule cards. */
.hero-wrap > .rules-grid{
  margin-top:32px;
}
@media(max-width:850px){
  .hero-wrap > .rules-grid{
    margin-top:44px;
  }
}
@media(max-width:560px){
  .hero-wrap > .rules-grid{
    margin-top:52px;
  }
}

/* v21 — footer stays on one row on mobile. */
.site-footer{
  display:flex!important;
  flex-direction:row!important;
  align-items:center!important;
  justify-content:space-between!important;
  flex-wrap:nowrap!important;
  gap:14px!important;
  width:100%!important;
  text-align:left!important;
}
.site-footer>span,
.site-footer>.footer-terms-link{
  min-width:0;
  white-space:nowrap!important;
}
.site-footer>.footer-terms-link{
  margin-left:auto!important;
  text-align:right!important;
}
@media(max-width:560px){
  .site-footer{
    flex-direction:row!important;
    align-items:center!important;
    justify-content:space-between!important;
    flex-wrap:nowrap!important;
    gap:10px!important;
    padding:18px 16px!important;
    min-height:58px!important;
  }
  .site-footer>span{font-size:12px!important;overflow:hidden;text-overflow:ellipsis;}
  .site-footer>.footer-terms-link{font-size:12px!important;flex:0 0 auto;}
}
@media(max-width:360px){
  .site-footer{gap:8px!important;padding-left:12px!important;padding-right:12px!important;}
  .site-footer>span,.site-footer>.footer-terms-link{font-size:11px!important;}
}

/* v22 — unified native-control cleanup and fully themed custom dropdowns. */
input[type="number"]{
  -moz-appearance:textfield!important;
  appearance:textfield!important;
}
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button{
  -webkit-appearance:none!important;
  appearance:none!important;
  margin:0!important;
  display:none!important;
}
.native-select-enhanced{
  position:absolute!important;
  width:1px!important;
  height:1px!important;
  padding:0!important;
  margin:-1px!important;
  overflow:hidden!important;
  clip:rect(0,0,0,0)!important;
  white-space:nowrap!important;
  border:0!important;
  opacity:0!important;
  pointer-events:none!important;
}
.custom-select-shell{
  position:relative;
  width:100%;
  min-width:0;
  font:inherit;
  color:var(--text);
  z-index:8;
}
.custom-select-trigger{
  width:100%;
  min-height:46px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  padding:0 14px;
  border:1px solid var(--line);
  border-radius:11px;
  background:#0c1412;
  color:var(--text);
  font:600 15px/1 system-ui,-apple-system,Segoe UI,Roboto,Arial,sans-serif;
  text-align:left;
  cursor:pointer;
  outline:none;
  transition:border-color .16s ease,box-shadow .16s ease,background .16s ease;
}
.custom-select-trigger:hover{background:#101b18;border-color:#345047}
.custom-select-trigger:focus-visible,.custom-select-shell.open .custom-select-trigger{border-color:var(--brand);box-shadow:0 0 0 3px rgba(104,224,179,.10)}
.custom-select-value{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.custom-select-chevron{width:9px;height:9px;flex:0 0 9px;border-right:2px solid #8ea39c;border-bottom:2px solid #8ea39c;transform:rotate(45deg) translateY(-2px);transition:transform .16s ease}
.custom-select-shell.open .custom-select-chevron{transform:rotate(225deg) translate(-1px,-1px)}
.custom-select-menu{
  position:absolute;
  left:0;
  right:0;
  top:calc(100% + 7px);
  z-index:1000;
  max-height:260px;
  overflow:auto;
  padding:6px;
  border:1px solid #2b4039;
  border-radius:12px;
  background:#0e1715;
  box-shadow:0 18px 42px rgba(0,0,0,.46);
  scrollbar-width:thin;
  scrollbar-color:#43685c #0b1210;
}
.custom-select-menu::-webkit-scrollbar{width:8px}
.custom-select-menu::-webkit-scrollbar-track{background:#0b1210;border-radius:999px}
.custom-select-menu::-webkit-scrollbar-thumb{background:#43685c;border-radius:999px;border:2px solid #0b1210}
.custom-select-option{
  width:100%;
  display:flex;
  align-items:center;
  min-height:40px;
  padding:9px 11px;
  border:0;
  border-radius:8px;
  background:transparent;
  color:#d9e8e3;
  font:600 14px/1.2 system-ui,-apple-system,Segoe UI,Roboto,Arial,sans-serif;
  text-align:left;
  cursor:pointer;
}
.custom-select-option:hover,.custom-select-option:focus-visible{background:#182823;color:#fff;outline:none}
.custom-select-option.selected{background:rgba(104,224,179,.12);color:var(--brand)}
.custom-select-option.selected::after{content:'✓';margin-left:auto;font-weight:900}
.custom-select-option:disabled{opacity:.4;cursor:not-allowed}
.custom-select-shell.is-disabled{opacity:.55}
.custom-select-nav{width:auto;min-width:82px}
.custom-select-nav .custom-select-trigger{min-height:38px;padding:0 12px;border-radius:10px;font-size:13px}
.custom-select-nav .custom-select-menu{min-width:118px;right:0;left:auto}
.custom-select-lobby{height:100%}
.custom-select-lobby .custom-select-trigger{height:100%;min-height:100%;border:0;border-radius:13px;background:#0c1412;padding:0 16px;font-size:16px;box-shadow:none!important}
.custom-select-lobby .custom-select-trigger:hover{background:#101b18}
.custom-select-lobby .custom-select-menu{top:calc(100% + 8px)}
/* The wrapper may contain the custom popup, so it must not clip it. */
.lobby-match-control{overflow:visible!important}
/* Any remaining browser-native option styling is a fallback only. */
select,select option{background:#0c1412;color:var(--text)}
@media(max-width:560px){
  .custom-select-trigger{font-size:16px;min-height:48px}
  .custom-select-option{min-height:44px;font-size:15px}
  .custom-select-nav .custom-select-trigger{min-height:40px;font-size:14px}
  .custom-select-menu{max-height:min(320px,55vh)}
}

/* v23 — Vietnamese typography + consistent screen/menu title styling */
html,body,button,input,select,textarea,.btn,.icon-btn,.notice,.turn-banner,.badge{
  font-family:-apple-system,BlinkMacSystemFont,"Segoe UI","Noto Sans","Helvetica Neue",Arial,sans-serif;
  font-synthesis:none;
  text-rendering:optimizeLegibility;
  -webkit-font-smoothing:antialiased;
  -moz-osx-font-smoothing:grayscale;
}
html[lang="vi"] body{font-family:-apple-system,BlinkMacSystemFont,"Segoe UI","Noto Sans",Arial,sans-serif}
/* Do not force ASCII/PHP uppercase on Vietnamese labels; keep authored Title Case. */
.eyebrow{
  text-transform:none!important;
  letter-spacing:.10em;
  line-height:1.35;
  font-weight:800;
}
html[lang="vi"] .eyebrow{letter-spacing:.065em}
.depth-connector small{letter-spacing:.08em;text-transform:none}
html[lang="vi"] .depth-connector small{letter-spacing:.04em}
/* Screen/menu headings are authored in Title Case; CSS must not override casing. */
.topbar nav a,.panel-head h2,.welcome-row h1,.rules-panel-head h2,.game-title,.auth-card h1,.terms-panel h1{
  text-transform:none;
}

/* v24 — green screen-eyebrow hierarchy
   Screen/section eyebrow labels use uppercase presentation consistently.
   CSS text-transform preserves the source translation and lets the browser
   handle Vietnamese Unicode casing correctly. */
.eyebrow {
  text-transform: none;
  font-size: 13.5px;
  line-height: 1.2;
  font-weight: 900;
  letter-spacing: .115em;
  color: var(--brand);
}
html[lang="vi"] .eyebrow {
  letter-spacing: .09em;
  font-family: Inter, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
.welcome-row .eyebrow,
.lobby-rules-card .eyebrow,
.rules-panel-head .eyebrow {
  font-size: 14px;
}
@media (max-width: 640px) {
  .eyebrow,
  .welcome-row .eyebrow,
  .lobby-rules-card .eyebrow,
  .rules-panel-head .eyebrow {
    font-size: 13px;
    line-height: 1.25;
  }
  html[lang="vi"] .eyebrow { letter-spacing: .075em; }
}


/* v25 — eyebrow casing is rendered server-side for deterministic SPA/mobile behavior. */
.eyebrow{
  text-transform:none!important;
  font-size:13.5px!important;
  line-height:1.2!important;
  font-weight:900!important;
  letter-spacing:.115em!important;
}
html[lang="vi"] .eyebrow{letter-spacing:.09em!important}
.welcome-row .eyebrow,.lobby-rules-card .eyebrow,.rules-panel-head .eyebrow{font-size:14px!important}
@media(max-width:640px){
  .eyebrow,.welcome-row .eyebrow,.lobby-rules-card .eyebrow,.rules-panel-head .eyebrow{font-size:13px!important;line-height:1.25!important}
  html[lang="vi"] .eyebrow{letter-spacing:.075em!important}
}


/* v26 — mobile two-board stage: prioritize both boards over decorative chrome. */
@media (max-width: 700px) {
  .game-shell{
    padding-left:6px;
    padding-right:6px;
  }
  .game-layout{gap:12px}
  .boards-area{
    --mobile-board-size:min(
      calc(100vw - 24px),
      calc((var(--game-mobile-vh, 100svh) - 104px) / 2)
    );
    display:flex!important;
    flex-direction:column;
    align-items:center;
    gap:2px!important;
    width:100%;
    contain:layout paint;
    scroll-margin-block:8px;
  }
  .boards-area .board-card{
    width:min(100%, calc(var(--mobile-board-size) + 10px));
    max-width:100%;
    padding:4px;
    border-radius:11px;
    box-shadow:0 8px 24px rgba(0,0,0,.20);
  }
  .boards-area .chess-board{
    width:var(--mobile-board-size);
    max-width:100%;
    margin-inline:auto;
    border-radius:5px;
  }
  .surface-card .board-label{
    margin:0 2px 4px;
    min-height:26px;
  }
  .underground-card .board-label{
    margin:4px 2px 0;
    min-height:26px;
  }
  .board-label{gap:7px;font-size:13px}
  .board-label small{display:none!important}
  .layer-dot{width:9px;height:9px;box-shadow:0 0 8px currentColor}
  .depth-connector{display:none!important}
  .underground-card{margin-top:0}
  .square .coord{font-size:8px}
  .game-top{margin-bottom:8px}
}

/* Short phones: shrink the boards further so both layers remain visible together. */
@media (max-width:700px) and (max-height:760px){
  .boards-area{
    --mobile-board-size:min(
      calc(100vw - 28px),
      calc((var(--game-mobile-vh, 100svh) - 84px) / 2)
    );
  }
  .surface-card .board-label,.underground-card .board-label{min-height:22px;font-size:12px}
  .game-top{margin-bottom:5px}
}

@media (max-width:700px) and (max-height:640px){
  .boards-area{
    --mobile-board-size:min(
      calc(100vw - 34px),
      calc((var(--game-mobile-vh, 100svh) - 66px) / 2)
    );
  }
  .surface-card .board-label,.underground-card .board-label{min-height:20px;margin-block:2px}
}

/* v27 — stable mobile board viewport + scroll-aware navigation. */
.topbar{
  transition:transform .22s cubic-bezier(.2,.75,.25,1),box-shadow .22s ease;
  will-change:transform;
}
@media (max-width:700px){
  .topbar.is-scroll-hidden{
    transform:translate3d(0,calc(-100% - 2px),0);
    pointer-events:none;
    box-shadow:none;
  }
  /* Never use JS-fed innerHeight here. Safari changes innerHeight as its address bar
     opens/closes while scrolling. svh is deliberately stable for the whole scroll. */
  .boards-area{
    --mobile-stable-vh:100vh;
    --mobile-board-size:min(
      calc(100vw - 20px),
      calc((var(--mobile-stable-vh) - 72px) / 2)
    )!important;
  }
  @supports (height:100svh){
    .boards-area{--mobile-stable-vh:100svh}
  }
  .boards-area .board-card{padding:3px!important}
  .surface-card .board-label{min-height:22px!important;margin:0 2px 2px!important}
  .underground-card .board-label{min-height:22px!important;margin:2px 2px 0!important}
  .board-label{font-size:12px!important;line-height:1.05}
  .game-top{margin-bottom:5px!important}
}
@media (max-width:700px) and (max-height:760px){
  .boards-area{
    --mobile-board-size:min(
      calc(100vw - 24px),
      calc((var(--mobile-stable-vh) - 58px) / 2)
    )!important;
  }
  .surface-card .board-label,.underground-card .board-label{min-height:19px!important;font-size:11px!important}
}
@media (max-width:700px) and (max-height:640px){
  .boards-area{
    --mobile-board-size:min(
      calc(100vw - 28px),
      calc((var(--mobile-stable-vh) - 48px) / 2)
    )!important;
  }
  .surface-card .board-label,.underground-card .board-label{min-height:17px!important;margin-block:1px!important}
}

/* v28 — desktop layer alignment.
   Desktop/tablet landscape keeps both layer labels above their boards so the
   two 8×8 grids share the same vertical baseline. Mobile retains the compact
   v26/v27 layout with the Underground label below the lower board. */
@media (min-width:701px){
  .boards-area{
    align-items:center;
  }
  .board-card{
    display:flex;
    flex-direction:column;
  }
  .surface-card .board-label,
  .underground-card .board-label{
    order:-1;
    margin:0 0 10px;
    min-height:42px;
  }
  .surface-card .chess-board,
  .underground-card .chess-board{
    order:0;
  }
  .depth-connector{
    align-self:center;
    display:flex;
    flex-direction:column;
    align-items:center;
    justify-content:center;
    margin:0;
    transform:none;
  }
  .depth-connector span{line-height:1}
  .depth-connector small{margin-top:6px}
}

/* v32 — admin-only diagnostics. The trigger is intentionally desktop-only;
   logging itself remains active on every viewport. */
.diagnostics-trigger{display:none;border:1px solid rgba(104,224,179,.32);background:rgba(104,224,179,.08);color:#c8f5e4;border-radius:9px;padding:8px 11px;font:800 12px/1 system-ui,-apple-system,Segoe UI,Roboto,Arial,sans-serif;cursor:pointer}
.diagnostics-trigger:hover,.diagnostics-trigger:focus-visible{background:rgba(104,224,179,.15);border-color:var(--brand);outline:2px solid transparent}
@media (min-width:1180px) and (min-height:720px){.diagnostics-trigger{display:inline-flex;align-items:center;justify-content:center;min-height:36px}}
.diagnostics-dialog{width:min(920px,calc(100vw - 40px));max-height:min(760px,calc(100vh - 48px));padding:0;border:1px solid rgba(255,255,255,.11);border-radius:20px;background:linear-gradient(180deg,#17231f,#0d1513);color:var(--text);box-shadow:0 28px 100px rgba(0,0,0,.65);overflow:hidden}
.diagnostics-dialog::backdrop{background:rgba(3,8,7,.72);backdrop-filter:blur(6px)}
.diagnostics-dialog[open]{display:grid;grid-template-rows:auto auto auto minmax(220px,1fr) auto;gap:0}
.diagnostics-head{display:flex;align-items:flex-start;justify-content:space-between;gap:20px;padding:22px 24px 10px}
.diagnostics-head .eyebrow{margin:0 0 3px}.diagnostics-head h2{margin:0;font-size:25px}.diagnostics-close{min-width:40px;min-height:40px;font-size:22px}
.diagnostics-help{margin:0;padding:0 24px 12px;color:var(--muted);max-width:78ch}
.diagnostics-meta{min-height:28px;padding:6px 24px 10px;color:#b8d4ca;font-size:12px}
.diagnostics-output{margin:0 24px;padding:16px;min-height:260px;max-height:52vh;overflow:auto;border:1px solid var(--line);border-radius:12px;background:#08100e;color:#d5e8e1;white-space:pre-wrap;overflow-wrap:anywhere;font:12px/1.65 ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;tab-size:2}
.diagnostics-output:focus-visible{outline:2px solid var(--brand);outline-offset:2px}
.diagnostics-actions{display:flex;justify-content:flex-end;gap:10px;padding:16px 24px 22px}
@media (prefers-reduced-motion:reduce){.diagnostics-dialog,.diagnostics-trigger{transition:none!important}}

/* v34: action-state clarity. Buttons that have no effect must look inactive. */
.game-top-actions .btn:disabled,
.game-top-actions .btn[aria-disabled="true"]{
  opacity:.42;
  filter:saturate(.35);
  cursor:not-allowed;
  pointer-events:none;
  transform:none!important;
  box-shadow:none!important;
  border-color:rgba(148,170,163,.2);
  color:rgba(238,247,243,.52);
  background:rgba(255,255,255,.025);
}
.game-top-actions .btn:not(:disabled){opacity:1}

/* v36 — Admin All Games / live spectating */
.admin-games-panel{min-width:0}
.admin-games-head{align-items:flex-start}
.admin-game-filters{display:grid;grid-template-columns:minmax(180px,1.4fr) minmax(145px,.9fr) minmax(145px,.9fr) minmax(145px,.9fr) auto;gap:12px;align-items:end;margin:14px 0 18px;padding:14px;border:1px solid rgba(255,255,255,.075);border-radius:16px;background:rgba(255,255,255,.025)}
.admin-game-filters label{display:grid;gap:7px;min-width:0}
.admin-game-filters label>span{font-size:.78rem;font-weight:750;color:var(--muted);letter-spacing:.02em}
.admin-game-filters .search{width:100%;min-width:0;height:44px}
.admin-game-row{min-width:0}
.admin-game-row>div{min-width:0}
.admin-game-row small{display:block;margin-top:5px;line-height:1.5;overflow-wrap:anywhere}
.live-watch-btn{white-space:nowrap;box-shadow:0 0 0 1px rgba(104,224,179,.16),0 8px 24px rgba(42,160,120,.08)}
@media(max-width:1000px){.admin-game-filters{grid-template-columns:1fr 1fr}.admin-game-filters #adminGameReset{width:100%}}
@media(max-width:620px){.admin-game-filters{grid-template-columns:1fr 1fr;gap:10px;padding:11px}.admin-game-filters label:first-child{grid-column:1/-1}.admin-game-filters #adminGameReset{grid-column:1/-1}.admin-game-row{align-items:flex-start;gap:10px}.admin-game-row .btn{flex:0 0 auto}}
.admin-game-filters input[type="date"]{color-scheme:dark;appearance:none;-webkit-appearance:none}
.admin-game-filters input[type="date"]::-webkit-calendar-picker-indicator{filter:invert(.82) sepia(.15) saturate(.7);opacity:.78;cursor:pointer}

/* v37 — balanced AI setup controls */
.ai-options-grid{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1fr);gap:12px;align-items:end;margin-top:12px}
.ai-options-grid .time-field{margin:0;min-width:0}
.ai-options-grid select,.ai-options-grid input{width:100%}
@media(max-width:560px){.ai-options-grid{grid-template-columns:1fr 1fr;gap:8px}.ai-options-grid .time-field span{font-size:12px}}

/* v43 — desktop rules layout: keep the first 8 rules as a balanced 4×2 grid,
   then let the longer Draw Rules card occupy the complete final row. */
@media (min-width:851px){
  .rules-grid-full > article:last-child{
    grid-column:1 / -1;
  }
}

/* v44 — lobby game-history pagination + balanced in-game rules. */
.games-pagination{
  display:flex;
  align-items:center;
  justify-content:center;
  gap:12px;
  margin-top:14px;
  padding-top:12px;
  border-top:1px solid rgba(255,255,255,.065);
}
.games-pagination[hidden]{display:none}
.games-page-info{color:var(--muted);font-size:13px;text-align:center;min-width:150px}
.games-page-info b{color:var(--text);font-size:14px}
.games-page-info small{color:#789188}
.games-pagination .btn:disabled{opacity:.38;cursor:not-allowed;pointer-events:none}
@media(max-width:560px){
  .games-pagination{gap:8px;justify-content:space-between}
  .games-page-info{min-width:0;flex:1;font-size:12px}
  .games-page-info small{display:none}
  .games-pagination .btn{padding-inline:10px}
}

/* The in-game rules panel has six compact rules plus the longer Draw Rules card.
   Keep the compact cards balanced and let Draw Rules own the final row. */
@media(min-width:561px){
  .game-rules-grid > article:last-child{grid-column:1 / -1}
}
