/* Class Board. The coach's screen: one big board, the game, and the ideas tried on it. */

@property --board-scale {
    syntax: '<number>';
    inherits: true;
    initial-value: 1;
}

.class-wrap {
    width: min(1280px, calc(100% - 28px));
    margin: 18px auto 40px;
    transition: width 0.28s ease;
}

.class-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    margin-bottom: 14px;
}

.class-toolbar h1 {
    font-size: 1.25rem;
    margin: 0 8px 0 0;
}

.class-toolbar .grow { flex: 1; }

.looking-at {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 8px;
    margin: 0 0 12px;
    padding: 8px 12px;
    border-radius: 10px;
    background: #12203a;
    border: 1px solid #1d4ed8;
    color: #e5e7eb;
    font-size: 0.95rem;
    position: sticky;
    top: 8px;
    z-index: 6;
}
.looking-at[hidden],
.looking-at-inline[hidden] { display: none !important; }
.looking-kicker {
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #93c5fd;
}
.looking-at-inline {
    margin: 0 0 8px;
    padding: 8px 10px;
    border-radius: 8px;
    background: #12203a;
    border: 1px solid #1d4ed8;
    color: #93c5fd;
    font-weight: 600;
    font-size: 0.88rem;
}
.game-pick .is-seen,
.lib-pull .is-seen {
    color: #86efac;
}
.game-pick .is-seen::after,
.pick-name.is-seen::after {
    content: ' · looked';
    color: #86efac;
    font-weight: 600;
    font-size: 0.8rem;
}
.game-pick .is-current,
.pick-name.is-current {
    outline: 2px solid #f59e0b;
    background: #1e293b;
}

