/* ============================================================
   FlexiWear — design tokens
   Palette: graphite black instrument panel, single amber accent
   (goniometer / CRT-readout inspired — this is a device that
   measures degrees, so the accent lives in the degree readouts).
   Type: IBM Plex Sans for labels/body, IBM Plex Mono for every
   number — the numbers are the product, so they get the
   instrument-readout treatment throughout.
   ============================================================ */

:root {
    --bg: #0a0b0c;
    --panel: #131417;
    --panel-raised: #17181c;
    --border: #232529;
    --border-soft: #1b1c20;

    --text: #edeeef;
    --text-muted: #888b91;
    --text-faint: #56585d;

    --accent: #e8a33d;
    --accent-dim: #8f6425;
    --accent-wash: rgba(232, 163, 61, 0.1);

    --warn: #c1594a;

    --font-body: 'IBM Plex Sans', -apple-system, sans-serif;
    --font-mono: 'IBM Plex Mono', ui-monospace, monospace;

    --radius: 10px;

    /* Fluid spacing so a section's content scales down to fit short
       viewports (small laptops, phones in landscape) instead of
       overflowing past 100vh. */
    --pad-x: clamp(16px, 4vw, 56px);
    --pad-y: clamp(12px, 3vh, 40px);
    --gap-lg: clamp(8px, 2vh, 24px);
    --gap-md: clamp(6px, 1.4vh, 16px);
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-body);
    -webkit-font-smoothing: antialiased;
}

@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}

/* ============================================================
   Scroll-snap shell
   ============================================================ */

.scroller {
    height: 100vh;
    height: 100dvh; /* accounts for mobile browser chrome */
    overflow-y: scroll;
    scroll-snap-type: y mandatory;
}

.section {
    height: 100vh;
    height: 100dvh;
    scroll-snap-align: start;
    scroll-snap-stop: always;
    padding: var(--pad-y) var(--pad-x);
    display: flex;
    flex-direction: column;
    gap: var(--gap-lg);
    border-bottom: 1px solid var(--border-soft);
    overflow: hidden;
}

/* Section rail — fixed nav dots for jumping between sections */
.rail {
    position: fixed;
    right: 24px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 20;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.rail__dot {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--panel);
    color: var(--text-faint);
    font-family: var(--font-mono);
    font-size: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: border-color 0.25s ease, color 0.25s ease;
}

.rail__dot:hover {
    color: var(--text-muted);
}

.rail__dot.is-active {
    border-color: var(--accent);
    color: var(--accent);
}

/* ============================================================
   Shared building blocks
   ============================================================ */

.section__eyebrow {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex: 0 0 auto;
}

.wordmark {
    font-family: var(--font-mono);
    font-size: 15px;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    text-transform: uppercase;
}

.section__title {
    font-family: var(--font-mono);
    font-size: 13px;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.panel {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: clamp(12px, 2.2vh, 22px) clamp(14px, 2vw, 22px);
    min-height: 0;
    min-width: 0;
}

.panel__label {
    font-family: var(--font-mono);
    font-size: 11px;
    letter-spacing: 0.09em;
    text-transform: uppercase;
    color: var(--text-faint);
    margin-bottom: clamp(6px, 1.4vh, 14px);
}

.panel__note {
    font-size: 12.5px;
    color: var(--text-faint);
    line-height: 1.4;
    margin: clamp(4px, 1vh, 10px) 0 0;
}

.stat-value {
    font-family: var(--font-mono);
    font-size: clamp(20px, 3.4vh, 32px);
    font-weight: 500;
    color: var(--text);
    letter-spacing: -0.01em;
}

/* ============================================================
   Connect button
   ============================================================ */

.btn-connect {
    font-family: var(--font-mono);
    font-size: 12px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    background: transparent;
    color: var(--accent);
    border: 1px solid var(--accent-dim);
    border-radius: 6px;
    padding: 10px 18px;
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease;
}

.btn-connect:hover {
    background: var(--accent-wash);
    border-color: var(--accent);
}

.btn-connect.is-connected {
    color: var(--text);
    border-color: var(--border);
}

/* ============================================================
   SECTION 1 — Overview
   ============================================================ */

.overview-grid {
    display: grid;
    grid-template-columns: 2.1fr 1fr;
    gap: var(--gap-md);
    flex: 1 1 auto;
    min-height: 0;
}

.panel--graph {
    display: flex;
    flex-direction: column;
    position: relative;
    min-height: 0;
}

.panel--graph canvas {
    flex: 1;
    width: 100%;
    min-height: 0;
}

.graph-readout {
    position: absolute;
    top: 20px;
    right: 22px;
    font-family: var(--font-mono);
    text-align: right;
}

.graph-readout span:first-child {
    font-size: 26px;
    color: var(--accent);
}

.graph-readout__unit {
    font-size: 11px;
    color: var(--text-faint);
    margin-left: 6px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.panel--status {
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.status-line {
    display: flex;
    align-items: center;
    gap: 10px;
    font-family: var(--font-mono);
    font-size: 14px;
    margin-bottom: 6px;
}

.status-sync {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--accent);
    min-height: 14px;
    margin-bottom: 16px;
}

.status-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--text-faint);
    transition: background 0.4s ease, opacity 1.2s ease, box-shadow 0.4s ease;
}

