:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #14171c;
  --muted: #69717d;
  --grid: #e3e6ea;
  --accent: #e8590c;
  --ok: #2b8a3e;
  --error: #c92a2a;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101216;
    --surface: #191c22;
    --text: #eceef1;
    --muted: #8d95a1;
    --grid: #2a2e36;
    --accent: #ff8a3d;
    --ok: #51cf66;
    --error: #ff6b6b;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 system-ui, sans-serif;
}

main {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 960px;
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
    max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

header,
footer,
.actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

header {
  justify-content: space-between;
}

h1 {
  margin: 0;
  font-size: 20px;
}

.meta {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

#status[data-kind='ok'] {
  color: var(--ok);
}

#status[data-kind='error'] {
  color: var(--error);
}

.notice {
  margin: 0;
  padding: 10px 12px;
  border: 1px solid var(--error);
  border-radius: 8px;
  font-size: 13px;
}

.stats {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr;
  gap: 8px;
}

.stat {
  display: flex;
  flex-direction: column;
  padding: 12px 16px;
  border-radius: 12px;
  background: var(--surface);
}

.label {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.value {
  font-size: 28px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.stat.primary .value {
  font-size: 48px;
  color: var(--accent);
}

.value .unit {
  font-size: 0.5em;
  font-weight: 400;
  color: var(--muted);
}

.view {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 16px;
  min-height: 0;
}

nav {
  display: flex;
  gap: 4px;
  padding: 4px;
  border-radius: 10px;
  background: var(--surface);
}

nav button {
  flex: 1;
  padding: 8px 16px;
  background: transparent;
  color: var(--muted);
}

nav button[aria-selected='true'] {
  background: var(--bg);
  color: var(--text);
}

.timer-display {
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 200px;
  border-radius: 12px;
  background: var(--surface);
}

.timer-display .label {
  font-size: 24px;
}

#timer-count {
  font-size: min(40vh, 45vw);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.timer-reps {
  font-size: 28px;
  font-weight: 600;
}

.timer-force {
  margin-top: 8px;
  font-size: 20px;
  font-variant-numeric: tabular-nums;
}

[data-phase='work'] .timer-display {
  background: var(--accent);
  color: #fff;
}

[data-phase='rest'] .timer-display {
  background: var(--ok);
  color: #fff;
}

[data-phase='work'] .label,
[data-phase='rest'] .label {
  color: inherit;
}

label {
  color: var(--muted);
  white-space: nowrap;
}

input {
  width: 4.5em;
  padding: 10px 8px;
  border: 1px solid var(--grid);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 16px;
  text-align: center;
}

canvas {
  flex: 1;
  width: 100%;
  min-height: 200px;
  border-radius: 12px;
  background: var(--surface);
}

button,
select {
  padding: 10px 16px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}

button.ghost,
select {
  border-color: var(--grid);
  background: var(--surface);
  color: var(--text);
}

button.danger {
  background: var(--error);
}

button.wide {
  flex: 1;
}

button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

[hidden] {
  display: none !important;
}

@media (max-width: 520px) {
  .stats {
    grid-template-columns: 1fr 1fr;
  }

  .stat.primary {
    grid-column: 1 / -1;
  }

  footer {
    flex-wrap: wrap;
  }

  button.wide {
    flex-basis: 100%;
  }
}
