/* DBSC Race Course – mobile-first */
* {
    box-sizing: border-box;
}

:root {
    --bg: #0b1f33;
    --card: #11304b;
    --card2: #14375a;
    --accent: #ffb000;
    --good: #2bb673;
    --port: #d33;
    --stbd: #1aa64a;
    --text: #f5f7fa;
    --muted: #8aa5bf;
    --line: #1f4870;
    --hi: #ffb00022;
    /* Chart-specific tokens (used by canvas drawing in app.js) */
    --chart-sea: #1d4a73;
    --chart-land: #2a3848;
    --chart-coast: #4a6280;
    --chart-grid: #2a5076;
    --chart-mark-bg: #f5f7fa;
    --chart-mark-text: #0a1a2c;
    --chart-mark-faint: #3d6b95;
    --chart-leg-done: #6a90b5;
    --chart-leg-todo: #f5faff;
    --chart-arrow: #cfe0f0;
    --chart-tide: #5fc0ff;
}

/* Light theme — applied when <html data-theme="light"> or system preference
   is light AND the user hasn't explicitly chosen dark. */
:root[data-theme="light"] {
    --bg: #f3f6fa;
    --card: #ffffff;
    --card2: #eaf0f7;
    --accent: #c97a00;
    --good: #1f8a4d;
    --port: #c1272d;
    --stbd: #128a3a;
    --text: #11243a;
    --muted: #5a6f86;
    --line: #c8d4e1;
    --hi: #c97a0022;
    --chart-sea: #cce4f5;
    --chart-land: #ebe1c8;
    --chart-coast: #b9a778;
    --chart-grid: #b9cee0;
    --chart-mark-bg: #11243a;
    --chart-mark-text: #ffffff;
    --chart-mark-faint: #98aabe;
    --chart-leg-done: #7a8ea5;
    --chart-leg-todo: #11243a;
    --chart-arrow: #4a5e75;
    --chart-tide: #1d7fb5;
}

html,
body {
    margin: 0;
    padding: 0;
    min-height: 100%;
    background: var(--bg);
    color: var(--text);
    font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    touch-action: manipulation; /* prevent double-tap zoom */
}

/* Respect iOS notch / Android cut-outs and bottom home indicator when
   installed to the home screen (status-bar-style is black-translucent,
   so the OS draws the status bar over our content unless we pad). */
body {
    padding-top: env(safe-area-inset-top);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
    padding-bottom: env(safe-area-inset-bottom);
}

header {
    padding: 14px 16px 10px;
    background: linear-gradient(180deg, var(--card), var(--bg));
    border-bottom: 1px solid var(--line);
}

header h1 {
    margin: 0;
    font-size: 20px;
    letter-spacing: .3px;
}

header .sub {
    color: var(--muted);
    font-size: 13px;
    margin-top: 2px;
}

section {
    padding: 12px 16px;
}

.picker {
    display: grid;
    /* Mobile: card spans full width; wind + course# share a row below it;
       TWD spans full width on its own row beneath those. */
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

/* Course card and TWD span both columns on mobile */
.picker label.full {
    grid-column: 1 / -1;
}

.picker label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 12px;
    color: var(--muted);
    min-width: 0;
}

.picker select {
    width: 100%;
    max-width: 100%;
    padding: 10px;
    font-size: 16px;
    background: var(--card);
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: 8px;
    -webkit-appearance: none;
    appearance: none;
    text-overflow: ellipsis;
}

@media (min-width: 560px) {

    /* All four items on one row: Card | Wind | # | TWD */
    .picker {
        grid-template-columns: 2fr 1fr 1fr 2fr;
    }

    .picker label.full {
        grid-column: auto;
    }

    /* Shrink the TWD reset button to just the icon at this width */
    .twd-btn-text {
        display: none;
    }
}

