/* Tabla — departure display for a Novi Pazar bus stop.
 *
 * Read at 2–5 m from a 43" kiosk, in direct sunlight or at night, in about
 * two seconds. Also opened on a phone. Design notes that are load-bearing:
 *
 *   One number wins. The countdown is roughly twice the line badge and three
 *   times the destination, so the eye always lands on it first. The previous
 *   revision set all three within a hair of each other and the board had no
 *   entry point.
 *
 *   Contrast by width, not weight. Countdowns are Archivo at a wide optical
 *   width so the figures read as physical objects; destinations are Barlow
 *   Semi Condensed because Novi Pazar's names are long ("Autobuska stanica –
 *   Netvrđe – Brđani"). Both fall back to system stacks — a kiosk that loses
 *   the network must not lose its countdown.
 *
 *   No cards. Drop shadows are invisible at three metres and noise up close.
 *   Rows are separated by a hairline and generous space.
 *
 *   Sparse is the normal state. The terminal stop shows two arrivals in
 *   ninety minutes on a Saturday; rows are top-aligned so a short board
 *   reads as finished rather than broken.
 *
 *   Palette comes from the city's coat of arms, not from taste: brass
 *   #c0a860 is the shield border and carries identity, roof red #d80000 is
 *   reserved for imminence, sky blue #0090d8 marks a live prediction.
 *   Neutrals are tinted toward the brass hue (91.5) so everything agrees.
 */

@import url("https://fonts.googleapis.com/css2?family=Archivo:wdth,wght@100..125,400..800&family=Barlow+Semi+Condensed:wght@400;500;600&display=swap");

:root {
    --brand-hue: 91.5;
    --brass: oklch(73.7% 0.096 91.5);
    --sky: oklch(62.5% 0.148 241.7);
    --roof: oklch(55.4% 0.227 29.2);

    --pad-block: 3.5vh;
    --pad-inline: 3vw;
    --radius: 6px;

    --font-figure: "Archivo", ui-sans-serif, system-ui, sans-serif;
    --font-text: "Barlow Semi Condensed", "Archivo Narrow", ui-sans-serif,
        system-ui, sans-serif;
}

/* Day. High contrast on a light ground: dark surfaces glare and wash out in
   direct sun, which is exactly when this screen is hardest to read. */
body[data-theme="light"] {
    --bg: oklch(98.2% 0.005 var(--brand-hue));
    --ink: oklch(21% 0.012 var(--brand-hue));
    --ink-soft: oklch(48% 0.014 var(--brand-hue));
    --ink-faint: oklch(66% 0.012 var(--brand-hue));
    --rule: oklch(88% 0.012 var(--brand-hue));
    --rule-strong: oklch(73.7% 0.096 91.5);
    --urgent: oklch(48% 0.21 29.2);
    --live: oklch(52% 0.14 241.7);
    --notice-bg: oklch(94% 0.05 91.5);
    --notice-ink: oklch(35% 0.07 70);
    --alarm-bg: oklch(93% 0.06 29.2);
    --alarm-ink: oklch(40% 0.16 29.2);
}

/* Night. Warm and low-glare rather than an inverted day theme — an
   unattended screen burning white into an empty street at 3 a.m. is both
   unpleasant and conspicuous. */
body[data-theme="dark"] {
    --bg: oklch(17% 0.012 var(--brand-hue));
    --ink: oklch(94% 0.012 var(--brand-hue));
    --ink-soft: oklch(70% 0.014 var(--brand-hue));
    --ink-faint: oklch(52% 0.012 var(--brand-hue));
    --rule: oklch(30% 0.014 var(--brand-hue));
    --rule-strong: oklch(68% 0.085 91.5);
    --urgent: oklch(70% 0.17 33);
    --live: oklch(72% 0.12 241.7);
    --notice-bg: oklch(28% 0.045 91.5);
    --notice-ink: oklch(86% 0.06 91.5);
    --alarm-bg: oklch(30% 0.09 29.2);
    --alarm-ink: oklch(84% 0.11 29.2);
}

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

html, body { height: 100%; overflow: hidden; }

