/* ═══════════════════════════════════════════════════════════
   RESET & BASE
═══════════════════════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

/* Player colours and their soft variants. Mirror COLOUR_HEX in
   js/constants.js — keep both in sync. */
:root {
    --red:         #e53935;
    --green:       #2e7d32;
    --blue:        #1565c0;
    --yellow:      #f9a825;
    --red-soft:    #ef9a9a;
    --green-soft:  #a5d6a7;
    --blue-soft:   #90caf9;
    --yellow-soft: #fff59d;
}

body {
    margin: 0;
    padding: 1rem 1rem 6rem;             /* bottom padding leaves room for FAB */
    min-height: 100vh;
    background: #f0ebe0;
    font-family: "Segoe UI", system-ui, sans-serif;
    display: flex;
    flex-direction: column;
    align-items: center;
    --player-current-colour: #888;       /* updated by renderUI() */
}

/* ═══════════════════════════════════════════════════════════
   TOP BUTTON ROW
═══════════════════════════════════════════════════════════ */
#top-bar {
    width: 80vmin;
    display: flex;
    gap: 0.6rem;
    margin-bottom: 0.75rem;
    justify-content: stretch;
}

.top-btn {
    flex: 1;
    padding: 0.55rem 0.9rem;
    font-size: 0.95rem;
    font-weight: 700;
    border: 0.15rem solid #888;
    border-radius: 0.55rem;
    background: white;
    color: #333;
    cursor: pointer;
    touch-action: manipulation;
    transition: background 0.15s, transform 0.1s;
}

.top-btn:hover { background: #eee; transform: scale(1.02); }
.top-btn:active { transform: scale(0.98); }

.top-btn-icon {
    flex: 0 0 auto;
    padding-left: 0.65rem;
    padding-right: 0.65rem;
    font-size: 1.1rem;
}

/* ═══════════════════════════════════════════════════════════
   APP LAYOUT
═══════════════════════════════════════════════════════════ */
#app {
    display: flex;
    align-items: flex-start;
    justify-content: center;
}

#board-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
}

/* ═══════════════════════════════════════════════════════════
   TURN / EVENT BANNER  (UX-01)
═══════════════════════════════════════════════════════════ */
#turn-banner {
    width: 80vmin;
    height: 2.6rem;
    padding: 0 0.9rem;
    border-radius: 0.6rem;
    background: var(--red);
    color: white;
    /* shrink gracefully on phones rather than truncating long extra-turn reasons */
    font-size: clamp(0.78rem, 2.6vw, 1rem);
    font-weight: 700;
    text-align: center;
    letter-spacing: 0.02em;
    transition: background 0.3s;
    white-space: nowrap;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0,0,0,0.18);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

/* ═══════════════════════════════════════════════════════════
   BOARD GRID
═══════════════════════════════════════════════════════════ */
#board {
    width: 80vmin;
    height: 80vmin;
    display: grid;
    grid-template-columns: 2fr 1fr 2fr;
    grid-template-rows: 2fr 1fr 2fr;
    box-shadow: 0 0 0 0.15vmin #333, 0 4px 20px rgba(0,0,0,0.18);
    border-radius: 0.3vmin;
    overflow: hidden;
}

#board > div {
    display: grid;
    align-items: center;
    justify-content: center;
    align-content: stretch;
    grid-auto-rows: 1fr;
    box-shadow: inset 0 0 0 0.1vmin #444;
}

/* grid-auto-rows: 1fr makes the sub-grid rows (in bases and north/south/west/east)
   distribute equally to fill the parent grid track — otherwise rows shrink to
   min-content height and leave empty space (body cream) at the bottom. */
.row1 { grid-template-columns: repeat(3, 1fr); }
.row2 { grid-template-columns: repeat(6, 1fr); }
.row3 { grid-template-columns: repeat(3, 1fr); }

.row1 > div,
.row2 > div,
.row3 > div {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 0.1vmin;
    box-shadow: inset 0 0 0 0.08vmin #555;
    height: 100%;
    width: 100%;
    overflow: hidden;
    touch-action: manipulation;          /* eliminates iOS ~300ms tap delay */
}

/* ═══════════════════════════════════════════════════════════
   HOME CENTRE
═══════════════════════════════════════════════════════════ */
#home {
    position: relative;
    display: block;
    height: 100% !important;
}

