/* Wo gsi? follows the texbrain look: dark surfaces, amber accent, small radii,
   topbar, sidebar, panes and a statusbar */

:root {
    --bg-deep: #111113;
    --bg-surface: #19191c;
    --bg-elevated: #212124;
    --bg-hover: #2a2a2e;
    --border: #2e2e33;
    --accent: #d19a66;
    --accent-hover: #c48b4f;
    --accent-dim: rgba(209, 154, 102, 0.12);
    --text: #d4d4d8;
    --text-2: #a1a1aa;
    --muted: #85858e;
    --error: #e06c75;
    --success: #73c991;
    --font-ui: 'Inter', system-ui, sans-serif;
    --font-mono: 'JetBrains Mono', ui-monospace, monospace;
    --font-brand: 'Instrument Serif', serif;
    --topbar-h: 44px;
    --toolbar-h: 34px;
    --statusbar-h: 24px;
    --sidebar-w: 260px;
    --radius: 3px;
}

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

html, body {
    height: 100%;
}

body {
    display: flex;
    flex-direction: column;
    background: var(--bg-deep);
    color: var(--text);
    font: 14px/1.5 var(--font-ui);
    -webkit-font-smoothing: antialiased;
    overflow: hidden;
}

button {
    font: inherit;
    color: inherit;
    background: none;
    border: 0;
    cursor: pointer;
}

a {
    color: var(--accent);
    text-decoration: none;
}

.mono {
    font-family: var(--font-mono);
    font-size: 12px;
}

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

[hidden] {
    display: none !important;
}

:focus-visible {
    outline: 1px solid var(--accent);
    outline-offset: 2px;
}

/* ---------- topbar ---------- */

.topbar {
    flex: none;
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-deep);
}

.brand {
    display: flex;
    align-items: center;
    gap: 9px;
    color: var(--text);
    font-family: var(--font-brand);
    font-size: 21px;
    letter-spacing: 0.2px;
}

.brand img {
    display: block;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 6px;
}

.tlink {
    padding: 5px 9px;
    border-radius: var(--radius);
    color: var(--text-2);
    font-size: 13px;
}

.tlink:hover {
    color: var(--text);
    background: var(--bg-hover);
}

.side-toggle {
    display: none;
}

.chip {
    padding: 4px 9px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--accent);
    background: var(--accent-dim);
}

.chip:hover {
    border-color: var(--accent);
}

/* ---------- body ---------- */

.body {
    flex: 1;
    min-height: 0;
    display: flex;
}

.sidebar {
    flex: none;
    width: var(--sidebar-w);
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
    background: var(--bg-surface);
}

.side-head {
    flex: none;
    height: var(--toolbar-h);
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 12px;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    font-size: 13px;
}

.side-head .mono {
    flex: 1;
    font-weight: 400;
}

.side-foot {
    flex: none;
    padding: 8px 12px;
    border-top: 1px solid var(--border);
    font-size: 11.5px;
}

.tbtn {
    padding: 3px 7px;
    border: 1px solid var(--border);
    border-radius: 2px;
    color: var(--text-2);
    font-family: var(--font-mono);
    font-size: 11px;
    white-space: nowrap;
}

.tbtn:hover {
    color: var(--text);
    border-color: var(--muted);
}

/* leaderboard list */

.lb {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    list-style: none;
}

.lb li {
    display: grid;
    grid-template-columns: 28px 1fr auto;
    align-items: center;
    gap: 8px;
    padding: 7px 12px;
    border-bottom: 1px solid var(--border);
}

.lb li:hover {
    background: var(--bg-elevated);
}

.lb li.me {
    background: var(--accent-dim);
    box-shadow: inset 2px 0 0 var(--accent);
}

.lb .rank {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--muted);
    text-align: right;
}

.lb li:nth-child(-n+3) .rank {
    color: var(--accent);
}

.lb .who {
    min-width: 0;
    display: flex;
    flex-direction: column;
    line-height: 1.3;
}

