@import url("https://cdn.jsdelivr.net/npm/@fontsource/cascadia-code@4.2.1/index.css");

:root {
    /* Near-black background — the board panel */
    --bg: #0a0a08;
    --surface: #0e0e0c;
    --surface2: #121210;
    --surface3: #161614;
    --border: #222220;
    --border2: #2c2c28;

    /* Dot-matrix warm yellow */
    --amber: #e8a800;
    --amber-dim: #906000;
    --amber-glow: rgba(232, 168, 0, 0.12);

    /* White for headers/labels */
    --white: #e8e8e8;
    --white-dim: #8a8a88;
    --muted: #484844;
    --muted2: #222220;

    --red: #e03030;
    --green: #40c060;
    --green-glow: rgba(64, 192, 96, 0.3);

    /* Section header — same dark bg, white sans text */
    --header-bg: #080808;
    --header-border: #202020;
}

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

body {
    background: var(--bg);
    color: var(--white);
    font-family: "Cascadia Code", monospace;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Scanlines */
body::after {
    content: "";
    position: fixed;
    inset: 0;
    background: repeating-linear-gradient(
        0deg,
        transparent,
        transparent 3px,
        rgba(0, 0, 0, 0.07) 3px,
        rgba(0, 0, 0, 0.07) 4px
    );
    pointer-events: none;
    z-index: 9999;
}

/* ── Header ── */
header {
    display: flex;
    align-items: center;
    gap: 24px;
    padding: 0 28px;
    height: 68px;
    background: var(--header-bg);
    border-bottom: 1px solid var(--header-border);
    flex-shrink: 0;
    position: relative;
}

.header-brand {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.logo {
    font-size: 26px;
    font-weight: 700;
    letter-spacing: 0.01em;
    color: var(--white);
}
.logo-sub {
    font-size: 11px;
    color: var(--white-dim);
    letter-spacing: 0.04em;
    font-weight: 400;
}

/* Header right group */
.header-right {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 20px;
}
.about-link {
    background: none;
    border: 1px solid var(--border2);
    border-radius: 50%;
    font-family: inherit;
    font-size: 0;
    color: var(--white-dim);
    cursor: pointer;
    padding: 0;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.15s, border-color 0.15s;
}
.about-link::after {
    content: "?";
    font-size: 14px;
    color: var(--white-dim);
    transition: color 0.15s;
}
.about-link:hover {
    border-color: var(--amber-dim);
}
.about-link:hover::after {
    color: var(--amber);
}

/* Live indicator */
.live-badge {
    display: flex;
    align-items: center;
    gap: 7px;
    background: rgba(64, 192, 96, 0.06);
    border: 1px solid rgba(64, 192, 96, 0.2);
    border-radius: 999px;
    padding: 0 12px 0 10px;
    height: 28px;
}
.live-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--green);
    flex-shrink: 0;
    position: relative;
    animation: live-dot-flash 1.6s ease-in-out infinite;
}
.live-dot::after {
    content: "";
    position: absolute;
    inset: -5px;
    border-radius: 50%;
    background: rgba(64, 192, 96, 0.35);
    animation: live-ring 1.6s ease-out infinite;
}
@keyframes live-dot-flash {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.25; }
}
@keyframes live-ring {
    0%   { transform: scale(0.4); opacity: 1; }
    100% { transform: scale(2.2); opacity: 0; }
}
.live-label {
    font-size: 11px;
    font-weight: 700;
    color: var(--green);
    letter-spacing: 0.14em;
    text-transform: uppercase;
}

/* ── Layout ── */
main {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 32px 16px 48px;
    background: var(--bg);
}

#stats-block {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    min-height: 480px;
}

/* ── Month nav ── */
.month-nav {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    width: 100%;
    max-width: 900px;
    margin-bottom: 28px;
}
.month-nav .nav-btn:first-child {
    justify-self: start;
}
.month-nav .nav-btn:last-child {
    justify-self: end;
}

.month-label {
    font-size: 15px;
    font-weight: 600;
    color: var(--white-dim);
    letter-spacing: 0.06em;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

/* Nav loading indicator */
.nav-spinner {
    display: none;
    align-items: center;
    gap: 3px;
}
.nav-spinner.htmx-request {
    display: inline-flex;
}
.nav-spinner-dot {
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: var(--amber);
    animation: dep-bounce 1.2s ease-in-out infinite;
}
.nav-spinner-dot:nth-child(2) { animation-delay: 0.2s; }
.nav-spinner-dot:nth-child(3) { animation-delay: 0.4s; }
.nav-btn {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--white-dim);
    padding: 7px 16px;
    border-radius: 2px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition:
        border-color 0.15s,
        color 0.15s,
        background 0.15s;
    letter-spacing: 0.04em;
}
.nav-btn:hover {
    color: var(--amber);
    border-color: var(--amber-dim);
    background: rgba(232, 168, 0, 0.04);
}

