:root {
  color-scheme: light;
  --bg: #f4f7f5;
  --surface: #ffffff;
  --surface-strong: #eef3ef;
  --ink: #17211c;
  --muted: #66746b;
  --line: #d8e0da;
  --accent: #d7462f;
  --accent-strong: #b42f20;
  --teal: #17847d;
  --amber: #e2a52a;
  --green: #3c8f5a;
  --shadow: 0 18px 50px rgba(24, 35, 28, 0.12);
  --radius: 8px;
  --progress: 0deg;
  --phase: var(--accent);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  display: flex;
  min-height: 100svh;
  align-items: flex-start;
  justify-content: center;
  margin: 0;
  background:
    radial-gradient(circle at top left, rgba(23, 132, 125, 0.14), transparent 38rem),
    linear-gradient(180deg, #fbfcfb 0%, var(--bg) 34%, #edf2ee 100%);
  color: var(--ink);
}

button,
input {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  border: 0;
}

button:focus-visible,
a:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(23, 132, 125, 0.22);
  outline-offset: 2px;
}

svg {
  display: block;
  width: 1.15rem;
  height: 1.15rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.app-shell {
  width: min(100%, 36rem);
  max-width: calc(100vw - 1rem);
  min-height: 100svh;
  margin: 0;
  padding: max(0.75rem, env(safe-area-inset-top)) 1rem max(1.25rem, env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.65rem;
}

.brand {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 0.55rem;
}

.brand-mark {
  width: 2.12rem;
  height: 2.12rem;
  flex: 0 0 auto;
  border-radius: 8px;
  box-shadow: 0 7px 18px rgba(183, 47, 32, 0.16);
}

.brand p,
.brand h1 {
  margin: 0;
}

.brand p {
  color: var(--muted);
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.brand h1 {
  color: var(--ink);
  font-size: 1.16rem;
  line-height: 1.05;
}

.icon-button {
  display: grid;
  width: 2.25rem;
  height: 2.25rem;
  place-items: center;
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 7px 20px rgba(23, 33, 28, 0.08);
}

.timer-stage {
  position: relative;
  overflow: hidden;
  padding: 1rem;
  border: 1px solid rgba(216, 224, 218, 0.9);
  border-radius: var(--radius);
  background:
    linear-gradient(160deg, rgba(255, 255, 255, 0.92), rgba(238, 243, 239, 0.82)),
    linear-gradient(135deg, rgba(215, 70, 47, 0.08), rgba(23, 132, 125, 0.08));
  box-shadow: var(--shadow);
}

.timer-stage::before {
  position: absolute;
  top: -5.4rem;
  right: -4.2rem;
  width: 12rem;
  height: 12rem;
  border: 1.15rem solid rgba(23, 132, 125, 0.08);
  border-radius: 50%;
  content: "";
}

.timer-ring {
  position: relative;
  display: grid;
  width: min(74vw, 18rem);
  aspect-ratio: 1;
  margin: 0.2rem auto 0.85rem;
  place-items: center;
  border-radius: 50%;
  background:
    conic-gradient(var(--phase) var(--progress), rgba(216, 224, 218, 0.82) 0),
    radial-gradient(circle, rgba(255, 255, 255, 0.86), rgba(238, 243, 239, 0.95));
  transition: background 160ms linear;
}

.timer-ring::before {
  position: absolute;
  inset: 0.7rem;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: inset 0 0 0 1px rgba(216, 224, 218, 0.9);
  content: "";
}

.ring-core {
  position: relative;
  display: grid;
  min-width: 0;
  width: 73%;
  justify-items: center;
  gap: 0.25rem;
  text-align: center;
}

.phase-label {
  min-height: 1.45rem;
  color: var(--phase);
  font-size: 0.9rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.time-left {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  font-size: clamp(3.45rem, 16vw, 5.25rem);
  line-height: 0.94;
}

.rep-label {
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 700;
}

.hand-cue {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.45rem;
  margin-bottom: 0.8rem;
}

.hand-cue span {
  display: grid;
  min-width: 0;
  min-height: 2.35rem;
  padding: 0.45rem 0.4rem;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.75);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
  text-align: center;
}

.hand-cue svg {
  width: 1.55rem;
  height: 1.55rem;
  stroke-width: 2;
}

.hand-icon-right {
  transform: scaleX(-1);
}

.hand-cue span.is-active {
  border-color: color-mix(in srgb, var(--phase) 46%, white);
  background: color-mix(in srgb, var(--phase) 14%, white);
  color: var(--phase);
}

.progress-line {
  height: 0.45rem;
  margin-bottom: 0.75rem;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(216, 224, 218, 0.95);
}

.progress-line span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--teal), var(--accent), var(--amber));
  transition: width 160ms linear;
}

