:root {
    --bg: #202e28;
    --bg-panel: #1a2620;
    --chalk: #f4f0e4;
    --chalk-dim: #b9c4bb;
    --line: rgba(244, 240, 228, 0.16);

    --p0: #ff8a7a;
    /* coral chalk */
    --p1: #5fd0f2;
    /* sky chalk */
    --p2: #ffd868;
    /* sunflower chalk */
    --p3: #c9a0ff;
    /* lilac chalk */

    --radius: 20px;
    --font-display: 'Fredoka', sans-serif;
    --font-hand: 'Kalam', cursive;
    --font-mono: 'Space Mono', monospace;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    height: 100%;
    background: var(--bg);
    color: var(--chalk);
    font-family: var(--font-display);
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior: none;
}

body {
    background-image:
        radial-gradient(circle at 20% 15%, rgba(244, 240, 228, 0.035) 0, transparent 45%),
        radial-gradient(circle at 85% 75%, rgba(244, 240, 228, 0.03) 0, transparent 40%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
}

button,
input {
    font-family: inherit;
}

.board {
    width: 100%;
    max-width: 480px;
    min-height: 100vh;
    padding: 24px 20px 32px;
    position: relative;
}

/* ---------- Screens ---------- */
.screen {
    display: none;
    animation: fade-in .25s ease;
}

.screen[data-active="true"] {
    display: block;
}

@keyframes fade-in {
    from {
        opacity: 0;
        transform: translateY(6px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.screen-title {
    font-size: 26px;
    font-weight: 600;
    margin: 8px 0 2px;
}

.screen-sub {
    font-family: var(--font-hand);
    color: var(--chalk-dim);
    font-size: 18px;
    margin: 0 0 20px;
}

/* ---------- Home ---------- */
.chalk-title {
    text-align: center;
    margin: 12vh 0 40px;
}

.chalk-emoji {
    font-size: 42px;
    display: block;
    margin-bottom: 6px;
}

.chalk-title h1 {
    font-size: 40px;
    font-weight: 700;
    margin: 0;
    letter-spacing: 0.5px;
}

.tagline {
    font-family: var(--font-hand);
    font-size: 19px;
    color: var(--chalk-dim);
    margin: 4px 0 0;
}

.home-actions {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.btn {
    border: none;
    border-radius: 999px;
    padding: 18px 20px;
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 18px;
    cursor: pointer;
    transition: transform .12s ease, opacity .12s ease;
}

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

.btn-primary {
    background: var(--p0);
    color: #241512;
}

.btn-ghost {
    background: transparent;
    color: var(--chalk);
    border: 2px dashed var(--line);
}

.btn-back {
    background: none;
    border: none;
    color: var(--chalk-dim);
    font-family: var(--font-hand);
    font-size: 18px;
    padding: 6px 0 18px;
    cursor: pointer;
}

/* ---------- Setup ---------- */
.name-form {
    display: flex;
    flex-direction: column;
    gap: 14px;
    margin-top: 8px;
}

.name-row {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--bg-panel);
    border: 2px solid var(--line);
    border-radius: 16px;
    padding: 4px 16px;
}

.dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    flex: none;
}

.dot-0 {
    background: var(--p0);
}

.dot-1 {
    background: var(--p1);
}

.dot-2 {
    background: var(--p2);
}

.dot-3 {
    background: var(--p3);
}

.name-row input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--chalk);
    font-size: 18px;
    padding: 14px 0;
}

.name-row input::placeholder {
    color: var(--chalk-dim);
    opacity: .7;
}

.form-error {
    font-family: var(--font-hand);
    color: var(--p0);
    font-size: 16px;
    margin: -4px 0 0;
}

/* ---------- Game screen ---------- */
.game-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 6px;
}

.btn-finish {
    background: var(--bg-panel);
    border: 2px dashed var(--line);
    color: var(--chalk);
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 14px;
    border-radius: 999px;
    padding: 10px 16px;
    cursor: pointer;
}

.score-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    margin-top: 10px;
}

/* If only 2 or 3 players, still 2 columns; 3rd spans naturally on next row */

.score-card {
    position: relative;
    border-radius: var(--radius);
    border: 3px dashed var(--card-color, var(--p0));
    background: var(--bg-panel);
    padding: 18px 12px 14px;
    min-height: 168px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    user-select: none;
    overflow: hidden;
}

.score-card:active {
    transform: scale(0.98);
}

