/* Relic — Warhammer 40K Board Game */

:root {
    --bg: #0d0d12;
    --bg-panel: #16161e;
    --bg-panel-hover: #1e1e28;
    --text: #e0ddd4;
    --text-muted: #8a8778;
    --accent: #c4a44e;       /* Imperial gold */
    --accent-hover: #d4b85e;
    --accent-dim: rgba(196, 164, 78, 0.15);
    --danger: #a03030;
    --danger-bg: rgba(160, 48, 48, 0.15);
    --success: #2a7a3a;
    --success-bg: rgba(42, 122, 58, 0.15);
    --info: #3a6a9a;
    --border: #2a2a35;
    --border-light: #3a3a48;
    --overlay: rgba(0, 0, 0, 0.7);
    --glass: rgba(22, 22, 30, 0.85);
    --glass-blur: blur(0.75rem);

    /* Board tier colours */
    --tier-outer: #3a6a3a;
    --tier-middle: #6a5a2a;
    --tier-inner: #7a2a2a;

    /* Threat deck colours */
    --threat-red: #c04040;
    --threat-blue: #4060c0;
    --threat-yellow: #c0a030;

    /* Board tile outlines and the movement spotlight (drawn on the board art,
       which is dark in both themes, so they change little between them) */
    --tile-line: rgba(240, 226, 190, 0.45);
    --tile-line-shadow: rgba(0, 0, 0, 0.55);
    --board-dim: rgba(4, 4, 10, 0.68);
    --reach: #f2c94c;
    --reach-halo: rgba(242, 201, 76, 0.35);
    --reach-halo-hover: rgba(255, 226, 130, 0.55);
    --reach-hover: #fff3c4;
    --reach-hover-fill: rgba(255, 228, 140, 0.16);
    --reach-label: #ffe9a8;
    --reach-label-bg: rgba(8, 8, 14, 0.9);

    --font-sans: "Petrov Sans", system-ui, -apple-system, sans-serif;
    --font-mono: "JetBrains Mono", "Cascadia Code", monospace;

    --radius: 0.375rem;
    --radius-lg: 0.625rem;
    --gutter: 1rem;

    /* Tile card */
    --card-bg: #131218;
    --card-edge: rgba(196, 164, 78, 0.55);
    --art-bg: #09080c;
    --parch-hi: #f1e4be;
    --parch-lo: #d4ba82;
    --parch-tail: #b39558;
    --parch-edge: #86672c;
    --parch-ink: #2a1f10;
    --option-bg: rgba(196, 164, 78, 0.07);
    --option-edge: rgba(196, 164, 78, 0.26);
}

@media (prefers-color-scheme: light) {
    :root:not([data-theme="dark"]) {
        --bg: #f0ede6;
        --bg-panel: #faf8f4;
        --bg-panel-hover: #f0ede6;
        --text: #1a1a1a;
        --text-muted: #6a6a6a;
        --accent: #8a7430;
        --accent-hover: #6a5a20;
        --accent-dim: rgba(138, 116, 48, 0.12);
        --danger: #c04040;
        --danger-bg: rgba(192, 64, 64, 0.12);
        --success: #2a7a3a;
        --success-bg: rgba(42, 122, 58, 0.12);
        --info: #3a6a9a;
        --border: #d0cdc4;
        --border-light: #e0ddd4;
        --overlay: rgba(0, 0, 0, 0.5);
        --glass: rgba(250, 248, 244, 0.85);

        --tier-outer: #4a8a4a;
        --tier-middle: #9a8a4a;
        --tier-inner: #aa4a4a;

        --threat-red: #d05050;
        --threat-blue: #5070d0;
        --threat-yellow: #d0b040;

        --tile-line: rgba(255, 248, 228, 0.5);
        --board-dim: rgba(20, 18, 14, 0.62);
        --reach: #ffd24a;

        --card-bg: #fbf7ee;
        --card-edge: rgba(138, 116, 48, 0.6);
        --parch-hi: #f7eed3;
        --parch-lo: #e3cd96;
        --parch-tail: #c9ad6c;
        --parch-edge: #8a6a28;
        --option-bg: rgba(138, 116, 48, 0.07);
        --option-edge: rgba(138, 116, 48, 0.3);
    }
}

:root[data-theme="dark"] {
    --bg: #0d0d12;
    --bg-panel: #16161e;
    --bg-panel-hover: #1e1e28;
    --text: #e0ddd4;
    --text-muted: #8a8778;
    --accent: #c4a44e;
    --accent-hover: #d4b85e;
    --accent-dim: rgba(196, 164, 78, 0.15);
    --danger: #a03030;
    --danger-bg: rgba(160, 48, 48, 0.15);
    --success: #2a7a3a;
    --success-bg: rgba(42, 122, 58, 0.15);
    --info: #3a6a9a;
    --border: #2a2a35;
    --border-light: #3a3a48;
    --overlay: rgba(0, 0, 0, 0.7);
    --glass: rgba(22, 22, 30, 0.85);

    /* Tile card */
    --card-bg: #131218;
    --card-edge: rgba(196, 164, 78, 0.55);
    --art-bg: #09080c;
    --parch-hi: #f1e4be;
    --parch-lo: #d4ba82;
    --parch-tail: #b39558;
    --parch-edge: #86672c;
    --parch-ink: #2a1f10;
    --option-bg: rgba(196, 164, 78, 0.07);
    --option-edge: rgba(196, 164, 78, 0.26);
}

/* --- UI size (web/js/uisize.js) ---
   Every UI length is in rem (hairlines and the board's own geometry stay
   px), so the root font size scales the whole interface while layout,
   hit tests and getBoundingClientRect stay in plain CSS px. --ui-auto is
   this screen's default: phones as they were, laptops and desktops bigger
   (a little less on short screens, where battles need the height).
   --ui-pick is the ⚙ menu's choice (html[data-ui-size], set before the
   first paint by index.html), gentler on phones. */
:root { --ui-auto: 1; --ui-pick: 1; }
@media (min-width: 769px) { :root { --ui-auto: 1.08; } }
@media (min-width: 1200px) and (min-height: 800px) { :root { --ui-auto: 1.18; } }
@media (min-width: 1200px) and (max-height: 799px) { :root { --ui-auto: 1.1; } }
@media (min-width: 1800px) and (min-height: 1000px) { :root { --ui-auto: 1.22; } }
:root[data-ui-size="small"] { --ui-pick: 0.87; }
:root[data-ui-size="large"] { --ui-pick: 1.15; }
:root[data-ui-size="xlarge"] { --ui-pick: 1.3; }
@media (max-width: 768px) {
    :root[data-ui-size="small"] { --ui-pick: 0.92; }
    :root[data-ui-size="large"] { --ui-pick: 1.07; }
    :root[data-ui-size="xlarge"] { --ui-pick: 1.14; }
}
/* Narrow phones: the header was fitted to 360 px at the old size, so the
   larger picks are gentler and make room by dropping the turn number (the
   phase track and the hint still say whose turn and what phase). */
@media (max-width: 420px) {
    :root[data-ui-size="large"] { --ui-pick: 1.04; }
    :root[data-ui-size="xlarge"] { --ui-pick: 1.08; }
    :root:is([data-ui-size="large"], [data-ui-size="xlarge"]) .game-header .turn-label { display: none; }
}
html { font-size: calc(100% * var(--ui-auto) * var(--ui-pick)); }

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

body {
    font-family: var(--font-sans);
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100dvh;
    -webkit-font-smoothing: antialiased;
    overflow: hidden;
}

.view { display: flex; flex-direction: column; }
.view[hidden] { display: none !important; }

.title {
    font-size: 3rem;
    font-weight: 700;
    color: var(--accent);
    text-align: center;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.subtitle {
    text-align: center;
    color: var(--text-muted);
    margin-bottom: 2rem;
    font-size: 0.95rem;
    letter-spacing: 0.04em;
}

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

.panel h2 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--accent);
    margin-bottom: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.form-group {
    margin-bottom: 0.75rem;
}

.form-group label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

input, select {
    width: 100%;
    padding: 0.5rem 0.75rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-family: var(--font-sans);
    font-size: 0.9rem;
}

input:focus, select:focus {
    outline: none;
    border-color: var(--accent);
}

