/* ============================================================
   Chess — Royal Strategy Theme
   accent: #854d0e (amber-800)
   ============================================================ */

:root {
    --ch-accent: #854d0e;
    --ch-accent-light: #a16207;
    --ch-accent-glow: rgba(133, 77, 14, .35);
    --ch-bg: #0c0a09;
    --ch-surface: #1c1917;
    --ch-surface2: #292524;
    --ch-border: #44403c;
    --ch-text: #fafaf9;
    --ch-text-dim: #a8a29e;
    --ch-light-sq: #e8d5b5;
    --ch-dark-sq: #b08968;
    --ch-highlight: rgba(133, 77, 14, .5);
    --ch-legal: rgba(133, 77, 14, .4);
    --ch-check: rgba(220, 38, 38, .6);
    --ch-last-move: rgba(234, 179, 8, .3);
}

/* ── Layout ── */
.ch-layout {
    display: flex;
    justify-content: center;
    gap: 1rem;
    max-width: 1200px;
    margin: 0 auto;
    padding: 1rem;
    min-height: calc(100vh - 60px);
}

.ad-slot { width: 160px; flex-shrink: 0; }
.ad-slot--left, .ad-slot--right { display: flex; align-items: flex-start; }
.ad-placeholder--vertical {
    width: 160px; height: 600px;
    background: var(--ch-surface);
    border: 1px dashed var(--ch-border);
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    color: var(--ch-text-dim); font-size: .75rem;
}

#chess-app {
    flex: 1;
    max-width: 640px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* ── Screens ── */
.screen { display: none; width: 100%; }
.screen.active { display: flex; flex-direction: column; align-items: center; }

/* ── Header ── */
.ch-header {
    text-align: center;
    margin-bottom: 2rem;
}
.ch-header h1 {
    font-family: 'Syne', sans-serif;
    font-size: 3rem;
    font-weight: 800;
    color: var(--ch-accent-light);
    letter-spacing: 0.12em;
    text-shadow: 0 0 40px var(--ch-accent-glow);
}
.ch-header .subtitle {
    font-family: 'DM Sans', sans-serif;
    color: var(--ch-text-dim);
    font-size: .95rem;
    margin-top: .25rem;
}

/* ── Cards ── */
.card {
    background: var(--ch-surface);
    border: 1px solid var(--ch-border);
    border-radius: 12px;
    padding: 1.25rem;
    margin-bottom: 1rem;
    width: 100%;
    max-width: 440px;
}
.card__title {
    font-family: 'Syne', sans-serif;
    font-weight: 600;
    color: var(--ch-accent-light);
    font-size: .85rem;
    text-transform: uppercase;
    letter-spacing: .08em;
    margin-bottom: .75rem;
}

/* ── Difficulty ── */
.difficulty-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: .5rem;
}
.diff-btn {
    background: var(--ch-surface2);
    border: 2px solid transparent;
    border-radius: 10px;
    padding: .75rem .5rem;
    cursor: pointer;
    text-align: center;
    transition: all .2s;
    color: var(--ch-text);
    font-family: 'DM Sans', sans-serif;
}
.diff-btn:hover { border-color: var(--ch-accent); }
.diff-btn.selected {
    border-color: var(--ch-accent);
    background: rgba(133, 77, 14, .15);
    box-shadow: 0 0 12px var(--ch-accent-glow);
}
.diff-icon { display: block; font-size: 1.5rem; margin-bottom: .25rem; }
.diff-desc { display: block; font-size: .7rem; color: var(--ch-text-dim); margin-top: .2rem; }

/* ── Color Select ── */
.color-select {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: .5rem;
}
.color-btn {
    background: var(--ch-surface2);
    border: 2px solid transparent;
    border-radius: 10px;
    padding: .75rem;
    cursor: pointer;
    color: var(--ch-text);
    font-family: 'DM Sans', sans-serif;
    font-size: .9rem;
    transition: all .2s;
    display: flex;
    align-items: center;
    gap: .5rem;
    justify-content: center;
}
.color-btn:hover { border-color: var(--ch-accent); }
.color-btn.selected {
    border-color: var(--ch-accent);
    background: rgba(133, 77, 14, .15);
}
.color-piece { font-size: 1.5rem; }

