/*
 * Cascade — app shell styles.
 *
 * Every other module renders into a slot this file lays out (#sidebar,
 * #grid-host, #dock, #hud, #statusbar, #modal-root) and reads its colors and
 * spacing off the custom properties defined here, never a hard-coded hex. That
 * is what lets `[data-theme="light"]` repaint the whole app in one place and
 * what keeps grid.js's cell-state classes (bold/highlight/card/kicked/color-*)
 * looking right regardless of theme.
 *
 * Dark is the default because a debate round happens in a dim classroom or a
 * hotel ballroom at a tournament, not a design studio — a white grid at 2am
 * before an out-round is a real complaint from a real coach. The brand voice
 * carries over from debate101.org: navy + a single confident blue, Inter for
 * UI, Playfair Display reserved for the wordmark, uppercase tracked labels,
 * hairline rules instead of heavy borders. What's different here is density:
 * this is a working tool, not a marketing page, so whitespace is a resource
 * we spend on legibility (the grid), not on air.
 */

/* ---------------------------------------------------------------------- */
/* Reset                                                                   */
/* ---------------------------------------------------------------------- */

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

html, body {
    height: 100%;
}

body {
    margin: 0;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

ul, ol {
    margin: 0;
    padding: 0;
    list-style: none;
}

fieldset {
    margin: 0;
    padding: 0;
    border: 0;
}

button, input, textarea, select {
    font: inherit;
    color: inherit;
}

button {
    background: none;
    border: 0;
    cursor: pointer;
}

img {
    display: block;
    max-width: 100%;
}

a {
    color: inherit;
}

/* ---------------------------------------------------------------------- */
/* Design tokens                                                          */
/* ---------------------------------------------------------------------- */

:root {
    /* Brand — matches debate101.org exactly; never redefine these per-theme. */
    --d1-navy: #051c2c;
    --d1-accent: #0072b1;
    --d1-accent-2: #38bdf8;

    /* Debate semantics — used for sides, cards, and the five highlight colors. */
    --aff: #10b981;
    --neg: #f43f5e;
    --card: #fbbf24;
    --aff-tint: rgba(16, 185, 129, 0.12);
    --neg-tint: rgba(244, 63, 94, 0.12);
    --aff-tint-strong: rgba(16, 185, 129, 0.22);
    --neg-tint-strong: rgba(244, 63, 94, 0.22);

    --color-amber: #f59e0b;
    --color-rose: #fb7185;
    --color-sky: #38bdf8;
    --color-lime: #a3e635;
    --color-violet: #a78bfa;

    /* Surfaces — dark theme (default). Numbered by elevation, low to high. */
    --bg-0: #04121f;
    --bg-1: #071a2b;
    --bg-2: #0c2438;
    --bg-3: #123047;
    --bg-4: #183c58;
    --border: rgba(230, 240, 250, 0.09);
    --border-strong: rgba(230, 240, 250, 0.18);
    --overlay-scrim: rgba(2, 8, 14, 0.72);

    --text-0: #f3f7fb;
    --text-1: #b7c8d6;
    --text-2: #7e93a6;
    --text-3: #4a6178;

    /* Status colors, theme-stable. */
    --info: var(--d1-accent-2);
    --success: var(--aff);
    --warn: var(--color-amber);
    --danger: var(--neg);

    /* Type. */
    --font-ui: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
    --font-serif: "Playfair Display", Georgia, "Times New Roman", serif;
    --font-mono: ui-monospace, "SF Mono", "Cascadia Mono", "JetBrains Mono", Menlo, Consolas, monospace;

    /* Scale. */
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 24px;
    --space-6: 32px;

    --radius-sm: 3px;
    --radius-md: 6px;
    --radius-lg: 10px;

    /* Chrome dimensions — read by JS for layout math, so keep names stable. */
    --topbar-h: 48px;
    --statusbar-h: 26px;
    --sidebar-w: 224px;
    --dock-w: 340px;
    --dock-min-w: 240px;
    --dock-max-w: 640px;

    --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-2: 0 8px 24px rgba(0, 0, 0, 0.35);
    --shadow-3: 0 16px 48px rgba(0, 0, 0, 0.45);

    --dur-fast: 110ms;
    --dur-med: 190ms;
    --dur-slow: 320ms;
    --ease: cubic-bezier(0.4, 0, 0.2, 1);
    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);

    --focus-ring: 0 0 0 2px var(--bg-0), 0 0 0 4px var(--d1-accent-2);

    color-scheme: dark;
}