/* ── Board ── */
.board {
    width: 100%;
    max-width: 900px;
    border: 1px solid var(--border2);
    border-radius: 2px;
    overflow: hidden;
    margin-bottom: 24px;
}

/* Amber header bar — like the top strip of a departure board */
.board-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: var(--header-bg);
    border-bottom: 1px solid var(--border);
}
.board-header-label {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: 0.01em;
    color: var(--white);
}
.board-header-tag {
    font-size: 14px;
    font-weight: 400;
    color: var(--white-dim);
}

/* Hero numbers */
.hero {
    display: flex;
    flex-wrap: wrap;
    align-items: stretch;
    background: var(--surface);
    border-top: none;
}
.hero-item {
    flex: 1;
    text-align: center;
    padding: 32px 16px;
    border-right: 1px solid var(--border);
}
.hero-item:last-child {
    border-right: none;
}
.hero-item--full {
    flex-basis: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
}

.hero-number {
    font-size: clamp(28px, 6vw, 72px);
    font-weight: 800;
    line-height: 1;
    letter-spacing: -1px;
    color: var(--amber);
    font-variant-numeric: tabular-nums;
}
.hero-label {
    font-size: 14px;
    color: var(--white-dim);
    margin-top: 10px;
    letter-spacing: 0.04em;
    font-weight: 400;
}

/* Unit toggle buttons */
.unit-btns {
    display: flex;
    justify-content: center;
    gap: 6px;
    margin-top: 14px;
}
.unit-btn {
    background: var(--surface2);
    border: 1px solid var(--border2);
    color: var(--white-dim);
    font-family: inherit;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.08em;
    padding: 4px 12px;
    border-radius: 2px;
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.unit-btn:hover {
    color: var(--white);
    border-color: var(--amber-dim);
}
.unit-btn--active {
    background: var(--amber-glow);
    border-color: var(--amber-dim);
    color: var(--amber);
}

/* Sub stats */
.sub-stats {
    display: flex;
    background: var(--surface2);
    border-top: 1px solid var(--border);
}
.sub-item {
    flex: 1;
    text-align: center;
    padding: 16px 8px;
    border-right: 1px solid var(--border);
    position: relative;
}
.sub-item:last-child {
    border-right: none;
}
.sub-value {
    font-size: 26px;
    font-weight: 700;
    color: var(--white);
    letter-spacing: -0.5px;
    font-variant-numeric: tabular-nums;
}
.sub-label {
    font-size: 11px;
    color: var(--white-dim);
    letter-spacing: 0.04em;
    margin-top: 6px;
}

/* ── Operators ── */
.operators {
    width: 100%;
    max-width: 900px;
    border: 1px solid var(--border2);
    border-radius: 2px;
    overflow: hidden;
}

.op-table-head {
    display: flex;
    align-items: center;
    padding: 6px 14px;
    background: var(--header-bg);
    border-bottom: 1px solid var(--border);
    gap: 10px;
}
.op-table-head-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--white-dim);
    letter-spacing: 0.08em;
}
.op-table-head-label.right {
    margin-left: auto;
}

.op-list {
    display: flex;
    flex-direction: column;
}

.op-card {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 10px 14px 8px;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px 8px;
    transition: background 0.1s;
    position: relative;
}
.op-card:last-child {
    border-bottom: none;
}
.op-card:nth-child(even) {
    background: var(--surface2);
}
.op-card:hover {
    background: var(--surface3);
}
.op-card[hx-get] {
    cursor: pointer;
}
.op-card:hover .op-chevron {
    color: var(--amber);
}

.op-chevron {
    font-size: 18px;
    color: var(--muted);
    flex-shrink: 0;
    transition: color 0.15s;
    line-height: 1;
}


.op-rank {
    font-size: 17px;
    font-weight: 700;
    width: 26px;
    flex-shrink: 0;
    color: var(--muted);
    margin-right: 4px;
}
.rank-1 .op-rank,
.rank-2 .op-rank,
.rank-3 .op-rank {
    color: var(--amber);
}