.triangle {
    position: absolute;
    top: 0; left: 0;
    width: 100%;
    height: 100% !important;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 0.2vmin;
    padding: 1.2vmin;
}

#red-home    { clip-path: polygon(0 0, 50% 50%, 0 100%);       background: var(--red); }
#green-home  { clip-path: polygon(0 0, 100% 0, 50% 50%);       background: var(--green); }
#blue-home   { clip-path: polygon(0 100%, 100% 100%, 50% 50%);  background: var(--blue); }
#yellow-home { clip-path: polygon(100% 0, 50% 50%, 100% 100%);  background: var(--yellow); }

#red-home    { justify-content: flex-start; padding: 2vmin 30% 2vmin 4%;  }
#green-home  { align-items: flex-start;     padding: 4% 2vmin 30% 2vmin;  }
#blue-home   { align-items: flex-end;       padding: 30% 2vmin 4%  2vmin; }
#yellow-home { justify-content: flex-end;   padding: 2vmin 4%  2vmin 30%; }

#red-home    .home-count { left: 17%; top: 50%;  }
#green-home  .home-count { top:  17%; left: 50%; }
#blue-home   .home-count { top:  83%; left: 50%; }
#yellow-home .home-count { left: 83%; top: 50%;  }

.done-token {
    font-size: 1.8vmin;
    line-height: 1;
    pointer-events: none;
    filter: drop-shadow(0 0 0.3vmin rgba(0,0,0,0.6));
}

.home-count {
    position: absolute;
    transform: translate(-50%, -50%);
    font-size: 2.2vmin;
    font-weight: 900;
    color: white;
    text-shadow: 0 0 0.5vmin rgba(0,0,0,0.7);
    pointer-events: none;
    line-height: 1;
    z-index: 2;
    white-space: nowrap;
}

/* ═══════════════════════════════════════════════════════════
   BASES
═══════════════════════════════════════════════════════════ */
#red-base    { background: var(--red-soft); }
#green-base  { background: var(--green-soft); }
#blue-base   { background: var(--blue-soft); }
#yellow-base { background: var(--yellow-soft); }

.base { grid-template-columns: repeat(6, 1fr); position: relative; }
.base > div { box-shadow: none; }

.base-inactive { opacity: 0.35; filter: grayscale(0.5); }