[data-theme="light"] {
    --bg-0: #f4f7fa;
    --bg-1: #ffffff;
    --bg-2: #ffffff;
    --bg-3: #edf2f6;
    --bg-4: #e2e9ef;
    --border: rgba(5, 28, 44, 0.1);
    --border-strong: rgba(5, 28, 44, 0.22);
    --overlay-scrim: rgba(5, 15, 24, 0.4);

    --text-0: #0b1e2d;
    --text-1: #3d4f5f;
    --text-2: #6b7c8b;
    --text-3: #94a3b1;

    --aff-tint: rgba(16, 185, 129, 0.09);
    --neg-tint: rgba(244, 63, 94, 0.09);
    --aff-tint-strong: rgba(16, 185, 129, 0.16);
    --neg-tint-strong: rgba(244, 63, 94, 0.16);

    --shadow-1: 0 1px 2px rgba(5, 28, 44, 0.06);
    --shadow-2: 0 8px 24px rgba(5, 28, 44, 0.08);
    --shadow-3: 0 16px 48px rgba(5, 28, 44, 0.14);

    --focus-ring: 0 0 0 2px var(--bg-0), 0 0 0 4px var(--d1-accent);

    color-scheme: light;
}

/* First-run theme (before JS applies a stored/system preference) follows the
   OS so the flash-of-wrong-theme window is as short as possible. */
@media (prefers-color-scheme: light) {
    :root:not([data-theme]) {
        color-scheme: light;
    }
}

body {
    background: var(--bg-0);
    color: var(--text-0);
    font-family: var(--font-ui);
    font-size: 13px;
    line-height: 1.45;
}

/* ---------------------------------------------------------------------- */
/* Focus, selection, scrollbars                                           */
/* ---------------------------------------------------------------------- */

:focus {
    outline: none;
}

:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
    border-radius: var(--radius-sm);
}

::selection {
    background: var(--d1-accent);
    color: #fff;
}

* {
    scrollbar-width: thin;
    scrollbar-color: var(--border-strong) transparent;
}

::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border-radius: 8px;
    border: 2px solid transparent;
    background-clip: padding-box;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-3);
    background-clip: padding-box;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

kbd {
    font-family: var(--font-mono);
    font-size: 10px;
    padding: 1px 5px;
    border: 1px solid var(--border-strong);
    border-bottom-width: 2px;
    border-radius: 4px;
    background: var(--bg-3);
    color: var(--text-1);
}

/* ---------------------------------------------------------------------- */
/* App shell layout                                                       */
/* ---------------------------------------------------------------------- */

#app {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#topbar {
    flex: 0 0 var(--topbar-h);
    display: flex;
    align-items: stretch;
    justify-content: space-between;
    gap: var(--space-3);
    padding: 0 var(--space-3);
    background: var(--bg-2);
    border-bottom: 1px solid var(--border);
    -webkit-app-region: drag;
}

#topbar button, #topbar a, #topbar input {
    -webkit-app-region: no-drag;
}

#topbar .slot-left, #topbar .slot-center, #topbar .slot-right {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    min-width: 0;
}

#topbar .slot-center {
    flex: 1 1 auto;
    justify-content: center;
    overflow: hidden;
}

#workspace {
    flex: 1 1 auto;
    display: flex;
    min-height: 0;
    position: relative;
}

#statusbar {
    flex: 0 0 var(--statusbar-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--space-3);
    background: var(--bg-2);
    border-top: 1px solid var(--border);
    font-family: var(--font-mono);
    font-size: 10.5px;
    color: var(--text-2);
}

/* ---------------------------------------------------------------------- */
/* Brand + topbar chrome                                                  */
/* ---------------------------------------------------------------------- */

