/* Circuit Interval Timer -- mobile-first, glanceable-from-across-the-room. */

:root {
  --bg: #0b1120;
  --card: #131c31;
  --card-2: #1a2540;
  --line: #26324f;
  --text: #eef2ff;
  --muted: #94a3b8;
  --accent: #22c55e;

  --work: #15a34a;
  --work-2: #0d7a36;
  --work-final: #22c55e;   /* last round of a station: same hue, lifted */
  --rest: #2563eb;
  --rest-2: #1a47b8;
  --break: #d97706;
  --break-2: #b45309;
  --prep: #6d28d9;
  --prep-2: #4c1d95;
  --done: #0f766e;
  --done-2: #115e59;

  --pad: 16px;
  --radius: 14px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

body { min-height: 100dvh; }

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }

/* A class rule carrying `display` outranks the UA rule for [hidden], which
   silently re-shows collapsed panels. Make the attribute win everywhere. */
[hidden] { display: none !important; }

/* ================================================================ SETUP == */

.setup {
  max-width: 640px;
  margin: 0 auto;
  padding: calc(var(--safe-t) + 14px) var(--pad) calc(var(--safe-b) + 40px);
}

.app-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.brand { display: flex; align-items: center; gap: 10px; }

.brand-mark {
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 4px solid var(--accent);
  border-right-color: transparent;
  transform: rotate(-45deg);
}

.brand-text { font-size: 19px; font-weight: 700; letter-spacing: -0.01em; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--pad);
  margin-bottom: 14px;
}

.card-title {
  margin: 0 0 12px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.sub-title {
  margin: 18px 0 8px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.row-between {
  display: flex; align-items: baseline; justify-content: space-between; gap: 10px;
}

.field-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.field { display: block; }

.num, .select, .text-in {
  width: 100%;
  min-height: 52px;
  padding: 10px 12px;
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 20px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  outline: none;
  appearance: none;
}

.text-in { font-size: 16px; font-weight: 500; }
.select { font-size: 17px; }

.num:focus, .select:focus, .text-in:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.22);
}

.summary {
  margin-top: 14px;
  padding: 12px 14px;
  background: var(--card-2);
  border-radius: 10px;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
}

.summary strong { color: var(--accent); }

.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

.mini-btn {
  flex: 1 1 auto;
  min-height: 46px;
  padding: 0 14px;
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
}

