:root {
  --bg: #16161a;
  --surface: #1e1e24;
  --line: #2e2e37;
  --text: #f2f2f5;
  --muted: #9b9ba6;
  --accent: #e0524b;
  --accent-soft: rgba(224, 82, 75, 0.14);
  --radius: 14px;
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

body[data-mode="short"] {
  --accent: #3f9a6d;
  --accent-soft: rgba(63, 154, 109, 0.14);
}

body[data-mode="long"] {
  --accent: #4a7fc1;
  --accent-soft: rgba(74, 127, 193, 0.14);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f5f3;
    --surface: #ffffff;
    --line: #e3e1dd;
    --text: #1b1b1f;
    --muted: #6d6d78;
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 16px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: grid;
  place-items: center;
  padding: 24px 16px;
  transition: background-color 0.4s var(--ease);
  -webkit-font-smoothing: antialiased;
}

.app {
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.icon-btn {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: color 0.2s var(--ease), background-color 0.2s var(--ease);
}

.icon-btn:hover { color: var(--text); background: var(--surface); }
.icon-btn[aria-expanded="true"] { color: var(--accent); background: var(--accent-soft); }
.icon-btn svg { width: 19px; height: 19px; fill: currentColor; }

.modes {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.mode {
  flex: 1;
  padding: 9px 4px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  transition: color 0.2s var(--ease), background-color 0.2s var(--ease);
}

.mode:hover { color: var(--text); }

.mode[aria-selected="true"] {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.dial {
  position: relative;
  display: grid;
  place-items: center;
  margin: 4px 0;
}

.ring {
  width: min(300px, 78vw);
  height: min(300px, 78vw);
  transform: rotate(-90deg);
  overflow: visible;
}

.ring circle {
  fill: none;
  stroke-width: 8;
  stroke-linecap: round;
}

.ring-track { stroke: var(--line); }

.ring-fill {
  stroke: var(--accent);
  stroke-dasharray: 678.58;
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 0.35s linear, stroke 0.4s var(--ease);
}

.readout {
  position: absolute;
  text-align: center;
}

.time {
  display: block;
  font-size: clamp(52px, 16vw, 68px);
  font-weight: 300;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.phase {
  margin: 6px 0 0;
  font-size: 14px;
  color: var(--muted);
}

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

.btn {
  min-width: 92px;
  padding: 12px 20px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: transform 0.12s var(--ease), border-color 0.2s var(--ease), opacity 0.2s var(--ease);
}

.btn:hover { border-color: var(--muted); }
.btn:active { transform: translateY(1px); }

.btn-primary {
  min-width: 132px;
  border-color: transparent;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.btn-primary:hover { border-color: transparent; opacity: 0.9; }

.btn-quiet {
  min-width: 0;
  padding: 7px 13px;
  font-size: 13px;
  color: var(--muted);
}

.tally {
  margin: 0;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
}

.settings {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.settings h2 {
  margin: 0 0 14px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.grid label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

.lbl {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.unit { opacity: 0.7; }

.grid input {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}

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

.toggles {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 16px;
}

.check {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 14px;
  cursor: pointer;
}

.check input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.alert-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

.alert-controls {
  display: flex;
  gap: 8px;
}

.alert-controls select {
  flex: 1;
  min-width: 0;
}

.alert-controls .btn {
  flex: none;
}

.alert-field select {
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 13.5px;
  cursor: pointer;
}

.alert-field select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.settings-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.hint {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
  text-align: right;
}

.foot {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
}

.foot p { margin: 0; }

kbd {
  padding: 1px 5px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--surface);
  font: inherit;
  font-size: 11px;
}

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

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 0.01ms !important; }
}

[hidden] { display: none !important; }
