*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root { --sq: 60px; }

body {
    background: #edf7eb;
    color: #2c5521;
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 32px 20px;
    gap: 28px;
    overscroll-behavior: none;
}

footer {
    margin-top: auto;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    color: #7aaa6e;
    padding-top: 8px;
}

footer a {
    color: #3a7a2a;
    text-decoration: none;
}

footer a:hover {
    text-decoration: underline;
}

h1 {
    font-size: 26px;
    font-weight: 700;
    letter-spacing: 3px;
    text-transform: uppercase;
    color: #3a7a2a;
    text-shadow: 0 0 24px rgba(58, 122, 42, 0.2);
}

/* ── Controls ───────────────────────────────────────── */
.controls {
    display: flex;
    align-items: stretch;
    gap: 14px;
    flex-wrap: wrap;
    justify-content: center;
}


.btn {
    padding: 9px 20px;
    background: rgba(106, 184, 90, 0.12);
    color: #3a7a2a;
    border: 2px solid #6ab85a;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 700;
    letter-spacing: 0.5px;
    line-height: 1;
    transition: background 0.2s, color 0.2s;
}
.btn:hover { background: #6ab85a; color: #f5fff3; }

/* ── White / Black side button states ───────────────────── */
.btn.wtg-white, .btn.flip-white {
    background: #ffffff;
    color: #1a1a1a;
    border-color: #1a1a1a;
}
.btn.wtg-white:hover, .btn.flip-white:hover {
    background: #e8e8e8;
    color: #1a1a1a;
}
.btn.wtg-black, .btn.flip-black {
    background: #1a1a1a;
    color: #ffffff;
    border-color: #1a1a1a;
}
.btn.wtg-black:hover, .btn.flip-black:hover {
    background: #383838;
    color: #ffffff;
}

/* ── Button groups ───────────────────────────────────────── */
.btn-group {
    display: flex;
    align-items: stretch;
    border: 2px solid #6ab85a;
    border-radius: 8px;
    overflow: hidden;
    flex: 1;
}

/* Buttons inside a group share the group outline */
.btn-group > .btn {
    border: none;
    border-right: 1px solid rgba(106, 184, 90, 0.35);
    border-radius: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
}
.btn-group > .btn:last-child { border-right: none; }

/* Divider tint when adjacent to a coloured button */
.btn-group > .btn.wtg-white,
.btn-group > .btn.flip-white {
    border-right-color: rgba(26, 26, 26, 0.2);
}
.btn-group > .btn.wtg-black,
.btn-group > .btn.flip-black {
    border-right-color: rgba(255, 255, 255, 0.15);
}

/* Count group: no internal divider; count button fills available width */
#count-group > .btn { border-right: none; flex: 1; }

/* Setup group: "Go" button stretches to fill spare width */
#wtg-btn { flex: 1; }

/* ── Stats bar ──────────────────────────────────────── */
.stats-bar {
    font-size: 15px;
    font-weight: 400;
    font-style: italic;
    color: #3a7a2a;
    letter-spacing: 0.3px;
}
.stats-bar.hidden { display: none; }

/* ── Layout ─────────────────────────────────────────── */
.chess-layout {
    display: flex;
    align-items: flex-start;
    gap: 18px;
}

/* ── Piece panels ───────────────────────────────────── */
.piece-panel {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 14px 10px;
    background: #f5fbf3;
    border: 2px solid #8acc7a;
    border-radius: 10px;
}
.panel-title {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    color: #3a7a2a;
    margin-bottom: 6px;
}
.piece-item {
    font-size: 42px;
    line-height: 1;
    cursor: grab;
    padding: 5px;
    border-radius: 6px;
    user-select: none;
    touch-action: none;
    transition: transform 0.15s, background 0.15s;
}
.piece-item:hover {
    transform: scale(1.2);
    background: rgba(106, 184, 90, 0.2);
}

/* ── Board area ─────────────────────────────────────── */
.board-area {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}
.board-and-ranks {
    display: flex;
    align-items: stretch;
    gap: 0;
}
.rank-col {
    display: flex;
    flex-direction: column;
    justify-content: space-around;
}
.rlabel {
    font-size: 14px;
    font-weight: 700;
    color: #7aaa6e;
    width: 24px;
    padding-right: 8px;
    height: var(--sq);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    border-radius: 3px;
    transition: color 0.15s, background 0.15s;
}
.rlabel-r {
    justify-content: flex-start;
    padding-right: 0;
    padding-left: 10px;
}
.board {
    display: flex;
    flex-direction: column;
    border: 3px solid #6ab85a;
    box-shadow: 0 0 32px rgba(106, 184, 90, 0.25);
}
.board-row { display: flex; }

.square {
    width: var(--sq);
    height: var(--sq);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    font-size: calc(var(--sq) * 0.7);
}
.sq-light { background: #e8f5e2; }
.sq-dark  { background: #7ab868; }

.drag-over::after {
    content: '';
    position: absolute;
    inset: 2px;
    border: 3px solid rgba(30, 110, 60, 0.75);
    border-radius: 2px;
    background: rgba(30, 110, 60, 0.15);
    pointer-events: none;
    z-index: 2;
}

.sq-move-count {
    position: absolute;
    top: 2px;
    right: 3px;
    font-size: 11px;
    font-weight: 700;
    line-height: 1;
    color: #1e5c14;
    background: rgba(255, 255, 255, 0.72);
    border-radius: 3px;
    padding: 0 2px;
    pointer-events: none;
    z-index: 3;
}

.sq-light .sq-move-count {
    background: none;
    padding: 0;
}

.piece-on-board {
    line-height: 1;
    user-select: none;
    cursor: grab;
    touch-action: none;
    z-index: 1;
}

.piece-w {
    color: #fffff0;
    text-shadow:
        -1px -1px 0 #2c5521,
         1px -1px 0 #2c5521,
        -1px  1px 0 #2c5521,
         1px  1px 0 #2c5521;
}

.piece-b {
    color: #1a1a0a;
    text-shadow:
        -1px -1px 0 #6ab85a,
         1px -1px 0 #6ab85a,
        -1px  1px 0 #6ab85a,
         1px  1px 0 #6ab85a;
}

.file-row {
    display: flex;
    margin-left: 27px;   /* aligns with board squares (rank-col 16px + gap 8px + border 3px) */
}
.file-row-top .flabel {
    padding-top: 0;
    padding-bottom: 4px;
}
.flabel {
    width: var(--sq);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 700;
    color: #7aaa6e;
    padding-top: 4px;
    border-radius: 3px;
    transition: color 0.15s, background 0.15s;
}

.label-highlight {
    color: #1e5c14 !important;
    background: rgba(106, 184, 90, 0.35);
}

/* ── En passant / castle indicators ─────────────────── */
.ep-indicator {
    position: absolute;
    top: 2px;
    left: 3px;
    display: flex;
    flex-direction: column;
    align-items: center;
    font-size: 11px;
    font-weight: 700;
    line-height: 1;
    pointer-events: none;
    z-index: 3;
}

.ep-arrow {
    display: block;
    line-height: 1;
}

.castle-indicator {
    position: absolute;
    top: 2px;
    left: 3px;
    font-size: 11px;
    line-height: 1;
    pointer-events: none;
    z-index: 3;
}

/* Arrows are text — use CSS color directly */
.sq-light .ep-indicator { color: #2c5521; }
.sq-dark  .ep-indicator { color: #d4f0c8; }

/* Castle icon is a text character — same color approach as arrows */
.sq-light .castle-indicator { color: #2c5521; }
.sq-dark  .castle-indicator { color: #d4f0c8; }

/* ── Touch drag ghost ───────────────────────────────── */
.touch-ghost {
    position: fixed;
    pointer-events: none;
    z-index: 9999;
    line-height: 1;
    opacity: 0.8;
    user-select: none;
}

/* ── Mobile layout ──────────────────────────────────── */
@media (max-width: 559px) {
    :root { --sq: calc((100vw - 80px) / 8); }

    .chess-layout {
        flex-wrap: wrap;
        justify-content: center;
    }

    .board-area { order: -1; }

    .piece-panel {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
        max-width: 120px;
        padding: 6px 8px;
    }

    .panel-title { width: 100%; }

    .piece-item {
        font-size: 28px;
        padding: 2px;
    }

    .btn-group { flex-basis: 100%; }
}

/* ── Depth spinner ───────────────────────────────────────── */
.depth-wrapper {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 2px;
    padding: 0 10px;
}
.depth-arrows {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.depth-arrow {
    width: 20px;
    height: 13px;
    padding: 0;
    background: transparent;
    color: #3a7a2a;
    border: none;
    cursor: pointer;
    font-size: 8px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 3px;
}
.depth-arrow:hover { background: rgba(106, 184, 90, 0.3); }
.depth-input {
    width: 28px;
    padding: 2px 0;
    background: transparent;
    color: #3a7a2a;
    border: none;
    font-size: 14px;
    font-weight: 700;
    text-align: center;
    -moz-appearance: textfield;
}
.depth-input::-webkit-outer-spin-button,
.depth-input::-webkit-inner-spin-button { -webkit-appearance: none; }

/* ── Stats turn lines ────────────────────────────────────── */
.turn-line {
    padding: 2px 0;
}

.mate-btn {
    cursor: pointer;
    font-weight: 700;
    text-decoration: underline;
    color: #3a7a2a;
}
.mate-btn:hover { color: #1e5c14; }

.truncated-warn {
    color: #cc6600;
    font-size: 12px;
}

/* ── Mate preview overlay ────────────────────────────────── */
.board-preview {
    pointer-events: none;
    border-color: #666;
    box-shadow: 0 0 32px rgba(100, 100, 100, 0.2);
}

/* ── Mated king cross ────────────────────────────────────── */
.king-cross {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: calc(var(--sq) * 0.88);
    font-weight: 900;
    color: rgba(210, 0, 0, 0.9);
    -webkit-text-stroke: 1.5px rgba(210, 0, 0, 0.9);
    pointer-events: none;
    z-index: 10;
    line-height: 1;
}
