:root {
    --color-bg-page: #f2ebe0;
    --color-bg-modal: #faf7f2;
    --color-text: #2c2c2c;
    --color-muted: #6b5b4f;
    --color-border: #c4b59a;
    --color-border-btn: #a08b6e;
    --color-disabled-bg: #e8e4dc;
    --color-disabled-text: #888;
    --piece-white-fill: #ffffff;
    --piece-white-stroke: #2c2c2c;
    --piece-black-fill: #2c2c2c;
    --piece-black-stroke: #ffffff;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: rgba(0,0,0,0);
    outline: none !important;
}

html, body {
    height: 100%;
    height: 100dvh; /* visible viewport on mobile (ignores URL bar) */
    width: 100%;
    overflow: hidden;
    background-color: #f2ebe0;
    background-color: var(--color-bg-page);
}

body {
    font-family: "Bookerly", "Caecilia", Georgia, serif;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: default;
}

body.fullscreen-mode {
    padding: 0;
    margin: 0;
    background-color: #000;
}

body.fullscreen-mode .player-status,
body.fullscreen-mode .player-bar,
body.fullscreen-mode .game-settings-btn {
    display: none;
}

body.fullscreen-mode .board-container {
    max-width: 100vh;
    max-height: 100vh;
    width: 100vw;
    height: 100vw;
    margin: 0;
}

body.fullscreen-mode .game-area,
body.fullscreen-mode .main-column {
    height: 100%;
    width: 100%;
}

body.fullscreen-mode .board {
    border: none;
}

