:root {
    color-scheme: dark;
    font-family: Inter, Arial, sans-serif;
    --bg: #08111f;
    --panel: #0b1626;
    --panel-2: #101e30;
    --border: #26364d;
    --text: #edf2f8;
    --muted: #8494a8;
    --green: #38e29a;
    --blue: #63a8ff;
    --red: #ff7a86;
}

* { box-sizing: border-box; }

html,
body {
    min-width: 320px;
    min-height: 100%;
    margin: 0;
}

body {
    padding: 16px;
    overflow-x: hidden;
    background:
        radial-gradient(circle at 50% -12%, #162c45 0, transparent 42%),
        var(--bg);
    color: var(--text);
}

button,
input,
select { font: inherit; }

button { color: inherit; }

.layout {
    width: 100%;
    min-height: calc(100vh - 32px);
    display: grid;
    grid-template-columns: 228px minmax(0, 1fr) 228px;
    gap: 16px;
    align-items: start;
}

.side-panel {
    position: sticky;
    top: 16px;
    max-height: calc(100vh - 32px);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 18px;
    background: rgba(11, 22, 38, .96);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: 0 22px 60px rgba(0, 0, 0, .24);
    backdrop-filter: blur(14px);
}

.side-panel button,
.clear-btn {
    width: 100%;
    min-height: 41px;
    padding: 9px 11px;
    border: 1px solid #304259;
    border-radius: 8px;
    background: #111f31;
    color: #dce5ef;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    transition: border-color .18s ease, background .18s ease, transform .18s ease;
}

.side-panel button:hover,
.clear-btn:hover {
    border-color: #4f6c8b;
    background: #172a41;
    transform: translateY(-1px);
}

.side-panel button.is-active {
    border-color: #2f8667;
    background: #113329;
    color: #6cebb4;
}

.side-panel .back-btn {
    background: #102d28;
    border-color: #2b725b;
    color: #67ebb2;
}

.contest-note {
    padding: 12px;
    background: #0f1c2d;
    border: 1px solid #263950;
    border-radius: 9px;
    color: #8fa0b4;
    font-size: 10px;
    line-height: 1.55;
    text-align: center;
    text-transform: uppercase;
    letter-spacing: .7px;
}

.live-dot {
    display: inline-block;
    width: 7px;
    height: 7px;
    margin-right: 7px;
    border-radius: 50%;
    background: var(--green);
    box-shadow: 0 0 10px var(--green);
}

.panel-separator {
    height: 1px;
    margin: 6px 0;
    background: #25364c;
}

.panel-caption {
    color: #8293a8;
    font-size: 9px;
    font-weight: 800;
    letter-spacing: 1.2px;
    text-transform: uppercase;
}

#timerDisplay {
    padding: 12px 6px;
    background: #091524;
    border: 1px solid #2a3c53;
    border-radius: 8px;
    color: var(--green);
    font: 800 25px Consolas, monospace;
    text-align: center;
    text-shadow: 0 0 12px rgba(56, 226, 154, .32);
}

.timer-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.signal-legend {
    display: grid;
    gap: 12px;
    color: #8798ad;
    font-size: 10px;
}

.signal-legend span {
    display: flex;
    align-items: center;
    gap: 8px;
}

.signal-legend i {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.legend-normal { background: var(--green); box-shadow: 0 0 7px var(--green); }
.legend-low { background: var(--blue); box-shadow: 0 0 7px var(--blue); }
.legend-high { background: var(--red); box-shadow: 0 0 7px var(--red); }

.center-panel {
    min-width: 0;
    padding: 22px;
    background: rgba(8, 17, 31, .72);
    border: 1px solid rgba(60, 80, 106, .55);
    border-radius: 14px;
}

.trainer-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 30px;
    margin-bottom: 14px;
    padding: 25px 27px;
    background: linear-gradient(135deg, #0d1c2e, #0a1626);
    border: 1px solid var(--border);
    border-radius: 12px;
}

.eyebrow {
    margin-bottom: 9px;
    color: var(--green);
    font-size: 9px;
    font-weight: 800;
    letter-spacing: 2px;
    text-transform: uppercase;
}

.trainer-head h1 {
    margin: 0 0 9px;
    color: #f4f7fb;
    font-size: clamp(25px, 2.4vw, 39px);
    line-height: 1.05;
    letter-spacing: -1.5px;
}

.trainer-head h1 em {
    color: var(--green);
    font-style: normal;
}

.trainer-head p {
    max-width: 690px;
    margin: 0;
    color: #94a4b7;
    font-size: 13px;
    line-height: 1.6;
}

.live-summary {
    min-width: 340px;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.live-summary > div {
    min-height: 75px;
    display: grid;
    place-items: center;
    padding: 9px;
    background: #091524;
    border: 1px solid #283a51;
    border-radius: 8px;
    text-align: center;
}

.live-summary span {
    color: #718299;
    font-size: 8px;
    font-weight: 800;
    letter-spacing: .8px;
    text-transform: uppercase;
}

.live-summary strong {
    color: var(--green);
    font: 800 18px Consolas, monospace;
}

.system-line {
    margin-bottom: 14px;
    padding: 0 4px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
    color: #718299;
    font-size: 10px;
}

#systemState {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #8ea0b4;
}

#systemState i {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--green);
    box-shadow: 0 0 8px var(--green);
}

