:root {
    --bg: #ebf3f7;
    --panel: rgba(255, 255, 255, 0.96);
    --panel-soft: #f5f9fb;
    --primary: #0b4d77;
    --accent: #14837b;
    --signal: #ffd84b;
    --ink: #163147;
    --muted: #607789;
    --border: #d4e0e8;
    --danger: #bb342d;
    --warning: #a66f13;
    --ok: #1d835a;
    --shadow: 0 18px 40px rgba(15, 61, 94, 0.08);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Inter", "Segoe UI", system-ui, sans-serif;
    color: var(--ink);
    background:
        radial-gradient(circle at top left, rgba(20, 131, 123, 0.12), transparent 28%),
        radial-gradient(circle at right center, rgba(11, 77, 119, 0.12), transparent 30%),
        linear-gradient(180deg, #f9fbfc 0%, var(--bg) 100%);
}

.sim-shell {
    padding: 24px;
}

.panel {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 24px;
    box-shadow: var(--shadow);
    backdrop-filter: blur(10px);
}

.topbar,
.hero,
.sim-main,
.sim-sidebar {
    padding: 22px;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin-bottom: 18px;
}

.brand {
    height: 54px;
    flex-shrink: 0;
}

.eyebrow,
.section-kicker {
    margin: 0 0 6px;
    color: var(--accent);
    font-size: 0.78rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

/* top-reading strong styling is handled by the shared .reading-card strong rule */
.hero h2,
.sim-main h2,
.sim-sidebar h3,
.tip-card h3 {
    margin: 0;
}

.meta,
.hero-copy,
.tip-card p,
.event-log,
.status-row span {
    color: var(--muted);
}

.top-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.button {
    appearance: none;
    border: 0;
    border-radius: 14px;
    padding: 11px 15px;
    font-size: 0.94rem;
    font-weight: 700;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.button.ghost {
    border: 1px solid var(--border);
    background: #fff;
    color: var(--primary);
}

.hero {
    display: grid;
    grid-template-columns: minmax(0, 1.45fr) minmax(280px, 0.8fr);
    gap: 18px;
    margin-bottom: 18px;
    background: linear-gradient(135deg, #0b4d77, #14837b);
    border-color: transparent;
    color: #fff;
}

.hero .eyebrow,
.hero h2,
.hero-copy,
.hero strong {
    color: #fff;
}

.hero-copy {
    margin: 12px 0 0;
    line-height: 1.7;
    max-width: 68ch;
    color: rgba(255, 255, 255, 0.88);
}

.hero-stats {
    display: grid;
    gap: 10px;
}

.stat {
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 16px;
    padding: 14px 16px;
    background: rgba(255, 255, 255, 0.08);
}

.stat-label {
    display: block;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    opacity: 0.82;
}

.stat-value {
    display: block;
    margin-top: 6px;
    font-size: 1rem;
}

.layout {
    display: grid;
    grid-template-columns: minmax(0, 1.55fr) minmax(320px, 0.85fr);
    gap: 18px;
}

.sim-header {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: flex-start;
    margin-bottom: 18px;
}

.status-chip {
    padding: 8px 14px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--panel-soft);
    color: var(--primary);
    font-weight: 700;
    white-space: nowrap;
}

.device-stage {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(220px, 280px);
    gap: 20px;
    align-items: start;
}

.device-wrap {
    position: relative;
    width: min(100%, 720px);
    margin: 0 auto;
}

.device-image {
    width: 100%;
    display: block;
    border-radius: 28px;
}

.alarm-beacon {
    position: absolute;
    left: 0;
    top: 0;
    width: 0;
    height: 0;
    opacity: 0;
    pointer-events: none;
    background: rgba(220, 30, 30, 0.82);
    box-shadow: 0 0 12px rgba(220, 30, 30, 0.6);
}

.screen-overlay {
    position: absolute;
    left: 0;
    top: 0;
    width: 0;
    height: 0;
    border-radius: 18px;
    padding: 14px 16px;
    background: linear-gradient(180deg, #c8edf8 0%, #a6ddf0 100%);
    color: #0f4268;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    box-shadow: inset 0 0 0 2px rgba(10, 40, 70, 0.22);
    overflow: hidden;
}

.screen-overlay.is-off {
    background: #0a0a0a;
    overflow: hidden;
}

/* Blank screen when instrument is off — hide ALL content regardless of nesting */
.screen-overlay.is-off * {
    visibility: hidden !important;
    pointer-events: none;
}

/* ══ Message screen (startup, cal menus, fresh-air prompts) — 3 vertical sections ══ */
.screen-msg {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
}

/* Section 1 of message: large primary text */
.screen-msg-top {
    font-family: 'Share Tech Mono', 'Courier New', monospace;
    font-size: clamp(6px, calc(var(--screen-scale, 1) * 18px), 18px);
    color: #0b3562;
    text-align: center;
    white-space: pre-wrap;
    letter-spacing: 0.05em;
    line-height: 1.3;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    flex: 1 1 0;
    padding: clamp(6px, calc(var(--screen-scale, 1) * 10px), 10px);
    box-sizing: border-box;
    overflow: auto;
    word-break: break-word;
}

/* Section 2 of message: horizontal divider rule (renamed to screen-msg-mid) */
.screen-msg-mid {
    width: 88%;
    height: clamp(2px, calc(var(--screen-scale, 1) * 2px), 2px);
    background: rgba(11, 53, 98, 0.35);
    margin: 0 auto;
    flex: 0 0 auto;
}

/* Section 3 of message: smaller detail / instruction text */
.screen-msg-bot {
    font-family: 'Share Tech Mono', 'Courier New', monospace;
    font-size: clamp(4px, calc(var(--screen-scale, 1) * 10px), 10px);
    color: #0b3562;
    text-align: center;
    white-space: pre-wrap;
    letter-spacing: 0.03em;
    line-height: 1.4;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    flex: 1 1 0;
    padding: clamp(6px, calc(var(--screen-scale, 1) * 8px), 8px);
    box-sizing: border-box;
    overflow: auto;
    word-break: break-word;
}

/* Allow flex children to shrink properly inside .screen-msg */
.screen-msg > * {
    min-height: 0;
    box-sizing: border-box;
}

/* ══ Message / menu mode — text content uses smaller, wrapping font ══ */
.screen-normal.is-msg .screen-lbl-row span {
    font-size: clamp(4px, calc(var(--screen-row-unit, 24px) * 0.44), 20px);
    white-space: pre-wrap;
    text-align: center;
    width: 100%;
}

.screen-normal.is-msg .screen-lbl-row {
    justify-content: center;
}

.screen-normal.is-msg .screen-val-row {
    grid-template-columns: 1fr;
}

.screen-normal.is-msg .screen-val-row strong {
    font-size: clamp(5px, calc(var(--screen-row-unit, 24px) * 0.70), 40px);
    white-space: pre-wrap;
    word-break: break-word;
    text-align: center;
    width: 100%;
}

/* ══ Normal operation screen — 3 equal vertical sections (each 1/3 of display height) ══ */
.screen-normal {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
}

/* label(1) / value(3) / label(1) / value(3) / status(3) */
.screen-normal > * {
    min-height: 0;
}
.screen-normal > .screen-lbl-row {
    flex: 1 1 0;
}
.screen-normal > .screen-val-row,
.screen-normal > .screen-bot {
    flex: 3 1 0;
}

/* ── Row 1 & 3: thin label rows ── */
.screen-lbl-row {
    display: flex;
    justify-content: space-around;
    align-items: center;
}

.screen-lbl-row span {
    font-family: 'Share Tech Mono', 'Courier New', monospace;
    font-size: clamp(4px, calc(var(--screen-row-unit, 24px) * 0.38), 15px);
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: #0f4268;
    line-height: 1;
}

/* ── Row 2 & 4: big value rows ── */
.screen-val-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.screen-val-row > div {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    min-height: 0;
}

.screen-val-row strong {
    font-family: 'Share Tech Mono', 'Courier New', monospace;
    font-size: clamp(10px, calc(var(--screen-row-unit, 24px) * 1.18), 90px);
    font-weight: 400;
    letter-spacing: 0.02em;
    line-height: 1;
    color: #0b3562;
}

/* Bottom time / status sizing — same height as value rows */
.screen-bot .screen-time {
    display: inline-block;
    font-size: clamp(8px, calc(var(--screen-row-unit, 24px) * 1.05), 75px);
    line-height: 1;
}

/* ── Row 5: Status bar — battery | alarm text | time ── */
.screen-bot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 2px;
    padding: 0 clamp(2px, calc(var(--screen-scale, 1) * 4px), 4px);
}

.screen-batt,
.screen-alarm-lbl,
.screen-mode-lbl {
    font-family: 'Share Tech Mono', 'Courier New', monospace;
    font-size: clamp(4px, calc(var(--screen-row-unit, 24px) * 0.55), 32px);
    color: #0b3562;
    line-height: 1;
}

.screen-mode-lbl {
    font-weight: 700;
    letter-spacing: 0.08em;
}

.screen-time {
    font-family: 'Share Tech Mono', 'Courier New', monospace;
    color: #0b3562;
    line-height: 1;
}

/* ── Alarm text flash animations ── */
.flash-warning {
    animation: blink-text 0.95s steps(2, end) infinite;
}

.flash-danger {
    animation: blink-text 0.55s steps(2, end) infinite;
}

.flash-batt {
    animation: blink-text 1.2s steps(2, end) infinite;
}

@keyframes blink-text {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0; }
}

/* ── Individual reading card alarm flashing ── */
.reading-alarm-warning strong {
    animation: blink-text 0.95s steps(2, end) infinite;
}

.reading-alarm-danger strong {
    animation: blink-text 0.55s steps(2, end) infinite;
}


.reading-card {
    border-radius: clamp(2px, calc(var(--screen-scale, 1) * 5px), 5px);
    padding: clamp(1px, calc(var(--screen-scale, 1) * 4px), 4px) clamp(2px, calc(var(--screen-scale, 1) * 6px), 6px);
    background: transparent;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.reading-card span {
    display: block;
    font-size: clamp(3px, calc(var(--screen-scale, 1) * 10px), 10px);
    font-weight: 700;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    color: #0f4268;
    line-height: 1.1;
}

.reading-card strong {
    display: block;
    font-family: 'Share Tech Mono', 'Courier New', monospace;
    font-size: clamp(5px, calc(var(--screen-scale, 1) * 52px), 52px);
    font-weight: 400;
    letter-spacing: 0.02em;
    line-height: 1;
    color: #0b3562;
}

.hotspot {
    position: absolute;
    border: 0;
    border-radius: 999px;
    background: rgba(11, 77, 119, 0.18);
    color: #fff;
    cursor: pointer;
    transition: transform 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.35);
    /* Prevent long-press context menu on mobile browsers */
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    touch-action: none;
}

.hotspot:hover,
.hotspot:focus-visible,
.hotspot.is-held {
    transform: scale(1.05);
    background: rgba(20, 131, 123, 0.36);
    box-shadow: 0 0 0 3px rgba(255, 216, 75, 0.6);
    outline: none;
}

.hotspot span {
    position: absolute;
    left: 50%;
    top: 100%;
    transform: translate(-50%, 10px);
    background: rgba(22, 49, 71, 0.92);
    color: #fff;
    border-radius: 999px;
    padding: 6px 10px;
    font-size: 0.78rem;
    font-weight: 700;
    white-space: nowrap;
}

.hotspot-air {
    left: 0;
    top: 0;
    width: 0;
    height: 0;
}

.hotspot-power {
    left: 0;
    top: 0;
    width: 0;
    height: 0;
}

.device-help {
    display: grid;
    gap: 12px;
}

.tip-card {
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: 18px;
    background: var(--panel-soft);
}

.tip-card p {
    margin: 10px 0 0;
    line-height: 1.65;
}

.slider-list {
    display: grid;
    gap: 12px;
    margin-bottom: 20px;
}

.slider-card {
    display: grid;
    gap: 8px;
    padding: 14px;
    border-radius: 18px;
    border: 1px solid var(--border);
    background: var(--panel-soft);
}

.slider-card span {
    font-size: 0.86rem;
    color: var(--muted);
}

.slider-card strong {
    font-size: 1.1rem;
}

.slider-card input[type="range"] {
    width: 100%;
    accent-color: var(--accent);
}

.status-list {
    display: grid;
    gap: 10px;
    margin-bottom: 20px;
}

.status-row {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    padding: 12px 14px;
    border-radius: 16px;
    background: var(--panel-soft);
    border: 1px solid var(--border);
}

.status-row strong {
    color: var(--ink);
}

.event-log {
    margin: 10px 0 0 20px;
    padding: 0;
    line-height: 1.6;
}

.event-log li + li {
    margin-top: 8px;
}

.alarm-normal #alarmState,
.alarm-normal .status-chip {
    color: var(--ok);
}

.alarm-warning #alarmState,
.alarm-warning .status-chip {
    color: var(--warning);
}

.alarm-danger #alarmState,
.alarm-danger .status-chip {
    color: var(--danger);
}

.alarm-warning .alarm-beacon {
    animation: flash-beacon 0.95s steps(2, end) infinite;
}

.alarm-danger .alarm-beacon {
    animation: flash-beacon-urgent 0.55s steps(2, end) infinite;
}

@keyframes flash-beacon {
    0%, 100% {
        opacity: 0;
    }
    50% {
        opacity: 0.5;
    }
}

@keyframes flash-beacon-urgent {
    0%, 100% {
        opacity: 0;
    }
    50% {
        opacity: 0.5;
    }
}

@media (max-width: 1080px) {
    .device-stage,
    .layout,
    .hero {
        grid-template-columns: 1fr;
    }

    .device-help {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 768px) {
    .sim-shell {
        padding: 8px;
    }

    .topbar {
        flex-direction: column;
        align-items: stretch;
    }

    .top-actions {
        width: 100%;
    }

    .top-actions .button {
        flex: 1 1 calc(50% - 5px);
    }

    .sim-header,
    .device-help {
        grid-template-columns: 1fr;
    }

    .sim-header {
        flex-direction: column;
    }

    .sim-main {
        padding: 14px 8px;
    }

    .device-wrap {
        width: 100%;
    }
}

@media (max-width: 520px) {
    .top-actions .button {
        flex-basis: 100%;
    }

    .hotspot span {
        font-size: 0.68rem;
        padding: 4px 8px;
    }
}
