:root {
  --bg: #f3f6f5;
  --surface: #ffffff;
  --surface-2: #eaf0ee;
  --text: #13201c;
  --muted: #5a6b65;
  --border: #d6e0dc;
  --accent: #0f766e;
  --accent-soft: #ccebe6;
  --accent-contrast: #ffffff;
  --warn: #b45309;
  --danger: #b91c1c;
  --radius: 16px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c1311;
    --surface: #151f1c;
    --surface-2: #1c2925;
    --text: #e6eeeb;
    --muted: #8fa29c;
    --border: #253430;
    --accent: #2dd4bf;
    --accent-soft: #123a35;
    --accent-contrast: #04201c;
    --warn: #f59e0b;
    --danger: #f87171;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom);
}

main {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
}

/* ---------- Top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 1.15rem; margin: 0; font-weight: 650; }
.back {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  margin-left: -8px;
  border-radius: 12px;
  color: var(--text);
  text-decoration: none;
}
.back:active { background: var(--surface-2); }
.back svg { width: 24px; height: 24px; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.card h2 {
  font-size: 0.95rem;
  margin: 0 0 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 650;
}

.saved {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--accent);
  opacity: 0;
  transition: opacity 0.3s;
}
.saved.show { opacity: 1; }

/* ---------- Inputs ---------- */
label, .label { display: block; font-size: 0.9rem; color: var(--muted); margin-bottom: 6px; }

.field { margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }

.input-wrap {
  display: flex;
  align-items: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0 12px;
}
.input-wrap:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input-wrap input, .input-wrap select {
  flex: 1;
  width: 100%;
  min-width: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 1.05rem;
  padding: 12px 0;
  outline: none;
}
.input-wrap select { appearance: none; cursor: pointer; }
.input-wrap .unit { color: var(--muted); font-size: 0.95rem; padding-left: 8px; }

.big .input-wrap input { font-size: 2.2rem; font-weight: 650; padding: 8px 0; font-variant-numeric: tabular-nums; }
.big .input-wrap .unit { font-size: 1.4rem; }

.hint { font-size: 0.82rem; color: var(--muted); margin-top: 6px; }

input[type="range"] {
  width: 100%;
  margin: 14px 0 2px;
  accent-color: var(--accent);
  height: 28px;
}

.check {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  color: var(--text);
  font-size: 1rem;
  cursor: pointer;
  margin: 0;
}
.check input { width: 22px; height: 22px; margin: 1px 0 0; accent-color: var(--accent); flex: none; }
.check small { display: block; color: var(--muted); font-size: 0.82rem; }

.row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; }

details { margin-top: 14px; border-top: 1px solid var(--border); padding-top: 12px; }
summary { cursor: pointer; color: var(--muted); font-size: 0.9rem; padding: 4px 0; }
details[open] summary { margin-bottom: 12px; }

/* ---------- Result ---------- */
.result { background: var(--accent-soft); border-color: transparent; text-align: center; padding: 20px 16px; }
.result-label { font-size: 0.9rem; color: var(--muted); }
.result-value {
  font-size: 2.8rem;
  font-weight: 750;
  line-height: 1.15;
  margin: 4px 0;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}
.result-value.empty { color: var(--muted); font-size: 1.4rem; font-weight: 500; padding: 14px 0; }
.result-sub { font-size: 0.92rem; color: var(--muted); }
.result-sub div + div { margin-top: 2px; }

.status { margin-top: 10px; font-size: 0.9rem; font-weight: 600; }
.status.warn { color: var(--warn); }
.status.danger { color: var(--danger); }

/* Battery gauge */
.gauge {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 12px auto 6px;
  max-width: 260px;
}
.gauge-body {
  flex: 1;
  height: 34px;
  border: 3px solid var(--text);
  border-radius: 8px;
  padding: 3px;
}
.gauge-fill {
  height: 100%;
  width: 0;
  border-radius: 3px;
  background: var(--accent);
  transition: width 0.25s ease;
}
.gauge-fill.low { background: var(--danger); }
.gauge-fill.mid { background: var(--warn); }
.gauge-cap { width: 6px; height: 14px; background: var(--text); border-radius: 0 3px 3px 0; }

.note { font-size: 0.85rem; color: var(--muted); padding: 0 4px; }
.note strong { color: var(--text); }

/* ---------- Launcher ---------- */
.hero { padding: calc(28px + env(safe-area-inset-top)) 16px 4px; max-width: 560px; margin: 0 auto; }
.hero h1 { margin: 0; font-size: 1.6rem; }
.hero p { margin: 4px 0 0; color: var(--muted); }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.tile {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 18px 16px;
  min-height: 150px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  text-decoration: none;
  transition: transform 0.1s, border-color 0.15s;
}
.tile:hover { border-color: var(--accent); }
.tile:active { transform: scale(0.98); }
.tile-icon {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: var(--accent-soft);
  color: var(--accent);
}
.tile-icon svg { width: 28px; height: 28px; }
.tile-title { font-weight: 650; font-size: 1.02rem; }
.tile-desc { font-size: 0.85rem; color: var(--muted); margin-top: -6px; }

.footer-status { text-align: center; font-size: 0.82rem; color: var(--muted); padding: 8px 0 24px; }

/* ---------- Update banner ---------- */
.update-banner {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  max-width: 528px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  background: var(--text);
  color: var(--bg);
  border-radius: 14px;
  box-shadow: 0 6px 24px rgb(0 0 0 / 0.25);
  z-index: 20;
}
.update-banner button {
  border: 0;
  border-radius: 10px;
  padding: 8px 14px;
  font: inherit;
  font-weight: 650;
  background: var(--accent);
  color: var(--accent-contrast);
  cursor: pointer;
}

/* Smaller headline for combined values like "60 % · 52.30 V" */
.result-value.compact { font-size: 2rem; }

/* Quick-pick buttons */
.chips { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin-top: 10px; }
.chip {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 0;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.chip:active { transform: scale(0.97); }
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-contrast); border-color: transparent; }