/* ── Buttons ── */
.btn {
    font-family: 'DM Sans', sans-serif;
    font-weight: 600;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all .2s;
    font-size: .9rem;
    padding: .6rem 1.2rem;
}
.btn--primary { background: var(--ch-accent); color: #fff; }
.btn--primary:hover { background: var(--ch-accent-light); box-shadow: 0 0 20px var(--ch-accent-glow); }
.btn--lg { padding: .85rem 2.5rem; font-size: 1rem; }
.btn--sm { padding: .4rem .8rem; font-size: .8rem; }
.btn--outline { background: transparent; border: 1px solid var(--ch-border); color: var(--ch-text); }
.btn--outline:hover { border-color: var(--ch-accent); color: var(--ch-accent-light); }
.btn--ghost { background: none; border: none; color: var(--ch-text-dim); text-decoration: underline; font-size: .85rem; }
.btn--ghost:hover { color: var(--ch-accent-light); }

.menu-actions {
    margin-top: 1.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .75rem;
}

/* ── HUD ── */
#game-hud {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    max-width: 520px;
    padding: .5rem 0;
    margin-bottom: .5rem;
}
.hud__cell { display: flex; flex-direction: column; gap: .2rem; }
.hud__cell--center { text-align: center; }
.hud__cell--right { text-align: right; }
.hud__label {
    font-family: 'JetBrains Mono', monospace;
    font-size: .7rem;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--ch-text-dim);
}
.hud__value {
    font-family: 'JetBrains Mono', monospace;
    font-size: 1rem;
    color: var(--ch-accent-light);
    font-weight: 700;
}
.hud__status {
    font-family: 'DM Sans', sans-serif;
    font-size: .85rem;
    color: var(--ch-accent-light);
    font-weight: 600;
}
#turn-indicator {
    font-size: .85rem;
    font-weight: 600;
    color: var(--ch-text);
}

/* ── Board ── */
.ch-board-area {
    display: flex;
    justify-content: center;
    width: 100%;
}
.ch-board-wrap {
    display: grid;
    grid-template-columns: 20px 1fr;
    grid-template-rows: 1fr 20px;
    gap: 0;
}
.ch-rank-labels {
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    align-items: center;
    font-family: 'JetBrains Mono', monospace;
    font-size: .65rem;
    color: var(--ch-text-dim);
    padding-right: 2px;
}
.ch-file-labels {
    display: flex;
    justify-content: space-around;
    align-items: center;
    font-family: 'JetBrains Mono', monospace;
    font-size: .65rem;
    color: var(--ch-text-dim);
    grid-column: 2;
    padding-top: 2px;
}

.ch-board {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    width: min(480px, calc(100vw - 60px));
    height: min(480px, calc(100vw - 60px));
    border: 2px solid var(--ch-accent);
    border-radius: 4px;
    overflow: hidden;
    box-shadow: 0 4px 30px rgba(0,0,0,.5);
}

.ch-cell {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: min(3.2rem, calc((100vw - 60px) / 10));
    cursor: pointer;
    position: relative;
    transition: background .15s;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}
.ch-cell--light { background: var(--ch-light-sq); }
.ch-cell--dark { background: var(--ch-dark-sq); }
.ch-cell--selected { background: var(--ch-highlight) !important; }
.ch-cell--legal::after {
    content: '';
    position: absolute;
    width: 28%;
    height: 28%;
    background: var(--ch-legal);
    border-radius: 50%;
}
.ch-cell--legal-capture {
    box-shadow: inset 0 0 0 4px var(--ch-legal);
}
.ch-cell--check { background: var(--ch-check) !important; }
.ch-cell--last-move { background-color: var(--ch-last-move) !important; }
.ch-cell:hover { filter: brightness(1.1); }

.ch-piece {
    line-height: 1;
    filter: drop-shadow(1px 1px 2px rgba(0,0,0,.4));
    transition: transform .1s;
    pointer-events: none;
}
.ch-cell--selected .ch-piece { transform: scale(1.1); }

/* ── Info bar ── */
.ch-info-bar {
    width: 100%;
    max-width: 520px;
    padding: .25rem 0;
    min-height: 1.5rem;
}
.captured-pieces {
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
    font-size: 1.1rem;
    min-height: 1.3rem;
}

/* ── Move History ── */
.ch-move-history {
    width: 100%;
    max-width: 520px;
    margin-top: .5rem;
}
.move-list {
    background: var(--ch-surface);
    border: 1px solid var(--ch-border);
    border-radius: 8px;
    padding: .5rem;
    max-height: 120px;
    overflow-y: auto;
    font-family: 'JetBrains Mono', monospace;
    font-size: .75rem;
    color: var(--ch-text-dim);
    display: flex;
    flex-wrap: wrap;
    gap: .15rem .5rem;
}
.move-entry {
    white-space: nowrap;
}
.move-num { color: var(--ch-text-dim); margin-right: .2rem; }
.move-white { color: var(--ch-text); }
.move-black { color: var(--ch-accent-light); }

