:root {
  color-scheme: dark;
  --bg: #0b0f14;
  --panel: rgba(16, 20, 26, 0.88);
  --line: #232a33;
  --ink: #dbe3ec;
  --dim: #8b98a8;
  --cyan: #7fe9ee;
  --good: #7ce49a;
  --bad: #f2a07a;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

#view {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: grab;
}

#view:active { cursor: grabbing; }

.panel {
  position: fixed;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  backdrop-filter: blur(8px);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
}

.panel h2 {
  margin: 0 0 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--dim);
}

/* ── meter ─────────────────────────────────────────────────────────────── */
#meter { top: 12px; left: 12px; width: 300px; }

#reading {
  display: block;
  font: 600 32px/1.1 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: #6f7b88;
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
}
#reading.live { color: var(--cyan); text-shadow: 0 0 14px rgba(127, 233, 238, 0.35); }

#detail { margin: 2px 0 8px; font-size: 11px; }

.modes { display: flex; gap: 4px; margin-bottom: 8px; }

button, select {
  font: inherit;
  color: var(--ink);
  background: #1a2029;
  border: 1px solid #2a323d;
  border-radius: 7px;
  padding: 6px 10px;
  cursor: pointer;
}
button:hover, select:hover { border-color: #3a4552; }
button:active { transform: translateY(1px); }

.modes button { flex: 1; padding: 7px 0; }
.modes button.on {
  background: #12333a;
  border-color: #2f6d75;
  color: var(--cyan);
}

.row { display: flex; gap: 8px; align-items: center; }

.switch {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  white-space: nowrap;
}
.switch input { accent-color: #4dd4dc; width: 16px; height: 16px; }

#knob { flex: 1; min-width: 0; }

#probes { margin: 8px 0 0; font-size: 11px; line-height: 1.6; }
#probes span { white-space: nowrap; }

.dim { color: var(--dim); }

/* ── notebook ──────────────────────────────────────────────────────────── */
#notebook { top: 236px; left: 12px; width: 300px; }

#devices {
  list-style: none;
  margin: 0 0 10px;
  padding: 0;
  max-height: 38vh;
  overflow: auto;
  scrollbar-width: thin;
}

#devices label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 4px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
}
#devices label:hover { background: rgba(255, 255, 255, 0.04); }
#devices input { accent-color: #4dd4dc; width: 16px; height: 16px; flex: none; }

.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.actions button { font-size: 12px; padding: 6px 9px; }
#submit { background: #14303a; border-color: #2f6d75; }

#verdict { margin: 8px 0 0; font-size: 12px; min-height: 1.2em; }
#verdict.win { color: var(--good); }
#verdict.lose { color: var(--bad); }

/* ── bottom bar ────────────────────────────────────────────────────────── */
#bar {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: 12px;
  display: flex;
  gap: 14px;
  align-items: center;
  padding: 8px 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 12px;
  backdrop-filter: blur(8px);
}
#hint { flex: 1; }
#hover { text-align: right; color: var(--cyan); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 45%; }

/* ── hold-to-unscrew progress ──────────────────────────────────────────── */
#progress {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 74px;
  width: min(320px, 60vw);
  height: 6px;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  overflow: hidden;
}
#progress > i {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, #37c2cc, var(--cyan));
}

.fatal {
  position: fixed;
  inset: 24px;
  margin: 0;
  padding: 16px;
  overflow: auto;
  background: #140d0d;
  border: 1px solid #5a2a2a;
  border-radius: 10px;
  color: #ffb4a8;
  font: 13px/1.5 ui-monospace, monospace;
  white-space: pre-wrap;
}

/* ── phone portrait: keep the scene visible, shrink the chrome ─────────── */
@media (max-width: 760px) {
  #meter { top: 8px; left: 8px; width: min(240px, 62vw); padding: 8px 10px; }
  #reading { font-size: 24px; }
  #detail { font-size: 10px; margin-bottom: 6px; }
  .modes button { padding: 5px 0; font-size: 12px; }
  #probes { display: none; }

  #notebook {
    top: auto;
    left: 8px;
    right: 8px;
    bottom: 52px;
    width: auto;
    padding: 8px 10px;
  }
  #devices {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 0 10px;
    max-height: 24vh;
    margin-bottom: 8px;
  }
  #devices label { font-size: 12px; padding: 3px 2px; }

  #bar { left: 8px; right: 8px; bottom: 8px; padding: 6px 10px; font-size: 11px; }
  #hover { display: none; }
  #progress { bottom: auto; top: 50%; }
}

/* Landscape phones: side panels only, no bottom sheet. */
@media (max-height: 520px) and (min-width: 700px) {
  #notebook { top: 210px; bottom: auto; }
  #devices { max-height: 34vh; }
  #bar { display: none; }
}
