@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,500;9..144,600;9..144,700&family=Inter:wght@400;500;600;700&family=IBM+Plex+Mono:wght@400;500;600&display=swap');

:root {
    --board: #1b2420;
    --board-deep: #131a16;
    --chalk: #f2efe4;
    --chalk-dim: rgba(242, 239, 228, 0.65);
    --chalk-faint: rgba(242, 239, 228, 0.15);
    --gold: #e8b84f;
    --human: #7fb3d5;
    --computer: #d9695f;
    --win-green: #7bc47f;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background-color: var(--board);
    background-image:
        radial-gradient(ellipse at top, rgba(255,255,255,0.04), transparent 60%),
        repeating-linear-gradient(0deg, rgba(255,255,255,0.015) 0px, rgba(255,255,255,0.015) 1px, transparent 1px, transparent 3px);
    color: var(--chalk);
    font-family: "Inter", sans-serif;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 40px 16px 60px;
}

.wrap {
    width: 100%;
    max-width: 720px;
}

/* --- Header --- */

.page-header {
    text-align: center;
    margin-bottom: 30px;
}

.eyebrow {
    font-family: "IBM Plex Mono", monospace;
    font-size: 0.8em;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--gold);
    margin: 0 0 6px;
}

.page-header h1 {
    font-family: "Fraunces", serif;
    font-weight: 600;
    font-size: 3em;
    margin: 0 0 8px;
    letter-spacing: -0.01em;
}

.page-header .tagline {
    color: var(--chalk-dim);
    font-size: 1.05em;
    margin: 0;
}

.nav-links {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-top: 18px;
    flex-wrap: wrap;
}

.nav-links a {
    font-family: "IBM Plex Mono", monospace;
    font-size: 0.82em;
    color: var(--chalk);
    text-decoration: none;
    background: rgba(242, 239, 228, 0.08);
    border: 1px solid var(--chalk-faint);
    padding: 7px 16px;
    border-radius: 20px;
    transition: background-color 0.15s, border-color 0.15s;
}

.nav-links a:hover {
    background: rgba(232, 184, 79, 0.15);
    border-color: var(--gold);
    color: var(--gold);
}

/* --- Status banner --- */

#status-banner {
    text-align: center;
    font-family: "IBM Plex Mono", monospace;
    font-size: 1.05em;
    padding: 12px 20px;
    border-radius: 10px;
    margin-bottom: 26px;
    background: rgba(242, 239, 228, 0.06);
    border: 1px solid var(--chalk-faint);
    min-height: 1.4em;
    transition: background-color 0.3s, border-color 0.3s;
}

#status-banner.turn-human {
    border-color: rgba(127, 179, 213, 0.5);
    color: var(--human);
}

#status-banner.turn-computer {
    border-color: rgba(217, 105, 95, 0.5);
    color: var(--computer);
}

#status-banner.game-over {
    border-color: var(--win-green);
    color: var(--win-green);
    font-size: 1.2em;
}

/* --- Board / piles --- */

#board {
    display: flex;
    justify-content: center;
    gap: 26px;
    flex-wrap: wrap;
    margin-bottom: 30px;
    min-height: 220px;
    align-items: flex-end;
}

.pile {
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
    padding: 10px 14px 0;
    border-radius: 14px;
    border: 2px dashed transparent;
    transition: border-color 0.15s, background-color 0.15s;
    touch-action: manipulation;
}

.pile:hover {
    background: rgba(242, 239, 228, 0.05);
}

.pile.disabled {
    cursor: default;
}

.stones {
    display: flex;
    flex-direction: column-reverse;
    align-items: center;
    gap: 6px;
    min-height: 190px;
    justify-content: flex-start;
}

.stone {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: radial-gradient(circle at 32% 28%, #fbf8ee, var(--chalk) 60%, #cfcabb 100%);
    box-shadow: 0 2px 4px rgba(0,0,0,0.35);
    transition: transform 0.15s ease, opacity 0.25s ease, box-shadow 0.15s ease;
    cursor: pointer;
    touch-action: manipulation;
}

.stone.preview {
    background: radial-gradient(circle at 32% 28%, #fff8e0, var(--gold) 60%, #c9932e 100%);
    box-shadow: 0 0 0 2px rgba(232, 184, 79, 0.5), 0 2px 6px rgba(0,0,0,0.4);
    transform: translateY(-2px);
}

.stone.removing {
    transform: scale(0.2) translateY(-20px);
    opacity: 0;
}

.pile-count {
    font-family: "IBM Plex Mono", monospace;
    font-size: 1.1em;
    font-weight: 600;
    margin-top: 10px;
    color: var(--chalk-dim);
}

/* --- Controls --- */

#controls {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    min-height: 50px;
}

.btn {
    font-family: "Inter", sans-serif;
    font-weight: 600;
    border: none;
    border-radius: 10px;
    padding: 11px 24px;
    cursor: pointer;
    font-size: 0.95em;
    transition: transform 0.1s, background-color 0.15s;
    touch-action: manipulation;
    min-height: 44px;
}

.btn:active {
    transform: scale(0.97);
}

.btn-primary {
    background: var(--gold);
    color: #241c0a;
}

.btn-primary:hover {
    background: #f0c766;
}

.btn-primary:disabled {
    background: #6b6248;
    color: rgba(255,255,255,0.4);
    cursor: default;
}

.btn-secondary {
    background: transparent;
    color: var(--chalk-dim);
    border: 1px solid var(--chalk-faint);
}

.btn-secondary:hover {
    border-color: var(--chalk);
    color: var(--chalk);
}

.hint-text {
    font-size: 0.85em;
    color: var(--chalk-dim);
    text-align: center;
    max-width: 400px;
}

/* --- Setup panel --- */

#setup-panel {
    background: rgba(242, 239, 228, 0.06);
    border: 1px solid var(--chalk-faint);
    border-radius: 14px;
    padding: 20px 24px;
    margin: 0 auto 26px;
    max-width: 500px;
    text-align: center;
}