.brand-link {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: 0 var(--space-2) 0 0;
    text-decoration: none;
    color: var(--text-0);
    opacity: 0.92;
    transition: opacity var(--dur-fast) var(--ease);
}

.brand-link:hover {
    opacity: 1;
}

.brand-mark {
    width: 20px;
    height: 20px;
    border-radius: 4px;
    object-fit: cover;
}

.brand-word {
    font-family: var(--font-serif);
    font-weight: 700;
    font-size: 15px;
    letter-spacing: 0.01em;
}

.topbar-title {
    display: flex;
    align-items: baseline;
    gap: var(--space-2);
    min-width: 0;
    font-size: 12px;
}

.topbar-round-name {
    font-weight: 600;
    color: var(--text-0);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 42vw;
    cursor: text;
    border-radius: var(--radius-sm);
    padding: 1px 4px;
    margin: -1px -4px;
}

.topbar-round-name:hover {
    background: var(--bg-3);
}

.topbar-round-name-input {
    font: inherit;
    font-weight: 600;
    color: var(--text-0);
    background: var(--bg-2);
    border: 1px solid var(--d1-accent);
    border-radius: var(--radius-sm);
    padding: 1px 6px;
    max-width: 42vw;
    min-width: 8rem;
}

.topbar-round-meta {
    color: var(--text-2);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-size: 10px;
    white-space: nowrap;
}

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: var(--radius-sm);
    color: var(--text-1);
    transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}

.icon-btn svg {
    width: 15px;
    height: 15px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.4;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.icon-btn:hover {
    background: var(--bg-3);
    color: var(--text-0);
}

.icon-btn[aria-pressed="false"] {
    color: var(--text-2);
}

.icon-btn.is-active,
.icon-btn[aria-pressed="true"] {
    color: var(--d1-accent-2);
}

/* Theme toggle: the sun/moon swap by data-theme, not by JS class juggling. */
.icon-moon { display: none; }
[data-theme="light"] .icon-sun { display: none; }
[data-theme="light"] .icon-moon { display: block; }

.toolbar-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 28px;
    padding: 0 var(--space-2);
    border-radius: var(--radius-sm);
    font-size: 11.5px;
    font-weight: 600;
    color: var(--text-1);
    white-space: nowrap;
    transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}

.toolbar-btn:hover:not(:disabled) {
    background: var(--bg-3);
    color: var(--text-0);
}

.toolbar-btn.is-active {
    background: var(--aff-tint-strong);
    color: var(--d1-accent-2);
}

.toolbar-btn:disabled {
    opacity: 0.4;
    cursor: default;
}

.toolbar-btn .tb-icon {
    font-size: 13px;
    line-height: 1;
}

/* ---------------------------------------------------------------------- */
/* Sidebar shell + sheets.js hooks                                        */
/* ---------------------------------------------------------------------- */

#sidebar {
    flex: 0 0 var(--sidebar-w);
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--bg-1);
    border-right: 1px solid var(--border);
    overflow: hidden;
    transition: flex-basis var(--dur-med) var(--ease), opacity var(--dur-med) var(--ease);
}

#sidebar.is-collapsed {
    flex-basis: 0;
    width: 0;
    opacity: 0;
    pointer-events: none;
    border-right-color: transparent;
}

.sheets-panel {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
}

.sheets-header {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-3) var(--space-3) var(--space-2);
    border-bottom: 1px solid var(--border);
}

.sheets-header-title {
    font-size: 10px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-2);
}

.sheets-header-actions {
    display: flex;
    gap: 4px;
}

.btn-sheet-add {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    line-height: 1;
    font-weight: 700;
    color: var(--bg-0);
    transition: filter var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}

.btn-sheet-add:hover {
    filter: brightness(1.12);
}

.btn-sheet-add:active {
    transform: scale(0.94);
}

#sheet-new-aff { background: var(--aff); }
#sheet-new-neg { background: var(--neg); }

.sheets-list {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: var(--space-2) 0 var(--space-5);
}

.sheets-group + .sheets-group {
    margin-top: var(--space-2);
}