.base-not-playing-label {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5vmin;
    font-weight: 700;
    color: #555;
    pointer-events: none;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.token-base {
    background: white;
    box-shadow: inset 0 0 0 0.25vmin #333 !important;
    height: 5.2vmin !important;
    font-size: 2.3vmin;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 0.4vmin;
    transition: opacity 0.3s;
    touch-action: manipulation;
}

.token-base-vacated {
    background: #f0f0f0;
    opacity: 0.3;
}

/* Player name badge — pinned to the outward corner of each base.
   Selector is `.base > .base-name-badge` (specificity 0,2,0) so it beats the
   `.row1 > div` / `.row3 > div` baseline (0,1,1) that would otherwise force
   `width: 100%; height: 100%; display: flex` on the badge and stretch it
   across the whole base. */
.base > .base-name-badge {
    position: absolute;
    display: block;
    background: rgba(0, 0, 0, 0.62);
    color: #fff;
    font-size: 1.4vmin;
    font-weight: 700;
    padding: 0.25vmin 0.7vmin;
    border-radius: 0.35vmin;
    letter-spacing: 0.02em;
    pointer-events: none;
    width: max-content;
    max-width: 45%;
    height: auto;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    z-index: 5;
}
#red-base    .base-name-badge { top:    0.4vmin; left:  0.4vmin; }
#green-base  .base-name-badge { top:    0.4vmin; right: 0.4vmin; }
#blue-base   .base-name-badge { bottom: 0.4vmin; left:  0.4vmin; }
#yellow-base .base-name-badge { bottom: 0.4vmin; right: 0.4vmin; }

/* ═══════════════════════════════════════════════════════════
   PATH CELLS + HOME COLUMN CELLS
═══════════════════════════════════════════════════════════ */
div[id^="path-"],
div[id^="rh-"], div[id^="gh-"],
div[id^="bh-"], div[id^="yh-"] {
    min-height: 2.5vmin;
    min-width:  2.5vmin;
    position: relative;
    background: #fff;
}

div[id^="rh-"], div.red-start    { background: var(--red-soft); }
div[id^="gh-"], div.green-start  { background: var(--green-soft); }
div[id^="bh-"], div.blue-start   { background: var(--blue-soft); }
div[id^="yh-"], div.yellow-start { background: var(--yellow-soft); }

div[id^="path-"] span,
div[id^="rh-"] span, div[id^="gh-"] span,
div[id^="bh-"] span, div[id^="yh-"] span {
    font-size: 1.7vmin;
    line-height: 1;
    cursor: default;
    transition: transform 0.15s;
}

/* ── Stack count badge (×N for 2+ same-colour tokens on one cell) ── */
.cell-token {
    position: relative;
    display: inline-block;
    z-index: 1;             /* above the path-direction arrow */
}

.stack-badge {
    position: absolute;
    top: -0.5vmin;
    right: -1vmin;
    font-size: 1.05vmin !important;     /* override the 1.7vmin span rule above */
    font-weight: 800;
    color: white;
    background: rgba(0,0,0,0.78);
    padding: 0.05vmin 0.3vmin;
    border-radius: 0.6vmin;
    line-height: 1;
    pointer-events: none;
}

/* ── Home-count badge pop (a token just finished) ────────── */
@keyframes home-count-pop {
    0%   { transform: translate(-50%, -50%) scale(1);   }
    40%  { transform: translate(-50%, -50%) scale(1.6); }
    100% { transform: translate(-50%, -50%) scale(1);   }
}

.home-count-pop {
    animation: home-count-pop 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ── Home-column entry pulse (token first reaches home column) ── */
.home-entry-pulse {
    animation: home-entry-pulse 0.7s ease-out;
}

@keyframes home-entry-pulse {
    0%   { box-shadow: inset 0 0 0 0 transparent, 0 0 0 transparent;
           filter: brightness(1); }
    40%  { box-shadow: inset 0 0 0 0.45vmin rgba(255,255,255,0.95),
                       0 0 1vmin rgba(255,255,255,0.7);
           filter: brightness(1.5); }
    100% { box-shadow: inset 0 0 0 0 transparent, 0 0 0 transparent;
           filter: brightness(1); }
}

/* ── Capture floater (🎯 rises and fades from the capture cell) ── */
.capture-floater {
    position: absolute;
    top: 50%;
    left: 50%;
    font-size: 2.4vmin;
    pointer-events: none;
    z-index: 10;
    animation: capture-float 1s ease-out forwards;
}

@keyframes capture-float {
    0%   { transform: translate(-50%, -50%)  scale(0.6); opacity: 0; }
    15%  { transform: translate(-50%, -60%)  scale(1.5); opacity: 1; }
    70%  { transform: translate(-50%, -120%) scale(1.1); opacity: 1; }
    100% { transform: translate(-50%, -180%) scale(1.0); opacity: 0; }
}

/* ── Next-exit marker: subtle pulse on current player's exit cell ── */
.next-exit {
    animation: next-exit-pulse 1.8s ease-in-out infinite;
}

@keyframes next-exit-pulse {
    0%, 100% { box-shadow: inset 0 0 0 0.2vmin var(--player-current-colour, #888),
                            0 0 0.7vmin  var(--player-current-colour, #888); }
    50%      { box-shadow: inset 0 0 0 0.35vmin var(--player-current-colour, #888),
                            0 0 1.6vmin  var(--player-current-colour, #888); }
}

/* ── Same-colour stack on a non-safe cell: blocked for opponents ── */
.cell-blocked-red,
.cell-blocked-green,
.cell-blocked-yellow,
.cell-blocked-blue {
    /* outline doesn't fight the inset box-shadow baseline on row cells */
    outline-offset: -0.4vmin;
    outline-style: dashed;
    outline-width: 0.25vmin;
}

.cell-blocked-red    { outline-color: var(--red);    }
.cell-blocked-green  { outline-color: var(--green);  }
.cell-blocked-yellow { outline-color: var(--yellow); }
.cell-blocked-blue   { outline-color: var(--blue);   }

/* ═══════════════════════════════════════════════════════════
   ENTRY-DIRECTION ARROWS
   Only the cell after each start cell shows an arrow, tinted in
   the start cell's colour, hinting where tokens travel after
   leaving base.
═══════════════════════════════════════════════════════════ */
div[id^="path-"][data-arrow]::after {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    font-size: 1.6vmin;
    pointer-events: none;
    z-index: 0;
    line-height: 1;
}

div[id^="path-"][data-arrow="N"]::after { content: "▲"; }
div[id^="path-"][data-arrow="E"]::after { content: "▶"; }
div[id^="path-"][data-arrow="S"]::after { content: "▼"; }
div[id^="path-"][data-arrow="W"]::after { content: "◀"; }

div[data-arrow-colour="red"]::after    { color: var(--red);    }
div[data-arrow-colour="green"]::after  { color: var(--green);  }
div[data-arrow-colour="yellow"]::after { color: var(--yellow); }
div[data-arrow-colour="blue"]::after   { color: var(--blue);   }

/* ── Exit-cell line arrows (→ style, always visible, no animation) ── */
div[id^="path-"][data-exit-arrow]::after {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    font-size: 2vmin;
    font-weight: 700;
    pointer-events: none;
    z-index: 0;
    line-height: 1;
}

div[id^="path-"][data-exit-arrow="N"]::after { content: "↑"; }
div[id^="path-"][data-exit-arrow="E"]::after { content: "→"; }
div[id^="path-"][data-exit-arrow="S"]::after { content: "↓"; }
div[id^="path-"][data-exit-arrow="W"]::after { content: "←"; }

/* ── Cell-ID overlay (debug toggle inside Move Log modal) ── */
.cell-id-label {
    position: absolute;
    bottom: 0.05vmin;
    left: 0.1vmin;
    font-size: 0.95vmin;
    line-height: 1;
    font-weight: 600;
    color: rgba(0, 0, 0, 0.8);
    background: rgba(255, 255, 255, 0.85);
    padding: 0.05vmin 0.2vmin;
    border-radius: 0.2vmin;
    pointer-events: none;
    z-index: 4;
    white-space: nowrap;
}

/* ═══════════════════════════════════════════════════════════
   STAR / SAFE CELLS
═══════════════════════════════════════════════════════════ */
.star-cell { position: relative; overflow: hidden; }

.star-cell::before {
    content: "★";
    position: absolute;
    top: 50%; left: 50%;
    font-size: 2.2vmin;
    color: rgba(200, 160, 80, 0.55);
    transform: translate(-50%, -50%);
    pointer-events: none;
    z-index: 0;
}

.star-cell > * { position: relative; z-index: 1; }

/* ═══════════════════════════════════════════════════════════
   MOVABLE CELL HIGHLIGHT
   (Phase 2: per-cell, not per-token. Clicking the cell moves
    the topmost same-colour movable token on it.)
═══════════════════════════════════════════════════════════ */
.cell-movable {
    cursor: pointer !important;
    animation: cell-pulse 1s ease-in-out infinite;
    /* !important wins against `.rowN > div` baseline box-shadow */
    box-shadow: inset 0 0 0 0.35vmin var(--player-current-colour, #fff),
                0 0 1.2vmin var(--player-current-colour, #fff) !important;
    z-index: 3;
}

.token-base.cell-movable {
    cursor: pointer !important;
    animation: cell-pulse 1s ease-in-out infinite;
    box-shadow: inset 0 0 0 0.35vmin var(--player-current-colour, #fff),
                0 0 0.8vmin var(--player-current-colour, #fff) !important;
}

/* ── Keyboard-shortcut number overlay on movable cells ────── */
.cell-movable-num {
    position: absolute;
    top: 1px;
    right: 2px;
    font-size: clamp(7px, 1.1vmin, 10px);
    font-weight: 800;
    color: white;
    background: rgba(0,0,0,0.55);
    border-radius: 50%;
    width: 1.4vmin;
    height: 1.4vmin;
    min-width: 11px;
    min-height: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    z-index: 10;
    line-height: 1;
}

@keyframes cell-pulse {
    0%, 100% { filter: brightness(1);   }
    50%      { filter: brightness(1.25); }
}

@keyframes token-hop {
    0%   { transform: scale(1);    }
    40%  { transform: scale(1.5) translateY(-0.4vmin); }
    70%  { transform: scale(0.9);  }
    100% { transform: scale(1);    }
}

.token-hop {
    animation: token-hop 0.35s ease-out forwards;
}

/* ═══════════════════════════════════════════════════════════
   FLOATING DICE BUTTON (FAB)
═══════════════════════════════════════════════════════════ */
#dice-fab {
    position: fixed;
    right: clamp(12px, 4vw, 28px);
    bottom: clamp(12px, 4vh, 28px);
    width: 4.4rem;
    height: 4.4rem;
    padding: 0.45rem;
    border: 0.32rem solid var(--player-current-colour, #888);
    border-radius: 1rem;
    background: white;
    cursor: pointer;
    touch-action: manipulation;
    box-shadow: 0 6px 18px rgba(0,0,0,0.28);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.12s, opacity 0.2s, border-color 0.3s;
    z-index: 150;
}

#dice-fab:hover:not(:disabled) { transform: scale(1.06); }
#dice-fab:active:not(:disabled) { transform: scale(0.95); }

#dice-fab:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

/* ═══════════════════════════════════════════════════════════
   CSS DIE FACE
═══════════════════════════════════════════════════════════ */
#dice-face {
    width: 100%;
    height: 100%;
    background: white;
    border-radius: 0.45rem;
    box-shadow: inset 0 0 0 0.1rem #ccc;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    padding: 0.3rem;
    gap: 0.15rem;
    transition: transform 0.12s;
}

#dice-face[data-value="0"] {
    background: #f0f0f0;
    box-shadow: inset 0 0 0 0.1rem #ddd;
}

@keyframes die-land {
    0%   { transform: scale(1.3) rotate(-6deg); }
    55%  { transform: scale(0.92) rotate(2deg); }
    80%  { transform: scale(1.04); }
    100% { transform: scale(1) rotate(0deg); }
}

#dice-face.die-rolling {
    animation: die-land 0.38s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

.pip {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: #222;
}

/* ═══════════════════════════════════════════════════════════
   MODAL (shared)
═══════════════════════════════════════════════════════════ */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.55);
    backdrop-filter: blur(3px);
    align-items: center;
    justify-content: center;
    z-index: 250;
    padding: 1rem;
}

.modal.visible { display: flex; }

.modal-card {
    background: white;
    border-radius: 1rem;
    padding: clamp(1.1rem, 4vw, 1.8rem) clamp(1.1rem, 5vw, 2rem);
    box-shadow: 0 12px 40px rgba(0,0,0,0.3);
    width: min(28rem, 100%);
    max-height: calc(100vh - 2rem);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    animation: winner-pop 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal-title {
    margin: 0;
    font-size: 1.3rem;
    font-weight: 800;
    color: #222;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.modal-close {
    background: transparent;
    border: none;
    font-size: 1.1rem;
    cursor: pointer;
    color: #666;
    padding: 0.3rem 0.55rem;
    border-radius: 0.4rem;
    touch-action: manipulation;
}

.modal-close:hover { background: #eee; color: #222; }

.modal-section {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
}

.modal-section-label {
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #777;
}

.modal-primary {
    margin-top: 0.4rem;
    padding: 0.7rem 1.4rem;
    font-size: 1rem;
    font-weight: 700;
    border: none;
    border-radius: 0.65rem;
    background: #222;
    color: white;
    cursor: pointer;
    touch-action: manipulation;
    transition: background 0.15s, transform 0.1s;
}

.modal-primary:hover { background: #444; transform: scale(1.02); }

.modal-secondary {
    padding: 0.7rem 1.4rem;
    font-size: 1rem;
    font-weight: 700;
    border: 0.15rem solid #888;
    border-radius: 0.65rem;
    background: white;
    color: #333;
    cursor: pointer;
    touch-action: manipulation;
    transition: background 0.15s, transform 0.1s;
}

.modal-secondary:hover { background: #eee; }

.modal-body {
    margin: 0;
    color: #555;
    font-size: 0.92rem;
    line-height: 1.4;
}

.modal-actions {
    display: flex;
    gap: 0.6rem;
    flex-wrap: wrap;
}

.modal-actions > button { flex: 1; }

/* ── Segmented control (player count, role rows) ──────────── */
.segmented {
    display: flex;
    background: #f1f1f1;
    border-radius: 0.55rem;
    padding: 0.18rem;
    gap: 0.15rem;
}

.segmented label {
    flex: 1;
    cursor: pointer;
    touch-action: manipulation;
}

.segmented label input { display: none; }

.segmented label span {
    display: block;
    text-align: center;
    padding: 0.45rem 0.5rem;
    font-size: 0.9rem;
    font-weight: 600;
    color: #555;
    border-radius: 0.4rem;
    transition: background 0.12s, color 0.12s;
}

.segmented label input:checked + span {
    background: white;
    color: #111;
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

/* ── Role row (one per active colour in setup modal) ─────── */
.role-row {
    display: flex;
    align-items: center;
    gap: 0.7rem;
}

.role-row .role-label {
    flex: 0 0 5.5rem;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.92rem;
    font-weight: 600;
}

.role-row .role-label::before {
    content: "";
    width: 0.9rem;
    height: 0.9rem;
    border-radius: 50%;
    background: var(--swatch, #888);
    box-shadow: inset 0 0 0 0.1rem rgba(0,0,0,0.2);
}

.role-row .segmented { flex: 1; }

.toggle-row {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    font-size: 0.9rem;
    color: #333;
    cursor: pointer;
    touch-action: manipulation;
}

.toggle-row input {
    width: 1.05rem;
    height: 1.05rem;
    cursor: pointer;
}

/* ── Move log inside modal ────────────────────────────────── */
#log-modal #move-log {
    list-style: none;
    margin: 0;
    padding: 0;
    max-height: 50vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    scrollbar-width: thin;
}

#log-modal #move-log:empty::before {
    content: "No moves yet — start playing!";
    color: #aaa;
    font-style: italic;
    font-size: 0.85rem;
    padding: 0.6rem 0.2rem;
}

#move-log li {
    font-size: 0.85rem;
    color: #333;
    padding: 0.32rem 0.55rem;
    border-left: 3px solid currentColor;
    background: #f9f9f9;
    border-radius: 0 0.3rem 0.3rem 0;
    line-height: 1.35;
    animation: log-slide-in 0.2s ease-out;
}

@keyframes log-slide-in {
    from { opacity: 0; transform: translateX(-6px); }
    to   { opacity: 1; transform: translateX(0);    }
}

/* ═══════════════════════════════════════════════════════════
   WINNER OVERLAY
═══════════════════════════════════════════════════════════ */
#winner-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    align-items: center;
    justify-content: center;
    z-index: 200;
    backdrop-filter: blur(3px);
    padding: 1rem;
}

#winner-overlay.visible { display: flex; }

#winner-card {
    background: white;
    border-radius: 1.3rem;
    padding: clamp(1rem, 5vw, 2.5rem) clamp(1.25rem, 6vw, 3rem);
    text-align: center;
    border: 4px solid transparent;
    box-shadow: 0 12px 40px rgba(0,0,0,0.3);
    display: flex;
    flex-direction: column;
    gap: 1.2rem;
    align-items: center;
    animation: winner-pop 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
    transition: border-color 0.2s, box-shadow 0.2s;
    max-width: min(24rem, 100%);
}

@keyframes winner-pop {
    from { transform: scale(0.7); opacity: 0; }
    to   { transform: scale(1);   opacity: 1; }
}

#winner-message {
    font-size: clamp(1.5rem, 5vw, 2.2rem);
    font-weight: 800;
    letter-spacing: -0.02em;
}

#play-again-btn {
    padding: 0.65rem 2.2rem;
    font-size: 1rem;
    font-weight: 700;
    border: none;
    border-radius: 0.7rem;
    background: #222;
    color: white;
    cursor: pointer;
    touch-action: manipulation;
    transition: background 0.15s, transform 0.1s;
}

#play-again-btn:hover {
    background: #444;
    transform: scale(1.05);
}

/* ═══════════════════════════════════════════════════════════
   RESPONSIVE
═══════════════════════════════════════════════════════════ */
@media (max-width: 900px) {
    /* Remove horizontal padding so children can reach the screen edges. */
    body { padding-left: 0; padding-right: 0; }

    /* Propagate full-width through every layer of the layout chain.
       Without this, #app stays content-sized and #board overflows off-centre. */
    #top-bar      { width: 100%; padding: 0 0.5rem; box-sizing: border-box; }
    #app          { width: 100%; }
    #board-section { width: 100%; }

    /* Square board that fills the viewport edge-to-edge.
       Rows have no explicit height, so align-self:stretch fills each
       grid track — no gaps regardless of board size. */
    #board        { width: 100%; height: 100vw; }

    /* Full-width banner with flush corners. */
    #turn-banner  { width: 100%; border-radius: 0; }

    /* Token slots scaled to the wider cells (100vw ÷ 15 tracks × 0.975). */
    .token-base   { height: 6.5vw !important; }
}

/* ── Rules modal body ────────────────────────────────────── */
.rules-body {
    max-height: 60vh;
    overflow-y: auto;
    font-size: 0.9rem;
    line-height: 1.55;
    color: #333;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    scrollbar-width: thin;
}

.rules-body h3 {
    margin: 0.7rem 0 0.1rem;
    font-size: 0.82rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: #777;
}

.rules-body h3:first-child { margin-top: 0; }

.rules-body p {
    margin: 0;
}

/* ── Setup error message ─────────────────────────────────── */
.setup-error {
    margin: 0;
    font-size: 0.82rem;
    color: #c62828;
    font-weight: 600;
}

/* ═══════════════════════════════════════════════════════════
   TURN TIMER DISPLAY
═══════════════════════════════════════════════════════════ */
#turn-timer-display {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: clamp(1.4rem, 5vmin, 2.2rem);
    font-weight: 800;
    color: #333;
    background: rgba(255,255,255,0.88);
    border-radius: 50%;
    width: clamp(2.5rem, 8vmin, 3.5rem);
    height: clamp(2.5rem, 8vmin, 3.5rem);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    pointer-events: none;
    z-index: 20;
}

#turn-timer-display.timer-urgent {
    color: #c62828;
    animation: timer-pulse 0.5s ease-in-out infinite alternate;
}

@keyframes timer-pulse {
    from { transform: translate(-50%, -50%) scale(1);    }
    to   { transform: translate(-50%, -50%) scale(1.15); }
}

/* ═══════════════════════════════════════════════════════════
   PLACEMENT BADGE (shown on finished player's base)
═══════════════════════════════════════════════════════════ */
.placement-badge {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: clamp(1.8rem, 6vmin, 3rem);
    pointer-events: none;
    z-index: 10;
    animation: winner-pop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.3));
}

/* ═══════════════════════════════════════════════════════════
   WINNER RANKING LIST
═══════════════════════════════════════════════════════════ */
#winner-ranking {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    width: 100%;
}

#winner-ranking li {
    font-size: 1.05rem;
    font-weight: 700;
    padding: 0.4rem 0.8rem;
    border-radius: 0.5rem;
    background: rgba(0,0,0,0.04);
    text-align: left;
}

