:root {
  --bg: #0f1115;
  --card: #171a21;
  --card-2: #1d212a;
  --line: #262b36;
  --grid: #232833;
  --text: #e8ebf0;
  --muted: #8b94a5;
  --accent: #4ade80;
  --danger: #f87171;

  --c-lvl: #60a5fa;
  --c-thr: #fbbf24;
  --c-floor: #6b7280;
  --c-hit: #4ade80;
  --c-rej: #4b5563;

  color-scheme: dark;
}

* { box-sizing: border-box; }

/* Egna display-regler slår annars ut webbläsarens [hidden], eftersom
   författarstilar går före UA-stilar oavsett specificitet. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%;
}

main {
  max-width: 780px;
  margin: 0 auto;
  padding: 16px 16px calc(32px + env(safe-area-inset-bottom));
  display: grid;
  gap: 14px;
}

header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding-top: env(safe-area-inset-top);
}

h1 { font-size: 19px; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 13px; margin: 0 0 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }

.badge {
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

section {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
}

/* ---- Räknare ---- */

.counter-card { text-align: center; }

#count {
  display: block;
  font-size: clamp(64px, 22vw, 104px);
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.04em;
}

.counter-sub {
  display: flex;
  justify-content: center;
  gap: 20px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
}

.counter-sub b { color: var(--text); font-variant-numeric: tabular-nums; }

.buttons {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-top: 18px;
  flex-wrap: wrap;
}

button {
  font: inherit;
  font-weight: 500;
  padding: 10px 18px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--card-2);
  color: var(--text);
  cursor: pointer;
  min-height: 44px;
}

button:hover:not(:disabled) { border-color: #38404f; }
button:disabled { opacity: 0.4; cursor: default; }

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #05200f;
}

button.primary.recording {
  background: var(--danger);
  border-color: var(--danger);
  color: #2a0808;
}

.status {
  margin: 14px 0 0;
  font-size: 13px;
  color: var(--muted);
  min-height: 1.5em;
}

/* ---- Oscilloskop ---- */

.scope-card { padding: 12px; }

#scope {
  display: block;
  width: 100%;
  height: 200px;
  background: #0c0e13;
  border-radius: 8px;
}

.legend {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  margin-top: 10px;
  font-size: 12px;
  color: var(--muted);
}

.k {
  display: inline-block;
  width: 14px;
  height: 3px;
  border-radius: 2px;
  vertical-align: middle;
  margin-right: 2px;
}

.k.lvl { background: var(--c-lvl); }
.k.thr { background: var(--c-thr); }
.k.flr { background: var(--c-floor); }
.k.hit { background: var(--c-hit); }

/* ---- Statistik ---- */

.stats-card {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 12px;
}

.stat { text-align: center; }
.stat label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.stat b { font-size: 18px; font-variant-numeric: tabular-nums; font-weight: 600; }

/* ---- Reglage ---- */

.ctl { margin-bottom: 20px; }
.ctl:last-child { margin-bottom: 0; }

.ctl label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
  margin-bottom: 8px;
}

.ctl label.row {
  justify-content: flex-start;
  gap: 8px;
  cursor: pointer;
}

.ctl output {
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  font-size: 13px;
}

.ctl output.muted { color: var(--muted); display: block; text-align: right; margin-top: 4px; }

.ctl small {
  display: block;
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  height: 28px;
}

input[type="range"]:disabled { opacity: 0.35; }

input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

/* ---- Logg ---- */

#log {
  list-style: none;
  margin: 0;
  padding: 0;
  font-variant-numeric: tabular-nums;
  font-size: 13px;
}

#log li {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1.2fr;
  gap: 8px;
  padding: 6px 0;
  border-top: 1px solid var(--line);
  color: var(--text);
}

#log li:first-child { border-top: none; }
#log li.rejected { color: var(--muted); }
#log li span:last-child { color: var(--muted); font-size: 12px; }

/* ---- Autokalibrering ---- */

.hint {
  margin: 0 0 14px;
  font-size: 13px;
  color: var(--muted);
}

.truth-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 14px;
}

.truth-row label { font-size: 14px; }

.truth-row input[type="number"] {
  font: inherit;
  width: 88px;
  padding: 9px 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--card-2);
  color: var(--text);
  text-align: center;
  font-variant-numeric: tabular-nums;
  min-height: 44px;
}

.calib-table {
  width: 100%;
  border-collapse: collapse;
  margin: 4px 0 12px;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.calib-table th {
  text-align: right;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  padding: 0 0 6px;
}

.calib-table th:first-child { text-align: left; }

.calib-table td {
  padding: 7px 0;
  border-top: 1px solid var(--line);
  text-align: right;
}

.calib-table td:first-child { text-align: left; color: var(--muted); }
.calib-table td.new { color: var(--accent); font-weight: 600; }
.calib-table td.old { color: var(--muted); }

#calibResult button { margin-top: 4px; }
