/* --- Tokens --- */
:root {
  /* Timer display: pure black scoreboard */
  --bg: #000;
  --fg: #fff;
  --font-heading: 'Oswald', sans-serif;
  --font-timer: 'Chivo Mono', monospace;
  --font-timer-display: 'Archivo ExtraCondensed', 'Oswald', sans-serif;

  /* Builder */
  --font-body: 'Barlow', 'Helvetica Neue', sans-serif;
  --surface-0: #0f0f11;
  --surface-1: #17171a;
  --surface-2: #202024;
  --surface-3: #2a2a2f;
  --line: #2a2a2f;
  --line-strong: #3a3a40;
  --ink: #f2efe8;
  --ink-muted: #a3a098;
  --ink-faint: #6c6a65;
  /* Signal palette, shared by timer and builder: red = stop / last ten, amber = rest background, green = go.
     Deep, muted tones with similar lightness; all keep white text readable (≥ 6:1 contrast). */
  --signal-red: #962820;
  --signal-red-rgb: 150, 40, 32;
  --signal-red-ink: #f2685b; /* red as text on the dark builder */
  --signal-amber: #82590f;
  --signal-amber-rgb: 130, 89, 15;
  --signal-amber-ink: #e3ad4a; /* amber as text on the dark builder */
  --signal-green: #1f6b47;
  --radius: 4px;
  --page-width: 52rem;
  --shadow-dialog: 0 1px 0 rgba(255, 255, 255, 0.04) inset, 0 28px 64px -16px rgba(0, 0, 0, 0.75), 0 8px 20px -10px rgba(0, 0, 0, 0.6);
}

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

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.4;
  background: var(--surface-0);
  color: var(--ink);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

#app {
  min-height: 100vh;
}