.sheets-group-label {
    padding: var(--space-2) var(--space-3) 4px;
    font-size: 9.5px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--text-3);
}

.sheets-empty {
    padding: var(--space-3);
    font-size: 11.5px;
    color: var(--text-2);
}

.sheet-row {
    position: relative;
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: 6px var(--space-3) 6px var(--space-2);
    cursor: default;
    user-select: none;
    border-left: 2px solid transparent;
    transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}

.sheet-row:hover {
    background: var(--bg-2);
}

.sheet-row.is-selected {
    background: var(--bg-3);
}

.sheet-row.is-active {
    background: var(--bg-3);
    border-left-color: var(--d1-accent-2);
}

.sheet-row.is-dragging {
    opacity: 0.45;
}

.sheet-row.is-drop-target::before {
    content: "";
    position: absolute;
    left: var(--space-2);
    right: var(--space-2);
    top: -1px;
    height: 2px;
    background: var(--d1-accent-2);
    border-radius: 2px;
}

.sheet-color-bar {
    flex: 0 0 4px;
    align-self: stretch;
    border-radius: 2px;
    background: var(--text-3);
}

.sheet-row[data-side="aff"] .sheet-color-bar { background: var(--aff); }
.sheet-row[data-side="neg"] .sheet-color-bar { background: var(--neg); }
.sheet-row[data-side="cx"] .sheet-color-bar { background: var(--card); }

.sheet-title {
    flex: 1 1 auto;
    min-width: 0;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-0);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sheet-row.is-active .sheet-title {
    font-weight: 700;
}

.sheet-title-input {
    flex: 1 1 auto;
    min-width: 0;
    background: var(--bg-0);
    border: 1px solid var(--d1-accent);
    border-radius: var(--radius-sm);
    padding: 2px 5px;
    font-size: 12px;
    color: var(--text-0);
}

.sheet-rowcount {
    flex: 0 0 auto;
    font-family: var(--font-mono);
    font-size: 9.5px;
    color: var(--text-3);
}

/* ---------------------------------------------------------------------- */
/* Grid host + flow table vocabulary (grid.js renders into #grid-host)    */
/* ---------------------------------------------------------------------- */

#grid-host {
    flex: 1 1 auto;
    min-width: 0;
    position: relative;
    overflow: auto;
    background:
        linear-gradient(var(--bg-0), var(--bg-0)) padding-box,
        repeating-linear-gradient(90deg, transparent 0, transparent 159px, var(--border) 159px, var(--border) 160px);
}

.flow-grid {
    border-collapse: separate;
    border-spacing: 0;
    font-family: var(--font-mono);
    font-size: 12px;
    line-height: 1.5;
    min-width: 100%;
}

.flow-grid thead th {
    position: sticky;
    top: 0;
    z-index: 3;
    background: var(--bg-2);
    border-bottom: 1px solid var(--border-strong);
    border-right: 1px solid var(--border);
    padding: 6px 10px;
    text-align: left;
    font-weight: 700;
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    white-space: nowrap;
}

.flow-grid th.col-aff { box-shadow: inset 0 -2px 0 var(--aff); color: var(--aff); }
.flow-grid th.col-neg { box-shadow: inset 0 -2px 0 var(--neg); color: var(--neg); }
.flow-grid th.col-live {
    border-right-color: var(--d1-accent-2);
    box-shadow: inset 0 -2px 0 var(--d1-accent-2), 2px 0 0 var(--d1-accent-2);
}

.flow-grid td {
    border-right: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    padding: 4px 10px;
    vertical-align: top;
    white-space: pre-wrap;
    word-break: break-word;
    color: var(--text-0);
}

.flow-grid td.col-aff { background: var(--aff-tint); }
.flow-grid td.col-neg { background: var(--neg-tint); }

.flow-grid td.is-selected {
    box-shadow: inset 0 0 0 1.5px var(--d1-accent-2);
    background: var(--bg-3);
}

.flow-grid tr.cell-kicked td,
.flow-grid td.cell-kicked {
    text-decoration: line-through;
    opacity: 0.5;
}