.controls,
.action-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.5rem;
}

.control-button,
.action-button,
.text-button,
.preset-row button {
  cursor: pointer;
}

.control-button,
.action-button {
  display: flex;
  min-width: 0;
  min-height: 3rem;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font-size: 0.9rem;
  font-weight: 800;
  text-decoration: none;
  box-shadow: 0 9px 24px rgba(23, 33, 28, 0.08);
}

.control-button.primary {
  border-color: transparent;
  background: var(--accent);
  color: white;
}

.control-button:disabled,
.action-button[aria-disabled="true"] {
  cursor: not-allowed;
  opacity: 0.42;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.5rem;
  margin: 0.8rem 0;
}

.summary-grid div {
  min-width: 0;
  padding: 0.74rem 0.7rem;
  border: 1px solid rgba(216, 224, 218, 0.88);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.78);
}

.summary-grid span {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.summary-grid strong {
  display: block;
  margin-top: 0.16rem;
  color: var(--ink);
  font-size: 1.05rem;
  font-variant-numeric: tabular-nums;
}

.settings {
  margin-top: 0.8rem;
  padding: 1rem;
  border: 1px solid rgba(216, 224, 218, 0.9);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.84);
  box-shadow: 0 12px 32px rgba(23, 33, 28, 0.07);
}

.settings.compact {
  padding-bottom: 0.8rem;
}

.completion-panel {
  margin-top: 0.8rem;
  padding: 1rem;
  border: 1px solid color-mix(in srgb, var(--green) 34%, var(--line));
  border-radius: var(--radius);
  background:
    linear-gradient(160deg, rgba(255, 255, 255, 0.92), rgba(238, 243, 239, 0.84)),
    linear-gradient(135deg, rgba(60, 143, 90, 0.12), rgba(23, 132, 125, 0.08));
  box-shadow: 0 12px 32px rgba(23, 33, 28, 0.07);
}

.about-panel {
  margin-top: 0.8rem;
  padding: 1rem;
  border: 1px solid color-mix(in srgb, var(--amber) 42%, var(--line));
  border-radius: var(--radius);
  background:
    linear-gradient(160deg, rgba(255, 255, 255, 0.9), rgba(251, 246, 231, 0.86)),
    linear-gradient(135deg, rgba(226, 165, 42, 0.12), rgba(23, 132, 125, 0.06));
  box-shadow: 0 12px 32px rgba(23, 33, 28, 0.06);
}

.about-panel p {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.48;
}

.about-panel strong,
.about-signoff {
  color: var(--ink);
}

.about-signoff {
  margin-top: 0.7rem;
  font-weight: 800;
}

.about-link {
  display: inline-flex;
  margin-top: 0.7rem;
  color: var(--teal);
  font-size: 0.92rem;
  font-weight: 800;
  text-decoration-thickness: 0.08em;
  text-underline-offset: 0.18em;
}

.completion-panel[hidden],
.share-fallback[hidden] {
  display: none;
}

.compact-summary {
  margin: 0 0 0.8rem;
}

.completion-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.5rem;
}

.celebration {
  position: fixed;
  inset: 0;
  z-index: 4;
  display: grid;
  place-items: center;
  overflow: hidden;
  padding: 1rem;
  background: rgba(23, 33, 28, 0.06);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 180ms ease, visibility 0s linear 180ms;
}

.celebration.is-visible {
  opacity: 1;
  visibility: visible;
  transition-delay: 0s;
}

