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

:root {
    --bg: #000000;
    --fg: #ffffff;
    --gray: #9a9a9a;
    --gray-dim: #6e6e6e;
    --gray-dark: #404040;
    --gray-light: #c0c0c0;
    --line: #262626;
    --surface-hover: #161616;
    --hover-glow: inset 0 0 26px rgba(255, 255, 255, 0.06);
    --hover-border: var(--gray);
    --signal: #3b82f6;
    --star: #e3b341;
    --on-air: #ff3b30;
    --accent: #00ff00;
    --mono: 'Chakra Petch', sans-serif;
    --box-pad: 18px 20px;
}

/* Intro: hidden until station.js reveals them. Only with JS on and motion
   allowed, so no-JS and reduced-motion visitors see everything at once */
.boot {
    display: none;
}

html:not(.js) .js-only {
    display: none;
}

@media (prefers-reduced-motion: no-preference) {
    .js .boot {
        display: flex;
    }

    .js .designation {
        opacity: 0;
        transition: opacity 0.8s cubic-bezier(0.4, 0, 0.2, 1);
    }

    .js .designation.show {
        opacity: 1;
    }

    /* Sections scan in top to bottom rather than fading */
    .js .reveal {
        opacity: 0;
        clip-path: inset(0 0 100% 0);
        transition: clip-path 0.9s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.25s ease;
    }

    .js .reveal.show {
        opacity: 1;
        clip-path: inset(-60px -60px -60px -60px);
    }

    .js .readouts .readout-value,
    .js .channel .channel-row {
        opacity: 0;
    }

    .js .readouts.show .readout-value {
        animation: flicker-in 0.5s steps(1) both;
        animation-delay: calc(var(--n) * 140ms + 250ms);
    }

    .js .channel.show .channel-row {
        animation: receive 0.5s cubic-bezier(0.16, 1, 0.3, 1) both;
        animation-delay: calc(var(--n) * 120ms + 250ms);
    }

    .js .main-title:not(.ready) {
        visibility: hidden;
    }

    .js .status-bar span:last-child,
    .js .reveal .section-header h2 {
        clip-path: inset(0 100% 0 0);
        transition: clip-path 0.6s cubic-bezier(0.16, 1, 0.3, 1);
    }

    .js .status-bar span:last-child.wipe-in,
    .js .reveal.show .section-header h2 {
        clip-path: inset(0 0 0 0);
        animation: wipe-flash 0.6s ease-out;
    }

    .js .log .tx {
        opacity: 0;
    }

    .js .log.show .tx {
        animation: receive 0.5s cubic-bezier(0.16, 1, 0.3, 1) both;
        animation-delay: calc(var(--i) * 40ms + 200ms);
    }

    .js .log .settled .tx {
        opacity: 1;
        animation: none;
    }
}

@keyframes wipe-flash {
    0% { text-shadow: none; }
    55% { text-shadow: 0 0 12px var(--accent); }
    100% { text-shadow: none; }
}

@keyframes flicker-in {
    0% { opacity: 0; }
    20% { opacity: 1; }
    35% { opacity: 0.2; }
    55% { opacity: 1; }
    70% { opacity: 0.4; }
    100% { opacity: 1; }
}

@keyframes receive {
    from {
        clip-path: inset(0 100% 0 0);
        opacity: 0.3;
    }
    to {
        clip-path: inset(-4px -4px -4px -4px);
        opacity: 1;
    }
}

html {
    scrollbar-gutter: stable;
    -webkit-tap-highlight-color: transparent;
}

html.scroll-locked {
    overflow: hidden;
}

body {
    background: var(--bg);
    color: var(--fg);
    font-family: 'Chakra Petch', sans-serif;
    font-weight: 300;
    line-height: 1.4;
    overflow-x: hidden;
    position: relative;
}

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

.boot {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: var(--bg);
    align-items: center;
    justify-content: center;
    padding: 20px;
    transition: opacity 0.35s ease;
}

.boot.done {
    opacity: 0;
}

.boot-log {
    font-family: var(--mono);
    font-size: clamp(0.6rem, 2.2vw, 0.8rem);
    line-height: 2;
    color: var(--gray-light);
    white-space: pre;
    min-width: min(44ch, 100%);
}

.boot-log .ok {
    color: var(--fg);
}

.vertical-text {
    position: fixed;
    right: 20px;
    bottom: 150px;
    font-size: 0.75rem;
    letter-spacing: 0.3em;
    color: var(--gray);
    font-weight: 400;
    z-index: 50;
    pointer-events: none;
    white-space: nowrap;
    writing-mode: vertical-rl;
    text-orientation: mixed;
    transform: rotate(180deg);
}

