/* ---------------------------------------------------------------------------
   Game of War - console frame.

   The whole app is one viewport-sized grid (.app, 100dvh) that never scrolls:
   HUD on top, the board bezelled by two rails in the middle, a status strip at
   the bottom. Only three lists scroll internally (#lobbyRoom, #lastAttack,
   #myTextArea). The `min-height: 0` / `min-width: 0` declarations sprinkled
   through the grid and flex children are what make that possible - without
   them a flex/grid item refuses to shrink below its content and pushes the
   frame taller than the screen.

   On phones the same markup re-flows: .theatre and .rail become
   `display: contents`, so every .block drops straight into the .app grid and
   the bottom deck shows one block at a time, chosen by #deckTabs. No element
   is duplicated and no JS moves any node.
--------------------------------------------------------------------------- */

:root {
    --bg: #0d1116;
    --bg-map-line: rgba(201, 165, 75, 0.05);
    --panel: #161c24;
    --panel-raised: #1b222c;
    --panel-inset: #0a0d11;
    --panel-border: #2a3341;
    --text: #e6e8eb;
    --text-muted: #8b96a5;
    --accent: #c9a54b;
    --accent-strong: #e0bb63;
    --accent-contrast: #14181d;
    --danger: #b1493f;
    --warn: #e0b02a;
    --blue: #4a7dff;
    --red: #ff4a4a;
    /* Intel toggles are their own family: what you can SEE, as opposed to
       what you can DO (brass orders) - a muted field green, not a signal
       green, so it stays chrome and never competes with the board. */
    --intel: #7fae63;
    --intel-strong: #9ccc7d;

    /* Console chrome: near-square corners and hairline rules instead of
       rounded floating cards with drop shadows. */
    --radius: 2px;
    --gap: 12px;
    --gap-md: 10px;
    --gap-sm: 6px;
    --rail: 260px;
    --hud-h: 52px;
    --tap: 44px;
}

*, *::before, *::after {
    box-sizing: border-box;
}

html, body {
    height: 100%;
}

body {
    font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    margin: 0;
    color: var(--text);
    background:
        linear-gradient(var(--bg-map-line) 1px, transparent 1px) 0 0 / 32px 32px,
        linear-gradient(90deg, var(--bg-map-line) 1px, transparent 1px) 0 0 / 32px 32px,
        var(--bg);
    overflow: hidden;
    overscroll-behavior: none;
}

.hidden {
    display: none !important;
}

/* --- frame ------------------------------------------------------------- */

.app {
    height: 100dvh;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    gap: 1px;
    background: var(--panel-border);   /* the 1px gaps become hairline rules */
}

.theatre {
    display: grid;
    grid-template-columns: var(--rail) minmax(0, 1fr) var(--rail);
    gap: 1px;
    min-height: 0;
    background: var(--panel-border);
}

/* --- HUD --------------------------------------------------------------- */