/* ── Actions ── */
.ch-actions {
    display: flex;
    gap: .5rem;
    margin-top: .75rem;
    flex-wrap: wrap;
    justify-content: center;
}

/* ── Promotion ── */
.overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    backdrop-filter: blur(4px);
}
.overlay.hidden { display: none; }
.overlay__box {
    background: var(--ch-surface);
    border: 1px solid var(--ch-border);
    border-radius: 16px;
    padding: 1.5rem;
    text-align: center;
    color: var(--ch-text);
}
.promotion-box h3 {
    font-family: 'Syne', sans-serif;
    margin-bottom: 1rem;
    color: var(--ch-accent-light);
}
.promo-choices {
    display: flex;
    gap: .75rem;
    justify-content: center;
}
.promo-btn {
    font-size: 2.5rem;
    background: var(--ch-surface2);
    border: 2px solid var(--ch-border);
    border-radius: 12px;
    width: 64px;
    height: 64px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all .2s;
}
.promo-btn:hover {
    border-color: var(--ch-accent);
    background: rgba(133, 77, 14, .15);
    transform: scale(1.1);
}

/* ── Result / Leaderboard ── */
.result-card, .lb-card {
    background: var(--ch-surface);
    border: 1px solid var(--ch-border);
    border-radius: 16px;
    padding: 2rem;
    text-align: center;
    width: 100%;
    max-width: 440px;
}
.result-card h2, .lb-card h2 {
    font-family: 'Syne', sans-serif;
    font-size: 1.8rem;
    color: var(--ch-accent-light);
    margin-bottom: 1rem;
}
.result-score {
    font-family: 'JetBrains Mono', monospace;
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--ch-accent-light);
    text-shadow: 0 0 20px var(--ch-accent-glow);
    margin-bottom: .5rem;
}
.result-detail {
    color: var(--ch-text-dim);
    font-size: .9rem;
    margin-bottom: 1rem;
}
#nickname {
    width: 100%;
    max-width: 280px;
    padding: .6rem;
    border: 1px solid var(--ch-border);
    border-radius: 8px;
    background: var(--ch-surface2);
    color: var(--ch-text);
    font-family: 'DM Sans', sans-serif;
    text-align: center;
    margin-bottom: 1rem;
}
#nickname::placeholder { color: var(--ch-text-dim); }
.result-actions {
    display: flex;
    gap: .75rem;
    justify-content: center;
    margin-bottom: .75rem;
}

/* Leaderboard */
#leaderboard-list {
    list-style: none;
    padding: 0;
    margin: 0 0 1rem;
}
#leaderboard-list li {
    display: flex;
    justify-content: space-between;
    padding: .5rem .75rem;
    border-bottom: 1px solid var(--ch-border);
    font-family: 'JetBrains Mono', monospace;
    font-size: .85rem;
}
#leaderboard-list li:last-child { border-bottom: none; }
.lb-rank { color: var(--ch-accent-light); font-weight: 700; width: 2rem; }
.lb-name { flex: 1; text-align: left; color: var(--ch-text); margin-left: .5rem; }
.lb-score { color: var(--ch-accent-light); font-weight: 600; }

/* ── AI Thinking ── */
.ai-thinking {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0,0,0,.7);
    color: var(--ch-accent-light);
    padding: .5rem 1rem;
    border-radius: 8px;
    font-family: 'DM Sans', sans-serif;
    font-size: .85rem;
    z-index: 50;
    pointer-events: none;
    animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse {
    0%, 100% { opacity: .6; }
    50% { opacity: 1; }
}

/* ── Responsive ── */
@media (max-width: 900px) {
    .ad-slot--left, .ad-slot--right { display: none; }
    .ch-layout { padding: .5rem; }
}

@media (max-width: 480px) {
    .ch-board {
        width: calc(100vw - 40px);
        height: calc(100vw - 40px);
    }
    .ch-cell { font-size: calc((100vw - 40px) / 10); }
    .ch-header h1 { font-size: 2rem; }
    .difficulty-grid { grid-template-columns: repeat(3, 1fr); }
}