.stat-pip {
    font-size: 0.7rem;
    font-weight: 600;
    padding: 0.1rem 0.4rem;
    border-radius: 0.1875rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.stat-str { background: var(--threat-red); color: #fff; }
.stat-wil { background: var(--threat-blue); color: #fff; }
.stat-cun { background: var(--threat-yellow); color: #000; }

/* Buttons */
.btn {
    display: inline-block;
    padding: 0.6rem 1.2rem;
    border: 1px solid transparent;
    border-radius: var(--radius);
    font-family: var(--font-sans);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    transition: background 0.15s, border-color 0.15s, opacity 0.15s;
    width: 100%;
}

.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn[hidden] { display: none; } /* the guest's lobby showed the host's Start Game */

.btn-primary { background: var(--accent); color: var(--bg); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn-secondary { background: transparent; border-color: var(--accent); color: var(--accent); }
.btn-secondary:hover:not(:disabled) { background: var(--accent); color: var(--bg); }

.btn-danger { background: var(--danger); color: #fff; }

.btn-small { padding: 0.35rem 0.75rem; font-size: 0.8rem; width: auto; }

.btn-icon {
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.3rem 0.5rem;
    font-size: 1rem;
    line-height: 1;
    font-family: var(--font-sans);
}

.btn-icon:hover { color: var(--text); border-color: var(--accent); }

/* The 2D/3D board toggle: text, matched to the icons' height. */
.btn-view { font-size: 0.72rem; font-weight: 700; letter-spacing: 0.04em; padding: 0.4rem 0.45rem; }

/* Fast mode (other players' turns play quicker): lit while on. */
.btn-fast { font-weight: 700; padding: 0.3rem 0.55rem; }
.btn-fast.is-on { color: var(--bg, #111); background: var(--accent); border-color: var(--accent); }

/* Sound on/off (sound.js): a speaker, crossed out while muted. */
.btn-sound { display: inline-flex; align-items: center; justify-content: center; padding: 0.3rem 0.4rem; }
.sound-icon { width: 1.125rem; height: 1.125rem; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.sound-icon .sound-cone { fill: currentColor; stroke-width: 1.2; }
.sound-icon .sound-cross { display: none; }
.btn-sound.is-muted .sound-waves { display: none; }
.btn-sound.is-muted .sound-cross { display: inline; }
.btn-sound.is-muted { color: var(--danger); border-color: var(--danger); }

/* --- Lobby --- */

.lobby {
    max-width: 30rem;
    margin: 0 auto;
    padding: var(--gutter);
    padding-top: 8vh;
    align-items: stretch;
    overflow-y: auto;
    max-height: 100dvh;
}

.lobby-code-panel { text-align: center; }

.invite-code {
    font-size: 2.5rem;
    font-weight: 700;
    letter-spacing: 0.15em;
    color: var(--accent);
    font-family: var(--font-mono);
    margin-bottom: 0.5rem;
    user-select: all;
}

.lobby-players { display: flex; flex-direction: column; gap: 0.5rem; }

.lobby-player {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0.75rem;
    background: var(--bg);
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.lobby-player img {
    width: 2.5rem; height: 2.5rem; border-radius: 50%;
    border: 0.125rem solid var(--pc, var(--accent)); object-fit: cover; background: var(--bg-panel);
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35);
}
/* The seat's colour (bots.js PLAYER_COLOURS) as a stripe on the left. */
.lobby-player { position: relative; overflow: hidden; }
.lobby-player:not(.lobby-nemesis)::before {
    content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 0.1875rem;
    background: var(--pc, transparent); box-shadow: inset -1px 0 0 rgba(0, 0, 0, 0.3);
}

.lobby-player .lp-name { font-weight: 600; font-size: 0.9rem; }
.lobby-player .lp-char { font-size: 0.75rem; color: var(--text-muted); }

.lobby-player .lp-host {
    margin-left: auto; font-size: 0.65rem; text-transform: uppercase;
    letter-spacing: 0.06em; color: var(--accent); font-weight: 600;
}

.lobby-player .lp-you {
    margin-left: auto; font-size: 0.65rem; text-transform: uppercase;
    letter-spacing: 0.06em; color: var(--success); font-weight: 600;
}

.lobby-hint {
    text-align: center; color: var(--text-muted); font-size: 0.85rem; margin-top: 0.5rem;
}

/* --- Computer opponents (lobby) --- */

.panel-hint { font-size: 0.8rem; color: var(--text-muted); margin: 0 0 0.75rem; }
.form-label {
    display: block; font-size: 0.8rem; color: var(--text-muted); margin-bottom: 0.35rem;
    text-transform: uppercase; letter-spacing: 0.04em;
}
.bot-rows { display: flex; flex-direction: column; gap: 0.4rem; margin-bottom: 0.5rem; }
.bot-rows:empty { display: none; }
.bot-row { display: flex; align-items: center; gap: 0.4rem; }
.bot-row select { flex: 1 1 0; min-width: 0; }
.bot-row .bot-icon { flex: none; }
.bot-row:not(.nem-bot-row) .bot-icon { color: var(--pc, var(--text-muted)); filter: drop-shadow(0 0 1px rgba(0, 0, 0, 0.55)); }
.bot-row .btn-small { flex: none; }
.bot-row-remove {
    flex: none; width: 2rem; height: 2rem; padding: 0; border-radius: 50%;
    background: transparent; border: 1px solid var(--border); color: var(--text-muted);
    font-size: 1.1rem; line-height: 1; cursor: pointer;
}
.bot-row-remove:hover, .bot-row-remove:focus-visible { color: var(--danger); border-color: var(--danger); }

.bot-icon { width: 1em; height: 1em; vertical-align: -0.125em; color: var(--text-muted); }
.lobby-player .lp-bot {
    display: inline-flex; align-items: center; gap: 0.25rem; margin-left: 0.4rem;
    font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.06em;
    color: var(--text-muted); font-weight: 600; vertical-align: 0.1em;
}
.lobby-player .lp-remove { margin-left: auto; }
.lobby-player .lp-host + .lp-you, .lobby-player .lp-host ~ .lp-remove { margin-left: 0.5rem; }
.lobby-add-bot { margin-top: 0.9rem; padding-top: 0.75rem; border-top: 1px solid var(--border); }
.lobby-add-bot[hidden] { display: none; }

/* Expansions and scenario (web/js/expansions.js): the lobby. */
.xp-list { display: grid; gap: 0.45rem; }
.xp-toggle {
    display: flex; align-items: flex-start; gap: 0.6rem; padding: 0.55rem 0.65rem;
    border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer;
    background: var(--bg-input, transparent); transition: border-color 0.15s, background-color 0.15s;
}
.xp-toggle.is-on { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 9%, transparent); }
.xp-toggle input { margin-top: 0.2rem; accent-color: var(--accent); flex: none; width: 1.05rem; height: 1.05rem; }
.xp-toggle input:disabled { cursor: default; }
.xp-text { display: flex; flex-direction: column; gap: 0.1rem; min-width: 0; }
.xp-name { font-weight: 600; font-size: 0.92rem; }
.xp-summary { font-size: 0.8rem; color: var(--text-muted); line-height: 1.35; }
.xp-scenario { margin-top: 0.7rem; }
.xp-scenario label {
    display: block; font-size: 0.8rem; color: var(--text-muted); margin-bottom: 0.25rem;
    text-transform: uppercase; letter-spacing: 0.04em;
}
.xp-scenario select { width: 100%; }
.xp-scenario-summary { font-size: 0.8rem; color: var(--text-muted); margin: 0.35rem 0 0; line-height: 1.35; }
.lobby-xp-panel .panel-hint:empty { display: none; }

/* ==========================================
   GAME VIEW
   ========================================== */

.game-container {
    height: 100dvh;
    overflow: hidden;
}

/* --- Header --- */

.game-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.4rem var(--gutter);
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border);
    min-height: 2.5rem;
    flex-shrink: 0;
    z-index: 20;
    position: relative;
}

.turn-info { display: flex; gap: 0.75rem; align-items: center; }

.turn-label {
    font-weight: 600; color: var(--accent); text-transform: uppercase;
    letter-spacing: 0.04em; font-size: 0.8rem;
}

.phase-badge {
    font-size: 0.7rem; font-weight: 600; text-transform: uppercase;
    letter-spacing: 0.04em; padding: 0.15rem 0.5rem; border-radius: 0.1875rem;
    background: var(--accent-dim); color: var(--accent);
}

.header-right { display: flex; align-items: center; gap: 0.5rem; }
.active-player { font-weight: 600; font-size: 0.85rem; }
.turn-label, .phase-badge, .active-player { white-space: nowrap; }

@media (max-width: 480px) {
    .game-header { gap: 0.4rem; }
    .turn-info { gap: 0.4rem; min-width: 0; }
    .header-right { gap: 0.2rem; min-width: 0; }
    .active-player { font-size: 0.75rem; overflow: hidden; text-overflow: ellipsis; max-width: 7.5rem; flex-shrink: 0; }
    .phase-badge { padding: 0.15rem 0.35rem; }
    .game-header .btn-icon { padding-left: 0.25rem; padding-right: 0.25rem; min-width: 1.65rem; }
}

/* --- Board viewport --- */

.board-viewport {
    flex: 1;
    overflow: hidden;
    position: relative;
    background: #080810;
    touch-action: none;
    cursor: grab;
}

.board-viewport:active { cursor: grabbing; }

.board-canvas {
    position: absolute;
    top: 0;
    left: 0;
    transform-origin: 0 0;
    will-change: transform;
}

.board-canvas.smooth {
    transition: transform 0.6s cubic-bezier(0.25, 0.1, 0.25, 1);
}

.board-canvas img {
    display: block;
    user-select: none;
    -webkit-user-drag: none;
    pointer-events: none;
}

/* Board loading */
.board-loading {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    z-index: 50;
    transition: opacity 0.4s;
}

.board-loading.loaded {
    opacity: 0;
    pointer-events: none;
}

.board-loading-inner { text-align: center; color: var(--text-muted); }

.board-loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    margin: 0 auto 1rem;
    animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* --- Board tokens --- */

.board-tokens {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.board-token {
    position: absolute;
    width: 280px;
    height: 280px;
    border-radius: 50%;
    border: 12px solid;
    transform: translate(-50%, -50%);
    pointer-events: none;
    overflow: hidden;
    box-shadow: 0 10px 28px rgba(0,0,0,0.65);
    z-index: 5;
    transition: left 0.4s ease,
                top 0.4s ease;
}

.board-token img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: 50% 12%;
    transform: scale(1.35);
    transform-origin: 50% 20%;
    display: block;
    pointer-events: none;
}

/* Fallback when no portrait is available */
.board-token--fallback {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 700;
    color: #000;
}

/* --- Board highlights (reachable spaces) --- */

.board-highlights {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

/* SVG tile layer: outlines on every tile, and the movement spotlight.
   Stroke widths are screen pixels times --inv-scale (1 / camera scale, set
   by board.js), so they keep the same on-screen width at every zoom.
   (vector-effect: non-scaling-stroke ignores the CSS transform on the
   canvas, so it can't do this.) */
.board-tiles {
    --inv-scale: 3;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 2;
    overflow: visible;
    pointer-events: none;
}

.tile-lines {
    fill: none;
    stroke: var(--tile-line);
    stroke-width: calc(1px * var(--inv-scale));
    stroke-linejoin: miter;
}

.tile-lines--shadow {
    stroke: var(--tile-line-shadow);
    stroke-width: calc(3px * var(--inv-scale));
}

/* The board's tiles (board.js showTiles): one cell per space, the cropped
   texture covering it. Boxes are in board pixels. */
.board-tiles-art { position: absolute; inset: 0; pointer-events: none; }
.board-tile { position: absolute; overflow: hidden; background: #2b2216; }
.board-canvas .board-tile img {
    position: absolute;
    max-width: none;
    user-select: none;
    -webkit-user-drag: none;
}

.board-dim {
    fill: var(--board-dim);
    opacity: 0;
    transition: opacity 0.25s ease;
}

.board-tiles.is-spotlight .board-dim { opacity: 1; }

.tile-reach {
    pointer-events: all;
    cursor: pointer;
}

.tile-reach-halo,
.tile-reach-edge {
    fill: transparent;
    stroke-linejoin: round;
    transition: fill 0.15s, stroke 0.15s, stroke-width 0.15s;
}

/* Soft gold glow spilling onto the dimmed board round the tile. */
.tile-reach-halo {
    stroke: var(--reach-halo);
    stroke-width: calc(16px * var(--inv-scale));
}

.tile-reach-edge {
    stroke: var(--reach);
    stroke-width: calc(4px * var(--inv-scale));
    animation: reach-pulse 1.6s ease-in-out infinite;
}

.tile-reach:hover .tile-reach-edge,
.tile-reach:focus-visible .tile-reach-edge {
    fill: var(--reach-hover-fill);
    stroke: var(--reach-hover);
    stroke-width: calc(6px * var(--inv-scale));
    animation: none;
}

.tile-reach:hover .tile-reach-halo {
    stroke: var(--reach-halo-hover);
    stroke-width: calc(24px * var(--inv-scale));
}

.tile-reach-label {
    fill: var(--reach-label);
    stroke: var(--reach-label-bg);
    stroke-width: calc(5px * var(--inv-scale));
    stroke-linejoin: round;
    paint-order: stroke;
    font-family: var(--font-sans);
    font-weight: 700;
    letter-spacing: 0.02em;
    text-anchor: middle;
    dominant-baseline: middle;
    pointer-events: none;
}

.tile-reach:hover .tile-reach-label { fill: var(--reach-hover); }

@keyframes reach-pulse {
    0%, 100% { stroke-opacity: 1; }
    50% { stroke-opacity: 0.7; }
}

@media (prefers-reduced-motion: reduce) {
    .tile-reach-edge { animation: none; }
}

/* While choosing a move, the reachable tiles take every click. */
.board-canvas.is-choosing .space-hitarea { pointer-events: none; }

/* --- Space hit areas (for inspection) --- */

.space-hitarea {
    position: absolute;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    transform: translate(-50%, -50%);
    cursor: pointer;
    z-index: 3;
    pointer-events: auto;
}

.space-hitarea:hover {
    background: radial-gradient(circle, rgba(196, 164, 78, 0.12) 0%, transparent 70%);
}

.threat-dot {
    width: 10px; height: 10px; border-radius: 50%;
    border: 1px solid rgba(0,0,0,0.3);
}

.threat-dot--red { background: var(--threat-red); }
.threat-dot--blue { background: var(--threat-blue); }
.threat-dot--yellow { background: var(--threat-yellow); }

/* --- Tile card (close-up) ---
   Talisman-style: the clean tile art on top, the name on a parchment banner
   overlapping it, then threats and rules. #tile-closeup is the full card,
   #tile-preview (.tile-closeup--preview) the small hover card.

   On arrival (.is-arrival, board.js showTileArrival) the card comes in big
   on the right of the board, labelled "You are here" with a gold leader
   line to the tile (#tile-leader); after a few seconds, or as soon as the
   player does anything, it docks: still on the right, vertically centred,
   wider than it used to be. Both widths are in rem, so they follow the UI
   size; the camera keeps the tile clear of the card (keepSpaceClear), and
   overlayInsets() counts it for the move fits. Phones: a bottom sheet on
   arrival, then a slim strip that opens again on a tap (.is-expanded). */

@property --tc-w {
    syntax: '<length>';
    inherits: true;
    initial-value: 0px;
}

:root {
    --tc-dock-w: clamp(20rem, 34vw, 27rem);
    --tc-arrive-w: clamp(22rem, 42vw, 36rem);
}

.tile-closeup {
    --tc-w: var(--tc-dock-w);
    position: absolute;
    top: 50%;
    right: var(--gutter);
    width: var(--tc-w);
    max-height: calc(100% - 2 * var(--gutter));
    display: flex;
    flex-direction: column;
    background: var(--card-bg);
    color: var(--text);
    border: 1px solid var(--card-edge);
    border-radius: var(--radius-lg);
    overflow: hidden;
    z-index: 30;
    --tc-y: -50%;
    transform: translateY(var(--tc-y));
    box-shadow: 0 0.625rem 2.5rem rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(0, 0, 0, 0.25), 0 0 2.5rem var(--accent-dim);
    animation: tile-card-in 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
    transition: --tc-w 0.45s cubic-bezier(0.3, 0.7, 0.2, 1), box-shadow 0.45s ease, border-color 0.45s ease;
}

.tile-closeup[hidden] { display: none; }
.tile-closeup.is-suppressed { visibility: hidden; }

.tc-open-hint { display: none; }

#tile-closeup.is-arrival {
    --tc-w: var(--tc-arrive-w);
    border-color: var(--accent);
    box-shadow: 0 1rem 3.5rem rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(0, 0, 0, 0.25), 0 0 3.5rem rgba(196, 164, 78, 0.35);
    animation: tile-card-arrive 0.5s cubic-bezier(0.2, 0.8, 0.2, 1);
}

/* "You are here" (or whose figure it is) over the art. */
.tc-here {
    position: absolute;
    top: 0.6rem;
    left: 0.6rem;
    z-index: 2;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.2rem 0.65rem 0.2rem 0.45rem;
    border: 1px solid var(--accent);
    border-radius: 999px;
    background: rgba(8, 8, 12, 0.72);
    color: #f6e7b8;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    pointer-events: none;
}

.tc-here::before {
    content: '';
    width: 0.55rem;
    height: 0.55rem;
    border-radius: 50%;
    background: var(--reach);
    box-shadow: 0 0 0 0.2rem rgba(242, 201, 76, 0.3);
    animation: tc-here-pulse 1.6s ease-in-out infinite;
}

.is-arrival .tc-here { font-size: 0.8rem; }

@keyframes tc-here-pulse {
    50% { box-shadow: 0 0 0 0.35rem rgba(242, 201, 76, 0.08); }
}

/* The gold line from the arriving card to its tile. */
.tile-leader {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 29;
    pointer-events: none;
    overflow: visible;
}

.tile-leader[hidden] { display: none; }

.tile-leader line {
    stroke: var(--reach);
    stroke-width: 2;
    stroke-dasharray: 6 5;
    stroke-linecap: round;
    filter: drop-shadow(0 0 3px rgba(0, 0, 0, 0.8));
    animation: tc-leader-run 0.9s linear infinite;
}

.tile-leader circle {
    fill: none;
    stroke: var(--reach);
    stroke-width: 2.5;
    filter: drop-shadow(0 0 4px rgba(0, 0, 0, 0.8));
}

.tile-leader .tc-leader-dot { fill: var(--reach); stroke: none; }

@keyframes tc-leader-run { to { stroke-dashoffset: -11; } }

.tc-art {
    position: relative;
    flex: none;
    /* The art's own shape at the card's width, within limits; shorter on
       short screens so the rules stay in view. */
    height: min(clamp(13rem, calc(var(--tc-w) / var(--ar, 1.4)), 21rem), 40vh);
    background: var(--art-bg);
    overflow: hidden;
}

/* The art itself is never cropped; a blurred copy fills any space around it. */
.tc-art-fill {
    position: absolute;
    inset: -1.5rem;
    background-size: cover;
    background-position: center;
    filter: blur(1.125rem) brightness(0.75) saturate(1.15);
}

.tc-art-img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    user-select: none;
}

.tc-art-crop {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    background-image: url('/data/board/board.png');
    background-repeat: no-repeat;
}

.tc-art.is-loading::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(100deg, transparent 30%, rgba(255, 255, 255, 0.06) 50%, transparent 70%) 0 0 / 200% 100%;
    animation: tc-shimmer 1.2s linear infinite;
}

/* Darken the foot of the art so the banner sits on it cleanly. */
.tc-art::after {
    content: '';
    position: absolute;
    inset: auto 0 0 0;
    height: 3.5rem;
    background: linear-gradient(to bottom, transparent, rgba(0, 0, 0, 0.55));
    pointer-events: none;
}

.tc-head {
    position: relative;
    z-index: 1;
    flex: none;
    margin-top: -1.75rem;
    padding: 0 1.75rem;
    text-align: center;
}

.tc-banner {
    position: relative;
    display: inline-block;
    max-width: 100%;
    padding: 0.45rem 1.4rem 0.5rem;
    background:
        radial-gradient(ellipse at 30% 20%, rgba(255, 255, 255, 0.35), transparent 60%),
        linear-gradient(180deg, var(--parch-hi), var(--parch-lo));
    border-top: 0.125rem solid var(--parch-edge);
    border-bottom: 0.125rem solid var(--parch-edge);
    box-shadow: 0 0.25rem 0.75rem rgba(0, 0, 0, 0.45), inset 0 0 1.125rem rgba(120, 80, 20, 0.25);
}

/* Ribbon tails, folded behind the banner. */
.tc-banner::before,
.tc-banner::after {
    content: '';
    position: absolute;
    top: 0.4375rem;
    bottom: -0.4375rem;
    width: 1.375rem;
    z-index: -1;
    background: linear-gradient(180deg, var(--parch-tail), var(--parch-edge));
}

.tc-banner::before {
    left: -1rem;
    clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%, 0.4375rem 50%);
}

.tc-banner::after {
    right: -1rem;
    clip-path: polygon(0 0, 100% 0, calc(100% - 0.4375rem) 50%, 100% 100%, 0 100%);
}

.tc-name {
    margin: 0;
    font-family: var(--font-sans);
    font-size: 1.12rem;
    font-weight: 700;
    line-height: 1.2;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--parch-ink);
    text-shadow: 0 1px 0 rgba(255, 255, 255, 0.35);
}

.tc-ring {
    margin: 0.4rem 0 0;
    font-size: 0.72rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.tc-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 0.7rem 1.1rem 1.1rem;
}

.tc-threats {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.2rem 0 0.75rem;
}

.tc-threats:not(:last-child) {
    border-bottom: 1px solid var(--option-edge);
    margin-bottom: 0.75rem;
}

.tc-seals { display: flex; gap: 0.3rem; flex: none; }

/* Wax seals in the threat colours. */
.tc-seal {
    --seal: var(--threat-red);
    width: 1.625rem;
    height: 1.625rem;
    border-radius: 50%;
    background:
        radial-gradient(circle at 34% 30%, rgba(255, 255, 255, 0.45), transparent 38%),
        radial-gradient(circle, transparent 52%, rgba(0, 0, 0, 0.22) 54%, rgba(0, 0, 0, 0.22) 60%, transparent 62%),
        var(--seal);
    box-shadow: inset 0 -0.125rem 0.1875rem rgba(0, 0, 0, 0.35), 0 1px 0.1875rem rgba(0, 0, 0, 0.5);
}

.tc-seal--red { --seal: var(--threat-red); }
.tc-seal--blue { --seal: var(--threat-blue); }
.tc-seal--yellow { --seal: var(--threat-yellow); }
.tc-seal--orange { --seal: #d9701c; }

.tc-threat-legend {
    font-size: 0.85rem;
    line-height: 1.35;
    color: var(--text);
}

.tc-rules {
    font-size: 0.9rem;
    line-height: 1.55;
}

.tc-rules p { margin: 0; }
.tc-rule > * + * { margin-top: 0.45rem; }

.tc-keyword {
    font-weight: 700;
    color: var(--accent);
}

.tc-outcomes,
.tc-conditions {
    list-style: none;
    margin: 0;
    padding: 0;
}

.tc-outcomes li {
    display: flex;
    align-items: baseline;
    gap: 0.6rem;
    padding: 0.2rem 0;
}

.tc-outcomes li + li { border-top: 1px dashed var(--option-edge); }

.tc-roll {
    flex: none;
    min-width: 2.6em;
    padding: 0.05rem 0.35rem;
    text-align: center;
    font-size: 0.8rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--accent);
    border: 1px solid var(--option-edge);
    border-radius: 0.25rem;
    background: var(--option-bg);
}

.tc-conditions li {
    position: relative;
    padding-left: 1.1rem;
}

.tc-conditions li::before {
    content: '';
    position: absolute;
    left: 0.25rem;
    top: 0.6em;
    width: 0.375rem;
    height: 0.375rem;
    transform: rotate(45deg);
    background: var(--accent);
}

.tc-rule-tail { color: var(--text); }

.tc-choose {
    text-align: center;
    font-size: 0.78rem;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    margin-bottom: 0.55rem !important;
}

.tc-option {
    padding: 0.6rem 0.75rem;
    background: var(--option-bg);
    border: 1px solid var(--option-edge);
    border-radius: var(--radius);
}

.tc-or {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin: 0.4rem 0;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--accent);
}

.tc-or::before,
.tc-or::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--option-edge);
}