.celebration canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.celebration-message {
  position: relative;
  display: grid;
  width: min(20rem, 100%);
  gap: 0.18rem;
  justify-items: center;
  padding: 0.9rem 1rem 0.95rem;
  border: 1px solid color-mix(in srgb, var(--green) 42%, var(--line));
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 20px 55px rgba(23, 33, 28, 0.18);
  text-align: center;
  transform: translateY(0.55rem) scale(0.96);
  opacity: 0;
  transition: transform 220ms ease, opacity 180ms ease;
}

.celebration.is-visible .celebration-message {
  transform: translateY(0) scale(1);
  opacity: 1;
}

.celebration-kicker,
.celebration-subtitle {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.celebration-title {
  color: var(--green);
  font-size: clamp(1.65rem, 9vw, 2.45rem);
  line-height: 1;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.75rem;
}

.section-heading h2 {
  margin: 0;
  font-size: 1rem;
}

.workout-heading {
  align-items: flex-start;
}

.workout-summary {
  display: flex;
  min-width: 0;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.28rem 0.55rem;
  color: var(--muted);
  font-size: 0.66rem;
  font-weight: 800;
  line-height: 1.2;
  text-align: right;
  text-transform: uppercase;
}

.workout-summary span {
  display: inline-flex;
  align-items: baseline;
  gap: 0.22rem;
  white-space: nowrap;
}

.workout-summary strong {
  color: var(--ink);
  font-size: 0.76rem;
  font-variant-numeric: tabular-nums;
}

.text-button {
  padding: 0.45rem 0.55rem;
  border-radius: var(--radius);
  background: var(--surface-strong);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.preset-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.55rem;
  width: min(100%, 23rem);
  margin: 0 auto 0.72rem;
}

.preset-row button {
  min-width: 0;
  min-height: 2rem;
  padding: 0.36rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) - 2px);
  background: var(--surface-strong);
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
}

.preset-row button.is-active {
  border-color: color-mix(in srgb, var(--teal) 38%, var(--line));
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 5px 12px rgba(23, 33, 28, 0.07);
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0;
}

.field {
  display: grid;
  min-width: 0;
}

.field-label {
  display: block;
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 800;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

.slider-field output {
  min-width: 3.35rem;
  padding: 0.16rem 0.35rem;
  border: 1px solid rgba(216, 224, 218, 0.76);
  border-radius: calc(var(--radius) - 2px);
  background: rgba(255, 255, 255, 0.68);
  color: var(--ink);
  font-size: 0.78rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  text-align: center;
  text-transform: none;
}

.field input[type="number"] {
  width: 100%;
  min-height: 2.85rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfcfb;
  color: var(--ink);
  font-size: 1.1rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  outline: none;
  padding: 0 0.72rem;
}

.field input[type="number"]:focus {
  border-color: color-mix(in srgb, var(--teal) 58%, white);
  box-shadow: 0 0 0 3px rgba(23, 132, 125, 0.13);
}

.slider-field {
  grid-template-columns: minmax(4.85rem, 0.66fr) minmax(5rem, 1fr) auto;
  align-items: center;
  gap: 0.6rem;
  padding: 0.31rem 0;
  border-bottom: 1px solid rgba(216, 224, 218, 0.82);
}

.slider-field:last-child {
  border-bottom: 0;
}

.slider-field input[type="range"] {
  width: 100%;
  min-width: 0;
  min-height: 1.35rem;
  margin: 0;
  accent-color: var(--teal);
}

.slider-field input[type="range"]:focus-visible {
  outline: 3px solid rgba(23, 132, 125, 0.18);
  outline-offset: 2px;
}

.settings-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.5rem;
  margin-top: 0.9rem;
}

.toggle-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.45rem;
  margin-bottom: 0.75rem;
}

.toggle {
  display: flex;
  min-width: 0;
  min-height: 2rem;
  align-items: center;
  justify-content: center;
  gap: 0.42rem;
  color: var(--ink);
  font-size: 0.84rem;
  font-weight: 800;
  line-height: 1;
  white-space: nowrap;
}

.toggle input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.track {
  position: relative;
  width: 2.1rem;
  height: 1.2rem;
  flex: 0 0 auto;
  border-radius: 999px;
  background: #d7dfd9;
  transition: background 150ms ease;
}