button,
input {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

/* --- Views --- */
.view {
  display: none;
  min-height: 100vh;
}

.view.active {
  display: block;
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 40px;
  padding: 0 18px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 0.95rem;
  white-space: nowrap;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.btn-primary {
  background: var(--ink);
  color: var(--surface-0);
}

.btn-primary:hover:not(:disabled) {
  background: #fff;
}

.btn-secondary {
  background: var(--surface-3);
  border-color: var(--line-strong);
}

.btn-secondary:hover {
  background: #35353b;
}

.btn-ghost {
  background: transparent;
  color: var(--ink-muted);
}

.btn-ghost:hover {
  background: var(--surface-2);
  color: var(--ink);
}

.btn-text {
  background: none;
  border: none;
  padding: 6px 10px;
  border-radius: var(--radius);
  font-weight: 500;
  font-size: 0.9rem;
  color: var(--ink-muted);
  transition: color 0.15s ease, background-color 0.15s ease;
}

.btn-text:hover {
  color: var(--ink);
  background: var(--surface-2);
}

.icon-btn {
  width: 32px;
  height: 32px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: var(--ink-muted);
  font-size: 0.95rem;
  line-height: 1;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.icon-btn:hover:not(:disabled) {
  background: var(--surface-3);
  color: var(--ink);
}

.icon-btn:disabled {
  opacity: 0.25;
  cursor: default;
}

.icon-btn-danger:hover:not(:disabled) {
  background: rgba(var(--signal-red-rgb), 0.16);
  color: var(--signal-red-ink);
}

/* --- Builder layout --- */
#builder-view.active {
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 16px;
  width: 100%;
  max-width: var(--page-width);
  margin: 0 auto;
  padding: 22px 16px 14px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-heading);
  text-transform: uppercase;
  user-select: none;
  color: inherit;
  text-decoration: none;
}

.brand-icon {
  display: block;
  width: 32px;
  height: 32px;
}

.brand-mark {
  font-family: var(--font-timer-display);
  font-weight: 900;
  font-size: 1.7rem;
  line-height: 1;
  letter-spacing: 0.01em;
  color: var(--ink);
}

.brand-name {
  font-weight: 500;
  font-size: 1rem;
  letter-spacing: 0.34em;
  color: var(--ink-muted);
}

.app-version {
  align-self: center;
  margin-left: 4px;
  font-family: var(--font-timer);
  font-size: 0.75rem;
  color: var(--ink-faint);
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  margin-left: auto;
  margin-right: -10px;
}

.builder-main {
  flex: 1;
  width: 100%;
  max-width: var(--page-width);
  margin: 0 auto;
  padding: 8px 16px 40px;
}

/* --- Empty state --- */
.empty-state {
  margin: 8px 0 4px;
  padding: 44px 24px 40px;
  text-align: center;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background: repeating-linear-gradient(-45deg, transparent 0 10px, rgba(255, 255, 255, 0.014) 10px 20px);
}

.empty-title {
  margin: 0 0 8px;
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: clamp(1.7rem, 5vw, 2.5rem);
  line-height: 1.05;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.empty-text {
  margin: 0 auto;
  max-width: 38ch;
  color: var(--ink-muted);
  line-height: 1.6;
}

/* --- Playlist --- */
.playlist,
.loop-body {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.row {
  position: relative;
}

.seg-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 56px;
  padding: 6px 6px 6px 6px;
  background: var(--surface-1);
  border: 1px solid var(--line);
  border-left: 3px solid var(--line-strong);
  border-radius: var(--radius);
  transition: background-color 0.15s ease;
}

.seg-row:hover {
  background: var(--surface-2);
}

/* Segments with a coloured background read as that colour in the list too */
.seg-row.bg-red {
  border-left-color: var(--signal-red);
  background: linear-gradient(90deg, rgba(var(--signal-red-rgb), 0.26), rgba(var(--signal-red-rgb), 0.06) 45%, var(--surface-1) 85%);
}

.seg-row.bg-red:hover {
  background: linear-gradient(90deg, rgba(var(--signal-red-rgb), 0.34), rgba(var(--signal-red-rgb), 0.1) 45%, var(--surface-2) 85%);
}

.seg-row.bg-amber {
  border-left-color: var(--signal-amber);
  background: linear-gradient(90deg, rgba(var(--signal-amber-rgb), 0.3), rgba(var(--signal-amber-rgb), 0.07) 45%, var(--surface-1) 85%);
}

.seg-row.bg-amber:hover {
  background: linear-gradient(90deg, rgba(var(--signal-amber-rgb), 0.4), rgba(var(--signal-amber-rgb), 0.12) 45%, var(--surface-2) 85%);
}

.drag-handle {
  flex: none;
  width: 18px;
  padding: 10px 0;
  text-align: center;
  font-size: 0.85rem;
  line-height: 1;
  letter-spacing: -2px;
  color: var(--ink-faint);
  cursor: grab;
  user-select: none;
}

.drag-handle:hover {
  color: var(--ink-muted);
}

.drag-handle:active {
  cursor: grabbing;
}

.step-num {
  flex: none;
  width: 2ch;
  font-family: var(--font-timer);
  font-weight: 500;
  font-size: 0.72rem;
  color: var(--ink-faint);
}

.seg-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  column-gap: 14px;
  row-gap: 4px;
  padding: 4px 2px;
  background: none;
  border: none;
  border-radius: var(--radius);
  text-align: left;
}

.seg-time {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
  min-width: 6.4ch;
  font-family: var(--font-timer);
  font-weight: 500;
  font-size: 1.3rem;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
}

.seg-dir {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.8rem;
  color: var(--ink-muted);
}

.seg-label {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--font-heading);
  font-weight: 500;
  font-size: 1.05rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.seg-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 7px 3px 6px;
  border: 1px solid var(--line-strong);
  border-radius: 3px;
  font-size: 0.66rem;
  font-weight: 600;
  line-height: 1;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  white-space: nowrap;
  color: var(--ink-muted);
}

/* Swatch = the screen colour an option produces, and where in the segment:
   left half = first seconds, right half = last seconds, full = whole segment. */
.chip::before,
.option-name::before,
.segmented-option span[class*="swatch-"]::before {
  content: '';
  flex: none;
  width: 10px;
  height: 7px;
  border-radius: 1px;
  box-shadow: inset 0 0 0 1px var(--swatch-color, var(--ink-faint));
  background: var(--swatch-fill, transparent);
}

.swatch-stop {
  --swatch-color: var(--signal-red);
  --swatch-fill: linear-gradient(90deg, var(--signal-red) 50%, transparent 50%);
}