.tc-empty {
    margin: 0;
    text-align: center;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.tc-close {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    z-index: 2;
    width: 2rem;
    height: 2rem;
    display: grid;
    place-items: center;
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 50%;
    background: rgba(8, 8, 12, 0.6);
    color: #f2ead6;
    font-size: 1.25rem;
    line-height: 1;
    cursor: pointer;
    backdrop-filter: blur(0.25rem);
    -webkit-backdrop-filter: blur(0.25rem);
}

.tc-close:hover { background: rgba(8, 8, 12, 0.85); border-color: var(--accent); }
.tc-close:focus-visible { outline: 0.125rem solid var(--accent); outline-offset: 0.125rem; }

/* Hover preview: smaller, never takes a click, on the side away from the tile. */
.tile-closeup--preview {
    width: 20rem;
    pointer-events: none;
    z-index: 31;
    animation: tile-preview-in 0.15s ease;
}

.tile-closeup--left {
    right: auto;
    left: var(--gutter);
    animation-name: tile-preview-in-left;
}

.tile-closeup--preview .tc-art { height: clamp(9.375rem, calc(20rem / var(--ar, 1.4)), 13.125rem); }
.tile-closeup--preview .tc-head { margin-top: -1.375rem; }
.tile-closeup--preview .tc-name { font-size: 0.95rem; }
.tile-closeup--preview .tc-body {
    overflow: hidden;
    max-height: 11.5rem;
    padding: 0.55rem 0.9rem 0.8rem;
    -webkit-mask-image: linear-gradient(to bottom, #000 75%, transparent);
    mask-image: linear-gradient(to bottom, #000 75%, transparent);
}
.tile-closeup--preview .tc-rules { font-size: 0.82rem; line-height: 1.45; }
.tile-closeup--preview .tc-seal { width: 1.375rem; height: 1.375rem; }
.tile-closeup--preview .tc-threat-legend { font-size: 0.8rem; }

@keyframes tile-card-arrive {
    from { opacity: 0; transform: translate(3rem, var(--tc-y)) scale(0.94); }
    to { opacity: 1; transform: translateY(var(--tc-y)); }
}

@keyframes tile-card-in {
    from { opacity: 0; transform: translate(2rem, var(--tc-y)); }
    to { opacity: 1; transform: translateY(var(--tc-y)); }
}

@keyframes tile-preview-in {
    from { opacity: 0; transform: translate(0.625rem, var(--tc-y)); }
    to { opacity: 1; transform: translateY(var(--tc-y)); }
}

@keyframes tile-preview-in-left {
    from { opacity: 0; transform: translate(-0.625rem, var(--tc-y)); }
    to { opacity: 1; transform: translateY(var(--tc-y)); }
}

@keyframes tile-sheet-in {
    from { transform: translateY(100%); }
    to { transform: none; }
}

@keyframes tc-shimmer {
    to { background-position: -200% 0; }
}

@media (prefers-reduced-motion: reduce) {
    .tile-closeup, .tc-art.is-loading::before, .tc-here::before, .tile-leader line { animation: none; }
    .tile-closeup { transition: none; }
}

/* Phones: the full card is a bottom sheet on arrival (and when opened
   again); docked it is a slim strip along the bottom (art, name, ring,
   seals) that opens on a tap. The preview sits at the top or bottom, away
   from the tile. No leader line: the sheet spans the width. */
@media (max-width: 768px) {
    .tile-closeup { --tc-y: 0px; }
    .tile-leader { display: none; }

    #tile-closeup,
    #tile-closeup.is-arrival {
        top: auto;
        left: 0;
        right: 0;
        bottom: 0;
        width: auto;
        max-height: 64%;
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        border-bottom: 0;
        animation: tile-sheet-in 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
        transition: none;
    }

    /* Docked: the strip. */
    #tile-closeup:not(.is-arrival):not(.is-expanded) {
        display: grid;
        grid-template-columns: 5.5rem minmax(0, 1fr);
        grid-template-rows: auto auto;
        align-items: center;
        column-gap: 0.75rem;
        padding: 0.4rem 7.25rem calc(0.4rem + env(safe-area-inset-bottom)) 0.4rem;
        cursor: pointer;
        animation: none;
    }
    #tile-closeup:not(.is-arrival):not(.is-expanded)[hidden] { display: none; }
    #tile-closeup:not(.is-arrival):not(.is-expanded) .tc-art {
        grid-row: 1 / 3;
        height: 3.75rem;
        border-radius: var(--radius);
    }
    #tile-closeup:not(.is-arrival):not(.is-expanded) .tc-art::after { display: none; }
    #tile-closeup:not(.is-arrival):not(.is-expanded) .tc-here { display: none; }
    #tile-closeup:not(.is-arrival):not(.is-expanded) .tc-head {
        margin: 0;
        padding: 0;
        text-align: left;
    }
    #tile-closeup:not(.is-arrival):not(.is-expanded) .tc-banner {
        padding: 0;
        background: none;
        border: 0;
        box-shadow: none;
    }
    #tile-closeup:not(.is-arrival):not(.is-expanded) .tc-banner::before,
    #tile-closeup:not(.is-arrival):not(.is-expanded) .tc-banner::after { display: none; }
    #tile-closeup:not(.is-arrival):not(.is-expanded) .tc-name {
        color: var(--accent);
        font-size: 0.92rem;
        text-shadow: none;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    #tile-closeup:not(.is-arrival):not(.is-expanded) .tc-ring { margin-top: 0.1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    #tile-closeup:not(.is-arrival):not(.is-expanded) .tc-body {
        overflow: hidden;
        padding: 0;
    }
    #tile-closeup:not(.is-arrival):not(.is-expanded) .tc-body > :not(.tc-threats),
    #tile-closeup:not(.is-arrival):not(.is-expanded) .tc-threat-legend { display: none; }
    #tile-closeup:not(.is-arrival):not(.is-expanded) .tc-threats { padding: 0.2rem 0 0; border: 0; margin: 0; }
    #tile-closeup:not(.is-arrival):not(.is-expanded) .tc-seal { width: 1.1rem; height: 1.1rem; }
    #tile-closeup:not(.is-arrival):not(.is-expanded) .tc-close { top: 50%; transform: translateY(-50%); }
    .tc-open-hint { display: none; }
    #tile-closeup:not(.is-arrival):not(.is-expanded) .tc-open-hint {
        display: block;
        position: absolute;
        right: 3.1rem;
        top: 50%;
        transform: translateY(-50%);
        padding: 0.15rem 0.5rem;
        border: 1px solid var(--option-edge);
        border-radius: 999px;
        font-size: 0.7rem;
        font-weight: 700;
        color: var(--accent);
        pointer-events: none;
    }

    #tile-closeup .tc-art {
        height: clamp(8.125rem, calc(100vw / var(--ar, 1.4)), 24vh);
    }

    .tc-body { padding: 0.6rem 1rem calc(1rem + env(safe-area-inset-bottom)); }

    .tile-closeup--preview,
    .tile-closeup--preview.tile-closeup--left {
        left: var(--gutter);
        right: var(--gutter);
        width: auto;
    }

    .tile-closeup--preview.tile-closeup--bottom {
        top: auto;
        bottom: 4.75rem; /* above the mobile move buttons */
    }

    .tile-closeup--preview .tc-art { height: clamp(5.625rem, calc((100vw - 2rem) / var(--ar, 1.4)), 8.125rem); }
    .tile-closeup--preview .tc-body { max-height: 6.5rem; }

    /* With the sheet up, lift the main prompt above it. */
    .board-viewport:has(#tile-closeup:is(.is-arrival, .is-expanded):not([hidden]):not(.is-suppressed)) .centre-prompt {
        top: 15%;
    }
}