.op-name {
    font-size: 20px;
    font-weight: 700;
    color: var(--white);
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.op-card:not(.rank-1):not(.rank-2):not(.rank-3) .op-name {
    color: var(--white-dim);
    font-weight: 400;
}

.op-bar-wrap {
    flex-basis: 100%;
    order: 99;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 2px;
}
.op-bar-pct {
    font-size: 11px;
    color: var(--muted);
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
    flex-shrink: 0;
}
.op-bar-pct.pct-low {
    color: var(--green);
}
.op-bar-pct.pct-mid {
    color: var(--amber);
}
.op-bar-pct.pct-high {
    color: var(--red);
}
.op-bar-track {
    flex: 1;
    height: 3px;
    background: var(--border2);
    border-radius: 1px;
    position: relative;
}
.op-bar-fill {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    background: var(--amber);
    transition: width 0.6s ease;
    border-radius: 1px;
}
.op-card:not(.rank-1):not(.rank-2):not(.rank-3) .op-bar-fill {
    background: var(--muted);
}

.op-delay {
    font-size: 20px;
    font-weight: 700;
    color: var(--amber);
    white-space: nowrap;
    min-width: 0;
    text-align: right;
    font-variant-numeric: tabular-nums;
    margin-left: auto;
    margin-right: 4px;
}
.op-card:not(.rank-1):not(.rank-2):not(.rank-3) .op-delay {
    color: var(--white-dim);
    font-weight: 400;
}

.op-meta {
    font-size: 11px;
    color: var(--muted);
    text-align: right;
    min-width: 0;
    flex-shrink: 0;
    font-variant-numeric: tabular-nums;
}

/* ── Misc ── */
.no-data {
    color: var(--muted);
    font-size: 13px;
    text-align: center;
    margin-top: 60px;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

footer {
    text-align: center;
    padding: 16px;
    color: var(--muted);
    font-size: 11px;
    border-top: 1px solid var(--border);
    background: var(--bg);
    letter-spacing: 0.08em;
    text-transform: uppercase;
}
footer a {
    color: var(--white-dim);
    text-decoration: none;
}
footer a:hover {
    color: var(--amber);
}

/* ── Modal ── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    padding: 20px;
    transition: opacity 0.2s;
}
.modal-overlay[aria-hidden="true"] {
    opacity: 0;
    pointer-events: none;
}
.modal-overlay[aria-hidden="false"] {
    opacity: 1;
    pointer-events: all;
}

.modal-box {
    background: var(--surface);
    border: 1px solid var(--border2);
    border-radius: 3px;
    width: 100%;
    max-width: 560px;
    max-height: 85vh;
    overflow-y: auto;
    padding: 32px;
    position: relative;
}

.modal-close {
    position: absolute;
    top: 16px;
    right: 16px;
    background: none;
    border: none;
    color: var(--white-dim);
    font-size: 18px;
    cursor: pointer;
    line-height: 1;
    padding: 4px 8px;
    transition: color 0.1s;
}
.modal-close:hover {
    color: var(--white);
}

.modal-title {
    font-size: 22px;
    font-weight: 700;
    color: var(--amber);
    margin-bottom: 16px;
    padding-right: 32px;
}

.modal-lead {
    font-size: 14px;
    color: var(--white-dim);
    line-height: 1.7;
    padding: 12px 14px;
    border-left: 3px solid var(--amber);
    background: var(--surface2);
    margin-bottom: 24px;
}

.modal-section {
    margin-bottom: 20px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border);
}
.modal-section:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.modal-h2 {
    font-size: 11px;
    color: var(--amber);
    letter-spacing: 0.15em;
    text-transform: uppercase;
    margin-bottom: 8px;
}

.modal-p {
    font-size: 14px;
    color: var(--white-dim);
    line-height: 1.7;
}

.modal-highlight {
    color: var(--amber);
}

.modal-code {
    background: var(--surface2);
    border: 1px solid var(--border2);
    color: var(--white);
    padding: 1px 5px;
    border-radius: 2px;
    font-size: 12px;
}

.modal-link {
    color: var(--white);
}
.modal-link:hover {
    color: var(--amber);
}

.modal-box--wide {
    max-width: 700px;
}

/* ── Departures list ── */
.dep-header {
    display: flex;
    align-items: baseline;
    gap: 12px;
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
}
.dep-title {
    font-size: 22px;
    font-weight: 700;
    color: var(--amber);
}
.dep-count {
    font-size: 11px;
    color: var(--muted);
    letter-spacing: 0.05em;
}
.dep-list {
    display: flex;
    flex-direction: column;
    gap: 0;
}
.dep-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 7px 4px;
    border-bottom: 1px solid var(--border);
}
.dep-row:last-child {
    border-bottom: none;
}
.dep-row:nth-child(even) {
    background: var(--surface2);
}
.dep-main {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
    min-width: 0;
}
.dep-top,
.dep-bottom {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
}
.dep-time-clock {
    color: var(--white-dim);
    font-size: 13px;
    font-variant-numeric: tabular-nums;
    flex-shrink: 0;
}
.dep-time-date {
    color: var(--muted);
    font-size: 11px;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    flex-shrink: 0;
}
.dep-from {
    color: var(--white-dim);
    font-size: 13px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}
.dep-to {
    color: var(--white);
    font-size: 13px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}
.dep-arrow {
    color: var(--muted);
    font-size: 10px;
    flex-shrink: 0;
}
.dep-train {
    font-size: 11px;
    color: var(--muted);
    white-space: nowrap;
}
.dep-delay {
    font-size: 12px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    flex-shrink: 0;
}
.dep-delay.dep-low  { color: var(--green); }
.dep-delay.dep-mid  { color: var(--amber); }
.dep-delay.dep-high { color: var(--red); }
.dep-delay.dep-canceled { color: var(--muted); font-weight: 400; }

.dep-spinner {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 6px;
    padding: 32px 0;
}
.dep-spinner-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--amber);
    animation: dep-bounce 1.2s ease-in-out infinite;
}
.dep-spinner-dot:nth-child(2) { animation-delay: 0.2s; }
.dep-spinner-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes dep-bounce {
    0%, 80%, 100% { opacity: 0.2; transform: scale(0.8); }
    40%            { opacity: 1;   transform: scale(1); }
}
.dep-empty {
    color: var(--muted);
    font-size: 13px;
    padding: 24px 0;
    text-align: center;
}