/* Nav / carrier */

.top-nav {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    padding: 20px 40px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 30px;
    z-index: 200;
    background: rgba(0, 0, 0, 0.95);
    border-bottom: 1px solid var(--gray-dark);
}

.nav-line {
    width: 60px;
    height: 1px;
    background: var(--fg);
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.3);
    flex-shrink: 0;
}

.carrier {
    display: flex;
    align-items: center;
    gap: 15px;
    flex: 1;
    max-width: 480px;
    min-width: 0;
}

.carrier-btn {
    width: 32px;
    height: 32px;
    background: transparent;
    border: 1px solid var(--gray);
    color: var(--fg);
    font-size: 10px;
    cursor: pointer;
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Chakra Petch', sans-serif;
}

.carrier-btn svg {
    width: 10px;
    height: 10px;
    fill: currentColor;
}

.carrier-btn .icon-pause,
.carrier-btn.playing .icon-play {
    display: none;
}

.carrier-btn.playing .icon-pause {
    display: block;
}

.carrier-btn:hover,
.carrier-btn:focus-visible,
.carrier-btn.playing {
    border-color: var(--fg);
}

.carrier-btn:hover,
.carrier-btn:focus-visible {
    box-shadow: 0 0 14px rgba(255, 255, 255, 0.45);
}

.carrier-progress {
    --progress: 0%;
    --track: linear-gradient(var(--fg), var(--fg)) 0 / var(--progress) 100% no-repeat, var(--gray-dark);
    -webkit-appearance: none;
    appearance: none;
    flex: 1;
    min-width: 0;
    height: 16px;
    margin: 0;
    background: transparent;
    cursor: pointer;
}

.carrier-progress:focus-visible {
    outline-offset: 4px;
}

.carrier-progress::-webkit-slider-runnable-track {
    height: 2px;
    border-radius: 1px;
    background: var(--track);
}

.carrier-progress::-moz-range-track {
    height: 2px;
    border-radius: 1px;
    background: var(--track);
}

.carrier-progress::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 8px;
    height: 8px;
    margin-top: -3px;
    border: none;
    border-radius: 50%;
    background: var(--fg);
    box-shadow: 0 0 8px rgba(255, 255, 255, 0.6);
    opacity: 0;
    transition: opacity 0.2s ease;
}

.carrier-progress::-moz-range-thumb {
    width: 8px;
    height: 8px;
    border: none;
    border-radius: 50%;
    background: var(--fg);
    box-shadow: 0 0 8px rgba(255, 255, 255, 0.6);
    opacity: 0;
    transition: opacity 0.2s ease;
}

.carrier-progress:hover::-webkit-slider-thumb,
.carrier-progress:focus-visible::-webkit-slider-thumb {
    opacity: 1;
}

.carrier-progress:hover::-moz-range-thumb,
.carrier-progress:focus-visible::-moz-range-thumb {
    opacity: 1;
}

.carrier-state {
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: var(--mono);
    font-size: 0.65rem;
    letter-spacing: 0.1em;
    color: var(--gray);
    white-space: nowrap;
    flex-shrink: 0;
}

.carrier-state::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--gray-dark);
}

.carrier-state.on-air {
    color: var(--fg);
}

.carrier-state.on-air::before {
    background: var(--on-air);
    box-shadow: 0 0 8px var(--on-air);
    animation: pulse 2s ease-in-out infinite;
}

.coordinates {
    text-align: right;
    font-size: 0.7rem;
    letter-spacing: 0.1em;
    color: var(--gray);
    font-weight: 400;
    white-space: nowrap;
    flex-shrink: 0;
}

/* Hero */

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 100px 40px 40px;
    position: relative;
    z-index: 1;
}

.hero {
    min-height: 38vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding-top: 24px;
    border-bottom: 1px solid var(--gray-dark);
    margin-bottom: 48px;
}

/* The telemetry sits beside the designation, or drops to its own line when narrow */
.designation {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 6px 2.5em;
    white-space: nowrap;
    font-size: 0.7rem;
    letter-spacing: 0.3em;
    color: var(--gray);
    margin-bottom: 20px;
    font-weight: 400;
}

.telemetry {
    font-family: var(--mono);
    font-size: 0.65rem;
    letter-spacing: 0.12em;
    color: var(--gray-dim);
    white-space: pre;
}

.main-title {
    font-size: clamp(4rem, 12vw, 10rem);
    font-weight: 600;
    line-height: 0.85;
    letter-spacing: 0.05em;
    margin-bottom: 40px;
}

.title-line {
    display: block;
}