.summary {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 12px 14px;
    margin: 12px 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Short / full picker labels — toggled by landscape media query below */
.lbl-short {
    display: none;
}

/* TWD override dot — blank at default, accent-coloured when user has edited */
.twd-hint {
    color: var(--accent);
    font-size: 10px;
    margin-left: 4px;
    vertical-align: middle;
}

/* Top row: badge + aside info */
.sum-top {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* "A1" badge — large, bold, instant orientation */
.sum-badge {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 52px;
    height: 52px;
    background: var(--accent);
    color: #07223a;
    border-radius: 10px;
    font-size: 24px;
    font-weight: 800;
    letter-spacing: .5px;
    font-variant-numeric: tabular-nums;
}

.sum-aside {
    flex: 1;
    min-width: 0;
}

.sum-wind {
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sum-override {
    color: var(--accent);
    font-weight: 700;
}

.sum-dist {
    font-size: 12px;
    color: var(--muted);
    margin-top: 2px;
}

/* Mark sequence row */
.sum-route {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0 2px;
    font-size: 14px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    row-gap: 4px;
}

.sum-mark {
    white-space: nowrap;
}

.sm-side {
    font-size: 9px;
    font-weight: 800;
    letter-spacing: .3px;
    vertical-align: super;
    margin-left: 1px;
}

.sm-side.p {
    color: var(--port);
}

.sm-side.s {
    color: var(--stbd);
}

.sum-sep {
    color: var(--muted);
    font-weight: 400;
    font-size: 12px;
    margin: 0 2px;
}

/* Light-mode badge: white text on the darker amber reads better than navy */
:root[data-theme="light"] .sum-badge {
    color: #fff;
}

.controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.controls button {
    padding: 14px;
    font-size: 16px;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: var(--card);
    color: var(--text);
    cursor: pointer;
}

.controls button.primary {
    background: var(--good);
    border-color: var(--good);
    font-weight: 700;
    grid-column: 1 / -1;
}

.controls button.primary:disabled {
    background: var(--card2);
    color: var(--muted);
    border-color: var(--line);
    opacity: .7;
}

.controls button.ghost:disabled {
    color: var(--muted);
    opacity: .55;
}

/* Toggle-style ghost buttons (Auto-round): show pressed-on state */
.controls button.ghost[aria-pressed="true"] {
    background: var(--hi);
    border-color: var(--accent);
    color: var(--accent);
    font-weight: 700;
}

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

.now {
    margin: 4px 16px 0;
    background: var(--card2);
    border: 1px solid var(--accent);
    border-radius: 12px;
    padding: 14px;
}

.now h3 {
    margin: 0 0 6px;
    font-size: 13px;
    color: var(--accent);
    letter-spacing: .8px;
    text-transform: uppercase;
}

.now .name {
    font-size: 22px;
    font-weight: 700;
}

.now .row {
    display: flex;
    gap: 16px;
    margin-top: 6px;
    flex-wrap: wrap;
}

.now .row .cell {
    min-width: 90px;
}

.now .row .cell .lbl {
    color: var(--muted);
    font-size: 12px;
}

.now .row .cell .val {
    font-size: 22px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.now .gps {
    font-size: 12px;
    color: var(--muted);
    margin-top: 6px;
}

.now .gps strong {
    color: var(--text);
}

.legs h2 {
    font-size: 14px;
    color: var(--muted);
    margin: 8px 0;
    text-transform: uppercase;
    letter-spacing: .8px;
}

.legs ol {
    list-style: none;
    padding: 0;
    margin: 0;
}

.legs li {
    display: grid;
    grid-template-columns: 28px 1fr auto;
    gap: 10px;
    align-items: center;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 10px;
    margin-bottom: 6px;
    background: var(--card);
}

.legs li.done {
    opacity: .55;
}

.legs li.current {
    background: var(--hi);
    border-color: var(--accent);
}

.legs li.start {
    background: #14443a;
    border-color: var(--good);
}

.legs li.finish {
    background: #4a2a14;
    border-color: var(--accent);
}

/* Light-theme overrides: the hard-coded dark green/brown above are
   illegible in light mode, so use soft tints of the same hues. */
:root[data-theme="light"] .legs li.start {
    background: #d6f0e3;
    border-color: var(--good);
}

:root[data-theme="light"] .legs li.finish {
    background: #ffe9c2;
    border-color: var(--accent);
}

.legs li .idx {
    color: var(--muted);
    font-variant-numeric: tabular-nums;
    text-align: right;
}

.legs li .info .name {
    font-weight: 700;
}

.legs li .info .meta {
    color: var(--muted);
    font-size: 13px;
}

.legs li .info .meta .pill {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 4px;
    font-weight: 700;
    font-size: 11px;
    margin-right: 4px;
    color: #fff;
}

.legs li .info .meta .pill.p {
    background: var(--port);
}

.legs li .info .meta .pill.s {
    background: var(--stbd);
}

.legs li .info .meta .pill.x {
    background: #555;
}

/* Pill colours apply everywhere (Now panel, anywhere we re-use the markup),
   not just inside the legs list. The dark-on-coloured contrast carries the
   port/starboard meaning at a glance. */
.pill.p {
    background: var(--port);
    color: #fff;
}

.pill.s {
    background: var(--stbd);
    color: #fff;
}

.pill.x {
    background: #555;
    color: #fff;
}

/* In the Now panel the pill is the dominant cue — make it bigger. */
.now .name .pill {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 6px;
    font-weight: 800;
    font-size: 13px;
    letter-spacing: .8px;
    margin-left: 8px;
    vertical-align: middle;
}

.legs li .info .meta .colour {
    font-size: 11px;
    color: var(--muted);
    margin-left: 4px;
}

.legs li .nav {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.legs li .nav .b {
    font-weight: 700;
}

.legs li .nav .d {
    color: var(--muted);
    font-size: 13px;
}

footer {
    padding: 16px;
    color: var(--muted);
    text-align: center;
}

@media (min-width: 720px) {
    body {
        max-width: 760px;
        margin: 0 auto;
    }
}

/* ---------- portrait: course-columns is a simple single column ---------- */
.course-columns {
    display: flex;
    flex-direction: column;
}

/* ============================================================
   Accordion sections
   Uses grid-template-rows 0fr → 1fr for smooth height animation
   without needing JS to calculate pixel heights.
   ============================================================ */

.ac-section {
    border-bottom: 1px solid var(--line);
}

/* Accordion header button */
.ac-hd {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 11px 16px;
    background: transparent;
    border: 0;
    color: var(--text);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    text-align: left;
}

.ac-hd:active {
    background: var(--hi);
}

.ac-title {
    flex: 1;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .9px;
    color: var(--muted);
}

/* Small hint text inside the header (e.g. "tap a leg to jump") */
.ac-hint {
    font-size: 11px;
    color: var(--muted);
    font-weight: 400;
    opacity: .7;
}

/* Chevron: rotates 180° when section is open */
.ac-chevron {
    flex-shrink: 0;
    width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    transition: transform 0.22s ease;
}

.ac-chevron::after {
    content: "▾";
    font-size: 13px;
    line-height: 1;
    display: block;
}

.ac-section.open .ac-chevron {
    transform: rotate(-180deg);
}

/* Collapsible body: grid trick for smooth height animation */
.ac-body {
    display: grid;
    grid-template-rows: 0fr;
    overflow: hidden;
    transition: grid-template-rows 0.25s ease;
}

.ac-section.open .ac-body {
    grid-template-rows: 1fr;
}

/* Required: inner wrapper must have min-height: 0 for the grid trick */
.ac-inner {
    min-height: 0;
}

/* Remove the old .legs h2 — the accordion header replaces it */
.legs h2 {
    display: none;
}

/* Inside accordion: sections don't need their own top padding since
   the accordion header already provides visual separation */
.ac-inner>section,
.ac-inner>.summary {
    padding-top: 4px;
}

/* .now is a self-contained card with its own full padding — restore symmetry */
.ac-inner>.now {
    padding-top: 14px;
    margin-bottom: 8px;
}

/* ---------- portrait reset — explicitly undo any landscape overrides ----------
   iOS Safari sometimes retains stale layout from landscape; this block is an
   insurance policy that forces the correct values back in portrait.            */
@media (orientation: portrait) {
    body {
        height: auto;
        min-height: 100%;
        overflow: auto;
    }

    header {
        position: static;
        transform: none;
        box-shadow: none;
        transition: none;
    }

    .view {
        height: auto;
        overflow: visible;
    }
}

/* ---------- Floating landscape nav button (hidden in portrait) ---------- */
.ls-menu-btn {
    display: none;
    /* shown only in landscape via media query */
    position: fixed;
    top: calc(22px + env(safe-area-inset-top));
    right: calc(16px + env(safe-area-inset-right));
    z-index: 200;
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: var(--card2);
    border: 1px solid var(--line);
    color: var(--text);
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .35);
    -webkit-tap-highlight-color: transparent;
    transition: background 0.15s, transform 0.15s;
}

.ls-menu-btn:active {
    transform: scale(0.93);
}

/* Hide the ☰ button while the header is slid open */
header.ls-open~.ls-menu-btn {
    opacity: 0;
    pointer-events: none;
    transform: scale(0.8);
    transition: opacity 0.15s, transform 0.15s;
}

/* Slide-down backdrop — closes the nav when tapping outside */
.ls-backdrop {
    position: fixed;
    inset: 0;
    z-index: 99;
    background: transparent;
}

.ls-backdrop[hidden] {
    display: none;
}

/* ---------- landscape two-column navigation layout ----------
   Body is locked; header floats above, hidden by default,
   revealed by the ☰ button with a spring slide animation.    */
@media (orientation: landscape) and (min-width: 600px) {

    body {
        max-width: none;
        margin: 0;
        height: 100svh;
        overflow: hidden;
    }

    /* Header is fixed, slides in from top when .ls-open */
    header {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 100;
        transform: translateY(-100%);
        transition: transform 0.28s cubic-bezier(0.34, 1.20, 0.64, 1);
    }

    header.ls-open {
        transform: translateY(0);
        box-shadow: 0 6px 24px rgba(0, 0, 0, .45);
    }

    /* Views fill the full screen (header is out of flow) */
    .view {
        height: 100svh;
        overflow: hidden;
    }

    .course-columns {
        flex-direction: row;
        height: 100%;
    }

    /* Left panel: pickers, summary, controls, Now */
    .course-left {
        width: 320px;
        flex-shrink: 0;
        border-right: 1px solid var(--line);
        height: 100%;
        overflow-y: auto;
        overscroll-behavior: contain;
    }

    /* Right panel: chart + legs */
    .course-right {
        flex: 1;
        min-width: 0;
        height: 100%;
        overflow-y: auto;
        overscroll-behavior: contain;
    }

    /* Footer is irrelevant in landscape */
    footer {
        display: none;
    }

    /* Show the floating nav button */
    .ls-menu-btn {
        display: flex;
    }

    /* Use short label text in landscape to prevent wrapping */
    .lbl-short {
        display: inline;
    }

    .lbl-full {
        display: none;
    }

    /* Tighten section padding inside the narrow left panel */
    .course-left section,
    .course-left .summary {
        margin-left: 0;
        margin-right: 0;
    }

    /* The chart should fill the available right-panel width */
    .course-right .chartwrap {
        margin: 12px 12px 0;
    }

    .course-right .legs {
        padding: 12px;
    }

    /* Controls grid: tighter in the narrow left panel */
    .course-left .controls {
        grid-template-columns: 1fr 1fr;
        gap: 6px;
    }

    .course-left .controls button {
        padding: 11px 8px;
        font-size: 14px;
    }
}

/* ---------- additions: install btn, chart, tappable legs ---------- */
.title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.title-row .install {
    background: var(--accent);
    color: #1a1a1a;
    border: 0;
    padding: 6px 12px;
    border-radius: 999px;
    font-weight: 700;
    font-size: 13px;
    cursor: pointer;
}

.chartwrap {
    margin: 0 16px;
    padding: 0;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 12px;
    overflow: hidden;
}

.chartwrap canvas {
    display: block;
    width: 100%;
    height: auto;
    background: var(--chart-sea);
    touch-action: pan-y;
}

.legs h2 .hint {
    font-size: 11px;
    color: var(--muted);
    margin-left: 8px;
    font-weight: 400;
    text-transform: none;
    letter-spacing: 0;
}

.legs li {
    cursor: pointer;
    user-select: none;
}

.legs li:active {
    transform: scale(0.995);
}

/* ---------- tabs ---------- */
.tabs {
    display: flex;
    gap: 4px;
    margin-top: 10px;
    border-bottom: 1px solid var(--line);
}

.tabs .tab {
    flex: 1;
    background: transparent;
    color: var(--muted);
    border: 0;
    border-bottom: 2px solid transparent;
    padding: 10px 6px;
    font-size: 14px;
    font-weight: 600;
    letter-spacing: .3px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.tabs .tab.active {
    color: var(--text);
    border-bottom-color: var(--accent);
}

.view[hidden] {
    display: none;
}

/* ---------- Today view ---------- */
.picker input[type="date"] {
    width: 100%;
    padding: 10px;
    font-size: 16px;
    background: var(--card);
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: 8px;
    -webkit-appearance: none;
    appearance: none;
    color-scheme: dark;
}

.date-row {
    display: flex;
    gap: 8px;
    align-items: stretch;
}

.date-row input[type="date"] {
    flex: 1;
}

.ghost-sm {
    background: var(--card);
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 0 14px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.ghost-sm:active {
    transform: translateY(1px);
}

.recommend {
    margin: 12px 16px;
    padding: 0;
}

.recommend .card {
    background: var(--card2);
    border: 1px solid var(--accent);
    border-radius: 12px;
    padding: 14px;
}

.recommend .day {
    color: var(--accent);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .8px;
    margin-bottom: 4px;
}

.recommend .big {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 8px;
}

.recommend .grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px 14px;
    margin-bottom: 12px;
}

.recommend .grid .lbl {
    color: var(--muted);
    font-size: 12px;
}

.recommend .grid .val {
    font-size: 18px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.recommend .note {
    color: var(--muted);
    font-size: 13px;
    margin-bottom: 10px;
}

.recommend button {
    width: 100%;
    padding: 14px;
    font-size: 16px;
    border-radius: 10px;
    border: 0;
    background: var(--good);
    color: #fff;
    font-weight: 700;
    cursor: pointer;
}

.recommend .pdf-btn {
    display: block;
    width: 100%;
    padding: 14px;
    box-sizing: border-box;
    font-size: 16px;
    border-radius: 10px;
    border: 0;
    background: var(--accent);
    color: #1a1a1a;
    font-weight: 700;
    text-align: center;
    text-decoration: none;
}

.recommend.warn .card {
    border-color: var(--port);
}

.recommend.warn .day {
    color: var(--port);
}

/* ---------- Docs view ---------- */
.docs-intro p {
    color: var(--muted);
    font-size: 13px;
    margin: 0 0 6px;
}

.docs-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.docs-list .docs-h {
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .8px;
    margin-top: 8px;
}

.docs-list .doc {
    display: block;
    padding: 12px 14px;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 10px;
    color: var(--text);
    text-decoration: none;
}

.docs-list .doc:active {
    background: var(--card2);
}

.docs-list .doc-name {
    font-weight: 700;
}

.docs-list .doc-sub {
    color: var(--muted);
    font-size: 13px;
    margin-top: 2px;
}

/* ---------- install banner ---------- */
.install-banner {
    position: relative;
    margin: 10px 16px 0;
    padding: 12px 38px 12px 14px;
    background: linear-gradient(180deg, var(--card2), var(--card));
    border: 1px solid var(--accent);
    border-radius: 12px;
    color: var(--text);
    font-size: 14px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, .25);
}

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

.install-banner .ib-title {
    font-weight: 700;
    margin-bottom: 4px;
    color: var(--accent);
    letter-spacing: .3px;
}

.install-banner .ib-body {
    color: var(--text);
    line-height: 1.45;
}

.install-banner .ib-body ol {
    margin: 4px 0 0;
    padding-left: 20px;
}

.install-banner .ib-body li {
    margin-bottom: 2px;
}

.install-banner .ib-body .key {
    display: inline-block;
    padding: 0 6px;
    border: 1px solid var(--line);
    border-radius: 4px;
    background: var(--bg);
    font-weight: 700;
    font-size: 12px;
}

.install-banner .ib-cta {
    display: inline-block;
    margin-top: 8px;
    padding: 8px 14px;
    background: var(--accent);
    color: #1a1a1a;
    border: 0;
    border-radius: 8px;
    font-weight: 700;
    font-size: 14px;
    cursor: pointer;
    text-decoration: none;
}

.install-banner .ib-close {
    position: absolute;
    top: 4px;
    right: 6px;
    width: 28px;
    height: 28px;
    background: transparent;
    border: 0;
    color: var(--muted);
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.install-banner .ib-close:active {
    color: var(--text);
}

footer small a {
    color: var(--muted);
    margin-left: 6px;
}

footer .app-version {
    display: block;
    margin-top: 4px;
    opacity: .7;
}

.version-btn {
    background: none;
    border: 0;
    color: var(--muted);
    font: inherit;
    padding: 2px 6px;
    cursor: pointer;
    border-radius: 4px;
}

.version-btn:hover,
.version-btn:focus {
    color: var(--accent, var(--text));
    text-decoration: underline;
    outline: none;
}

/* ---------- update toast ---------- */
.update-toast {
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    bottom: calc(16px + env(safe-area-inset-bottom));
    z-index: 1000;
    display: flex;
    align-items: center;
    gap: 10px;
    max-width: calc(100vw - 24px);
    padding: 10px 12px 10px 14px;
    background: var(--card2);
    border: 1px solid var(--accent);
    border-radius: 999px;
    color: var(--text);
    font-size: 14px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, .35);
}

.update-toast[hidden] {
    display: none;
}

/* generic info toast (auto-round, GPS auto-off, etc.) */
.toast {
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    bottom: calc(72px + env(safe-area-inset-bottom));
    z-index: 1000;
    max-width: calc(100vw - 32px);
    padding: 10px 16px;
    background: var(--card2);
    border: 1px solid var(--accent);
    border-radius: 999px;
    color: var(--text);
    font-size: 14px;
    font-weight: 600;
    box-shadow: 0 4px 14px rgba(0, 0, 0, .35);
    pointer-events: none;
}

.toast[hidden] {
    display: none;
}

.update-toast .ut-text {
    white-space: nowrap;
}

.update-toast .ut-reload {
    background: var(--accent);
    color: #07223a;
    border: 0;
    border-radius: 999px;
    padding: 6px 12px;
    font-weight: 700;
    font-size: 13px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.update-toast .ut-close {
    background: transparent;
    border: 0;
    color: var(--muted);
    font-size: 20px;
    line-height: 1;
    width: 28px;
    height: 28px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.update-toast .ut-close:active {
    color: var(--text);
}

/* ---------- header action buttons ---------- */
.title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.header-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.theme-toggle {
    background: transparent;
    border: 1px solid var(--line);
    color: var(--text);
    border-radius: 999px;
    width: 36px;
    height: 36px;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.theme-toggle:active {
    background: var(--card2);
}

/* ---------- info strip (countdown + tides) ---------- */
.info-strip {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 12px 16px 0;
}

.info-strip[hidden] {
    display: none;
}

@media (max-width: 480px) {
    .info-strip {
        grid-template-columns: 1fr;
    }
}

.info-card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 10px 12px;
    color: var(--text);
    text-align: left;
    font: inherit;
    cursor: default;
}

.info-card.countdown {
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.info-card.countdown:active {
    background: var(--card2);
}

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

.info-card .ic-lbl {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .6px;
    color: var(--muted);
    margin-bottom: 2px;
}

.info-card .ic-big {
    font-size: 16px;
    font-weight: 700;
    color: var(--accent);
}

.info-card .ic-sub {
    font-size: 12px;
    color: var(--muted);
    margin-top: 2px;
}

/* ---------- chart expand button ---------- */
.chartwrap {
    position: relative;
}

.chart-expand {
    position: absolute;
    bottom: 8px;
    right: 8px;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: rgba(11, 31, 51, .65);
    color: var(--text);
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

:root[data-theme="light"] .chart-expand {
    background: rgba(255, 255, 255, .85);
}

.chart-expand:active {
    background: var(--card2);
}

/* single Chart/Steer toggle button, top-left of chartwrap */
.view-toggle-single {
    position: absolute;
    top: 8px;
    left: 8px;
    z-index: 2;
    border: 1px solid var(--line);
    background: rgba(11, 31, 51, .65);
    color: var(--text);
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    padding: 7px 12px;
    border-radius: 8px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

:root[data-theme="light"] .view-toggle-single {
    background: rgba(255, 255, 255, .85);
}

.view-toggle-single[aria-pressed="true"] {
    background: var(--accent);
    color: #07223a;
    border-color: var(--accent);
}

.view-toggle-single:active {
    transform: scale(.97);
}

/* ---------- fullscreen chart modal ---------- */
.chart-modal {
    position: fixed;
    inset: 0;
    z-index: 1100;
    background: var(--bg);
    display: flex;
    align-items: stretch;
    justify-content: stretch;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.chart-modal[hidden] {
    display: none;
}

.chart-modal .cm-canvas {
    flex: 1;
    width: 100%;
    height: 100%;
    display: block;
    background: var(--chart-sea);
}

.chart-modal .cm-close {
    position: absolute;
    top: calc(8px + env(safe-area-inset-top));
    right: calc(8px + env(safe-area-inset-right));
    width: 44px;
    height: 44px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: var(--card);
    color: var(--text);
    font-size: 26px;
    line-height: 1;
    cursor: pointer;
    z-index: 1;
    -webkit-tap-highlight-color: transparent;
}

.chart-modal .cm-close:active {
    background: var(--card2);
}

/* ---------- compass / heading-aware GPS readout ---------- */
.now .gps.live {
    background: var(--card2);
    border-radius: 8px;
    padding: 8px 10px;
    margin-top: 8px;
    border: 1px solid var(--line);
}

.now .gps.live .gps-row {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 8px;
}

.now .gps.live .gps-cell .lbl {
    font-size: 11px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .5px;
}

.now .gps.live .gps-cell .val {
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
}

.now .gps.live .steer {
    color: var(--accent);
}

/* ---------- true wind direction input ---------- */
.twd-label .twd-hint {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--muted);
    margin-left: 6px;
}

.twd-label .twd-hint.override {
    color: var(--accent);
}

.twd-row {
    display: flex;
    gap: 8px;
    align-items: stretch;
}

.twd-row #twdInput {
    flex: 1;
    background: var(--card);
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px 12px;
    font: inherit;
    font-variant-numeric: tabular-nums;
}

.twd-row #twdInput:focus {
    outline: 2px solid var(--accent);
    outline-offset: 0;
}

.twd-row .ghost-sm {
    white-space: nowrap;
}

/* ---------- TWA chips on legs ---------- */
.legs li .twa {
    font-size: 12px;
    color: var(--muted);
    margin-top: 2px;
    font-variant-numeric: tabular-nums;
}

.legs li .twa .pos {
    font-weight: 600;
    color: var(--text);
}

.legs li .twa .tack-s {
    color: var(--stbd);
    font-weight: 700;
}

.legs li .twa .tack-p {
    color: var(--port);
    font-weight: 700;
}

.now .twa-line {
    margin-top: 6px;
    font-size: 14px;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}

.now .twa-line .pos {
    font-weight: 700;
    color: var(--text);
}

.now .twa-line .tack-s {
    color: var(--stbd);
    font-weight: 700;
}

.now .twa-line .tack-p {
    color: var(--port);
    font-weight: 700;
}

/* ---------- generic modal (used by the GPS explainer) ---------- */
.modal {
    position: fixed;
    inset: 0;
    z-index: 1200;
    background: rgba(7, 19, 33, .65);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.modal[hidden] {
    display: none;
}

.modal .modal-card {
    background: var(--card);
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 18px 18px 14px;
    max-width: 380px;
    width: 100%;
    box-shadow: 0 8px 28px rgba(0, 0, 0, .4);
}

.modal .modal-card h2 {
    margin: 0 0 8px;
    font-size: 17px;
}

.modal .modal-card p {
    margin: 6px 0;
    font-size: 14px;
    line-height: 1.45;
}

.modal .modal-card ul {
    margin: 6px 0 8px;
    padding-left: 20px;
    font-size: 14px;
    line-height: 1.45;
}

.modal .modal-card .modal-note {
    color: var(--muted);
    font-size: 12.5px;
    line-height: 1.45;
}

.modal .modal-row {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 10px;
}

.modal .modal-row button {
    padding: 8px 14px;
    border-radius: 8px;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid var(--line);
}

.modal .modal-row .ghost {
    background: transparent;
    color: var(--text);
}

.modal .modal-row .primary {
    background: var(--accent);
    color: #07223a;
    border-color: var(--accent);
}

/* taller welcome card with scrollable body */
.modal .welcome-card {
    max-width: 520px;
    max-height: 88vh;
    overflow-y: auto;
}

.modal .welcome-card h2 {
    font-size: 19px;
}

/* ordered list inside welcome card */
.modal .welcome-card .welcome-steps {
    margin: 8px 0 10px;
    padding-left: 22px;
    font-size: 14px;
    line-height: 1.6;
}

.modal .welcome-card .welcome-steps li {
    margin-bottom: 6px;
}

/* ---- Full Help Guide ---- */
.modal .help-card {
    max-width: 560px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    padding: 0;
    display: flex;
    flex-direction: column;
}

/* Sticky header row inside help card */
.help-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px 12px;
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    background: var(--card);
    z-index: 1;
    border-radius: 14px 14px 0 0;
}

.help-header h2 {
    margin: 0;
    font-size: 18px;
}

.help-close-btn {
    background: transparent;
    border: 1px solid var(--line);
    color: var(--muted);
    border-radius: 8px;
    padding: 4px 10px;
    font-size: 16px;
    cursor: pointer;
    line-height: 1;
    flex-shrink: 0;
}

/* Each help section */
.help-section {
    padding: 18px 20px 14px;
    border-bottom: 1px solid var(--line);
}

.help-section:last-of-type {
    border-bottom: none;
}

.help-section-title {
    margin: 0 0 10px;
    font-size: 16px;
    font-weight: 800;
    color: var(--accent);
}

.help-section p,
.help-section li {
    font-size: 15px;
    line-height: 1.6;
    color: var(--text);
    margin: 6px 0;
}

.help-section ol,
.help-section ul {
    padding-left: 22px;
    margin: 8px 0;
}

.help-section li {
    margin-bottom: 6px;
}

.help-tip {
    margin-top: 10px !important;
    padding: 10px 14px;
    border-radius: 8px;
    background: var(--hi);
    border-left: 3px solid var(--accent);
    font-size: 14px !important;
    color: var(--text);
}

/* Footer close button */
.help-footer-row {
    padding: 14px 20px;
    border-top: 1px solid var(--line);
    justify-content: center !important;
    position: sticky;
    bottom: 0;
    background: var(--card);
    border-radius: 0 0 14px 14px;
}

.help-footer-row .primary {
    padding: 12px 32px;
    font-size: 15px;
}

.modal .welcome-card h3 {
    margin: 14px 0 4px;
    font-size: 14px;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: .6px;
}

.modal .welcome-card .tack-s {
    color: var(--stbd);
    font-weight: 700;
}

.modal .welcome-card .tack-p {
    color: var(--port);
    font-weight: 700;
}

/* ---------- header meta — shows boat + date from Race Finder ---------- */
.header-meta {
    font-size: 11px;
    color: var(--accent);
    margin-left: 8px;
    font-weight: 600;
}

/* ---------- settings panel ---------- */
.settings-panel {
    position: fixed;
    inset: 0;
    z-index: 400;
    background: rgba(0, 0, 0, .6);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

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

.settings-card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 16px;
    width: 100%;
    max-width: 360px;
    padding: 20px;
}

.settings-hd {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.settings-title {
    font-size: 16px;
    font-weight: 700;
}

.settings-close {
    background: none;
    border: 0;
    color: var(--muted);
    font-size: 24px;
    cursor: pointer;
    line-height: 1;
    padding: 0 4px;
}

.settings-note {
    font-size: 12px;
    color: var(--muted);
    margin: 0 0 14px;
}

.settings-rows {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.settings-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.settings-vis {
    background: none;
    border: 0;
    font-size: 18px;
    cursor: pointer;
    padding: 2px;
    opacity: .4;
}

.settings-vis.active {
    opacity: 1;
}

.settings-label {
    flex: 1;
    font-size: 14px;
    font-weight: 600;
}

.settings-label.muted {
    color: var(--muted);
    text-decoration: line-through;
}

.settings-cols {
    display: flex;
    gap: 4px;
}

.settings-col-btn {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: var(--card2);
    color: var(--muted);
    font-weight: 700;
    font-size: 13px;
    cursor: pointer;
}

.settings-col-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #07223a;
}

.settings-order {
    display: flex;
    gap: 2px;
}

.settings-ord-btn {
    width: 28px;
    height: 32px;
    border-radius: 6px;
    border: 1px solid var(--line);
    background: var(--card2);
    color: var(--text);
    font-size: 13px;
    cursor: pointer;
}

.settings-ord-btn:disabled {
    opacity: .25;
    cursor: default;
}

.settings-footer {
    display: flex;
    gap: 8px;
    margin-top: 16px;
}

.settings-footer .ghost {
    flex: 1;
    padding: 12px;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: var(--card);
    color: var(--text);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}

.settings-footer .primary {
    flex: 1;
    padding: 12px;
    border-radius: 10px;
    border: 0;
    background: var(--good);
    color: #fff;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
}

/* ============================================================
   Race Start Sequence
   ============================================================ */

.start-view {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 24px 16px 40px;
    gap: 24px;
}

/* Status pill */
.start-status {
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 1.2px;
    text-transform: uppercase;
    padding: 5px 16px;
    border-radius: 20px;
    border: 1px solid var(--line);
    color: var(--muted);
    transition: color 0.3s, border-color 0.3s;
}

.start-status[data-phase="countdown"] {
    color: var(--accent);
    border-color: var(--accent);
}

.start-status[data-phase="racing"] {
    color: var(--good);
    border-color: var(--good);
}

.start-status[data-phase="finished"] {
    color: var(--muted);
    border-color: var(--line);
}

/* Big clock */
.start-clock-wrap {
    text-align: center;
}

.start-clock {
    font-size: 88px;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    line-height: 1;
    letter-spacing: -3px;
    transition: color 0.3s;
}

.start-clock.warn {
    color: var(--accent);
}

.start-clock-label {
    font-size: 13px;
    color: var(--muted);
    margin-top: 6px;
    letter-spacing: .5px;
    text-transform: uppercase;
}

/* ±1 min + Sync row */
.start-adjust {
    display: flex;
    gap: 8px;
    align-items: center;
}

.start-adj-btn {
    padding: 12px 20px;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: var(--card);
    color: var(--text);
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.start-adj-btn:active {
    background: var(--card2);
}

.start-sync-btn {
    padding: 12px 18px;
    border-radius: 10px;
    border: 1px solid var(--accent);
    background: var(--hi);
    color: var(--accent);
    font-size: 14px;
    font-weight: 800;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.start-sync-btn:active {
    background: var(--accent);
    color: #07223a;
}

/* Action buttons */
.start-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
    max-width: 320px;
}

.start-go {
    padding: 18px;
    border-radius: 12px;
    border: 0;
    background: var(--good);
    color: #fff;
    font-size: 18px;
    font-weight: 800;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.start-go:active {
    opacity: .85;
}

.start-finish {
    padding: 16px;
    border-radius: 12px;
    border: 0;
    background: var(--accent);
    color: #07223a;
    font-size: 16px;
    font-weight: 800;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.start-finish:active {
    opacity: .85;
}

.start-reset {
    padding: 12px;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: var(--card);
    color: var(--muted);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

/* Signal strip */
.start-signals {
    width: 100%;
    max-width: 380px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.start-signal-row {
    display: grid;
    grid-template-columns: 42px 1fr;
    grid-template-rows: auto auto;
    column-gap: 12px;
    padding: 10px 14px;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: var(--card);
    transition: border-color 0.2s, background 0.2s, opacity 0.2s;
}

.start-signal-row .sig-time {
    grid-row: 1 / 3;
    align-self: center;
    font-size: 15px;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    color: var(--muted);
}

.start-signal-row .sig-name {
    font-size: 13px;
    font-weight: 700;
    color: var(--text);
}

.start-signal-row .sig-detail {
    font-size: 11px;
    color: var(--muted);
}

/* Active — signal just fired */
.start-signal-row.active {
    border-color: var(--accent);
    background: var(--hi);
}

.start-signal-row.active .sig-time,
.start-signal-row.active .sig-name {
    color: var(--accent);
}

/* Past — already done */
.start-signal-row.past {
    opacity: .38;
}

/* Gun — starting signal */
.start-signal-row.gun {
    border-color: var(--good);
    background: var(--card2);
}

.start-signal-row.gun .sig-time,
.start-signal-row.gun .sig-name {
    color: var(--good);
}