:root {
  color-scheme: dark;
  font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", "Segoe UI", Arial, sans-serif;
  background: #000;
  color: #fff;
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
}
* { box-sizing: border-box; }
body { margin: 0; overscroll-behavior: none; }
button, input { font: inherit; }
button {
  border: 0;
  color: inherit;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-appearance: none;
  appearance: none;
}
button:focus-visible, summary:focus-visible { outline: 2px solid #ff9f0a; outline-offset: 2px; }
button:disabled { cursor: default; }
button, svg { -webkit-user-select: none; user-select: none; }
body:has(dialog[open]) { overflow: hidden; }

.clock {
  position: relative;
  container-type: inline-size;
  width: min(100%, 480px);
  height: 100vh;
  height: 100dvh;
  margin-inline: auto;
  display: grid;
  grid-template-rows: 50.8% minmax(0, 1fr) auto;
  overflow: hidden;
}
.watch-face {
  position: absolute;
  top: max(calc(env(safe-area-inset-top) + 48px), 23.65%);
  left: 0;
  width: 100%;
  transform: translateY(-50%);
  text-align: center;
}
.time {
  display: block;
  width: 100%;
  padding: 0;
  background: transparent;
  font-size: min(22.5vw, 108px);
  font-size: 22.5cqw;
  font-weight: 200;
  letter-spacing: -.025em;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  white-space: nowrap;
  touch-action: none;
  -webkit-touch-callout: none;
}
#digits { display: inline-block; transform: scaleX(var(--digit-scale, 1)); }
#display { user-select: none; -webkit-user-select: none; }
#settings-trigger { touch-action: none; -webkit-touch-callout: none; }
.mode-picker, #precision-settings { margin: 0; padding: 0; border: 0; min-inline-size: 0; }
.mode-picker { margin-block: 22px; }
.mode-picker legend { margin: 0 0 8px; color: #bcbcc1; font-size: .9rem; }
.mode-options { display: flex; padding: 3px; background: #303033; border-radius: 10px; }
.mode-options label { flex: 1; position: relative; text-align: center; }
.mode-options input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.mode-options span { display: block; padding: 12px 2px; border-radius: 8px; font-size: .95rem; }
.mode-options input:checked + span { background: #545458; font-weight: 600; }
.mode-options input:focus-visible + span { outline: 2px solid #ff9f0a; }
.controls, .lap-list { margin-inline: 3.9%; }
.controls {
  grid-row: 1;
  align-self: end;
  transform: translateY(50%);
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 1;
}
.round {
  width: clamp(58px, 20.9cqw, 100px);
  aspect-ratio: 1;
  border-radius: 50%;
  padding: 0;
  white-space: nowrap;
  font-size: clamp(.93rem, 4.1cqw, 1.15rem);
  font-weight: 400;
}
.secondary { background: #333; color: #fff; }
.secondary:disabled { background: #1c1c1e; color: #98989f; opacity: 1; }
.start { color: #48d460; background: #0b2a13; }
.stop { color: #ff453a; background: #34100e; }
.round:active { filter: brightness(1.25); }
.page-dots { display: flex; align-items: center; gap: 2.4cqw; }
.page-dots i { width: 1.94cqw; aspect-ratio: 1; border-radius: 50%; background: #737373; }
.page-dots i:first-child { background: #939393; }
.page-dots i:first-child.armed { background: #fff; }
.lap-list {
  grid-row: 2;
  margin-top: calc(clamp(29px, 10.45cqw, 50px) + 3.9cqw);
  min-height: 0;
  overflow: auto;
  border-top: 1px solid #202022;
  scrollbar-width: none;
}
.lap-row {
  min-height: 49px;
  border-bottom: 1px solid #262628;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 1.05rem;
  font-variant-numeric: tabular-nums;
}
.lap-row.best { color: #30d158; }
.lap-row.worst { color: #ff453a; }
.bottom {
  grid-row: 3;
  margin-inline: 5.2%;
  /* The home-indicator clearance sits outside the painted capsule. */
  margin-bottom: min(5.2cqw, env(safe-area-inset-bottom, 0px));
  display: grid;
  grid-template-columns: 1fr 1fr 1.64fr 1fr;
  align-items: stretch;
  padding: clamp(3px, 1cqw, 5px) 4.3%;
  border-radius: 999px;
  background: linear-gradient(#222, #1f1f1f);
  box-shadow: inset 0 1px 1px #ffffff26, inset 0 -1px 1px #ffffff16;
}
.nav-item {
  position: relative;
  isolation: isolate;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  min-width: 0;
  min-height: clamp(47px, 13.4cqw, 63px);
  padding: 0;
  gap: 2px;
  border: 0;
  background: none;
  color: #fafafa;
  white-space: nowrap;
  font-size: clamp(.65rem, 2.75cqw, .78rem);
  font-weight: 550;
  line-height: 1.2;
}
.nav-item svg {
  width: clamp(22px, 6.2cqw, 30px);
  aspect-ratio: 1;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.85;
  stroke-linejoin: round;
  stroke-linecap: round;
}
.nav-item.selected { color: #ff9f32; touch-action: none; -webkit-touch-callout: none; }
.nav-item.selected::before {
  content: "";
  position: absolute;
  z-index: -1;
  inset: 0 -11%;
  border-radius: 999px;
  background: #090909;
}
.decorative { cursor: default; }
@media (max-height: 440px) {
  .clock { grid-template-rows: 49% minmax(0, 1fr) auto; }
  .watch-face { top: max(calc(env(safe-area-inset-top) + 28px), 21%); }
  .time { font-size: min(19cqw, 17dvh); }
  .round { width: 54px; }
  .lap-list { margin-top: 34px; }
  .nav-item { min-height: 42px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
dialog{background:#1c1c1e;color:#fff;padding:0;border:0;border-radius:20px 20px 0 0;margin:auto auto 0;max-height:94dvh;width:min(100%,480px);max-width:100%;box-shadow:0 -15px 80px #0008}
dialog::backdrop{background:#0009;backdrop-filter:blur(4px)}
.sheet-head{position:sticky;top:0;background:#1c1c1ef5;z-index:1;display:flex;align-items:center;justify-content:space-between;padding:20px 16px;border-bottom:1px solid #343436}
.sheet-head button{background:none;color:#ff9f0a;font-size:1rem;padding:4px 0}
.sheet-head h2{font-size:1.05rem;margin:0}
.sheet-body{padding:0 20px calc(28px + env(safe-area-inset-bottom))}
.intro,.help{color:#aaaab0;font-size:.88rem;line-height:1.7}
.intro{margin:20px 2px}
.setting-group{background:#2c2c2e;border-radius:12px;overflow:hidden}
.toggle-row{position:relative;display:flex;align-items:center;justify-content:space-between;min-height:58px;padding:12px 14px;gap:8px}
.toggle-row+.toggle-row{border-top:1px solid #444447}
.toggle-row input{position:absolute;right:14px;width:48px;height:29px;opacity:0;z-index:1;cursor:pointer}
.switch{width:48px;height:29px;border-radius:30px;background:#626267;flex-shrink:0;transition:background .15s}
.switch:after{content:"";display:block;margin:2px;width:25px;height:25px;border-radius:50%;background:#fff;transition:transform .15s}
.toggle-row input:checked+.switch{background:#30d158}
.toggle-row input:checked+.switch:after{transform:translateX(19px)}
.toggle-row input:focus-visible+.switch{outline:2px solid #ff9f0a;outline-offset:3px}
h3{font-weight:400;font-size:.85rem;color:#aaaab0;margin:24px 12px 8px}
.target-inputs label{display:flex;align-items:center;gap:10px;padding:12px 14px;min-height:57px}
.target-inputs label+label{border-top:1px solid #444447}
.target-inputs label>span:first-child{flex:1}
.unit{color:#a4a4aa;width:42px;font-size:.9rem}
input[type=number]{min-width:0;width:85px;border:1px solid #4b4b50;border-radius:7px;background:#1c1c1e;color:#fff;text-align:right;padding:8px;font-variant-numeric:tabular-nums;font-size:1.08rem;appearance:textfield}
input::-webkit-inner-spin-button{appearance:none}
.tolerance-row{padding:12px 14px;display:flex;align-items:center;justify-content:space-between;gap:10px}
.tolerance-row>span{white-space:nowrap;color:#bdbdc3}
.tolerance-row input{width:76px}
.presets{display:flex;gap:8px;margin-top:12px}
.presets button{flex:1;background:#343436;color:#e7e7eb;padding:10px 3px;border-radius:8px;font-size:.86rem}
.presets button:active{background:#555}
.range{font-size:1.1rem;line-height:1.6;text-align:center;margin:22px 0 5px;font-variant-numeric:tabular-nums;color:#ffb340}
.help{margin:5px 0 18px}
#form-error{color:#ff6961;line-height:1.6}
.instructions{color:#aaaab0;font-size:.88rem;line-height:1.75}
details{border-top:1px solid #38383a;padding-top:17px}
summary{color:#c2c2c7;cursor:pointer;font-size:.9rem}
