:root {
  --bg: #121110;
  --surface: #1c1b19;
  --surface-2: #2a2825;
  --line: #34312c;
  --text: #f3f1ec;
  --muted: #a8a399;

  --work: #c6f432;
  --work-ink: #0e0f0b;
  --rest: #2a2a2a;
  --rest-ink: #ffffff;
  --prep: #d9d9d4;
  --prep-ink: #121110;

  /* The timer view paints itself with these; body[data-phase] swaps them. */
  --stage: var(--bg);
  --ink: var(--text);

  --font-num: 'Barlow Condensed', 'Arial Narrow', sans-serif;
  --font-ui: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;

  /* Extra space under the main button; shared by setup and timer so both sit at the same height. */
  --dock: clamp(0px, 10dvh - 40px, 64px);

  color-scheme: dark;
}

body[data-phase="prep"] { --stage: var(--prep); --ink: var(--prep-ink); }
body[data-phase="work"] { --stage: var(--work); --ink: var(--work-ink); }
body[data-phase="rest"] { --stage: var(--rest); --ink: var(--rest-ink); }

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 1rem;
  line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

button { font: inherit; color: inherit; cursor: pointer; }

:focus-visible { outline: 3px solid var(--focus, var(--text)); outline-offset: 2px; }

svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

.view {
  display: none;
  flex-direction: column;
  min-height: 100dvh;
  padding: max(8px, 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));
}
.view.is-active { display: flex; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 52px;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 12px;
  background: transparent;
}
.icon-btn:hover { background: color-mix(in srgb, currentColor 10%, transparent); }

/* ---------- Configuración ---------- */

.setup { width: 100%; max-width: 560px; margin: 0 auto; padding-bottom: 0; background: var(--bg); }

.wordmark {
  font-family: var(--font-num);
  font-weight: 700;
  font-size: 1.5rem;
  letter-spacing: 0.01em;
}

.setup-body { flex: 1; }

.section-title {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--muted);
  margin: 20px 0 10px;
}

.presets {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scroll-snap-type: x proximity;
  margin: 0 -16px;
  padding: 0 16px 4px;
  scrollbar-width: none;
}
.presets::-webkit-scrollbar { display: none; }

.preset {
  flex: none;
  display: grid;
  align-content: start;
  gap: 8px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  text-align: left;
  scroll-snap-align: start;
}
.preset:hover { background: var(--surface-2); }
.preset[aria-pressed="true"] { border-color: var(--text); background: var(--surface-2); }
.preset-name { font-weight: 600; }
.preset-facts {
  display: grid;
  grid-template-columns: auto auto;
  column-gap: 14px;
  row-gap: 2px;
  align-items: baseline;
}
.preset-facts dt { font-size: 0.8125rem; color: var(--muted); }
.preset-facts dd {
  font-weight: 600;
  font-size: 0.9375rem;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.settings {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
}

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 72px;
  padding: 10px 12px 10px 16px;
}
.row + .row { border-top: 1px solid var(--line); }
label.row { cursor: pointer; min-height: 60px; }

.row-label { display: flex; align-items: center; gap: 10px; font-weight: 600; }

.swatch { width: 10px; height: 10px; border-radius: 3px; }
.swatch[data-type="prep"] { background: var(--prep); }
.swatch[data-type="work"] { background: var(--work); }
.swatch[data-type="rest"] { background: var(--rest); box-shadow: inset 0 0 0 1.5px var(--muted); }

.stepper { display: flex; align-items: center; }

