:root {
    --bg: #0b1220;
    --bg-raise: #121a2b;
    --line: rgba(232, 238, 247, 0.12);
    --text: #e8eef7;
    --muted: #93a0b5;
    --accent: #3ee0a0;
    --accent-ink: #06281c;
    --warn: #ffb020;
    --danger: #ff6b81;
    --shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
    font-family: "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    min-height: 100%;
    background:
        radial-gradient(1200px 500px at 10% -10%, rgba(62, 224, 160, 0.16), transparent 55%),
        var(--bg);
    color: var(--text);
}

body {
    min-height: 100vh;
    min-height: 100dvh;
}

a { color: var(--accent); }

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

.wrap {
    width: min(1080px, calc(100% - 28px));
    margin: 0 auto;
    padding: 22px 0 40px;
}

.top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    letter-spacing: 0.01em;
    white-space: nowrap;
}

.brand small {
    display: block;
    font-weight: 500;
    color: var(--muted);
    letter-spacing: 0;
}

.live-dot, .idle-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--muted);
    box-shadow: 0 0 0 0 rgba(62, 224, 160, 0.6);
}

.live-dot {
    background: var(--accent);
    animation: pulse 1.6s ease-out infinite;
}

@keyframes pulse {
    70% { box-shadow: 0 0 0 10px rgba(62, 224, 160, 0); }
    100% { box-shadow: 0 0 0 0 rgba(62, 224, 160, 0); }
}

.ghost, .solid, .danger {
    border-radius: 999px;
    border: 1px solid var(--line);
    background: transparent;
    color: var(--text);
    padding: 8px 14px;
    cursor: pointer;
    text-decoration: none;
}

.solid {
    background: var(--accent);
    color: var(--accent-ink);
    border-color: transparent;
    font-weight: 700;
}

.danger {
    background: rgba(255, 107, 129, 0.14);
    border-color: rgba(255, 107, 129, 0.4);
    color: #ffd0d7;
}

.card {
    background: rgba(18, 26, 43, 0.92);
    border: 1px solid var(--line);
    border-radius: 18px;
    box-shadow: var(--shadow);
}

.gate {
    width: min(440px, 100%);
    margin: 12vh auto 0;
    padding: 28px 24px;
}

.gate h1, .section h2, .empty h2 {
    margin: 0 0 8px;
    font-size: 1.6rem;
}

.muted { color: var(--muted); }

.stack { display: grid; gap: 12px; }

label { display: grid; gap: 6px; font-size: 0.92rem; }

input[type="text"], input[type="password"], input[type="file"], input[type="date"] {
    width: 100%;
    padding: 12px 12px;
    border-radius: 12px;
    border: 1px solid var(--line);
    background: #0c1322;
    color-scheme: dark;
}

.filter { margin: 12px 0; }

.filter label { width: min(220px, 100%); }

.history-run + .history-run {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--line);
}

.history-run h3 {
    margin: 0 0 4px;
    font-size: 1.05rem;
}

.history-run ul {
    margin: 8px 0 0;
    padding-left: 18px;
}

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

.row.filter { align-items: end; }

.stats {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 2px 12px;
    width: 100%;
    min-width: 0;
    margin-bottom: 8px;
    padding: 4px 8px;
    background: rgba(18, 26, 43, 0.92);
    border: 1px solid var(--line);
    border-radius: 10px;
}

.stats .stat {
    flex: 0 0 auto;
    background: transparent;
    border: 0;
    border-radius: 0;
    box-shadow: none;
}

.stat {
    display: flex;
    align-items: baseline;
    gap: 4px;
    padding: 1px 0;
    min-width: 0;
}

.stat .k {
    flex: 0 0 auto;
    color: var(--muted);
    font-size: 0.66rem;
    line-height: 1.1;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.stat .v {
    display: flex;
    align-items: baseline;
    gap: 4px;
    margin: 0;
    min-width: 0;
    line-height: 1.1;
}

.stat strong, .pace-card strong {
    flex: 0 0 auto;
    font-variant-numeric: tabular-nums;
    font-size: 0.95rem;
    font-weight: 700;
}

.pace-card strong {
    color: var(--accent);
}

.stat .v .muted {
    font-size: 0.68rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pace-card em {
    font-style: normal;
    color: var(--muted);
    font-size: 0.68rem;
    margin-left: 1px;
}

#age,
#course-name {
    margin: 0 0 6px;
    font-size: 0.78rem;
    line-height: 1.2;
}

.map-card { position: relative; overflow: hidden; }

#map {
    height: min(62dvh, 640px);
    min-height: 320px;
    background: #0e1626;
}

.legend .ghost { padding: 4px 10px; }

.legend {
    position: absolute;
    z-index: 500;
    top: 12px;
    right: 12px;
    display: grid;
    gap: 6px;
    padding: 10px 12px;
    border-radius: 12px;
    background: rgba(11, 18, 32, 0.88);
    border: 1px solid var(--line);
    font-size: 0.85rem;
}

