:root {
  --bg: #0e0e11;
  --bg-soft: #17171c;
  --bg-input: #202027;
  --line: #2c2c35;
  --text: #f2f2f5;
  --muted: #8b8b96;
  --pause: #8b8b96;
  --work: #ff3b30;
  --accent: #4c8dff;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

/* ---------- top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px 6px;
}

.topbar h1 {
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0;
}

.icon-btn {
  background: none;
  border: 0;
  color: var(--muted);
  padding: 8px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  cursor: pointer;
}

.icon-btn:active { background: var(--bg-soft); }
.icon-btn[aria-expanded="true"] { color: var(--text); }

/* ---------- stage ---------- */

.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 8px 20px;
  gap: 6px;
  min-height: 0;
}

.progress {
  font-size: 0.85rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  min-height: 1.2em;
}

.phase-label {
  font-size: 0.95rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--muted);
  transition: color 0.2s ease;
}

.exercise {
  font-size: clamp(1.8rem, 9vw, 3.2rem);
  font-weight: 700;
  line-height: 1.15;
  color: var(--pause);
  transition: color 0.2s ease;
  overflow-wrap: anywhere;
  max-width: 100%;
}

.clock {
  font-size: clamp(3.4rem, 22vw, 7rem);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  letter-spacing: -0.02em;
  color: var(--pause);
  transition: color 0.2s ease;
}

.next {
  font-size: 0.9rem;
  color: var(--muted);
  min-height: 1.3em;
}

/* phase colours: grey while pausing, red while training */

body.phase-work .exercise,
body.phase-work .clock,
body.phase-work .phase-label {
  color: var(--work);
}

body.phase-done .exercise,
body.phase-done .clock,
body.phase-done .phase-label {
  color: var(--accent);
}

body.phase-paused .clock { opacity: 0.45; }

/* ---------- controls ---------- */

.controls {
  display: flex;
  gap: 12px;
  padding: 10px 18px 18px;
}

.btn {
  flex: 1;
  appearance: none;
  border: 1px solid var(--line);
  background: var(--bg-soft);
  color: var(--text);
  font-size: 1.05rem;
  font-weight: 600;
  padding: 16px 18px;
  border-radius: var(--radius);
  cursor: pointer;
  touch-action: manipulation;
}

.btn:active { transform: scale(0.985); }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn-primary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ---------- settings ---------- */

.settings {
  background: var(--bg-soft);
  border-top: 1px solid var(--line);
  padding: 18px;
  max-height: 62dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.field-row {
  display: flex;
  gap: 10px;
}

.field {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.field span {
  font-size: 0.75rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
}

input[type="number"],
input[type="text"] {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  font-size: 1.05rem;
  padding: 12px;
  font-family: inherit;
}

input:focus {
  outline: none;
  border-color: var(--accent);
}

.section-title {
  font-size: 0.75rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 22px 0 8px;
}

.exercise-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.exercise-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-input);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 10px 10px 14px;
}

.exercise-list .idx {
  color: var(--muted);
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
  min-width: 1.4em;
}

.exercise-list .name {
  flex: 1;
  overflow-wrap: anywhere;
}

.remove-btn {
  background: none;
  border: 0;
  color: var(--muted);
  font-size: 1.3rem;
  line-height: 1;
  padding: 6px 10px;
  border-radius: 8px;
  cursor: pointer;
}

.remove-btn:active { background: #2c2c35; color: var(--work); }

.empty-hint {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 4px 0 12px;
}

.add-row {
  display: flex;
  gap: 10px;
  margin-top: 12px;
}

.add-row input { flex: 1; }

.btn-add {
  flex: 0 0 auto;
  width: 56px;
  font-size: 1.6rem;
  line-height: 1;
  padding: 8px;
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.hint {
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.5;
  margin: 16px 0 0;
}

/* ---------- footer ---------- */

.footer {
  padding: 0 18px 10px;
  font-size: 0.75rem;
  color: var(--muted);
  text-align: center;
  min-height: 1em;
}

.footer .btn {
  flex: none;
  width: auto;
  display: inline-block;
  padding: 10px 18px;
  font-size: 0.85rem;
}

/* keep the clock readable on short landscape screens */
@media (max-height: 520px) {
  .clock { font-size: clamp(2.4rem, 14vh, 4rem); }
  .exercise { font-size: clamp(1.3rem, 5vh, 2rem); }
  .stage { gap: 2px; }
}