.step-btn {
  width: clamp(40px, 12vw, 48px);
  height: clamp(40px, 12vw, 48px);
  border: 0;
  border-radius: 12px;
  background: var(--surface-2);
  font-size: 1.5rem;
  line-height: 1;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.step-btn:hover { background: var(--line); }
.step-btn:active { background: #3f3b35; }
.step-btn:disabled { opacity: 0.35; cursor: default; }

.step-value {
  width: clamp(56px, 18vw, 88px);
  text-align: center;
  font-weight: 600;
  font-size: 1.375rem;
  font-variant-numeric: tabular-nums;
}

.switch {
  appearance: none;
  flex: none;
  position: relative;
  width: 50px;
  height: 30px;
  border-radius: 15px;
  background: var(--line);
  cursor: pointer;
  transition: background-color 150ms ease;
}
.switch::before {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--text);
  transition: transform 150ms ease;
}
.switch:checked { background: var(--work); }
.switch:checked::before { transform: translateX(20px); }

.setup-footer {
  position: sticky;
  bottom: 0;
  padding-top: 28px;
  /* The view's bottom padding lives here so the sticky footer keeps it while scrolling. */
  padding-bottom: calc(var(--dock) + max(16px, env(safe-area-inset-bottom)));
  background: var(--bg);
}

.summary {
  display: flex;
  justify-content: center;
  gap: 48px;
  margin-bottom: 20px;
  color: var(--muted);
  text-align: center;
}
.summary span { display: grid; }
.summary strong {
  font-weight: 700;
  font-size: 2.5rem;
  line-height: 1;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.footer-actions { display: flex; gap: 8px; }

@media (max-height: 700px) {
  .setup-footer { padding-top: 12px; }
  .summary { margin-bottom: 12px; }
  .summary strong { font-size: 2rem; }
}

.btn {
  flex: 1;
  height: 64px;
  border: 0;
  border-radius: 14px;
  font-family: var(--font-num);
  font-weight: 700;
  font-size: 1.5rem;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--work); color: var(--work-ink); }
.btn-secondary { background: var(--surface-2); color: var(--text); }

/* ---------- Reloj ---------- */

.timer {
  --focus: var(--ink);
  background: var(--stage);
  color: var(--ink);
  transition: background-color 200ms ease, color 200ms ease;
}

.timer-top { display: grid; grid-template-columns: 1fr auto 1fr; }

.back-btn {
  justify-self: start;
  display: inline-flex;
  align-items: center;
  gap: 2px;
  height: 44px;
  padding: 0 12px 0 4px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  font-weight: 600;
}
.back-btn:hover { background: color-mix(in srgb, currentColor 10%, transparent); }

.round {
  font-family: var(--font-num);
  font-weight: 600;
  font-size: 1.375rem;
  font-variant-numeric: tabular-nums;
}

.topbar-actions { justify-self: end; display: flex; }

.timeline {
  display: flex;
  gap: var(--gap, 3px);
  height: 8px;
  margin-top: 8px;
}

.seg {
  flex-basis: 0;
  min-width: 1px;
  border-radius: 2px;
  overflow: hidden;
  background: color-mix(in srgb, var(--ink) 20%, transparent);
}
.seg > i { display: block; height: 100%; width: 0; background: var(--ink); }
.seg.done > i { width: 100%; }

.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 16px 0;
}

.phase-label {
  font-family: var(--font-num);
  font-weight: 700;
  font-size: clamp(1.75rem, 7vw, 3rem);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  line-height: 1;
}

.digits {
  font-family: var(--font-num);
  font-weight: 700;
  font-size: min(50vw, 40vh);
  line-height: 0.9;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}
.digits[data-long] { font-size: min(42vw, 40vh); }
body[data-paused] .digits { opacity: 0.4; }

.next { font-size: 1.125rem; font-weight: 500; }
.next span { opacity: 0.75; }

.controls {
  display: grid;
  grid-template-columns: 64px 1fr 64px;
  gap: 12px;
  width: 100%;
  max-width: 480px;
  margin: 0 auto var(--dock);
}

.ctl {
  display: grid;
  place-items: center;
  height: 64px;
  border: 0;
  border-radius: 16px;
  background: color-mix(in srgb, var(--ink) 14%, transparent);
}
.ctl:active { transform: scale(0.96); }
.ctl:disabled { opacity: 0.35; cursor: default; transform: none; }
.ctl svg { width: 26px; height: 26px; }

.ctl-main {
  background: var(--ink);
  color: var(--stage);
  font-family: var(--font-num);
  font-weight: 700;
  font-size: 1.75rem;
}

/* ---------- Fin ---------- */

.finish {
  margin: auto;
  width: min(400px, calc(100% - 32px));
  padding: 28px 20px 20px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--surface);
  color: var(--text);
}
.finish::backdrop { background: rgb(0 0 0 / 0.6); }
.finish h2 { font-family: var(--font-num); font-weight: 700; font-size: 2.75rem; line-height: 1; }
.finish-stats { color: var(--muted); margin: 8px 0 24px; font-variant-numeric: tabular-nums; }
.finish-stats strong { color: var(--text); font-weight: 600; }
.finish-actions { display: grid; gap: 8px; }

@media (orientation: landscape) and (max-height: 520px) {
  .timer { height: 100dvh; --dock: 0px; }
  .phase-label { font-size: 1.5rem; }
  .digits, .digits[data-long] { font-size: min(30vw, 44vh); }
  .stage { padding: 0; }
  .ctl { height: 56px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
}