.main-title {
    position: relative;
}

.title-ghost {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.title-ghost-1 {
    color: rgba(255, 59, 48, 0.7);
}

.title-ghost-2 {
    color: rgba(0, 229, 255, 0.7);
}

.main-title.locked > .title-line {
    animation: lock-flash 0.6s ease-out;
}

@keyframes lock-flash {
    0% { text-shadow: 0 0 22px rgba(255, 255, 255, 0.9); }
    100% { text-shadow: none; }
}

.title-line,
.section-header h2,
.status-bar span {
    will-change: clip-path;
    transform: translateZ(0);
}

.status-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.75rem;
    letter-spacing: 0.2em;
    color: var(--gray-light);
    font-weight: 400;
    margin-bottom: 32px;
}

.status-indicator {
    width: 8px;
    height: 8px;
    background: var(--gray-dark);
    border-radius: 50%;
}

.status-indicator.live {
    background: var(--signal);
    box-shadow: 0 0 10px var(--signal);
    animation: pulse 2s ease-in-out infinite;
}

.status-indicator.intermittent {
    background: var(--signal);
    opacity: 0.6;
    animation: flicker 4s steps(1) infinite;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.3;
        transform: scale(0.9);
    }
}

@keyframes flicker {
    0%, 62%, 66%, 100% { opacity: 0.6; }
    64% { opacity: 0.1; }
}

/* Sections */

.section-header {
    display: flex;
    align-items: center;
    gap: 30px;
    margin-bottom: 20px;
}

.section-header h2 {
    font-size: 0.8rem;
    letter-spacing: 0.3em;
    font-weight: 500;
    white-space: nowrap;
    flex-shrink: 0;
}

.header-line {
    flex: 1;
    height: 1px;
    background: var(--gray-dark);
}

.section-meta {
    font-family: var(--mono);
    font-size: 0.65rem;
    letter-spacing: 0.1em;
    color: var(--gray);
    white-space: nowrap;
    flex-shrink: 0;
    font-variant-numeric: tabular-nums;
    transition: color 0.2s ease;
}

.section-meta.active {
    color: var(--fg);
}

/* Fixed-width digit slots for live numbers (see setDigits) */
.digit {
    display: inline-block;
    width: 0.62em;
    text-align: center;
}

/* Readouts */

.readouts {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    margin-bottom: 32px;
}

.readout {
    position: relative;
    background: var(--bg);
    padding: var(--box-pad);
    border: 1px solid var(--gray-dark);
    margin: -1px 0 0 -1px;
    transition: background 0.3s ease, box-shadow 0.3s ease, border-color 0.3s ease;
}

.readout-label {
    font-size: 0.65rem;
    letter-spacing: 0.2em;
    color: var(--gray);
    margin-bottom: 8px;
    font-weight: 400;
}

.readout-value {
    font-family: var(--mono);
    font-size: 1rem;
    letter-spacing: 0.05em;
}

/* Signal strip */

.signal {
    margin-bottom: 48px;
}

.signal-canvas {
    display: block;
    width: 100%;
    height: 120px;
    cursor: crosshair;
    /* Sideways drags scrub the passband on touchscreens; vertical ones still scroll */
    touch-action: pan-y;
    background: var(--bg);
    border-top: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
}

.signal-axis {
    position: relative;
    height: 24px;
}

.signal-axis span {
    position: absolute;
    top: 8px;
    font-family: var(--mono);
    font-size: 0.6rem;
    letter-spacing: 0.1em;
    color: var(--gray-dim);
    border-left: 1px solid var(--line);
    padding-left: 4px;
}

/* Transmission log */

.log {
    margin-bottom: 48px;
}

.log-head,
.tx {
    display: grid;
    grid-template-columns: 80px minmax(0, 1fr) 104px 80px 132px 16px;
    gap: 32px;
}

.sort {
    background: none;
    border: none;
    padding: 0;
    font: inherit;
    letter-spacing: inherit;
    color: inherit;
    text-align: left;
    cursor: pointer;
    transition: color 0.2s ease;
}

.sort::after {
    content: '';
    display: inline-block;
    width: 1.2em;
    text-align: center;
}

.sort.active {
    color: var(--fg);
}

.sort.active::after {
    content: '▾';
}

.sort.active.reversed::after {
    content: '▴';
}

/* The arrow slot on both sides keeps the label centred over its column */
.log-head-center {
    text-align: center;
}

.log-head-center::before {
    content: '';
    display: inline-block;
    width: 1.2em;
}


