:root {
  --bg: #0a0c0b;
  --surface: #141816;
  --surface-2: #1b201d;
  --line: rgba(255, 255, 255, 0.08);
  --text: #edf2ee;
  --muted: #8b968f;
  --accent: #c2f04a;
  --accent-dim: #9dc72f;
  --pause: #f0b429;
  --danger: #f2555a;
  --radius: 18px;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  background:
    radial-gradient(120% 60% at 50% -10%, rgba(194, 240, 74, 0.09), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: contain;
}

.app {
  max-width: 460px;
  margin: 0 auto;
  padding: 0 18px calc(84px + env(safe-area-inset-bottom));
}

/* ---------- barre haute ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 0 10px;
  position: sticky;
  top: 0;
  z-index: 20;
  background: linear-gradient(var(--bg) 70%, transparent);
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 650;
  letter-spacing: -0.02em;
  font-size: 17px;
}

.brand .mark {
  width: 22px;
  height: 22px;
  border-radius: 7px;
  background: var(--accent);
  display: grid;
  place-items: center;
  color: #10140c;
  font-size: 13px;
  font-weight: 800;
}

.chip {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  font-weight: 550;
  padding: 8px 13px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.chip:hover {
  border-color: rgba(255, 255, 255, 0.18);
}

.chip .led {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
}

.chip.on {
  border-color: rgba(194, 240, 74, 0.35);
  background: rgba(194, 240, 74, 0.08);
}

.chip.on .led {
  background: var(--accent);
  box-shadow: 0 0 10px var(--accent);
}

.chip.warn .led {
  background: var(--pause);
}

/* ---------- vues ---------- */
.view {
  display: none;
  animation: fade 0.25s ease;
}

.view.active {
  display: block;
}

@keyframes fade {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}

/* ---------- cadran ---------- */
.hero {
  position: relative;
  width: min(78vw, 290px);
  aspect-ratio: 1;
  margin: 8px auto 22px;
  display: grid;
  place-items: center;
}

.ring {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.ring circle {
  fill: none;
  stroke-width: 9;
  stroke-linecap: round;
}

.ring .track {
  stroke: rgba(255, 255, 255, 0.06);
}

.ring .progress {
  stroke: var(--accent);
  stroke-dasharray: 553;
  stroke-dashoffset: 553;
  transition: stroke-dashoffset 0.45s ease, stroke 0.3s;
}

body[data-belt="paused"] .ring .progress {
  stroke: var(--pause);
}

body[data-belt="stopped"] .ring .progress {
  stroke: #4b544e;
}

.hero-inner {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.speed {
  font-size: 62px;
  font-weight: 620;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.speed .unit {
  font-size: 15px;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: 0;
  margin-left: 5px;
}

.belt {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-top: 6px;
}

body[data-belt="running"] .belt {
  color: var(--accent);
}

body[data-belt="paused"] .belt {
  color: var(--pause);
}

/* ---------- métriques ---------- */
.metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}

.metric {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 13px 15px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.metric .k {
  font-size: 11.5px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  font-weight: 600;
}

.metric .v {
  font-size: 25px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.metric .v small {
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
  margin-left: 3px;
  letter-spacing: 0;
}

/* ---------- cible de vitesse ---------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 12px;
}

.panel-head .label {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  font-weight: 600;
}

.panel-head .value {
  font-size: 19px;
  font-weight: 620;
  font-variant-numeric: tabular-nums;
}

.stepper {
  display: flex;
  align-items: center;
  gap: 12px;
}

.rnd {
  width: 46px;
  height: 46px;
  flex: none;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  font-size: 22px;
  line-height: 1;
  font-weight: 400;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background 0.15s, transform 0.08s;
}

.rnd:active {
  transform: scale(0.93);
  background: #252b27;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  height: 6px;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--accent) var(--fill, 40%), #262c28 var(--fill, 40%));
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #fff;
  border: 4px solid #0a0c0b;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.5);
  cursor: grab;
}

input[type="range"]::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  border: 4px solid #0a0c0b;
  cursor: grab;
}

.presets {
  display: flex;
  gap: 7px;
  margin-top: 14px;
}

.presets button {
  flex: 1;
  padding: 9px 0;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: 0.15s;
}

.presets button:hover {
  color: var(--text);
  border-color: rgba(255, 255, 255, 0.18);
}

.presets button.sel {
  background: rgba(194, 240, 74, 0.12);
  border-color: rgba(194, 240, 74, 0.4);
  color: var(--accent);
}

/* ---------- actions ---------- */
.actions {
  display: grid;
  grid-template-columns: 1.6fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}

.btn {
  height: 60px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font: inherit;
  font-size: 16px;
  font-weight: 650;
  letter-spacing: -0.01em;
  cursor: pointer;
  transition: filter 0.15s, transform 0.08s, opacity 0.15s;
}

.btn:active {
  transform: scale(0.985);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn.primary {
  background: var(--accent);
  color: #0d1108;
}

.btn.primary:hover {
  filter: brightness(1.06);
}

.btn.danger {
  background: transparent;
  border-color: rgba(242, 85, 90, 0.4);
  color: var(--danger);
}

.btn.danger:hover {
  background: rgba(242, 85, 90, 0.09);
}

.btn.ghost {
  background: var(--surface);
  border-color: var(--line);
  color: var(--text);
  height: 44px;
  font-size: 14px;
}

/* ---------- avis ---------- */
.notice {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.5;
  padding: 0 2px;
}

.notice:empty {
  display: none;
}

.notice.warn {
  color: #f3d08a;
}

.notice a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid rgba(194, 240, 74, 0.4);
}

/* ---------- historique ---------- */
.history {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.entry {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 13px 15px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 12px;
}

.entry .when {
  font-weight: 600;
  font-size: 14px;
}

.entry .nums {
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  grid-column: 1;
}

.entry .big {
  grid-row: 1 / span 2;
  grid-column: 2;
  align-self: center;
  text-align: right;
  font-size: 19px;
  font-weight: 620;
  font-variant-numeric: tabular-nums;
}

.entry .big small {
  display: block;
  font-size: 11px;
  color: var(--muted);
  font-weight: 500;
}

.entry .del {
  grid-column: 2;
  justify-self: end;
  background: none;
  border: 0;
  color: #5b645e;
  font-size: 12px;
  cursor: pointer;
  padding: 0;
}

.entry .del:hover {
  color: var(--danger);
}

.empty {
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  padding: 34px 10px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}

.stats .metric .v {
  font-size: 21px;
}

/* ---------- réglages ---------- */
.field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.field:last-child {
  border-bottom: 0;
}

.field .lbl {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.field .lbl b {
  font-weight: 550;
  font-size: 14.5px;
}

.field .lbl span {
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.35;
}

.field input[type="number"],
.field input[type="text"],
.field select {
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  padding: 8px 10px;
  border-radius: 10px;
  width: 110px;
  text-align: right;
}

.field select {
  width: 150px;
}

input[type="checkbox"] {
  width: 22px;
  height: 22px;
  accent-color: var(--accent);
  flex: none;
}

.section-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 700;
  margin: 22px 4px 8px;
}

/* ---------- journal ---------- */
.log {
  background: #070908;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  height: 46vh;
  overflow: auto;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 11.5px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-all;
  color: #9fb3a4;
}

.log .out {
  color: #8fd2ff;
}

.log .err {
  color: #ff9a9d;
}

/* ---------- onglets ---------- */
.tabs {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: center;
  gap: 4px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: rgba(10, 12, 11, 0.82);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  z-index: 30;
}

.tabs button {
  flex: 1;
  max-width: 110px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 11.5px;
  font-weight: 600;
  padding: 7px 4px;
  border-radius: 11px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}

.tabs button svg {
  width: 21px;
  height: 21px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tabs button.active {
  color: var(--accent);
  background: rgba(194, 240, 74, 0.07);
}

/* ---------- compte à rebours ---------- */
.countdown {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(8, 10, 9, 0.9);
  backdrop-filter: blur(6px);
  display: grid;
  place-items: center;
  cursor: pointer;
}

.countdown[hidden] {
  display: none;
}

.countdown .num {
  font-size: 140px;
  font-weight: 650;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  animation: pop 0.45s ease;
}

@keyframes pop {
  from {
    transform: scale(0.7);
    opacity: 0.3;
  }
}

/* ---------- toast ---------- */
#toast {
  position: fixed;
  left: 50%;
  bottom: calc(92px + env(safe-area-inset-bottom));
  transform: translate(-50%, 14px);
  background: #242a26;
  border: 1px solid var(--line);
  color: var(--text);
  padding: 11px 17px;
  border-radius: 12px;
  font-size: 13.5px;
  max-width: 86vw;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: 0.25s;
  z-index: 200;
}

#toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.hidden {
  display: none !important;
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}
