:root {
    --bg: #1b2116;
    --card-bg: #232b1c;
    --border: #3d4a30;
    --text: #eef0e6;
    --muted: #9aa68c;
    --accent: #c99a3a;
    --error: #d64545;
    --success: #3aa35a;
    /* Terrain accent colors -- used both for tile borders in the UI and to
       key CSS classes (terrain-wheat etc), same "good-X" per-type accent
       pattern gem-trade uses for its 6 token colors. */
    --terrain-wheat: #e0b93a;
    --terrain-forest: #2f7a3d;
    --terrain-water: #3a7ec9;
    --terrain-grass: #8fc23a;
    --terrain-swamp: #7a5a3a;
    --terrain-mine: #8a8a8a;
    --terrain-castle: #c94a4a;
}

* { box-sizing: border-box; }

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

.wrap {
    max-width: 760px;
    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: #1b2116;
    border: none;
    border-radius: 8px;
    padding: 0.6rem 1.2rem;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    margin-top: 0.75rem;
}
button:hover, .btn:hover { opacity: 0.9; }
button:disabled { opacity: 0.4; cursor: not-allowed; }

.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: 1rem;
    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;
}

/* Draft offer tiles -- one domino (2 terrain squares) per offer slot. */
.offer-tile {
    display: flex;
    border: 2px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    width: 132px;
    user-select: none;
}
.offer-tile.claimed { opacity: 0.55; }
.offer-tile.claimable { cursor: pointer; }
.offer-tile.claimable:hover { box-shadow: 0 0 0 3px var(--accent); }
.offer-square {
    flex: 1;
    height: 64px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: 0.65rem;
    text-align: center;
    color: #1b2116;
    font-weight: 700;
}
.offer-square .crown-row { font-size: 0.8rem; }
.offer-meta { text-align: center; font-size: 0.65rem; color: var(--muted); padding: 0.15rem 0; }

.terrain-wheat { background: var(--terrain-wheat); }
.terrain-forest { background: var(--terrain-forest); color: #eef0e6; }
.terrain-water { background: var(--terrain-water); color: #eef0e6; }
.terrain-grass { background: var(--terrain-grass); }
.terrain-swamp { background: var(--terrain-swamp); color: #eef0e6; }
.terrain-mine { background: var(--terrain-mine); color: #eef0e6; }
.terrain-castle { background: var(--terrain-castle); color: #eef0e6; }
.terrain-empty { background: repeating-linear-gradient(45deg, #232b1c, #232b1c 6px, #1b2116 6px, #1b2116 12px); }

/* Kingdom grid -- a fixed square grid of .kingdom-cell divs, castle at center. */
.kingdom-grid {
    display: grid;
    gap: 2px;
    background: var(--border);
    border: 2px solid var(--border);
    border-radius: 8px;
    width: fit-content;
    margin: 0.5rem 0;
}
.kingdom-cell {
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    color: #1b2116;
    font-weight: 700;
}
@media (max-width: 480px) {
    .kingdom-cell { width: 26px; height: 26px; font-size: 0.6rem; }
}

.opp-info { display: flex; align-items: center; flex-wrap: wrap; gap: 0.5rem; color: var(--muted); font-size: 0.9rem; }

.action-bar { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }

.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; }

@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; }
    .action-bar { gap: 0.35rem; }
    .action-bar button { padding: 0.4rem 0.7rem; font-size: 0.85rem; margin-top: 0.35rem; }
}

/*
 * ---- 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;
    }
}

/* A board square must show its TERRAIN and its CROWNS at the same time.
   It used to show one or the other, so a crowned square hid the very thing
   you need to read the board -- scoring is (region size x crowns) over
   contiguous same-terrain regions, which you cannot count if crowned
   squares don't say what they are. Crowns are now a corner badge over the
   terrain glyph. */
.kingdom-cell { position: relative; }
.cell-crowns {
    position: absolute;
    top: 0;
    right: 0;
    font-size: 0.62em;
    line-height: 1;
    padding: 0.1em 0.2em;
    background: #000000b0;
    border-bottom-left-radius: 4px;
    letter-spacing: -0.05em;
}