.score-name {
    font-family: var(--font-hand);
    font-size: 19px;
    font-weight: 700;
    color: var(--card-color, var(--p0));
    text-align: center;
    line-height: 1.1;
    max-width: 100%;
    overflow-wrap: anywhere;
}

.score-value {
    font-size: 56px;
    font-weight: 700;
    line-height: 1;
    color: var(--chalk);
}

.score-minus {
    align-self: flex-end;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: 2px solid var(--line);
    background: rgba(244, 240, 228, 0.05);
    color: var(--chalk);
    font-size: 20px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.score-minus:active {
    background: rgba(244, 240, 228, 0.14);
}

.floater {
    position: absolute;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 22px;
    color: var(--chalk);
    pointer-events: none;
    animation: float-up .6s ease forwards;
}

@keyframes float-up {
    0% {
        opacity: 1;
        transform: translateY(0);
    }

    100% {
        opacity: 0;
        transform: translateY(-38px);
    }
}

.tap-hint {
    text-align: center;
    font-family: var(--font-hand);
    color: var(--chalk-dim);
    font-size: 15px;
    margin-top: 18px;
}

/* ---------- Result ---------- */
.result-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin: 10px 0 26px;
}

.result-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-panel);
    border: 2px solid var(--line);
    border-radius: 16px;
    padding: 14px 18px;
}

.result-row.winner {
    border-color: var(--p2);
    background: rgba(255, 216, 104, 0.08);
}

.result-name {
    font-family: var(--font-hand);
    font-size: 19px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.result-score-wrap {
    display: flex;
    align-items: baseline;
    gap: 8px;
}

.result-score {
    font-size: 24px;
    font-weight: 700;
}

.result-diff {
    font-family: var(--font-mono);
    font-size: 13px;
    color: var(--chalk-dim);
}

.result-actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.diffs-title {
    font-family: var(--font-hand);
    font-size: 17px;
    color: var(--chalk-dim);
    margin: 4px 0 10px;
    font-weight: 700;
}

.diff-grid {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 22px;
}

.diff-chip {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-panel);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 8px 14px;
    font-family: var(--font-hand);
    font-size: 15px;
    color: var(--chalk-dim);
}

.diff-chip b {
    color: var(--chalk);
    font-family: var(--font-display);
    font-size: 15px;
}

/* ---------- History ---------- */
.history-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.history-card {
    background: var(--bg-panel);
    border: 2px solid var(--line);
    border-radius: 16px;
    padding: 14px 18px;
}

.history-row-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.history-card-active {
    border-color: var(--p2);
}

.history-status-pill {
    display: inline-block;
    background: var(--p2);
    color: #22302a;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 999px;
    margin-right: 6px;
    vertical-align: middle;
}

.history-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.history-date {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--chalk-dim);
}

.history-resume {
    background: none;
    border: 1px solid var(--line);
    border-radius: 999px;
    color: var(--chalk);
    font-family: var(--font-hand);
    font-size: 13px;
    padding: 4px 12px;
    cursor: pointer;
}

.history-resume:active {
    background: rgba(244, 240, 228, 0.08);
}

.history-delete {
    background: none;
    border: none;
    color: var(--chalk-dim);
    font-size: 16px;
    padding: 4px 6px;
    cursor: pointer;
    opacity: 0.7;
}

.history-delete:active {
    opacity: 1;
}

.history-players {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.history-chip {
    font-family: var(--font-hand);
    font-size: 15px;
    background: rgba(244, 240, 228, 0.06);
    border-radius: 999px;
    padding: 4px 12px;
}

.history-chip.winner {
    color: #22302a;
    background: var(--p2);
    font-weight: 700;
}

.history-empty {
    font-family: var(--font-hand);
    color: var(--chalk-dim);
    font-size: 18px;
    text-align: center;
    margin-top: 40px;
}

.history-diffs {
    margin-top: 10px;
}

.history-diffs summary {
    font-family: var(--font-hand);
    font-size: 14px;
    color: var(--chalk-dim);
    cursor: pointer;
    margin-bottom: 8px;
}

.history-diffs .diff-grid {
    margin-bottom: 0;
}

.history-diffs .diff-chip {
    padding: 6px 12px;
    font-size: 13px;
}

.history-diffs .diff-chip b {
    font-size: 13px;
}

@media (min-width: 520px) {
    .chalk-title {
        margin-top: 8vh;
    }
}