.container {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

.game-area {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.main-column {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
}

.player-status {
    display: flex;
    align-items: stretch;
    margin: 5px 0;
    height: 44px;
    width: calc(100vw - 10px);
    max-width: calc(100vh - 115px);
}

.player-status-top { transform: rotate(180deg); }

.player-status-inner {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    flex: 1;
    min-width: 0;
    padding: 2px 8px;
}

.player-status-row {
    display: flex;
    align-items: center;
    min-width: 0;
}

.player-name {
    font-size: 13px;
    font-weight: bold;
    color: #2c2c2c;
    color: var(--color-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.player-captured {
    display: flex;
    align-items: center;
    margin-left: auto;
    margin-top: 0.5em; /* gap fallback */
    gap: 2px;
}

.btn {
    height: 44px;
    padding: 0;
    font-family: "Bookerly", "Caecilia", Georgia, serif;
    font-size: 24px;
    font-weight: bold;
    background: #2c2c2c;
    color: #fff;
    border: 1px solid #1a1a1a;
    border-radius: 0;
    width: calc(12.5% + 2px);
    flex: 0 0 calc(12.5% + 2px);
    line-height: 40px;
    cursor: pointer;
    touch-action: manipulation;
}

.btn:disabled { background: #e8e4dc; border-color: #c4b59a; color: #888; }
.btn:disabled { background: var(--color-disabled-bg); border-color: var(--color-border); color: var(--color-disabled-text); }
.btn.btn-new { font-size: 16px; width: auto; padding: 0 12px; flex: 0 0 auto; }

.btn-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-appearance: none;
    appearance: none;
    padding: 0;
}

.btn-nav svg {
    width: 26px;
    height: 22px;
    display: block;
    flex-shrink: 0;
    margin: 0 auto;
}

.btn-nav svg path { fill: #fff !important; }

.promotion-content .btn {
    width: 100%;
    flex: none;
    display: block;
    padding: 0 20px;
}

.player-message {
    font-size: 13px;
    font-weight: bold;
    color: #2c2c2c;
    color: var(--color-text);
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.player-score {
    font-size: 13px;
    font-weight: bold;
    line-height: 13px;
    margin: 0;
    margin-left: auto;
    color: #005500;
    white-space: nowrap;
}

.captured-row {
    display: flex;
    align-items: center;
    margin-right: 3px;
    height: 16px;
}
.captured-count {
    font-size: 13px;
    font-weight: bold;
    line-height: 13px;
    height: 13px;
    margin: 0;
    display: block;
    color: #6b5b4f;
}
.captured-symbol {
    width: 16px;
    height: 16px;
    display: flex;
    justify-content: center;
    align-items: center;
}
.captured-symbol svg { width: 100%; height: 100%; }

.board {
    position: relative;
    width: 100%;
    height: 100%;
    border: 2px solid #c4b59a;
    background: #b58863;
}
.square {
    position: absolute;
    width: 12.5%;
    height: 12.5%;
    display: flex;
    justify-content: center;
    align-items: center;
    touch-action: manipulation;
}
.square.light { background-color: #F0E0C7; }
.square.dark { background-color: #b58863; }
.square.selected { background-color: #90a050 !important; box-shadow: inset 0 0 0 3px #2c2c2c; }
.square.last-move { background-color: #bac84a !important; box-shadow: inset 0 0 0 2px #2c2c2c; }
.square.possible-move::after {
    content: '';
    position: absolute;
    width: 30%;
    height: 30%;
    top: 35%;
    left: 35%;
    background-color: #5a5a5a;
    border-radius: 50%;
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
}
.square.possible-move-ring::after {
    content: '';
    position: absolute;
    width: 30%;
    height: 30%;
    top: 35%;
    left: 35%;
    border: 2px solid #5a5a5a;
    background: transparent;
    border-radius: 50%;
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
}
.square.possible-move-hidden::after {
    display: none;
}
.square.possible-capture {
    box-shadow: inset 0 0 0 3px #2c2c2c;
}
.square.possible-capture-ring {
    box-shadow: inset 0 0 0 3px #2c2c2c;
    opacity: 0.6;
}
.square .coord-rank,
.square .coord-file {
    position: absolute;
    font-size: 10px;
    line-height: 1;
    pointer-events: none;
    user-select: none;
    z-index: 0;
}
.square .coord-rank { top: 2px; left: 2px; }
.square .coord-file { bottom: 2px; right: 2px; }
.square .coord-rank:empty,
.square .coord-file:empty { display: none; }
.square.light .coord-rank,
.square.light .coord-file { color: #2c2c2c; }
.square.dark .coord-rank,
.square.dark .coord-file { color: #f0e0c7; }
.square-inner {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    flex-shrink: 0;
}
.piece {
    position: relative;
    z-index: 1;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    pointer-events: none;
}
.rank1 { top: 87.5%; } .rank2 { top: 75%; } .rank3 { top: 62.5%; } .rank4 { top: 50%; }
.rank5 { top: 37.5%; } .rank6 { top: 25%; } .rank7 { top: 12.5%; } .rank8 { top: 0%; }
.file1 { left: 0%; } .file2 { left: 12.5%; } .file3 { left: 25%; } .file4 { left: 37.5%; }
.file5 { left: 50%; } .file6 { left: 62.5%; } .file7 { left: 75%; } .file8 { left: 87.5%; }

.board-container {
    position: relative;
    width: calc(100vw - 10px);
    height: calc(100vw - 10px);
    max-width: calc(100vh - 115px);
    max-width: calc(100dvh - 115px);
    max-height: calc(100vh - 115px);
    max-height: calc(100dvh - 115px);
    margin: 0 auto;
    display: flex;
    justify-content: center;
    align-items: center;
}

.promotion-modal {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: transparent;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

#welcomeModal {
    background: #f2ebe0;
    background: var(--color-bg-page);
}

#welcomeModal .promotion-content {
    position: relative;
    background: #faf7f2;
    background: var(--color-bg-modal);
    padding: 0;
    border: 1px solid #c4b59a;
    border: 1px solid var(--color-border);
    border-radius: 0;
    max-width: 400px;
    width: 90%;
    min-width: 340px;
    height: 580px;
    box-sizing: border-box;
    overflow: visible;
}

#welcomeModal .promotion-content-inner {
    overflow-y: auto;
    height: 100%;
    padding: 2.5em 2em 1em 2em;
    box-sizing: border-box;
    text-align: center;
}

.welcome-gear-btn {
    position: fixed;
    top: 6px;
    right: 6px;
    width: 28px;
    height: 28px;
    padding: 0;
    border: none;
    background: transparent;
    opacity: 0.35;
    z-index: 1001;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    display: block;
}

.welcome-gear-btn svg {
    width: 100%;
    height: 100%;
    display: block;
}

.game-settings-btn {
    position: fixed;
    top: 6px;
    right: 6px;
    width: 28px;
    height: 28px;
    padding: 0;
    border: none;
    background: transparent;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    z-index: 10;
    opacity: 0.35;
}
.game-settings-btn svg {
    width: 100%;
    height: 100%;
    display: block;
}

#welcomeModal .promotion-title {
    font-size: 1.5em;
    font-weight: 600;
    letter-spacing: 0.02em;
    margin: 0.4em 0 0.3em;
    padding-bottom: 0.6em;
    border-bottom: 1px solid #c4b59a;
    border-bottom: 1px solid var(--color-border);
    color: #2c2c2c;
    color: var(--color-text);
}

#welcomeModal .btn {
    background: #faf7f2;
    background: var(--color-bg-modal);
    border: 1px solid #a08b6e;
    border: 1px solid var(--color-border-btn);
    color: #2c2c2c;
    color: var(--color-text);
    padding-left: 30px;
    padding-right: 30px;
    width: 340px;
    box-sizing: border-box;
    font-size: 18px;
    font-weight: bold;
}

#welcomeModal .btn:disabled { background: #e8e4dc; border-color: #c4b59a; color: #888; }
#welcomeModal .btn:disabled { background: var(--color-disabled-bg); border-color: var(--color-border); color: var(--color-disabled-text); }
#welcomeModal .welcome-continue-wrap { margin-bottom: 0; }
#welcomeModal .welcome-buttons-wrap { display: flex; flex-direction: column; align-items: center; margin: 0 auto; gap: 0.5em; }
#welcomeModal .welcome-buttons-wrap .title-page-actions,
#welcomeModal .welcome-buttons-wrap .welcome-continue-wrap { display: flex; flex-direction: column; align-items: stretch; }
#welcomeModal .title-page-actions { margin-top: 0; gap: 0.5em; }
#welcomeModal .welcome-tagline { font-size: 0.85em; color: #6b5b4f; margin: 0 0 0.3em; text-align: center; }
#welcomeModal .welcome-tagline { font-size: 0.85em; color: var(--color-muted); margin: 0 0 0.3em; text-align: center; }

#gameInfoModal {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: transparent;
    z-index: 1002;
    align-items: center;
    justify-content: center;
    padding: 1em;
}

#gameInfoModal.show { display: flex; }

#gameInfoModal .variants-info-content {
    position: relative;
    background: #f2ebe0;
    background: var(--color-bg-page);
    border: 1px solid #c4b59a;
    border: 1px solid var(--color-border);
    max-width: 380px;
    width: calc(90vw - 20px);
    min-width: 320px;
    height: 560px;
    box-sizing: border-box;
    overflow-y: auto;
    padding: 1.25em 1.5em;
}

#gameInfoModal .variants-info-title {
    font-size: 1.5em;
    font-weight: 600;
    color: #2c2c2c;
    color: var(--color-text);
    margin-bottom: 0.75em;
    padding-bottom: 0.5em;
    border-bottom: 1px solid #c4b59a;
    border-bottom: 1px solid var(--color-border);
}

#gameInfoModal .variant-item {
    margin-bottom: 0.85em;
    font-size: 0.9em;
    line-height: 1.35;
    color: #2c2c2c;
    color: var(--color-text);
}

#gameInfoModal .variant-item strong { color: #2c2c2c; }
#gameInfoModal .variant-item strong { color: var(--color-text); }
#gameInfoModal .variant-item span { color: #6b5b4f; }
#gameInfoModal .variant-item span { color: var(--color-muted); }

#gameInfoModal .variants-info-close {
    position: absolute;
    top: 0.5em;
    right: 0.5em;
    width: 32px;
    height: 32px;
    margin: 16px;
    padding: 0;
    border: none;
    background: transparent;
    color: #2c2c2c;
    color: var(--color-text);
    cursor: pointer;
    touch-action: manipulation;
    display: flex;
    align-items: center;
    justify-content: center;
}
#gameInfoModal .variants-info-close::before {
    content: '\00d7';
    font-size: 2.5rem;
}

#eink-refresh-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background-color: #000;
    display: none;
    z-index: 10001;
}

.main-footer,
#welcomeFooter {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    text-align: center;
    padding: 10px;
    font-size: 12px;
    color: #6b5b4f;
    color: var(--color-muted);
}
#welcomeFooter { display: none; z-index: 1001; }