/* --- Waiting indicator --- */

.waiting-indicator {
    position: absolute;
    top: 0.5rem;
    left: 50%;
    transform: translateX(-50%);
    background: var(--glass);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: 1px solid var(--border);
    border-radius: 1.25rem;
    padding: 0.3rem 1rem;
    font-size: 0.75rem;
    color: var(--text-muted);
    z-index: 15;
    white-space: nowrap;
}

.waiting-indicator[hidden] { display: none; }

/* --- Turn banner overlay --- */

.turn-banner {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 60;
    background: rgba(0, 0, 0, 0.6);
    animation: banner-in 0.4s ease;
    pointer-events: none;
}

.turn-banner[hidden] { display: none; }

.turn-banner-inner { text-align: center; }

.turn-banner-name {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    text-shadow: 0 0.125rem 1.25rem rgba(196, 164, 78, 0.5);
    animation: banner-text-in 0.5s ease;
}

.turn-banner-portrait {
    width: 5rem;
    height: 5rem;
    border-radius: 50%;
    border: 0.1875rem solid var(--accent);
    object-fit: cover;
    margin: 0 auto 0.75rem;
    display: block;
    box-shadow: 0 0.25rem 1.25rem rgba(196, 164, 78, 0.4);
    animation: banner-text-in 0.5s ease;
}