.flow-grid .cell-bold { font-weight: 700; }
.flow-grid .cell-highlight { background: rgba(251, 191, 36, 0.16); }
.flow-grid .cell-card { box-shadow: inset 3px 0 0 var(--card); padding-left: 8px; }
.flow-grid .cell-group { box-shadow: inset 0 0 0 1px var(--border-strong); }
.flow-grid .cell-star::after { content: "\2605"; margin-left: 5px; color: var(--card); font-size: 10px; }
.flow-grid .cell-flagged::before { content: "\25B2"; margin-right: 5px; color: var(--danger); font-size: 8px; }
.flow-grid .cell-answered { opacity: 0.72; }
.flow-grid .cell-voter { box-shadow: inset 3px 0 0 var(--d1-accent-2); }

.flow-grid .cell-color-amber { background: rgba(245, 158, 11, 0.16); }
.flow-grid .cell-color-rose { background: rgba(251, 113, 133, 0.16); }
.flow-grid .cell-color-sky { background: rgba(56, 189, 248, 0.16); }
.flow-grid .cell-color-lime { background: rgba(163, 230, 53, 0.16); }
.flow-grid .cell-color-violet { background: rgba(167, 139, 250, 0.16); }

.grid-empty {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-2);
    font-size: 12.5px;
    text-align: center;
    padding: var(--space-5);
}

/* ---------------------------------------------------------------------- */
/* HUD — floating overlay pinned above the grid                           */
/* ---------------------------------------------------------------------- */

/* Pinned to the bottom of the window rather than the top of the grid: at the
   top it sat directly over the speech column headers, which are the one thing
   a debater has to be able to read while the clock is running. The bottom of a
   sheet is empty for most of a round, and timers.js makes the panel draggable
   for the rest of it. */
#hud {
    position: fixed;
    left: 0;
    right: 0;
    bottom: calc(var(--statusbar-h, 26px) + var(--space-3));
    z-index: 10;
    display: flex;
    justify-content: center;
    pointer-events: none;
}

#hud:empty {
    display: none;
}

#hud > * {
    pointer-events: auto;
}

.hud-panel {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    padding: 6px var(--space-4);
    background: var(--bg-2);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-2);
    font-family: var(--font-mono);
    backdrop-filter: blur(6px);
}

/* ---------------------------------------------------------------------- */
/* Dock — panel host                                                      */
/* ---------------------------------------------------------------------- */

#dock {
    position: relative;
    flex: 0 0 var(--dock-w, 340px);
    width: var(--dock-w, 340px);
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--bg-1);
    border-left: 1px solid var(--border);
    transition: flex-basis var(--dur-med) var(--ease), width var(--dur-med) var(--ease), opacity var(--dur-med) var(--ease);
}

#dock.is-collapsed {
    flex-basis: 0 !important;
    width: 0 !important;
    opacity: 0;
    pointer-events: none;
    border-left-color: transparent;
}

#dock-resizer {
    position: absolute;
    left: -3px;
    top: 0;
    bottom: 0;
    width: 6px;
    cursor: col-resize;
    z-index: 6;
}

#dock-resizer:hover, #dock-resizer.is-dragging {
    background: var(--d1-accent-2);
    opacity: 0.35;
}

#dock-tabs {
    flex: 0 0 auto;
    display: flex;
    overflow-x: auto;
    border-bottom: 1px solid var(--border);
    background: var(--bg-2);
}

.dock-tab {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    flex: 0 0 auto;
    padding: 8px var(--space-3) 7px;
    font-size: 10.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-2);
    border-bottom: 2px solid transparent;
    transition: color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}

.dock-tab:hover {
    color: var(--text-0);
}

.dock-tab[aria-selected="true"] {
    color: var(--d1-accent-2);
    border-bottom-color: var(--d1-accent-2);
}

.dock-tab-icon {
    font-size: 12px;
    line-height: 1;
}

.dock-tab-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 15px;
    height: 15px;
    padding: 0 4px;
    border-radius: 8px;
    background: var(--danger);
    color: #fff;
    font-size: 9px;
    font-weight: 800;
}