.swatch-go {
  --swatch-color: var(--signal-green);
  --swatch-fill: linear-gradient(90deg, var(--signal-green) 50%, transparent 50%);
}

/* STANDBY changes the text, not the colour: a neutral end marker */
.swatch-standby {
  --swatch-color: var(--ink-muted);
  --swatch-fill: linear-gradient(90deg, transparent 50%, var(--ink-muted) 50%);
}

.swatch-ten {
  --swatch-color: var(--signal-red);
  --swatch-fill: linear-gradient(90deg, transparent 50%, var(--signal-red) 50%);
}

.swatch-red {
  --swatch-color: var(--signal-red);
  --swatch-fill: var(--signal-red);
}

.swatch-amber {
  --swatch-color: var(--signal-amber);
  --swatch-fill: var(--signal-amber);
}

.swatch-none {
  --swatch-color: var(--ink-faint);
  --swatch-fill: #000;
}

.row-actions {
  flex: none;
  display: flex;
  align-items: center;
  gap: 2px;
  opacity: 0.45;
  transition: opacity 0.15s ease;
}

.seg-row:hover > .row-actions,
.seg-row:focus-within > .row-actions,
.loop-head:hover > .row-actions,
.loop-head:focus-within > .row-actions {
  opacity: 1;
}

/* Drag and drop + arrival feedback */
.row.is-dragging {
  opacity: 0.35;
}

.row.drop-before::before,
.row.drop-after::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--ink);
  border-radius: 2px;
  pointer-events: none;
}

.row.drop-before::before {
  top: -4px;
}

.row.drop-after::after {
  bottom: -4px;
}

.playlist.drop-append,
.loop-body.drop-append {
  outline: 1px dashed var(--ink-muted);
  outline-offset: 4px;
  border-radius: var(--radius);
}

@keyframes row-arrive {
  from {
    box-shadow: 0 0 0 2px var(--ink);
    transform: translateY(-3px);
  }
  to {
    box-shadow: 0 0 0 2px transparent;
    transform: none;
  }
}

.row.is-new {
  animation: row-arrive 0.9s cubic-bezier(0.2, 0.7, 0.2, 1);
}

/* --- Loops --- */
.loop {
  padding: 4px 6px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(var(--surface-1), var(--surface-0) 120px);
}

.loop-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 10px;
  min-height: 48px;
}

.loop-title {
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.16em;
}

.stepper {
  display: inline-flex;
  align-items: center;
  background: var(--surface-0);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
}

.stepper .icon-btn {
  width: 30px;
  height: 30px;
}

.stepper-input {
  width: 3.2ch;
  padding: 0;
  border: none;
  background: transparent;
  text-align: center;
  font-family: var(--font-timer);
  font-weight: 500;
  font-size: 1.05rem;
  appearance: textfield;
  -moz-appearance: textfield;
}

.stepper-input::-webkit-outer-spin-button,
.stepper-input::-webkit-inner-spin-button,
.duration-field input::-webkit-outer-spin-button,
.duration-field input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.loop-rounds {
  font-size: 0.9rem;
  color: var(--ink-muted);
}

.loop-total {
  flex: 1;
  text-align: right;
  white-space: nowrap;
  font-family: var(--font-timer);
  font-size: 0.82rem;
  color: var(--ink-muted);
}

.loop-total strong {
  font-weight: 500;
  color: var(--ink);
}

/* The left rule groups the loop's segments like a bracket */
.loop-body {
  margin: 6px 0 0 9px;
  padding-left: 14px;
  border-left: 2px solid var(--line-strong);
}

.loop-empty {
  padding: 14px 4px;
  font-size: 0.9rem;
  font-style: italic;
  color: var(--ink-faint);
}

/* --- Add bars --- */
.add-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.add-bar-top {
  padding-top: 16px;
}

.add-bar-loop {
  margin: 10px 0 0 25px;
}

.add-bar-label {
  margin-right: 4px;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.add-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding: 0 14px 0 10px;
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 0.92rem;
  white-space: nowrap;
  transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}

.add-btn:hover {
  background: var(--surface-3);
  border-color: var(--ink-faint);
}

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