/* ── Mobile ── */
@media (max-width: 640px) {
    header {
        padding: 0 14px;
        height: 54px;
        gap: 12px;
    }
    .logo {
        font-size: 16px;
    }
    .logo-sub {
        display: none;
    }
    .live-badge {
        padding: 4px 10px 4px 8px;
        gap: 6px;
    }
    .live-label {
        font-size: 10px;
    }

    main {
        padding: 20px 10px 36px;
    }

    .month-nav {
        margin-bottom: 20px;
    }
    .nav-btn {
        padding: 6px 10px;
        font-size: 10px;
    }
    .month-label {
        font-size: 11px;
        letter-spacing: 0.15em;
    }

    .hero {
        flex-direction: column;
    }
    .hero-item {
        width: 100%;
        padding: 22px 16px;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }
    .hero-item:last-child {
        border-bottom: none;
    }
    .hero-number {
        font-size: clamp(24px, 10vw, 56px);
    }

    .sub-stats {
        display: grid;
        grid-template-columns: 1fr 1fr;
    }
    .sub-item {
        border-right: 1px solid var(--border);
        border-bottom: 1px solid var(--border);
        padding: 14px 8px;
    }
    .sub-item:nth-child(2n) {
        border-right: none;
    }
    .sub-item:nth-last-child(-n+2) {
        border-bottom: none;
    }
    .sub-value {
        font-size: 20px;
    }
    .sub-label {
        font-size: 11px;
    }

    .op-name {
        font-size: 14px;
    }
    .op-chevron {
        font-size: 14px;
    }
    .op-delay {
        font-size: 14px;
    }
    .op-rank {
        font-size: 12px;
        width: 22px;
    }
    .op-bar-track {
        height: 5px;
    }
    .op-card {
        padding: 12px 14px 10px;
    }

    .board-header {
        padding: 8px 12px;
    }
    .board-header-label {
        font-size: 14px;
    }
    .op-table-head {
        padding: 7px 10px;
    }

    footer {
        font-size: 9px;
        padding: 12px;
    }

    /* Bottom sheet modal on mobile */
    .modal-overlay {
        align-items: flex-end;
        padding: 0;
    }
    .modal-box {
        max-width: 100%;
        max-height: 85vh;
        border-radius: 12px 12px 0 0;
        padding: 24px 16px 40px;
    }
    .dep-header {
        flex-wrap: wrap;
    }
    .dep-row {
        padding: 10px 6px;
    }
}

@media (max-width: 400px) {
    .hero-number {
        font-size: clamp(20px, 10vw, 48px);
    }
}
