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

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

body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

[hidden] {
  display: none !important;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

button {
  font: inherit;
  color: inherit;
}

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

::selection {
  background: var(--ink);
  color: var(--on-ink);
}

kbd {
  padding: 0.1rem 0.45rem;
  border-radius: 6px;
  background: var(--fill);
  font: inherit;
  font-weight: 600;
  color: var(--ink-2);
}

.sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

/* ---------- word trail (behind everything) ---------- */

.trail {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

.trail-word {
  position: absolute;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--ink-2);
  white-space: nowrap;
}

/* ---------- layout: mobile first, stacked ---------- */

.layout {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  min-height: 100dvh;
  padding: var(--pad);
  --clock: calc((100vw - 2 * var(--pad)) / var(--clock-ratio));
}

/* Desktop: one screen, no scrolling.
   ┌ to-do (full height) ┬ video ─────┐
   │                     │ clock      │
   │                     │ status     │
   └─────────────────────┴ lengths · start ┘ */
@media (min-width: 900px) and (min-height: 560px) {
  .layout {
    /* Right column: as wide as fits video (0.5625w) + clock (0.3w) + ~7rem of controls */
    --side-w: min(48vw, calc((100dvh - 2 * var(--pad) - 3 * var(--gap) - 13.5rem - var(--brand-h)) / 0.87));
    --clock: calc(var(--side-w) / var(--clock-ratio));

    display: grid;
    grid-template-columns: minmax(0, 1fr) var(--side-w);
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas:
      'brand brand'
      'todo  side';
    column-gap: calc(var(--gap) * 1.5);
    height: 100dvh;
    min-height: 0;
  }

  .brand {
    grid-area: brand;
  }

  .todo {
    grid-area: todo;
  }

  .side {
    grid-area: side;
    justify-content: center;
    min-height: 0;
  }

  /* The player takes the spare height (bigger record) within limits, so the gap to the
     clock stays the same on every screen; anything left over is split above and below. */
  .screen {
    flex: 1 1 auto;
    aspect-ratio: auto;
    min-height: calc(var(--side-w) * 0.42);
    max-height: calc(var(--side-w) * 0.62);
  }
}

.side {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

/* ---------- brand ---------- */

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

.brand-title {
  margin: 0;
  line-height: 0;
}

/* 中 / EN switch */
.lang {
  display: inline-flex;
  padding: 3px 3px 5px;
  border-radius: var(--radius-pill);
  background: var(--fill);
  box-shadow: inset 0 2px 3px rgb(0 0 0 / 0.07);
}

.lang button {
  min-width: 2.9rem;
  height: 2.1rem;
  padding: 0 0.8rem;
  border: 0;
  border-radius: var(--radius-pill);
  background: none;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--ink-2);
  cursor: pointer;
  transition:
    transform 110ms var(--ease-out-expo),
    background var(--duration-fast),
    color var(--duration-fast);
}

.lang button:hover {
  color: var(--ink);
}

.lang button[aria-pressed='true'] {
  background: var(--key-dark);
  color: var(--on-ink);
  box-shadow: 0 2px 0 var(--key-dark-edge);
  transform: translateY(-1px);
}

.brand-logo {
  width: auto;
  height: var(--brand-h);
}

/* ---------- to-do card ---------- */

.todo {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 1.75rem 2rem 1.5rem;
  border: 1px solid rgb(0 0 0 / 0.05);
  border-radius: var(--radius-card);
  background: var(--surface);
  box-shadow:
    0 1px 2px rgb(0 0 0 / 0.04),
    0 8px 20px -8px rgb(0 0 0 / 0.1),
    0 28px 56px -28px rgb(0 0 0 / 0.18);
}

.todo-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
}

.todo-title {
  margin: 0;
  font-size: var(--text-eyebrow);
  font-weight: 600;
  color: var(--ink-2);
}

.todo-count {
  margin: 0;
  font-size: var(--text-eyebrow);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--ink-2);
}

[data-all-done='true'] .todo-count {
  color: var(--done);
}

.todo-items {
  flex: 1;
  min-height: 0;
  margin: 0.5rem 0 1rem;
  padding: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  list-style: none;
}

/* edit mode: one text box per line */
.todo-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  column-gap: 0.9rem;
  border-bottom: 1px solid var(--line);
  transition: border-color var(--duration-fast);
}

/* "回车 写下一件" appears under whichever line is being typed */
.todo-row-hint {
  display: none;
  grid-column: 2;
  margin: -0.35rem 0 0.6rem;
  font-size: 0.875rem;
  color: var(--ink-3);
}

.todo-row:focus-within .todo-row-hint {
  display: block;
}

.todo-key {
  padding: 0.1rem 0.45rem;
  border-radius: 6px;
  background: var(--fill);
  font: inherit;
  font-weight: 600;
  color: var(--ink-2);
}

.todo-row:focus-within {
  border-bottom-color: var(--ink);
}

.todo-dot {
  flex: none;
  width: 1.5rem;
  height: 1.5rem;
  border: 2px solid var(--line);
  border-radius: 50%;
  transition: border-color var(--duration-fast);
}

.todo-row:focus-within .todo-dot {
  border-color: var(--ink);
}

