:root {
  color-scheme: dark;
  --bg: #111315;
  --surface: #1b1e22;
  --surface-2: #2a2e34;
  --line: #3a3f47;
  --fg: #f2f2f0;
  --muted: #9aa0a6;
  --accent: #7cc4ff;
  --accent-ink: #06243a;
  --warn: #ffc35a;
  --danger: #ff8a80;
  --thumb: 28px;
  --radius: 14px;
}

* { box-sizing: border-box; }

html {
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 17px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior-y: none;
  -webkit-tap-highlight-color: transparent;
}

[hidden] { display: none !important; }

h1, h2, p { margin: 0; }

.app {
  max-width: 30rem;
  min-height: 100dvh;
  margin: 0 auto;
  padding:
    calc(env(safe-area-inset-top) + 12px)
    max(16px, env(safe-area-inset-right))
    calc(env(safe-area-inset-bottom) + 16px)
    max(16px, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

.label {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.icon {
  width: 24px;
  height: 24px;
  fill: currentColor;
  flex: none;
}

/* Buttons */

button, .btn {
  font: inherit;
  color: inherit;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  padding: 0 14px;
  border: 0;
  border-radius: 12px;
  background: var(--surface-2);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}

.btn:active, .round:active, .chip:active, .track-btn:active { filter: brightness(1.3); }
.btn:disabled, .round:disabled { opacity: 0.35; }

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

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

.btn-big {
  min-height: 60px;
  padding: 0 28px;
  font-size: 1.1rem;
}

.btn-quiet {
  min-height: 40px;
  background: transparent;
  color: var(--muted);
}

.btn-danger {
  background: var(--danger);
  color: #3b0a06;
}

.danger { color: var(--danger); }

/* Header */

.track-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  min-height: 56px;
  padding: 8px 14px;
  border: 0;
  border-radius: var(--radius);
  background: var(--surface);
  text-align: left;
  cursor: pointer;
}

.track-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.track-name {
  overflow: hidden;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.track-btn .icon { color: var(--muted); }

.notice {
  padding: 10px 14px;
  border-radius: 12px;
  background: #3a2a10;
  color: var(--warn);
  font-size: 0.95rem;
}

.hint {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 0.95rem;
}

/* Empty state */

.empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 24px 8px;
  text-align: center;
}

.empty h1 { font-size: 1.75rem; }

/* Player */

main {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.time {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  font-variant-numeric: tabular-nums;
}

.time-now {
  font-size: 2.6rem;
  font-weight: 700;
  line-height: 1.1;
}

.time-total { color: var(--muted); }

.scrub {
  position: relative;
  height: 48px;
  --a: 0;
  --b: 0;
  --p: 0;
}

/* Inset by half a thumb so fractions line up with the centre of the thumb. */
.scrub-track {
  position: absolute;
  top: 50%;
  left: calc(var(--thumb) / 2);
  right: calc(var(--thumb) / 2);
  height: 12px;
  border-radius: 6px;
  background: var(--surface-2);
  overflow: hidden;
  transform: translateY(-50%);
}

.scrub-played {
  position: absolute;
  inset: 0 auto 0 0;
  width: calc(var(--p) * 100%);
  background: #5b626b;
}

.scrub-loop {
  position: absolute;
  top: 0;
  bottom: 0;
  left: calc(var(--a) * 100%);
  width: calc((var(--b) - var(--a)) * 100%);
  min-width: 3px;
  background: var(--accent);
  opacity: 0.75;
}

.scrub-loop.off {
  background: transparent;
  border-inline: 3px solid var(--accent);
  opacity: 0.6;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  margin: 0;
  background: transparent;
  touch-action: pan-y;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 48px;
  background: transparent;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: var(--thumb);
  height: var(--thumb);
  margin-top: calc((48px - var(--thumb)) / 2);
  border: 0;
  border-radius: 50%;
  background: var(--fg);
  box-shadow: 0 1px 4px rgb(0 0 0 / 0.5);
}

input[type="range"]::-moz-range-track {
  height: 48px;
  background: transparent;
}

input[type="range"]::-moz-range-thumb {
  width: var(--thumb);
  height: var(--thumb);
  border: 0;
  border-radius: 50%;
  background: var(--fg);
}

.scrub input[type="range"] {
  position: absolute;
  inset: 0;
  height: 100%;
}

/* Transport */

.transport {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.round {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--surface-2);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}

.play {
  width: 76px;
  height: 76px;
  background: var(--accent);
  color: var(--accent-ink);
}

.play .icon {
  width: 36px;
  height: 36px;
}

.play .icon-pause, .play.is-playing .icon-play { display: none; }
.play.is-playing .icon-pause { display: block; }
.play.is-gap { background: var(--warn); color: #2b1d00; }

.toggle[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-ink);
}

/* Cards */

.card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px;
  border-radius: var(--radius);
  background: var(--surface);
}

.chips {
  display: flex;
  gap: 8px;
  margin: 0 -14px;
  padding: 2px 14px;
  overflow-x: auto;
  scrollbar-width: none;
}

.chips::-webkit-scrollbar { display: none; }

.chip {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  max-width: 12rem;
  min-height: 48px;
  padding: 4px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: transparent;
  line-height: 1.2;
  cursor: pointer;
}

.chip-name {
  max-width: 100%;
  overflow: hidden;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chip-range {
  color: var(--muted);
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
}

.chip[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
}

.chip[aria-pressed="true"] .chip-range { color: inherit; opacity: 0.8; }

.chip-new {
  align-items: center;
  border-style: dashed;
  color: var(--muted);
  font-weight: 600;
}

.edges {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.edge {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.edge-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}

.edge-time {
  font-size: 1.35rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.nudges {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.nudges .btn { padding: 0 4px; }

.loop-actions {
  display: flex;
  justify-content: space-between;
}

.setting {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.setting-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}

.setting-value {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.stepper {
  display: grid;
  grid-template-columns: 52px 1fr 52px;
  align-items: center;
  gap: 10px;
}

.stepper .btn {
  padding: 0;
  font-size: 1.4rem;
}

.stepper input[type="range"] {
  height: 48px;
  background:
    linear-gradient(var(--surface-2), var(--surface-2))
    center / calc(100% - var(--thumb)) 8px no-repeat;
  border-radius: 6px;
}

/* Countdown before a repeat: covers the screen so it reads from across a room. */

.gap-overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: env(safe-area-inset-top) 16px env(safe-area-inset-bottom);
  border: 0;
  background: rgb(17 19 21 / 0.94);
  color: var(--warn);
  cursor: pointer;
}

/* As large as fits: one digit can be much bigger than "10". */
.gap-count {
  font-size: min(110vw, 58dvh);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.two-digit .gap-count { font-size: min(68vw, 58dvh); }

.gap-caption {
  color: var(--fg);
  font-size: 1.6rem;
  font-weight: 600;
}

.gap-stop {
  color: var(--muted);
  font-size: 1.1rem;
}

/* Footer */

/* Equal side columns keep the link centred whatever the status text says. */
.foot {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  margin-top: auto;
  padding-top: 4px;
  color: var(--muted);
  font-size: 0.8rem;
}

.foot-link {
  margin: -10px 0;
  padding: 10px 8px;
  color: inherit;
}

#version { text-align: right; }

/* Dialogs */

.dialog {
  width: min(26rem, calc(100vw - 32px));
  max-height: calc(100dvh - 64px);
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  color: var(--fg);
}

.dialog::backdrop { background: rgb(0 0 0 / 0.6); }

.dialog h2 { font-size: 1.15rem; }

.dialog form, .dialog[open] {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.dialog input[type="text"] {
  width: 100%;
  min-height: 48px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
  color: var(--fg);
  font: inherit;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.track-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  list-style: none;
}

.track-row {
  display: flex;
  align-items: stretch;
  gap: 8px;
}

.track-open {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
  min-height: 56px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.track-open[aria-current="true"] { border-color: var(--accent); }

.track-open .track-name { max-width: 100%; }

.track-meta {
  color: var(--muted);
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}

.track-delete {
  flex: none;
  width: 52px;
  padding: 0;
  color: var(--danger);
}