.status-dot.is-connected {
    background: var(--accent);
    box-shadow: 0 0 10px 1px var(--accent-wash);
    animation: pulse-fade 2.4s ease-in-out infinite;
}

@keyframes pulse-fade {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.gauge-row {
    display: flex;
    flex-direction: column;
    gap: clamp(8px, 1.6vh, 16px);
}

.gauge__label {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.gauge__track {
    height: 6px;
    border-radius: 3px;
    background: var(--panel-raised);
    border: 1px solid var(--border-soft);
    overflow: hidden;
}

.gauge__fill {
    height: 100%;
    background: var(--accent-dim);
    border-radius: 3px;
    transition: width 0.6s ease;
}

.gauge__value {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 5px;
}

.stats-row {
    display: grid;
    grid-template-columns: 1.3fr 1fr 1fr 1fr;
    gap: var(--gap-md);
    flex: 0 1 auto;
    min-height: 0;
}

.panel--degree {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    min-height: 0;
}

.degree-gauge {
    width: 100%;
    max-width: clamp(120px, 16vh, 220px);
    height: auto;
    margin: 2px 0;
}

.degree-readout {
    font-family: var(--font-mono);
    font-size: clamp(18px, 3vh, 30px);
    color: var(--accent);
    margin-top: 2px;
}

.degree-caption {
    font-size: 11.5px;
    color: var(--text-faint);
    margin-top: 4px;
}

.stat-pair {
    display: flex;
    gap: 24px;
}

.stat-pair__label {
    display: block;
    font-size: 11px;
    color: var(--text-faint);
    text-transform: uppercase;
    letter-spacing: 0.07em;
    margin-bottom: 4px;
}

.stat-pair__value {
    display: block;
    font-family: var(--font-mono);
    font-size: 20px;
    color: var(--text);
}

/* ============================================================
   SECTION 2 — In-depth stats
   ============================================================ */

.panel--weekgraph {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
}

.panel--weekgraph canvas {
    flex: 1;
    width: 100%;
    min-height: 0;
}

.week-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: clamp(14px, 3vw, 28px);
    flex: 0 0 auto;
}

.week-nav__arrow {
    width: clamp(32px, 5vh, 38px);
    height: clamp(32px, 5vh, 38px);
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--panel);
    color: var(--text-muted);
    font-size: 16px;
    cursor: pointer;
    transition: border-color 0.2s ease, color 0.2s ease, opacity 0.2s ease;
}

.week-nav__arrow:hover:not(:disabled) {
    border-color: var(--accent);
    color: var(--accent);
}

.week-nav__arrow:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.week-nav__center {
    text-align: center;
    min-width: 220px;
}

.week-nav__label {
    font-family: var(--font-mono);
    font-size: 16px;
    color: var(--text);
}

.week-nav__sub {
    font-size: 12px;
    color: var(--text-faint);
    margin-top: 4px;
}