.dock-tab-badge:empty, .dock-tab-badge[hidden] {
    display: none;
}

#dock-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
    position: relative;
}

.dock-panel {
    height: 100%;
    padding: var(--space-3);
}

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

.dock-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-2);
    font-size: 11.5px;
    text-align: center;
    padding: var(--space-4);
}

/* ---------------------------------------------------------------------- */
/* Status bar segments                                                    */
/* ---------------------------------------------------------------------- */

.status-left, .status-right {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    min-width: 0;
}

.status-brand {
    font-weight: 700;
    color: var(--text-1);
}

.status-sep {
    color: var(--border-strong);
}

.status-hint kbd {
    font-size: 9px;
    padding: 0 4px;
}

.status-segment {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
}

.status-segment + .status-segment::before {
    content: "";
    display: inline-block;
    width: 1px;
    height: 11px;
    background: var(--border-strong);
    margin-right: var(--space-2);
}

/* ---------------------------------------------------------------------- */
/* Buttons + form controls                                                */
/* ---------------------------------------------------------------------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 32px;
    padding: 0 var(--space-4);
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}

.btn:active {
    transform: translateY(1px);
}

.btn-primary {
    background: var(--d1-accent);
    color: #fff;
}

.btn-primary:hover {
    background: var(--d1-accent-2);
}

.btn-ghost {
    background: transparent;
    border-color: var(--border-strong);
    color: var(--text-0);
}

.btn-ghost:hover {
    border-color: var(--d1-accent-2);
    color: var(--d1-accent-2);
}

.btn-danger {
    background: transparent;
    border-color: var(--danger);
    color: var(--danger);
}

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

.btn-sm {
    height: 26px;
    padding: 0 var(--space-3);
    font-size: 10.5px;
}

.btn:disabled {
    opacity: 0.4;
    cursor: default;
    transform: none;
}

input[type="text"], input[type="search"], input[type="password"], textarea {
    width: 100%;
    background: var(--bg-0);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    padding: 7px 9px;
    font-size: 12.5px;
    color: var(--text-0);
    transition: border-color var(--dur-fast) var(--ease);
}

input[type="text"]:focus, input[type="search"]:focus, textarea:focus {
    border-color: var(--d1-accent-2);
}

input::placeholder, textarea::placeholder {
    color: var(--text-3);
}

/* ---------------------------------------------------------------------- */
/* Modals + toasts (rendered into #modal-root)                            */
/* ---------------------------------------------------------------------- */

#modal-root {
    position: fixed;
    inset: 0;
    z-index: 100;
    pointer-events: none;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: var(--overlay-scrim);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-5);
    pointer-events: auto;
    animation: modal-fade var(--dur-fast) var(--ease-out);
}

.modal-dialog {
    width: 100%;
    max-width: var(--modal-width, 420px);
    max-height: min(720px, 86vh);
    display: flex;
    flex-direction: column;
    background: var(--bg-2);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-3);
    animation: modal-pop var(--dur-med) var(--ease-out);
}

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

@keyframes modal-pop {
    from { opacity: 0; transform: translateY(6px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-4) var(--space-4) var(--space-3);
    border-bottom: 1px solid var(--border);
}

.modal-title {
    margin: 0;
    font-family: var(--font-serif);
    font-weight: 700;
    font-size: 16px;
}

.modal-close {
    width: 26px;
    height: 26px;
    border-radius: var(--radius-sm);
    color: var(--text-2);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
}

.modal-close:hover {
    background: var(--bg-3);
    color: var(--text-0);
}

.modal-body {
    padding: var(--space-4);
    overflow-y: auto;
    font-size: 13px;
    color: var(--text-1);
}

.modal-body p {
    margin: 0 0 var(--space-3);
}

.modal-body p:last-child {
    margin-bottom: 0;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-4) var(--space-4);
}

.toast-stack {
    position: absolute;
    right: var(--space-4);
    bottom: calc(var(--statusbar-h) + var(--space-4));
    display: flex;
    flex-direction: column-reverse;
    gap: var(--space-2);
    pointer-events: none;
}