.main-footer a,
#welcomeFooter a {
    text-decoration: underline;
    color: #6b5b4f;
    color: var(--color-muted);
}
.main-footer a:hover,
#welcomeFooter a:hover { color: #2c2c2c; }
#welcomeFooter a:hover { color: var(--color-text); }

.welcome-continue-wrap {
    margin-top: 14px;
}

/* Chess-specific inline styles */
.square.check { background-color: #cc5555 !important; }
.piece svg { width: 80%; height: 80%; }
.piece[data-piece$="P"] svg { width: 80%; height: 80%; }
.piece[data-piece$="P"] { padding-top: 12%; }
.board.black-turn .piece[data-piece$="P"] { padding-top: 12%; padding-bottom: 0; }
.piece[data-piece$="R"] svg { width: 80%; height: 80%; }
.piece[data-piece$="R"] { padding-top: 8%; }
.board.black-turn .piece[data-piece$="R"] { padding-top: 8%; padding-bottom: 0; }
.board.black-turn .piece { transform: rotate(180deg); }
.board.rotation-locked { transform: rotate(0deg) !important; }
.board.rotation-locked .piece[data-piece^="b"] { transform: rotate(180deg) !important; }
.board.rotation-locked .piece[data-piece^="w"] { transform: rotate(0deg) !important; }

#promotionModal .promotion-content {
    background: #faf7f2;
    padding: 1.25em 1.5em;
    border: 1px solid #c4b59a;
    border-radius: 0;
    text-align: center;
    max-width: 90%;
}
#promotionModal .promotion-content .promotion-title {
    font-size: 1.5em;
    font-weight: 600;
    letter-spacing: 0.02em;
    margin: 0.4em 0 1em;
    padding-bottom: 0.6em;
    border-bottom: 1px solid #c4b59a;
    color: #2c2c2c;
}
.promotion-options { display: flex; justify-content: center; }
.promo-option {
    cursor: pointer; width: 55px; height: 55px;
    border: 1px solid #ccc; display: flex;
    justify-content: center; align-items: center;
    margin: 0 8px;
    touch-action: manipulation;
}
.promo-option svg { width: 70%; height: 70%; }