.track::after {
  position: absolute;
  top: 0.15rem;
  left: 0.16rem;
  width: 0.9rem;
  height: 0.9rem;
  border-radius: 50%;
  background: white;
  box-shadow: 0 2px 8px rgba(23, 33, 28, 0.18);
  content: "";
  transition: transform 150ms ease;
}

.toggle input:checked + .track {
  background: var(--teal);
}

.toggle input:checked + .track::after {
  transform: translateX(0.88rem);
}

.toggle input:focus-visible + .track {
  outline: 3px solid rgba(23, 132, 125, 0.18);
  outline-offset: 2px;
}

.action-row {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.share-fallback {
  display: grid;
  gap: 0.45rem;
  margin-top: 0.85rem;
}

.share-fallback label {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
  text-transform: uppercase;
}

.share-fallback div {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.45rem;
}

.share-fallback input {
  min-width: 0;
  min-height: 2.75rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfcfb;
  color: var(--ink);
  padding: 0 0.72rem;
}

.toast {
  position: fixed;
  right: 1rem;
  bottom: max(1rem, env(safe-area-inset-bottom));
  left: 1rem;
  z-index: 5;
  max-width: 29rem;
  min-height: 2.75rem;
  margin: 0 auto;
  padding: 0.8rem 1rem;
  border-radius: var(--radius);
  background: #17211c;
  color: white;
  font-weight: 800;
  text-align: center;
  transform: translateY(calc(100% + 2rem));
  opacity: 0;
  transition: transform 180ms ease, opacity 180ms ease;
  pointer-events: none;
}

.toast.is-visible {
  transform: translateY(0);
  opacity: 1;
}

body.is-running .timer-stage {
  border-color: color-mix(in srgb, var(--phase) 34%, var(--line));
}

body.is-paused .timer-ring {
  filter: saturate(0.65);
}

@media (min-width: 42rem) {
  .app-shell {
    padding-top: 1.25rem;
    padding-bottom: 2rem;
  }

  .timer-stage,
  .completion-panel,
  .about-panel,
  .settings,
  .summary-grid div {
    backdrop-filter: blur(10px);
  }
}

@media (max-height: 640px) {
  .app-shell {
    padding-top: max(0.55rem, env(safe-area-inset-top));
    padding-bottom: max(0.85rem, env(safe-area-inset-bottom));
  }

  .topbar {
    margin-bottom: 0.45rem;
  }

  .timer-stage {
    padding: 0.75rem;
  }

  .timer-stage::before {
    top: -6.4rem;
    right: -5.1rem;
  }

  .timer-ring {
    width: min(66vw, 15.75rem);
    margin: 0.05rem auto 0.65rem;
  }

  .timer-ring::before {
    inset: 0.62rem;
  }

  .ring-core {
    gap: 0.12rem;
  }

  .phase-label {
    min-height: 1.18rem;
    font-size: 0.8rem;
  }

  .time-left {
    font-size: clamp(3.1rem, 13.5vw, 4.45rem);
  }

  .rep-label {
    font-size: 0.84rem;
  }

  .hand-cue {
    gap: 0.38rem;
    margin-bottom: 0.55rem;
  }

  .hand-cue span {
    padding: 0.5rem 0.35rem;
  }

  .progress-line {
    height: 0.36rem;
    margin-bottom: 0.6rem;
  }

  .control-button,
  .action-button {
    min-height: 2.65rem;
  }
}

@media (max-width: 22rem) {
  .controls,
  .summary-grid {
    grid-template-columns: 1fr;
  }

  .preset-row {
    gap: 0.42rem;
  }

  .preset-row button {
    padding-inline: 0.32rem;
    font-size: 0.7rem;
  }

  .toggle-grid {
    gap: 0.25rem;
  }

  .toggle {
    gap: 0.28rem;
    font-size: 0.68rem;
  }

  .track {
    width: 1.75rem;
    height: 1rem;
  }

  .track::after {
    top: 0.13rem;
    left: 0.14rem;
    width: 0.74rem;
    height: 0.74rem;
  }

  .toggle input:checked + .track::after {
    transform: translateX(0.73rem);
  }

  .control-button {
    min-height: 2.8rem;
  }

  .field-grid {
    grid-template-columns: 1fr;
  }

  .completion-actions,
  .settings-actions,
  .share-fallback div {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