.mini-btn:active { background: #24314f; }
.mini-btn.danger { color: #fca5a5; }

.ghost-btn {
  min-height: 44px;
  padding: 0 14px;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
}

.ghost-btn[aria-pressed="true"] { color: #fca5a5; border-color: #7f1d1d; }
.ghost-btn.light { border-color: rgba(255, 255, 255, 0.4); color: #fff; }

.toggle {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 11px 0;
  font-size: 15px;
  line-height: 1.4;
  border-bottom: 1px solid var(--line);
}

.toggle:last-of-type { border-bottom: 0; }

.toggle input {
  flex: 0 0 auto;
  width: 26px; height: 26px;
  margin: 0;
  accent-color: var(--accent);
}

.disclosure {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 44px;
  padding: 0;
  background: none;
  border: 0;
  font-size: 15px;
  font-weight: 600;
  text-align: left;
}

.chev {
  width: 9px; height: 9px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(45deg);
  transition: transform 0.15s ease;
}

.disclosure[aria-expanded="true"] .chev { transform: rotate(-135deg); }

.station-list { display: grid; gap: 8px; margin-top: 12px; }

.station-row { display: flex; align-items: center; gap: 10px; }

.station-num {
  flex: 0 0 34px;
  height: 34px;
  display: grid;
  place-items: center;
  background: var(--card-2);
  border-radius: 8px;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
}

.hint { font-size: 12.5px; color: var(--muted); line-height: 1.5; }
.pad-top { margin-top: 12px; }

.start-btn {
  display: block;
  width: 100%;
  min-height: 76px;
  margin: 20px 0 14px;
  background: linear-gradient(180deg, #22c55e, #16a34a);
  border: 0;
  border-radius: 16px;
  color: #04140a;
  font-size: 24px;
  font-weight: 800;
  letter-spacing: 0.02em;
  box-shadow: 0 8px 22px rgba(34, 197, 94, 0.28);
}

.start-btn:active { transform: translateY(1px); }

.log-list { display: grid; gap: 6px; }

.log-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 11px;
  background: var(--card-2);
  border-radius: 8px;
  font-size: 13.5px;
}

.log-row span:last-child { color: var(--muted); font-variant-numeric: tabular-nums; }

.caps { font-size: 12.5px; color: var(--muted); line-height: 1.7; }
.caps b { color: var(--text); font-weight: 600; }
.caps .no { color: #fca5a5; }
.caps .yes { color: #86efac; }

.foot {
  margin: 26px 0 0;
  text-align: center;
  font-size: 12px;
  color: #64748b;
}

/* ================================================================== RUN == */

.run {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: calc(var(--safe-t) + 12px) 16px calc(var(--safe-b) + 14px);
  background: var(--prep);
  color: #fff;
  transition: background-color 0.25s ease;
}

.run[data-phase="work"]  { background: var(--work); }
.run[data-phase="work"][data-final="true"] { background: var(--work-final); }
.run[data-phase="rest"]  { background: var(--rest); }
.run[data-phase="break"] { background: var(--break); }
.run[data-phase="prep"]  { background: var(--prep); }
.run[data-phase="done"]  { background: var(--done); }
.run[data-phase="idle"]  { background: #1e293b; }

.run.paused { background: #334155 !important; }

.run-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex: 0 0 auto;
}

.run-pos {
  font-size: clamp(15px, 4.4vw, 22px);
  font-weight: 700;
  letter-spacing: 0.02em;
  opacity: 0.95;
}

.dot-sep { opacity: 0.6; margin: 0 6px; }

.run-mid {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 0;
  text-align: center;
}

.phase {
  font-size: clamp(22px, 8vw, 46px);
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  opacity: 0.92;
}

.clock {
  font-size: clamp(84px, 33vw, 250px);
  font-weight: 800;
  line-height: 0.92;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
  text-shadow: 0 6px 26px rgba(0, 0, 0, 0.25);
}

.clock.urgent { animation: pulse 1s ease-in-out infinite; }

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  22%      { transform: scale(1.055); }
}

@media (prefers-reduced-motion: reduce) {
  .clock.urgent { animation: none; }
}

.final-pill {
  margin-top: 8px;
  padding: 6px 18px;
  background: rgba(0, 0, 0, 0.3);
  border: 2px solid rgba(255, 255, 255, 0.85);
  border-radius: 999px;
  font-size: clamp(14px, 4.2vw, 22px);
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.station-name {
  margin-top: 4px;
  font-size: clamp(20px, 6.4vw, 38px);
  font-weight: 700;
  line-height: 1.15;
  max-width: 20ch;
}

.next-up {
  margin-top: 10px;
  font-size: clamp(13px, 3.8vw, 18px);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  opacity: 0.75;
}

.run-progress { flex: 0 0 auto; padding-bottom: 12px; }

.dots {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  margin-bottom: 8px;
}

.dots i {
  display: block;
  width: 13px; height: 13px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.28);
}

.dots i.done { background: rgba(255, 255, 255, 0.72); }
.dots i.now  { background: #fff; box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.3); }

.dots-round i { width: 9px; height: 9px; border-radius: 3px; }

.bar {
  height: 7px;
  margin: 10px 0 7px;
  background: rgba(0, 0, 0, 0.22);
  border-radius: 999px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  width: 0%;
  background: rgba(255, 255, 255, 0.9);
  border-radius: 999px;
}

.totals {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  opacity: 0.85;
}

.controls {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: 1.6fr 1fr 1fr;
  gap: 10px;
}

.ctl {
  min-height: 68px;
  padding: 0 8px;
  background: rgba(0, 0, 0, 0.24);
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 14px;
  color: #fff;
  font-size: 18px;
  font-weight: 700;
}

.ctl:active { background: rgba(0, 0, 0, 0.38); }

.ctl-primary {
  background: rgba(255, 255, 255, 0.95);
  border-color: transparent;
  color: #0b1120;
  font-size: 20px;
  font-weight: 800;
}

.wake-note {
  position: absolute;
  left: 16px; right: 16px;
  bottom: calc(var(--safe-b) + 96px);
  padding: 9px 12px;
  background: rgba(0, 0, 0, 0.4);
  border-radius: 10px;
  font-size: 12.5px;
  line-height: 1.45;
  text-align: center;
}

/* ================================================================ TOAST == */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-b) + 24px);
  transform: translateX(-50%);
  z-index: 50;
  max-width: min(560px, calc(100vw - 32px));
  padding: 12px 18px;
  background: #f8fafc;
  border-radius: 12px;
  color: #0b1120;
  font-size: 14.5px;
  font-weight: 600;
  line-height: 1.4;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}

.toast[hidden] { display: none; }

/* ============================================================== LAYOUT == */

@media (min-width: 520px) {
  .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* Landscape phone: the clock has to shrink or it pushes the controls off. */
@media (orientation: landscape) and (max-height: 520px) {
  .clock { font-size: clamp(60px, 17vh, 130px); }
  .phase { font-size: clamp(16px, 4.4vh, 28px); }
  .station-name { font-size: clamp(16px, 4.6vh, 26px); }
  .ctl { min-height: 54px; font-size: 16px; }
  .run-progress { padding-bottom: 6px; }
  .dots { margin-bottom: 4px; }
}