.lb .nm {
    font-weight: 500;
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.lb .meta {
    font-family: var(--font-mono);
    font-size: 10.5px;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.lb .pts {
    font-family: var(--font-mono);
    font-size: 12.5px;
    font-weight: 500;
}

.lb-note {
    display: block !important;
    padding: 18px 12px !important;
    color: var(--muted);
    font-family: var(--font-mono);
    font-size: 12px;
    border-bottom: 0 !important;
}

.lb-note a {
    color: var(--accent);
}

/* ---------- main panes ---------- */

.main {
    flex: 1;
    min-width: 0;
    position: relative;
    display: grid;
    grid-template-columns: 1fr 380px;
    background: var(--bg-deep);
}

.main.map-big {
    grid-template-columns: 1fr 1fr;
}

.pane {
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    position: relative;
    isolation: isolate; /* keeps leaflet's own z-index inside the pane */
}

.map-pane {
    border-left: 1px solid var(--border);
}

.pane-head {
    flex: none;
    height: var(--toolbar-h);
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 12px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-surface);
}

.pane-title {
    flex: 1;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--text-2);
}

.timer {
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    min-width: 4ch;
    text-align: right;
}

.timer.low {
    color: var(--error);
}

.timebar {
    flex: none;
    height: 2px;
    background: var(--border);
}

.timebar-fill {
    height: 100%;
    width: 100%;
    background: var(--accent);
    transition: width 0.25s linear, background 0.3s;
}

.timebar-fill.low {
    background: var(--error);
}

.pano {
    flex: 1;
    min-height: 0;
    background: #0b0b0d;
}

.pano iframe {
    width: 100%;
    height: 100%;
    border: 0;
    display: block;
}

.pano-note {
    position: absolute;
    left: 12px;
    bottom: 12px;
    padding: 5px 9px;
    border: 1px solid var(--border);
    border-radius: 2px;
    background: rgba(17, 17, 19, 0.88);
    color: var(--text-2);
}

#map {
    flex: 1;
    min-height: 0;
    background: var(--bg-deep);
    cursor: crosshair;
}

.map-foot {
    flex: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 8px 12px;
    border-top: 1px solid var(--border);
    background: var(--bg-surface);
    font-size: 12.5px;
}

/* buttons */

.btn {
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-elevated);
    color: var(--text);
    font-weight: 600;
    font-size: 13.5px;
    white-space: nowrap;
    transition: background 0.15s, border-color 0.15s, transform 0.08s;
}

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

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

.btn.primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #111113;
}

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

.btn:disabled {
    opacity: 0.45;
    cursor: default;
}

/* ---------- overlays and cards ---------- */

.overlay {
    position: absolute;
    inset: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(17, 17, 19, 0.8);
    overflow-y: auto;
}

.card {
    width: min(520px, 100%);
    margin: auto;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--bg-surface);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.card.wide {
    width: min(600px, 100%);
}

.card-head {
    height: var(--toolbar-h);
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 12px;
    border-bottom: 1px solid var(--border);
    color: var(--muted);
}

.dots {
    display: inline-flex;
    gap: 5px;
}

.dots i {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #3a3a40;
}

.card-body {
    padding: 22px 24px 24px;
}

.card h1 {
    font-family: var(--font-brand);
    font-weight: 400;
    font-size: 46px;
    line-height: 1;
    margin-bottom: 14px;
}

.card h2 {
    font-size: 26px;
    font-weight: 700;
    line-height: 1.15;
    letter-spacing: -0.2px;
}

.card p {
    color: var(--text-2);
    margin-bottom: 14px;
}

.rules {
    list-style: none;
    margin: 0 0 18px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.rules li {
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
    color: var(--text-2);
}

.rules li:last-child {
    border-bottom: 0;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 5px;
    margin-bottom: 14px;
}

.field span {
    font-size: 12px;
    color: var(--muted);
}

.field input {
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-deep);
    color: var(--text);
    font: 500 14px var(--font-ui);
    outline: none;
}

.field input:focus {
    border-color: var(--accent);
}

.field input.bad {
    border-color: var(--error);
}

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

.row + .row {
    margin-top: 12px;
}

.history {
    margin-top: 18px;
    padding-top: 14px;
    border-top: 1px solid var(--border);
}

.history h3 {
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    margin-bottom: 6px;
}