body {
    display: grid;
    grid-template-rows: auto 1fr auto;
    gap: 2.5vh;
    padding: var(--pad-block) var(--pad-inline);
    background: var(--bg);
    color: var(--ink);
    font-family: var(--font-text);
    font-variant-numeric: tabular-nums;
    line-height: 1.1;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

/* --- Header: crest, stop, clock ---------------------------------- */

/* On a portrait screen the crest and the clock leave the stop name roughly
   450px of a 1080px board, and "Autobuska stanica" truncates. So portrait
   gives the name a full-width row of its own; landscape has the width to
   keep all three on one line. */
.head {
    display: grid;
    align-items: center;
    column-gap: 2.2vw;
    padding-bottom: 2vh;
    /* The one decorative move on the board: a brass rule under the header,
       the same brass as the shield border above it. */
    border-bottom: 3px solid var(--rule-strong);
}

body.portrait .head {
    grid-template-columns: auto 1fr auto;
    grid-template-areas:
        "crest .    clock"
        "stop  stop stop";
    row-gap: 1.6vh;
}

body.landscape .head {
    grid-template-columns: auto 1fr auto;
    grid-template-areas: "crest stop clock";
}

.crest { grid-area: crest; }
.stop { grid-area: stop; }
.clock { grid-area: clock; }

.crest { height: 9.5vh; width: auto; display: block; }
body.portrait .crest { height: 9vw; }

.stop { min-width: 0; }

.stop h1 {
    font-size: 7vh;
    font-weight: 600;
    letter-spacing: -0.005em;
    line-height: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.stop-code {
    display: inline-block;
    margin-top: 1vh;
    color: var(--ink-faint);
    font-size: 2.5vh;
    font-weight: 500;
    letter-spacing: 0.16em;
    text-transform: uppercase;
}

.clock {
    font-family: var(--font-figure);
    font-variation-settings: "wdth" 112;
    font-size: 6.4vh;
    font-weight: 500;
    color: var(--ink-soft);
    line-height: 1;
}

.logo img { height: 7vh; width: auto; object-fit: contain; }

/* --- Arrivals ----------------------------------------------------- */

main { min-height: 0; overflow: hidden; }

.arrivals {
    list-style: none;
    display: grid;
    grid-auto-rows: min-content;
    /* Top-aligned: two arrivals should read as the whole of today's news,
       not as four rows that failed to load. */
    align-content: start;
}

.row {
    display: grid;
    grid-template-columns: minmax(7.5vw, auto) 1fr auto;
    align-items: center;
    column-gap: 2.4vw;
    padding: 2.4vh 0;
    border-bottom: 1px solid var(--rule);
}

.row:last-child { border-bottom: 0; }

/* Line badge. Fixed minimum width so badges stack into a column the eye can
   run down looking for its own line — the primary scan on this board. */
.badge {
    justify-self: start;
    min-width: 7.5vw;
    padding: 0.9vh 1.4vw;
    border-radius: var(--radius);
    background: var(--ink);
    color: var(--bg);
    font-family: var(--font-figure);
    font-variation-settings: "wdth" 100;
    font-size: 6.2vh;
    font-weight: 700;
    letter-spacing: -0.01em;
    line-height: 1.05;
    text-align: center;
    /* background + color are overwritten inline from lineColors */
}

.dest {
    min-width: 0;
    font-size: 5vh;
    font-weight: 500;
    color: var(--ink);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Countdown. The one thing legible from across the street. */
.when {
    display: flex;
    align-items: baseline;
    justify-content: flex-end;
    gap: 0.7vw;
    min-width: 15vw;
    font-family: var(--font-figure);
}

.when .n {
    font-variation-settings: "wdth" 118;
    font-size: 13vh;
    font-weight: 800;
    line-height: 0.82;
    letter-spacing: -0.02em;
    color: var(--ink);
}

.when .u {
    font-family: var(--font-text);
    font-size: 3vh;
    font-style: normal;
    font-weight: 600;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--ink-faint);
}

/* "sada" is a word, not a figure, so it takes the text face and the roof
   red. It is the only red on the board, which is what makes it work. */
.when .now {
    font-family: var(--font-text);
    font-variation-settings: normal;
    font-size: 8.5vh;
    font-weight: 600;
    letter-spacing: -0.01em;
    line-height: 0.9;
    color: var(--urgent);
}

.row.imminent .when .n { color: var(--urgent); }

/* Beyond an hour the board shows a departure time instead of a countdown.
   It is set a shade smaller than the figure — a time an hour away does not
   need to shout across the street the way "4 min" does. */
.when .at {
    font-variation-settings: "wdth" 112;
    font-size: 8vh;
    font-weight: 600;
    line-height: 0.9;
    letter-spacing: -0.01em;
    color: var(--ink-soft);
}

/* Live vs timetable. A filled dot reads at distance where an italic or a
   tilde does not; scheduled rows simply lack it and sit slightly back. */
.when .live-dot {
    align-self: center;
    width: 1.5vh;
    height: 1.5vh;
    border-radius: 50%;
    background: var(--live);
    flex: none;
}

.row.scheduled .dest,
.row.scheduled .when .n { color: var(--ink-soft); }

/* After the dimming, so imminence wins: two minutes is two minutes whether
   a tracker or the timetable said so. The dot carries the difference. */
.row.imminent .when .n,
.row.scheduled.imminent .when .n { color: var(--urgent); }

.row.empty {
    display: block;
    padding: 6vh 0;
    border-bottom: 0;
    color: var(--ink-faint);
    font-size: 4vh;
    font-weight: 500;
}

/* --- Landscape: two columns of arrivals --------------------------- */

/* Portrait sizes from viewport WIDTH. The board is 1080x1920: a 7vh heading
   is 134px tall in a box 1080px wide, which no stop name survives. */
body.portrait .stop h1 { font-size: 6.2vw; }
body.portrait .stop-code { font-size: 2.2vw; }
body.portrait .clock { font-size: 5.4vw; }
body.portrait .badge { min-width: 13vw; font-size: 5.6vw; padding: 1vw 1.6vw; }
body.portrait .dest { font-size: 4.4vw; }
body.portrait .when { min-width: 26vw; }
body.portrait .when .n { font-size: 12vw; }
body.portrait .when .u { font-size: 2.6vw; }
body.portrait .when .now { font-size: 8vw; }
body.portrait .when .at { font-size: 7.4vw; }
/* Sparse is normal — two arrivals on a 1920px board. Taller rows let them
   occupy the space with intent instead of huddling at the top. */
body.portrait .row { padding: 3.4vh 0; }

body.landscape .arrivals { grid-template-columns: 1fr 1fr; column-gap: 4vw; }
body.landscape .row { column-gap: 1.8vw; }
body.landscape .when .n { font-size: 11vh; }
body.landscape .when .at { font-size: 7vh; }
body.landscape .badge { min-width: 5.5vw; font-size: 5.4vh; }
body.landscape .dest { font-size: 4.2vh; }

/* --- Footer, staleness, failure ----------------------------------- */

/* Three children that come and go independently — staleness, alerts and the
   operator name — so flex with an auto margin rather than a fixed grid. */
footer {
    display: flex;
    align-items: center;
    flex-wrap: nowrap;
    gap: 1.6vw;
    padding-top: 1.6vh;
    border-top: 1px solid var(--rule);
    color: var(--ink-faint);
    font-size: 2.4vh;
    font-weight: 500;
}

.alerts-strip {
    padding: 1vh 1.4vw;
    border-radius: var(--radius);
    background: var(--notice-bg);
    color: var(--notice-ink);
    font-size: 2.6vh;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.operator { margin-left: auto; letter-spacing: 0.04em; text-align: right; white-space: nowrap; }

#alerts { min-width: 0; }

/* A screen that has stopped receiving data must say so. Silence here would
   leave a rider trusting a countdown that froze ten minutes ago. */
.staleness {
    flex: none;
    padding: 0.9vh 1.4vw;
    border-radius: var(--radius);
    background: var(--notice-bg);
    color: var(--notice-ink);
    font-size: 2.6vh;
    font-weight: 600;
}

.staleness.offline { background: var(--alarm-bg); color: var(--alarm-ink); }

.fatal {
    display: grid;
    place-content: center;
    gap: 2vh;
    height: 100%;
    padding: 6vw;
    text-align: center;
    color: var(--ink);
}

.fatal h1 {
    font-family: var(--font-figure);
    font-variation-settings: "wdth" 115;
    font-size: 9vh;
    font-weight: 700;
}

.fatal p { font-size: 3.4vh; color: var(--ink-soft); }

/* No entrance animation on rows. The countdown re-renders the list every
   second, so any animation restarts every second: the board would sit
   permanently mid-fade and flicker in the street. Departure boards change
   by replacing a number, not by moving. */

/* Phone. The board is built for a wall; on a handset the vh scale would
   give a countdown the height of a thumbnail, so it re-pins to viewport
   width. */
@media (max-width: 700px) {
    body { padding: 4vw; gap: 3vw; }
    .crest { height: 11vw; }
    .stop h1 { font-size: 7.5vw; }
    .stop-code { font-size: 3.2vw; margin-top: 1.4vw; }
    .clock { font-size: 6.5vw; }
    .row { padding: 3.4vw 0; column-gap: 4vw; grid-template-columns: minmax(16vw, auto) 1fr auto; }
    .badge { min-width: 16vw; font-size: 7vw; padding: 1.2vw 2.4vw; }
    .dest { font-size: 5.4vw; }
    .when { min-width: 26vw; gap: 1.6vw; }
    .when .n { font-size: 15vw; }
    .when .u { font-size: 3.2vw; }
    .when .now { font-size: 9.5vw; }
    .when .live-dot { width: 2.2vw; height: 2.2vw; }
    footer { font-size: 3vw; }
    .alerts-strip, .staleness { font-size: 3.2vw; }
}