#systemState.has-warning { color: #f0b6bc; }
#systemState.has-warning i { background: var(--red); box-shadow: 0 0 8px var(--red); }

.sensor-container {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.sensor {
    min-width: 0;
    overflow: hidden;
    padding: 18px;
    background: linear-gradient(145deg, #0e1b2c, #0a1524);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 18px 42px rgba(0, 0, 0, .22);
    transition: border-color .18s ease, transform .18s ease, box-shadow .18s ease;
}

.sensor:hover {
    border-color: #3a4e68;
    transform: translateY(-2px);
}

.sensor[data-state="low"] { border-color: rgba(99, 168, 255, .5); }
.sensor[data-state="high"] { border-color: rgba(255, 122, 134, .55); }

.sensor-header {
    display: grid;
    grid-template-columns: 42px minmax(0, 1fr) auto;
    gap: 11px;
    align-items: center;
}

.sensor-badge {
    width: 40px;
    height: 40px;
    display: grid;
    place-items: center;
    border: 1px solid #31516b;
    border-radius: 50%;
    background: #10253a;
    color: #7ea8c8;
    font: 800 11px Consolas, monospace;
}

.sensor-title strong {
    display: block;
    color: #f0f4f8;
    font-size: 14px;
}

.sensor-title span {
    display: block;
    margin-top: 3px;
    color: #718299;
    font-size: 10px;
}

.sensor-state {
    padding: 5px 7px;
    border: 1px solid #2b725b;
    border-radius: 999px;
    background: #102d28;
    color: #67ebb2;
    font-size: 8px;
    font-weight: 800;
    letter-spacing: .7px;
}

.sensor[data-state="low"] .sensor-state {
    border-color: #335f91;
    background: #10233b;
    color: #87baff;
}

.sensor[data-state="high"] .sensor-state {
    border-color: #8f4550;
    background: #361c26;
    color: #ff9ca5;
}

.sensor-range {
    margin: 12px 0 10px;
    padding: 7px 9px;
    background: #101e30;
    border: 1px solid #293b52;
    border-radius: 7px;
    color: #a7b5c5;
    font: 700 10px Consolas, monospace;
    text-align: center;
}

.gauge-canvas {
    width: 100%;
    height: 218px;
    overflow: hidden;
    background: #0a1525;
    border: 1px solid #25364d;
    border-radius: 9px;
}

.gauge-canvas svg,
.trend-canvas svg {
    display: block;
    width: 100%;
    height: 100%;
}

.svg-error {
    display: grid;
    place-items: center;
    color: var(--red);
    font-size: 11px;
}

.measurement-panel {
    margin-top: 10px;
    display: grid;
    grid-template-columns: 1fr 1.15fr;
    gap: 9px;
}

.primary-reading,
.secondary-readings {
    min-height: 94px;
    padding: 12px;
    background: #0c1929;
    border: 1px solid #283a51;
    border-radius: 8px;
}

.primary-reading {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: end;
}

.primary-label {
    grid-column: 1 / -1;
    align-self: start;
    color: #718299;
    font-size: 8px;
    font-weight: 800;
    letter-spacing: .8px;
    text-transform: uppercase;
}

.primary-value {
    color: #f2f6fa;
    font: 800 26px Consolas, monospace;
}

.primary-unit {
    padding-bottom: 4px;
    color: var(--green);
    font-size: 10px;
    font-weight: 800;
}

.secondary-readings {
    display: grid;
    gap: 8px;
}

.secondary-readings div {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
}

.secondary-readings span {
    color: #718299;
    font-size: 9px;
}

.secondary-readings strong {
    color: #b8c6d6;
    font: 700 11px Consolas, monospace;
}

.current-scale {
    margin-top: 11px;
}

.current-scale-head {
    display: flex;
    justify-content: space-between;
    margin-bottom: 6px;
    color: #64758a;
    font: 700 8px Consolas, monospace;
}

.current-track {
    height: 8px;
    overflow: hidden;
    background: #1c2c40;
    border-radius: 999px;
}

.current-track i {
    display: block;
    width: 0;
    height: 100%;
    background: linear-gradient(90deg, #63a8ff, #38e29a 48%, #ff7a86);
    border-radius: inherit;
    box-shadow: 0 0 8px rgba(56, 226, 154, .4);
    transition: width .18s ease;
}

.manual-control {
    display: block;
    margin-top: 13px;
}

.manual-control > span {
    display: block;
    margin-bottom: 8px;
    color: #8495aa;
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .7px;
}

.sensor-slider {
    width: 100%;
    height: 5px;
    appearance: none;
    border-radius: 999px;
    background: #2a3c53;
    outline: none;
    cursor: pointer;
}

.sensor-slider::-webkit-slider-thumb {
    width: 18px;
    height: 18px;
    appearance: none;
    border: 3px solid #0f2d25;
    border-radius: 50%;
    background: var(--green);
    box-shadow: 0 0 9px rgba(56, 226, 154, .55);
}

.sensor-slider::-moz-range-thumb {
    width: 13px;
    height: 13px;
    border: 3px solid #0f2d25;
    border-radius: 50%;
    background: var(--green);
    box-shadow: 0 0 9px rgba(56, 226, 154, .55);
}

.trend-block {
    margin-top: 14px;
}

.trend-head {
    display: flex;
    justify-content: space-between;
    margin-bottom: 7px;
    color: #7c8da1;
    font-size: 9px;
}

.trend-head small { color: #53657c; }

.trend-canvas {
    width: 100%;
    height: 92px;
    overflow: hidden;
    background: #091524;
    border: 1px solid #22344a;
    border-radius: 7px;
}

.sensor-footer {
    margin-top: 11px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
}

.sensor-footer > span {
    color: #687b91;
    font-size: 9px;
}

.sensor-footer b {
    color: var(--green);
    font-weight: 700;
}

.sensor[data-state="low"] .sensor-footer b { color: var(--blue); }
.sensor[data-state="high"] .sensor-footer b { color: var(--red); }

.sensor-random {
    min-height: 31px;
    padding: 6px 9px;
    border: 1px solid #304259;
    border-radius: 7px;
    background: #101e30;
    color: #9eafc2;
    font-size: 9px;
    font-weight: 700;
    cursor: pointer;
}

.sensor-random:hover {
    border-color: #4f6c8b;
    background: #172a41;
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 18px;
    background: rgba(3, 8, 15, .82);
    backdrop-filter: blur(8px);
}

.modal-content {
    position: relative;
    width: min(820px, 96vw);
    max-height: 88vh;
    overflow-y: auto;
    padding: 28px;
    background: #0b1626;
    border: 1px solid #31475f;
    border-radius: 12px;
    box-shadow: 0 30px 80px rgba(0, 0, 0, .5);
}

.modal-kicker {
    margin-bottom: 8px;
    color: var(--green);
    font-size: 9px;
    font-weight: 800;
    letter-spacing: 1.7px;
    text-transform: uppercase;
}

.modal-content h2 {
    margin: 0 40px 22px 0;
    color: #f1f5f9;
    font-size: 25px;
}

.modal-content p,
.help-steps span {
    color: #91a2b6;
    font-size: 12px;
    line-height: 1.7;
}

.close {
    position: absolute;
    top: 12px;
    right: 14px;
    width: 38px;
    height: 38px;
    border: 0;
    background: transparent;
    color: #8394a9;
    font-size: 27px;
    cursor: pointer;
}

.formula-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.formula-grid > div,
.calc-column {
    padding: 16px;
    background: #0d1b2c;
    border: 1px solid #293d54;
    border-radius: 9px;
}

.formula-grid span {
    display: block;
    margin-bottom: 10px;
    color: #76889e;
    font-size: 9px;
    font-weight: 800;
    text-transform: uppercase;
}

.formula-grid code {
    color: var(--green);
    font: 700 12px/1.65 Consolas, monospace;
}

.calc-range-label,
.calc-column label {
    display: block;
    margin-bottom: 7px;
    color: #8293a8;
    font-size: 10px;
    font-weight: 700;
}

.calc-range-select,
.calc-column input {
    width: 100%;
    min-height: 42px;
    padding: 8px 10px;
    border: 1px solid #31445c;
    border-radius: 8px;
    background: #101e30;
    color: #e4ebf3;
    outline: none;
}

.calc-range-select:focus,
.calc-column input:focus { border-color: #3a9674; }

.calc-range-hint {
    margin: 8px 0 14px;
    color: var(--green);
    font: 700 10px Consolas, monospace;
}

.calc-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.calc-column h3 {
    margin: 0 0 14px;
    color: #dce4ed;
    font-size: 13px;
}

.calc-result {
    margin-top: 12px;
    padding: 11px;
    background: #091524;
    border-radius: 7px;
    color: #8394a9;
    font-size: 11px;
    text-align: center;
}

.calc-result strong { color: var(--green); font: 800 15px Consolas, monospace; }
.clear-btn { width: auto; margin-top: 13px; }
.input-error { border-color: var(--red) !important; background: #2d1821 !important; }
.result-error { color: var(--red) !important; }

.help-steps {
    margin: 0;
    padding-left: 22px;
    display: grid;
    gap: 14px;
}

.help-steps b {
    display: block;
    margin-bottom: 3px;
    color: #dce4ed;
    font-size: 12px;
}

.toast {
    position: fixed;
    right: 22px;
    bottom: 22px;
    z-index: 1200;
    max-width: min(360px, calc(100vw - 44px));
    padding: 12px 15px;
    transform: translateY(18px);
    opacity: 0;
    pointer-events: none;
    background: #102d28;
    border: 1px solid #2f7b61;
    border-radius: 8px;
    color: #73edb8;
    font-size: 11px;
    box-shadow: 0 16px 36px rgba(0, 0, 0, .36);
    transition: opacity .2s ease, transform .2s ease;
}

.toast.show { transform: translateY(0); opacity: 1; }
.toast.error { background: #321c25; border-color: #82414c; color: #ff9ca5; }

@media (max-width: 1280px) {
    .layout { grid-template-columns: 205px minmax(0, 1fr) 205px; }
    .side-panel { padding: 14px; }
    .trainer-head { align-items: flex-start; flex-direction: column; }
    .live-summary { width: 100%; min-width: 0; }
}

@media (max-width: 1040px) {
    .layout { display: block; }
    .side-panel { position: static; width: 100%; max-height: none; margin-bottom: 12px; }
    .left-panel,
    .right-panel { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .contest-note,
    .panel-separator,
    .panel-caption,
    .signal-legend { grid-column: 1 / -1; }
    .timer-buttons { display: grid; grid-template-columns: 1fr 1fr; }
    .center-panel { margin-bottom: 12px; }
}

@media (max-width: 760px) {
    body { padding: 8px; }
    .center-panel { padding: 12px; }
    .sensor-container { grid-template-columns: 1fr; }
    .trainer-head { padding: 20px; }
    .live-summary { grid-template-columns: 1fr; }
    .live-summary > div { min-height: 58px; }
    .system-line { align-items: flex-start; flex-direction: column; gap: 5px; }
    .left-panel,
    .right-panel { grid-template-columns: 1fr 1fr; }
    .formula-grid,
    .calc-container { grid-template-columns: 1fr; }
}

@media (max-width: 460px) {
    .left-panel,
    .right-panel { display: flex; }
    .sensor { padding: 12px; }
    .sensor-header { grid-template-columns: 40px 1fr; }
    .sensor-state { grid-column: 1 / -1; justify-self: start; }
    .gauge-canvas { height: 190px; }
    .measurement-panel { grid-template-columns: 1fr; }
    .sensor-footer { align-items: stretch; flex-direction: column; }
    .sensor-random { width: 100%; }
}
