/* ═══════════════════════════════════════════════════════════
   Draughts Engine GUI
   ═══════════════════════════════════════════════════════════ */

:root {
    --board-light: #f0d9b5;
    --board-dark: #b58863;
    --board-size: 480px;
    --sq-size: calc(var(--board-size) / 8);
    --bg-primary: #312e2b;
    --bg-secondary: #272522;
    --bg-surface: #1f1d1a;
    --text-primary: #ccc;
    --text-secondary: #999;
    --accent: #7fc97f;
    --accent-dark: #4a9e4a;
    --last-move: #ffd600;
    /* below this width the page is one column: bar, buttons, board, the rest */
    --narrow: 800px;
}

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

html { -webkit-text-size-adjust: 100%; }

body {
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: 'Segoe UI', system-ui, sans-serif;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 100vh;
    padding: 20px 12px 32px;
}

/* ── Layout ───────────────────────────────────── */

.container {
    display: flex;
    gap: 16px;
    align-items: flex-start;
}

.sidebar {
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: center;
}

.center-column {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.info-panel {
    width: 200px;
    padding-top: 4px;
}

/* ── Eval bar ───────────────────────────────────
   Grows from the bottom (from the left when it lies down): the share of the
   side whose pieces are at the bottom of the board. */

.eval-bar-container {
    width: 28px;
    height: var(--board-size);
    background: var(--bg-surface);
    border: 1px solid #3a3733;
    border-radius: 4px;
    overflow: hidden;
    position: relative;
    flex-shrink: 0;
}

.eval-fill {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 50%;
    background: #f2f2f2;
    transition: height 0.4s ease, width 0.4s ease;
}

/* Black at the bottom: the bar is Black's share, drawn dark */
.eval-bar-container.black-bottom .eval-fill { background: #14120f; }

.eval-text {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    font-size: 11px;
    font-weight: 700;
    color: #ccc;
    writing-mode: vertical-rl;
    pointer-events: none;
    white-space: nowrap;
}

/* ── Controls ─────────────────────────────────── */

.controls {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.controls button {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 6px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    transition: background 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.controls button:hover { background: #3a3733; }
/* armed: the next press throws the game away */
.controls button.confirm { background: #b3541e; color: #fff; }
.controls button.confirm:hover { background: #c9601f; }
.controls button:active { background: var(--accent-dark); }
.controls button.off { color: #777; }
.controls .ico { line-height: 1; }
/* Icon alone on a wide screen; icon and word where there is no hover for the tooltip */
.controls .lbl { display: none; }

/* ── Player bars ──────────────────────────────── */

.player-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 12px;
    background: var(--bg-secondary);
    border-radius: 6px;
    border-left: 3px solid transparent;
    width: var(--board-size);
    font-size: 14px;
    gap: 8px;
}

/* The side to move */
.player-bar.active { border-left-color: var(--accent); }

.player-name { font-weight: 600; }

.player-badge {
    font-size: 11px;
    color: var(--text-secondary);
    background: var(--bg-surface);
    padding: 1px 7px;
    border-radius: 10px;
    margin-right: auto;
}

.piece-count {
    background: var(--bg-primary);
    padding: 2px 8px;
    border-radius: 4px;
    font-weight: 700;
    min-width: 28px;
    text-align: center;
}

.piece-count.advantage { color: var(--accent); }

/* ── Board ────────────────────────────────────── */

.board-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.board-row { display: flex; gap: 4px; }

.board {
    width: var(--board-size);
    height: var(--board-size);
    display: grid;
    grid-template-columns: repeat(8, var(--sq-size));
    grid-template-rows: repeat(8, var(--sq-size));
    border: 3px solid #1a1816;
    border-radius: 4px;
    overflow: hidden;
    box-shadow: 0 8px 32px rgba(0,0,0,0.5);
    touch-action: manipulation;    /* a tap is a tap; pieces opt out of scrolling themselves */
    user-select: none;
    -webkit-user-select: none;
}

.square {
    width: var(--sq-size);
    height: var(--sq-size);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

.square.light { background: var(--board-light); }
.square.dark { background: var(--board-dark); }

.square.highlight-move::after {
    content: '';
    position: absolute;
    width: 26%;
    height: 26%;
    border-radius: 50%;
    background: rgba(20, 20, 20, 0.35);
    pointer-events: none;
}

/* the square a capture of ours could land on is marked with a ring */
.square.highlight-move.capture::after {
    width: 78%;
    height: 78%;
    background: transparent;
    border: 4px solid rgba(20, 20, 20, 0.35);
}

.square.highlight-selected { background: #6295c4 !important; }

.square.highlight-hint::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(0,200,100,0.45);
    pointer-events: none;
}

.square.last-move { background-color: #e2cf5a !important; }
.square.dark.last-move { background-color: #b9a53e !important; }
.square.dark.clickable { cursor: pointer; }
.square.dark.clickable:hover { filter: brightness(1.15); }

/* ── Pieces ───────────────────────────────────── */

.piece {
    width: calc(var(--sq-size) - 12px);
    height: calc(var(--sq-size) - 12px);
    border-radius: 50%;
    position: absolute;
    top: 6px;
    left: 6px;
    cursor: grab;
    z-index: 10;
    touch-action: none;            /* dragging a piece must not scroll the page */
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.piece.white {
    background: radial-gradient(circle at 35% 35%, #fff, #e8e8e8 40%, #bbb 80%, #999);
    box-shadow: 0 2px 4px rgba(0,0,0,0.3), inset 0 1px 2px rgba(255,255,255,0.8);
    border: 1px solid #aaa;
}

.piece.black {
    background: radial-gradient(circle at 35% 35%, #666, #444 40%, #222 80%, #111);
    box-shadow: 0 2px 4px rgba(0,0,0,0.5), inset 0 1px 2px rgba(255,255,255,0.15);
    border: 1px solid #000;
}

.piece.king::after {
    content: '♛';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: calc(var(--sq-size) * 0.42);
    line-height: 1;
    pointer-events: none;
}

.piece.white.king::after { color: #333; text-shadow: 0 1px 1px rgba(255,255,255,0.5); }
.piece.black.king::after { color: #ffd700; text-shadow: 0 1px 2px rgba(0,0,0,0.8); }

/* the piece that just moved: the square alone is hidden under it */
.square.last-move .piece { outline: 3px solid var(--last-move); outline-offset: -1px; }

.piece.dragging {
    cursor: grabbing;
    z-index: 100;
    transform: scale(1.15);
    filter: drop-shadow(0 8px 12px rgba(0,0,0,0.5));
}

/* ── Coordinates ──────────────────────────────── */

.coords {
    display: flex;
    font-size: 11px;
    color: var(--text-secondary);
    font-weight: 600;
}

.coords-top, .coords-bottom {
    width: var(--board-size);
    justify-content: space-around;
}

.coords-left, .coords-right {
    flex-direction: column;
    height: var(--board-size);
    justify-content: space-around;
    width: 14px;
}

.coords span {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 14px;
    height: 14px;
}

/* ── Status ───────────────────────────────────── */

.status {
    font-size: 14px;
    color: var(--text-primary);
    text-align: center;
    margin-top: 4px;
    min-height: 1.4em;
}

.status.win { color: var(--accent); font-weight: 600; }

/* ── Move list ────────────────────────────────── */

.move-list {
    width: var(--board-size);
    background: var(--bg-secondary);
    border-radius: 6px;
    padding: 8px;
    min-height: 20px;
    max-height: 120px;
    overflow-y: auto;
    font-size: 13px;
    font-family: 'Consolas', monospace;
    margin-top: 4px;
}

.move-pair {
    display: flex;
    gap: 6px;
    padding: 1px 4px;
}

.move-num { color: var(--text-secondary); min-width: 24px; }

.move { padding: 1px 4px; border-radius: 3px; }

/* ── Side, settings ───────────────────────────── */

.side-select {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
}

.settings {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.setting-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.side-select label,
.setting-row label {
    font-size: 12px;
    color: var(--text-secondary);
}

.side-select select,
.setting-row select,
.setting-row input {
    background: var(--bg-surface);
    color: var(--text-primary);
    border: 1px solid #555;
    border-radius: 4px;
    padding: 3px 6px;
    font-family: inherit;
    font-size: 12px;
}

.setting-row input { width: 60px; text-align: center; }

/* ── Openings: the tables of the IDF ───────────── */

.opening-select {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    max-width: 100%;
}

/* the number row is a .setting-row, and that is display: flex — which wins
   over the browser's own rule for [hidden], so it is said here */
.opening-select [hidden] { display: none; }

.opening-select > label { font-size: 12px; color: var(--text-secondary); }

.opening-select > select {
    max-width: 100%;
    background: var(--bg-surface);
    color: var(--text-primary);
    border: 1px solid #555;
    border-radius: 4px;
    padding: 3px 6px;
    font-family: inherit;
    font-size: 12px;
}

.opening-select .setting-row { justify-content: flex-start; gap: 6px; }

.opening-select input { width: 64px; text-align: center; }

.opening-select button {
    padding: 3px 8px;
    border: none;
    border-radius: 4px;
    background: var(--bg-surface);
    border: 1px solid #555;
    font-family: inherit;
    font-size: 13px;
    line-height: 1;
    cursor: pointer;
}

.opening-select button:hover { border-color: var(--accent); }

/* What the table says of the chosen opening: its place and its moves */
.opening-text {
    max-width: 240px;
    font-size: 11px;
    line-height: 1.4;
    color: var(--text-secondary);
    overflow-wrap: anywhere;
}

/* The moves an opening dictated: played before this game was anybody's */
.move.forced { color: #8b9098; }

/* ── Engine info + PDN ────────────────────────── */

.engine-info {
    margin-bottom: 10px;
    padding: 8px;
    background: var(--bg-surface);
    border-radius: 6px;
    border: 1px solid #444;
}

.eval-display {
    font-size: 14px;
    font-weight: bold;
    color: var(--accent);
    margin-bottom: 4px;
}

.pv-display {
    font-size: 11px;
    color: #aaa;
    font-family: monospace;
    word-break: break-all;
}

.pdn-area { margin-top: 10px; }

.pdn-area label,
.fen-area summary {
    display: block;
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.pdn-area textarea {
    width: 100%;
    background: var(--bg-surface);
    color: var(--text-primary);
    border: 1px solid #555;
    border-radius: 4px;
    padding: 6px;
    font-size: 11px;
    font-family: monospace;
    resize: vertical;
}

.pdn-area textarea:focus { outline: none; border-color: var(--accent); }

.pdn-area button,
.fen-area button {
    margin-top: 4px;
    padding: 4px 10px;
    border: none;
    border-radius: 4px;
    background: var(--accent-dark);
    color: #fff;
    font-family: inherit;
    font-size: 11px;
    cursor: pointer;
}

.pdn-area button:hover,
.fen-area button:hover { background: var(--accent); }

.fen-area { margin-top: 10px; }

.fen-area summary {
    cursor: pointer;
    text-decoration: underline dotted;
    margin-bottom: 0;
}

.fen-area label { display: block; font-size: 12px; color: var(--text-secondary); margin-top: 8px; }

.fen-area input {
    width: 100%;
    margin: 4px 0;
    padding: 5px 6px;
    border: 1px solid #444;
    border-radius: 4px;
    background: var(--bg-surface);
    color: var(--text-primary);
    font-size: 11px;
    font-family: monospace;
}

/* ── One column: phones and narrow windows ────── */

@media (max-width: 800px) {
    body { padding: 8px 3vw 24px; }

    :root { --board-size: min(94vw, 440px); }

    .container {
        flex-direction: column;
        align-items: center;
        gap: 8px;
        width: 100%;
    }

    /* Bar, buttons, two settings — then the board, then the rest */
    .sidebar { order: 0; width: var(--board-size); gap: 8px; }
    .center-column { order: 1; }
    .info-panel { order: 2; width: var(--board-size); }

    /* The eval bar lies down above the board */
    .eval-bar-container { width: var(--board-size); height: 22px; }
    .eval-fill { top: 0; bottom: 0; height: 100%; width: 50%; }
    .eval-text { writing-mode: horizontal-tb; }

    /* A finger needs a bigger target than a pointer, and it gets no tooltip */
    .controls { flex-direction: row; flex-wrap: wrap; justify-content: center; gap: 6px; }
    .controls button { width: auto; height: 44px; padding: 0 10px; font-size: 15px; }
    .controls .lbl { display: inline; font-size: 12px; }

    .side-select { flex-direction: row; align-items: center; gap: 8px; }
    .settings { flex-direction: row; flex-wrap: wrap; justify-content: center; gap: 6px 16px; }
    .setting-row { gap: 6px; }
    .setting-row input { width: 54px; }

    .player-bar { font-size: 14px; }
    .status { font-size: 15px; }
    .coords { font-size: 10px; }
}
