* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; }
.chess-page { max-width: 1120px; margin: auto; padding: 28px 20px; }
h1 { margin: 0 0 10px; } p { line-height: 1.5; }
.chess-layout { display: grid; grid-template-columns: minmax(0,1fr) minmax(240px,310px); gap: 28px; align-items: start; }
.chess-board { display: grid; grid-template-columns: repeat(8,minmax(0,1fr)); grid-template-rows: repeat(8,minmax(0,1fr)); aspect-ratio: 1; width: 100%; max-width: 700px; margin: auto; border: clamp(6px,1.4vw,12px) solid #775133; border-radius: 8px; overflow: hidden; box-shadow: 0 12px 26px #37201625; container-type: inline-size; }
.chess-square { position: relative; display: grid; place-items: center; min-width: 0; min-height: 0; width: 100%; height: 100%; padding: 0; border: 0; border-radius: 0; cursor: pointer; touch-action: manipulation; }
.chess-light { background: linear-gradient(110deg,#ebd6b0,#dfc396); }
.chess-dark { background: linear-gradient(110deg,#79563c,#503624); }
.chess-piece { font-family: 'DejaVu Sans','Segoe UI Symbol','Apple Symbols',serif; font-size: clamp(24px,8cqw,62px); line-height: 1; pointer-events: none; }
.chess-white { color: #fff9e9; text-shadow: 0 1px 2px #28180f,1px 0 #68472b,-1px 0 #68472b; }
.chess-black { color: #191613; text-shadow: 0 1px 1px #f1d6a3; }
.chess-selected { box-shadow: inset 0 0 0 4px #f2c14e; }
.chess-target::after { content: ''; position: absolute; width: 22%; aspect-ratio: 1; border-radius: 50%; background: #f2c14e; border: 2px solid #624717; pointer-events: none; }
.chess-target:has(.chess-piece)::after { width: 88%; border-radius: 8px; background: transparent; border: 3px dashed #ffdf73; }
.chess-check { box-shadow: inset 0 0 0 4px #b51f35; }
.chess-square:focus-visible { outline: 3px solid #0874c9; outline-offset: -4px; z-index: 1; }
.chess-panel { padding: 22px; border: 1px solid #dae5ed; border-radius: 18px; background: #fff; }
.chess-panel h2 { font-size: 1rem; margin: 20px 0 8px; }
.chess-captures { display: flex; flex-wrap: wrap; gap: 8px; margin: 0; padding: 0; list-style: none; font-size: 1.15rem; overflow-wrap: anywhere; }
.chess-panel button,.chess-dialog button { min-height: 44px; padding: 10px 16px; margin: 5px 0; background: #fff1b8; color: #12345b; border: 1px solid #d6bd75; border-radius: 10px; font: inherit; cursor: pointer; }
.chess-panel button:focus-visible,.chess-dialog button:focus-visible { outline: 3px solid #17659a; outline-offset: 2px; }
#chess-history { max-height: 240px; overflow-y: auto; padding-left: 26px; font-size: .9rem; }
#chess-message { min-height: 1.5em; }
.chess-dialog { width: min(460px,calc(100vw - 24px)); max-width: calc(100vw - 24px); max-height: calc(100dvh - 24px); padding: 20px; overflow-y: auto; border: 1px solid #b8cedf; border-radius: 20px; color: #12345b; background: #fff; }
.chess-dialog::backdrop { background: #12345b88; }
.promotion-options { display: flex; flex-wrap: wrap; gap: 10px; }
@media(max-width:767px) { .chess-layout { grid-template-columns: 1fr; gap: 14px; } .chess-page { padding: 22px 12px; } .chess-panel { padding: 18px; } }

#chess-draw-controls { margin: 12px 0; overflow-wrap: anywhere; }
#chess-draw-controls select { display: block; width: 100%; min-width: 0; min-height: 44px; margin: 8px 0; font: inherit; color: #12345b; }
#chess-draw-controls select:focus-visible { outline: 3px solid #17659a; outline-offset: 2px; }

/* Indicações independentes de cor; bordas duplas contrastam em ambas as casas. */
.chess-sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
.chess-board-legend { margin: 8px 0; font-size: .85rem; color: #163653; }
.chess-coordinate { position: absolute; z-index: 3; pointer-events: none; padding: 0 2px; border-radius: 2px; font: 700 clamp(10px,1.55cqw,12px)/1.15 "Segoe UI",sans-serif; color: #163653; background: #fff9e9; }
.chess-coordinate-rank { top: 1px; left: 1px; }
.chess-coordinate-file { bottom: 1px; right: 1px; }
.chess-white { -webkit-text-stroke: .8px #191613; paint-order: stroke fill; }
.chess-black { -webkit-text-stroke: .8px #fff9e9; paint-order: stroke fill; }
.chess-selected { box-shadow: inset 0 0 0 3px #163653,inset 0 0 0 6px #fff9e9; }
.chess-selection-mark { position: absolute; bottom: 1px; left: 1px; z-index: 3; padding: 0 2px; border-radius: 2px; background: #163653; color: #fff9e9; font: 700 12px/1.2 sans-serif; pointer-events: none; }
.chess-target::after { background: #163653; border: 2px solid #fff9e9; }
.chess-target:has(.chess-piece)::after { background: transparent; border: 3px dashed #fff9e9; box-shadow: 0 0 0 2px #163653; }
.chess-check { box-shadow: inset 0 0 0 3px #9b1631,inset 0 0 0 6px #fff9e9; }
.chess-check::before { content: '!'; position: absolute; top: 1px; right: 1px; z-index: 3; width: 16px; height: 16px; border-radius: 50%; background: #9b1631; color: #fff; font: 700 13px/16px sans-serif; pointer-events: none; }
.chess-square:focus-visible { outline: 3px solid #163653; outline-offset: -4px; box-shadow: inset 0 0 0 7px #fff9e9; z-index: 2; }
.chess-square { scroll-margin-block-start: calc(var(--game-header-height,80px) + 12px); }
.chess-dialog button { min-width: 44px; touch-action: manipulation; }
.chess-dialog-actions { display: flex; flex-wrap: wrap; gap: 10px; }
@media(max-width:430px) { .chess-panel button { width: 100%; } .chess-dialog { padding: 16px; } }
@media(forced-colors:active) { .chess-square:focus-visible { outline-color: Highlight; } .chess-selected { outline: 3px double Highlight; outline-offset: -6px; } .chess-target::after { background: Highlight; border-color: Canvas; } .chess-check::before { color: Canvas; background: CanvasText; } }

/* Modos educativos locais: os tabuleiros reutilizam a apresentação existente. */
#chess-learning [hidden] { display: none !important; }
.chess-mode-tabs { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 8px; margin: 0 0 16px; }
.chess-mode-tabs button,.chess-learning-card button,.chess-learning-actions button,.game-help button { min-height: 44px; padding: 10px 12px; border: 1px solid #d6bd75; border-radius: 10px; background: #fff1b8; color: #12345b; font: inherit; cursor: pointer; touch-action: manipulation; overflow-wrap: anywhere; }
.chess-mode-tabs button[aria-selected="true"] { border: 3px solid #163653; background: #163653; color: #fff9e9; font-weight: 700; }
#chess-learning button:focus-visible,#chess-learning select:focus-visible { outline: 3px solid #17659a; outline-offset: 2px; }
#chess-learning .chess-square:focus-visible { outline-offset: -4px; }
.chess-learning-layout { display: grid; grid-template-columns: minmax(0,1fr) minmax(240px,310px); gap: 28px; align-items: start; }
.chess-learning-layout > * { min-width: 0; }
.chess-learning-card { padding: 22px; border: 1px solid #dae5ed; border-radius: 18px; background: #fff; overflow-wrap: anywhere; }
.chess-learning-card h2 { margin: 16px 0 8px; font-size: 1.15rem; }
.chess-learning-card button { margin-block: 5px; }
.chess-learning-card label { font-weight: 700; }
.chess-learning-card select,#chess-practice-promotion { width: 100%; min-width: 0; min-height: 44px; margin-block: 8px; font: inherit; color: #12345b; }
.chess-learning-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.chess-learning-feedback { min-height: 3em; padding: 10px; border-left: 4px solid #17659a; background: #edf5fb; overflow-wrap: anywhere; }
.chess-learning-feedback[data-kind="correct"] { border-color: #21613c; background: #e9f6ee; }
.chess-learning-feedback:is([data-kind="incorrect"],[data-kind="illegal"],[data-kind="error"]) { border-color: #9b1631; background: #fff0f2; }
.chess-goal { outline: 3px dashed #163653; outline-offset: -7px; }
.chess-goal-mark { position: absolute; right: 2px; top: 2px; z-index: 3; color: #163653; background: #fff9e9; border-radius: 3px; font: 700 14px/1.1 sans-serif; pointer-events: none; }
@media(max-width:767px) { .chess-learning-layout { grid-template-columns: 1fr; gap: 14px; } .chess-learning-card { padding: 18px; } }
@media(max-width:430px) { .chess-learning-actions button,.chess-learning-card > button { width: 100%; } }

.chess-mode-tabs button { padding-inline: 4px; white-space: nowrap; font-size: clamp(14px,3.8vw,16px); }
.chess-learning-intro { margin-bottom: 16px; overflow-wrap: anywhere; }
.chess-learning-intro h2 { margin: 0 0 8px; font-size: 1.2rem; }
.chess-learning-intro p { margin: 0; }
.chess-learning-actions button:disabled,.chess-learning-card button:disabled { opacity: .6; cursor: not-allowed; }

.chess-course-progress { margin: 0 0 16px; padding: 12px; border: 1px solid #dae5ed; border-radius: 12px; background: #fff; overflow-wrap: anywhere; }
.chess-course-progress p { margin: 0 0 8px; }
#chess-course-meter { width: 100%; height: 14px; accent-color: #17659a; }
.chess-practice-choices { display: grid; gap: 8px; margin-block: 12px; }
.chess-practice-choices button { width: 100%; text-align: left; }
.chess-study-highlight { outline: 2px dashed #17659a; outline-offset: -6px; }
.chess-forbidden-mark { position: absolute; bottom: 1px; left: 1px; z-index: 4; color: #fff; background: #9b1631; border-radius: 3px; font: 700 14px/1.1 sans-serif; padding-inline: 2px; pointer-events: none; }
#chess-lesson-completion { font-weight: 600; }
