:root {
  --bg: #0f1420;
  --panel: #182033;
  --fg: #e8edf7;
  --muted: #8b98b3;
  --accent: #4ade80;
  --accent-dim: #22c55e;
  --danger: #f87171;
  --ring-bg: #263149;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6fb;
    --panel: #ffffff;
    --fg: #16203a;
    --muted: #6b7893;
    --accent: #16a34a;
    --accent-dim: #15803d;
    --danger: #dc2626;
    --ring-bg: #dfe4ef;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Noto Sans JP", sans-serif;
}

.app {
  width: 100%;
  max-width: 420px;
  background: var(--panel);
  border-radius: 20px;
  padding: 28px 24px 22px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .18);
  text-align: center;
}

.title {
  margin: 0 0 20px;
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: .02em;
}

.mode-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 4px;
  margin: 0 0 22px;
  background: var(--bg);
  border-radius: 12px;
}

.mode-tab {
  padding: 8px 4px;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 9px;
  font: inherit;
  font-size: .8rem;
  cursor: pointer;
}

.mode-tab:hover { color: var(--fg); }
.mode-tab.is-active { color: #06210f; background: var(--accent); font-weight: 600; }
.mode-tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- dial ---- */
.dial {
  position: relative;
  width: 240px;
  max-width: 100%;
  aspect-ratio: 1;
  margin: 0 auto 22px;
}

.ring {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.ring circle {
  fill: none;
  stroke-width: 10;
  stroke-linecap: round;
}

.ring-bg { stroke: var(--ring-bg); }

.ring-fg {
  stroke: var(--accent);
  stroke-dasharray: 578.05;
  stroke-dashoffset: 0;
  transition: stroke-dashoffset .2s linear, stroke .3s ease;
}

.readout {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.display {
  font-size: 2.6rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: .02em;
}

.display.is-long { font-size: 2rem; }

.status {
  font-size: .8rem;
  color: var(--muted);
}

body.finished .ring-fg { stroke: var(--danger); }
body.finished .display { color: var(--danger); animation: blink 1s steps(2, start) infinite; }

@keyframes blink { to { opacity: .3; } }

@media (prefers-reduced-motion: reduce) {
  .ring-fg { transition: none; }
  body.finished .display { animation: none; }
}

/* ---- inputs ---- */
.inputs {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-bottom: 16px;
}

.inputs label {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font-size: .75rem;
  color: var(--muted);
}

.inputs input {
  width: 72px;
  padding: 8px;
  font-size: 1.05rem;
  text-align: center;
  font-variant-numeric: tabular-nums;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--ring-bg);
  border-radius: 10px;
}

.inputs input:focus-visible,
.btn:focus-visible,
.preset:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.inputs input:disabled { opacity: .5; }

/* ---- buttons ---- */
.presets {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-bottom: 18px;
}

.preset {
  padding: 6px 14px;
  font-size: .85rem;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--ring-bg);
  border-radius: 999px;
  cursor: pointer;
}

.preset:hover { border-color: var(--accent); }

.controls {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
}

.btn {
  flex: 1;
  padding: 13px;
  font-size: 1rem;
  font-weight: 600;
  font-family: inherit;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--ring-bg);
  border-radius: 12px;
  cursor: pointer;
}

.btn:hover { border-color: var(--accent); }

.btn-primary {
  color: #06210f;
  background: var(--accent);
  border-color: var(--accent);
}

.btn-primary:hover { background: var(--accent-dim); border-color: var(--accent-dim); }

.hint {
  margin: 0;
  font-size: .72rem;
  color: var(--muted);
}

/* ---- stopwatch / clock ---- */
.stopwatch-readout,
.clock-readout {
  display: flex;
  min-height: 238px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 22px;
  background: var(--bg);
  border: 10px solid var(--ring-bg);
  border-radius: 50%;
}

.stopwatch-display,
.clock-display {
  font-size: 2.45rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: .02em;
}

.clock-date { color: var(--muted); font-size: .85rem; }

.laps {
  max-height: 132px;
  margin: -4px 0 16px;
  padding: 0;
  overflow: auto;
  list-style: none;
  text-align: left;
}

.laps:empty { display: none; }

.laps li {
  display: flex;
  justify-content: space-between;
  padding: 7px 4px;
  border-bottom: 1px solid var(--ring-bg);
  color: var(--muted);
  font-size: .85rem;
  font-variant-numeric: tabular-nums;
}

.laps time { color: var(--fg); }