/* Inline interception in player-status boxes */
.intercept-actions {
    display: none;
    align-items: center;
    margin-left: auto;
    margin-top: 0.5em; /* gap fallback */
    gap: 4px;
    flex-shrink: 0;
}

.player-status.intercepting .intercept-actions {
    display: flex;
}

.player-status.intercepting .player-score,
.player-status.intercepting .move-annotation {
    display: none;
}

.player-status.intercepting {
    background: #faf7f2;
    background: var(--color-bg-modal);
    border: 1px solid #c4b59a;
    border: 1px solid var(--color-border);
}

.player-status.reflecting .player-name::after {
    content: ' \00a0!\00a0';
    color: #6b5b4f;
    color: var(--color-muted);
}

.btn-intercept {
    font-family: inherit;
    font-size: 11px;
    padding: 2px 8px;
    border: 1px solid #a08b6e;
    border: 1px solid var(--color-border-btn);
    background: #faf7f2;
    background: var(--color-bg-modal);
    color: #2c2c2c;
    color: var(--color-text);
    cursor: pointer;
    touch-action: manipulation;
    white-space: nowrap;
    height: 20px;
    line-height: 16px;
}

.btn-intercept-back {
    background: #2c2c2c;
    background: var(--color-text);
    color: #f2ebe0;
    color: var(--color-bg-page);
    border-color: #2c2c2c;
    border-color: var(--color-text);
}

.eval-bar {
    position: absolute;
    right: -5px;
    top: 0;
    display: none;
    flex-direction: column;
    pointer-events: none;
    overflow: hidden;
}
.eval-full {
    width: 4px;
    height: 100%;
}
.eval-sq {
    width: 3px;
    height: 100%;
}
.eval-black {
    background: #2c2c2c;
    flex-shrink: 0;
}
.eval-white {
    background: #f0e0c7;
    flex: 1;
}

.settings-section {
    margin-top: 1.5em;
    padding-top: 1em;
    border-top: 1px solid #c4b59a;
    border-top: 1px solid var(--color-border);
}
.settings-title {
    font-size: 1.1em;
    font-weight: 600;
    margin-bottom: 0.75em;
    color: #2c2c2c;
    color: var(--color-text);
}
.setting-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.6em;
}
.setting-label {
    font-size: 0.9em;
    color: #2c2c2c;
    color: var(--color-text);
}
.btn-setting {
    font-family: inherit;
    font-size: 0.85em;
    padding: 4px 12px;
    border: 1px solid #a08b6e;
    border: 1px solid var(--color-border-btn);
    background: #faf7f2;
    background: var(--color-bg-modal);
    color: #2c2c2c;
    color: var(--color-text);
    cursor: pointer;
    touch-action: manipulation;
    min-width: 80px;
    text-align: center;
    height: 36px;
}