.hud {
    display: flex;
    align-items: center;
    gap: var(--gap);
    min-height: var(--hud-h);
    padding: 0 var(--gap);
    background: var(--panel-raised);
    /* Turn state is a thick edge rule, not a flood fill of the whole bar -
       readable at a glance without repainting half the screen a flat colour.
       Set by changeHeaderColor() in client.js. */
    border-left: 6px solid #333c48;
}
.hud-idle   { border-left-color: #333c48; }
.hud-mine   { border-left-color: #4ad66d; background: linear-gradient(90deg, rgba(74, 214, 109, 0.12), transparent 320px), var(--panel-raised); }
.hud-theirs { border-left-color: #ff5050; background: linear-gradient(90deg, rgba(255, 80, 80, 0.10), transparent 320px), var(--panel-raised); }
.hud-wait   { border-left-color: #ffbf00; background: linear-gradient(90deg, rgba(255, 191, 0, 0.10), transparent 320px), var(--panel-raised); }

.hud-badge {
    flex: 0 0 auto;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    padding: 5px 10px;
    border: 1px solid var(--panel-border);
    border-radius: var(--radius);
    color: var(--text-muted);
}
.hud-badge.side-blue { color: var(--blue); border-color: var(--blue); }
.hud-badge.side-red  { color: var(--red);  border-color: var(--red); }

.hud-readout {
    flex: 1 1 auto;
    min-width: 0;
}
.hud-readout h1 {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.hud-readout #matchup {
    margin: 0;
    font-size: 11px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.hud-tools {
    flex: 0 0 auto;
    display: flex;
    gap: var(--gap-sm);
}
.hud-tools .toggle-button {
    padding: 6px 10px;
    font-size: 12px;
}
.hud-tools #boardThemeButton {
    display: grid;
    place-items: center;
    min-width: 34px;
    padding: 6px;
}
#boardThemeButton[aria-pressed="true"],
#boardViewButton[aria-pressed="true"] { color: var(--accent); }
#boardThemeButton:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }

@keyframes gameStartFlash {
    0%   { box-shadow: inset 0 0 0 0 rgba(80, 255, 80, 0); }
    30%  { box-shadow: inset 0 0 40px 4px rgba(80, 255, 80, 0.45); }
    100% { box-shadow: inset 0 0 0 0 rgba(80, 255, 80, 0); }
}
#headerBackground.flash-start {
    animation: gameStartFlash 0.8s ease-out;
}

/* --- rails and blocks --------------------------------------------------- */

.rail {
    display: flex;
    flex-direction: column;
    gap: 1px;
    min-height: 0;
    min-width: 0;
    overflow: hidden;
    background: var(--panel-border);
}

/* overflow:hidden is the frame's guarantee: on a short viewport a block
   gets clipped rather than pushing the whole app past the screen edge. */
.block {
    display: flex;
    flex-direction: column;
    gap: var(--gap-sm);
    min-height: 0;
    overflow: hidden;
    padding: var(--gap-md);
    background: var(--panel);
}
/* Blocks that should absorb the rail's spare height rather than leaving a
   gap at the bottom - this is what killed the old "triangulated" look. */
.block-grow {
    flex: 1 1 0;
}
/* Each rail has exactly one .block-grow (the player list on the left, the
   chat on the right), so the spare height always lands somewhere and never
   leaves the rail's hairline background showing as a stripe. */

.block-title {
    margin: 0;
    flex: 0 0 auto;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--text-muted);
}

/* --- lobby -------------------------------------------------------------- */

.lobby-room {
    flex: 1 1 auto;
    min-height: 60px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 2px;
    background: var(--panel-inset);
    border: 1px solid var(--panel-border);
    border-radius: var(--radius);
    padding: 4px;
}

.lobby-player {
    padding: 7px 9px;
    border-radius: var(--radius);
    border-left: 2px solid transparent;
    cursor: pointer;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.lobby-player:hover {
    background: var(--accent);
    color: var(--accent-contrast);
}
.lobby-player.self {
    cursor: default;
    color: var(--text-muted);
    font-style: italic;
}
.lobby-player.self:hover {
    background: transparent;
    color: var(--text-muted);
}
.lobby-player.in-game {
    cursor: pointer;
    color: var(--danger);
    border-left-color: var(--danger);
}
.lobby-player.in-game:hover {
    background: var(--accent);
    color: var(--accent-contrast);
}

.lobby-hint {
    flex: 0 0 auto;
    margin: 0;
    font-size: 11px;
    color: var(--text-muted);
}

/* The Report is a four-line rolling readout (see updateLastAttackPanel() in
   client.js): the live hover summary on top, then the most recent attack
   outcomes. Four lines tall whether or not it is full, so the rail does not
   jump as lines arrive. The chat below it takes the spare height. */
.block-report {
    flex: 0 0 auto;
}

/* No box: the Report is a title and labelled values sitting straight on the
   block, not a field you could mistake for something typeable. Baseline
   alignment matters here - the value is several points larger than its
   label, so anything else leaves them visibly off each other. No reserved
   height either: the block is exactly as tall as its rows, so the space
   below RESULT goes to the chat instead. */
.event-log {
    flex: 0 0 auto;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-content: start;
    align-items: baseline;
    column-gap: 14px;
    row-gap: 4px;
    font-size: 15px;
    line-height: 1.35;
    color: var(--text);
}

.report-label {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.report-value {
    min-width: 0;
    overflow-wrap: anywhere;
}

/* The attack verdict - the one coloured value in the panel. */
.report-accent {
    color: var(--accent-strong);
}

/* --- map ---------------------------------------------------------------- */

.map {
    min-width: 0;
    min-height: 0;
    padding: var(--gap-sm);
    background: var(--panel);
    display: flex;
}

.map-viewport {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 0;
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--panel-inset);
    border: 1px solid var(--panel-border);
    border-radius: var(--radius);
}

/* Sized in JS by fitBoard(); the transform is the pinch-zoom/pan state.
   touch-action:none stops the browser from claiming the gestures first. */
#board,
#board3d {
    display: block;
    background: var(--panel-inset);
    touch-action: none;
    transform-origin: center center;
    will-change: transform;
}

#board3d { background: transparent; }

.map-viewport.board-in-3d {
    background:
        radial-gradient(ellipse at 36% 18%, #78735828, #18191399 95%),
        repeating-linear-gradient(3deg, #5451410d 0 2px, transparent 2px 7px),
        #37372e;
}

#boardResetView {
    position: absolute;
    right: 10px;
    bottom: 10px;
    background: var(--panel);
}

#boardAnimation {
    position: absolute;
    left: 10px;
    bottom: 10px;
    background: var(--panel);
}

/* --- right rail: orders / intel / comms --------------------------------- */

.orders {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--gap-sm);
}
#atackButton {
    grid-column: 1 / -1;
}