.swatch {
    display: inline-block;
    width: 22px;
    height: 4px;
    margin-right: 6px;
    vertical-align: middle;
    border-radius: 4px;
}

.swatch.course { background: repeating-linear-gradient(90deg, #9eb0cc 0 7px, transparent 7px 11px); }
.swatch.track { background: var(--accent); }

.shout {
    margin: 0 0 8px;
    padding: 8px 10px;
    display: grid;
    gap: 4px;
}

.shout-line {
    display: flex;
    align-items: center;
    gap: 8px;
}

.shout-line input {
    flex: 1;
    min-width: 0;
    width: auto;
    padding: 7px 10px;
    font-size: 16px;
}

.shout-line .solid {
    flex: 0 0 auto;
    padding: 7px 14px;
}

.shout-note {
    margin: 0;
    font-size: 0.72rem;
    line-height: 1.25;
}

#shout-status:not(:empty) + #shout-hint { display: none; }

.empty, .section { padding: 22px; }

.empty { text-align: center; padding: 48px 22px; }

.warn {
    color: var(--warn);
}

.flash {
    padding: 12px 14px;
    border-radius: 12px;
    margin-bottom: 14px;
    background: rgba(62, 224, 160, 0.12);
    border: 1px solid rgba(62, 224, 160, 0.35);
}

.flash.bad {
    background: rgba(255, 107, 129, 0.12);
    border-color: rgba(255, 107, 129, 0.4);
}

.section + .section { margin-top: 14px; }

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.92rem;
}

th, td {
    text-align: left;
    padding: 8px 6px;
    border-bottom: 1px solid var(--line);
    vertical-align: top;
}

th { color: var(--muted); font-weight: 600; }

.table-scroll { overflow-x: auto; }

.pill {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    background: rgba(62, 224, 160, 0.16);
    color: var(--accent);
    font-size: 0.78rem;
}

code, .key {
    font-family: Consolas, "Courier New", monospace;
    word-break: break-all;
}

.footer-link {
    margin-top: 22px;
    color: var(--muted);
    font-size: 0.85rem;
}

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

#live-app:has(#live-panel[hidden]) #shout {
    display: none;
}

@media (max-width: 800px) {
    .wrap:has(#live-app) {
        width: min(1080px, calc(100% - 12px));
        padding: 0 0 16px;
    }

    .screen:has(#live-panel:not([hidden])) {
        box-sizing: border-box;
        width: 100%;
        min-width: 0;
        height: 100dvh;
        height: 100svh;
        display: flex;
        flex-direction: column;
        padding: 8px 0 6px;
        overflow: hidden;
    }

    #live-panel:not([hidden]) {
        flex: 1;
        min-width: 0;
        min-height: 0;
        display: flex;
        flex-direction: column;
    }

    .top { align-items: flex-start; }

    #live-panel:not([hidden]) > :not(.map-card) {
        flex: 0 0 auto;
    }

    #live-app .top {
        flex-wrap: wrap;
        gap: 4px;
        width: 100%;
        min-width: 0;
        margin-bottom: 4px;
    }

    #live-app .top .row {
        flex: 1 1 160px;
        justify-content: flex-end;
        min-width: 0;
    }

    #live-app .brand { font-size: 0.92rem; gap: 6px; }
    #live-app .top .muted { font-size: 0.72rem; }
    #live-app .top .ghost { padding: 3px 8px; font-size: 0.75rem; }

    .stats {
        gap: 0 8px;
        margin-bottom: 3px;
        padding: 2px 6px;
    }

    .stats .stat { gap: 3px; }

    .stat .k { font-size: 0.58rem; letter-spacing: 0.02em; }

    .stat strong,
    .pace-card strong {
        font-size: 0.75rem;
    }

    .pace-card em,
    .stat .v .muted { font-size: 0.58rem; }

    #age,
    #course-name {
        margin: 0 0 3px;
        font-size: 0.68rem;
    }

    .shout {
        margin: 0 0 4px;
        padding: 5px 6px;
        gap: 2px;
        border-radius: 10px;
        box-shadow: none;
    }

    .shout-line { gap: 6px; }
    .shout-line input { padding: 6px 8px; }
    .shout-line .solid { padding: 6px 10px; font-size: 0.8rem; }
    .shout-note { font-size: 0.64rem; }

    .map-card {
        flex: 1;
        min-height: 0;
        display: flex;
        flex-direction: column;
    }

    .screen #map {
        flex: 1 1 0;
        height: auto;
        min-height: 0;
    }

    .legend {
        position: static;
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: 2px 8px;
        margin: 0;
        border: 0;
        border-top: 1px solid var(--line);
        border-radius: 0;
        background: transparent;
        padding: 3px 8px;
        font-size: 0.68rem;
    }
}

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