:root {
  --bg: #0e1013;
  --panel: #171a20;
  --panel-2: #1f232b;
  --line: #2b313b;
  --text: #f3f5f8;
  --muted: #9aa4b2;
  --accent: #f4c430; /* set per belt from the cauldron file */
  --tech: #5cd0e6;
  --warn: #ffb454;
  --ok: #5fd08a;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
}

/* The app is 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.5rem;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--line);
}
.field { display: grid; gap: 0.25rem; min-width: 0; }
.field.pick { flex: 0 1 9.5rem; }
.field.grow { flex: 1 1 0; }

/* Labels only appear when there is room; phones rely on the selected value. */
.lbl {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

select {
  width: 100%;
  min-height: 2.75rem;
  padding: 0.4rem 0.6rem;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 0.6rem;
  font: inherit;
  font-size: 0.95rem;
  text-overflow: ellipsis;
}
select:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.tools { flex: none; display: flex; align-items: center; gap: 0.5rem; }
.tool {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  width: 2.75rem; height: 2.75rem; padding: 0;
  background: var(--panel); color: var(--text);
  border: 1px solid var(--line); border-radius: 0.6rem; font: inherit; cursor: pointer;
}
.tool span { display: none; }
.tool svg { width: 1.2rem; height: 1.2rem; fill: currentColor; }
.tool[aria-pressed="true"] { color: var(--muted); }
.tool[aria-pressed="true"] .waves { display: none; }

/* ---------- stage ---------- */
.stage {
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding: 0.5rem 0.75rem 0.5rem;
  overflow-y: auto; /* safety net only; the layout is sized so this never engages */
}

.now {
  flex: 1 1 0;
  min-height: 14rem;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.meta { flex: none; display: flex; align-items: center; gap: 0.4rem; min-width: 0; }
.badge {
  flex: none;
  padding: 0.25rem 0.65rem; border-radius: 999px;
  background: var(--panel-2); border: 1px solid var(--line);
  font-size: 0.85rem; font-weight: 600; white-space: nowrap;
}
.badge.kind { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 50%, transparent); }
.badge.equip { background: var(--accent); color: #101216; border-color: var(--accent); }
.stage[data-kind="technique"] .badge.kind { color: var(--tech); border-color: color-mix(in srgb, var(--tech) 50%, transparent); }
.badge[hidden] { display: none; }

/* Screen-awake status: a small dot on phones, a labelled pill when there is room. */
.pill {
  margin-left: auto;
  width: 0.75rem; height: 0.75rem; padding: 0; border-radius: 50%;
  font-size: 0; border: 0; background: currentColor; color: var(--muted);
}
.pill[hidden] { display: none; }
.pill.ok { color: var(--ok); }
.pill.warn { color: var(--warn); }

.clock {
  flex: none;
  font-size: clamp(3.5rem, min(38vw, 22vh), 12rem);
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}
.stage[data-kind="technique"] .clock { color: var(--tech); }
.stage[data-state="finished"] .clock { color: var(--ok); }

.track { flex: none; height: 0.5rem; background: var(--panel-2); border-radius: 999px; overflow: hidden; }
#stepFill { height: 100%; width: 0; background: var(--accent); }
.stage[data-kind="technique"] #stepFill { background: var(--tech); }

/* The step text takes whatever height is left; app.js shrinks the font until it fits. */
.textbox { flex: 1 1 0; min-height: 0; position: relative; }
.text {
  position: absolute; inset: 0; margin: 0;
  display: flex; align-items: center; overflow: hidden;
  font-weight: 750; line-height: 1.1;
  text-wrap: balance; overflow-wrap: anywhere;
}
.text > span { display: block; width: 100%; font-size: 2rem; }
/* A cumulative interval ("+ Sprawl") stacks its lines: the base drill, then each addition. */
.text .ln + .ln { margin-top: 0.1em; }

.line {
  flex: none; margin: 0.15rem 0 0;
  display: flex; align-items: center; gap: 0.45rem; min-width: 0;
  white-space: nowrap; color: var(--muted);
  font-size: clamp(1.05rem, 4.6vw, 1.5rem);
}
.line[hidden] { display: none; }
.line .lead { flex: none; }
.line .val { min-width: 0; overflow: hidden; text-overflow: ellipsis; color: var(--text); font-weight: 700; }
.badge.mini { flex: none; padding: 0.1rem 0.55rem; font-size: 0.8rem; }

/* ---------- round steps and progress ---------- */
.side { flex: none; display: grid; gap: 0.45rem; }
.side-h { display: none; }

/* Phones: this round shows as a row of numbered chips. */
.round-list { list-style: none; margin: 0; padding: 0; display: flex; gap: 0.4rem; }
.round-list li {
  flex: 1 1 0; display: flex; justify-content: center; gap: 0.5rem;
  padding: 0.3rem 0; border-radius: 999px;
  background: var(--panel); border: 1px solid transparent; color: var(--muted);
}
.round-list .n { font-weight: 700; font-variant-numeric: tabular-nums; }
.round-list .what { display: none; }
.round-list li.done { opacity: 0.45; }
.round-list li.current { color: var(--text); background: var(--panel-2); border-color: var(--accent); }
.round-list li.technique.current { border-color: var(--tech); }

.progress { display: grid; gap: 0.3rem; }
.segments { display: flex; gap: 4px; }
.segments div { flex: 1; height: 0.5rem; background: var(--panel-2); border-radius: 3px; overflow: hidden; }
.segments i { display: block; height: 100%; width: 0; background: var(--accent); }
.totals { display: flex; justify-content: space-between; margin: 0; }
.totals div { display: flex; align-items: baseline; gap: 0.4rem; }
.totals dt { font-size: 0.7rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }
.totals dd { margin: 0; font-size: 0.95rem; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------- controls ---------- */
.controls {
  flex: none;
  display: flex; justify-content: center; align-items: stretch; gap: 0.4rem;
  padding: 0.5rem 0.6rem calc(0.5rem + env(safe-area-inset-bottom));
  background: var(--bg);
  border-top: 1px solid var(--line);
}
.ctl {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.15rem;
  min-width: 0; min-height: 3.5rem; padding: 0.3rem 0.45rem;
  background: var(--panel); color: var(--text);
  border: 1px solid var(--line); border-radius: 0.9rem;
  font: inherit; font-size: 0.78rem; 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:not(.small):not(.primary) { width: 4rem; }
.ctl.small { width: 2.9rem; color: var(--muted); }
.ctl.small span { display: none; }
.ctl.primary {
  flex: 1 1 0; max-width: 14rem; font-size: 1.05rem;
  background: var(--accent); border-color: var(--accent); color: #101216;
}
.ctl.primary svg { width: 1.7rem; height: 1.7rem; }

.debug {
  position: fixed; right: 4px; top: 3.6rem; z-index: 10; pointer-events: none;
  padding: 2px 6px; border-radius: 4px; background: #000c; color: #fff; font: 11px/1.4 ui-monospace, monospace;
}

/* ---------- wider than a phone: labels and roomier controls ---------- */
@media (min-width: 720px) and (min-height: 521px) {
  .top { align-items: end; gap: 0.75rem; padding: 0.75rem 1rem; }
  .lbl {
    position: static; width: auto; height: auto; overflow: visible; clip: auto;
    font-size: 0.7rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted);
  }
  .field.pick { flex-basis: 13rem; }
  .tool { width: auto; padding: 0 0.85rem; }
  .tool span { display: inline; }
  .stage { padding: 1rem 1.5rem; gap: 0.75rem; }
  .now { gap: 0.5rem; }
  .badge { font-size: clamp(0.9rem, 1.6vw, 1.1rem); padding: 0.35rem 0.8rem; }
  .pill {
    width: auto; height: auto; padding: 0.3rem 0.65rem; border-radius: 999px; font-size: 0.8rem;
    border: 1px solid currentColor; background: none;
  }
  .line { font-size: clamp(1.2rem, 2.1vw, 1.6rem); }
  .controls { gap: 0.6rem; padding: 0.75rem 1rem calc(0.75rem + env(safe-area-inset-bottom)); }
  .ctl { min-height: 4rem; font-size: 0.85rem; }
  .ctl.small { width: 3.5rem; }
}

/* ---------- desktop / tablet landscape: full list and progress panel beside the timer ---------- */
@media (min-width: 960px) and (min-height: 521px) {
  .stage { flex-direction: row; gap: 2rem; padding: 1.5rem 2rem; overflow: hidden; }
  .now { min-height: 0; }
  .clock { font-size: clamp(5rem, min(20vw, 30vh), 14rem); }
  .side { flex: 0 0 22rem; display: block; overflow-y: auto; }
  .side-h {
    display: block; margin: 0 0 0.6rem; font-size: 0.75rem; letter-spacing: 0.08em;
    text-transform: uppercase; color: var(--muted); font-weight: 600;
  }
  .round-list { display: grid; gap: 0.4rem; margin-bottom: 1.5rem; }
  .round-list li {
    display: grid; grid-template-columns: 1.6rem 1fr; gap: 0.6rem; align-items: baseline;
    justify-content: stretch; padding: 0.55rem 0.7rem; border-radius: 0.6rem;
  }
  .round-list .what { display: inline; }
  .round-list li.technique { margin-top: 0.3rem; }
  .segments div { height: 0.6rem; }
  .segments { margin-bottom: 0.9rem; }
  .totals { gap: 2rem; justify-content: flex-start; }
  .totals div { display: block; }
  .totals dd { margin-top: 0.1rem; font-size: 1.5rem; }
}

/* ---------- landscape phones: clock on the left, step text on the right ---------- */
@media (max-height: 520px) and (orientation: landscape) {
  .top { padding: 0.3rem 0.75rem; }
  select, .tool { min-height: 2.4rem; height: 2.4rem; }
  .stage { padding: 0.3rem 0.75rem 0.3rem; gap: 0; }
  .side { display: none; }
  .now {
    min-height: 0;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-rows: auto auto auto auto;
    grid-template-areas: "meta meta" "clock text" "track text" "next next";
    column-gap: 1.25rem; row-gap: 0.15rem;
  }
  .meta { grid-area: meta; }
  .clock { grid-area: clock; font-size: min(22vw, 30vh); }
  .track { grid-area: track; }
  .textbox { grid-area: text; }
  #next { grid-area: next; }
  .line { font-size: 1rem; }
  .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; }
  .ctl svg, .ctl.primary svg { width: 1.3rem; height: 1.3rem; }
}

@media (prefers-reduced-motion: no-preference) {
  #stepFill, .segments i { transition: width 0.15s linear; }
}