.options-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--gap-sm);
}

/* Comms takes whatever the fixed-height Report above it leaves. */
.block-comms {
    flex: 1 1 0;
}

/* No box, same as the Report: sender as a label, message as the value,
   sitting straight on the block. This one does scroll - it is a growing
   conversation, not a fixed readout. */
/* min-height:0, not a pixel floor: as the conversation grows, this is the
   element that has to give way. It already scrolls, so shrinking it costs
   nothing, whereas the composer below it is flex:0 0 auto and sits last -
   so anything that does not fit gets cut off the composer by .block's
   overflow:hidden. That was the composer's text being clipped in half once
   enough messages had arrived. */
.comms-log {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-content: start;
    align-items: baseline;
    column-gap: 14px;
    row-gap: 3px;
    font-size: 13px;
    line-height: 1.4;
    color: var(--text);
}

.comms-who {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-muted);
    white-space: nowrap;
}
/* Each sender's name in their own army's colour - the same blue and red the
   pieces are drawn in (TEAM_COLOR, UnitSymbols.js). */
.comms-who.who-blue { color: var(--blue); }
.comms-who.who-red  { color: var(--red); }

.comms-said {
    min-width: 0;
    overflow-wrap: anywhere;
    /* Shift+Enter line breaks inside a message have to survive. */
    white-space: pre-wrap;
}

.comms-empty {
    grid-column: 1 / -1;
    color: var(--text-muted);
    font-size: 12px;
}

/* One borderless editable line that grows with the text - no field chrome,
   no button. A single hairline separates it from the conversation, and that
   rule is also the focus cue, since an outline ring around something with no
   box of its own reads as a mistake. */
/* flex: 0 0 auto is load-bearing, not tidiness: the composer sits last inside
   a .block with overflow:hidden, so anything that lets it shrink lets a long
   enough conversation squeeze it away entirely. It had its own #chat-form rule
   setting flex: 1 1 auto - left over from an older layout, and higher
   specificity than this - and one full Debord thesis in the log was enough to
   collapse the composer to a sliver of caret. Do not give the form back a flex
   of its own. */
.chat-composer {
    flex: 0 0 auto;
    display: flex;
    padding-top: var(--gap-sm);
    border-top: 1px solid var(--panel-border);
    transition: border-color 0.12s ease;
}
.chat-composer:focus-within {
    border-top-color: var(--accent);
}

#chat {
    flex: 1 1 auto;
    min-width: 0;
    font: inherit;
    font-size: 13px;
    line-height: 1.4;
    color: var(--text);
    background: none;
    border: none;
    border-radius: 0;
    padding: 0;
    margin: 0;
    resize: none;
    overflow-y: auto;
    outline: none;
}
#chat::placeholder {
    color: var(--text-muted);
}