.add-plus {
  font-family: var(--font-timer);
  font-weight: 500;
  font-size: 1rem;
  color: var(--ink-muted);
}

.add-btn.bg-red {
  border-left: 3px solid var(--signal-red);
}

.add-btn.bg-red .add-plus {
  color: var(--signal-red-ink);
}

.add-btn.bg-amber {
  border-left: 3px solid var(--signal-amber);
}

.add-btn.bg-amber .add-plus {
  color: var(--signal-amber-ink);
}

.add-btn-ghost {
  background: transparent;
  border-style: dashed;
  color: var(--ink-muted);
}

.add-btn-ghost:hover {
  background: var(--surface-1);
  color: var(--ink);
}

.add-bar-top .add-btn {
  height: 44px;
  padding: 0 18px 0 14px;
  font-size: 1rem;
}

.add-bar-loop .add-btn {
  height: 32px;
  font-size: 0.86rem;
}

/* --- Start bar --- */
.start-bar {
  position: sticky;
  bottom: 0;
  z-index: 20;
  background: rgba(15, 15, 17, 0.88);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}

.start-bar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  max-width: var(--page-width);
  margin: 0 auto;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
}

.start-summary {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.1;
}

.start-total {
  font-family: var(--font-timer);
  font-weight: 900;
  font-size: 1.9rem;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.start-meta {
  margin-top: 3px;
  font-size: 0.8rem;
  color: var(--ink-muted);
}

.btn-start {
  height: 52px;
  padding: 0 28px;
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 1.05rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

.btn-start::after {
  content: '▶';
  font-size: 0.7em;
}

/* --- Dialogs --- */
.dialog {
  width: min(34rem, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  padding: 0;
  overflow: auto;
  color: var(--ink);
  background: var(--surface-1);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow-dialog);
}

.dialog-small {
  width: min(23rem, calc(100vw - 32px));
}

.dialog::backdrop {
  background: rgba(6, 6, 8, 0.72);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}

@keyframes dialog-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.985);
  }
}

.dialog[open] {
  animation: dialog-in 0.18s cubic-bezier(0.2, 0.7, 0.2, 1);
}

.dialog-inner {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 22px 22px 18px;
}

.dialog-head {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.dialog-title {
  margin: 0;
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 1.5rem;
  line-height: 1.1;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.dialog-sub {
  margin: 0;
  max-width: 52ch;
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--ink-muted);
}

.dialog-sub:empty {
  display: none;
}

.dialog-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 4px;
}

.btn-push-left {
  margin-right: auto;
}

a.btn {
  text-decoration: none;
}

/* Free web edition: locked import/export */
.lock-icon {
  display: none;
  margin-left: 5px;
  vertical-align: -1px;
}

.is-locked .lock-icon {
  display: inline-block;
}

.upgrade-list {
  margin: 0;
  padding: 0 0 0 1.2em;
  line-height: 1.7;
}

.upgrade-price {
  margin: 16px 0 0;
  font-weight: 600;
}

.upgrade-note {
  margin: 4px 0 0;
  font-size: 0.9rem;
  color: var(--ink-muted);
}

.dialog-small .dialog-head,
.dialog-small .dialog-inner {
  text-align: center;
}

.dialog-small .dialog-actions .btn {
  flex: 1;
}

/* --- Form fields --- */
.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: none;
}

