/* ==========================================================================
   Clamor — sound level meter
   Dark, instrument-style UI: one big readout, stats, history graph, controls.
   ========================================================================== */

:root {
    --bg: #080c14;
    --surface: #111726cc;
    --surface-solid: #121826;
    --border: #222a3c;
    --text: #e9edf6;
    --text-soft: #9aa4ba;
    --text-faint: #626c82;
    --accent: #38bdf8;
    --accent-2: #a78bfa;
    --ok: #34d399;
    --warn: #fbbf24;
    --hot: #fb7185;
    --radius: 16px;
    --radius-sm: 10px;
    --font: 'Space Grotesk', system-ui, -apple-system, sans-serif;
    --mono: 'JetBrains Mono', ui-monospace, Menlo, monospace;
}

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

body {
    font-family: var(--font);
    color: var(--text);
    background:
        radial-gradient(900px 500px at 12% -5%, rgba(56, 189, 248, 0.12), transparent 60%),
        radial-gradient(800px 600px at 92% 0%, rgba(167, 139, 250, 0.12), transparent 55%),
        var(--bg);
    background-attachment: fixed;
    min-height: 100vh;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

.wrap {
    width: min(100% - 2rem, 960px);
    margin: 0 auto;
    padding: clamp(1.5rem, 4vw, 3rem) 0 3rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

/* ---- Hero ---- */
.hero {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .5rem;
}

.hero-mark {
    font-size: 2.6rem;
    line-height: 1;
}

h1 {
    font-size: clamp(2rem, 6vw, 3rem);
    letter-spacing: -.02em;
    background: linear-gradient(100deg, var(--accent), var(--accent-2));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.lede {
    color: var(--text-soft);
    max-width: 62ch;
}

.lede strong {
    color: var(--text);
}

/* ---- Stage ---- */
.stage {
    display: grid;
    grid-template-columns: minmax(260px, 1fr) minmax(240px, 340px);
    gap: 1.25rem;
    align-items: center;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: clamp(1rem, 3vw, 1.75rem);
    backdrop-filter: blur(8px);
}

@media (max-width: 720px) {
    .stage {
        grid-template-columns: 1fr;
    }
}

.gauge {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.gauge-svg {
    width: 100%;
    max-width: 380px;
    height: auto;
    overflow: visible;
}

.gauge-track {
    fill: none;
    stroke: #1b2333;
    stroke-width: 14;
    stroke-linecap: round;
}

.gauge-arc {
    fill: none;
    stroke: url(#arcGrad);
    stroke-width: 14;
    stroke-linecap: round;
    transition: stroke-dashoffset .12s linear;
}

.gauge-peak {
    stroke: #e2e8f0;
    stroke-width: 3;
    stroke-linecap: round;
    opacity: .85;
}

.gauge-alarm {
    stroke: var(--hot);
    stroke-width: 3;
    stroke-linecap: round;
    opacity: 0;
}

.gauge-alarm.on {
    opacity: 1;
}

.gauge-readout {
    margin-top: -3.6rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.db-now {
    font-family: var(--mono);
    font-weight: 700;
    font-size: clamp(2.8rem, 12vw, 4.4rem);
    line-height: 1;
    letter-spacing: -.03em;
    font-variant-numeric: tabular-nums;
}

.db-unit {
    font-size: .78rem;
    color: var(--text-faint);
    letter-spacing: .04em;
    text-transform: uppercase;
}

.db-label {
    margin-top: .35rem;
    font-size: .95rem;
    color: var(--text-soft);
    min-height: 1.5em;
}

.stage-side {
    display: flex;
    flex-direction: column;
    gap: .9rem;
}

/* ---- Status pill ---- */
.pill {
    align-self: flex-start;
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    padding: .3rem .75rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: #0d121d;
    font-size: .82rem;
    color: var(--text-soft);
}

.pill .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-faint);
}

.pill-live .dot {
    background: var(--ok);
    box-shadow: 0 0 8px var(--ok);
    animation: pulse 1.6s ease-in-out infinite;
}

.pill-alarm .dot {
    background: var(--hot);
    box-shadow: 0 0 8px var(--hot);
}

.pill-error .dot {
    background: var(--warn);
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: .35;
    }
}

/* ---- Stats ---- */
.stats {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: .6rem;
}

.stat {
    background: #0d121d;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: .55rem .7rem;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.stat-label {
    font-size: .7rem;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--text-faint);
}

.stat-value {
    font-family: var(--mono);
    font-size: 1.05rem;
    font-variant-numeric: tabular-nums;
}

/* ---- Cards ---- */
.graph-card,
.scale-card,
.controls {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: clamp(1rem, 3vw, 1.5rem);
    backdrop-filter: blur(8px);
}

.card-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: .75rem;
}

.card-head h2 {
    font-size: 1.05rem;
    letter-spacing: .01em;
}

.card-note {
    font-size: .8rem;
    color: var(--text-faint);
}

.history {
    width: 100%;
    height: 180px;
    display: block;
    border-radius: var(--radius-sm);
    background: #0a0f19;
    border: 1px solid var(--border);
}

/* ---- Controls ---- */
.controls {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.control-row {
    display: flex;
    flex-wrap: wrap;
    gap: .75rem;
    align-items: center;
}

.btn {
    font: inherit;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    padding: .65rem 1.1rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: #0d121d;
    color: var(--text);
    cursor: pointer;
    transition: transform .12s ease, border-color .12s ease, background .12s ease;
}

.btn:hover {
    border-color: var(--accent);
    transform: translateY(-1px);
}

.btn:active {
    transform: translateY(0);
}

.btn:focus-visible,
input:focus-visible,
a:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.btn-primary {
    background: linear-gradient(100deg, rgba(56, 189, 248, .22), rgba(167, 139, 250, .22));
    border-color: #2b4a63;
}

.btn.is-live {
    background: linear-gradient(100deg, rgba(251, 113, 133, .22), rgba(251, 191, 36, .18));
    border-color: #5c3040;
}

.btn[disabled] {
    opacity: .55;
    cursor: not-allowed;
    transform: none;
}

.notice {
    border: 1px solid #4a3a1c;
    background: #1b1509;
    color: #f5d99a;
    border-radius: var(--radius-sm);
    padding: .7rem .9rem;
    font-size: .9rem;
}

.control-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 1rem;
}

.panel {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: .9rem 1rem 1rem;
    display: flex;
    flex-direction: column;
    gap: .75rem;
    background: #0c111b80;
    min-width: 0;
}

.panel legend {
    padding: 0 .4rem;
    font-size: .78rem;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--text-faint);
}

