:root {
    --bg: #201808;
    --card-bg: #2d2210;
    --border: #57431f;
    --text: #f2e9d4;
    --muted: #b8a67e;
    --accent: #c9922f;
    --error: #d64545;
    --success: #3aa35a;
}

* { box-sizing: border-box; }

body {
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, sans-serif;
    margin: 0;
    padding: 0;
}

.wrap {
    max-width: 720px;
    margin: 2rem auto;
    padding: 0 1rem;
}

h1 { text-align: center; }

.header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
}
.header-row h1 { margin: 0; }

.card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.5rem;
    margin-bottom: 1rem;
}

label { display: block; margin: 0.75rem 0 0.25rem; font-size: 0.85rem; color: var(--muted); }

input, select {
    width: 100%;
    padding: 0.6rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 1rem;
}

button, .btn {
    display: inline-block;
    background: var(--accent);
    color: #241a08;
    font-weight: 600;
    border: none;
    border-radius: 8px;
    padding: 0.6rem 1.2rem;
    font-size: 1rem;
    cursor: pointer;
    text-decoration: none;
    margin-top: 0.75rem;
}
button:hover, .btn:hover { opacity: 0.9; }
button:disabled { opacity: 0.4; cursor: not-allowed; }

.ra-btn-alt {
    background: transparent;
    color: var(--text);
    border: 1px solid var(--border);
    font-weight: 400;
}

.error { background: rgba(214,69,69,.15); border: 1px solid var(--error); border-radius: 8px; padding: 0.75rem; margin-bottom: 0.75rem; }
.success { background: rgba(58,163,90,.15); border: 1px solid var(--success); border-radius: 8px; padding: 0.75rem; }

.game-list-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.6rem 0;
    border-bottom: 1px solid var(--border);
}
.game-list-item:last-child { border-bottom: none; }

.back { color: var(--muted); text-decoration: none; font-size: 0.85rem; }

.scoreboard {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.5rem;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 0.75rem 1.25rem;
    margin-bottom: 0.75rem;
    font-size: 0.9rem;
}

.banner { text-align: center; }
.banner h3 { margin-top: 0; }

.muted { color: var(--muted); font-size: 0.8rem; }

.card-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.log-list { list-style: none; margin: 0; padding: 0; font-size: 0.85rem; color: var(--muted); max-height: 220px; overflow-y: auto; }
.log-list li { padding: 0.3rem 0; border-bottom: 1px solid var(--border); }
.log-list li:last-child { border-bottom: none; }

/* ---- Rival Ages specifics ---- */

div.card.ra-card {
    width: 128px;
    padding: 0.5rem;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    text-align: left;
    font-size: 0.68rem;
    user-select: none;
    border-left-width: 4px;
}
.ra-card-top { display: flex; align-items: center; gap: 0.3rem; }
.ra-card-emoji { font-size: 1.1rem; }
.ra-card-name { font-weight: 700; font-size: 0.72rem; line-height: 1.15; }
.ra-card-cost, .ra-card-effect { line-height: 1.25; }
.ra-card-actions { display: flex; flex-direction: column; gap: 0.25rem; margin-top: 0.25rem; }
.ra-card-actions button { margin-top: 0; padding: 0.3rem 0.5rem; font-size: 0.68rem; width: 100%; }

.ra-card-back { align-items: center; justify-content: center; text-align: center; opacity: 0.7; border-style: dashed; }
.ra-card-back .ra-card-emoji { font-size: 1.6rem; }

