:root {
    --bg: #14120f;
    --card-bg: #201d18;
    --border: #3a352c;
    --text: #eee;
    --muted: #999;
    --accent: #8a3a1c;
    --error: #d64545;
    --success: #3aa35a;
    --field-dark: #2a2620;
    --field-light: #302b23;
    --deploy-zone: #3d2a1a;
    --seat0: #4ea3e0;
    --seat1: #c4703a;
}

* { 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: 900px; }

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

/*
 * The battlefield: an abstract grid (WIDTH x HEIGHT squares -- see
 * inc/engine.php), with deployment-zone columns shaded on each edge.
 * Percentages here derive from DEPLOY_DEPTH/WIDTH in engine.php -- if
 * those constants ever change, update these too.
 */
.battlefield {
    position: relative;
    width: 100%;
    aspect-ratio: var(--field-w) / var(--field-h);
    background-color: var(--field-dark);
    background-image:
        linear-gradient(90deg, var(--deploy-zone), var(--deploy-zone)),
        linear-gradient(90deg, var(--deploy-zone), var(--deploy-zone)),
        repeating-linear-gradient(90deg, var(--field-dark) 0, var(--field-dark) calc(100% / 10), var(--field-light) calc(100% / 10), var(--field-light) calc(200% / 10));
    background-size: 20% 100%, 20% 100%, 100% 100%;
    background-position: left, right, center;
    background-repeat: no-repeat, no-repeat, repeat-x;
    border: 2px solid var(--border);
    border-radius: 6px;
    overflow: hidden;
}

.squad-token {
    position: absolute;
    width: 7%;
    aspect-ratio: 1;
    transform: translate(-50%, -50%);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    font-weight: 700;
    color: #fff;
    border: 2px solid #000;
    cursor: pointer;
}
.squad-token.seat-0 { background: var(--seat0); }
.squad-token.seat-1 { background: var(--seat1); }
.squad-token:hover { box-shadow: 0 0 0 3px #fff8; }
.squad-token.selected { box-shadow: 0 0 0 3px gold; }
.squad-token.pinned { opacity: 0.6; border-style: dashed; }
.squad-token.immobilized { filter: grayscale(0.5); }
.squad-count {
    position: absolute;
    bottom: -0.5em;
    right: -0.5em;
    font-size: 0.6rem;
    background: #000c;
    border-radius: 50%;
    width: 1.3em;
    height: 1.3em;
    display: flex;
    align-items: center;
    justify-content: center;
}

.battlefield[onclick] { cursor: crosshair; }

.squad-picker { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0.5rem 0; }
.squad-chip {
    padding: 0.4rem 0.7rem;
    border-radius: 8px;
    background: var(--bg);
    border: 1px solid var(--border);
    cursor: pointer;
    font-size: 0.85rem;
}
.squad-chip:hover { border-color: var(--accent); }
.squad-chip.selected { border-color: gold; box-shadow: 0 0 0 2px gold inset; }
.squad-chip.placed { opacity: 0.6; }

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

@media (max-width: 480px) {
    .wrap { margin: 0.5rem auto; padding: 0 0.6rem; }
    h1 { font-size: 1.05rem; }
    .squad-token { font-size: 0.75rem; }
}

/*
 * ---- Shared polish pass ----
 * Three defects this fixes, all of which were present repo-wide:
 *   1. No focus indicator anywhere. Keyboard and switch users had no way
 *      to see what was selected. :focus-visible (not :focus) so a mouse
 *      click doesn't leave a ring behind.
 *   2. Wide content (the rules stat tables, the battlefield) could force
 *      the whole page to scroll sideways on a phone. Now each wide block
 *      scrolls inside its own box and the body never does.
 *   3. Motion played unconditionally. Honour prefers-reduced-motion.
 */

:focus-visible {
    outline: 2px solid var(--seat0);
    outline-offset: 2px;
    border-radius: 4px;
}
/* The board tokens/chips sit on busy backgrounds, so give them a dark
   halo as well or the outline vanishes against a light field square. */
.squad-token:focus-visible,
.squad-chip:focus-visible,
.game-list-item:focus-visible {
    outline: 2px solid #fff;
    box-shadow: 0 0 0 4px #000a;
}

/* Wide tables: scroll the table, 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: 20rem;
    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 thead th {
    background: var(--bg);
    color: var(--muted);
    font-weight: 600;
}
.rules-table tbody th {
    background: var(--bg);
    color: var(--text);
    font-weight: 600;
}
.rules-table tbody tr:nth-child(even) td { background: #0002; }

/* Never let a long log line or a wide board push the page sideways. */
body { overflow-x: hidden; }
.log-list li { overflow-wrap: anywhere; }

/* Comfortable hit targets on touch: the squad chips were 0.4rem tall
   padding only, well under the 44px guideline. */
.squad-chip {
    min-height: 2.4rem;
    display: inline-flex;
    align-items: center;
}

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