.field-label {
  padding: 0;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

legend.field-label {
  margin-bottom: 8px;
}

.text-input {
  height: 44px;
  padding: 0 12px;
  background: var(--surface-0);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  font-size: 1rem;
}

.text-input::placeholder {
  color: var(--ink-faint);
}

.field-error {
  margin: 0;
  font-size: 0.85rem;
  color: var(--signal-red-ink);
}

.duration-input {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.dialog-small .duration-input {
  justify-content: center;
}

.duration-field {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.duration-field input {
  width: 2.6em;
  padding: 6px 4px;
  background: var(--surface-0);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  text-align: center;
  font-family: var(--font-timer);
  font-weight: 900;
  font-size: 2.6rem;
  line-height: 1.1;
  appearance: textfield;
  -moz-appearance: textfield;
}

.duration-unit {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.duration-colon {
  padding-top: 10px;
  font-family: var(--font-timer);
  font-weight: 900;
  font-size: 2.6rem;
  line-height: 1;
  color: var(--ink-faint);
}

.duration-input-compact .duration-field input,
.duration-input-compact .duration-colon {
  font-size: 1.8rem;
}

.duration-input-compact .duration-colon {
  padding-top: 8px;
}

.template-summary {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.summary-dir {
  margin-right: 4px;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--ink-muted);
}

/* Down / Up switch */
.segmented {
  display: inline-flex;
  align-self: flex-start;
  padding: 3px;
  background: var(--surface-0);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
}

.segmented-option {
  position: relative;
}

.segmented-option input {
  position: absolute;
  inset: 0;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.segmented-option span {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 16px;
  border-radius: 3px;
  font-weight: 600;
  font-size: 0.92rem;
  color: var(--ink-muted);
  transition: background-color 0.15s ease, color 0.15s ease;
}

.segmented-option input:checked + span {
  background: var(--ink);
  color: var(--surface-0);
}

.segmented-option input:focus-visible + span {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

/* Option toggles */
.option-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(10.5rem, 1fr));
  gap: 6px;
}

.option {
  display: grid;
  grid-template-columns: 18px 1fr;
  align-items: center;
  column-gap: 10px;
  row-gap: 1px;
  padding: 10px 12px;
  background: var(--surface-0);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.option:hover {
  border-color: var(--ink-faint);
}

.option:has(input:checked) {
  background: var(--surface-2);
  border-color: var(--ink-muted);
}

.option input {
  grid-row: span 2;
  display: grid;
  place-content: center;
  width: 18px;
  height: 18px;
  margin: 0;
  border: 1.5px solid var(--ink-faint);
  border-radius: 3px;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
  transition: background-color 0.12s ease, border-color 0.12s ease;
}

.option input::after {
  content: '';
  width: 9px;
  height: 5px;
  border-left: 2px solid var(--surface-0);
  border-bottom: 2px solid var(--surface-0);
  transform: translate(0, -1px) rotate(-45deg);
  opacity: 0;
}

.option input:checked {
  background: var(--ink);
  border-color: var(--ink);
}

.option input:checked::after {
  opacity: 1;
}

.option-name {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 0.92rem;
}

.option-desc {
  font-size: 0.78rem;
  color: var(--ink-muted);
}

/* --- Template manager --- */
.templates-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.template-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 12px;
  padding: 8px 8px 8px 12px;
  background: var(--surface-0);
  border: 1px solid var(--line);
  border-left: 3px solid var(--line-strong);
  border-radius: var(--radius);
}

.template-row.bg-red {
  border-left-color: var(--signal-red);
}

.template-row.bg-amber {
  border-left-color: var(--signal-amber);
}

.template-row .seg-time {
  font-size: 1.05rem;
}

.template-row .row-actions {
  margin-left: auto;
  opacity: 1;
}

.templates-empty {
  padding: 12px 0;
  font-style: italic;
  color: var(--ink-faint);
}

/* --- Toast --- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + env(safe-area-inset-bottom));
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 16px;
  width: max-content;
  max-width: calc(100vw - 32px);
  padding: 8px 8px 8px 16px;
  background: var(--ink);
  color: var(--surface-0);
  border-radius: var(--radius);
  font-weight: 500;
  font-size: 0.95rem;
  box-shadow: 0 14px 34px -10px rgba(0, 0, 0, 0.7);
  opacity: 0;
  visibility: hidden;
  transform: translate(-50%, 12px);
  transition: opacity 0.2s ease, transform 0.2s ease, visibility 0s linear 0.2s;
}

.toast.is-visible {
  opacity: 1;
  visibility: visible;
  transform: translate(-50%, 0);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast-undo {
  padding: 7px 10px;
  background: transparent;
  border: none;
  border-radius: 3px;
  font-weight: 700;
  font-size: 0.8rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--surface-0);
}

.toast-undo:hover {
  background: rgba(0, 0, 0, 0.08);
}

.toast-undo:focus-visible {
  outline-color: var(--surface-0);
}

/* --- Touch and small screens --- */
@media (hover: none) {
  .row-actions {
    opacity: 1;
  }

  .drag-handle {
    display: none;
  }
}

@media (max-width: 600px) {
  .topbar {
    padding-top: 16px;
  }

  .seg-row {
    gap: 6px;
    padding-left: 8px;
  }

  .seg-main {
    column-gap: 10px;
  }

  .icon-btn {
    width: 30px;
  }

  .loop-body {
    margin-left: 2px;
    padding-left: 8px;
  }

  .add-bar-loop {
    margin-left: 12px;
  }

  .start-total {
    font-size: 1.55rem;
  }

  .btn-start {
    padding: 0 20px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .row.is-new,
  .dialog[open] {
    animation: none;
  }
}

/* --- Timer view --- */
/* Only .active shows the view; an id-level display here would override .view { display: none } */
#timer-view {
  /* One size for everything in the display: digits, STOP, GO! and STANDBY.
     Sized from the width so the widest word fits: STANDBY is ~3.55 em wide in the display font,
     and the room is the container width (90vw minus 2rem padding on each side). */
  --display-size: min(calc((90vw - 4rem) / 3.7), 20rem, 45vh);
  align-items: center;
  justify-content: center;
  background: var(--bg);
  color: var(--fg);
  transition: background-color 0.2s ease, color 0.2s ease;
}

#timer-view.active {
  display: flex;
}

#timer-container {
  position: relative;
  text-align: center;
  padding: 2rem;
  width: 100%;
  max-width: 90vw;
}

/* Signal screens: the state classes live on #timer-container, the colour fills the whole view.
   Text stays white on every screen. STANDBY only swaps the text and keeps the current colour. */
/* A segment's own background has the lowest weight: last ten, STOP, STANDBY and GO! all win over it */
#timer-view.segment-amber {
  background: var(--signal-amber);
}

#timer-view.segment-red,
#timer-view:has(#timer-container.warning-zone),
#timer-view:has(#timer-container.overlay-stop) {
  background: var(--signal-red);
}