.button-row {
    display: flex;
    flex-wrap: wrap;
    gap: var(--gap-sm);
}
.button-row button {
    flex: 1 1 auto;
    white-space: nowrap;
}

/* --- bottom strip ------------------------------------------------------- */

.strip {
    display: flex;
    align-items: center;
    gap: var(--gap);
    padding: var(--gap-sm) var(--gap);
    background: var(--panel-raised);
    min-height: 0;
}

.strip-item {
    flex: 0 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.strip-label {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--text-muted);
}

#army,
#enemyArmy,
#moves {
    display: block;
    max-width: 100%;
    height: auto;
    border-radius: var(--radius);
    background: var(--panel-inset);
}
/* The moves counter is the one thing in the strip you check every turn, so
   it is drawn at its own scale rather than squeezed next to the armies. */
.strip-moves {
    flex: 0 0 auto;
}
#moves {
    border: 1px solid var(--panel-border);
}

.opponent-activity {
    flex: 1 1 150px;
    min-width: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    color: var(--text-muted);
    font-size: 11px;
    visibility: hidden;
}
.opponent-activity.is-thinking,
.opponent-activity.is-reconnecting { visibility: visible; }
.opponent-activity.activity-blue { color: var(--blue); }
.opponent-activity.activity-red { color: var(--red); }
.activity-text {
    min-width: 0;
    overflow: hidden;
    line-height: 1.4;
}
.activity-dots { display: flex; flex: 0 0 auto; gap: 4px; }
.activity-dots i {
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: currentColor;
    opacity: 0.3;
}
.is-thinking .activity-dots i { animation: opponentThinking 1.8s ease-in-out infinite; }
.is-thinking .activity-dots i:nth-child(2) { animation-delay: 0.2s; }
.is-thinking .activity-dots i:nth-child(3) { animation-delay: 0.4s; }
.is-reconnecting .activity-dots { display: none; }
@keyframes opponentThinking {
    0%, 65%, 100% { opacity: 0.3; }
    30% { opacity: 0.9; }
}

/* Six unit types, so a fixed 3 x 2 block that parks in the strip's right
   corner and never re-flows as the window changes width. */
.board-legend {
    flex: 0 0 auto;
    margin-left: auto;
    display: grid;
    grid-template-columns: repeat(3, auto);
    align-content: center;
    gap: 2px var(--gap-md);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 5px;
    color: var(--text-muted);
    font-size: 11px;
}

.legend-text {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
}

.legend-power {
    font-size: 10px;
    color: var(--text-muted);
    opacity: 0.75;
}

.legend-item canvas {
    background: var(--panel-inset);
    border-radius: var(--radius);
}

/* --- controls ----------------------------------------------------------- */

button {
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--accent-contrast);
    background: var(--accent);
    border: 1px solid var(--accent);
    border-radius: var(--radius);
    padding: 8px 12px;
    min-height: 34px;
    cursor: pointer;
    transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}
button:hover:not(:disabled) {
    background: var(--accent-strong);
    border-color: var(--accent-strong);
}
button:active:not(:disabled) {
    transform: translateY(1px);
}
button:disabled {
    background: transparent;
    border-color: #2f3845;
    color: #5c6675;
    cursor: not-allowed;
}
button:focus-visible,
textarea:focus-visible,
input:focus-visible {
    outline: 2px solid var(--accent-strong);
    outline-offset: 1px;
}

/* Primary order: the only saturated red in the chrome. */
#atackButton {
    background: var(--danger);
    border-color: var(--danger);
    color: #f7ece9;
}
#atackButton:hover:not(:disabled) {
    background: #c65a4e;
    border-color: #c65a4e;
}
#atackButton:disabled {
    background: transparent;
    border-color: #2f3845;
    color: #5c6675;
}

/* Pass goes yellow only once the turn's five moves are spent and passing is
   actually possible - that is the moment it becomes the thing to do. Until
   then it is plain chrome like Resign. The .moves-spent class is set from
   the moves widget, see setMovesSpent() in client.js. */
#passButton.moves-spent:not(:disabled) {
    background: var(--warn);
    border-color: var(--warn);
    color: #17130a;
}
#passButton.moves-spent:not(:disabled):hover {
    background: #efc243;
    border-color: #efc243;
}

