/* A graphite table, pearl and carbon pieces. Motion belongs to each move. */
html:has(.chess-page){height:100%;overflow:hidden;overscroll-behavior:none}
body.chess-page{height:100dvh;min-height:0;overflow:hidden;overscroll-behavior:none;user-select:none;-webkit-user-select:none;-webkit-touch-callout:none}
body.chess-page:not([data-world-motion=ready])::before{opacity:.08}body.chess-page .world-motion{opacity:.12}
.chess-page .shell{height:100%;max-width:1420px;padding:0 clamp(16px,3.5vw,48px)}
.chess-page .play-header{height:68px;min-height:68px}
.chess-page button{touch-action:manipulation}
.chess-page :is(input,textarea){user-select:text;-webkit-user-select:text}
.chess-page .chess-layout{--board-size:min(calc(100vw - clamp(32px,7vw,96px) - clamp(28px,4vw,60px) - 280px),calc(100dvh - 184px),760px);display:grid;grid-template-columns:var(--board-size) minmax(228px,280px);grid-template-rows:minmax(0,1fr);gap:clamp(28px,4vw,60px);justify-content:center;align-items:center;height:calc(100% - 68px);padding:8px 0 26px}
.chess-stage{width:var(--board-size);min-width:0;justify-self:center}
.chess-table{position:relative;padding:10px;border-radius:12px;background:linear-gradient(150deg,#333,#222 70%);box-shadow:inset 0 1px 1px #ffffff15,inset 0 -1px 2px #0006,0 18px 42px #0003}
.chess-board{display:grid;grid-template-columns:repeat(8,1fr);aspect-ratio:1;position:relative;border-radius:4px;box-shadow:0 0 0 1px #151515;touch-action:manipulation}
.chess-square{position:relative;display:grid;place-items:center;aspect-ratio:1;min-width:0;width:100%;height:auto;margin:0;padding:0;border:0;border-radius:0;isolation:isolate;background:#373737;background-image:url('./art/card-grain.svg');box-shadow:inset 0 1px #ffffff03;color:#dedede;cursor:default;outline:none;touch-action:manipulation}
.chess-square.light{background-color:#626262}
.chess-square:first-child{border-top-left-radius:4px}.chess-square:nth-child(8){border-top-right-radius:4px}.chess-square:nth-child(57){border-bottom-left-radius:4px}.chess-square:last-child{border-bottom-right-radius:4px}
.chess-square[aria-disabled=false]{cursor:pointer}
.chess-square::before{content:'';position:absolute;inset:0;background:#ffffff08;opacity:0;pointer-events:none;z-index:-1}
.chess-square.last::before{opacity:1;background:#ffffff14}
.chess-square.selected{box-shadow:inset 0 0 0 2px #d6d6d6;background-color:#777}
.chess-square.legal::after{content:'';position:absolute;width:15%;aspect-ratio:1;border-radius:50%;background:#cfcfcf99;pointer-events:none;box-shadow:0 1px 2px #0003;z-index:2}
.chess-square.legal.occupied::after{inset:4%;width:auto;border:2px solid #dededeaa;background:none;border-radius:50%;box-shadow:none}
.chess-square.in-check{box-shadow:inset 0 0 0 2px #e8e8e8;background-color:#797979}
.chess-square:focus-visible{outline:2px solid #f5f5f5;outline-offset:-3px;z-index:6}
.chess-square>.chess-piece{width:88%;height:94%;position:relative;z-index:1;pointer-events:none;filter:drop-shadow(0 3px 2px #0005);transform-origin:50% 85%}
.chess-piece.ivory{color:#737373}.chess-piece.carbon{color:#a1a1a1}
.chess-square[data-fallen=true]>.chess-piece{transform:rotate(34deg) translate(6%,6%);opacity:.6;transition:transform .65s cubic-bezier(.2,.65,.25,1),opacity .65s}
.square-coordinate{position:absolute;pointer-events:none;font:500 clamp(8px,.85vw,11px)/1 var(--sans);color:#b7b7b7}
.light>.square-coordinate{color:#303030}.square-rank{top:5%;left:6%}.square-file{bottom:5%;right:6%}
.chess-capture{position:absolute;pointer-events:none;z-index:8;display:grid;place-items:center}.chess-capture svg{width:88%;height:94%}
.chess-player{display:flex;align-items:center;gap:10px;min-height:44px;padding:4px 4px;min-width:0;color:#bdbdbd}
.player-token{width:32px;height:34px;display:grid;place-items:center;background:linear-gradient(150deg,#333,#242424);border-radius:8px;box-shadow:inset 0 1px #ffffff08;flex:none}
.player-token svg{width:25px;height:30px;filter:drop-shadow(0 1px 1px #0005)}
.player-identity{flex:1;min-width:0;display:flex;align-items:center;gap:16px}.player-name{font-size:13px;white-space:nowrap}.player-side{font-size:11px;color:#999}
.taken-pieces{display:flex;align-items:center;min-width:0;overflow:hidden;height:25px}.taken-pieces svg{width:18px;height:23px;flex:none;margin-left:-4px;opacity:.78}.taken-pieces svg:first-child{margin-left:0}
.turn-dot{width:5px;height:5px;border-radius:50%;background:#d2d2d2;opacity:0;flex:none;margin-inline:4px}.chess-player[data-turn=true] .turn-dot{opacity:1}
.chess-sidebar{display:flex;flex-direction:column;align-self:center;min-width:0;min-height:0;height:100%;max-height:calc(var(--board-size) + 88px);margin:auto 0;width:100%}
.chess-heading{display:flex;align-items:center;justify-content:space-between;gap:12px;margin:0 0 20px}.chess-heading h1{font:400 clamp(24px,2.4vw,34px)/1.2 var(--sans);letter-spacing:-.05em;margin:0}
.chess-icon-button{display:grid;place-items:center;width:40px;height:40px;border:0;background:transparent;color:#aaa;border-radius:8px;font-size:24px}
.chess-icon-button svg,.chess-toolbar svg{width:19px;height:19px;fill:none;stroke:currentColor;stroke-width:1.4;stroke-linecap:round;stroke-linejoin:round}
.chess-modes{display:flex;gap:4px;padding:4px;background:#202020;border-radius:12px;box-shadow:inset 0 1px 3px #0003}
.chess-modes button{flex:1;min-width:0;min-height:40px;padding:6px 10px;border:0;border-radius:8px;background:transparent;color:#9f9f9f;font:400 13px/1.3 var(--sans)}
.chess-modes button[aria-pressed=true]{background:linear-gradient(150deg,#383838,#2e2e2e);color:#ededed;box-shadow:inset 0 1px #ffffff08,0 2px 4px #0003}
.chess-status-row{display:flex;gap:10px;justify-content:space-between;align-items:center;min-height:96px;padding:18px 0}
#chess-status{font-size:18px;letter-spacing:-.025em;margin:0;color:#ddd}#chess-hint{font-size:12px;color:#999;margin:9px 0 0;min-height:16px}
.chess-level{border:0;border-radius:7px;min-height:40px;padding:6px 10px;background:#292929;font-size:11px;color:#b4b4b4;flex:none}
.chess-history{display:flex;flex-direction:column;min-height:70px;flex:1;overflow:hidden;margin:4px 0 24px;padding:18px 14px 8px;background:#ffffff03;border-radius:12px}
.history-heading{display:flex;align-items:center;justify-content:space-between;padding:0 4px 14px;color:#929292}.history-heading h2{font:400 12px var(--sans);margin:0}.history-heading>span{font-size:10px;letter-spacing:.06em}
.move-list{overflow:auto;overscroll-behavior:contain;scrollbar-width:thin;scrollbar-color:#444 transparent;min-height:0;max-height:100%;outline-offset:-2px;padding:0 4px 10px}
.move-row{display:grid;grid-template-columns:32px 1fr 1fr;align-items:center;min-height:34px;font-size:14px;gap:4px}.move-row>span:first-child{font-size:11px;color:#898989}.move-row>span:not(:first-child){padding:7px 9px;border-radius:6px;color:#bcbcbc}.move-row .recent{background:#ffffff07;color:#eee!important}.move-empty{font-size:12px;line-height:1.7;color:#888;margin:12px 0}
.chess-toolbar{display:flex;gap:8px;margin-top:auto}.chess-toolbar>button{display:flex;flex:1;flex-direction:column;align-items:center;justify-content:center;gap:9px;border:0;border-radius:10px;min-height:64px;padding:12px 2px;background:linear-gradient(145deg,#2e2e2e,#272727);box-shadow:inset 0 1px #ffffff07,0 4px 9px #0002;color:#bdbdbd;font-size:10px}
.chess-toolbar button:disabled{opacity:.35}.chess-toolbar button:active:not(:disabled){transform:translateY(1px);background:#242424}.chess-toolbar>#chess-history-open{display:none}
.chess-dialog{width:min(380px,calc(100vw - 28px));max-height:calc(100dvh - 32px);padding:26px;border:0;border-radius:20px;color:#ddd;background:#292929 url('./art/card-grain.svg');box-shadow:inset 0 1px #ffffff0a,0 24px 80px #0008;overscroll-behavior:contain}
.chess-dialog::backdrop{background:#111a;backdrop-filter:blur(6px)}
.chess-dialog h2{font:400 22px/1.3 var(--sans);letter-spacing:-.035em;margin:0 0 22px}.dialog-heading{display:flex;align-items:center;justify-content:space-between;margin-bottom:16px}.dialog-heading h2{margin:0}
.setup-label{font-size:12px;color:#a2a2a2;margin:22px 0 10px}.chess-options{display:flex;gap:6px}.chess-options button{display:flex;align-items:center;justify-content:center;gap:10px;flex:1;min-height:48px;border:0;border-radius:9px;background:#222;color:#999;font-size:13px}.chess-options button[aria-pressed=true]{background:#484848;color:#eee;box-shadow:inset 0 1px #ffffff09}
.side-disc{width:16px;height:16px;border-radius:50%;box-shadow:inset 0 1px #ffffff4d,0 2px 3px #0005}.side-disc.white{background:linear-gradient(#ddd,#aaa)}.side-disc.black{background:linear-gradient(#565656,#222)}
.dialog-note{font-size:12px;line-height:1.8;color:#aaa;margin:20px 0}.dialog-actions{display:flex;gap:8px;margin-top:24px}.dialog-actions button{flex:1}
.chess-primary,.chess-secondary{min-height:46px;padding:10px 17px;border:0;border-radius:10px;font:400 13px/1.4 var(--sans)}.chess-primary{background:linear-gradient(155deg,#e0e0e0,#b8b8b8);color:#252525;box-shadow:inset 0 1px #ffffff88,0 3px 8px #0003}.chess-secondary{background:#353535;color:#c9c9c9}.chess-primary:active,.chess-secondary:active{transform:translateY(1px)}
.chess-result{text-align:center;padding-top:32px}.chess-result #result-piece{height:106px;margin:0 auto 20px}.chess-result #result-piece svg{height:100%;width:94px;filter:drop-shadow(0 5px 4px #0004)}.chess-result #result-kind{font-size:12px;color:#999;margin:0 0 12px}.chess-result h2{font-size:30px;margin:0 0 28px}
.promotion-dialog{text-align:center}#promotion-pieces{display:flex;gap:7px;margin:22px 0}#promotion-pieces button{flex:1;min-width:0;height:80px;padding:6px 2px;border:0;border-radius:10px;background:#3b3b3b}#promotion-pieces svg{width:100%;height:100%}
#chess-moves-dialog .move-list{max-height:55dvh}
@media(hover:hover){.chess-square[aria-disabled=false]:hover::before{opacity:1}.chess-icon-button:hover{background:#ffffff06}.chess-toolbar>button:hover:not(:disabled){filter:brightness(1.08)}}
@media(max-width:1000px) and (orientation:portrait){
 .chess-page .shell{padding:0 max(12px,env(safe-area-inset-left)) 0 max(12px,env(safe-area-inset-right))}
 .chess-page .play-header{height:calc(52px + env(safe-area-inset-top));min-height:calc(52px + env(safe-area-inset-top));padding-top:env(safe-area-inset-top)}
 .chess-page .chess-layout{--board-size:min(calc(100vw - 24px),calc(100dvh - 272px - env(safe-area-inset-top) - env(safe-area-inset-bottom)));height:calc(100% - 52px - env(safe-area-inset-top));display:grid;grid-template-columns:minmax(0,1fr);grid-template-rows:44px calc(var(--board-size) + 68px) 34px 50px;align-content:center;gap:2px;padding:6px 0 max(12px,env(safe-area-inset-bottom))}
 .chess-sidebar{display:contents}.chess-heading,.chess-history{display:none}.chess-modes{grid-row:1;justify-self:center;width:min(100%,380px);padding:3px}.chess-modes button{min-height:38px}
 .chess-stage{grid-row:2;align-self:center}.chess-table{padding:6px;border-radius:9px}.chess-player{min-height:34px;padding:2px 3px;gap:8px}.player-token{width:27px;height:28px;border-radius:6px}.player-token svg{width:21px;height:25px}.player-name{font-size:12px}.player-side{font-size:10px}.player-identity{gap:10px}.taken-pieces svg{width:15px;height:20px}
 .chess-status-row{grid-row:3;min-height:0;width:min(100%,420px);justify-self:center;padding:0 4px}.chess-status-row>div{display:flex;align-items:center;gap:8px}#chess-status{font-size:14px}#chess-hint{font-size:11px;margin:0;min-height:0}.chess-level{min-height:32px;padding:5px 9px}
 .chess-toolbar{grid-row:4;justify-self:center;width:min(100%,420px);gap:7px;margin:0;height:50px}.chess-toolbar>button{min-height:48px;padding:5px 8px;gap:4px;font-size:9px}.chess-toolbar svg{width:18px;height:18px}.chess-toolbar>#chess-history-open{display:flex}
 #chess-retry,#chess-result-open{grid-row:3;grid-column:1;justify-self:end;align-self:center;min-height:32px;padding:5px 10px;font-size:11px;z-index:4}
 .chess-status-row:has(~ #chess-result-open:not([hidden])) .chess-level,.chess-status-row:has(~ #chess-retry:not([hidden])) .chess-level{visibility:hidden}
 .square-coordinate{font-size:8px}.chess-square>.chess-piece{filter:drop-shadow(0 2px 1px #0005)}
}
@media(max-height:650px) and (min-width:761px),(max-height:500px) and (orientation:landscape){
 .chess-page .play-header{height:52px;min-height:52px}.chess-page .shell{padding-inline:16px}
 .chess-page .chess-layout{--board-size:min(calc(100dvh - 128px),calc(100vw - 300px));height:calc(100% - 52px);gap:24px;grid-template-columns:var(--board-size) minmax(180px,240px);padding:0 0 8px}.chess-player{min-height:32px}.player-token{width:24px;height:26px}.player-token svg{width:22px;height:24px}.chess-heading{margin-bottom:8px}.chess-heading h1{font-size:22px}.chess-status-row{min-height:64px;padding:10px 0}#chess-status{font-size:15px}#chess-hint{font-size:10px;margin-top:5px}.chess-history{margin:0 0 12px;padding:8px;min-height:0}.history-heading{padding-bottom:4px}.chess-toolbar>button{min-height:44px;gap:4px;padding:6px}.chess-table{padding:6px}
}
@media(max-height:420px) and (orientation:landscape){.chess-heading{display:none}.chess-history{margin-top:0}.chess-modes button{min-height:32px;font-size:11px}.chess-history .history-heading{display:none}.player-side,.taken-pieces{display:none}}
@media(prefers-reduced-motion:reduce){.chess-square[data-fallen=true]>.chess-piece{transition:none;transform:none}}

.chess-sidebar>.chess-modes button{font-size:12px;padding-inline:5px}.player-name{overflow:hidden;text-overflow:ellipsis;max-width:180px}@media(max-width:420px){.chess-sidebar>.chess-modes button{font-size:11px}.player-name{max-width:110px}}
/* The final position stays on the table; actions stay on the existing rail. */
.chess-toolbar #chess-records{display:flex;align-items:center;justify-content:center;flex:1;min-width:0;min-height:48px;border-radius:10px;background:linear-gradient(145deg,#333,#282828);box-shadow:inset 0 1px #ffffff0b;color:#bdbdbd;font-size:11px;text-align:center}
.chess-page[data-finished=true] #chess-new{background:linear-gradient(145deg,#d2d2d2,#aaa);color:#242424}
.chess-page[data-finished=true] #chess-status .turn-cue-token{background:#c8c8c8;color:#222}
.chess-page[data-finished=true] #chess-status .turn-cue-title{color:#e4e4e4}
@media(max-width:760px){.chess-toolbar #chess-records{min-height:44px;font-size:10px}.chess-page[data-finished=true] #chess-undo{display:none}}