#setup-panel.hidden {
    display: none;
}

#setup-panel h2 {
    font-family: "Fraunces", serif;
    font-weight: 600;
    margin-top: 0;
}

#setup-panel label {
    display: block;
    font-family: "IBM Plex Mono", monospace;
    font-size: 0.85em;
    color: var(--chalk-dim);
    margin: 14px 0 6px;
}

#setup-panel input {
    font-family: "IBM Plex Mono", monospace;
    background: var(--board-deep);
    border: 1px solid var(--chalk-faint);
    color: var(--chalk);
    padding: 8px 12px;
    border-radius: 8px;
    width: 100%;
    max-width: 300px;
    font-size: 0.95em;
}

#setup-panel .setup-actions {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-top: 18px;
}

#setup-error {
    color: var(--computer);
    font-size: 0.85em;
    margin-top: 8px;
    min-height: 1.2em;
}

footer.page-footer {
    text-align: center;
    margin-top: 30px;
}

footer.page-footer a {
    color: var(--gold);
    font-family: "IBM Plex Mono", monospace;
    font-size: 0.9em;
    text-decoration: none;
}

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

/* --- Solution page --- */

.info-section {
    background: rgba(242, 239, 228, 0.05);
    border: 1px solid var(--chalk-faint);
    border-radius: 14px;
    padding: 26px 30px;
    margin-bottom: 24px;
}

.info-section h2 {
    font-family: "Fraunces", serif;
    font-weight: 600;
    color: var(--gold);
    margin-top: 0;
}

.info-section p {
    line-height: 1.65;
    color: var(--chalk);
}

.info-section p.dim {
    color: var(--chalk-dim);
    font-size: 0.92em;
}

.binary-table {
    font-family: "IBM Plex Mono", monospace;
    width: 100%;
    border-collapse: collapse;
    margin: 18px 0;
}

.binary-table th, .binary-table td {
    text-align: center;
    padding: 8px 6px;
    border-bottom: 1px solid var(--chalk-faint);
}

.binary-table th {
    color: var(--chalk-dim);
    font-weight: 500;
    font-size: 0.85em;
}

.binary-table td.bit {
    font-size: 1.15em;
}

.binary-table tr.xor-row td {
    color: var(--gold);
    font-weight: 600;
    border-top: 2px solid var(--gold);
}

.binary-table td.pile-label {
    text-align: left;
    color: var(--chalk-dim);
    font-size: 0.85em;
}

.calc-box {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    justify-content: center;
    margin-bottom: 18px;
}

.calc-box input {
    font-family: "IBM Plex Mono", monospace;
    background: var(--board-deep);
    border: 1px solid var(--chalk-faint);
    color: var(--chalk);
    padding: 8px 12px;
    border-radius: 8px;
    width: 200px;
    font-size: 0.95em;
}

.result-pill {
    display: inline-block;
    font-family: "IBM Plex Mono", monospace;
    font-weight: 600;
    padding: 6px 16px;
    border-radius: 20px;
    margin-top: 8px;
}

.result-pill.winning {
    background: rgba(123, 196, 127, 0.15);
    color: var(--win-green);
    border: 1px solid var(--win-green);
}

.result-pill.losing {
    background: rgba(217, 105, 95, 0.15);
    color: var(--computer);
    border: 1px solid var(--computer);
}

@media (max-width: 600px) {
    body {
        padding: 24px 12px 40px;
    }
    .page-header h1 {
        font-size: 2.3em;
    }
    .page-header .tagline {
        font-size: 0.92em;
    }
    #board {
        gap: 14px;
        min-height: 180px;
    }
    .stones {
        min-height: 150px;
    }
    .stone {
        width: 28px;
        height: 28px;
    }
    .pile {
        padding: 8px 8px 0;
    }
    #controls {
        width: 100%;
        padding: 0 4px;
    }
    .setup-actions {
        flex-direction: column;
        align-items: stretch;
    }
    .setup-actions .btn {
        width: 100%;
    }
    #setup-panel {
        padding: 18px 16px;
    }
    .info-section {
        padding: 18px 18px;
    }
    .binary-table {
        font-size: 0.9em;
    }
    .calc-box input {
        width: 100%;
        max-width: none;
    }
    .calc-box {
        flex-direction: column;
        align-items: stretch;
    }
    .calc-box .btn {
        width: 100%;
    }
}

@media (max-width: 380px) {
    .page-header h1 {
        font-size: 1.9em;
    }
    .eyebrow {
        font-size: 0.7em;
    }
    .stone {
        width: 22px;
        height: 22px;
    }
    .stones {
        min-height: 120px;
    }
    #board {
        gap: 10px;
    }
    .pile-count {
        font-size: 0.95em;
    }
    .nav-links a {
        font-size: 0.76em;
        padding: 6px 12px;
    }
    .binary-table th, .binary-table td {
        padding: 6px 3px;
        font-size: 0.9em;
    }
}
