:root {
  --bg: #0f1118;
  --bg-2: #171a24;
  --card: #1c2030;
  --line: #2a2f43;
  --text: #f2efe8;
  --muted: #8a8fa6;
  --accent: #ffb547;
  --accent-2: #ff7a59;
  --good: #4ade80;
  --bad: #f87171;
  --mono: "JetBrains Mono", ui-monospace, Menlo, monospace;
  --sans: "Space Grotesk", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(1200px 600px at 50% -10%, #23283a 0%, transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}

#confetti {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 10;
}

.app {
  max-width: 480px;
  margin: 0 auto;
  padding: 24px 16px 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

/* Brand */
.brand { display: flex; align-items: center; gap: 10px; width: 100%; }
.logo { width: 28px; height: 28px; color: var(--accent); }
.logo svg { width: 100%; height: 100%; }
.brand h1 { margin: 0; font-size: 22px; font-weight: 700; letter-spacing: -0.02em; }
.tagline { margin-left: auto; color: var(--muted); font-size: 13px; }

/* Dial */
.dial-wrap {
  position: relative;
  width: min(84vw, 340px);
  aspect-ratio: 1;
}
.dial { width: 100%; height: 100%; transform: rotate(-90deg); overflow: visible; }

.ticks line { stroke: var(--line); stroke-width: 2; stroke-linecap: round; }
.ticks line.major { stroke: var(--muted); stroke-width: 3; }

.track { fill: none; stroke: var(--bg-2); stroke-width: 10; }
.ghost-track { stroke-width: 6; }

.sweep {
  fill: none;
  stroke: var(--accent);
  stroke-width: 10;
  stroke-linecap: round;
  filter: drop-shadow(0 0 6px rgba(255, 181, 71, 0.45));
}
.ghost {
  fill: none;
  stroke: var(--muted);
  stroke-width: 6;
  stroke-linecap: round;
  transition: stroke 0.3s;
}
.ghost.ahead { stroke: var(--good); }
.ghost.behind { stroke: var(--bad); }

.bird {
  fill: var(--text);
  filter: drop-shadow(0 0 6px rgba(255, 255, 255, 0.6));
}

.readout {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.time {
  font-family: var(--mono);
  font-weight: 600;
  font-size: clamp(40px, 13vw, 58px);
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}
.time .cs { color: var(--muted); font-size: 0.55em; }
.time.hours { font-size: clamp(32px, 10vw, 46px); }

.lap-now { font-family: var(--mono); color: var(--muted); font-size: 14px; }
.ghost-label { font-family: var(--mono); font-size: 13px; min-height: 1.2em; }
.ghost-label.ahead { color: var(--good); }
.ghost-label.behind { color: var(--bad); }

.quip {
  margin: 0;
  min-height: 1.4em;
  color: var(--muted);
  font-size: 15px;
  text-align: center;
  transition: opacity 0.25s;
}
.quip.flash { animation: pop 0.4s ease; color: var(--text); }
@keyframes pop {
  0% { transform: translateY(4px); opacity: 0; }
  100% { transform: none; opacity: 1; }
}

/* Controls */
.controls {
  display: grid;
  grid-template-columns: 1fr 1.2fr 1fr;
  gap: 12px;
  width: 100%;
  align-items: center;
}
.btn {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 14px 10px;
  font: 600 15px var(--sans);
  color: var(--text);
  background: var(--card);
  cursor: pointer;
  transition: transform 0.08s, background 0.2s, opacity 0.2s;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}
.btn:active:not(:disabled) { transform: scale(0.96); }
.btn:disabled { opacity: 0.35; cursor: default; }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

.btn.primary {
  padding: 20px 10px;
  font-size: 18px;
  border: none;
  color: #1a1206;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 8px 24px rgba(255, 140, 70, 0.3);
}
.btn.primary.running {
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--accent);
  box-shadow: none;
}

.btn .label { position: relative; z-index: 1; }
.hold-fill {
  position: absolute;
  inset: 0;
  background: var(--bad);
  transform: scaleX(0);
  transform-origin: left;
  opacity: 0.55;
}
.hold-fill.filling { transform: scaleX(1); transition: transform 0.7s linear; }

/* Laps */
.laps-panel {
  width: 100%;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px 16px 6px;
}
.laps-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 6px; }
.laps-head h2 { margin: 0; font-size: 15px; font-weight: 600; }
.stats { color: var(--muted); font-size: 12px; font-family: var(--mono); }
.link-btn {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--accent);
  font: 500 13px var(--sans);
  cursor: pointer;
  padding: 4px;
}

.laps { list-style: none; margin: 0; padding: 0; max-height: 300px; overflow-y: auto; }
.laps li {
  display: grid;
  grid-template-columns: 44px 1fr auto auto;
  gap: 10px;
  align-items: center;
  padding: 10px 0;
  border-top: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}
.laps li:first-child { border-top: none; animation: slide 0.3s ease; }
@keyframes slide {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: none; }
}
.laps .num { color: var(--muted); }
.laps .split { font-weight: 600; }
.laps .split .badge { font-family: var(--sans); font-size: 11px; font-weight: 600; margin-left: 8px; padding: 2px 7px; border-radius: 999px; }
.laps .badge.best { background: rgba(74, 222, 128, 0.15); color: var(--good); }
.laps .badge.worst { background: rgba(248, 113, 113, 0.15); color: var(--bad); }
.laps .delta { font-size: 12px; text-align: right; min-width: 64px; }
.laps .delta.faster { color: var(--good); }
.laps .delta.slower { color: var(--bad); }
.laps .total { color: var(--muted); font-size: 12px; }

.keys {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 14px;
  color: var(--muted);
  font-size: 12px;
}
kbd {
  font-family: var(--mono);
  font-size: 11px;
  padding: 2px 6px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--bg-2);
  color: var(--text);
}

@media (hover: none) { .keys { display: none; } }

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