#scenariosModal {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: #f2ebe0;
    background: var(--color-bg-page);
    z-index: 1002;
    align-items: center;
    justify-content: center;
    padding: 1em;
}

#scenariosModal.show { display: flex; }

.scenarios-content {
    position: relative;
    background: #faf7f2;
    background: var(--color-bg-modal);
    border: 1px solid #c4b59a;
    border: 1px solid var(--color-border);
    max-width: 400px;
    width: 90%;
    min-width: 320px;
    height: 580px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
}

.scenarios-title {
    font-size: 1.5em;
    font-weight: 600;
    color: #2c2c2c;
    color: var(--color-text);
    padding: 1.25em 1.5em 0.75em;
    border-bottom: 1px solid #c4b59a;
    border-bottom: 1px solid var(--color-border);
    flex-shrink: 0;
}

.scenarios-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.5em 0;
}

.scenario-card {
    display: flex;
    align-items: center;
    padding: 0.6em 1.25em;
    min-height: 60px;
    cursor: pointer;
    touch-action: manipulation;
    border-bottom: 1px solid #c4b59a;
    border-bottom: 1px solid var(--color-border);
}

.scenario-card:last-child { border-bottom: none; }

.scenario-icon {
    width: 48px;
    height: 48px;
    flex: 0 0 48px;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-right: 0.75em;
}

.scenario-icon svg { width: 100%; height: 100%; }

.scenario-text {
    flex: 1;
    min-width: 0;
}

.scenario-name {
    font-size: 1em;
    font-weight: 600;
    color: #2c2c2c;
    color: var(--color-text);
    line-height: 1.3;
}

.scenario-meta {
    font-size: 0.8em;
    color: #6b5b4f;
    color: var(--color-muted);
    line-height: 1.3;
}

.scenario-desc {
    font-size: 0.8em;
    color: #2c2c2c;
    color: var(--color-text);
    line-height: 1.3;
    margin-top: 0.15em;
}

.player-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 0.5em; /* gap fallback */
    gap: 6px;
    width: calc(100vw - 10px);
    max-width: calc(100vh - 115px);
    min-height: 24px;
    padding: 2px 4px;
    flex-wrap: wrap;
}

.player-bar-top {
    -webkit-transform: rotate(180deg);
    transform: rotate(180deg);
}

.player-pill {
    display: inline-block;
    font-family: inherit;
    font-size: 12px;
    line-height: 20px;
    padding: 0 8px;
    border: 1px solid #c4b59a;
    border: 1px solid var(--color-border);
    background: #f2ebe0;
    background: var(--color-bg-page);
    color: #6b5b4f;
    color: var(--color-muted);
    cursor: pointer;
    touch-action: manipulation;
    white-space: nowrap;
}

.player-pill.assigned-w {
    background: #2c2c2c;
    background: var(--color-text);
    color: #f2ebe0;
    color: var(--color-bg-page);
    border-color: #2c2c2c;
    border-color: var(--color-text);
}

.player-pill.assigned-b {
    background: #2c2c2c;
    background: var(--color-text);
    color: #f2ebe0;
    color: var(--color-bg-page);
    border-color: #2c2c2c;
    border-color: var(--color-text);
}

.player-bar input {
    font-family: inherit;
    font-size: 12px;
    line-height: 20px;
    height: 22px;
    padding: 0 6px;
    border: 1px solid #c4b59a;
    border: 1px solid var(--color-border);
    background: #f2ebe0;
    background: var(--color-bg-page);
    color: #2c2c2c;
    color: var(--color-text);
    box-sizing: border-box;
    width: 80px;
}

.move-annotation {
    font-size: 14px;
    font-weight: bold;
    line-height: 1;
    margin-left: 4px;
    color: #2c2c2c;
    color: var(--color-text);
    pointer-events: none;
    flex-shrink: 0;
}

.parent-signal {
    position: absolute;
    top: 4px;
    right: 4px;
    font-size: 14px;
    opacity: 0.3;
    pointer-events: none;
    line-height: 1;
}

