:root {
    --bg: #201a14;
    --card-bg: #2a2219;
    --border: #4a3826;
    --text: #eee;
    --muted: #a89880;
    --accent: #b5622a;
    --error: #d64545;
    --success: #3aa35a;
    --sand: #8a6a3f;
    --sand-dark: #6e5330;
    --seat0: #c0522a;
    --seat1: #3a9aa8;
}

* { box-sizing: border-box; }

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

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

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); }
.muted { color: var(--muted); }

input, select, textarea {
    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: #fff;
    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; }

.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;
    align-items: center;
    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.95rem;
    font-weight: 600;
}
.seat-0-label { color: var(--seat0); }
.seat-1-label { color: var(--seat1); }

/*
 * The battlefield grid -- 14x9 (see inc/engine.php's GRID_WIDTH/
 * GRID_HEIGHT), a plain sand-colored aspect-ratio box with a subtle
 * column-striping pattern for visual grid reference. Terrain tiles and
 * vehicle tokens are absolutely positioned by percentage on top -- that
 * percentage math IS the real grid geometry, not decoration.
 */
.battlefield {
    position: relative;
    width: 100%;
    aspect-ratio: var(--grid-w) / var(--grid-h);
    background-color: var(--sand);
    background-image: repeating-linear-gradient(90deg, var(--sand) 0, var(--sand) calc(100% / 14), var(--sand-dark) calc(100% / 14), var(--sand-dark) calc(200% / 14));
    border: 2px solid var(--border);
    border-radius: 6px;
    overflow: hidden;
}
.battlefield[onclick] { cursor: crosshair; }

.terrain-tile {
    position: absolute;
    width: 6%;
    aspect-ratio: 1;
    transform: translate(-50%, -50%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    pointer-events: none;
    opacity: 0.9;
}

.vehicle-token {
    position: absolute;
    width: 8%;
    aspect-ratio: 1;
    transform: translate(-50%, -50%);
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #fff;
    border: 2px solid #000;
}
.vehicle-token.seat-0 { background: var(--seat0); }
.vehicle-token.seat-1 { background: var(--seat1); }
.vehicle-token.clickable { cursor: pointer; }
.vehicle-token.clickable:hover { box-shadow: 0 0 0 3px #fff8; }
.vehicle-token.selected { box-shadow: 0 0 0 3px gold; }
.vehicle-token.immobilized { opacity: 0.6; border-style: dashed; }
.vehicle-token.ram-target { box-shadow: 0 0 0 3px var(--error); }
.vehicle-token.ram-target:hover { box-shadow: 0 0 0 4px var(--error); }
.vehicle-token.shoot-target:not(.ram-target) { box-shadow: 0 0 0 3px #ffcf40; }
.vehicle-token.shoot-target:not(.ram-target):hover { box-shadow: 0 0 0 4px #ffcf40; }
.vehicle-icon { font-size: 1rem; line-height: 1; }
.hp-bar {
    display: block;
    width: 80%;
    height: 3px;
    background: #0006;
    border-radius: 2px;
    margin-top: 2px;
    overflow: hidden;
}
.hp-fill { display: block; height: 100%; background: var(--success); }

.roster-row {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}
.roster-panel {
    flex: 1 1 260px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1rem;
}
.roster-panel h4 { margin: 0 0 0.5rem; }
.roster-panel.seat-0 h4 { color: var(--seat0); }
.roster-panel.seat-1 h4 { color: var(--seat1); }
.roster-line {
    padding: 0.4rem 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.85rem;
}
.roster-line:last-child { border-bottom: none; }
.roster-line.wrecked { opacity: 0.5; text-decoration: line-through; }
.roster-line.selected { background: rgba(255,255,255,.05); border-radius: 6px; }
.roster-line .vehicle-icon { margin-right: 0.3rem; }
.tag {
    display: inline-block;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.05rem 0.4rem;
    font-size: 0.7rem;
    margin-left: 0.3rem;
    color: var(--muted);
}
.tag.dead { color: var(--error); border-color: var(--error); }

.log-list { margin: 0; padding-left: 1.2rem; font-size: 0.85rem; color: var(--muted); }
.log-list li { margin-bottom: 0.25rem; }

.banner h3 { margin: 0; }

@media (max-width: 480px) {
    .wrap { margin: 0.5rem auto; padding: 0 0.6rem; }
    h1 { font-size: 1.05rem; }
    .vehicle-icon { font-size: 0.8rem; }
    .roster-row { flex-direction: column; }
}

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

/* Keyboard cursor for the board. The board is navigated with arrow keys
   rather than made a tab stop, because tabbing through several hundred
   cells would be unusable and this board works out the target square from
   a position rather than from a per-cell element. */
.kb-grid-cursor {
    position: absolute;
    pointer-events: none;
    box-sizing: border-box;
    outline: 2px solid #fff;
    box-shadow: 0 0 0 3px #000a, inset 0 0 0 1px #000a;
    z-index: 5;
}
[data-kb-grid]:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 2px;
}
