:root {
    --bg: #101012;
    --surface: #1a1a1e;
    --surface-2: #222227;
    --border: #2c2c33;
    --text: #ececef;
    --text-muted: #8b8b93;
    --accent-gold: #d8b463;
    --p0: #63b3b0; /* dusty teal */
    --p1: #d6a756; /* muted mustard */
    --p2: #9a8fd1; /* soft violet */
    --p3: #7fb88a; /* sage green */
    --radius: 14px;
    --radius-sm: 8px;
    --font-ui: sans-serif;
    --font-num: sans-serif;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}
* {
    box-sizing: border-box;
}
html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-ui);
    -webkit-tap-highlight-color: transparent;
}
body {
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    padding-bottom: calc(96px + var(--safe-bottom));
}
button, input {
    font-family: inherit;
    color: inherit;
}
.hidden {
    display: none !important;
}
form {
    text-align: center;
}
/* -------------------- Topbar -------------------- */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 18px;
    border-bottom: 1px solid var(--border);
}
.brand {
    font-family: var(--font-num);
    font-size: 15px;
    letter-spacing: 0.18em;
    color: var(--text-muted);
}
.nav-link {
    color: var(--text);
    text-decoration: none;
    font-size: 14px;
    padding: 8px 14px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: transparent;
}
.nav-link:active {
    background: var(--surface-2);
}
/* -------------------- Layout -------------------- */
main#app {
    flex: 1;
    padding: 20px 16px 8px;
    max-width: 520px;
    width: 100%;
    margin: 0 auto;
}
h1 {
    font-size: 20px;
    margin: 4px 0 4px;
}
.hint {
    color: var(--text-muted);
    font-size: 14px;
    margin: 0 0 20px;
}
/* -------------------- Setup screen -------------------- */
.player-inputs {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 12px;
}
.player-name-input {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px 14px;
    font-size: 16px;
    color: var(--text);
}
.player-name-input:focus {
    outline: none;
    border-color: var(--text-muted);
}
.btn-ghost, .btn-primary, .btn-text {
    border: none;
    border-radius: var(--radius-sm);
    padding: 13px 16px;
    font-size: 15px;
    cursor: pointer;
    width: 100%;
}
.btn-ghost {
    background: transparent;
    border: 1px dashed var(--border);
    color: var(--text-muted);
    margin-bottom: 22px;
}
.btn-primary {
    background: var(--text);
    color: var(--bg);
    font-weight: 600;
}
.btn-primary:active {
    opacity: 0.85;
}
.btn-text {
    width: auto;
    background: none;
    color: var(--text-muted);
    padding: 6px 8px;
    font-size: 13px;
}
/* -------------------- Game header -------------------- */
.game-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}
#round-label {
    font-family: var(--font-num);
    font-size: 13px;
    color: var(--text-muted);
    letter-spacing: 0.04em;
}
/* -------------------- Player grid -------------------- */
.player-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 18px;
}
.player-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
    position: relative;
    overflow: hidden;
    transition: box-shadow 0.25s ease, border-color 0.25s ease;
}
.player-card::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--card-accent, var(--text-muted));
}
.player-card.active {
    border-color: var(--card-accent);
    box-shadow: 0 0 0 1px var(--card-accent), 0 0 22px -6px var(--card-accent);
}
.player-name {
    font-size: 13px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 6px;
}
.player-total {
    font-family: var(--font-num);
    font-variant-numeric: tabular-nums;
    font-size: 28px;
    font-weight: 600;
    line-height: 1;
}
.player-turn-badge {
    display: inline-block;
    margin-top: 8px;
    font-size: 11px;
    color: var(--card-accent);
    letter-spacing: 0.05em;
}
/* -------------------- Round history -------------------- */
.history-toggle {
    margin-bottom: 10px;
    text-align: left;
}
.round-history {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 20px;
}
#history-table {
    width: 100%;
    border-collapse: collapse;
    font-family: var(--font-num);
    font-variant-numeric: tabular-nums;
    font-size: 13px;
}
#history-table th, #history-table td {
    padding: 9px 12px;
    text-align: right;
    white-space: nowrap;
}
#history-table th:first-child, #history-table td:first-child {
    text-align: left;
    color: var(--text-muted);
}
#history-table thead th {
    border-bottom: 1px solid var(--border);
    font-family: var(--font-ui);
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 500;
}
#history-table tbody tr:not(:last-child) td {
    border-bottom: 1px solid var(--surface-2);
}

/* -------------------- Turn bar (signature element) -------------------- */
.turn-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding: 10px 14px calc(12px + var(--safe-bottom));
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.35);
    transition: box-shadow 0.3s ease;
}
.turn-bar::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--bar-accent, var(--text-muted));
    box-shadow: 0 0 12px 1px var(--bar-accent, transparent);
}
.undo-btn {
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text-muted);
    border-radius: 999px;
    width: 40px;
    height: 40px;
    font-size: 16px;
    flex-shrink: 0;
}
.turn-info {
    position: absolute;
    top: -22px;
    left: 14px;
    font-size: 12px;
    color: var(--bar-accent, var(--text-muted));
    letter-spacing: 0.02em;
}
.score-input-row {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}
.sign-toggle {
    width: 40px;
    height: 40px;
    max-width: calc(20% - 10px);
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    font-family: var(--font-num);
    font-size: 18px;
    flex-shrink: 0;
}
#score-input {
    flex: 1;
    min-width: 0;
    max-width: calc(50% - 10px);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    font-family: var(--font-num);
    font-variant-numeric: tabular-nums;
    font-size: 20px;
    text-align: center;
}
#score-input:focus {
    outline: none;
    border-color: var(--bar-accent, var(--text-muted));
}
.btn-add {
    background: var(--bar-accent, var(--text));
    color: var(--bg);
    border: none;
    border-radius: var(--radius-sm);
    padding: 10px 16px;
    font-size: 15px;
    font-weight: 600;
    flex-shrink: 0;
    max-width: calc(40% - 10px);
}
.btn-add:active {
    opacity: 0.85;
}
/* -------------------- Modal -------------------- */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 20;
}
.modal-box {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 18px 18px 0 0;
    padding: 22px 18px calc(22px + var(--safe-bottom));
    width: 100%;
    max-width: 520px;
}
.modal-box h2 {
    margin: 0 0 14px;
    font-size: 18px;
}
.result-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid var(--surface-2);
    font-size: 15px;
}
.result-row:last-of-type {
    border-bottom: none;
}
.result-row .r-score {
    font-family: var(--font-num);
    font-variant-numeric: tabular-nums;
    font-size: 18px;
}
.result-row.winner .r-name::after {
    content: " 👑";
}
.result-row.winner .r-score {
    color: var(--accent-gold);
}
.modal-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 18px;
}
.modal-actions a.btn-ghost {
    display: block;
    text-align: center;
    text-decoration: none;
    margin-bottom: 0;
}
/* -------------------- History page (score.php) -------------------- */
.game-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.game-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
}
.game-date {
    font-family: var(--font-num);
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 8px;
}
.game-player-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 5px 0;
    font-size: 14px;
}
.game-player-row .gp-score {
    font-family: var(--font-num);
    font-variant-numeric: tabular-nums;
}
.game-player-row.winner .gp-name::after {
    content: " 👑";
}
.game-player-row.winner .gp-score {
    color: var(--accent-gold);
    font-weight: 600;
}
/* -------------------- Player color assignment -------------------- */
.accent-0 { --card-accent: var(--p0);}
.accent-1 { --card-accent: var(--p1);}
.accent-2 { --card-accent: var(--p2);}
.accent-3 { --card-accent: var(--p3);}