/* Secondary orders sit a tier below Attack. */
#passButton,
#resignButton,
#downloadLogButton,
#loadGameButton,
#stopWatchingButton,
#reviewControls button {
    background: transparent;
    border-color: var(--panel-border);
    color: var(--text);
}
#passButton:hover:not(:disabled),
#resignButton:hover:not(:disabled),
#downloadLogButton:hover:not(:disabled),
#loadGameButton:hover:not(:disabled),
#stopWatchingButton:hover:not(:disabled),
#reviewControls button:hover:not(:disabled) {
    background: transparent;
    border-color: var(--accent);
    color: var(--accent-strong);
}

/* Ghost tier: view toggles and HUD tools. */
/* Also worn by the Rules <a>, which the element-level button{} rules above
   do not reach - so this tier carries its own type treatment. */
.toggle-button {
    background: transparent;
    border: 1px solid var(--panel-border);
    border-radius: var(--radius);
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    cursor: pointer;
    letter-spacing: 0.06em;
    padding: 7px 8px;
    text-decoration: none;
    text-align: center;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.toggle-button:hover:not(:disabled) {
    border-color: var(--accent);
    color: var(--text);
    background: transparent;
}
.toggle-button.active {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-contrast);
}

.options-grid .toggle-button {
    color: var(--intel);
    border-color: rgba(127, 174, 99, 0.35);
}
.options-grid .toggle-button:hover:not(:disabled) {
    color: var(--intel-strong);
    border-color: var(--intel);
}
.options-grid .toggle-button.active {
    background: var(--intel);
    border-color: var(--intel);
    color: #10180c;
}
.options-grid .toggle-button:disabled {
    color: #4d5a44;
    border-color: #2f3845;
}

input {
    flex: 1 1 auto;
    min-width: 0;
    font: inherit;
    font-size: 13px;
    color: var(--text);
    background: var(--panel-inset);
    border: 1px solid var(--panel-border);
    border-radius: var(--radius);
    padding: 8px 10px;
    outline: none;
    transition: border-color 0.12s ease;
}

/* --- phone deck tabs ---------------------------------------------------- */

.deck-tabs {
    display: none;
}

/* --- overlays: start screen, dialogs, toasts ---------------------------- */

.overlay {
    position: fixed;
    inset: 0;
    z-index: 1100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--gap);
    background: rgba(6, 9, 12, 0.82);
}

.overlay-box {
    width: 100%;
    max-width: 420px;
    display: flex;
    flex-direction: column;
    gap: var(--gap-md);
    background: var(--panel-raised);
    border: 1px solid var(--panel-border);
    border-top: 3px solid var(--accent);
    border-radius: var(--radius);
    padding: var(--gap) var(--gap) calc(var(--gap) + 4px);
}

.start-title {
    margin: 0;
    font-size: 24px;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--accent-strong);
}
.start-sub {
    margin: -6px 0 0;
    font-size: 12px;
    letter-spacing: 0.06em;
    color: var(--text-muted);
}
.start-label {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--text-muted);
}
.start-box input {
    min-height: var(--tap);
    font-size: 16px;   /* 16px stops iOS Safari from zooming on focus */
}
.start-box button {
    min-height: var(--tap);
}
.start-error {
    margin: 0;
    font-size: 12px;
    color: var(--danger);
}

.dialog-title {
    margin: 0;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--accent-strong);
}
.dialog-body {
    margin: 0;
    font-size: 14px;
    color: var(--text);
}
.dialog-actions {
    display: flex;
    justify-content: flex-end;
    gap: var(--gap-sm);
}
.dialog-actions button {
    min-height: var(--tap);
    min-width: 96px;
}

.toast-layer {
    position: fixed;
    left: 50%;
    bottom: 24px;
    transform: translateX(-50%);
    z-index: 1200;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--gap-sm);
    pointer-events: none;
    width: min(420px, calc(100vw - 2 * var(--gap)));
}

.toast {
    width: 100%;
    padding: 10px 12px;
    background: var(--panel-raised);
    border: 1px solid var(--panel-border);
    border-left: 3px solid var(--accent);
    border-radius: var(--radius);
    font-size: 13px;
    color: var(--text);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
    animation: toastIn 0.16s ease-out;
}
@keyframes toastIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: none; }
}