.turn-banner-character {
    font-size: 1rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
    letter-spacing: 0.06em;
}

/* --- Corruption announcement (ui.js showCorruptionBanner) --- */

.corruption-banner {
    /* Always over a dark veil, so the colours don't follow the theme. */
    --warp: #9be05a;
    --warp-glow: rgba(140, 220, 80, 0.45);
    --chaos: #b04ad8;
    --veil-ink: #ece6d6;
    --veil-muted: #b5ad98;
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 61;
    padding: 0 var(--gutter);
    background: radial-gradient(ellipse at center, rgba(40, 10, 50, 0.82), rgba(0, 0, 0, 0.78));
    animation: banner-in 0.4s ease;
    cursor: pointer;
}

.corruption-banner.is-leaving { animation: banner-out 0.4s ease forwards; }

.corruption-inner { text-align: center; max-width: 32rem; }

.corruption-title {
    font-size: 2.4rem;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--warp);
    text-shadow: 0 0 1.125rem var(--warp-glow), 0 0.125rem 0 #000;
    animation: banner-text-in 0.5s ease;
}

.corruption-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1.25rem;
    margin: 1rem 0 0.75rem;
}

.corruption-fig { margin: 0; display: flex; flex-direction: column; align-items: center; gap: 0.4rem; }

.corruption-fig figcaption { font-size: 0.9rem; color: var(--veil-ink); letter-spacing: 0.04em; }

.corruption-portrait {
    width: 5.75rem;
    height: 5.75rem;
    border-radius: 50%;
    object-fit: cover;
    display: block;
}

.corruption-portrait.is-lost {
    border: 0.1875rem solid var(--chaos);
    filter: grayscale(1) sepia(0.4) hue-rotate(250deg) brightness(0.7);
    box-shadow: 0 0 1.375rem rgba(176, 74, 216, 0.55);
}

.corruption-portrait.is-new {
    border: 0.1875rem solid var(--accent);
    box-shadow: 0 0.25rem 1.375rem rgba(196, 164, 78, 0.5);
    animation: banner-text-in 0.6s ease 0.5s both;
}

.corruption-arrow { font-size: 1.8rem; color: var(--veil-muted); }

.corruption-out {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--chaos);
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.corruption-text { font-size: 1rem; color: var(--veil-muted); line-height: 1.45; }

@media (max-width: 480px) {
    .corruption-title { font-size: 1.8rem; }
    .corruption-portrait { width: 4.25rem; height: 4.25rem; }
}

@media (prefers-reduced-motion: reduce) {
    .corruption-banner, .corruption-banner.is-leaving, .corruption-title, .corruption-portrait.is-new { animation: none; }
}

@keyframes banner-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes banner-text-in {
    from { opacity: 0; transform: scale(0.8); }
    to { opacity: 1; transform: scale(1); }
}

@keyframes banner-out {
    from { opacity: 1; }
    to { opacity: 0; }
}

/* --- Space landing notification --- */

.space-landing {
    position: absolute;
    left: 50%;
    top: 30%;
    transform: translate(-50%, -50%);
    z-index: 35;
    pointer-events: none;
}

.space-landing[hidden] { display: none; }

.space-landing-inner {
    text-align: center;
    background: var(--glass);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: 1px solid var(--accent);
    border-radius: var(--radius-lg);
    padding: 0.75rem 2rem;
    box-shadow: 0 0.25rem 1.875rem rgba(196, 164, 78, 0.3), 0 0 3.75rem rgba(196, 164, 78, 0.1);
}

.space-landing-name {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    text-shadow: 0 0.125rem 0.625rem rgba(196, 164, 78, 0.4);
}

.space-landing-detail {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-top: 0.15rem;
}

@keyframes space-landing-in {
    from { opacity: 0; transform: translate(-50%, -50%) scale(0.85); }
    to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

@keyframes space-landing-out {
    from { opacity: 1; transform: translate(-50%, -50%) scale(1); }
    to { opacity: 0; transform: translate(-50%, -50%) scale(0.9) translateY(-0.625rem); }
}

/* --- Centre prompt (Roll Dice / End Turn) --- */

.centre-prompt {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    z-index: 40;
    animation: prompt-in 0.3s ease;
}

.centre-prompt[hidden] { display: none; }

.centre-prompt-btn {
    display: block;
    min-width: 12.5rem;
    padding: 1rem 2.5rem;
    background: var(--accent);
    color: var(--bg);
    border: 0.125rem solid rgba(255,255,255,0.15);
    border-radius: var(--radius-lg);
    font-family: var(--font-sans);
    font-size: 1.3rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    cursor: pointer;
    box-shadow: 0 0.25rem 1.875rem rgba(196, 164, 78, 0.4), 0 0 3.75rem rgba(196, 164, 78, 0.15);
    transition: transform 0.15s, box-shadow 0.15s;
}

.centre-prompt-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 0.375rem 2.5rem rgba(196, 164, 78, 0.5), 0 0 5rem rgba(196, 164, 78, 0.2);
}

.centre-prompt-btn:active { transform: scale(0.97); }

.centre-prompt-alt {
    display: block;
    margin: 0.625rem auto 0;
    padding: 0.4rem 1rem;
    background: var(--surface, rgba(20, 18, 14, 0.85));
    color: var(--accent);
    border: 1px solid var(--accent);
    border-radius: var(--radius-lg);
    font-family: var(--font-sans);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
}

.centre-prompt-alt:hover { background: var(--accent); color: var(--bg); }

/* A choice offering Power cards from the hand: the character panel rises
   over the backdrop so its lit cards can be clicked. */