.history ul {
    list-style: none;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.history li {
    padding: 3px 8px;
    border: 1px solid var(--border);
    border-radius: 2px;
    font-family: var(--font-mono);
    font-size: 11.5px;
    color: var(--text-2);
}

.history li.best {
    border-color: var(--accent);
    color: var(--accent);
}

.stats {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 14px 0;
}

.stats span {
    padding: 4px 9px;
    border: 1px solid var(--border);
    border-radius: 2px;
    color: var(--text-2);
}

.stats span:empty {
    display: none;
}

.stats span:last-child {
    border-color: var(--accent);
    color: var(--accent);
}

#result-map {
    height: 240px;
    margin-bottom: 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.rounds {
    width: 100%;
    border-collapse: collapse;
    margin: 14px 0 18px;
    font-size: 12px;
}

.rounds td, .rounds th {
    padding: 6px 8px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    white-space: nowrap;
}

.rounds th {
    font-weight: 500;
    color: var(--muted);
}

.rounds td.num, .rounds th.num {
    text-align: right;
}

.rounds td.place {
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text-2);
}

.save {
    padding: 14px;
    margin-bottom: 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-deep);
}

.save .field {
    margin-bottom: 10px;
}

.ok {
    color: var(--success);
}

.bad-text {
    color: var(--error);
}

/* ---------- statusbar ---------- */

.statusbar {
    flex: none;
    height: var(--statusbar-h);
    display: flex;
    align-items: center;
    gap: 18px;
    padding: 0 12px;
    border-top: 1px solid var(--border);
    background: var(--bg-surface);
    color: var(--text-2);
    font-size: 11.5px;
    white-space: nowrap;
    overflow: hidden;
}

.statusbar .grow {
    flex: 1;
}

.statusbar .sep {
    color: var(--border);
    margin: 0 -8px;
}

.statusbar .heart {
    color: var(--error);
}

/* ---------- leaflet on dark ---------- */

.leaflet-container {
    background: var(--bg-deep);
    font-family: var(--font-ui);
}

.dark-tiles {
    filter: invert(1) hue-rotate(180deg) brightness(0.82) contrast(0.92) saturate(0.55);
}

.leaflet-bar a {
    background: var(--bg-elevated);
    color: var(--text);
    border-bottom-color: var(--border);
}

.leaflet-bar a:hover {
    background: var(--bg-hover);
    color: var(--text);
}

.leaflet-bar {
    border: 1px solid var(--border);
    box-shadow: none;
}

.leaflet-control-attribution {
    background: rgba(17, 17, 19, 0.8);
    color: var(--muted);
    font-size: 10px;
}

.leaflet-control-attribution a {
    color: var(--text-2);
}

.pin {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--accent);
    border: 2px solid #111113;
    box-shadow: 0 0 0 2px var(--accent);
    animation: drop 0.18s ease-out;
}

.pin.actual {
    background: var(--success);
    box-shadow: 0 0 0 2px var(--success);
}

@keyframes drop {
    from { transform: scale(0.4); }
    to { transform: scale(1); }
}

.leaflet-popup-content-wrapper, .leaflet-popup-tip {
    background: var(--bg-elevated);
    color: var(--text);
    border: 1px solid var(--border);
    box-shadow: none;
    border-radius: var(--radius);
}

.leaflet-popup-content {
    margin: 8px 12px;
    font-size: 12.5px;
}

/* ---------- small screens ---------- */

@media (max-width: 900px) {
    body {
        overflow: auto;
    }

    .side-toggle {
        display: inline-block;
    }

    .topbar .tlink:not(.side-toggle) {
        display: none;
    }

    .body {
        position: relative;
    }

    .sidebar {
        position: absolute;
        top: 0;
        bottom: 0;
        left: 0;
        z-index: 30;
        width: min(300px, 88vw);
        transform: translateX(-100%);
        transition: transform 0.18s ease-out;
        box-shadow: 0 0 40px rgba(0, 0, 0, 0.6);
    }

    .sidebar.open {
        transform: none;
    }

    .main, .main.map-big {
        grid-template-columns: 1fr;
        grid-template-rows: minmax(0, 1.2fr) minmax(0, 1fr);
    }

    .map-pane {
        border-left: 0;
        border-top: 1px solid var(--border);
    }

    #map-size {
        display: none;
    }

    .card-body {
        padding: 18px 16px 20px;
    }

    .card h1 {
        font-size: 40px;
    }

    #result-map {
        height: 200px;
    }

    .statusbar {
        gap: 12px;
    }

    .statusbar .sep,
    .statusbar .sep + .muted {
        display: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        transition: none !important;
        animation: none !important;
    }
}