.log-head {
    background: var(--bg);
    padding: var(--box-pad);
    border: 1px solid var(--gray-dark);
    font-family: var(--mono);
    font-size: 0.6rem;
    letter-spacing: 0.2em;
    color: var(--gray-dim);
}

.log-empty {
    padding: 50px;
    text-align: center;
    font-size: 0.75rem;
    letter-spacing: 0.2em;
    color: var(--gray);
    background: var(--bg);
    border-bottom: 1px solid var(--line);
}

.log-empty a {
    color: var(--fg);
    text-decoration: none;
    border-bottom: 1px solid var(--gray-dark);
}

.tx {
    position: relative;
    align-items: baseline;
    padding: var(--box-pad);
    margin-top: -1px;
    background: var(--bg);
    border: 1px solid var(--gray-dark);
    color: var(--fg);
    text-decoration: none;
    transition: background 0.3s ease, box-shadow 0.3s ease, border-color 0.3s ease;
}

/* Hover bar: covers the box's left border rather than sitting inside it */
.tx::before,
.channel-row::before {
    content: '';
    position: absolute;
    top: -1px;
    bottom: -1px;
    left: -1px;
    width: 3px;
    background: var(--lang, var(--gray-light));
    opacity: 0;
    transition: opacity 0.3s ease;
}

.tx-id {
    font-family: var(--mono);
    font-size: 0.7rem;
    letter-spacing: 0.05em;
    color: var(--gray);
    transition: color 0.3s ease;
}

.tx-priority .tx-id {
    color: var(--fg);
}

.tx-main {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
}

.tx-name {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 1rem;
    font-weight: 500;
    letter-spacing: 0.02em;
    overflow-wrap: anywhere;
    transition: text-shadow 0.3s ease;
}

.tx-tag {
    font-family: var(--mono);
    font-size: 0.55rem;
    letter-spacing: 0.15em;
    font-weight: 400;
    color: var(--gray-light);
    border: 1px solid var(--gray-dark);
    padding: 2px 6px;
    flex-shrink: 0;
}

.tx-desc {
    font-size: 0.85rem;
    color: var(--gray);
    line-height: 1.5;
    transition: color 0.3s ease;
}

.tx-lang,
.tx-stats,
.tx-last {
    font-family: var(--mono);
    font-size: 0.7rem;
    letter-spacing: 0.05em;
    color: var(--gray);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tx-lang {
    text-align: center;
    text-transform: uppercase;
    color: var(--gray-light);
}

.tx-lang::before {
    content: '';
    display: inline-block;
    width: 8px;
    height: 8px;
    margin-right: 8px;
    border-radius: 50%;
    background: var(--lang, var(--gray-dim));
    vertical-align: 0;
}

.tx-stats {
    display: flex;
    justify-content: center;
    gap: 16px;
    font-variant-numeric: tabular-nums;
}

.tx-last {
    text-align: center;
}

.star-icon {
    color: var(--star);
}

.tx-recent {
    color: var(--fg);
}

.tx-open {
    font-family: var(--mono);
    font-size: 0.8rem;
    color: var(--gray-dim);
    transition: color 0.3s ease;
}

/* Open channel */

.channel {
    margin-bottom: 0;
}

/* Contact boxes, laid out like the readouts: label and hint on top, value below */
.channel-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
}

.channel-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
        "label hint"
        "value value";
    gap: 8px 16px;
    align-items: baseline;
    margin: -1px 0 0 -1px;
    position: relative;
    padding: var(--box-pad);
    background: var(--bg);
    border: 1px solid var(--gray-dark);
    color: var(--fg);
    text-decoration: none;
    transition: background 0.3s ease, box-shadow 0.3s ease, border-color 0.3s ease;
}

.channel-label {
    grid-area: label;
    font-family: var(--mono);
    font-size: 0.65rem;
    letter-spacing: 0.2em;
    color: var(--gray);
}

.channel-value {
    grid-area: value;
    font-size: 0.95rem;
    font-weight: 400;
    letter-spacing: 0.05em;
    overflow-wrap: anywhere;
    transition: text-shadow 0.3s ease;
}

.channel-hint {
    grid-area: hint;
    font-family: var(--mono);
    font-size: 0.6rem;
    letter-spacing: 0.2em;
    color: var(--gray-dim);
    transition: color 0.3s ease;
}

/* Hover effects only on devices that can hover. Keyboard focus mirrors hover */
/* Touchscreens: the same highlight while a finger is pressing the box.
   .pressed is set by station.js the instant a touch lands (the browser's own
   :active is delayed); it comes on immediately and fades out on release */