body:has(#choice-overlay.choice-overlay--hand) #hud { z-index: 58; }
/* ...and the dialog stays above it (choices.js sets --hud-room). */
.choice-overlay.choice-overlay--hand { padding-bottom: calc(var(--hud-room, 0px) + var(--gutter)); }
.choice-overlay--hand .choice-panel { max-height: calc(100dvh - var(--hud-room, 0px) - 2 * var(--gutter)); }

.centre-prompt-btn--secondary {
    min-width: 10rem;
    padding: 0.75rem 2rem;
    font-size: 1rem;
    box-shadow: 0 0.25rem 1.25rem rgba(196, 164, 78, 0.3);
}

@keyframes prompt-in {
    from { opacity: 0; transform: translate(-50%, -50%) scale(0.85); }
    to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

/* --- Dice result animation --- */

.dice-result {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    z-index: 45;
    pointer-events: none;
}

.dice-result[hidden] { display: none; }

.dice-result span {
    display: block;
    font-size: 5rem;
    font-weight: 700;
    color: var(--accent);
    text-shadow: 0 0.25rem 1.875rem rgba(196, 164, 78, 0.6);
    animation: dice-pop 1s ease forwards;
}

@keyframes dice-pop {
    0% { opacity: 0; transform: scale(2); }
    20% { opacity: 1; transform: scale(1); }
    70% { opacity: 1; transform: scale(1); }
    100% { opacity: 0; transform: scale(0.6) translateY(-1.875rem); }
}

/* --- Card reveal overlay --- */

.card-reveal {
    position: absolute;
    inset: 0;
    z-index: 50;
    container-type: size; /* the drawn cards size by the room the overlay has */
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fade-in 0.3s ease;
}

.card-reveal[hidden] { display: none; }

/* In the game the drawn cards take the whole window under the header,
   over the character panel too, so they can be big. */
.view-game .card-reveal,
#view-game .card-reveal {
    position: fixed;
    inset: var(--reveal-top, 3.25rem) 0 0 0;
}

.card-reveal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
}

.card-reveal-content {
    /* Drawn cards: as big as the room allows, in the card's own shape
       (276 x 427), by width per card and by height (title, notes, name and
       Continue need about 10rem; scans keep their name box below). */
    --rv-ratio: 1.547;
    --rv-w: min(24rem, 40cqw, calc((92cqh - 10rem) / var(--rv-ratio)));
    position: relative;
    text-align: center;
    max-width: 90vw;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.card-reveal-title {
    font-size: 1rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--accent);
    margin-bottom: 1rem;
}

/* Why these cards were drawn, and what follows (one line each). */
.card-reveal-why {
    max-width: 34rem;
    margin: -0.5rem auto 0.9rem;
    font-size: 0.85rem;
    line-height: 1.4;
    text-align: center;
    color: var(--text-muted);
}

