:root {
    --page: #071019;
    --rail: #0d1722;
    --rail-2: #121f2c;
    --surface: #0b1420;
    --stroke: #26384b;
    --stroke-strong: #3a536d;
    --text: #edf5ff;
    --muted: #93a8bd;
    --player: #3c9dff;
    --computer: #ff982f;
    --danger: #ff4b4b;
    --ok: #6ee7a8;
    --rail-width: 336px;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-height: 100%;
    overflow: hidden;
}

body {
    font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--text);
    background: var(--page);
}

button {
    border: 0;
    border-radius: 8px;
    font: inherit;
    cursor: pointer;
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.45;
}

.app-shell {
    height: 100vh;
    min-height: 100vh;
    background:
        linear-gradient(90deg, rgba(20, 35, 50, 0.8) 0, rgba(20, 35, 50, 0.8) var(--rail-width), transparent var(--rail-width)),
        radial-gradient(circle at 72% 26%, rgba(53, 122, 160, 0.16), transparent 26%),
        linear-gradient(145deg, #09131f 0%, #05090f 100%);
}

.control-rail {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 5;
    width: var(--rail-width);
    height: 100vh;
    padding: 20px;
    display: grid;
    grid-template-rows: auto auto auto 1fr auto;
    gap: 14px;
    background: linear-gradient(180deg, var(--rail) 0%, #09111b 100%);
    border-right: 1px solid var(--stroke);
    box-shadow: 18px 0 42px rgba(0, 0, 0, 0.28);
    overflow: hidden;
    transform: none;
    contain: layout paint style;
}

.rail-brand {
    display: grid;
    grid-template-columns: 46px 1fr;
    gap: 12px;
    align-items: center;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--stroke);
}

.brand-mark {
    width: 46px;
    height: 46px;
    display: grid;
    place-items: center;
    border-radius: 8px;
    background: #18304a;
    border: 1px solid #2b5277;
    color: #a9d5ff;
    font-size: 1.35rem;
    font-weight: 800;
}

.rail-brand h1 {
    margin: 0;
    font-size: 1.15rem;
    line-height: 1.1;
    letter-spacing: 0;
}

.rail-brand p {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 0.82rem;
}

.turn-panel,
.message-panel,
.score-panel,
.action-panel {
    border: 1px solid var(--stroke);
    background: rgba(14, 26, 38, 0.88);
    border-radius: 8px;
}

.turn-panel {
    display: grid;
    grid-template-columns: 1fr 108px;
    min-height: 86px;
}

.turn-main,
.turn-time {
    padding: 14px;
    display: grid;
    align-content: center;
    gap: 6px;
}

.turn-time {
    border-left: 1px solid var(--stroke);
}

.metric-label {
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.turn-main strong,
.turn-time strong,
.message-panel strong {
    min-width: 0;
    overflow-wrap: anywhere;
}

.turn-main strong {
    font-size: 1.55rem;
}

.turn-time strong {
    font-size: 1.1rem;
    font-variant-numeric: tabular-nums;
}

.message-panel {
    min-height: 102px;
    padding: 14px;
    display: grid;
    align-content: start;
    gap: 10px;
}

.message-panel strong {
    font-size: 0.98rem;
    line-height: 1.38;
}

.score-panel {
    padding: 12px;
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
    align-self: start;
}

.score-tile {
    min-height: 70px;
    padding: 12px;
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    border-radius: 8px;
    border: 1px solid var(--stroke);
    background: var(--rail-2);
}

.score-tile span {
    color: var(--muted);
    font-size: 0.86rem;
    font-weight: 700;
}

.score-tile strong {
    font-size: 1.75rem;
    font-variant-numeric: tabular-nums;
}

.player-score {
    border-left: 4px solid var(--player);
}

.computer-score {
    border-left: 4px solid var(--computer);
}

.draw-score {
    border-left: 4px solid var(--ok);
}

.action-panel {
    padding: 12px;
    display: grid;
    gap: 10px;
}

.rail-button {
    min-height: 46px;
    padding: 0 14px;
    color: var(--text);
    font-weight: 750;
    text-align: left;
    border: 1px solid var(--stroke-strong);
    background: #142334;
}

.rail-button.strong {
    background: #2166a5;
    border-color: #3a8bd4;
}

.rail-button.quiet {
    background: #101c29;
}

.rail-button:hover:not(:disabled) {
    filter: brightness(1.08);
}

.board-area {
    margin-left: var(--rail-width);
    height: 100vh;
    min-height: 0;
    padding: 18px;
    display: grid;
    grid-template-rows: auto 1fr;
    gap: 10px;
    transform: none;
}

.board-hint {
    min-height: 34px;
    display: grid;
    place-items: center;
    color: var(--muted);
    font-size: 0.88rem;
    border: 1px solid var(--stroke);
    border-radius: 8px;
    background: rgba(12, 23, 34, 0.72);
}

.scene {
    position: relative;
    min-height: 0;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--stroke);
    background:
        radial-gradient(circle at 50% 45%, rgba(61, 131, 176, 0.12), transparent 42%),
        #07111b;
}

.board-canvas {
    position: absolute;
    inset: 0;
    display: block;
    width: 100%;
    height: 100%;
    cursor: grab;
    touch-action: none;
    user-select: none;
}

.overlay {
    position: fixed;
    inset: 0;
    z-index: 20;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(3, 8, 14, 0.78);
    backdrop-filter: blur(8px);
}

.overlay.visible {
    display: flex;
}

.overlay-card {
    width: min(92vw, 480px);
    padding: 20px;
    border-radius: 8px;
    border: 1px solid var(--stroke-strong);
    background: #0d1723;
    box-shadow: 0 28px 70px rgba(0, 0, 0, 0.5);
    text-align: center;
}

.overlay-card h2,
.overlay-card p {
    margin: 0;
}

.overlay-card h2 {
    font-size: 1.2rem;
}

.overlay-card p {
    margin-top: 8px;
    color: var(--muted);
}

.overlay-actions {
    margin-top: 18px;
    display: grid;
    gap: 10px;
}

.primary,
.secondary {
    min-height: 52px;
    color: var(--text);
    font-weight: 750;
}

.primary {
    background: #2f7ed8;
    border: 1px solid #68a8ef;
}

.secondary {
    background: #142334;
    border: 1px solid var(--stroke-strong);
}

@media (max-width: 920px) {
    html,
    body {
        overflow: auto;
    }

    .app-shell {
        height: auto;
        min-height: 100vh;
        background: #071019;
    }

    .control-rail {
        position: relative;
        width: auto;
        height: auto;
        inset: auto;
        grid-template-rows: auto;
        margin: 12px;
    }

    .score-panel {
        grid-template-columns: repeat(3, 1fr);
    }

    .score-tile {
        grid-template-columns: 1fr;
    }

    .board-area {
        margin-left: 0;
        height: auto;
        min-height: 70vh;
        padding: 12px;
    }

    .scene {
        min-height: 620px;
    }
}

@media (max-width: 620px) {
    .turn-panel,
    .score-panel {
        grid-template-columns: 1fr;
    }

    .turn-time {
        border-left: 0;
        border-top: 1px solid var(--stroke);
    }

    .scene {
        min-height: 520px;
    }
}
