/* Same palette as the other tools. The page tints to the phase colour so it reads from across the room. */
:root {
  --bg: #0e1013;
  --panel: #171a20;
  --panel-2: #1f232b;
  --line: #2b313b;
  --text: #f3f5f8;
  --muted: #9aa4b2;
  --ok: #5fd08a;
  --warn: #ffb454;
  --phase: #ffb454;
  color-scheme: dark;
}
body[data-phase="prep"] { --phase: #ffb454; }
body[data-phase="round"] { --phase: #ff5d52; }
body[data-phase="rest"] { --phase: #4cc3ff; }
body[data-phase="done"] { --phase: #5fd08a; }
body[data-view="setup"] { --phase: #ff5d52; }

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
}
body { background: color-mix(in srgb, var(--phase) 13%, var(--bg)); transition: background-color 0.3s; }
body[data-view="setup"] { background: var(--bg); }

/* Exactly one screen tall: header, stage and controls share it and nothing scrolls. */
#app {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
}

/* ---------- header ---------- */
.top {
  flex: none;
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--line);
}
.app { flex: 1 1 auto; margin: 0; font-size: 1.15rem; font-weight: 700; }
.tool {
  flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  width: 2.75rem; height: 2.75rem; padding: 0;
  background: var(--panel); color: var(--text); text-decoration: none;
  border: 1px solid var(--line); border-radius: 0.6rem; cursor: pointer;
}
.tool svg { width: 1.2rem; height: 1.2rem; fill: currentColor; }
.tool[aria-pressed="true"] { color: var(--muted); }
.tool[aria-pressed="true"] .waves { display: none; }
.tool:focus-visible, button:focus-visible, input:focus-visible { outline: 2px solid var(--phase); outline-offset: 2px; }

/* Screen-awake status while running: green when the screen will stay on. */
.dot { flex: none; width: 0.7rem; height: 0.7rem; border-radius: 50%; background: var(--warn); }
.dot.ok { background: var(--ok); }
.dot[hidden] { display: none; }

/* ---------- stage ---------- */
.stage { flex: 1 1 0; min-height: 0; display: flex; flex-direction: column; padding: 1rem; overflow: hidden; }
.setup, .run { flex: 1 1 0; min-height: 0; width: 100%; max-width: 34rem; margin: 0 auto; }
body[data-view="setup"] .run, body[data-view="run"] .setup { display: none; }

.setup { display: flex; flex-direction: column; justify-content: center; gap: 0.7rem; }
.setting {
  display: grid; grid-template-columns: minmax(0, 1fr) auto auto auto; align-items: center; gap: 0.6rem;
  min-height: 4rem; padding: 0.5rem 0.8rem;
  background: var(--panel); border: 1px solid var(--line); border-radius: 0.9rem;
}
.setting .name { font-size: 1.1rem; font-weight: 600; }
.setting .value {
  min-width: 4.2rem; text-align: center;
  font-size: 1.7rem; font-weight: 800; font-variant-numeric: tabular-nums;
}
.step {
  width: 3rem; height: 3rem; padding: 0;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 0.7rem;
  font: inherit; font-size: 1.6rem; font-weight: 700; line-height: 1; cursor: pointer;
}
.step:disabled { opacity: 0.35; cursor: default; }
.toggle { grid-template-columns: minmax(0, 1fr) auto; cursor: pointer; }
.toggle input { width: 1.5rem; height: 1.5rem; margin: 0 0.4rem; accent-color: #ff5d52; cursor: pointer; }
.total { margin: 0.3rem 0 0; text-align: center; color: var(--muted); font-size: 1rem; }

.run { display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; gap: 0.5rem; }
.phase {
  margin: 0; color: var(--phase);
  font-size: clamp(1.4rem, 6vw, 2.4rem); font-weight: 800; letter-spacing: 0.04em; text-transform: uppercase;
}
.clock {
  font-size: clamp(4rem, min(38vw, 30vh), 16rem);
  font-weight: 800; line-height: 1; letter-spacing: -0.02em; font-variant-numeric: tabular-nums;
}
/* Final seconds of a round, once the warning has sounded: the clock turns amber and pulses. */
body[data-warn="true"] .clock { color: var(--warn); }
@media (prefers-reduced-motion: no-preference) {
  body[data-warn="true"] .clock { animation: pulse 1s ease-in-out infinite; }
  #fill { transition: width 0.15s linear; }
}
@keyframes pulse { 50% { opacity: 0.55; } }

.bar { width: 100%; height: 0.6rem; background: var(--panel-2); border-radius: 999px; overflow: hidden; }
#fill { display: block; height: 100%; width: 0; background: var(--phase); }
.next { margin: 0.4rem 0 0; color: var(--muted); font-size: clamp(1.05rem, 4.5vw, 1.4rem); }
.next b { color: var(--text); }
.dots { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.4rem; margin-top: 0.3rem; }
.dots i { width: 0.8rem; height: 0.8rem; border-radius: 50%; background: var(--panel-2); border: 1px solid var(--line); }
.dots i.done { background: var(--muted); border-color: var(--muted); }
.dots i.now { background: var(--phase); border-color: var(--phase); }
.left { margin: 0; color: var(--muted); font-size: 0.95rem; font-variant-numeric: tabular-nums; }

/* ---------- controls ---------- */
.controls {
  flex: none;
  display: flex; justify-content: center; gap: 0.6rem;
  padding: 0.6rem 0.75rem calc(0.6rem + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
}
.ctl {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.15rem;
  width: 4.5rem; min-height: 3.75rem; padding: 0.3rem;
  background: var(--panel); color: var(--text);
  border: 1px solid var(--line); border-radius: 0.9rem;
  font: inherit; font-size: 0.8rem; font-weight: 600; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.ctl svg { width: 1.4rem; height: 1.4rem; fill: currentColor; }
.ctl:active:not(:disabled) { transform: scale(0.97); }
.ctl:disabled { opacity: 0.35; cursor: default; }
.ctl.primary {
  flex: 1 1 0; max-width: 16rem; font-size: 1.05rem;
  background: var(--phase); border-color: var(--phase); color: #101216;
}
.ctl.primary svg { width: 1.8rem; height: 1.8rem; }
body[data-view="setup"] #reset, body[data-view="setup"] #skip { visibility: hidden; }

/* Landscape phones: settings in two columns, and a slimmer running screen so the clock keeps its size. */
@media (max-height: 520px) and (orientation: landscape) {
  .top { padding: 0.3rem 0.75rem; }
  .tool { width: 2.4rem; height: 2.4rem; }
  .stage { padding: 0.4rem 1rem; }
  .setup, .run { max-width: 46rem; }
  .run { gap: 0.15rem; }
  .phase { font-size: 1.15rem; }
  .clock { font-size: min(22vw, 34vh); }
  .next { margin: 0; font-size: 1rem; }
  .left { display: none; }
  .setup { display: grid; grid-template-columns: 1fr 1fr; align-content: center; gap: 0.5rem; }
  .total { grid-column: 1 / -1; margin: 0; }
  .setting { min-height: 3rem; padding: 0.25rem 0.8rem; }
  .setting .value { min-width: 3.6rem; font-size: 1.4rem; }
  .step { width: 2.5rem; height: 2.5rem; }
  .controls { padding-top: 0.3rem; padding-bottom: calc(0.3rem + env(safe-area-inset-bottom)); }
  .ctl { min-height: 2.9rem; flex-direction: row; gap: 0.4rem; width: auto; padding: 0 0.8rem; }
}