/* Shared by the <a> Rules link and the <button> tutorial-close trigger -
   resets the generic button chrome so it renders as a plain text link. */
.rules-link {
    align-self: center;
    color: var(--accent);
    text-decoration: none;
    font-size: 13px;
    font-weight: normal;
    letter-spacing: normal;
    text-transform: none;
    border-bottom: 1px solid transparent;
    background: none;
    border: none;
    border-radius: 0;
    padding: 0;
    min-height: 0;
    cursor: pointer;
}
.rules-link:hover,
button.rules-link:hover {
    color: #a8d8a8;
    border-bottom-color: #a8d8a8;
    background: none;
}

/* --- tutorial ----------------------------------------------------------- */

.tutorial-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.72);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: var(--gap);
    overflow-y: auto;
    z-index: 1000;
}

.tutorial-modal-content {
    position: relative;
    width: 100%;
    max-width: 1080px;
    background: var(--bg);
    border: 1px solid var(--panel-border);
    border-top: 3px solid var(--accent);
    border-radius: var(--radius);
    padding: var(--gap) var(--gap) 32px;
}

.tutorial-video {
    display: block;
    width: 100%;
    aspect-ratio: 16 / 9;
    background: #17252b;
    border: 1px solid var(--panel-border);
    border-radius: var(--radius);
}
.tutorial-chapters {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 12px 0;
}
.tutorial-chapters button { font-size: 12px; }
.tutorial-downloads { font-size: 13px; margin-bottom: 20px; }
.tutorial-modal-content a { color: var(--accent); }
.tutorial-transcript { white-space: pre-wrap; line-height: 1.6; margin-top: 16px; }
.tutorial-section summary { cursor: pointer; font-weight: bold; }

.tutorial-close {
    position: absolute;
    top: 4px;
    right: 4px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 28px;
    line-height: 1;
    cursor: pointer;
    padding: 4px 10px;
    min-height: 0;
}
.tutorial-close:hover {
    color: var(--text);
    background: none;
}