.btn-secondary {
    background: #faf7f2 !important;
    background: var(--color-bg-modal) !important;
    color: #2c2c2c !important;
    color: var(--color-text) !important;
    border: 1px solid #a08b6e !important;
    border: 1px solid var(--color-border-btn) !important;
}

/* --- Opening name display --- */

.opening-name-display {
    font-size: 13px;
    font-weight: bold;
    color: #6b5b4f;
    color: var(--color-muted);
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: pointer;
    touch-action: manipulation;
}

.near-miss-hint {
    font-size: 11px;
    color: #6b5b4f;
    color: var(--color-muted);
    opacity: 0.6;
    line-height: 1;
    white-space: nowrap;
}

/* --- Opening modal --- */

#openingModal {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: transparent;
    z-index: 1002;
    align-items: center;
    justify-content: center;
    padding: 1em;
}

#openingModal.show { display: flex; }

.opening-content {
    position: relative;
    background: #f2ebe0;
    background: var(--color-bg-page);
    border: 1px solid #c4b59a;
    border: 1px solid var(--color-border);
    max-width: 380px;
    width: calc(90vw - 20px);
    min-width: 320px;
    max-height: 560px;
    box-sizing: border-box;
    overflow-y: auto;
    padding: 1.25em 1.5em;
}

.opening-title {
    font-size: 1.5em;
    font-weight: 600;
    color: #2c2c2c;
    color: var(--color-text);
    margin-bottom: 0.3em;
    padding-bottom: 0.5em;
    border-bottom: 1px solid #c4b59a;
    border-bottom: 1px solid var(--color-border);
}

.opening-eco {
    font-size: 0.85em;
    color: #6b5b4f;
    color: var(--color-muted);
    margin-bottom: 0.5em;
}

.opening-reputation {
    font-size: 0.85em;
    font-weight: 600;
    color: #6b5b4f;
    color: var(--color-muted);
    margin-bottom: 1em;
}

.opening-reputation:empty { display: none; }