.todo-input {
  flex: 1;
  min-width: 0;
  padding: 0.75rem 0;
  border: 0;
  background: transparent;
  font: inherit;
  font-size: var(--text-todo);
  font-weight: 600;
  letter-spacing: -0.015em;
  color: var(--ink);
  caret-color: var(--ink);
}

.todo-input:focus-visible {
  outline: none;
}

.todo-input::placeholder {
  font-weight: 500;
  color: var(--ink-3);
}

/* list mode: tap to tick off */
.todo-label {
  display: flex;
  align-items: flex-start;
  gap: 0.9rem;
  padding: 0.8rem 0;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}

.todo-checkbox {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.todo-box {
  position: relative;
  flex: none;
  width: 1.5rem;
  height: 1.5rem;
  margin-top: calc((var(--text-todo) * 1.3 - 1.5rem) / 2);
  border: 2px solid var(--ink);
  border-radius: 50%;
  transition:
    background var(--duration-fast),
    transform var(--duration-fast) var(--ease-out-expo);
}

.todo-box::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 45%;
  width: 0.35rem;
  height: 0.7rem;
  border: solid var(--on-ink);
  border-width: 0 2.5px 2.5px 0;
  opacity: 0;
  transform: translate(-50%, -50%) rotate(45deg);
}

.todo-label:hover .todo-box {
  background: var(--fill);
}

.todo-label:active .todo-box {
  transform: scale(0.9);
}

.todo-checkbox:focus-visible + .todo-box {
  outline: 2px solid var(--ink);
  outline-offset: 3px;
}

[data-done='true'] .todo-box {
  background: var(--ink);
}

.just-done .todo-box {
  animation: stamp 520ms cubic-bezier(0.2, 0.9, 0.3, 1.2);
}

.just-done .todo-label {
  animation: thud 360ms 140ms ease-out;
}

@keyframes stamp {
  30% {
    transform: scale(1.6) rotate(-10deg);
  }
  55% {
    transform: scale(0.82);
  }
  78% {
    transform: scale(1.08);
  }
}

@keyframes thud {
  35% {
    transform: translateY(3px);
  }
}

/* ---------- the same hit feedback on every button ---------- */

.btn-primary,
.btn-small,
.btn-text,
.btn-quiet,
.icon-key,
.segmented span,
.lang button {
  position: relative;
}

.is-hit {
  animation: button-stamp 460ms cubic-bezier(0.2, 0.9, 0.3, 1.2);
}

@keyframes button-stamp {
  25% {
    transform: scale(1.09);
  }
  50% {
    transform: scale(0.93);
  }
  75% {
    transform: scale(1.02);
  }
}

/* four strokes fly out of the corners, like a game hit marker */
.hit-burst {
  position: absolute;
  inset: -2px;
  pointer-events: none;
}

.hit-burst i {
  position: absolute;
  width: 3px;
  height: 0.75rem;
  border-radius: 2px;
  background: var(--ink);
  opacity: 0;
  animation: corner-burst 480ms ease-out forwards;
}

.hit-burst i:nth-child(1) {
  left: 0;
  top: 0;
  --angle: -45deg;
}

.hit-burst i:nth-child(2) {
  right: 0;
  top: 0;
  --angle: 45deg;
}

.hit-burst i:nth-child(3) {
  right: 0;
  bottom: 0;
  --angle: 135deg;
}

.hit-burst i:nth-child(4) {
  left: 0;
  bottom: 0;
  --angle: -135deg;
}

@keyframes corner-burst {
  0% {
    opacity: 1;
    transform: rotate(var(--angle)) translateY(0) scaleY(0.5);
  }
  55% {
    opacity: 1;
    transform: rotate(var(--angle)) translateY(-0.75rem) scaleY(1);
  }
  100% {
    opacity: 0;
    transform: rotate(var(--angle)) translateY(-1.1rem) scaleY(0.7);
  }
}

