*{box-sizing:border-box}
:root{--bg:#07111f;--panel:#11233ddd;--text:#f4f7fb;--gold:#e6b85c;--light:#e9d7b2;--dark:#6d4a31;--sel:#5de0a3;--move:#7bdff2;--capture:#ff6b81;--check:#ff394f}
html,body{margin:0;width:100%;height:100%;overflow:hidden}
body{font-family:Inter,system-ui,-apple-system,Segoe UI,sans-serif;color:var(--text);background:
radial-gradient(circle at 15% 10%,#1b4777 0,transparent 30%),radial-gradient(circle at 85% 85%,#3a241a 0,transparent 28%),linear-gradient(145deg,#050b13,#12243c)}
body:before{content:"";position:fixed;inset:-40%;background:repeating-radial-gradient(circle,transparent 0 28px,#ffffff08 29px 30px);animation:drift 20s linear infinite;pointer-events:none}
@keyframes drift{to{transform:translate(3%,4%) rotate(5deg)}}
button{font:inherit}
.app{height:100dvh;max-width:1180px;margin:auto;padding:10px;display:flex;flex-direction:column;gap:10px}
.topbar{display:flex;justify-content:space-between;align-items:center;gap:10px;background:var(--panel);backdrop-filter:blur(16px);border:1px solid #ffffff18;border-radius:20px;padding:11px 16px;box-shadow:0 14px 35px #0007}
h1{margin:0;font-size:clamp(1.2rem,3vw,1.9rem)}.status{font-size:.88rem;opacity:.78;margin-top:3px}
.score{display:flex;gap:14px;background:#02081288;border-radius:14px;padding:9px 12px;white-space:nowrap}
.panel{margin:auto;width:min(650px,100%);background:var(--panel);border:1px solid #ffffff20;border-radius:26px;padding:26px;text-align:center;box-shadow:0 24px 70px #0009}
.panel h2{font-size:clamp(1.6rem,5vw,2.4rem);margin:0 0 8px}.panel>p{opacity:.8}
.mode-grid{display:grid;grid-template-columns:1fr 1fr;gap:12px;margin-top:18px}
.mode{min-height:105px;border:0;border-radius:22px;font-weight:900;font-size:1.15rem;cursor:pointer;transition:.2s;box-shadow:0 12px 30px #0007}
.mode:hover{transform:translateY(-3px);filter:brightness(1.06)}.mode:active{transform:scale(.97)}
.mode small{display:block;font-size:.76rem;margin-top:6px;opacity:.75}
.mode.white{background:linear-gradient(145deg,#fff8e8,#d8c29c);color:#24180e}
.mode.black{background:linear-gradient(145deg,#37485e,#111b2a);color:white;border:1px solid #ffffff18}
.network-setup{border-top:1px solid #ffffff18;margin-top:20px;padding-top:14px}.hint{font-size:.82rem;opacity:.7;line-height:1.5}
.hidden{display:none!important}
.game{min-height:0;flex:1;display:flex;flex-direction:column;gap:8px}
.gamebar{display:flex;align-items:center;justify-content:space-between;gap:8px}
.turn-badge{padding:8px 14px;border-radius:999px;background:#ffffff13;border:1px solid #ffffff13;font-weight:900}
.actions{display:flex;gap:6px;flex-wrap:wrap;justify-content:flex-end}.actions button{border:0;border-radius:10px;padding:7px 10px;background:#ffffff16;color:white;font-weight:700;cursor:pointer}.actions .danger{background:#812c3a}.actions .ghost{background:#ffffff0b}
.layout{min-height:0;flex:1;display:grid;grid-template-columns:minmax(300px,1fr) 260px;gap:12px;align-items:center}
.board-shell{min-height:0;height:100%;display:flex;align-items:center;justify-content:center}
.board{width:min(72vh,calc(100vw - 310px),760px);aspect-ratio:1;display:grid;grid-template-columns:repeat(8,1fr);grid-template-rows:repeat(8,1fr);border:clamp(6px,1vw,12px) solid #2d1d13;border-radius:12px;overflow:hidden;box-shadow:0 24px 70px #000b,inset 0 0 0 2px #ffffff18}
.square{position:relative;border:0;padding:0;display:flex;align-items:center;justify-content:center;font-size:clamp(2rem,7vh,4.8rem);cursor:pointer;user-select:none;line-height:1;transition:filter .12s,transform .12s}
.square.light{background:linear-gradient(145deg,#eeddb9,#d9c197)}.square.dark{background:linear-gradient(145deg,#815b3e,#63412c)}
.square:hover{filter:brightness(1.08)}.square.selected{box-shadow:inset 0 0 0 5px var(--sel);z-index:2}
.square.move:after{content:"";position:absolute;width:20%;aspect-ratio:1;border-radius:50%;background:#1e6f85aa;box-shadow:0 0 12px #7bdff288}
.square.capture:after{content:"";position:absolute;inset:7%;border-radius:50%;border:5px solid #d62949aa}
.square.last{box-shadow:inset 0 0 0 5px #f5c54288}.square.check{animation:checkpulse .7s infinite alternate;box-shadow:inset 0 0 0 6px var(--check)}
@keyframes checkpulse{to{filter:brightness(1.35)}}
.piece{filter:drop-shadow(0 3px 2px #0008);transform:translateZ(0);animation:piecein .18s ease}
@keyframes piecein{from{transform:scale(.7);opacity:.4}}
.coord{position:absolute;font-size:clamp(.48rem,1.1vw,.68rem);font-weight:900;opacity:.58;pointer-events:none}.coord.file{bottom:2px;right:3px}.coord.rank{top:2px;left:3px}
.side{display:flex;flex-direction:column;gap:10px;min-height:0;max-height:100%}.card{background:var(--panel);border:1px solid #ffffff18;border-radius:18px;padding:13px;box-shadow:0 14px 30px #0005}.card h3{margin:0 0 10px}.meta-row{display:flex;justify-content:space-between;padding:5px 0;border-bottom:1px solid #ffffff0e}.history-card{min-height:0;flex:1;display:flex;flex-direction:column}.history{overflow:auto;min-height:80px;font-family:ui-monospace,monospace;font-size:.82rem;line-height:1.7}.move-row{display:grid;grid-template-columns:28px 1fr 1fr;gap:5px;border-bottom:1px solid #ffffff0b;padding:2px}
.toast{position:fixed;z-index:30;left:50%;top:50%;transform:translate(-50%,-50%);padding:17px 26px;border-radius:20px;background:#07111ff2;border:1px solid #ffffff28;box-shadow:0 20px 80px #000d;font-size:clamp(1.2rem,5vw,2rem);font-weight:900;animation:pop .2s}
@keyframes pop{from{transform:translate(-50%,-50%) scale(.7);opacity:0}}
.modal{position:fixed;inset:0;z-index:40;background:#0009;display:grid;place-items:center}.modal-box{background:#102139;border:1px solid #ffffff25;border-radius:24px;padding:22px;text-align:center;box-shadow:0 30px 80px #000}.promotion-buttons{display:flex;gap:8px}.promotion-buttons button{font-size:2.8rem;width:72px;height:72px;border:0;border-radius:14px;background:#f1dfbd;color:#23180f;cursor:pointer}
#confetti{position:fixed;inset:0;width:100%;height:100%;pointer-events:none;z-index:50}
@media(max-width:800px){.layout{grid-template-columns:1fr}.side{display:grid;grid-template-columns:1fr 1fr}.board{width:min(80vh,96vw)}.history-card{max-height:130px}.gamebar{align-items:flex-start}.actions button{font-size:.72rem;padding:6px 7px}}
@media(max-width:560px){.app{padding:6px}.topbar{padding:8px 10px;border-radius:14px}.score{gap:8px;font-size:.85rem;padding:7px}.mode-grid{grid-template-columns:1fr}.panel{padding:18px}.board{width:96vw}.side{display:grid;grid-template-columns:1fr 1fr}.card{padding:9px;font-size:.78rem}.piece{font-size:.92em}}
@media(max-height:650px) and (orientation:landscape){.topbar{padding:5px 10px}.layout{grid-template-columns:1fr 230px}.board{width:min(74vh,calc(100vw - 250px))}.side{display:flex}.history-card{max-height:none}}
