/* Shared chrome for the live traffic pages. Night-time version of the site palette. */
:root {
    --bg-color: #F8F4E3;
    --text-color: #49306B;
    --accent-color: #ADBDFF;
    --cta-color: #F28482;
    --dark-color: #0D160B;
    --night: #0D160B;
    --ink: #F8F4E3;
    --ink-dim: rgba(248, 244, 227, 0.62);
    --ink-faint: rgba(248, 244, 227, 0.32);
    --panel: rgba(13, 22, 11, 0.72);
    --panel-edge: rgba(173, 189, 255, 0.18);
    /* Room for a phone's rounded corners, notch and home bar (needs
       viewport-fit=cover). Zero everywhere else. */
    --safe-t: env(safe-area-inset-top, 0px);
    --safe-r: env(safe-area-inset-right, 0px);
    --safe-b: env(safe-area-inset-bottom, 0px);
    --safe-l: env(safe-area-inset-left, 0px);
}

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

html, body {
    height: 100%;
    overflow: hidden;
    background: var(--night);
    color: var(--ink);
    font-family: 'Funnel Display', -apple-system, BlinkMacSystemFont, sans-serif;
    -webkit-font-smoothing: antialiased;
}

canvas#stage {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
    touch-action: none;
}

.tf-top {
    position: fixed;
    top: 0; left: 0; right: 0;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    padding: calc(1.1rem + var(--safe-t)) calc(1.25rem + var(--safe-r)) 1.1rem calc(1.25rem + var(--safe-l));
    pointer-events: none;
    z-index: 5;
    background: linear-gradient(180deg, rgba(13, 22, 11, 0.85) 0%, rgba(13, 22, 11, 0) 100%);
}
.tf-top > * { pointer-events: auto; }

.tf-title h1 {
    font-family: 'Londrina Shadow', 'Funnel Display', sans-serif;
    font-weight: 400;
    font-size: clamp(2rem, 5vw, 3.1rem);
    line-height: 1;
    letter-spacing: 0.02em;
    color: var(--ink);
}
.tf-title p {
    margin-top: 0.35rem;
    max-width: 34rem;
    font-size: 0.92rem;
    line-height: 1.4;
    color: var(--ink-dim);
}
.tf-title p strong { color: var(--ink); font-weight: 500; }

.tf-about { margin-top: 0.45rem; max-width: 34rem; font-size: 0.8rem; color: var(--ink-dim); }
.tf-about summary { cursor: pointer; width: fit-content; color: var(--accent-color); list-style-position: inside; }
.tf-about summary:hover, .tf-about summary:focus-visible { color: var(--ink); outline: none; }
.tf-about[open] { padding: 0.6rem 0.8rem 0.7rem; background: rgba(13, 22, 11, 0.94); border: 1px solid var(--panel-edge); border-radius: 12px; }
.tf-about p { margin-top: 0.45rem; font-size: 0.8rem; line-height: 1.5; max-width: none; }

.tf-nav {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
}
.tf-nav a {
    color: var(--ink-dim);
    text-decoration: none;
    padding: 0.3rem 0.7rem;
    border: 1px solid var(--panel-edge);
    border-radius: 999px;
    background: var(--panel);
    transition: all 0.3s ease;
    white-space: nowrap;
}
.tf-nav a:hover, .tf-nav a:focus-visible { color: var(--night); background: var(--accent-color); border-color: var(--accent-color); outline: none; }

.tf-motion {
    font: inherit;
    color: var(--ink-dim);
    padding: 0.3rem 0.7rem;
    border: 1px solid var(--panel-edge);
    border-radius: 999px;
    background: var(--panel);
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.3s ease;
}
.tf-motion:hover, .tf-motion:focus-visible { color: var(--night); background: var(--accent-color); border-color: var(--accent-color); outline: none; }
.tf-motion[data-motion="calm"], .tf-motion[data-motion="still"] { color: var(--ink); border-color: var(--accent-color); }