.opening-reputation.rep-well-regarded-opening { color: #2d6a2e; }
.opening-reputation.rep-solid-opening { color: #3d6b5e; }
.opening-reputation.rep-offbeat-opening { color: #8b6914; }
.opening-reputation.rep-dubious-opening { color: #8b3a3a; }

.opening-flavour {
    font-size: 0.95em;
    line-height: 1.4;
    color: #2c2c2c;
    color: var(--color-text);
    margin-bottom: 0.75em;
    font-style: italic;
}

.opening-strategy {
    font-size: 0.9em;
    line-height: 1.4;
    color: #2c2c2c;
    color: var(--color-text);
    margin-bottom: 0.75em;
}

.opening-strength {
    font-size: 0.9em;
    line-height: 1.4;
    color: #2c2c2c;
    color: var(--color-text);
    margin-bottom: 0.75em;
}

.opening-pgn {
    font-size: 0.8em;
    color: #6b5b4f;
    color: var(--color-muted);
    font-family: monospace;
    margin-bottom: 0.75em;
}

.opening-funfact {
    font-size: 0.85em;
    line-height: 1.4;
    color: #6b5b4f;
    color: var(--color-muted);
    padding-top: 0.5em;
    border-top: 1px solid #c4b59a;
    border-top: 1px solid var(--color-border);
}

.opening-funfact:empty,
.opening-flavour:empty,
.opening-strategy:empty,
.opening-pgn:empty { display: none; }

/* --- Near-miss dot on board --- */

.square.near-miss-dot::before {
    content: '';
    position: absolute;
    width: 8%;
    height: 8%;
    top: 6%;
    right: 6%;
    background-color: #6b5b4f;
    background-color: var(--color-muted);
    border-radius: 50%;
    z-index: 2;
    opacity: 0.5;
}

/* ---- Coach map ---- */

.coach-map {
    position: fixed;
    top: 40px;
    right: 6px;
    display: none;
    grid-template-columns: repeat(8, 8px);
    grid-template-rows: repeat(8, 8px);
    opacity: 0.35;
    pointer-events: none;
    z-index: 10;
}
.coach-map.active { display: grid; }
.coach-map.rotated { transform: rotate(180deg); }
.coach-map-cell {
    width: 8px;
    height: 8px;
    position: relative;
    box-sizing: border-box;
}
.coach-map-cell.rank-border {
    border-bottom: 0.5px solid rgba(0, 0, 0, var(--rank-opacity, 0));
}
.coach-map-cell.file-border {
    border-right: 0.5px solid rgba(0, 0, 0, var(--file-opacity, 0));
}
.coach-map-cell.dot-best::before,
.coach-map-cell.dot-best::after {
    content: '';
    position: absolute;
    width: 7px;
    height: 1.5px;
    top: 3.25px;
    left: 0.5px;
    background: #2c2c2c;
}
.coach-map-cell.dot-best::before {
    -webkit-transform: rotate(45deg);
    -webkit-transform: rotate(45deg);
    transform: rotate(45deg);
}
.coach-map-cell.dot-best::after {
    -webkit-transform: rotate(-45deg);
    -webkit-transform: rotate(-45deg);
    transform: rotate(-45deg);
}
.coach-map-cell.dot-best-hard::after {
    content: '';
    position: absolute;
    width: 5px;
    height: 5px;
    top: 1.5px;
    left: 1.5px;
    background: #2c2c2c;
    border-radius: 50%;
}
.coach-map-cell.dot-ok::after {
    content: '';
    position: absolute;
    width: 3px;
    height: 3px;
    top: 2.5px;
    left: 2.5px;
    background: #2c2c2c;
    border-radius: 50%;
}

/* ---- Child whisper ---- */

.child-whisper {
    position: absolute;
    bottom: -16px;
    left: 0;
    right: 0;
    text-align: center;
    font-size: 12px;
    color: #6b5b4f;
    color: var(--color-muted);
    opacity: 0;
    transition: opacity 0.4s;
    pointer-events: none;
}
.child-whisper.visible { opacity: 1; }

/* ---- Pattern overlay ---- */

.pattern-overlay {
    position: absolute;
    top: 2px; left: 2px;
    width: calc(100% - 4px); height: calc(100% - 4px);
    pointer-events: none;
    z-index: 5;
}

/* Hint dot (distance 2 patterns) */
.square.pattern-hint-dot::before {
    content: '';
    position: absolute;
    width: 5px; height: 5px;
    border-radius: 50%;
    background: #2c2c2c;
    top: 2px; right: 2px;
    z-index: 3;
    opacity: 0.4;
}

/* Pattern text in status bar */
.pattern-name-display { font-style: italic; }
.pattern-text-socratic { font-style: italic; }

/* ---- Dev tools modal ---- */

#devToolsModal {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: #f2ebe0;
    background: var(--color-bg-page);
    z-index: 1002;
    align-items: center;
    justify-content: center;
    padding: 1em;
}

#devToolsModal.show { display: flex; }

.devtools-content {
    position: relative;
    background: #faf7f2;
    background: var(--color-bg-modal);
    border: 1px solid #c4b59a;
    border: 1px solid var(--color-border);
    max-width: 400px;
    width: 90%;
    min-width: 320px;
    box-sizing: border-box;
    padding: 1.25em 1.5em;
}

.devtools-title {
    font-size: 1.5em;
    font-weight: 600;
    color: #2c2c2c;
    color: var(--color-text);
    margin-bottom: 0.75em;
    padding-bottom: 0.5em;
    border-bottom: 1px solid #c4b59a;
    border-bottom: 1px solid var(--color-border);
}

.devtools-list {
    display: flex;
    flex-direction: column;
    margin-top: 0.5em; /* gap fallback */
    gap: 0.5em;
}

.devtools-link {
    display: block;
    text-align: center;
    text-decoration: none;
    line-height: 44px;
    width: 100%;
    flex: none;
    background: #faf7f2;
    background: var(--color-bg-modal);
    border: 1px solid #a08b6e;
    border: 1px solid var(--color-border-btn);
    color: #2c2c2c;
    color: var(--color-text);
    font-size: 18px;
    font-weight: bold;
}

body.fullscreen-mode .coach-map,
body.fullscreen-mode .child-whisper,
body.fullscreen-mode .pattern-overlay,
body.fullscreen-mode .bug-report-btn { display: none !important; }

/* ---- Bug report button ---- */

.bug-report-btn {
    position: fixed;
    top: 6px;
    left: 6px;
    width: 28px;
    height: 28px;
    padding: 0;
    border: none;
    background: transparent;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    z-index: 10;
    opacity: 0.35;
    font-size: 20px;
    line-height: 28px;
    text-align: center;
    color: #2c2c2c;
    color: var(--color-text);
}

.bug-report-btn.bug-report-sent::after {
    content: '\2713';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    line-height: 28px;
    text-align: center;
    font-size: 20px;
    color: #2c2c2c;
    color: var(--color-text);
    background: #f2ebe0;
    background: var(--color-bg-page);
}

.bug-report-btn[data-sending="true"] {
    opacity: 0.15;
    pointer-events: none;
}

/* --- Handicap modal --- */

#handicapModal {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: #f2ebe0;
    background: var(--color-bg-page);
    z-index: 1002;
    align-items: center;
    justify-content: center;
    padding: 1em;
}

#handicapModal.show { display: flex; }

.handicap-intro {
    font-size: 0.85em;
    color: #6b5b4f;
    color: var(--color-muted);
    padding: 0.75em 1.5em;
    border-bottom: 1px solid #c4b59a;
    border-bottom: 1px solid var(--color-border);
}

.handicap-card {
    display: flex;
    align-items: center;
    padding: 0.5em 1.25em;
    min-height: 52px;
    cursor: pointer;
    touch-action: manipulation;
    border-bottom: 1px solid #c4b59a;
    border-bottom: 1px solid var(--color-border);
}

.handicap-card:last-child { border-bottom: none; }

.handicap-pieces {
    display: flex;
    align-items: center;
    margin-top: 0.5em; /* gap fallback */
    gap: 0;
    flex: 0 0 auto;
}

.handicap-pieces .handicap-piece {
    width: 30px;
    height: 30px;
    flex: 0 0 30px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.handicap-pieces .handicap-piece svg { width: 100%; height: 100%; }

.handicap-pieces .handicap-piece.removed { opacity: 0.15; }

.handicap-label {
    font-size: 0.8em;
    color: #6b5b4f;
    color: var(--color-muted);
    margin-right: auto;
    padding-right: 0.75em;
    white-space: nowrap;
}

.handicap-elo {
    display: block;
    font-size: 0.8em;
    opacity: 0.4;
}

/* ---- Coaching panels ---- */

.coaching-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: calc(100vw - 10px);
    max-width: calc(100vh - 115px);
    min-height: 0;
    overflow: hidden;
}

.coaching-panel-top {
    -webkit-transform: rotate(180deg);
    transform: rotate(180deg);
}

/* When interception is active, shrink the board and give the panel room */
.main-column.coaching-active .board-container {
    max-height: calc(100vh - 360px);
    max-height: calc(100dvh - 360px);
    max-width: calc(100vh - 360px);
    max-width: calc(100dvh - 360px);
}

.main-column.coaching-active .coaching-panel {
    flex: 0 0 0;
}

.main-column.coaching-active .coaching-panel.active {
    flex: 0 0 auto;
    overflow: visible;
}

.coaching-panel-inner {
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 12px 16px;
}

.coaching-panel.active .coaching-panel-inner {
    display: flex;
}

.coaching-panel-actions {
    width: 100%;
    max-width: 320px;
}

.coaching-panel-message {
    font-size: 18px;
    font-weight: 600;
    color: #2c2c2c;
    color: var(--color-text);
    text-align: center;
    line-height: 1.4;
    margin-bottom: 16px;
    padding: 0 8px;
}

.coaching-panel-btn {
    font-family: inherit;
    font-size: 16px;
    font-weight: bold;
    width: 100%;
    max-width: 320px;
    height: 48px;
    border: 1px solid #a08b6e;
    border: 1px solid var(--color-border-btn);
    cursor: pointer;
    touch-action: manipulation;
}

.coaching-panel-btn-back {
    background: #2c2c2c;
    background: var(--color-text);
    color: #f2ebe0;
    color: var(--color-bg-page);
    border-color: #2c2c2c;
    border-color: var(--color-text);
    margin-bottom: 8px;
}

.coaching-panel-btn-play {
    background: #faf7f2;
    background: var(--color-bg-modal);
    color: #2c2c2c;
    color: var(--color-text);
}

body.fullscreen-mode .coaching-panel { display: none !important; }

/* ---- Ghost piece (interception) ---- */

.square.ghost-piece .piece { opacity: 0.25; padding-top: 0 !important; }
.square.ghost-source .piece { opacity: 0.4; }
.square.ghost-piece { background-color: #d4a0a0 !important; }
.square.ghost-piece::after,
.square.ghost-source::after { display: none; }

@media (max-width: 600px) {
    .btn { font-size: 18px; line-height: 44px; }
}
