:root {
  --bg: #0b0d10;
  --bg-2: #14181d;
  --card: #1a1f26;
  --line: #262d36;
  --text: #f4f6f9;
  --muted: #8a96a6;
  --accent: #ff5f1f;        /* high-vis safety orange */
  --accent-2: #ffb347;
  --good: #21d07a;
  --bad: #ef4444;
  --warn: #fbbf24;
  --rest: #38bdf8;
  --shadow: 0 8px 30px rgba(0,0,0,0.5);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; background: var(--bg); color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "SF Pro", "Inter", "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none; -webkit-tap-highlight-color: transparent;
  user-select: none;
}
body { padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 18px; background: linear-gradient(180deg, rgba(11,13,16,0.95), rgba(11,13,16,0.7));
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: 0.4px; }
.brand .logo { font-size: 22px; }
.brand .name { font-size: 16px; }
.topactions { display: flex; gap: 8px; }
.iconbtn {
  background: transparent; color: var(--text); border: 1px solid var(--line);
  width: 38px; height: 38px; border-radius: 10px; font-size: 16px; cursor: pointer;
}
.iconbtn:active { transform: scale(0.96); }

main { padding: 18px; max-width: 720px; margin: 0 auto; }

.view { display: none; animation: fade .25s ease; }
.view.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.hero { font-size: 28px; margin: 6px 0 18px; font-weight: 800; letter-spacing: -0.5px; }
.hero::after { content: ""; display: block; width: 42px; height: 4px; background: var(--accent); border-radius: 4px; margin-top: 8px; }

.presets {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
}
.preset {
  background: var(--card); color: var(--text); border: 1px solid var(--line);
  border-radius: 16px; padding: 18px 16px; text-align: left; cursor: pointer;
  transition: border-color .15s, transform .1s;
}
.preset:hover { border-color: var(--accent); }
.preset:active { transform: scale(0.98); }
.preset-name { font-size: 22px; font-weight: 800; letter-spacing: 0.5px; }
.preset-sub { font-size: 13px; color: var(--muted); margin-top: 4px; }

.saved-wrap { margin-top: 28px; }
.saved-wrap h2 { font-size: 14px; text-transform: uppercase; letter-spacing: 1.5px; color: var(--muted); margin: 0 0 10px; }
.saved-list { display: grid; gap: 8px; }
.saved-item {
  display: flex; align-items: center; gap: 10px;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px;
}
.saved-item .si-name { flex: 1; font-weight: 600; }
.saved-item .si-meta { color: var(--muted); font-size: 12px; }
.saved-item button { background: transparent; color: var(--muted); border: none; cursor: pointer; padding: 6px; }
.saved-item button:hover { color: var(--accent); }
.saved-empty { color: var(--muted); font-size: 14px; padding: 14px; border: 1px dashed var(--line); border-radius: 12px; text-align: center; }

.back {
  background: transparent; color: var(--muted); border: none; padding: 6px 0; margin-bottom: 6px;
  font-size: 14px; cursor: pointer;
}
.back:hover { color: var(--text); }

.setup-form {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px;
}
.field { display: none; flex-direction: column; gap: 6px; background: var(--card); padding: 12px; border-radius: 12px; border: 1px solid var(--line); }
.field.show { display: flex; }
.field.full { grid-column: 1 / -1; }
.field span { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }
.field input {
  background: transparent; border: none; outline: none; color: var(--text);
  font-size: 22px; font-weight: 700; padding: 4px 0;
  border-bottom: 2px solid transparent;
}
.field input[type="text"] { font-size: 16px; font-weight: 500; }
.field input:focus { border-bottom-color: var(--accent); }

.setup-actions { display: flex; gap: 10px; margin-top: 18px; }
.primary, .ghost {
  flex: 1; padding: 14px 16px; border-radius: 12px; font-size: 16px; font-weight: 700; cursor: pointer;
  border: 1px solid transparent;
}
.primary { background: var(--accent); color: #1a1004; }
.primary:active { transform: scale(0.98); }
.ghost { background: transparent; color: var(--text); border-color: var(--line); }
.ghost:hover { border-color: var(--muted); }
.block { width: 100%; }

/* Run view */
.run-view {
  min-height: calc(100vh - 88px);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding-top: 0;
}
.run-meta { display: flex; gap: 16px; align-items: baseline; color: var(--muted); margin-top: 4px; }
.mode-label { font-weight: 800; letter-spacing: 2px; font-size: 14px; color: var(--accent); }
.round-label { font-size: 14px; }
.phase {
  font-size: 22px; letter-spacing: 4px; font-weight: 800;
  color: var(--good); margin: 18px 0 6px; transition: color .2s;
}
.phase.rest { color: var(--rest); }
.phase.prep { color: var(--warn); }
.phase.done { color: var(--accent); }
.bigtime {
  font-variant-numeric: tabular-nums;
  font-size: clamp(96px, 22vw, 200px);
  font-weight: 900; line-height: 1; letter-spacing: -4px;
  text-shadow: 0 0 30px rgba(255,95,31,0.18);
}
.bigtime.warn { color: var(--warn); animation: pulse 0.6s ease infinite alternate; }
.bigtime.go { color: var(--good); }
@keyframes pulse { from { transform: scale(1); } to { transform: scale(1.04); } }

.ring { position: relative; width: 240px; height: 240px; margin: 18px 0 8px; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: var(--line); stroke-width: 8; }
.ring-fg { fill: none; stroke: var(--accent); stroke-width: 10; stroke-linecap: round;
  stroke-dasharray: 578; stroke-dashoffset: 0; transition: stroke-dashoffset .25s linear, stroke .2s; }
.ring-fg.rest { stroke: var(--rest); }
.ring-fg.prep { stroke: var(--warn); }

.run-controls { display: flex; gap: 10px; width: 100%; max-width: 420px; margin-top: 12px; }

.lap-list { width: 100%; max-width: 420px; margin-top: 14px; max-height: 30vh; overflow: auto;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; }
.lap-list .lap { display: flex; justify-content: space-between; padding: 10px 14px; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; font-size: 14px; }
.lap-list .lap:last-child { border-bottom: none; }
.lap-list .lap .idx { color: var(--muted); }

.hidden { display: none !important; }

.done-title { font-size: 36px; margin: 12px 0; }
.done-stats { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 18px; }
.done-stats .ds-row { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px dashed var(--line); }
.done-stats .ds-row:last-child { border-bottom: none; }
.done-stats .ds-label { color: var(--muted); }
.done-stats .ds-val { font-weight: 700; }

/* Settings sheet */
.sheet { position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: flex; align-items: flex-end; justify-content: center; z-index: 50; }
.sheet-card { width: 100%; max-width: 520px; background: var(--bg-2); border: 1px solid var(--line); border-radius: 18px 18px 0 0; padding: 20px; box-shadow: var(--shadow); }
.sheet-card h2 { margin: 0 0 12px; }
.row { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--line); }
.row:last-of-type { border-bottom: none; }
.row span { font-size: 15px; }
.row input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--accent); }
.row input[type="range"] { width: 50%; accent-color: var(--accent); }

@media (min-width: 720px) {
  .presets { grid-template-columns: 1fr 1fr 1fr; }
}