/* game-style hit marker: four short strokes flying out of the tick */
.todo-burst {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.todo-burst i {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 3px;
  height: 0.6rem;
  margin: -0.3rem 0 0 -1.5px;
  border-radius: 2px;
  background: var(--ink);
  opacity: 0;
  animation: hitmarker 450ms ease-out forwards;
}

.todo-burst i:nth-child(1) {
  --angle: 45deg;
}

.todo-burst i:nth-child(2) {
  --angle: 135deg;
}

.todo-burst i:nth-child(3) {
  --angle: 225deg;
}

.todo-burst i:nth-child(4) {
  --angle: 315deg;
}

@keyframes hitmarker {
  0% {
    opacity: 1;
    transform: rotate(var(--angle)) translateY(-0.7rem) scaleY(0.5);
  }
  55% {
    opacity: 1;
    transform: rotate(var(--angle)) translateY(-1.3rem) scaleY(1);
  }
  100% {
    opacity: 0;
    transform: rotate(var(--angle)) translateY(-1.6rem) scaleY(0.7);
  }
}

[data-done='true'] .todo-box::after {
  opacity: 1;
}

.todo-text {
  min-width: 0;
  font-size: var(--text-todo);
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: -0.015em;
  overflow-wrap: anywhere;
  transition: color var(--duration-normal);
}

[data-done='true'] .todo-text {
  color: var(--ink-3);
  text-decoration: line-through;
  text-decoration-thickness: 2px;
}

.todo-foot {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 1rem;
}

.btn-small {
  height: 4rem;
  padding: 0 2.25rem;
  font-size: 1.3rem;
}

.btn-text {
  height: 4rem;
  padding: 0 1.9rem;
  font-size: 1.25rem;
}

/* ---------- video ---------- */

.screen {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  aspect-ratio: 16 / 9;
  overflow: visible; /* let the record's shadow and tonearm breathe */
  background: transparent;
}

/* Bilibili's player sits underneath the card: only its sound is used */
.screen-frame {
  position: absolute;
  inset: 8px; /* well inside the cover layer, so no edge of the hidden player can peek out */
  z-index: 0;
  pointer-events: none; /* never interactive: it only provides the sound */
}

.screen-frame iframe {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
}

/* Before a round: an idle record (decorative, not a button) + the music choice */
.placeholder {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  align-items: center;
  gap: clamp(1.5rem, 0.8rem + 2.5vw, 2.75rem);
  height: 100%;
  margin: 0;
  padding: 0.5rem 0;
}

.vinyl-idle .vinyl-disc {
  animation: none;
}

.vinyl-idle .vinyl-disc::after {
  background:
    radial-gradient(circle, var(--bg) 0 2.2%, #2c2c30 2.6% 16%, rgb(255 255 255 / 0.18) 16.4% 17%, transparent 17.4%),
    repeating-radial-gradient(circle, rgb(255 255 255 / 0.06) 0 1px, transparent 1px 3px);
}

.placeholder-body {
  min-width: 0;
}

.placeholder-title {
  margin: 0 0 0.5rem;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--ink);
}

.modes {
  display: grid;
  gap: 0.5rem;
  margin: 0;
  padding: 0;
  border: 0;
}

/* each choice is a card with a radio dot, a name and what it plays */
.mode-card {
  position: relative;
  display: grid;
  gap: 0.1rem;
  padding: 0.6rem 1rem 0.65rem 2.7rem;
  border-radius: 16px;
  background: var(--surface);
  box-shadow:
    inset 0 0 0 1.5px var(--line),
    0 3px 0 var(--key-light-edge);
  cursor: pointer;
  transition:
    transform 110ms var(--ease-out-expo),
    box-shadow var(--duration-fast);
}

.mode-card input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.mode-card::before {
  content: '';
  position: absolute;
  left: 0.95rem;
  top: 0.8rem;
  width: 1.1rem;
  height: 1.1rem;
  border-radius: 50%;
  box-shadow: inset 0 0 0 2px var(--ink-3);
  transition: box-shadow var(--duration-fast);
}

.mode-card:hover {
  transform: translateY(-1px);
}

.mode-card:active {
  transform: translateY(2px);
  box-shadow: inset 0 0 0 1.5px var(--line), 0 1px 0 var(--key-light-edge);
}

.mode-card:has(input:checked) {
  box-shadow:
    inset 0 0 0 2px var(--ink),
    0 3px 0 var(--ink);
}

.mode-card:has(input:checked)::before {
  box-shadow: inset 0 0 0 2px var(--ink), inset 0 0 0 5px var(--surface), inset 0 0 0 9px var(--ink);
}

.mode-card:has(input:focus-visible) {
  outline: 2px solid var(--ink);
  outline-offset: 3px;
}

.mode-name {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--ink);
}

.mode-desc {
  overflow: hidden;
  font-size: 0.8rem;
  color: var(--ink-2);
  white-space: nowrap;
  text-overflow: ellipsis;
}

.placeholder-text {
  margin: 0.5rem 0 0;
  font-size: 0.85rem;
  color: var(--ink-2);
  text-wrap: balance;
}

/* short player area (small laptops, phones): no idle record, cards side by side */
@container (max-height: 13rem) {
  .placeholder {
    grid-template-columns: minmax(0, 1fr);
  }

  .placeholder .vinyl-idle,
  .placeholder-title {
    display: none;
  }

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

  .mode-card {
    padding: 0.55rem 0.7rem 0.6rem 2.2rem;
  }

  .mode-card::before {
    left: 0.7rem;
    top: 0.75rem;
    width: 1rem;
    height: 1rem;
  }

  .mode-name {
    font-size: 1rem;
  }

  .mode-desc {
    font-size: 0.75rem;
  }

  .placeholder-text {
    margin-top: 0.45rem;
    font-size: 0.8rem;
  }
}

/* ---------- player card: spinning vinyl + name ---------- */

.now-playing {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  align-items: center;
  gap: clamp(1.5rem, 0.8rem + 2.5vw, 2.75rem);
  margin: 0;
  padding: 0.5rem 0;
  background: var(--bg); /* same as the page: no visible box, but the hidden player stays covered */
}

/* The record: the cover printed across the whole disc, grooves on top; the frame carries the sheen */
.vinyl {
  position: relative;
  height: min(100%, 48cqw); /* as tall as the player, but never crowding out the title */
  aspect-ratio: 1;
  border-radius: 50%;
  box-shadow: 0 16px 30px -14px rgb(0 0 0 / 0.55);
}

