:root {
  --bg: #0e1116;
  --bg-raised: #161b23;
  --bg-pad: #10151d;
  --border: #2a3240;
  --text: #e8edf4;
  --text-dim: #94a0b0;
  --accent: #4da3ff;
  --accent-strong: #1f7ae0;
  --good: #37c978;
  --warn: #f2b135;
  --bad: #f2635a;
  --radius: 16px;
  font-size: 16px;
}

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

html, body {
  height: 100%;
  overscroll-behavior: none;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* ---------- screens ---------- */
.screen {
  position: fixed;
  inset: 0;
  display: none;
  flex-direction: column;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--bg);
}
.screen.active { display: flex; }
.screen.overlay { z-index: 10; }

/* ---------- top / bottom bars ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  flex: 0 0 auto;
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: 0.02em;
}
.brand-icon { width: 26px; height: 26px; }
.topbar-actions { display: flex; gap: 8px; }

.bottombar {
  display: flex;
  gap: 12px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  flex: 0 0 auto;
}
.bottombar .btn { flex: 1; }

/* ---------- buttons ---------- */
.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--bg-raised);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  padding: 14px 18px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: filter 0.15s ease, opacity 0.15s ease;
}
.btn:active { filter: brightness(1.25); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.primary {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
  color: #fff;
}
.btn.ghost { background: transparent; }
.btn.small { padding: 8px 12px; border-radius: 12px; font-size: 0.85rem; }

/* ---------- banner ---------- */
.banner {
  margin: 0 16px 8px;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 0.85rem;
  line-height: 1.4;
  background: rgba(242, 177, 53, 0.12);
  border: 1px solid rgba(242, 177, 53, 0.45);
  color: var(--warn);
  flex: 0 0 auto;
}
.banner.bad {
  background: rgba(242, 99, 90, 0.12);
  border-color: rgba(242, 99, 90, 0.45);
  color: var(--bad);
}
.hidden { display: none !important; }

/* ---------- weighing pad ---------- */
.pad {
  flex: 1 1 auto;
  margin: 4px 16px;
  border: 2px dashed var(--border);
  border-radius: 24px;
  background:
    radial-gradient(ellipse at 50% 35%, rgba(77, 163, 255, 0.07), transparent 60%),
    var(--bg-pad);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  touch-action: none;
  position: relative;
  overflow: hidden;
}
.pad.touching { border-color: var(--accent); }

.readout { text-align: center; }
.mass {
  font-size: clamp(3.5rem, 18vw, 6.5rem);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  letter-spacing: -0.02em;
}
.mass-unit {
  color: var(--text-dim);
  font-size: 1rem;
  margin-top: 6px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}
.status-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 18px;
  min-height: 20px;
}
.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--text-dim);
  transition: background 0.2s ease;
}
.dot.stable { background: var(--good); }
.dot.unstable { background: var(--warn); }
.status-text { color: var(--text-dim); font-size: 0.9rem; }
.raw-line {
  margin-top: 10px;
  color: var(--text-dim);
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
  opacity: 0.7;
}

.pad-hint {
  position: absolute;
  bottom: 14px;
  left: 16px;
  right: 16px;
  text-align: center;
  color: var(--text-dim);
  font-size: 0.78rem;
  line-height: 1.45;
  pointer-events: none;
}

/* ---------- calibration ---------- */
.cal-step {
  display: none;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
}
.cal-step.active { display: flex; }

.cal-body {
  padding: 8px 20px 16px;
  overflow-y: auto;
  flex: 0 1 auto;
}
.cal-body.center { text-align: center; margin: auto 0; }
.cal-body h2 { font-size: 1.35rem; margin-bottom: 12px; }
.cal-body p { color: var(--text-dim); line-height: 1.5; margin-bottom: 10px; }
.cal-body p strong, .steps-list strong { color: var(--text); }
.steps-list {
  margin: 0 0 12px 20px;
  color: var(--text-dim);
  line-height: 1.55;
  display: grid;
  gap: 10px;
}
.muted { color: var(--text-dim); font-size: 0.85rem; }

.field { display: block; margin: 8px 0 4px; }
.field span {
  display: block;
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-bottom: 6px;
}
.field input {
  width: 100%;
  font: inherit;
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--text);
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
}
.field input:focus { outline: 2px solid var(--accent); border-color: transparent; }

.cal-pad {
  flex: 1 1 auto;
  margin: 4px 16px calc(16px + env(safe-area-inset-bottom));
  border: 2px dashed var(--border);
  border-radius: 24px;
  background: var(--bg-pad);
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  min-height: 200px;
}
.cal-pad.touching { border-color: var(--accent); }
.cal-pad-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  width: min(320px, 80%);
  text-align: center;
}
.cal-raw {
  font-size: 1.6rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text-dim);
}
.cal-raw-value { color: var(--text); }
.btn-capture { width: 100%; }
.capture-progress {
  width: 100%;
  height: 8px;
  border-radius: 4px;
  background: var(--bg-raised);
  overflow: hidden;
}
.capture-bar {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.1s linear;
}
.cal-msg { font-size: 0.85rem; color: var(--warn); min-height: 1.2em; }
.cal-result { font-size: 1rem; color: var(--text); line-height: 1.6; }

/* ---------- sensor check ---------- */
.sensor-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 8px 20px calc(20px + env(safe-area-inset-bottom));
  gap: 16px;
}
.sensor-body > p { color: var(--text-dim); line-height: 1.5; }
.sensor-body strong { color: var(--text); }
.sensor-pad {
  flex: 1;
  border: 2px dashed var(--border);
  border-radius: 24px;
  background: var(--bg-pad);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  touch-action: none;
  min-height: 220px;
}
.sensor-pad.touching { border-color: var(--accent); }
.sensor-raw {
  font-size: 3rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.sensor-raw-label {
  color: var(--text-dim);
  font-size: 0.8rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}
.sensor-bar-wrap {
  width: 70%;
  height: 10px;
  border-radius: 5px;
  background: var(--bg-raised);
  overflow: hidden;
  margin-top: 10px;
}
.sensor-bar {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.05s linear;
}
.sensor-verdict {
  border: 1px solid var(--border);
  background: var(--bg-raised);
  border-radius: var(--radius);
  padding: 14px 16px;
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--text-dim);
}
.sensor-verdict.good { border-color: rgba(55, 201, 120, 0.5); color: var(--good); }
.sensor-verdict.bad { border-color: rgba(242, 99, 90, 0.5); color: var(--bad); }

/* ---------- sim panel (?sim demo mode) ---------- */
.sim-panel {
  position: fixed;
  right: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom));
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--accent);
  border-radius: 12px;
  background: rgba(22, 27, 35, 0.95);
  font-size: 0.8rem;
  color: var(--text-dim);
}
.sim-panel label { display: flex; align-items: center; gap: 6px; }
.sim-panel input[type="range"] { width: 130px; }
.sim-panel span { font-variant-numeric: tabular-nums; color: var(--text); min-width: 3.2em; }

/* ---------- help ---------- */
.help-body {
  flex: 1;
  overflow-y: auto;
  padding: 4px 20px calc(24px + env(safe-area-inset-bottom));
}
.help-body h3 { margin: 20px 0 8px; font-size: 1.05rem; }
.help-body p, .help-body li { color: var(--text-dim); line-height: 1.55; font-size: 0.92rem; }
.help-body strong, .help-body em { color: var(--text); }
.help-body ul { margin: 6px 0 6px 20px; display: grid; gap: 8px; }