@media (hover: none) {
    .readout.pressed,
    .tx.pressed,
    .channel-row.pressed {
        z-index: 1;
        background: var(--surface-hover);
        border-color: var(--hover-border);
        box-shadow: var(--hover-glow);
        transition: none;
    }

    .tx.pressed::before,
    .channel-row.pressed::before {
        opacity: 1;
        transition: none;
    }

    .tx.pressed .tx-id,
    .tx.pressed .tx-desc {
        color: var(--fg);
        transition: none;
    }
}

@media (hover: hover) {
    .readout:hover,
    .tx:hover,
    .channel-row:hover {
        z-index: 1;
        background: var(--surface-hover);
        border-color: var(--hover-border);
        box-shadow: var(--hover-glow);
    }

    .tx:hover::before,
    .channel-row:hover::before {
        opacity: 1;
    }

    .tx:hover .tx-id,
    .tx:hover .tx-open {
        color: var(--fg);
    }

    .tx:hover .tx-desc {
        color: var(--gray-light);
    }

    .channel-row:hover .channel-hint {
        color: var(--fg);
    }

    .sort:hover {
        color: var(--gray-light);
    }

    .sort.active:hover {
        color: var(--fg);
    }
}

.tx:focus-visible,
.channel-row:focus-visible {
    outline-offset: -1px;
}

/* Footer */

.footer {
    border-top: 1px solid var(--gray-dark);
    padding: 24px 40px;
    margin-top: 56px;
}

.footer-line {
    width: 60px;
    height: 1px;
    background: var(--gray-dark);
    margin-bottom: 20px;
}

.footer-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    font-size: 0.7rem;
    letter-spacing: 0.1em;
    color: var(--gray);
    font-weight: 400;
}

.particle-canvas {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
}

@media (max-width: 1024px) {
    .readouts {
        grid-template-columns: repeat(2, 1fr);
    }

    .vertical-text {
        right: 15px;
        bottom: 130px;
        font-size: 0.7rem;
    }

    .carrier {
        max-width: 340px;
    }
}

@media (max-width: 768px) {
    .container {
        padding: 80px 20px 20px;
    }

    .top-nav {
        padding: 15px 20px;
        gap: 15px;
    }

    .nav-line {
        width: 40px;
    }

    .carrier {
        max-width: none;
        min-width: 100px;
    }

    .coordinates {
        font-size: 0.65rem;
    }

    .vertical-text {
        display: none;
    }

    .main-title {
        font-size: 3rem;
    }

    .hero {
        margin-bottom: 32px;
    }

    .hero {
        min-height: 32vh;
    }

    .signal,
    .log {
        margin-bottom: 40px;
    }

    :root {
        --box-pad: 14px 12px;
    }

    .signal-canvas {
        height: 90px;
    }

    .section-header {
        gap: 16px;
    }

    /* Only the passband readout stays; it's where touch scrubbing reports */
    .section-meta:not(#signal-readout) {
        display: none;
    }

    /* Sort buttons spread evenly across one row (wrapping only if they must) */
    .log-head {
        display: flex;
        flex-wrap: wrap;
        justify-content: space-between;
        gap: 10px 12px;
        letter-spacing: 0.1em;
    }

    .log-head-center {
        text-align: left;
    }

    .log-head-center::before {
        display: none;
    }

    .sort::after {
        width: 1em;
    }

    .log-head > span:empty {
        display: none;
    }

    /* Rows wrap to two lines: name and last RX, then stars/forks and mode */
    .tx {
        grid-template-columns: 44px auto minmax(0, 1fr) auto;
        grid-template-areas:
            "id main main last"
            ". stats lang lang";
        gap: 10px 14px;
    }

    .tx-id { grid-area: id; }
    .tx-main { grid-area: main; }
    .tx-last { grid-area: last; }

    .tx-stats {
        grid-area: stats;
        justify-content: flex-start;
    }

    .tx-lang {
        grid-area: lang;
        text-align: left;
    }

    .tx-open {
        display: none;
    }

    .channel-grid {
        grid-template-columns: 1fr;
    }

    .footer {
        padding: 20px;
        margin-top: 40px;
    }

    .footer-content {
        flex-direction: column;
        align-items: flex-start;
    }
}

@media (max-width: 480px) {
    .top-nav {
        padding: 15px 16px;
        gap: 10px;
    }

    .nav-line {
        width: 20px;
    }

    .carrier {
        min-width: 80px;
    }
}

@media (min-width: 769px) and (max-width: 1400px) {
    .vertical-text {
        right: 15px;
        bottom: 140px;
    }
}

@media (min-height: 900px) {
    .vertical-text {
        bottom: 170px;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    .particle-canvas {
        display: none;
    }
}