.card-reveal-why > span { display: block; }
.card-reveal-why > span + span { color: #fff; font-weight: 600; margin-top: 0.15rem; }
/* Over the dark backdrop in both themes. */
.card-reveal-why { color: rgb(255 255 255 / 0.82); text-shadow: 0 1px 2px rgb(0 0 0 / 0.6); }
.card-reveal-why[hidden] { display: none; }

.card-reveal-cards {
    display: flex;
    gap: 1rem;
    justify-content: safe center; /* scrolls from the first card when they overflow */
    flex-wrap: nowrap;
    overflow-x: auto;
    padding: 0.5rem;
    max-width: 100%;
}

.card-reveal-content:has(.reveal-card:nth-child(3)) { --rv-w: min(22rem, 28cqw, calc((92cqh - 10rem) / var(--rv-ratio))); }
.card-reveal-content:has(.reveal-card:nth-child(4)) { --rv-w: min(19rem, 21cqw, calc((92cqh - 10rem) / var(--rv-ratio))); }

.reveal-card {
    flex-shrink: 0;
    width: var(--rv-w);
    background: var(--bg-panel);
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.2s, border-color 0.2s;
    text-align: center;
}

/* A redrawn card carries its own name, type and text, and its own frame. */
.reveal-card:has(.rcard) { background: none; border: 0; overflow: visible; }
.reveal-card:has(.rcard) .reveal-card-info { display: none; }

.reveal-card:hover {
    transform: translateY(-0.375rem);
    border-color: var(--accent);
}

.reveal-card img {
    width: var(--rv-w);
    height: calc(var(--rv-w) * var(--rv-ratio));
    object-fit: cover;
    display: block;
    background: var(--bg);
}

/* Dealt face down, then turned over (ui.js, timings in cardflip.js). */
.reveal-flip {
    position: relative;
    width: var(--rv-w);
    height: calc(var(--rv-w) * var(--rv-ratio));
    transform-style: preserve-3d;
    transform: perspective(56.25rem) rotateY(0deg);
    transition: transform var(--flip-ms, 520ms) cubic-bezier(0.3, 0.6, 0.25, 1);
}

.reveal-card.is-face-down .reveal-flip { transform: perspective(56.25rem) rotateY(180deg); }

.reveal-face {
    position: absolute;
    inset: 0;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

.reveal-face--back { transform: rotateY(180deg); }

/* A lift while it turns. */
.reveal-card.is-flipping .reveal-face { animation: reveal-lift var(--flip-ms, 520ms) ease-out; }

@keyframes reveal-lift {
    50% { filter: brightness(1.15) drop-shadow(0 0.625rem 0.875rem rgba(0, 0, 0, 0.55)); }
}

/* Sliding in face down. */
.reveal-card.is-dealing {
    animation: reveal-deal var(--deal-ms, 260ms) cubic-bezier(0.2, 0.7, 0.3, 1) both;
    animation-delay: var(--deal-delay, 0ms);
}

@keyframes reveal-deal {
    from { opacity: 0; transform: translateY(-2.25rem) rotate(-5deg) scale(0.92); }
    to { opacity: 1; transform: none; }
}

/* The text waits for the face. */
.reveal-card .reveal-card-info { transition: opacity 0.25s ease; }
.reveal-card.is-face-down .reveal-card-info { opacity: 0; }

.reveal-card-blank {
    width: 100%;
    height: 100%;
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* A back drawn in CSS, for cards without an image. */
.reveal-card-back {
    width: 100%;
    height: 100%;
    border: 0.375rem solid var(--card-edge);
    border-radius: var(--radius);
    background:
        radial-gradient(circle at 50% 50%, rgba(196, 164, 78, 0.35) 0 18%, transparent 19%),
        repeating-linear-gradient(45deg, #1b1410 0 0.625rem, #241a14 0.625rem 1.25rem);
}

@media (prefers-reduced-motion: reduce) {
    .reveal-flip { transition: none; }
    .reveal-card.is-dealing, .reveal-card.is-flipping .reveal-face { animation: none; }
}

.reveal-card-info {
    padding: 0.5rem;
}

.reveal-card-name {
    font-weight: 600;
    font-size: 0.8rem;
    color: var(--text);
    margin-bottom: 0.15rem;
}

.reveal-card-type {
    font-size: 0.65rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.reveal-card-threat {
    display: inline-block;
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--danger);
    margin-left: 0.25rem;
}

.reveal-card-text {
    font-size: 0.65rem;
    color: var(--text-muted);
    line-height: 1.3;
    margin-top: 0.25rem;
    max-height: 4em;
    overflow: hidden;
}

.card-reveal-continue {
    margin-top: 1rem;
    width: auto;
    min-width: 8.75rem;
}

/* --- Card inspection (full-screen single card) --- */

.card-inspection {
    position: absolute;
    inset: 0;
    z-index: 55;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fade-in 0.2s ease;
    cursor: pointer;
}

.card-inspection[hidden] { display: none; }

.card-inspection-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
}

.card-inspection-content {
    position: relative;
    text-align: center;
    max-width: 25rem;
    width: 90%;
}

.card-inspection-image img {
    max-width: 100%;
    max-height: 50vh;
    border-radius: var(--radius);
    border: 0.125rem solid var(--border-light);
}

.card-inspection-details {
    margin-top: 0.75rem;
}

.card-inspection-details h3 {
    font-size: 1.1rem;
    color: var(--accent);
    margin-bottom: 0.25rem;
}

.card-inspection-type {
    display: inline-block;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    padding: 0.1rem 0.5rem;
    background: var(--accent-dim);
    border-radius: 0.1875rem;
    margin-bottom: 0.5rem;
}

.card-inspection-details p {
    font-size: 0.85rem;
    color: var(--text);
    line-height: 1.5;
}

/* A lit card opened from the panel (handplay.js): its Play / Use button.
   Over a choice dialog (57) and the panel it raises (58). */
.card-inspection--action { position: fixed; z-index: 59; }
.card-inspection-actions {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
    margin-top: 0.75rem;
}
.card-inspection-actions[hidden] { display: none; }
.card-inspection-actions .btn { width: auto; min-width: 7.5rem; }

/* --- Log panel --- */

.log-panel {
    position: absolute;
    right: var(--gutter);
    bottom: 5rem;
    width: 17.5rem;
    max-height: 18.75rem;
    background: var(--glass);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    z-index: 25;
    display: flex;
    flex-direction: column;
    animation: fade-in 0.2s ease;
}

.log-panel[hidden] { display: none; }

.log-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.4rem 0.75rem;
    border-bottom: 1px solid var(--border);
}

.log-panel-header h3 {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--accent);
    font-weight: 600;
}

.log-area {
    flex: 1;
    overflow-y: auto;
    font-size: 0.7rem;
    color: var(--text-muted);
    padding: 0.25rem 0.5rem;
    line-height: 1.4;
    max-height: 12.5rem;
}

.log-line { padding: 1px 0; border-bottom: 1px solid var(--border); }
.log-line:last-child { border-bottom: none; }
.log-line--system { color: var(--accent); }
.log-line--chat { color: var(--info); }
.log-line--error { color: var(--danger); }

.chat-input-row {
    display: flex; gap: 0.25rem; padding: 0.25rem 0.5rem;
    border-top: 1px solid var(--border);
}

.chat-input-row input { flex: 1; font-size: 0.75rem; padding: 0.25rem 0.5rem; }
.chat-input-row .btn { font-size: 0.65rem; padding: 0.25rem 0.4rem; }

/* --- Toast --- */

.toast-container {
    /* Bottom centre, just above the character panel (ui.js sets
       --toast-bottom from it), so toasts never cover the header's controls,
       the scenario strip or a battle's title. */
    position: fixed;
    left: 50%;
    bottom: var(--toast-bottom, 5rem);
    transform: translateX(-50%);
    z-index: 200;
    display: flex;
    flex-direction: column-reverse;
    align-items: center;
    gap: 0.5rem;
    width: max-content;
    max-width: calc(100vw - 2 * var(--gutter));
    pointer-events: none;
}

.toast {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 0.25rem 1rem rgb(0 0 0 / 0.35);
    padding: 0.5rem 1rem;
    font-size: 0.8rem;
    color: var(--text);
    text-align: center;
    pointer-events: none; /* a passing note: never in the way of a click */
    animation: toast-in 0.3s ease;
    max-width: min(26rem, calc(100vw - 2 * var(--gutter)));
}

/* Phones: only the newest, so a pile never covers the screen's buttons. */
@media (max-width: 768px) {
    .toast:not(:last-child) { display: none; }
}

.toast--error { border-color: var(--danger); color: var(--danger); }
.toast--success { border-color: var(--success); }

@keyframes toast-in {
    from { opacity: 0; transform: translateY(0.625rem); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ==========================================
   RESPONSIVE
   ========================================== */

@media (max-width: 768px) {
    .turn-banner-name { font-size: 1.5rem; }
    .turn-banner-character { font-size: 0.8rem; }
    .turn-banner-portrait { width: 3.75rem; height: 3.75rem; }

    .space-landing-name { font-size: 1rem; }
    .space-landing-inner { padding: 0.6rem 1.25rem; }

    .centre-prompt-btn {
        min-width: 10rem;
        padding: 0.75rem 2rem;
        font-size: 1.1rem;
    }

    .centre-prompt-btn--secondary {
        min-width: 8.125rem;
        padding: 0.6rem 1.5rem;
        font-size: 0.9rem;
    }

    /* Phones: one card nearly fills the width; more scroll sideways. */
    .card-reveal-content { --rv-w: min(17rem, 72cqw, calc((88cqh - 12rem) / var(--rv-ratio))); }
    .card-reveal-content:has(.reveal-card:nth-child(2)) { --rv-w: min(15rem, 60cqw, calc((88cqh - 12rem) / var(--rv-ratio))); }

    .log-panel {
        right: var(--gutter);
        bottom: 4.375rem;
        width: calc(100vw - var(--gutter) * 2);
        max-width: none;
    }

}

@media (max-width: 480px) {
    .lobby { padding-top: 5vh; }
    .title { font-size: 2rem; }
    .invite-code { font-size: 1.8rem; }


}

/* Short laptop screens: the drawn cards go by the screen's height, so the
   bigger UI size still fits the title, the cards and Continue. */
@media (min-width: 769px) and (max-height: 820px) {
    .card-reveal-content { max-height: calc(100% - 1rem); overflow-y: auto; }
}

/* ===== Demo mode (TALISMAN_DEMO=1 only; self-contained) ===== */

.demo-tools {
    position: absolute;
    left: var(--gutter);
    bottom: var(--gutter);
    z-index: 28;
    max-width: min(18.75rem, calc(100vw - 2 * var(--gutter)));
    background: var(--glass);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: 1px dashed var(--accent);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.8rem;
    cursor: default;
}
.demo-tools summary {
    padding: 0.35rem 0.6rem;
    cursor: pointer;
    color: var(--accent);
    font-weight: 600;
    user-select: none;
}
.demo-roll-status { color: var(--text-muted); font-weight: 400; margin-left: 0.3rem; }
.demo-tools-body {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    padding: 0 0.6rem 0.6rem;
}
.demo-row { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.demo-row--stack { flex-direction: column; align-items: stretch; gap: 0.25rem; }
.demo-row small { color: var(--text-muted); font-size: 0.7rem; }
.demo-inline { display: flex; gap: 0.4rem; align-items: center; }
.demo-inline select { flex: 1; min-width: 0; }
.demo-tools select {
    background: var(--bg-panel);
    color: var(--text);
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    padding: 0.25rem 0.35rem;
    font: inherit;
}
.demo-tools .btn-small { white-space: nowrap; }

/* ===== Rejoin and reconnect (reconnect.js) ===== */

.reconnect-pill {
    position: fixed;
    top: 0.75rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.35rem 0.9rem;
    border-radius: 999px;
    background: var(--glass);
    -webkit-backdrop-filter: var(--glass-blur);
    backdrop-filter: var(--glass-blur);
    border: 1px solid var(--border-light);
    color: var(--text);
    font-size: 0.85rem;
    pointer-events: none;
}

.reconnect-pill[hidden] {
    display: none;
}

.reconnect-dot {
    width: 0.55rem;
    height: 0.55rem;
    border-radius: 50%;
    background: var(--accent);
    animation: reconnect-pulse 1s ease-in-out infinite alternate;
}

@keyframes reconnect-pulse {
    from { opacity: 0.3; }
    to { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
    .reconnect-dot { animation: none; }
}

/* The rejoin pill is the landing page's (landing.css). */

/* ===== Pixel effects (pfx.js) ===== */

/* A canvas scaled up without smoothing. Over the battle and card overlays
   (50), under the choice overlay (57), turn banner, toasts and pill. */
.pfx {
    position: fixed;
    z-index: 56;
    margin: 0;
    padding: 0;
    border: 0;
    background: transparent;
    pointer-events: none;
    image-rendering: pixelated;
}

/* ===== Landing toast and tile card ===== */

/* The arriving tile card already shows the space's name and ring big, so
   the landing toast would only repeat it. */
.board-viewport:has(#tile-closeup:not([hidden]):not(.is-suppressed)) .space-landing {
    display: none;
}

/* Desktop: the centre prompt and the hint sit in the middle of the board
   left beside the card (--tc-room), so they never touch it, and a choice
   dialog moves left of the card, which comes up over the dialog's backdrop:
   the space's rules beside the question about them. */
@media (min-width: 769px) {
    .board-viewport:has(#tile-closeup:not([hidden]):not(.is-suppressed)) {
        --tc-room: calc(var(--tc-dock-w) + var(--gutter));
    }
    .board-viewport:has(#tile-closeup.is-arrival:not([hidden]):not(.is-suppressed)) {
        --tc-room: calc(var(--tc-arrive-w) + var(--gutter));
    }
    .board-viewport:has(#tile-closeup:not([hidden]):not(.is-suppressed)) .centre-prompt {
        left: calc((100% - var(--tc-room)) / 2);
    }
    body:has(#tile-closeup:not([hidden]):not(.is-suppressed)) .choice-overlay {
        padding-right: calc(var(--tc-dock-w) + 2 * var(--gutter));
    }
    body:has(#choice-overlay) #tile-closeup { z-index: 58; }
}

/* Desktop: the arriving card comes in at the middle of the board, the
   camera keeping the tile clear beside it, then slides to its dock on the
   right (--tc-c runs 1 → 0). The centre prompt and the hint wait while it's
   in the middle. */
@property --tc-c {
    syntax: '<number>';
    inherits: false;
    initial-value: 0;
}

@media (min-width: 769px) {
    #tile-closeup {
        --tc-c: 0;
        right: calc(var(--gutter) + var(--tc-c) * (50% - var(--tc-w) / 2 - var(--gutter)));
        transition: --tc-w 0.45s cubic-bezier(0.3, 0.7, 0.2, 1), --tc-c 0.45s cubic-bezier(0.3, 0.7, 0.2, 1),
            box-shadow 0.45s ease, border-color 0.45s ease;
    }
    #tile-closeup.is-arrival { --tc-c: 1; }
    .board-viewport:has(#tile-closeup.is-arrival:not([hidden]):not(.is-suppressed)) :is(.centre-prompt, .guide-hint) {
        visibility: hidden;
    }
}

/* A tile card inside an overlay (board.js buildTileCard): a space's own
   abilities asked on its card, or the space beside its drawn cards. */
.tile-closeup--inline {
    --tc-w: var(--tc-arrive-w);
    --tc-y: 0px;
    position: relative;
    top: auto;
    right: auto;
    max-width: 100%;
    max-height: 100%;
    transform: none;
    border-color: var(--accent);
    box-shadow: 0 1rem 3.5rem rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(0, 0, 0, 0.25), 0 0 3.5rem rgba(196, 164, 78, 0.35);
    animation: tile-inline-in 0.25s ease;
}

@keyframes tile-inline-in {
    from { opacity: 0; transform: scale(0.97); }
}

/* The space's own question: its card in the middle, the rules as buttons. */
.choice-overlay--tile .tile-closeup--inline { max-height: calc(100dvh - 2 * var(--gutter)); }
body:has(#choice-overlay.choice-overlay--tile) #tile-closeup { visibility: hidden; }
@media (min-width: 769px) {
    body:has(#tile-closeup:not([hidden]):not(.is-suppressed)) .choice-overlay.choice-overlay--tile { padding-right: var(--gutter); }
}

.tc-pick {
    display: block;
    width: 100%;
    margin: 0;
    font: inherit;
    color: inherit;
    text-align: left;
    cursor: pointer;
    transition: border-color 0.15s ease, background-color 0.15s ease, box-shadow 0.15s ease;
}

/* A single rule that is the space's one ability looks like an option too. */
.tc-pick:not(.tc-option) {
    padding: 0.6rem 0.75rem;
    background: var(--option-bg);
    border: 1px solid var(--option-edge);
    border-radius: var(--radius);
}

.tc-pick:hover:not(:disabled),
.tc-pick:focus-visible {
    border-color: var(--accent);
    background: var(--accent-dim);
    box-shadow: 0 0 0 1px var(--accent);
    outline: none;
}

.tc-pick:disabled { cursor: not-allowed; opacity: 0.55; }

.tc-pick-reason {
    display: block;
    margin-top: 0.4rem;
    font-size: 0.8rem;
    font-style: italic;
    color: var(--danger, #e07a7a);
}

.tc-actions {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 0.9rem;
}

.tc-actions .btn { width: 100%; }

/* Wide enough screens: drawn cards are dealt beside the space they came
   from (a copy of the tile card in the overlay; ui.js showCardReveal). */
.card-reveal-tile { display: none; }

@media (min-width: 1100px) {
    .card-reveal--tile {
        --tc-in-w: clamp(20rem, 26cqw, 27rem);
        gap: 2rem;
        padding: 1rem 2rem;
    }
    .card-reveal--tile .card-reveal-tile {
        --tc-w: var(--tc-in-w);
        display: flex;
        flex: none;
        max-height: 100%;
    }
    .card-reveal--tile .card-reveal-content {
        --rv-w: min(24rem, calc((100cqw - var(--tc-in-w) - 9rem) * 0.45), calc((92cqh - 10rem) / var(--rv-ratio)));
        flex: 0 1 auto;
        min-width: 0;
        max-width: calc(100cqw - var(--tc-in-w) - 6rem);
    }
    .card-reveal--tile .card-reveal-content:has(.reveal-card:nth-child(3)) { --rv-w: min(22rem, calc((100cqw - var(--tc-in-w) - 10rem) * 0.31), calc((92cqh - 10rem) / var(--rv-ratio))); }
    .card-reveal--tile .card-reveal-content:has(.reveal-card:nth-child(4)) { --rv-w: min(19rem, calc((100cqw - var(--tc-in-w) - 11rem) * 0.23), calc((92cqh - 10rem) / var(--rv-ratio))); }
    .board-viewport:has(#card-reveal.card-reveal--tile:not([hidden])) #tile-closeup { visibility: hidden; }
}

/* --- Choice prompts (web/js/choices.js) --- */

.choice-overlay {
    position: fixed;
    inset: 0;
    z-index: 57;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--gutter);
    animation: fade-in 0.2s ease;
}

.choice-backdrop {
    position: absolute;
    inset: 0;
    background: var(--overlay);
}

.choice-panel {
    position: relative;
    width: 100%;
    max-width: 32.5rem;
    max-height: calc(100dvh - 2 * var(--gutter));
    overflow-y: auto;
    overscroll-behavior: contain;
    background: var(--glass);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: 1px solid var(--accent);
    border-radius: var(--radius-lg);
    box-shadow: 0 0.75rem 2.5rem rgba(0, 0, 0, 0.5);
    padding: 1.1rem 1.1rem 1rem;
    color: var(--text);
}

.choice-panel--cards { max-width: 47.5rem; }

.choice-panel.is-sent { opacity: 0.6; }

.choice-title {
    font-size: 1rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--accent);
    text-align: center;
    margin: 0 0 0.6rem;
}

.choice-text {
    font-size: 0.85rem;
    line-height: 1.45;
    color: var(--text);
    margin: 0 0 0.75rem;
    text-align: center;
}

.choice-dice {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    margin-bottom: 0.6rem;
}

.choice-die {
    width: 2.6rem;
    height: 2.6rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--bg);
    background: var(--accent);
    border-radius: var(--radius);
    box-shadow: inset 0 -0.1875rem 0 rgba(0, 0, 0, 0.25);
}

.choice-die--six { background: var(--reach); }

.choice-rows {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
    margin: 0 0 0.8rem;
}

.choice-rows th,
.choice-rows td {
    padding: 0.35rem 0.5rem;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: top;
    color: var(--text-muted);
}

.choice-rows th {
    width: 4.5rem;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.choice-row--hit th,
.choice-row--hit td {
    color: var(--text);
    background: var(--accent-dim);
    font-weight: 600;
}

.choice-row--hit th { box-shadow: inset 0.1875rem 0 0 var(--accent); }

.choice-options {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
}

/* A new character after a death: a grid of portraits with their stats. */
.choice-options--characters {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr));
    max-height: 60vh;
    overflow-y: auto;
}
.choice-options--characters .choice-option { display: grid; grid-template-columns: 3rem 1fr; column-gap: 0.55rem; align-items: center; text-align: left; }
.choice-options--characters .choice-option > :not(.choice-portrait) { grid-column: 2; }
.choice-portrait { grid-row: 1 / span 3; width: 3rem; height: 3rem; border-radius: 0.3rem; object-fit: cover; }
.choice-portrait--random { display: grid; place-items: center; background: radial-gradient(circle at 50% 40%, #4b3a1c, #17120b 75%); color: #f2cf6c; font: 700 1.5rem/1 var(--font-display, serif); }

.choice-option {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    width: 100%;
    text-align: left;
    padding: 0.6rem 0.75rem;
    background: var(--bg-panel);
    color: var(--text);
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    font: inherit;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
}

.choice-option:hover:not(:disabled),
.choice-option:focus-visible,
.choice-card:hover:not(:disabled),
.choice-card:focus-visible {
    border-color: var(--accent);
    background: var(--bg-panel-hover);
    outline: none;
}

.choice-option:focus-visible,
.choice-card:focus-visible { box-shadow: 0 0 0 0.125rem var(--accent-dim); }

.choice-option.is-selected,
.choice-card.is-selected {
    border-color: var(--accent);
    background: var(--accent-dim);
    box-shadow: inset 0 0 0 1px var(--accent);
}

.choice-option:disabled,
.choice-card:disabled {
    cursor: not-allowed;
    opacity: 0.55;
}

.choice-option-label {
    font-weight: 600;
    font-size: 0.88rem;
}

.choice-option-detail {
    font-size: 0.75rem;
    line-height: 1.35;
    color: var(--text-muted);
}

.choice-option-reason {
    font-size: 0.72rem;
    color: var(--danger);
    font-style: italic;
}

.choice-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(9.375rem, 1fr));
    gap: 0.6rem;
}

.choice-card {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    padding: 0 0 0.5rem;
    background: var(--bg-panel);
    color: var(--text);
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    overflow: hidden;
    font: inherit;
    text-align: center;
    cursor: pointer;
    transition: transform 0.15s, border-color 0.15s;
}

.choice-card img {
    width: 100%;
    aspect-ratio: 5 / 7;
    object-fit: cover;
    display: block;
    background: var(--bg);
    margin-bottom: 0.3rem;
}

.choice-card .choice-option-label,
.choice-card .choice-option-detail,
.choice-card .choice-option-reason { padding: 0 0.45rem; }

.choice-card .choice-option-detail {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.choice-hint {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-align: center;
    margin: 0.7rem 0 0;
}

.choice-actions {
    display: flex;
    justify-content: center;
    gap: 0.6rem;
    margin-top: 0.8rem;
}

.choice-actions .btn {
    width: auto;
    min-width: 7.5rem;
}

.choice-waiting {
    position: fixed;
    top: 2.75rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 45;
    max-width: calc(100vw - 2 * var(--gutter));
    background: var(--glass);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: 1px solid var(--accent);
    border-radius: 1.25rem;
    padding: 0.3rem 1rem;
    font-size: 0.75rem;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

@media (max-width: 480px) {
    .choice-panel { padding: 0.9rem 0.75rem 0.8rem; }
    .choice-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .choice-option { padding: 0.55rem 0.65rem; }
}

/* Cards read for their text (missions, Power, Corruption): big enough to
   read, no caption repeating them; on phones a row to swipe through. */
.choice-cards--read {
    grid-template-columns: repeat(auto-fit, minmax(13.5rem, 17rem));
    justify-content: center;
}
.choice-cards--read .choice-card { padding: 0.45rem 0.45rem 0.55rem; }
.choice-cards--read .choice-card .rcard { margin-bottom: 0.35rem; }
.choice-card-badge {
    align-self: center;
    margin-top: -0.1rem;
    padding: 0.12rem 0.6rem;
    border-radius: 1rem;
    background: var(--accent);
    color: var(--bg);
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.03em;
}
@media (max-width: 480px) {
    .choice-cards.choice-cards--read {
        grid-template-columns: none;
        grid-auto-flow: column;
        grid-auto-columns: min(15rem, 78%);
        justify-content: start;
        overflow-x: auto;
        scroll-snap-type: x mandatory;
        overscroll-behavior-x: contain;
        padding-bottom: 0.3rem;
    }
    .choice-cards--read .choice-card { scroll-snap-align: center; }
}
