:root {
  --bg: #f4f1fb;
  --card: #ffffff;
  --text: #3b3552;
  --muted: #7a7494;
  --accent: #8e7cf0;
  --accent-soft: #e6e1fb;
  --go: #6cc9a0;
  --pause: #f3c969;
  --stop: #f19aa6;
  --ring: #ffd9de;
  --shadow: 0 8px 30px rgba(90, 70, 160, 0.12);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1d1a2b;
    --card: #272339;
    --text: #ece9f8;
    --muted: #a9a3c4;
    --accent: #a898ff;
    --accent-soft: #373150;
    --ring: #5a2f3a;
    --shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: "Pretendard", "Noto Sans KR", "Malgun Gothic", system-ui, sans-serif;
  line-height: 1.6;
  transition: background 0.2s;
}

.wrap {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px;
}

.site-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  margin: 8px 0 20px;
}

.site-nav a {
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--text);
  text-decoration: none;
  font-size: 14px;
}

.site-nav a[aria-current="page"] {
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}

h1 {
  text-align: center;
  font-size: clamp(22px, 5vw, 30px);
  margin: 0 0 4px;
}

.lead {
  text-align: center;
  color: var(--muted);
  margin: 0 0 20px;
}

.card {
  background: var(--card);
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 24px 16px;
}

.display {
  text-align: center;
  font-weight: 800;
  font-size: clamp(64px, 20vw, 140px);
  line-height: 1.1;
  letter-spacing: 2px;
  font-variant-numeric: tabular-nums;
  margin: 8px 0 20px;
  user-select: none;
}

.display.small {
  font-size: clamp(48px, 15vw, 104px);
}

.presets {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-bottom: 16px;
}

.preset {
  border: 2px solid var(--accent-soft);
  background: transparent;
  color: var(--text);
  border-radius: 14px;
  padding: 10px 18px;
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
}

.preset:hover,
.preset.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.custom {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 20px;
  color: var(--muted);
}

.custom input {
  width: 84px;
  padding: 10px;
  border-radius: 12px;
  border: 2px solid var(--accent-soft);
  background: transparent;
  color: var(--text);
  font-size: 20px;
  font-weight: 700;
  text-align: center;
}

.custom input:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.controls {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

.btn {
  flex: 1 1 120px;
  max-width: 200px;
  border: 0;
  border-radius: 16px;
  padding: 16px 12px;
  font-size: 20px;
  font-weight: 800;
  color: #2f2a44;
  cursor: pointer;
  transition: transform 0.05s, opacity 0.2s;
}

.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.35; cursor: not-allowed; }
.btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.btn-start { background: var(--go); }
.btn-pause { background: var(--pause); }
.btn-reset { background: var(--stop); }
.btn-lap { background: var(--accent-soft); color: var(--text); }

.alarm-off {
  display: none;
  width: 100%;
  margin: 16px 0 0;
  padding: 16px;
  border: 0;
  border-radius: 16px;
  background: #e5546b;
  color: #fff;
  font-size: 22px;
  font-weight: 800;
  cursor: pointer;
}

.ringing .alarm-off { display: block; }

.laps {
  list-style: none;
  padding: 0;
  margin: 16px 0 0;
  max-height: 220px;
  overflow: auto;
  font-variant-numeric: tabular-nums;
}

.laps li {
  display: flex;
  justify-content: space-between;
  padding: 8px 12px;
  border-bottom: 1px solid var(--accent-soft);
}

.status {
  text-align: center;
  color: var(--muted);
  min-height: 1.6em;
  margin: 12px 0 0;
  font-size: 14px;
}

body.ringing .card {
  animation: flash 0.8s steps(1) infinite;
}

@keyframes flash {
  0%   { background: var(--card); }
  50%  { background: var(--ring); }
}

@media (prefers-reduced-motion: reduce) {
  body.ringing .card { animation: none; background: var(--ring); }
}

.info {
  margin-top: 28px;
}

.info h2 {
  font-size: 20px;
  margin: 24px 0 8px;
}

.info h3 {
  font-size: 16px;
  margin: 16px 0 4px;
}

.info p, .info li { color: var(--muted); }

footer {
  margin: 32px 0 16px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

footer a { color: var(--muted); }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.sound-test {
  text-align: center;
  margin: 16px 0 0;
}

.link-btn {
  border: 0;
  background: transparent;
  color: var(--accent);
  font-size: 15px;
  font-weight: 700;
  text-decoration: underline;
  cursor: pointer;
  padding: 6px 10px;
}

h1 small {
  font-size: 0.5em;
  color: var(--muted);
  font-weight: 600;
}

.tool-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
}

.tool-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 20px 16px;
  background: var(--card);
  border-radius: 20px;
  box-shadow: var(--shadow);
  color: var(--text);
  text-decoration: none;
  transition: transform 0.1s;
}

.tool-card:hover { transform: translateY(-2px); }
.tool-card:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.tool-card .tool-ico { font-size: 32px; }
.tool-card strong { font-size: 18px; }
.tool-card span:last-child { color: var(--muted); font-size: 14px; }