/* ═══════════════════════════════════════════════════════════
   ONLINE TOAST + SPECTATING BANNER
═══════════════════════════════════════════════════════════ */
.online-toast {
    position: fixed;
    top: 0.6rem;
    left: 50%;
    transform: translateX(-50%);
    background: #b71c1c;
    color: #fff;
    font-size: 0.95rem;
    font-weight: 600;
    padding: 0.5rem 1rem;
    border-radius: 0.4rem;
    box-shadow: 0 4px 14px rgba(0,0,0,0.25);
    z-index: 500;
    max-width: 92vw;
    pointer-events: none;
    animation: toast-slide 0.25s ease-out;
}

@keyframes toast-slide {
    from { opacity: 0; transform: translate(-50%, -120%); }
    to   { opacity: 1; transform: translate(-50%, 0); }
}

.online-spectating-banner {
    position: fixed;
    top: 0.6rem;
    left: 50%;
    transform: translateX(-50%);
    background: #6a1b9a;
    color: #fff;
    font-size: 0.85rem;
    font-weight: 700;
    padding: 0.3rem 0.8rem;
    border-radius: 1rem;
    letter-spacing: 0.08em;
    z-index: 240;
    pointer-events: none;
}

/* ═══════════════════════════════════════════════════════════
   LOBBY/WAITING-ROOM ROWS (inside Setup → Online pane)
═══════════════════════════════════════════════════════════ */
.lobby-player-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.6rem;
    border-left: 4px solid var(--swatch, #ccc);
    background: #f7f7f7;
    border-radius: 0.3rem;
    margin-bottom: 0.3rem;
    font-size: 0.95rem;
}
.lobby-slot-row {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-size: 0.9rem;
    padding: 0.2rem 0;
}
.lobby-slot-row label { display: inline-flex; gap: 0.25rem; align-items: center; }