.toast {
    pointer-events: auto;
    min-width: 220px;
    max-width: 360px;
    padding: 10px var(--space-3);
    background: var(--bg-3);
    border: 1px solid var(--border-strong);
    border-left: 3px solid var(--info);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-2);
    font-size: 12px;
    color: var(--text-0);
    animation: toast-in var(--dur-med) var(--ease-out);
}

.toast.is-leaving {
    animation: toast-out var(--dur-med) var(--ease) forwards;
}

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

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

@keyframes toast-out {
    to { opacity: 0; transform: translateY(4px); }
}

/* ---------------------------------------------------------------------- */
/* Start screen                                                           */
/* ---------------------------------------------------------------------- */

#start-screen {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-5);
    overflow-y: auto;
    background:
        radial-gradient(1200px 600px at 50% -10%, rgba(0, 114, 177, 0.16), transparent 60%),
        var(--bg-0);
}

#start-screen[hidden] {
    display: none;
}

.start-card {
    width: 100%;
    max-width: 560px;
    display: flex;
    flex-direction: column;
    gap: var(--space-5);
    padding: var(--space-6);
    margin: auto;
    background: var(--bg-1);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-3);
}

.start-wordmark {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.start-logo {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    object-fit: cover;
}

.start-wordmark-text h1 {
    margin: 0;
    font-family: var(--font-serif);
    font-weight: 700;
    font-size: 30px;
    letter-spacing: -0.01em;
    color: var(--text-0);
}

.start-byline {
    margin: 0;
    font-size: 10.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    color: var(--d1-accent-2);
}

.start-tagline {
    margin: 0;
    color: var(--text-1);
    font-size: 13px;
}

.start-actions {
    display: flex;
    gap: var(--space-3);
}

.start-actions .btn {
    flex: 1 1 0;
}

.start-desktop-link {
    display: block;
    width: 100%;
    padding: 10px var(--space-4);
    border: 1.5px solid var(--border-strong);
    border-radius: var(--radius-md);
    text-align: center;
    text-decoration: none;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.04em;
    color: var(--text-2);
    transition: border-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}

.start-desktop-link:hover {
    border-color: var(--d1-accent);
    color: var(--d1-accent);
    background: var(--bg-2);
}

.start-dropzone {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: var(--space-5) var(--space-4);
    border: 1.5px dashed var(--border-strong);
    border-radius: var(--radius-md);
    text-align: center;
    cursor: pointer;
    transition: border-color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}

.start-dropzone:hover, .start-dropzone:focus-visible {
    border-color: var(--d1-accent);
    background: var(--bg-2);
}

.start-dropzone.is-dragover {
    border-color: var(--d1-accent-2);
    background: var(--aff-tint);
}

.start-dropzone-icon {
    width: 22px;
    height: 22px;
    stroke: var(--text-2);
    fill: none;
    stroke-width: 1.5;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.start-dropzone-text {
    margin: 0;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--text-0);
}

.start-dropzone-sub {
    margin: 0;
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--text-3);
}

.start-config {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-4);
}

.start-fieldset legend {
    font-size: 9.5px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-2);
    margin-bottom: 6px;
}

.segmented {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 4px;
    padding: 3px;
    background: var(--bg-0);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

.segmented-2 {
    grid-template-columns: repeat(2, 1fr);
}

.segmented-opt {
    position: relative;
}

.segmented-opt input {
    position: absolute;
    opacity: 0;
    width: 1px;
    height: 1px;
}

.segmented-opt span {
    display: block;
    text-align: center;
    padding: 6px 4px;
    border-radius: 3px;
    font-size: 11px;
    font-weight: 700;
    color: var(--text-2);
    transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}

.segmented-opt input:checked + span {
    background: var(--d1-accent);
    color: #fff;
}

.segmented-opt input:focus-visible + span {
    box-shadow: var(--focus-ring);
}

.segmented-opt:hover span {
    color: var(--text-0);
}

.start-recents-wrap {
    border-top: 1px solid var(--border);
    padding-top: var(--space-4);
}

.start-recents-title {
    margin: 0 0 var(--space-2);
    font-size: 9.5px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-2);
}

