:root {
  color-scheme: light dark;
  --bg: #101410;
  --panel: #191e19;
  --panel-raised: #232b22;
  --input: #141914;
  --line: #323b31;
  --text: #f3f6ee;
  --muted: #abb6a7;
  --accent: #c5f866;
  --accent-ink: #1a2809;
  --line-accent: #486035;
  --dial-base: #33412f;
  --hero-top: #253322;
  --warning: #ffb0a7;
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

:root[data-theme="dark"] { color-scheme: dark; }
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #eef2e9;
  --panel: #fff;
  --panel-raised: #edf3e6;
  --input: #f8faf5;
  --line: #d1dacb;
  --text: #222b21;
  --muted: #505f4b;
  --accent: #416c20;
  --accent-ink: #fff;
  --line-accent: #a2b790;
  --dial-base: #dfebd4;
  --hero-top: #e7f0db;
  --warning: #a12d23;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    color-scheme: light;
    --bg: #eef2e9;
    --panel: #fff;
    --panel-raised: #edf3e6;
    --input: #f8faf5;
    --line: #d1dacb;
    --text: #222b21;
    --muted: #505f4b;
    --accent: #416c20;
    --accent-ink: #fff;
    --line-accent: #a2b790;
    --dial-base: #dfebd4;
    --hero-top: #e7f0db;
    --warning: #a12d23;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--text); }
body, main { padding-bottom: env(safe-area-inset-bottom); }
a { color: inherit; }
button, select, input, textarea { font: inherit; color: inherit; }
button, select, summary { cursor: pointer; }
button:disabled, select:disabled { cursor: default; opacity: .5; }
:focus-visible, .import-button:focus-within { outline: 3px solid var(--accent); outline-offset: 3px; }
h1, h2, p { margin: 0; }
h2 { font-size: 1.08rem; letter-spacing: -.02em; }
p { color: var(--muted); }
.shell { width: min(100% - 48px, 1080px); margin-inline: auto; }
.top { border-bottom: 1px solid var(--line); padding-top: env(safe-area-inset-top); }
.top-inner { display: flex; align-items: center; justify-content: space-between; min-height: 74px; gap: 18px; }
.brand { display: flex; align-items: center; text-decoration: none; font-size: 1.44rem; font-weight: 800; letter-spacing: -.055em; }
.brand img { margin-right: 10px; border-radius: 9px; }
.brand span { color: var(--accent); }
nav { display: flex; align-items: center; gap: 4px; }
nav a { padding: 10px 14px; color: var(--muted); text-decoration: none; border-radius: 10px; font-size: .94rem; }
nav a[aria-current="page"], nav a:hover { color: var(--text); background: var(--panel-raised); }
.page-heading { padding: 26px 0 20px; }
h1 { font-size: clamp(2rem, 4.6vw, 3rem); line-height: 1.1; letter-spacing: -.055em; }
.page-heading p { margin-top: 8px; }
.dashboard { display: grid; grid-template-columns: minmax(0, 1.26fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.timer-column, .builder-column, .settings-grid { display: grid; gap: 14px; min-width: 0; }
.panel, .timer-card { background: var(--panel); border: 1px solid var(--line); border-radius: 20px; padding: 20px; }
.timer-card {
  display: grid;
  gap: 21px;
  background: radial-gradient(ellipse at 50% 35%, var(--hero-top), transparent 79%), var(--panel);
  border-color: var(--line-accent);
}
.timer-top, .timer-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.phase-tag { color: var(--accent); border: 1px solid var(--line-accent); padding: 4px 10px; border-radius: 20px; font-size: .85rem; font-weight: 650; }
.session-step, .timer-foot { font-size: .875rem; color: var(--muted); }
.timer-foot { margin-top: -5px; min-height: 21px; }
.dial {
  --progress: 100%;
  display: grid;
  place-items: center;
  width: min(100%, 290px);
  aspect-ratio: 1;
  border-radius: 50%;
  padding: 8px;
  margin: 4px auto 0;
  background: conic-gradient(var(--accent) var(--progress), var(--dial-base) 0);
}
.dial-inner {
  display: grid;
  align-content: center;
  justify-items: center;
  width: 100%;
  height: 100%;
  padding: 24px 14px;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 15%, var(--hero-top), var(--panel));
  text-align: center;
}
.phase-label, .phase-next { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; overflow-wrap: anywhere; }
.phase-label { color: var(--accent); font-weight: 700; }
.phase-next { font-size: .86rem; color: var(--muted); min-height: 1.25rem; }
.clock { font-size: clamp(3.75rem, 9vw, 5rem); line-height: 1.06; font-weight: 760; letter-spacing: -.08em; font-variant-numeric: tabular-nums; padding-right: .07em; }
.clock.long { font-size: clamp(2.9rem, 7vw, 3.75rem); }
.exercise-note { border-left: 3px solid var(--accent); padding-left: 12px; overflow-wrap: anywhere; white-space: pre-wrap; }
.timer-controls { display: flex; gap: 8px; flex-wrap: wrap; }
.primary, .secondary, .plain, .chip {
  border: 1px solid transparent;
  border-radius: 11px;
  min-height: 44px;
  font-weight: 650;
  padding: 8px 13px;
}
.primary { background: var(--accent); color: var(--accent-ink); flex: 1; min-height: 49px; }
.primary:hover { filter: brightness(.92); }
.secondary { background: var(--panel-raised); border-color: var(--line); }
.secondary:hover, .chip:hover, .plain:hover { border-color: var(--line-accent); color: var(--accent); }
.plain { background: transparent; color: var(--muted); }
.radio { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; }
.radio-title, .radio-controls { display: flex; align-items: center; gap: 11px; }
.radio-title p { font-size: .875rem; margin-top: 1px; }
.radio-symbol { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 12px; background: var(--panel-raised); color: var(--accent); font-weight: 700; font-size: 1.4rem; }
.radio-controls select { min-width: 155px; }
.radio-button { width: 46px; }
fieldset { padding: 0; border: 0; margin: 0; min-width: 0; }
legend { font-size: 1.08rem; letter-spacing: -.02em; font-weight: 700; padding: 0; margin-bottom: 14px; }
.field { display: grid; gap: 5px; color: var(--muted); font-size: .875rem; min-width: 0; }
.field :is(input, select, textarea), .radio select {
  border: 1px solid var(--line);
  background: var(--input);
  border-radius: 10px;
  min-height: 44px;
  width: 100%;
  padding: 8px 11px;
  color: var(--text);
  font-size: 1rem;
}
textarea { resize: vertical; }
select {
  appearance: none;
  padding-right: 30px !important;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%) !important;
  background-position: right 15px center, right 10px center !important;
  background-size: 5px 5px !important;
  background-repeat: no-repeat !important;
}
.plan-name { margin-bottom: 13px; }
.fields-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 11px 12px; }
.builder-actions, .backup-actions { display: flex; gap: 7px; flex-wrap: wrap; }
.chip { font-size: .87rem; color: var(--muted); background: var(--input); border-color: var(--line); }
.builder-actions { margin-top: 15px; }
.library, #circuit-fields { margin-block: 12px; }
.library { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.library > summary { font-weight: 680; min-height: 33px; }
.inventory { margin-top: 9px; }
.inventory .check { font-size: .9rem; }
.circuit-note { margin: 8px 0; font-size: .875rem; }

#phase-list { display: grid; gap: 10px; margin-bottom: 9px; }
.phase-editor { border: 1px solid var(--line); border-radius: 12px; padding: 11px; display: grid; gap: 9px; }
.phase-tools { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; }
.phase-tools strong { margin-right: auto; }
.phase-tools button { min-width: 44px; padding-inline: 9px; }
.saved h2 { margin-bottom: 8px; }
.saved-row { display: flex; gap: 6px; align-items: center; padding: 6px 0; }
.saved-row + .saved-row, .history-row + .history-row { border-top: 1px solid var(--line); }
.saved-row .open-plan { flex: 1; text-align: left; overflow-wrap: anywhere; }
.history-row { padding: 12px 0; }
.history-row summary { font-weight: 680; min-height: 44px; padding-top: 6px; overflow-wrap: anywhere; }
.history-row p { margin: 5px 0 0; }
.history-row ol { margin: 8px 0 0; padding-left: 24px; }
.history-row li { padding-top: 4px; overflow-wrap: anywhere; }
.settings-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.settings-grid p { margin-top: 8px; }
#voice-status:empty { display: none; }
.setting { margin-top: 12px; }
.check { display: flex; gap: 6px; min-height: 44px; align-items: center; }
.check input { accent-color: var(--accent); width: 20px; height: 20px; }
.backup-actions { margin-top: 12px; }
.import-button { cursor: pointer; display: inline-grid; place-items: center; position: relative; }
.import-button input { position: absolute; width: 100%; height: 100%; opacity: 0; inset: 0; cursor: pointer; }
.toast { position: fixed; bottom: calc(16px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); z-index: 2; width: max-content; max-width: calc(100% - 30px); padding: 12px 17px; background: var(--panel-raised); border: 1px solid var(--line-accent); border-radius: 12px; box-shadow: 0 8px 24px #0004; }
.toast.error { color: var(--warning); }

@media (max-width: 780px) {
  .dashboard, .settings-grid { grid-template-columns: 1fr; }
  .shell { width: min(100% - 30px, 580px); }
  .top-inner { min-height: 63px; }
  .page-heading { padding-top: 21px; }
}

@media (max-width: 420px) {
  nav a { padding-inline: 8px; font-size: .875rem; }
  .top-inner { gap: 6px; }
  .brand img { margin-right: 6px; width: 27px; height: 27px; }
  .brand { font-size: 1.25rem; }
  .panel, .timer-card { padding: 15px; }
  .dial { width: min(100%, 246px); }
  .timer-secondary { flex: 1; }
  .timer-controls .primary { flex-basis: 100%; }
}

.workout-progress { display: grid; gap: 5px; font-size: .9rem; color: var(--muted); }
.workout-progress > div { display: flex; justify-content: space-between; gap: 8px; }
.workout-progress span { color: var(--text); font-variant-numeric: tabular-nums; font-weight: 700; }
.workout-progress progress { width: 100%; height: 9px; accent-color: var(--accent); }

html:has(body[data-workout-running]) { overflow: hidden; overscroll-behavior: none; }
body[data-workout-running] { position: fixed; inset: 0; min-height: 0; overflow: hidden; padding: 0; }
body[data-workout-running] :is(.top, .page-heading, .builder-column, .timer-foot) { display: none; }
body[data-workout-running] main.shell {
  width: min(100% - 24px, 640px);
  height: 100dvh;
  padding: max(8px, env(safe-area-inset-top)) 0 max(8px, env(safe-area-inset-bottom));
  display: grid;
  align-items: center;
}
body[data-workout-running] .dashboard { grid-template-columns: minmax(0, 1fr); }
body[data-workout-running] .timer-column { gap: clamp(6px, 1.4dvh, 14px); }
body[data-workout-running] .timer-card { gap: clamp(8px, 1.65dvh, 16px); }
body[data-workout-running] .dial { width: min(100%, clamp(134px, 35dvh, 300px)); margin-top: 0; }
body[data-workout-running] .dial-inner { padding: 9px; }
body[data-workout-running] .clock { font-size: clamp(2.8rem, 9dvh, 5.2rem); }
body[data-workout-running] .clock.long { font-size: clamp(2.15rem, 7dvh, 3.75rem); }
body[data-workout-running] .exercise-note {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-size: .93rem;
}
body[data-workout-running] .timer-controls { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
body[data-workout-running] .timer-controls button { padding-inline: 4px; }
body[data-workout-running] .radio { padding: 10px 12px; }
body[data-workout-running] .radio-controls select { min-width: 135px; }

@media (max-height: 560px) {
  body[data-workout-running] .dial { width: min(100%, clamp(106px, 32dvh, 178px)); padding: 5px; }
  body[data-workout-running] .timer-card { padding: 11px; }
  body[data-workout-running] .radio-title h2 { font-size: .95rem; }
  body[data-workout-running] .radio-symbol { display: none; }
}

@media (orientation: landscape) and (max-height: 530px) {
  body[data-workout-running] main.shell { width: min(100% - 52px, 640px); }
  body[data-workout-running] .timer-card { grid-template-columns: minmax(110px, 34%) minmax(0, 1fr); align-items: center; }
  body[data-workout-running] .timer-card > :not(.dial) { grid-column: 2; }
  body[data-workout-running] .dial { grid-column: 1; grid-row: 1 / span 4; }
}

.icon-library { position: absolute; width: 0; height: 0; overflow: hidden; }
#plan-fields > legend { font-size: 1.28rem; }
.timer-mode { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 10px; }
.timer-mode button {
  border: 1px solid transparent;
  border-radius: 30px;
  background: transparent;
  min-height: 42px;
  padding: 6px 12px;
  color: var(--muted);
  font-size: .875rem;
  font-weight: 650;
}
.timer-mode button[aria-pressed="true"] { background: var(--panel-raised); border-color: var(--line-accent); color: var(--text); }
.timer-unit { text-align: right; font-size: .8125rem; margin-bottom: 6px; color: var(--muted); }

.timing-diagram {
  --warm: #d9a441;
  --work: #22b573;
  --rest: #528fde;
  --cool: #a38bd4;
  --round: #e08c46;
  --number: 56px;
  --edge: 8px;
  --brace: 15px;
  --counter-width: calc(var(--number) + var(--edge) * 2);
  --block-gap: 8px;
  display: grid;
  gap: var(--block-gap);
  min-width: 0;
}

.timing-round, .timing-cycle { display: grid; align-items: stretch; min-width: 0; }
.timing-round {
  grid-template-columns: minmax(0, 1fr) 0px 0px;
  transition: grid-template-columns 200ms ease;
}
.timing-diagram[data-expanded] .timing-round { grid-template-columns: minmax(0, 1fr) var(--brace) var(--counter-width); }
.timing-round-content, .timing-cycle-content { min-width: 0; }
.timing-cycle { grid-template-columns: minmax(0, 1fr) var(--brace) var(--counter-width); }
.timing-cycle-content { display: grid; gap: var(--block-gap); }
.timing-round-rest {
  display: grid;
  grid-template-rows: 0fr;
  opacity: 0;
  transition: grid-template-rows 200ms ease, opacity 160ms ease;
}
.timing-round-rest > div { min-height: 0; overflow: hidden; }
.timing-round-rest .timing-phase { margin-top: var(--block-gap); }
.timing-diagram[data-expanded] .timing-round-rest { grid-template-rows: 1fr; opacity: 1; }
.timing-round-count { min-width: 0; display: grid; align-items: center; overflow: hidden; }
.timing-round-count, .timing-brace.round-brace { opacity: 0; visibility: hidden; transition: opacity 160ms ease, visibility 160ms; }
.timing-diagram[data-expanded] :is(.timing-round-count, .timing-brace.round-brace) { opacity: 1; visibility: visible; }

.timing-warmup { --tone: var(--warm); }
.timing-work, .timing-cycle-count { --tone: var(--work); }
.timing-rest, .timing-long-rest { --tone: var(--rest); }
.timing-cooldown { --tone: var(--cool); }
.timing-round-count { --tone: var(--round); }
.timing-phase, .timing-counter {
  color: light-dark(color-mix(in srgb, var(--tone) 42%, #111a14), var(--tone));
  background: color-mix(in srgb, var(--tone) 13%, var(--panel));
  border: 1px solid color-mix(in srgb, var(--tone) 20%, transparent);
  border-radius: 12px;
  min-width: 0;
  padding: 8px max(1px, calc(var(--edge) - 1px));
}

.timing-phase:is(label), .timing-phase-line {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--number);
  gap: 4px;
  align-items: center;
}
.timing-caption { display: flex; align-items: center; gap: 5px; min-width: 0; font-size: .875rem; font-weight: 690; line-height: 1.2; }
.timing-diagram svg { fill: none; stroke: currentColor; stroke-width: 1.65; stroke-linecap: round; stroke-linejoin: round; }
.timing-caption svg, .timing-counter svg { width: 18px; height: 18px; flex: 0 0 auto; }
.timing-diagram input[type="number"] {
  width: var(--number);
  min-width: 0;
  min-height: 40px;
  padding: 4px 1px;
  text-align: center;
  appearance: textfield;
  background: color-mix(in srgb, var(--tone) 6%, var(--input));
  color: inherit;
  border: 1px solid color-mix(in srgb, var(--tone) 47%, var(--line));
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 770;
  font-variant-numeric: tabular-nums;
}
.timing-diagram input::-webkit-inner-spin-button, .timing-diagram input::-webkit-outer-spin-button { appearance: none; margin: 0; }
.timing-counter { display: grid; grid-template-columns: minmax(0, 1fr); gap: 4px; justify-items: center; align-content: center; font-size: .8125rem; }
.timing-counter span { max-width: 100%; font-size: min(.8125rem, calc(var(--number) / 3.7)); }
.timing-counter.timing-cycle-count { align-self: center; }
.timing-brace { display: block; width: 100%; height: 100%; min-height: 0; color: var(--work); padding: 2px 1px; }
.timing-brace.round-brace { color: var(--round); }

.timing-switch {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 4px;
  font-size: .8125rem;
  line-height: 1.2;
  color: var(--text);
  margin-top: 7px;
  min-height: 32px;
  border-top: 1px solid color-mix(in srgb, var(--tone) 26%, transparent);
  padding-top: 4px;
  cursor: pointer;
}
.timing-switch span { display: flex; align-items: center; gap: 4px; min-width: 0; }
.timing-switch span svg { width: 13px; height: 13px; flex: 0 0 auto; color: light-dark(#2867af, var(--rest)); }
.timing-switch input {
  appearance: none;
  flex: 0 0 28px;
  width: 28px;
  height: 17px;
  margin: 0;
  border-radius: 100px;
  border: 1px solid var(--line);
  background: var(--line);
  position: relative;
  cursor: pointer;
}
.timing-switch input::after { content: ""; position: absolute; left: 1px; top: 1px; width: 13px; height: 13px; border-radius: 50%; background: #fff; transition: transform 150ms ease; }
.timing-switch input:checked { background: #397ac9; border-color: #397ac9; }
.timing-switch input:checked::after { transform: translateX(11px); }

.timing-summary { margin: 16px 0 14px; border-top: 1px solid var(--line); padding-top: 12px; }
.timing-metrics { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.timing-metrics span { color: var(--muted); font-size: .875rem; }
.timing-metrics output { display: block; font-size: clamp(1.6rem, 5vw, 2.25rem); font-weight: 760; letter-spacing: -.055em; font-variant-numeric: tabular-nums; }
.timing-timeline { display: flex; overflow: hidden; border-radius: 12px; height: 8px; background: var(--line); margin-top: 9px; }
.timing-timeline span { flex-basis: 0; flex-shrink: 1; min-width: 0; box-shadow: inset -1px 0 #10141030; }
.timeline-prepare { background: #d9a441; }
.timeline-work { background: #22b573; }
.timeline-rest { background: #528fde; }
.timeline-round-rest { background: #89b0e3; }
.timeline-cooldown { background: #a38bd4; }
.timing-error { margin-top: 8px; font-size: .875rem; color: var(--warning); }

.timer-exercises { margin: 0 0 14px; border: 1px solid var(--line); border-radius: 12px; padding: 11px; }
.timer-exercises > summary { min-height: 30px; font-weight: 690; }
.timer-exercises > summary span { margin-left: 5px; color: var(--muted); font-size: .8125rem; font-weight: 500; white-space: nowrap; }
.timer-exercises .inventory { margin-bottom: 6px; }
.timer-assignment-list { display: grid; gap: 6px; }
.timer-assignment { grid-template-columns: minmax(54px, auto) minmax(0, 1fr); align-items: center; }
.timer-assignment select { text-overflow: ellipsis; }
.builder .plan-name { margin-top: 13px; }

@media (max-width: 440px) {
  .timing-diagram { --number: 46px; --edge: 6px; --brace: 11px; --block-gap: 6px; }
  .timing-caption { gap: 4px; font-size: .8125rem; }
  .timing-caption svg { width: 15px; height: 15px; }
}
@media (max-width: 365px) {
  .top-inner { flex-wrap: wrap; padding-block: 8px; }
  .top-inner nav { flex: 1 0 100%; }
}
@media (max-width: 350px) {
  .timing-diagram { --number: 42px; --edge: 5px; --brace: 10px; }
  .timing-switch { font-size: .75rem; }
}
@media (prefers-reduced-motion: reduce) {
  .timing-round, .timing-round-rest, .timing-round-count, .timing-brace.round-brace, .timing-switch input::after { transition: none; }
}
