:root {
  color-scheme: light dark;
  --bg: #0f1218;
  --surface: #171b24;
  --text: #e8ecf4;
  --muted: #9aa4b8;
  --border: #2a3140;
  --phase-in: #4ade80;
  --phase-out: #60a5fa;
  --phase-hold: #c084fc;
  --accent: #f59e0b;
  --focus: #fbbf24;
  --danger: #f87171;

  font-family:
    ui-sans-serif,
    system-ui,
    -apple-system,
    Segoe UI,
    Roboto,
    Ubuntu,
    Cantarell,
    Noto Sans,
    sans-serif;
  line-height: 1.5;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6fa;
    --surface: #ffffff;
    --text: #141822;
    --muted: #5c677a;
    --border: #d6dbe8;
    --accent: #b45309;
    --danger: #b91c1c;
    --phase-in: #16a34a;
    --phase-out: #2563eb;
    --phase-hold: #7c3aed;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

.app {
  max-width: 52rem;
  margin: 0 auto;
  padding: 1.25rem clamp(1rem, 4vw, 2rem) 3rem;
}

.header h1 {
  margin: 0 0 0.35rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  font-size: clamp(1.75rem, 4vw, 2.25rem);
}

.tagline {
  margin: 0;
  color: var(--muted);
  max-width: 36rem;
}

.main {
  display: grid;
  gap: 2rem;
  margin-top: 1.75rem;
}

@media (min-width: 900px) {
  .main {
    grid-template-columns: minmax(0, 280px) 1fr;
    align-items: start;
    gap: 2.5rem;
  }

  .controls {
    order: 2;
  }

  .viz {
    position: sticky;
    top: 1rem;
  }
}

.viz {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.25rem 1rem;
}

.viz-ring-wrap {
  position: relative;
  width: 100%;
  max-width: 240px;
  margin-inline: auto;
  aspect-ratio: 1;
}

.viz-svg {
  display: block;
  width: 100%;
  height: 100%;
}

.viz-center-readout {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  pointer-events: none;
}

.viz-center-readout-inner {
  width: min(52%, 100%);
  max-width: 52%;
  min-width: 0;
  padding-inline: 2px;
  box-sizing: border-box;
}

.viz-track-bg {
  stroke: var(--border);
  stroke-width: 12;
}

.viz-phase-in {
  stroke: var(--phase-in);
}

.viz-phase-out {
  stroke: var(--phase-out);
}

.viz-phase-hold {
  stroke: var(--phase-hold);
}

.viz-segments path {
  fill: none;
  stroke-linecap: round;
  stroke-width: 12;
}

.viz-dot {
  fill: var(--accent);
  stroke: color-mix(in srgb, var(--surface), transparent 20%);
  stroke-width: 2;
}

.viz-readout-meta {
  margin-top: 1rem;
  text-align: center;
}

.viz-center-readout .phase-segment-caption {
  margin: 0 0 0.2rem;
  width: 100%;
  min-width: 0;
  font-size: clamp(0.72rem, 2.9vmin, 0.875rem);
  font-weight: 500;
  line-height: 1.3;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.viz-center-readout .phase-segment-caption:empty {
  display: none;
}

.viz-center-readout .phase-label {
  margin: 0;
  font-size: clamp(0.95rem, 3.8vmin, 1.125rem);
  font-weight: 600;
  line-height: 1.25;
  color: var(--text);
}

.viz-center-readout .phase-countdown {
  margin: 0.25rem 0 0;
  color: var(--muted);
  min-height: 1.35em;
  font-size: clamp(0.8rem, 3vmin, 0.9375rem);
  line-height: 1.35;
  font-variant-numeric: tabular-nums;
}

.cycle-total {
  margin: 0;
  color: var(--muted);
  font-size: 0.9375rem;
}

.controls {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1rem 1.1rem;
}

.transport {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.segments-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.segments-head h2 {
  margin: 0;
  font-size: 1rem;
}

.btn {
  font: inherit;
  cursor: pointer;
  padding: 0.5rem 0.85rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  touch-action: manipulation;
  transition:
    transform 160ms ease-out,
    border-color 160ms ease-out,
    background-color 160ms ease-out,
    filter 160ms ease-out;
}

.btn:disabled,
.icon-btn:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.btn:not(:disabled):active,
.icon-btn:not(:disabled):active {
  transform: scale(0.98);
}

.btn:hover:not(:disabled) {
  filter: brightness(1.06);
}

.btn:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.btn-copy-link {
  /* Steady width across Copy link / Copying… / Copied! */
  min-width: 12ch;
}

.btn.primary {
  background: linear-gradient(
    165deg,
    color-mix(in srgb, var(--phase-out), transparent 82%),
    var(--surface)
  );
  border-color: color-mix(in srgb, var(--phase-out), var(--border) 60%);
}

.btn.small {
  padding: 0.35rem 0.65rem;
  font-size: 0.875rem;
}

.segment-list {
  list-style: none;
  margin: 0.85rem 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.segment-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5rem;
  align-items: center;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
}

@media (max-width: 479px) {
  .segment-row {
    grid-template-columns: 1fr;
  }

  .segment-row-moves {
    justify-content: flex-start;
  }
}

.segment-row-fields {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.segment-row-fields label span {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.segment-row-fields label {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.segment-row-fields label.segment-label-wrap {
  flex-basis: 100%;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.25rem;
}

.segment-kind,
.segment-duration {
  font: inherit;
  padding: 0.35rem 0.55rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  min-width: 8rem;
}

.segment-duration {
  width: 5rem;
}

.segment-label {
  box-sizing: border-box;
  font: inherit;
  line-height: 1.35;
  padding: 0.35rem 0.55rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  min-width: 0;
  flex: 1 1 10rem;
  max-width: 100%;
  max-height: calc(2 * 0.35rem + 1.35em);
}

.segment-row-moves {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  justify-self: end;
}

.icon-btn {
  font: inherit;
  cursor: pointer;
  padding: 0.35rem 0.55rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  touch-action: manipulation;
  transition:
    transform 160ms ease-out,
    border-color 160ms ease-out,
    background-color 160ms ease-out,
    filter 160ms ease-out;
}

.icon-btn:hover:not(:disabled) {
  filter: brightness(1.06);
}

.icon-btn:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.icon-btn.rm {
  border-color: color-mix(in srgb, var(--danger), var(--border));
  color: var(--danger);
}

/* Cycle starts at top; dot moves clockwise — same convention as arcs in JS. */
@media (prefers-reduced-motion: reduce) {
  .viz-dot {
    visibility: hidden;
  }

  .btn,
  .icon-btn {
    transition-duration: 0.01ms;
  }

  .btn:not(:disabled):active,
  .icon-btn:not(:disabled):active {
    transform: none;
  }

  button {
    scroll-behavior: auto;
  }
}