.ra-cat-raw { border-left-color: #8a6a3d; }
.ra-cat-manufactured { border-left-color: #cfcfcf; }
.ra-cat-civilian { border-left-color: #4f8fd6; }
.ra-cat-commercial { border-left-color: #e0c34a; }
.ra-cat-military { border-left-color: #c14a4a; }
.ra-cat-scientific { border-left-color: #4fbf7a; }
.ra-cat-guild { border-left-color: #9a5fd6; }

.ra-wonder { border-left: 4px solid var(--accent); background: linear-gradient(180deg, rgba(201,146,47,0.12), transparent); }
.ra-wonder-built { opacity: 0.75; }

.ra-player-panel.ra-me { border-color: var(--accent); }
.ra-stat-row { display: flex; gap: 1rem; font-size: 0.95rem; margin-bottom: 0.25rem; }

.ra-pending { border-color: var(--accent); background: rgba(201,146,47,0.08); }

.ra-military-track { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.75rem; font-size: 0.75rem; }
.ra-track-bar { display: flex; flex: 1; height: 18px; border-radius: 4px; overflow: hidden; border: 1px solid var(--border); }
.ra-track-cell { flex: 1; background: var(--card-bg); border-right: 1px solid var(--border); position: relative; }
.ra-track-cell:last-child { border-right: none; }
.ra-track-mid { background: var(--border); }
.ra-track-token { background: rgba(214,69,69,0.35); }
.ra-track-pawn { background: var(--accent) !important; }

.ra-pyramid { display: flex; flex-direction: column; align-items: center; gap: 0.5rem; overflow-x: auto; }
.ra-pyramid-row { display: flex; gap: 0.5rem; justify-content: center; }

@media (max-width: 480px) {
    .wrap { margin: 0.4rem auto; padding: 0 0.5rem; }
    h1 { font-size: 1.05rem; margin: 0.2rem 0; }
    .card { padding: 0.6rem 0.75rem; margin-bottom: 0.5rem; }
    .card h3 { margin: 0 0 0.4rem; font-size: 0.95rem; }
    .scoreboard { padding: 0.5rem 0.75rem; margin-bottom: 0.5rem; font-size: 0.8rem; gap: 0.25rem; }
    .card-row { flex-wrap: wrap; row-gap: 0.35rem; gap: 0.3rem; }
    div.card.ra-card { width: 92px; font-size: 0.6rem; }
    .ra-card-name { font-size: 0.64rem; }
    .ra-card-actions button { font-size: 0.6rem; padding: 0.25rem 0.35rem; }
    .ra-pyramid-row { gap: 0.3rem; }
}

/*
 * ---- Shared polish pass ----
 * Fixes three defects that were present in every game in this repo:
 *   1. No focus indicator anywhere, so keyboard and switch users had no
 *      visible cursor. :focus-visible (not :focus) so a mouse click
 *      doesn't leave a ring behind. White + dark halo rather than the
 *      theme accent, because these rings have to stay visible on top of
 *      boards, cards and tokens, not just on the page background.
 *   2. Wide content (stat tables, boards, logs) could push the whole
 *      page sideways on a phone. Wide blocks now scroll inside their own
 *      box and the body never does.
 *   3. Motion played unconditionally -- now honours prefers-reduced-motion.
 */

:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 2px;
    box-shadow: 0 0 0 4px #000a;
    border-radius: 4px;
}

/* Wide tables scroll themselves, never the page. */
.table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0.6rem 0;
}
.rules-table {
    border-collapse: collapse;
    width: 100%;
    min-width: 18rem;
    font-size: 0.82rem;
}
.rules-table th,
.rules-table td {
    border: 1px solid var(--border);
    padding: 0.3rem 0.5rem;
    text-align: center;
    white-space: nowrap;
}
.rules-table td.wrap-cell {
    white-space: normal;
    text-align: left;
    min-width: 12rem;
}
.rules-table thead th { background: var(--bg); color: var(--muted); font-weight: 600; }
.rules-table tbody th { background: var(--bg); color: var(--text); font-weight: 600; text-align: left; }
.rules-table tbody tr:nth-child(even) td { background: #0002; }
.rules-table caption {
    caption-side: top;
    text-align: left;
    color: var(--muted);
    font-size: 0.8rem;
    padding-bottom: 0.3rem;
}

/* A long unbroken token in a log line must not widen the page. */
body { overflow-x: hidden; }
.log-list li, .log li { overflow-wrap: anywhere; }

/* Rules pages read better with a little vertical rhythm. */
.card h3 + p { margin-top: 0; }
.card ul, .card ol { padding-left: 1.15rem; }
.card li { margin-bottom: 0.3rem; }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
        scroll-behavior: auto !important;
    }
}