#timer-view:has(#timer-container.overlay-go) {
  background: var(--signal-green);
}

#timer-container .segment-label,
#timer-container #timer-segment-label {
  position: fixed;
  top: 0;
  right: 0;
  padding: 1.25rem 1.5rem;
  font-size: clamp(1rem, 4vw, 1.5rem);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin: 0;
  opacity: 0.9;
  z-index: 10;
}

.timer-display {
  font-family: var(--font-timer-display);
  font-weight: 900;
  font-size: var(--display-size);
  line-height: 1;
  margin: 0;
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
  min-height: 0.3em;
}

/* Buttons are pinned to the bottom so they never move when the display changes */
.timer-actions-wrapper {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  padding: 1rem 1rem calc(1rem + env(safe-area-inset-bottom));
  transition: opacity 0.3s ease;
}

.timer-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.75rem;
}

/* Fullscreen: controls and cursor fade out after a few idle seconds (set from app.js) */
#timer-view.controls-hidden {
  cursor: none;
}

#timer-view.controls-hidden .timer-actions-wrapper {
  opacity: 0;
  pointer-events: none;
}

/* Translucent so the buttons sit well on black, red, amber and green screens */
.btn-timer {
  padding: 0.6rem 1.2rem;
  font-size: 1rem;
  background: rgba(16, 16, 18, 0.72);
  color: var(--fg);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: var(--radius);
  cursor: pointer;
}

.btn-timer:hover {
  background: rgba(16, 16, 18, 0.9);
}

.btn:disabled,
.btn:disabled:hover {
  opacity: 0.4;
  cursor: default;
}

/* Fullscreen */
#timer-view.fullscreen #timer-container {
  max-width: 100%;
}

#timer-view.fullscreen {
  --display-size: min(calc((100vw - 4rem) / 3.7), 40vh);
}

body.fullscreen-supported:-webkit-full-screen #timer-view,
body.fullscreen-supported:-moz-full-screen #timer-view,
body.fullscreen-supported:fullscreen #timer-view {
  width: 100vw;
  height: 100vh;
}

#timer-view .timer-display {
  user-select: none;
}