.cb-btn {
    appearance: none;
    border: 1px solid var(--border-subtle);
    background: var(--bg-secondary);
    color: var(--text-main);
    border-radius: 10px;
    min-height: 44px;
    padding: 8px 14px;
    font: inherit;
    font-weight: 600;
    font-size: 0.92rem;
    cursor: pointer;
}
.cb-btn:hover { background: var(--bg-tertiary); }
.cb-btn.primary { background: var(--accent-blue); border-color: transparent; color: #fff; }
.cb-btn.primary:hover { background: var(--accent-hover); }
.cb-btn.gold { background: var(--accent-gold); border-color: transparent; color: #0f172a; }
.cb-btn.on { outline: 2px solid var(--accent-gold); }
.cb-btn:disabled { opacity: 0.45; cursor: default; }

.class-wrap.roomy { width: min(1680px, calc(100% - 20px)); }

.size-control {
    display: inline-flex;
    align-items: stretch;
    height: 44px;
    border: 1px solid var(--border-subtle);
    border-radius: 10px;
    overflow: hidden;
    background: #0f172a;
}
.size-control .cb-btn {
    border: 0;
    border-radius: 0;
    min-width: 42px;
    min-height: 44px;
    padding: 0 12px;
    background: transparent;
    font-size: 1.15rem;
    line-height: 1;
}
.size-control .cb-btn:hover { background: var(--bg-tertiary); }
.size-control .cb-btn:disabled { background: transparent; }
.size-label {
    display: grid;
    place-items: center;
    min-width: 58px;
    padding: 0 8px;
    border-left: 1px solid var(--border-subtle);
    border-right: 1px solid var(--border-subtle);
    font-weight: 700;
    font-size: 0.85rem;
    color: var(--text-main);
}

.class-main {
    --board-scale: 1;
    --fit: min(640px, max(240px, calc(100vh - 280px)));
    --stack: min(1040px, max(220px, calc(var(--fit) * var(--board-scale))));
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: flex-start;
    gap: 18px;
    transition: --board-scale 0.28s ease;
}
@supports (height: 100dvh) {
    .class-main { --fit: min(640px, max(240px, calc(100dvh - 280px))); }
}

.board-card, .side-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: 16px;
    padding: 14px;
    min-width: 0;
}
.board-card {
    flex: 0 0 auto;
    width: min(100%, calc(var(--stack) + 28px));
}
.side-col {
    flex: 1 1 320px;
    max-width: 420px;
    min-width: 280px;
}
.board-stack {
    width: 100%;
    max-width: var(--stack);
    margin-inline: auto;
}

.player-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    min-height: 42px;
    padding: 0 12px;
    border-radius: 10px;
    background: #0f172a;
    border: 1px solid #1e293b;
    margin: 6px 0;
    font-weight: 700;
}
.player-bar .who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-bar .elo { color: var(--text-muted); font-weight: 600; font-size: 0.85rem; }
.player-bar.turn { box-shadow: inset 4px 0 0 var(--accent-gold); }
.player-bar.white-side { background: #f8fafc; color: #0f172a; }
.player-bar.white-side .elo { color: #475569; }

.board-row {
    display: grid;
    grid-template-columns: 22px minmax(0, 1fr);
    gap: 8px;
    align-items: stretch;
    min-width: 0;
}
.board-row.no-eval { grid-template-columns: minmax(0, 1fr); }

.eval-col {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}
.eval-num {
    font-weight: 800;
    font-size: 0.78rem;
    letter-spacing: -0.03em;
    color: var(--accent-gold);
}
.eval-track {
    flex: 1;
    width: 16px;
    border-radius: 8px;
    background: #1e293b;
    overflow: hidden;
    display: flex;
    flex-direction: column-reverse;
    min-height: 0;
}
.eval-fill {
    width: 100%;
    background: #f8fafc;
    height: 50%;
}
.eval-track.flipped { flex-direction: column; }

.board-frame { position: relative; width: 100%; }
.board {
    width: 100%;
    aspect-ratio: 1;
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    border-radius: 6px;
    overflow: hidden;
    user-select: none;
    touch-action: none;
    position: relative;
}
.sq {
    position: relative;
    display: grid;
    place-items: center;
}
.sq.light { background: #eeeed2; }
.sq.dark { background: #769656; }
.sq.last { box-shadow: inset 0 0 0 999px rgba(245, 158, 11, 0.38); }
.sq.selected { box-shadow: inset 0 0 0 999px rgba(245, 158, 11, 0.55); }
.sq.check { box-shadow: inset 0 0 0 999px rgba(220, 38, 38, 0.55); }
.sq img.piece {
    width: 88%;
    height: 88%;
    pointer-events: none;
    user-select: none;
}
.sq .coord {
    position: absolute;
    font-size: 11px;
    font-weight: 700;
    line-height: 1;
    pointer-events: none;
}
.sq.dark .coord { color: #eeeed2; }
.sq.light .coord { color: #769656; }
.sq .coord.file { right: 3px; bottom: 2px; }
.sq .coord.rank { left: 3px; top: 2px; }
.hint {
    width: 28%;
    height: 28%;
    border-radius: 50%;
    background: rgba(15, 23, 42, 0.35);
    pointer-events: none;
}
.sq.capture .hint {
    width: 86%;
    height: 86%;
    background: transparent;
    box-shadow: inset 0 0 0 5px rgba(15, 23, 42, 0.35);
}
.arrow-layer {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}
.arrow-layer .mark-hit {
    pointer-events: stroke;
    cursor: pointer;
}
.piece-ghost {
    position: fixed;
    pointer-events: none;
    z-index: 80;
    transform: translate(-50%, -50%);
    filter: drop-shadow(0 6px 8px rgba(0,0,0,.45));
}

.opening-line, .status-line, .idea-banner {
    margin: 8px 2px 0;
    color: var(--text-muted);
    font-size: 0.92rem;
}
.idea-banner {
    background: rgba(245, 158, 11, 0.12);
    color: #fde68a;
    border-radius: 10px;
    padding: 8px 12px;
}
.words-for-kids {
    margin-top: 8px;
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text-main);
}

.side-card h2 {
    font-size: 0.95rem;
    margin: 0 0 8px;
}
#engine-tools {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 8px;
}
#engine-tools[hidden],
#engine-lines[hidden],
#btn-best[hidden],
#words-for-kids[hidden],
.engine-card-toggle[hidden] {
    display: none !important;
}
.engine-card-toggle { display: none; margin-bottom: 8px; }
body.class-screen .engine-card-toggle { display: inline-flex; }
.side-card + .side-card { margin-top: 12px; }

.engine-lines { display: flex; flex-direction: column; gap: 6px; min-height: 72px; }
.engine-line {
    text-align: left;
    width: 100%;
    border: 1px solid var(--border-subtle);
    background: #0f172a;
    color: var(--text-main);
    border-radius: 10px;
    padding: 8px 10px;
    cursor: pointer;
    font: inherit;
}
.engine-line:hover { border-color: var(--accent-gold); }
.engine-line .pv-score {
    display: inline-block;
    min-width: 52px;
    font-weight: 800;
    color: var(--accent-gold);
    margin-right: 6px;
}
.engine-line .pv-san { color: #e2e8f0; }
.engine-meta { color: var(--text-dim); font-size: 0.8rem; margin-top: 6px; }

.move-list {
    max-height: 320px;
    overflow: auto;
    line-height: 2;
    font-size: 1rem;
}
.move-list button.move {
    background: transparent;
    border: 0;
    color: #e2e8f0;
    font: inherit;
    font-weight: 600;
    padding: 2px 5px;
    border-radius: 6px;
    cursor: pointer;
}
.move-list button.move.current {
    background: #f59e0b;
    color: #0f172a;
}
.variation {
    color: #94a3b8;
}
.variation .move { color: #cbd5e1; font-weight: 500; }
.note-chip {
    color: #93c5fd;
    font-size: 0.82rem;
    margin-right: 4px;
}
.move-tools, .note-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.note-row textarea, .note-row input, .drawer textarea, .drawer input[type="text"], .drawer select,
.modal textarea, .modal input[type="text"], .modal select {
    width: 100%;
    background: #0f172a;
    color: var(--text-main);
    border: 1px solid var(--border-subtle);
    border-radius: 10px;
    padding: 8px 10px;
    font: inherit;
}
.note-row textarea { min-height: 72px; resize: vertical; }

.lesson-strip {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 8px;
    margin-bottom: 8px;
}
.lesson-strip button {
    flex: 0 0 auto;
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.drawer-back {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 60;
}
.drawer {
    position: fixed;
    top: 0;
    right: 0;
    height: 100%;
    width: min(460px, 100%);
    background: #0b0f19;
    border-left: 1px solid var(--border-subtle);
    z-index: 61;
    overflow: auto;
    padding: 18px 16px 32px;
}
.drawer h2 { margin: 0 0 8px; }
.drawer h3 { font-size: 0.95rem; margin: 16px 0 8px; }
.drawer .row { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0; }
.game-pick {
    max-height: 280px;
    overflow: auto;
    border: 1px solid var(--border-subtle);
    border-radius: 10px;
}
.game-pick button {
    display: block;
    width: 100%;
    text-align: left;
    background: transparent;
    color: var(--text-main);
    border: 0;
    border-bottom: 1px solid #1e293b;
    padding: 10px 12px;
    font: inherit;
    cursor: pointer;
}
.game-pick button:hover, .game-pick button.active { background: #1e293b; }
.game-pick .lib-pull button {
    width: auto;
    border-bottom: 0;
}
.game-pick .lib-pull .pick-name {
    flex: 1;
    min-width: 0;
    text-align: left;
}
.help { color: var(--text-muted); font-size: 0.9rem; }

.palette { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.palette button {
    width: 44px;
    height: 44px;
    border-radius: 8px;
    border: 1px solid var(--border-subtle);
    background: #0f172a;
    padding: 4px;
    cursor: pointer;
}
.palette button.selected { outline: 2px solid var(--accent-gold); }
.palette button img { width: 100%; height: 100%; pointer-events: none; }
.castle-row { display: flex; gap: 12px; flex-wrap: wrap; color: var(--text-muted); }
.castle-row label { display: flex; align-items: center; gap: 6px; min-height: 44px; }

.modal-back {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.6);
    z-index: 70;
    display: grid;
    place-items: center;
    padding: 16px;
}
.modal {
    width: min(420px, 100%);
    background: #131b2e;
    border: 1px solid var(--border-subtle);
    border-radius: 16px;
    padding: 16px;
}
.promo-pieces { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.promo-pieces button {
    width: 64px;
    height: 64px;
    background: #0f172a;
    border: 1px solid var(--border-subtle);
    border-radius: 10px;
    cursor: pointer;
}
.promo-pieces button img { width: 100%; height: 100%; }

.toast {
    position: fixed;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    background: #1e293b;
    color: #fff;
    padding: 10px 16px;
    border-radius: 999px;
    z-index: 90;
    max-width: min(520px, calc(100% - 24px));
}

.keys { color: var(--text-dim); font-size: 0.8rem; margin-top: 8px; }

.side-card .row { flex-wrap: wrap; }

@media (prefers-reduced-motion: reduce) {
    .class-wrap, .class-main { transition: none; }
}

@media (max-height: 820px) {
    .move-list { max-height: 180px; }
}

@media (max-width: 900px) {
    .class-main { flex-direction: column; align-items: stretch; }
    .class-wrap { width: min(100% - 16px, 1280px); }
    .board-card, .side-col { width: 100%; max-width: none; min-width: 0; flex: 1 1 auto; }
    .board-stack { max-width: min(100%, var(--stack)); }
    .move-list { max-height: 220px; }
    .cb-btn { padding: 8px 12px; }
}

@media (max-width: 520px) {
    .class-wrap { margin-top: 8px; }
    .class-toolbar { gap: 6px; margin-bottom: 6px; }
    .cb-btn { min-height: 40px; padding: 6px 10px; font-size: 0.84rem; }
    .player-bar { min-height: 34px; margin: 2px 0; }
}

/* Class screen: the children see the board, the names, and Back / Next. */

.class-transport[hidden],
.class-moves-back[hidden] {
    display: none !important;
}

.class-transport {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 8px;
}
.class-transport .class-step {
    min-height: 64px;
    font-size: 1.15rem;
    border-radius: 12px;
}
.class-coach-row {
    grid-column: 1 / -1;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}
.class-coach-row > .size-control { flex: 1 1 160px; height: 44px; }
.class-coach-row > .cb-btn { flex: 1 1 90px; }
.class-coach-row .size-control .cb-btn { flex: 0 0 auto; min-width: 42px; }

.class-account {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-height: 44px;
    padding: 0 2px;
    color: #e2e8f0;
    font-weight: 700;
}
.class-account:empty { display: none; }
.class-account .who {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.class-account .cb-btn { flex: 0 0 auto; min-height: 40px; }

.class-import[hidden] { display: none !important; }
.class-import {
    grid-column: 1 / -1;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px;
    border: 1px solid #2d3748;
    border-radius: 12px;
    background: #131b2e;
}
.class-import label { font-weight: 700; color: #f8fafc; }
.class-import textarea,
.class-import input[type="text"] {
    width: 100%;
    font: inherit;
    font-size: 16px;
    border-radius: 10px;
    border: 1px solid #2d3748;
    background: #0b0f19;
    color: #f8fafc;
    padding: 8px 10px;
}
.class-import textarea { min-height: 96px; resize: vertical; }
.class-import-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.class-import .game-pick { max-height: 180px; }

.class-moves-back {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 70;
}

body.class-screen {
    overflow: auto;
}
body.class-screen .site-nav,
body.class-screen .class-toolbar,
body.class-screen .lesson-strip,
body.class-screen .looking-at,
body.class-screen .ip-credit,
body.class-screen .opening-line,
body.class-screen .status-line,
body.class-screen .words-for-kids,
body.class-screen .idea-banner {
    display: none !important;
}
body.class-screen #eval-col { display: none !important; }
body.class-screen .board-row { grid-template-columns: minmax(0, 1fr) !important; }
body.class-screen .class-wrap,
body.class-screen .class-wrap.roomy {
    --fit: min(calc(100vw - 36px), 920px, max(180px, calc(100vh - 320px)));
    --stack: min(1480px, max(180px, calc(var(--fit) * var(--board-scale, 1))));
    width: min(calc(var(--stack) + 36px), calc(100vw - 12px));
    min-height: 100vh;
    min-height: 100dvh;
    margin: 0 auto;
    padding: 8px 0 16px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    justify-content: safe center;
    transition: none;
}
@supports (height: 100dvh) {
    body.class-screen .class-wrap,
    body.class-screen .class-wrap.roomy {
        --fit: min(calc(100vw - 36px), 920px, max(180px, calc(100dvh - 320px)));
    }
}
body.class-screen .class-main {
    --fit: inherit;
    --stack: inherit;
    flex: 0 0 auto;
    width: 100%;
    gap: 0;
    transition: none;
}
body.class-screen .board-card {
    width: min(100%, calc(var(--stack) + 8px));
    border: 0;
    background: transparent;
    padding: 0 4px;
    box-shadow: none;
}
body.class-screen .player-bar {
    min-height: 46px;
    margin: 4px 0;
    font-size: 1.2rem;
    padding: 0 16px;
}
body.class-screen .side-col { display: none !important; }
body.class-screen.moves-open .side-col {
    display: flex !important;
    flex-direction: column;
    position: fixed;
    z-index: 80;
    top: 12px;
    right: 12px;
    bottom: 12px;
    width: min(420px, calc(100vw - 24px));
    max-width: none;
    min-width: 0;
    margin: 0;
    overflow: auto;
    background: transparent;
    border: 0;
    padding: 0;
}
body.class-screen.moves-open .side-card {
    box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
}
body.class-screen.moves-open .move-list { max-height: none; }

@media (max-width: 520px) {
    body.class-screen .class-transport .class-step { min-height: 56px; font-size: 1.05rem; }
    body.class-screen .player-bar { min-height: 40px; font-size: 1.05rem; }
}

.library-drawer { width: min(520px, 100%); }
.library-drawer label { display: block; margin: 10px 0 4px; font-weight: 600; }
.library-drawer textarea { min-height: 72px; }
.lib-item {
    display: flex;
    align-items: stretch;
    border-bottom: 1px solid #1e293b;
}
.lib-main { flex: 1; min-width: 0; }
.lib-item .lib-open {
    flex: none;
    width: 100%;
    min-width: 0;
    text-align: left;
    background: transparent;
    color: var(--text-main);
    border: 0;
    padding: 10px 12px;
    font: inherit;
    cursor: pointer;
}
.lib-item .lib-open:hover { background: #1e293b; }
.lib-item .lib-remove {
    flex: 0 0 auto;
    border: 0;
    border-left: 1px solid #1e293b;
    background: transparent;
    color: #fca5a5;
    padding: 8px 12px;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}
.lib-kind {
    display: inline-block;
    margin-right: 6px;
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: #93c5fd;
}
.lib-title { font-weight: 700; }
.lib-meta { display: block; color: var(--text-muted); font-size: 0.82rem; margin-top: 2px; }
.fen-input, .lib-fen {
    font-family: Consolas, "Courier New", monospace;
    font-size: 0.78rem;
    word-break: break-all;
}
.lib-fen-row {
    display: flex;
    gap: 8px;
    align-items: flex-start;
    padding: 0 12px 10px;
}
.lib-fen { flex: 1; min-width: 0; color: var(--text-muted); }
.lib-fen-row .cb-btn { width: auto; min-height: 32px; padding: 4px 8px; }
.lib-pull {
    display: flex;
    gap: 8px;
    align-items: center;
    padding: 8px 10px;
    border-bottom: 1px solid #1e293b;
}
.lib-pull span { flex: 1; min-width: 0; }
.lib-pull .cb-btn { min-height: 36px; padding: 6px 10px; width: auto; }

.nav-tools {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
}
.account-slot {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    min-height: 44px;
    min-width: 0;
}
.account-slot:empty { display: none; }
.account-slot .who {
    font-weight: 700;
    font-size: 0.88rem;
    color: #e2e8f0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 220px;
}
.account-slot .cb-btn,
.class-account .cb-btn,
.account-slot a.cb-btn,
.class-account a.cb-btn {
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.cb-btn.danger {
    background: #b91c1c;
    border-color: transparent;
    color: #fff;
}
.cb-btn.danger:hover { background: #991b1b; color: #fff; }
@media (max-width: 860px) {
    .account-slot .who { max-width: 34vw; font-size: 0.8rem; }
}