.tf-status {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.3rem 0.7rem;
    border-radius: 999px;
    border: 1px solid var(--panel-edge);
    background: var(--panel);
    color: var(--ink-dim);
    white-space: nowrap;
}
.tf-status::before {
    content: '';
    width: 0.5rem; height: 0.5rem;
    border-radius: 50%;
    background: var(--ink-faint);
}
.tf-status[data-state="live"] { color: var(--ink); }
.tf-status[data-state="live"]::before { background: #A8DADC; box-shadow: 0 0 8px #A8DADC; animation: tf-pulse 2.4s ease-in-out infinite; }
.tf-status[data-state="simulated"] { color: var(--night); background: var(--cta-color); border-color: var(--cta-color); font-weight: 500; }
.tf-status[data-state="simulated"]::before { background: var(--night); }
@keyframes tf-pulse { 50% { opacity: 0.35; } }

.tf-transport {
    position: fixed;
    left: 50%;
    bottom: calc(3.4rem + var(--safe-b));
    transform: translateX(-50%);
    z-index: 6;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.55rem;
    border-radius: 999px;
    background: var(--panel);
    border: 1px solid var(--panel-edge);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    font-size: 0.8rem;
    white-space: nowrap;
}
.tf-transport[data-mode="replay"] { border-color: var(--cta-color); }
.tf-transport button {
    font: inherit;
    color: var(--ink);
    background: rgba(173, 189, 255, 0.12);
    border: 1px solid var(--panel-edge);
    border-radius: 999px;
    padding: 0.28rem 0.7rem;
    min-width: 2.3rem;
    cursor: pointer;
    transition: all 0.2s ease;
}
.tf-transport button:hover:not(:disabled), .tf-transport button:focus-visible { background: var(--accent-color); color: var(--night); outline: none; }
.tf-transport .tt-live::before { content: ''; display: inline-block; width: 0.45rem; height: 0.45rem; margin-right: 0.4rem; border-radius: 50%; background: var(--ink-faint); vertical-align: middle; }
.tf-transport .tt-live:disabled { cursor: default; color: var(--ink); background: transparent; }
.tf-transport .tt-live:disabled::before { background: #A8DADC; box-shadow: 0 0 8px #A8DADC; }
.tf-transport[data-mode="replay"] .tt-live { background: var(--cta-color); border-color: var(--cta-color); color: var(--night); font-weight: 500; }
.tf-transport[data-mode="replay"] .tt-live::before { background: var(--night); }
.tf-transport .tt-time { font-family: ui-monospace, 'SF Mono', Menlo, monospace; font-size: 0.74rem; color: var(--ink-dim); min-width: 2.2rem; text-align: center; }
.tf-transport[data-mode="replay"] .tt-time { min-width: 9.5rem; color: var(--ink); }
.tf-transport input[type="range"] { width: clamp(6rem, 18vw, 16rem); accent-color: var(--accent-color); cursor: pointer; }
.tf-transport[data-mode="replay"] input[type="range"] { accent-color: var(--cta-color); }
.tf-transport [hidden] { display: none; }

.tf-panel {
    position: fixed;
    z-index: 5;
    background: var(--panel);
    border: 1px solid var(--panel-edge);
    border-radius: 14px;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    padding: 0.85rem 1rem;
    font-size: 0.85rem;
}
.tf-panel h2 {
    font-size: 0.7rem;
    font-weight: 500;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--ink-faint);
    margin-bottom: 0.5rem;
}

.tf-legend { left: calc(1.25rem + var(--safe-l)); bottom: calc(3.4rem + var(--safe-b)); min-width: 14.5rem; }
.tf-legend ul { list-style: none; }
.tf-legend li {
    display: grid;
    grid-template-columns: 1.3rem 1fr auto;
    align-items: center;
    gap: 0.4rem;
    padding: 0.12rem 0;
    color: var(--ink-dim);
}
.tf-legend li[data-on="1"] { color: var(--ink); }
.tf-legend .g {
    font-family: ui-monospace, 'SF Mono', Menlo, monospace;
    font-weight: 700;
    text-align: center;
    text-shadow: 0 0 8px currentColor;
}
.tf-legend .n { font-variant-numeric: tabular-nums; font-family: ui-monospace, 'SF Mono', Menlo, monospace; font-size: 0.8rem; }
.tf-legend .foot { margin-top: 0.55rem; padding-top: 0.5rem; border-top: 1px solid var(--panel-edge); color: var(--ink-dim); font-size: 0.78rem; line-height: 1.45; }
.tf-legend .foot b { color: var(--ink); font-weight: 500; font-variant-numeric: tabular-nums; }
/* busy site: only a sample of visitors is drawn (lightning-bugs.js, "density") */
.tf-sample { margin-top: 0.4rem; color: var(--accent-color); font-size: 0.78rem; font-variant-numeric: tabular-nums; cursor: help; }
.tf-sample[hidden], .tf-sample-short { display: none; }

.tf-ticker {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 5;
    padding: 0.7rem calc(1.25rem + var(--safe-r)) calc(0.8rem + var(--safe-b)) calc(1.25rem + var(--safe-l));
    font-family: ui-monospace, 'SF Mono', Menlo, monospace;
    font-size: 0.78rem;
    color: var(--ink-dim);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    background: linear-gradient(0deg, rgba(13, 22, 11, 0.92) 30%, rgba(13, 22, 11, 0) 100%);
    pointer-events: none;
}
.tf-ticker b { font-weight: 600; }

.tf-tip {
    position: fixed;
    z-index: 10;
    max-width: 17rem;
    padding: 0.6rem 0.75rem;
    border-radius: 10px;
    background: rgba(13, 22, 11, 0.94);
    border: 1px solid currentColor;
    font-size: 0.8rem;
    line-height: 1.45;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s ease;
}
.tf-tip[data-show="1"] { opacity: 1; }
.tf-tip .k { font-weight: 600; }
.tf-tip .d { color: var(--ink-dim); }
.tf-tip .p { font-family: ui-monospace, 'SF Mono', Menlo, monospace; font-size: 0.74rem; color: var(--ink); word-break: break-all; }

.tf-short, .tf-about-intro, .tf-legend-toggle { display: none; }

/* legend entries are buttons: click to hide or show a kind */
.tf-legend li[role="button"] { cursor: pointer; border-radius: 4px; transition: opacity 0.2s ease; }
.tf-legend li[role="button"]:hover, .tf-legend li[role="button"]:focus-visible { background: rgba(173, 189, 255, 0.12); outline: none; }
.tf-legend li[data-off="1"] { opacity: 0.38; text-decoration: line-through; }
.tf-legend li.tf-legend-reset { display: block; margin-top: 0.3rem; color: var(--accent-color); font-size: 0.78rem; }
.tf-legend li[hidden], .tf-legend li.tf-legend-reset[hidden] { display: none; }
.tf-tip[data-pinned="1"] { border-width: 2px; }

/* ---- Compact layout: phones and tablets ---------------------------------
   Header becomes: title + status / links + "About this" / transport.
   The intro text moves into "About this"; the legend is one row of counts
   that opens into the full key. */
@media (max-width: 900px), (max-width: 1280px) and (max-height: 860px) {
    .tf-top {
        display: grid;
        grid-template-columns: auto auto auto 1fr auto;
        align-items: center;
        gap: 0.45rem 0.4rem;
        padding: calc(0.65rem + var(--safe-t)) calc(0.75rem + var(--safe-r)) 0.9rem calc(0.75rem + var(--safe-l));
    }
    .tf-title, .tf-nav { display: contents; }
    .tf-title h1 { grid-column: 1 / 4; grid-row: 1; font-size: 1.9rem; white-space: nowrap; }
    .tf-title > p { display: none; }
    /* Spans the flexible column too, so a long label never sets the width
       of the column "About this" sits in. */
    .tf-status { grid-column: 4 / 6; grid-row: 1; justify-self: end; font-size: 0.78rem; padding: 0.22rem 0.6rem; white-space: nowrap; }
    .tf-nav a, .tf-motion { grid-row: 2; font-size: 0.78rem; padding: 0.22rem 0.6rem; }
    .tf-about { grid-column: 4 / 6; grid-row: 2; justify-self: end; margin: 0; max-width: none; }
    .tf-about[open] { padding: 0; background: none; border: 0; }
    .tf-about summary { list-style: none; padding: 0.22rem 0.1rem; font-size: 0.78rem; }
    .tf-about summary::-webkit-details-marker { display: none; }
    .tf-about summary::after { content: ' ▾'; }
    .tf-about[open] summary::after { content: ' ▴'; }
    .tf-long { display: none; }
    .tf-short { display: inline; }
    .tf-about-intro { display: block; color: var(--ink); }
    .tf-about-body {
        position: absolute; left: 0.75rem; right: 0.75rem; top: calc(100% - 0.4rem);
        padding: 0.7rem 0.85rem 0.8rem;
        background: rgba(13, 22, 11, 0.96);
        border: 1px solid var(--panel-edge);
        border-radius: 12px;
        max-height: 60vh; overflow: auto;
    }
    .tf-about-body p:first-child { margin-top: 0; }

    .tf-transport {
        grid-column: 1 / -1; grid-row: 3;
        justify-self: start; width: 100%; max-width: 26rem;
        position: static; transform: none;
        gap: 0.35rem; padding: 0.3rem 0.4rem;
        font-size: 0.76rem;
    }
    .tf-transport button { padding: 0.24rem 0.55rem; min-width: 2rem; }
    .tf-transport input[type="range"] { flex: 1 1 3rem; width: auto; min-width: 3rem; }
    .tf-transport .tt-long, .tf-transport .tt-clock { display: none; }
    .tf-transport[data-mode="live"] .tt-time { display: none; }
    .tf-transport[data-mode="replay"] .tt-time { min-width: 2.9rem; }

    .tf-legend {
        /* only as wide as the symbols need, from the left */
        left: calc(0.75rem + var(--safe-l)); right: auto; max-width: calc(100% - 1.5rem - var(--safe-l) - var(--safe-r));
        bottom: calc(2.1rem + var(--safe-b)); min-width: 0;
        padding: 0.35rem 0.6rem;
        display: flex; flex-wrap: wrap; align-items: center; gap: 0.3rem 0.4rem;
        font-size: 0.78rem;
    }
    .tf-legend h2, .tf-legend .foot { display: none; }
    .tf-legend ul { display: flex; flex-wrap: wrap; gap: 0.15rem 0.5rem; flex: 0 1 auto; min-width: 0; }
    .tf-legend li { display: flex; gap: 0.2rem; padding: 0.05rem 0.1rem; }
    .tf-legend li.tf-legend-reset { margin-top: 0; font-size: 0.72rem; }
    .tf-legend:not([data-open="1"]) li { background: none !important; }
    .tf-legend li > span:nth-child(2) { display: none; }
    .tf-sample { margin-top: 0; font-size: 0.72rem; white-space: nowrap; }
    .tf-sample-long { display: none; }
    .tf-sample-short { display: inline; }
    .tf-legend[data-open="1"] .tf-sample { margin-top: 0.4rem; }
    .tf-legend[data-open="1"] .tf-sample-long { display: inline; }
    .tf-legend[data-open="1"] .tf-sample-short { display: none; }
    .tf-legend-toggle {
        display: inline-block; margin-left: auto;
        font: inherit; font-size: 0.72rem; color: var(--accent-color);
        background: none; border: 1px solid var(--panel-edge); border-radius: 999px;
        padding: 0.1rem 0.5rem; cursor: pointer; line-height: 1.3;
    }
    /* opened: the full key */
    .tf-legend[data-open="1"] { display: block; padding: 0.6rem 0.8rem; }
    .tf-legend[data-open="1"] h2 { display: block; }
    .tf-legend[data-open="1"] ul { display: grid; grid-template-columns: 1fr 1fr; column-gap: 1rem; }
    .tf-legend[data-open="1"] li { display: grid; padding: 0.12rem 0; }
    .tf-legend[data-open="1"] li > span:nth-child(2) { display: inline; }
    .tf-legend[data-open="1"] .tf-legend-toggle { position: absolute; top: 0.45rem; right: 0.6rem; }

    .tf-ticker { padding: 0.4rem calc(0.75rem + var(--safe-r)) calc(0.5rem + var(--safe-b)) calc(0.75rem + var(--safe-l)); font-size: 0.7rem; }
}

/* very narrow phones: keep the title row and links on one line each */
@media (max-width: 380px) {
    .tf-title h1 { font-size: 1.65rem; }
    .tf-status, .tf-nav a, .tf-motion, .tf-about summary { font-size: 0.7rem; }
    .tf-status, .tf-nav a, .tf-motion { padding: 0.2rem 0.42rem; }
    .tf-top { column-gap: 0.3rem; }
    .tf-status-more { display: none; }
}

@media (max-width: 340px) {
    .tf-title h1 { font-size: 1.45rem; }
}

@media (prefers-reduced-motion: reduce) {
    .tf-status[data-state="live"]::before { animation: none; }
}