.tutorial-modal-content h1 {
    color: var(--accent-strong);
    margin: 0 0 4px;
    font-size: 20px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.tutorial-intro {
    color: var(--text-muted);
    margin: 0 0 var(--gap);
    font-size: 13px;
}

.tutorial-section {
    background: var(--panel);
    border: 1px solid var(--panel-border);
    border-radius: var(--radius);
    padding: var(--gap-md);
    margin-bottom: var(--gap);
}

.tutorial-section h2 {
    margin-top: 0;
    color: var(--accent);
    font-size: 13px;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.tutorial-section p {
    margin: 0 0 var(--gap-sm);
}

#tutorialLegend {
    justify-content: flex-start;
    max-height: none;
}

.tutorial-footer {
    text-align: center;
    margin-top: var(--gap);
}

/* --- narrow / short desktop --------------------------------------------- */

@media (max-width: 1200px) {
    :root { --rail: 220px; }
}

/* --- phone / small tablet ----------------------------------------------- */

/* .theatre and .rail become `display: contents`, so the HUD, the map, every
   .block, the strip and the tab bar are all direct children of the same .app
   grid. Blocks tagged data-deck-panel share the single "deck" row and only
   the active one is shown; #ordersBlock has no tag, so it keeps its own row
   and stays visible at all times. */
@media (max-width: 860px) {
    :root {
        --gap: 10px;
        --gap-md: 8px;
    }

    .app {
        grid-template-columns: minmax(0, 1fr);
        grid-template-rows: auto minmax(0, 1fr) auto auto auto minmax(130px, 0.7fr) auto;
        grid-template-areas:
            "hud"
            "map"
            "report"
            "strip"
            "orders"
            "deck"
            "tabs";
    }

    .theatre,
    .rail {
        display: contents;
    }

    .hud    { grid-area: hud; }
    .map    { grid-area: map; padding: 2px; }
    .strip  { grid-area: strip; }
    /* The hover/attack readout and the orders stay out of the tabbed deck -
       they are what you look at while actually playing a turn. */
    .block-report { grid-area: report; padding: var(--gap-sm) var(--gap-md); }
    .block-report .block-title { display: none; }
    .block-report .event-log { font-size: 14px; row-gap: 2px; }
    #ordersBlock { grid-area: orders; }
    .block[data-deck-panel] { grid-area: deck; }
    .block[data-deck-panel]:not(.deck-active) { display: none; }
    #deckTabs { grid-area: tabs; }

    .hud-tools .toggle-button { padding: 8px 9px; }
    .hud-tools { gap: 4px; }
    .hud-tools #boardThemeButton { padding: 8px 6px; }
    .hud-readout h1 { font-size: 13px; }
    .hud-badge { padding: 4px 7px; }

    /* The legend lives in the Tutorial on phones. */
    .board-legend { display: none; }

    .strip {
        gap: var(--gap-md);
        padding: 4px var(--gap-md);
    }
    .strip-label { font-size: 9px; }
    .strip-item { flex: 1 1 0; }
    .strip-moves { flex: 0 1 auto; max-width: 150px; }
    .opponent-activity { flex: 0 0 30px; }
    .opponent-activity.is-thinking .activity-text { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
    .opponent-activity.is-reconnecting { flex: 0 1 90px; }

    #ordersBlock { padding: var(--gap-sm) var(--gap-md); }
    #ordersBlock .block-title { display: none; }
    .orders { grid-template-columns: 2fr 1fr 1fr; }
    #atackButton { grid-column: auto; }
    .orders button { min-height: var(--tap); }

    .options-grid button { min-height: var(--tap); }
    .button-row button { min-height: var(--tap); }
    .comms-log { font-size: 14px; }
    /* 16px is what stops iOS Safari zooming the page when the composer takes
       focus - not a style choice. */
    #chat { font-size: 16px; }
    .chat-composer { padding-top: var(--gap-md); padding-bottom: var(--gap-sm); }
    .lobby-player { padding: 11px 9px; }

    .deck-tabs {
        grid-area: tabs;
        display: grid;
        grid-auto-flow: column;
        grid-auto-columns: 1fr;
        gap: 1px;
        background: var(--panel-border);
        padding-bottom: env(safe-area-inset-bottom);
    }
    .deck-badge {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        min-width: 16px;
        height: 16px;
        margin-left: 5px;
        padding: 0 4px;
        border-radius: 8px;
        background: var(--accent);
        color: var(--accent-contrast);
        font-size: 10px;
        font-weight: 700;
        letter-spacing: 0;
    }

    .deck-tab {
        background: var(--panel-raised);
        border: none;
        border-radius: 0;
        min-height: var(--tap);
        color: var(--text-muted);
        font-size: 11px;
        letter-spacing: 0.1em;
    }
    .deck-tab:hover:not(:disabled) {
        background: var(--panel-raised);
        color: var(--text);
    }
    .deck-tab-active {
        background: var(--panel);
        color: var(--accent-strong);
        box-shadow: inset 0 2px 0 0 var(--accent);
    }
}

/* Narrow phones keep the full readout on its own row, with the compact
   tools aligned right below it. Rules and the theme switch stay together. */
@media (max-width: 480px) {
    .hud {
        display: grid;
        grid-template-columns: auto minmax(0, 1fr);
        gap: 4px 8px;
        padding: 6px 8px;
    }
    .hud-tools { grid-column: 1 / -1; justify-self: end; }
    .hud-tools .toggle-button { padding: 7px 8px; }
    .hud-tools #boardThemeButton { padding: 7px 6px; }
}

/* Landscape phone: the strip and the deck would leave the board almost no
   height, so drop the strip's labels and shrink the deck further. */
@media (max-width: 860px) and (max-height: 520px) {
    .app { grid-template-rows: auto minmax(0, 1fr) auto auto auto minmax(0, 0.5fr) auto; }
    .strip-label { display: none; }
    .block-report { display: none; }
}

@media (prefers-reduced-motion: reduce) {
    .is-thinking .activity-dots i { animation: none !important; opacity: 0.65; }
    *, *::before, *::after {
        animation-duration: 0.001ms !important;
        transition-duration: 0.001ms !important;
    }
}