.vinyl::after {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 2;
  border-radius: 50%;
  background: conic-gradient(
    from 20deg,
    transparent 0 12%,
    rgb(255 255 255 / 0.16) 17%,
    transparent 24% 62%,
    rgb(255 255 255 / 0.12) 67%,
    transparent 74%
  );
  pointer-events: none;
}

.vinyl-disc {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border-radius: 50%;
  background: #141416;
  animation: spin 12s linear infinite;
  animation-play-state: paused;
}

[data-state='running'] .vinyl-disc {
  animation-play-state: running;
}

.vinyl-cover {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* grooves, darker rim, small centre label and the spindle hole */
.vinyl-disc::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background:
    radial-gradient(circle, var(--surface) 0 2.2%, #1a1a1c 2.6% 9%, rgb(255 255 255 / 0.25) 9.2% 9.6%, transparent 10%),
    repeating-radial-gradient(circle, rgb(0 0 0 / 0.24) 0 1px, transparent 1px 3px),
    radial-gradient(circle, transparent 58%, rgb(0 0 0 / 0.45) 100%);
}

.no-cover .vinyl-cover {
  visibility: hidden;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Tonearm: rests off the record, swings onto it while the music plays */
.tonearm {
  position: absolute;
  top: -6%;
  right: -8%;
  z-index: 3;
  width: 40%;
  overflow: visible;
  transform: rotate(-28deg);
  transform-origin: 78% 12.5%;
  transition: transform 800ms cubic-bezier(0.3, 0.7, 0.2, 1);
  filter: drop-shadow(0 3px 3px rgb(0 0 0 / 0.28));
}

[data-state='running'] .tonearm {
  transform: rotate(0deg);
}


.np-info {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.35rem;
  min-width: 0;
}

.np-title {
  display: -webkit-box;
  overflow: hidden;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  font-size: clamp(1.1rem, 0.7rem + 1vw, 1.65rem);
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.np-author {
  max-width: 100%;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: clamp(0.85rem, 0.75rem + 0.3vw, 1rem);
  color: var(--ink-2);
}

.np-status {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  margin: 0.5rem 0 0;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--ink-2);
}

.np-controls {
  display: flex;
  gap: 1.4rem;
  margin-top: 1rem;
}

/* round tactile key with a caption underneath */
.icon-key {
  --depth: 4px;
  display: grid;
  justify-items: center;
  gap: 0.45rem;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
}

.icon-key svg {
  box-sizing: content-box;
  width: 2.35rem;
  height: 2.35rem;
  padding: 1.3rem;
  border-radius: 50%;
  fill: var(--ink);
  color: var(--ink);
  background: var(--key-light);
  box-shadow:
    inset 0 0 0 1px var(--line),
    0 var(--depth) 0 var(--key-light-edge),
    0 calc(var(--depth) + 6px) 14px -8px rgb(0 0 0 / 0.25);
  transition:
    transform 110ms var(--ease-out-expo),
    box-shadow 110ms var(--ease-out-expo);
}

.icon-key:hover svg {
  transform: translateY(-1px);
}

.icon-key:active svg {
  transform: translateY(var(--depth));
  box-shadow: inset 0 0 0 1px var(--line), 0 0 0 var(--key-light-edge);
  transition-duration: 40ms;
}

.icon-key[aria-pressed='true'] svg {
  fill: var(--on-ink);
  color: var(--on-ink);
  background: var(--key-dark);
  box-shadow:
    inset 0 1px 0 rgb(255 255 255 / 0.14),
    0 var(--depth) 0 var(--key-dark-edge),
    0 calc(var(--depth) + 6px) 14px -8px rgb(0 0 0 / 0.3);
}

.icon-key:focus-visible {
  outline: none;
}

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

.icon-key-label {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--ink-2);
}

/* Short music area (small laptops, phones): compact keys, captions kept for screen readers only */
.screen {
  container-type: size;
}

@container (max-height: 15.5rem) {
  .icon-key-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  .icon-key svg {
    width: 1.5rem;
    height: 1.5rem;
    padding: 0.8rem;
  }

  .np-controls {
    gap: 0.75rem;
    margin-top: 0.6rem;
  }

  .np-status {
    margin-top: 0.3rem;
  }
}

/* little equalizer: moves while the round runs, rests when paused */
.np-bars {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 1.1rem;
}

.np-bars i {
  width: 3px;
  height: 100%;
  border-radius: 2px;
  background: var(--ink);
  transform: scaleY(0.3);
  transform-origin: bottom;
}

[data-state='running'] .np-bars i {
  animation: eq 0.9s ease-in-out infinite;
}

[data-state='running'] .np-bars i:nth-child(2) {
  animation-delay: -0.3s;
}

[data-state='running'] .np-bars i:nth-child(3) {
  animation-delay: -0.6s;
}

[data-state='running'] .np-bars i:nth-child(4) {
  animation-delay: -0.15s;
}

[data-state='loading'] .np-bars i {
  opacity: 0.3;
}

@keyframes eq {
  50% {
    transform: scaleY(1);
  }
}

/* ---------- dock: clock, progress, status, controls ---------- */

.dock {
  display: flex;
  flex-direction: column;
}

.clock {
  margin: 0 0 0 -0.045em;
  font-size: var(--clock);
  font-weight: 700;
  line-height: 0.78;
  letter-spacing: -0.045em;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.bar-controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem var(--gap);
  margin-top: 1rem;
}

/* ---------- journey: the progress bar as a little trip ----------
   --p (0..1) comes from the timer. The vehicle moves with it, and the strip shows two
   worlds split right at the vehicle: travelled (behind) and still ahead.
   Cartoon art: Microsoft Fluent Emoji (MIT) in assets/journey/. */

.journey {
  --vehicle-w: 3.9rem;
  --edge: calc(0.3rem + var(--p, 0) * (100cqw - var(--vehicle-w) - 2.8rem) + var(--vehicle-w) * 0.4);
  position: relative;
  height: 5rem;
  margin: 1rem 0 1.1rem;
  overflow: hidden;
  border-radius: 1.1rem;
  container-type: inline-size;
  box-shadow: inset 0 0 0 1px rgb(0 0 0 / 0.05);
}

.journey-layer,
.journey-scenery,
.journey-vehicle,
.journey-flag {
  position: absolute;
}

.journey-layer {
  inset: 0;
  overflow: hidden;
}

.journey-ahead {
  background: var(--j-ahead);
}

.journey-behind {
  background: var(--j-behind);
  clip-path: inset(0 calc(100% - var(--edge)) 0 0);
  transition: clip-path 1s linear;
}

/* scenery is twice as wide and drifts slowly sideways while the round runs (transform only) */
.journey-scenery {
  inset: 0 auto 0 0;
  width: 200%;
  animation: drift 50s linear infinite;
  animation-play-state: paused;
}

.journey-ahead .journey-scenery {
  background: var(--j-ahead-scenery);
}

.journey-behind .journey-scenery {
  background: var(--j-behind-scenery);
}

[data-status='running'] .journey-scenery {
  animation-play-state: running;
}

@keyframes drift {
  to {
    transform: translateX(-50%);
  }
}

.journey-flag {
  right: 0.55rem;
  bottom: var(--j-flag-bottom);
  width: 2.1rem;
  height: 2.1rem;
}

.journey-vehicle {
  left: 0.3rem;
  bottom: var(--j-vehicle-bottom);
  width: var(--vehicle-w);
  height: var(--vehicle-w);
  transform: translateX(calc(var(--p, 0) * (100cqw - var(--vehicle-w) - 2.8rem)));
  transition: transform 1s linear;
}

.journey-vehicle-body {
  display: block;
  width: 100%;
  height: 100%;
}

[data-status='running'] .journey-vehicle-body {
  animation: var(--j-motion) 2.6s ease-in-out infinite;
}

/* the emoji art faces different ways; turn each one to face right */
.journey-vehicle img {
  display: block;
  width: 100%;
  height: 100%;
  transform: var(--j-face);
  filter: drop-shadow(0 2px 2px rgb(0 0 0 / 0.15));
}

@keyframes bob {
  50% {
    transform: translateY(-2px) rotate(-2deg);
  }
}

@keyframes hover {
  50% {
    transform: translateY(-3px);
  }
}

@keyframes rumble {
  25% {
    transform: translateY(-0.6px);
  }
  75% {
    transform: translateY(0.6px);
  }
}

/* sea: sunny day ahead; behind the ship the water is deeper blue with a white wake */
[data-journey='sea'] {
  --j-ahead: url('../assets/journey/sun.svg') right 3.4rem top 8% / auto 34% no-repeat, linear-gradient(#e3f3fd 0 52%, #9fd3f1 52% 100%);
  --j-ahead-scenery: url('../assets/journey/cloud.svg') 10% 10% / auto 32% no-repeat, url('../assets/journey/cloud.svg') 60% 10% / auto 32% no-repeat, url('../assets/journey/cloud.svg') 34% 4% / auto 24% no-repeat, url('../assets/journey/cloud.svg') 84% 4% / auto 24% no-repeat;
  --j-behind: linear-gradient(#e3f3fd 0 52%, #5ea9dc 52% 100%);
  --j-behind-scenery:
    repeating-linear-gradient(90deg, #ffffff 0 14px, transparent 14px 22px) 0 calc(52% + 4px) / 100% 4px no-repeat,
    url('../assets/journey/cloud.svg') 10% 10% / auto 32% no-repeat, url('../assets/journey/cloud.svg') 60% 10% / auto 32% no-repeat;
  --vehicle-w: 3.3rem;
  --j-face: scaleX(-1); /* the emoji ship faces left */
  --j-vehicle-bottom: 26%;
  --j-flag-bottom: 46%;
  --j-motion: bob;
}

/* rail: mountains and trees; only behind the train are the rails laid */
[data-journey='rail'] {
  --j-ahead: linear-gradient(#eef7ff 0 62%, #cfe7b8 62% 100%);
  --j-ahead-scenery: url('../assets/journey/mountain.svg') 6% 12% / auto 58% no-repeat, url('../assets/journey/mountain.svg') 56% 12% / auto 58% no-repeat, url('../assets/journey/evergreen_tree.svg') 22% 30% / auto 42% no-repeat, url('../assets/journey/evergreen_tree.svg') 72% 30% / auto 42% no-repeat, url('../assets/journey/deciduous_tree.svg') 38% 26% / auto 46% no-repeat, url('../assets/journey/deciduous_tree.svg') 88% 26% / auto 46% no-repeat,
    repeating-linear-gradient(90deg, #a4b98f 0 6px, transparent 6px 16px) 0 calc(100% - 0.95rem) / 100% 2px no-repeat;
  --j-behind: linear-gradient(#eef7ff 0 62%, #c2dca8 62% 100%);
  --j-behind-scenery: url('../assets/journey/mountain.svg') 6% 12% / auto 58% no-repeat, url('../assets/journey/mountain.svg') 56% 12% / auto 58% no-repeat, url('../assets/journey/evergreen_tree.svg') 22% 30% / auto 42% no-repeat, url('../assets/journey/evergreen_tree.svg') 72% 30% / auto 42% no-repeat, url('../assets/journey/deciduous_tree.svg') 38% 26% / auto 46% no-repeat, url('../assets/journey/deciduous_tree.svg') 88% 26% / auto 46% no-repeat,
    linear-gradient(#5b5147, #5b5147) 0 calc(100% - 1.05rem) / 100% 3px no-repeat,
    linear-gradient(#5b5147, #5b5147) 0 calc(100% - 0.55rem) / 100% 3px no-repeat,
    repeating-linear-gradient(90deg, #8b7a66 0 6px, transparent 6px 15px) 0 calc(100% - 0.4rem) / 100% 0.85rem no-repeat;
  --j-face: scaleX(-1); /* the emoji train faces left */
  --j-vehicle-bottom: 0.2rem;
  --j-flag-bottom: 0.45rem;
  --j-motion: rumble;
}

/* sky: the plane flies out of the night (behind) into a sunny day (ahead) */
[data-journey='sky'] {
  --j-ahead: url('../assets/journey/sun.svg') right 3.4rem top 8% / auto 34% no-repeat, linear-gradient(#a9d4ff, #e8f4ff);
  --j-ahead-scenery: url('../assets/journey/cloud.svg') 6% 58% / auto 38% no-repeat, url('../assets/journey/cloud.svg') 56% 58% / auto 38% no-repeat, url('../assets/journey/cloud.svg') 24% 8% / auto 30% no-repeat, url('../assets/journey/cloud.svg') 74% 8% / auto 30% no-repeat, url('../assets/journey/cloud.svg') 40% 50% / auto 26% no-repeat, url('../assets/journey/cloud.svg') 90% 50% / auto 26% no-repeat;
  --j-behind: url('../assets/journey/crescent_moon.svg') 1rem 10% / auto 36% no-repeat, linear-gradient(#0d1430, #26336a);
  --j-behind-scenery: url('../assets/journey/star.svg') 8% 18% / auto 16% no-repeat, url('../assets/journey/star.svg') 58% 18% / auto 16% no-repeat, url('../assets/journey/star.svg') 22% 64% / auto 12% no-repeat, url('../assets/journey/star.svg') 72% 64% / auto 12% no-repeat, url('../assets/journey/star.svg') 36% 24% / auto 14% no-repeat, url('../assets/journey/star.svg') 86% 24% / auto 14% no-repeat;
  --j-face: rotate(45deg);
  --j-vehicle-bottom: 14%;
  --j-flag-bottom: 20%;
  --j-motion: hover;
}

/* space: a ringed planet ahead; behind the rocket a purple nebula and a glowing trail */
[data-journey='space'] {
  --j-ahead: url('../assets/journey/ringed_planet.svg') right 3.6rem top 12% / auto 44% no-repeat, linear-gradient(#141327, #221f43);
  --j-ahead-scenery: url('../assets/journey/star.svg') 12% 20% / auto 14% no-repeat, url('../assets/journey/star.svg') 62% 20% / auto 14% no-repeat, url('../assets/journey/star.svg') 30% 70% / auto 10% no-repeat, url('../assets/journey/star.svg') 80% 70% / auto 10% no-repeat, url('../assets/journey/star.svg') 44% 30% / auto 12% no-repeat, url('../assets/journey/star.svg') 94% 30% / auto 12% no-repeat;
  --j-behind:
    linear-gradient(transparent calc(50% - 2px), rgb(255 159 10 / 0.85) calc(50% - 2px) calc(50% + 2px), transparent calc(50% + 2px)),
    radial-gradient(120% 140% at 30% 50%, #6d3fb8, #2a1f5c 70%);
  --j-behind-scenery: url('../assets/journey/star.svg') 12% 20% / auto 14% no-repeat, url('../assets/journey/star.svg') 62% 20% / auto 14% no-repeat, url('../assets/journey/star.svg') 30% 70% / auto 10% no-repeat, url('../assets/journey/star.svg') 80% 70% / auto 10% no-repeat;
  --j-face: rotate(45deg);
  --j-vehicle-bottom: calc(50% - var(--vehicle-w) / 2);
  --j-flag-bottom: 28%;
  --j-motion: hover;
}

.label {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  margin: 0;
  font-size: var(--text-bar);
  font-weight: 500;
  color: var(--ink-2);
}

.label::before {
  content: '';
  flex: none;
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 50%;
  background: var(--ink-3);
}

[data-status='running'] .label,
[data-finished='true'] .label {
  color: var(--ink);
}

[data-status='running'] .label::before {
  background: var(--live);
  animation: pulse 1.6s ease-in-out infinite;
}

[data-finished='true'] .label::before {
  background: var(--done);
}

@keyframes pulse {
  50% {
    opacity: 0.3;
  }
}

/* Apple-style segmented control */
.segmented {
  display: inline-flex;
  margin: 0;
  padding: 4px 4px 8px; /* room below for the chosen key's edge */
  border: 0;
  border-radius: var(--radius-pill);
  background: var(--fill);
  box-shadow: inset 0 2px 4px rgb(0 0 0 / 0.08);
}

.segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented span {
  display: inline-grid;
  place-items: center;
  min-width: 5rem;
  height: 4.75rem;
  padding: 0 1.2rem;
  border-radius: var(--radius-pill);
  font-size: 1.5rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--ink-2);
  cursor: pointer;
  transition:
    transform 110ms var(--ease-out-expo),
    box-shadow 110ms var(--ease-out-expo),
    background var(--duration-fast),
    color var(--duration-fast);
}

.segmented span:hover {
  color: var(--ink);
  background: rgb(255 255 255 / 0.55);
}

.segmented label:active span {
  transform: translateY(2px);
}

.segmented input:checked + span {
  background: var(--key-dark);
  color: var(--on-ink);
  box-shadow:
    inset 0 1px 0 rgb(255 255 255 / 0.14),
    0 3px 0 var(--key-dark-edge),
    0 7px 12px -6px rgb(0 0 0 / 0.3);
  transform: translateY(-1px);
}

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

.actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
  gap: 1.25rem;
  margin-left: auto; /* stays on the right even while the length picker is hidden */
}

.btn-primary {
  --depth: 6px;
  min-width: 14rem;
  height: 5.5rem;
  padding: 0 3rem;
  font-size: 1.9rem;
  letter-spacing: 0.04em;
}

.btn-quiet {
  --depth: 5px;
  height: 5.5rem;
  padding: 0 2rem;
  font-size: 1.5rem;
}

/* ---------- tactile buttons ----------
   Flat faces sitting on a solid edge, like a physical key:
   hover lifts a pixel, press sinks the face onto its edge. */

.btn-small,
.btn-text {
  --depth: 4px;
}

.btn-primary,
.btn-small,
.btn-text,
.btn-quiet {
  --face: var(--key-dark);
  --edge: var(--key-dark-edge);
  --face-text: var(--on-ink);
  --rim: inset 0 1px 0 rgb(255 255 255 / 0.14);
  border: 0;
  border-radius: var(--radius-pill);
  background: var(--face);
  color: var(--face-text);
  font-weight: 600;
  cursor: pointer;
  box-shadow:
    var(--rim),
    0 var(--depth) 0 var(--edge),
    0 calc(var(--depth) + 6px) 14px -6px rgb(0 0 0 / 0.28);
  transition:
    transform 110ms var(--ease-out-expo),
    box-shadow 110ms var(--ease-out-expo),
    background var(--duration-fast),
    color var(--duration-fast);
}

/* Light keys: white face, grey edge, hairline so they read on the light page */
.btn-text,
.btn-quiet {
  --face: var(--key-light);
  --edge: var(--key-light-edge);
  --face-text: var(--ink);
  --rim: inset 0 0 0 1px var(--line);
}

:is(.btn-primary, .btn-small, .btn-text, .btn-quiet):hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow:
    var(--rim),
    0 calc(var(--depth) + 1px) 0 var(--edge),
    0 calc(var(--depth) + 9px) 18px -6px rgb(0 0 0 / 0.3);
}

:is(.btn-primary, .btn-small, .btn-text, .btn-quiet):active:not(:disabled) {
  transform: translateY(var(--depth));
  box-shadow:
    var(--rim),
    0 0 0 var(--edge),
    0 1px 3px rgb(0 0 0 / 0.2);
  transition-duration: 40ms;
}

/* Disabled keys rest pressed-in and greyed out */
:is(.btn-primary, .btn-small, .btn-text, .btn-quiet):disabled {
  --face: var(--fill);
  --face-text: var(--ink-3);
  --rim: inset 0 0 0 1px var(--line);
  transform: translateY(var(--depth));
  box-shadow: var(--rim);
  cursor: not-allowed;
}

.btn-primary:disabled {
  cursor: progress;
}

/* ---------- small screens ---------- */

@media (max-width: 899px), (max-height: 559px) {
  .todo {
    min-height: 16rem;
  }

  /* On phones the card is a bit taller than 16:9 so the record + info fit; the card always covers the hidden player */
  .screen {
    aspect-ratio: auto;
    height: clamp(12rem, 52vw, 15rem);
  }

  .actions {
    margin-left: 0;
  }

  .bar-controls {
    flex-direction: column;
    align-items: stretch;
  }

  .segmented label {
    flex: 1;
  }

  .segmented span {
    width: 100%;
    min-width: 0;
  }

  /* phones: 换一个 / 静音 / 结束 share a row, the main button gets its own full-width row */
  .actions button {
    flex: 1;
    min-width: 0;
  }

  .actions .btn-primary {
    flex-basis: 100%;
  }
}

/* ---------- portrait phones: everything on one screen, no page scrolling ----------
   The to-do card shows four lines and scrolls inside itself (on very short screens it
   gives up height first); the music card sits midway between it and the clock. */
@media (max-width: 899px) and (orientation: portrait) {
  .layout {
    --pad: 1rem;
    --gap: 0.65rem;
    --brand-h: 1.35rem;
    --clock: min(calc((100vw - 2 * var(--pad)) / var(--clock-ratio) * 0.86), 12.5dvh);
    display: grid;
    grid-template-rows: auto minmax(0, auto) 1fr;
    height: 100dvh;
    min-height: 0;
    padding: calc(0.75rem + env(safe-area-inset-top)) var(--pad) calc(0.75rem + env(safe-area-inset-bottom));
  }

  .todo {
    --todo-row: clamp(2.55rem, 6.4dvh, 3.4rem);
    min-height: 0;
    padding: 0.9rem 1.1rem 0.8rem;
    border-radius: 20px;
  }

  .todo-items {
    flex: 0 1 auto;
    height: calc(4 * var(--todo-row));
    margin: 0.25rem 0 0.5rem;
  }

  /* a hand-scroll settles on a whole line */
  .todo[data-mode='list'] .todo-items {
    scroll-snap-type: y proximity;
  }

  .todo-row,
  .todo-label {
    min-height: var(--todo-row);
    scroll-snap-align: start;
  }

  .todo-label {
    align-items: center;
  }

  .todo-input,
  .todo-text {
    font-size: 1.05rem;
  }

  .todo-input {
    padding: 0.55rem 0;
  }

  .todo-label {
    padding: 0.55rem 0;
  }

  .todo-dot,
  .todo-box {
    width: 1.25rem;
    height: 1.25rem;
  }

  .btn-small,
  .btn-text {
    --depth: 3px;
    height: 2.5rem;
    padding: 0 1.2rem;
    font-size: 1rem;
  }

  .side {
    gap: 0.55rem;
  }

  /* compact music row: small record, one-line title, small keys */
  .screen {
    height: clamp(5.25rem, 35dvh - 9rem, 9.5rem);
    margin-block: auto;
  }

  .clock {
    margin: 0;
    text-align: center;
  }

  .now-playing {
    gap: 1.6rem;
    padding: 0.25rem 0;
  }

  .tonearm {
    width: 36%;
  }

  .np-title {
    -webkit-line-clamp: 1;
    font-size: 1rem;
  }

  .np-author {
    font-size: 0.8rem;
  }

  .np-status {
    display: none;
  }

  .np-controls {
    gap: 0.6rem;
    margin-top: 0.4rem;
  }

  .icon-key {
    --depth: 3px;
  }

  .icon-key svg {
    width: 1.15rem;
    height: 1.15rem;
    padding: 0.6rem;
  }


  .journey {
    --vehicle-w: 2.5rem;
    height: clamp(3.1rem, 10.4dvh - 1.25rem, 4.5rem);
    margin: 0.5rem 0 0.45rem;
    border-radius: 0.8rem;
  }

  /* title + author on the left, the two round keys on the right: fits a short row */
  .np-info {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    column-gap: 0.75rem;
  }

  .np-title,
  .np-author {
    grid-column: 1;
  }

  .np-controls {
    grid-column: 2;
    grid-row: 1 / span 2;
    margin: 0;
  }

  .label {
    justify-content: center;
    font-size: 0.9rem;
  }

  /* lengths and the main button share one row */
  .bar-controls {
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    gap: 0.6rem;
    margin-top: 0.5rem;
  }

  .segmented {
    flex: 1;
    min-width: 0;
    padding: 3px 3px 6px;
  }

  .segmented span {
    height: 2.75rem;
    padding: 0;
    font-size: 1.05rem;
  }

  .actions {
    flex: 1;
    flex-wrap: nowrap;
    gap: 0.6rem;
  }

  .durations:not([hidden]) + .actions {
    flex: none;
  }

  .btn-primary,
  .btn-quiet {
    --depth: 4px;
    height: 3rem;
    min-width: 0;
    padding: 0 1.4rem;
    font-size: 1.15rem;
  }

  .actions .btn-primary {
    flex: 1 0 auto;
  }

  .actions .btn-quiet {
    flex: none;
  }
}

/* ---------- misc ---------- */

.storage-warning {
  position: fixed;
  inset: auto var(--pad) var(--pad);
  z-index: 3;
  margin: 0;
  padding: 0.75rem 1rem;
  border-radius: 12px;
  background: var(--ink);
  color: var(--on-ink);
  font-size: var(--text-eyebrow);
}

.noscript {
  padding: var(--pad);
  text-align: center;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition-duration: 0.01ms !important;
  }
}