.stats-row--week {
    grid-template-columns: 1fr 1fr;
    max-width: 560px;
    margin: 0 auto;
    width: 100%;
    flex: 0 0 auto;
}

/* ============================================================
   SECTION 3 — Calibration & progress
   ============================================================ */

.cal-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
    gap: var(--gap-md);
    flex: 1 1 auto;
    min-height: 0;
}

.cal-grid .panel {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.form {
    display: flex;
    flex-direction: column;
    gap: clamp(6px, 1.4vh, 14px);
    margin-top: clamp(6px, 1.4vh, 16px);
    min-height: 0;
    overflow-y: auto;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 12.5px;
    color: var(--text-muted);
    flex: 0 0 auto;
}

.field input,
.field select {
    font-family: var(--font-mono);
    font-size: 14px;
    background: var(--panel-raised);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: clamp(6px, 1.2vh, 10px) 12px;
    color: var(--text);
}

.field input:focus,
.field select:focus {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
    border-color: var(--accent);
}

.btn-primary {
    font-family: var(--font-mono);
    font-size: 12px;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    background: var(--accent);
    color: #17130a;
    border: none;
    border-radius: 6px;
    padding: clamp(8px, 1.6vh, 12px) 16px;
    cursor: pointer;
    font-weight: 600;
    transition: filter 0.2s ease;
    flex: 0 0 auto;
}

.btn-primary:hover {
    filter: brightness(1.08);
}

.btn-primary:focus-visible,
.btn-connect:focus-visible,
.rail__dot:focus-visible,
.week-nav__arrow:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.curve-chart {
    width: 100%;
    height: auto;
    flex: 1 1 auto;
    min-height: 0;
    margin-bottom: 8px;
}

.cal-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: 0 1 auto;
    min-height: 0;
    overflow-y: auto;
}

.cal-list li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-family: var(--font-mono);
    font-size: 12.5px;
    color: var(--text-muted);
    padding: 8px 10px;
    border: 1px solid var(--border-soft);
    border-radius: 6px;
}

.cal-list li .cal-list__remove {
    background: none;
    border: none;
    color: var(--text-faint);
    cursor: pointer;
    font-size: 13px;
    padding: 2px 6px;
}

.cal-list li .cal-list__remove:hover {
    color: var(--warn);
}

.cal-list__empty {
    color: var(--text-faint);
    font-family: var(--font-body);
    font-size: 12.5px;
    padding: 8px 2px;
}

/* ============================================================
   Responsive
   ============================================================ */

@media (max-width: 980px) {
    .stats-row {
        grid-template-columns: 1fr 1fr;
    }
    .cal-grid {
        grid-template-columns: 1fr;
        grid-template-rows: none;
        overflow-y: auto;
    }
    .cal-grid .panel {
        min-height: 260px;
    }
    .rail {
        right: 8px;
    }
    .rail__dot {
        width: 24px;
        height: 24px;
    }
}

@media (max-width: 640px) {
    .overview-grid {
        grid-template-columns: 1fr;
        overflow-y: auto;
    }
    .panel--graph {
        min-height: 160px;
    }
    .panel--status {
        min-height: 140px;
        overflow-y: auto;
    }
    .stats-row {
        grid-template-columns: 1fr 1fr;
        overflow-y: auto;
    }
    .stats-row--week {
        grid-template-columns: 1fr 1fr;
    }
    .wordmark {
        font-size: 13px;
    }
    .btn-connect {
        padding: 8px 14px;
        font-size: 11px;
    }
}

/* Short viewports (small laptops, phones in landscape): compress
   further and allow a section to scroll internally as a last resort
   rather than bleed into the next section. */
@media (max-height: 620px) {
    :root {
        --pad-y: clamp(8px, 2vh, 20px);
        --gap-lg: clamp(6px, 1.2vh, 14px);
        --gap-md: clamp(4px, 1vh, 10px);
    }
    .section {
        overflow-y: auto;
    }
    .panel--graph,
    .panel--weekgraph {
        min-height: 120px;
    }
    .degree-gauge {
        max-width: 100px;
    }
}