/* ---- Switches ---- */
.switch {
    display: flex;
    align-items: center;
    gap: .6rem;
    cursor: pointer;
    user-select: none;
}

.switch input {
    position: absolute;
    opacity: 0;
    width: 1px;
    height: 1px;
}

.switch-track {
    flex: none;
    width: 40px;
    height: 22px;
    border-radius: 999px;
    background: #1b2333;
    border: 1px solid var(--border);
    position: relative;
    transition: background .15s ease, border-color .15s ease;
}

.switch-track::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--text-faint);
    transition: transform .15s ease, background .15s ease;
}

.switch input:checked+.switch-track {
    background: rgba(56, 189, 248, .3);
    border-color: var(--accent);
}

.switch input:checked+.switch-track::after {
    transform: translateX(18px);
    background: var(--accent);
}

.switch input:focus-visible+.switch-track {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.switch-label {
    font-size: .92rem;
    color: var(--text-soft);
}

/* ---- Sliders ---- */
.slider {
    display: flex;
    flex-direction: column;
    gap: .3rem;
}

.slider label {
    display: flex;
    justify-content: space-between;
    gap: .75rem;
    font-size: .92rem;
    color: var(--text-soft);
}

.slider output {
    font-family: var(--mono);
    color: var(--text);
    font-size: .88rem;
}

input[type='range'] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    border-radius: 999px;
    background: #1b2333;
    cursor: pointer;
}

input[type='range']::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--accent);
    border: 2px solid #0b1018;
}

input[type='range']::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border: 2px solid #0b1018;
    border-radius: 50%;
    background: var(--accent);
}

.hint {
    font-size: .78rem;
    color: var(--text-faint);
}

.shortcuts {
    font-size: .82rem;
    color: var(--text-faint);
}

kbd {
    font-family: var(--mono);
    font-size: .78rem;
    padding: .05rem .35rem;
    border: 1px solid var(--border);
    border-bottom-width: 2px;
    border-radius: 6px;
    background: #0d121d;
    color: var(--text-soft);
}

/* ---- Scale ---- */
.scale-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: .5rem;
    color: var(--text-soft);
    font-size: .93rem;
}

.chip {
    display: inline-block;
    min-width: 6.6rem;
    text-align: center;
    margin-right: .6rem;
    padding: .1rem .5rem;
    border-radius: 999px;
    font-family: var(--mono);
    font-size: .78rem;
    color: #08111a;
    background: var(--text-faint);
}

.chip-quiet {
    background: #67e8f9;
}

.chip-calm {
    background: #34d399;
}

.chip-normal {
    background: #a3e635;
}

.chip-loud {
    background: #fbbf24;
}

.chip-harm {
    background: #fb923c;
}

.chip-danger {
    background: #fb7185;
}

.disclaimer {
    margin-top: .9rem;
    font-size: .82rem;
    color: var(--text-faint);
}

/* ---- Footer ---- */
.foot {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: .5rem;
    font-size: .85rem;
    color: var(--text-faint);
}

.back {
    color: var(--accent);
    text-decoration: none;
}

.back:hover {
    text-decoration: underline;
}

/* ---- Alarm flash ---- */
.flash {
    position: fixed;
    inset: 0;
    pointer-events: none;
    background: rgba(251, 113, 133, .35);
    opacity: 0;
    transition: opacity .12s ease;
    z-index: 50;
}

.flash.on {
    opacity: 1;
}

body.alarming .db-now {
    color: var(--hot);
}

@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        animation-duration: .001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .001ms !important;
    }
}