.start-recents {
    display: flex;
    flex-direction: column;
    gap: 2px;
    max-height: 160px;
    overflow-y: auto;
}

/* .start-recents-empty is the static placeholder baked into index.html;
   .start-empty is what main.js renders once it has actually checked for
   recents and found none. Both read the same. */
.start-recents-empty, .start-empty {
    font-size: 12px;
    color: var(--text-3);
    padding: var(--space-2) 0;
}

/* .start-recent is what main.js's renderRecents() actually creates (a
   <button> per saved round); .start-recent-item stays as an alias in case a
   future static/server-rendered list uses the more conventional name. */
.start-recent, .start-recent-item {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-3);
    width: 100%;
    padding: 7px 8px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    text-align: left;
}

.start-recent:hover, .start-recent-item:hover {
    background: var(--bg-2);
}

.start-recent-name {
    font-weight: 600;
    color: var(--text-0);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.start-recent-meta {
    flex: 0 0 auto;
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--text-3);
}

.start-drop-overlay {
    position: fixed;
    inset: 0;
    z-index: 60;
    display: none;
    align-items: center;
    justify-content: center;
    background: var(--aff-tint-strong);
    border: 3px dashed var(--d1-accent-2);
    margin: var(--space-4);
    border-radius: var(--radius-lg);
}

.start-drop-overlay.is-active {
    display: flex;
}

.start-drop-overlay p {
    font-size: 22px;
    font-weight: 700;
    color: var(--text-0);
    background: var(--bg-1);
    padding: var(--space-3) var(--space-5);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-2);
}

/* ---------------------------------------------------------------------- */
/* Responsive — down to a tablet                                          */
/* ---------------------------------------------------------------------- */

@media (max-width: 1024px) {
    :root {
        --sidebar-w: 188px;
        --dock-w: 300px;
    }

    .topbar-round-meta {
        display: none;
    }
}

@media (max-width: 820px) {
    #sidebar {
        position: absolute;
        top: 0;
        bottom: 0;
        left: 0;
        z-index: 20;
        box-shadow: var(--shadow-3);
    }

    #dock {
        position: absolute;
        top: 0;
        bottom: 0;
        right: 0;
        z-index: 20;
        box-shadow: var(--shadow-3);
    }

    #dock-resizer {
        display: none;
    }

    .start-config {
        grid-template-columns: 1fr;
    }
}

/* ---------------------------------------------------------------------- */
/* Reduced motion                                                         */
/* ---------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
        scroll-behavior: auto !important;
    }
}

/* ---------------------------------------------------------------------- */
/* Print — a sheet on paper, landscape, columns preserved, no chrome      */
/* ---------------------------------------------------------------------- */

@media print {
    @page {
        size: landscape;
        margin: 12mm;
    }

    html, body {
        height: auto;
        background: #fff !important;
        color: #000 !important;
    }

    #topbar, #sidebar, #dock, #hud, #statusbar,
    #modal-root, #start-screen, #dock-resizer,
    .icon-btn, .toolbar-btn, .sheets-header-actions {
        display: none !important;
    }

    #app {
        position: static;
        display: block;
        overflow: visible;
    }

    #workspace {
        display: block;
        overflow: visible;
    }

    #grid-host {
        position: static;
        overflow: visible;
        background: #fff;
    }

    .flow-grid {
        width: 100%;
        page-break-inside: auto;
        color: #000;
        font-size: 10px;
    }

    .flow-grid thead {
        display: table-header-group;
    }

    .flow-grid tr {
        page-break-inside: avoid;
    }

    .flow-grid th, .flow-grid td {
        border: 1px solid #999 !important;
        background: #fff !important;
        color: #000 !important;
        box-shadow: none !important;
    }

    .flow-grid th.col-aff, .flow-grid td.col-aff {
        background: #eefaf4 !important;
    }

    .flow-grid th.col-neg, .flow-grid td.col-neg {
        background: #fdeef1 !important;
    }

    .sheet-print-page {
        page-break-after: always;
    }
}
