/* Palette lives in tokens.css. Do not add a color here: add a token.
   Base, card, button and segmented-control rules follow ListenQuiz's
   app.css so the two Midphrase tools feel like one family. */

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  -webkit-tap-highlight-color: transparent;
}

.screen {
  width: 100%;
  max-width: 480px;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top, 0) var(--gutter) calc(env(safe-area-inset-bottom, 0px) + 96px);
}

.hidden { display: none !important; }

.icon-defs { display: none; }
.icon { display: inline-block; width: 1em; height: 1em; fill: currentColor; flex-shrink: 0; vertical-align: -0.15em; }

/* ── Top bar ─────────────────────────────────────────────────── */
.bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 0 12px;
}
/* The mark is masked over a token color, as in ListenQuiz, so it follows
   the theme without a second SVG. */
.mark {
  display: block;
  width: 26px;
  height: 26px;
  background-color: var(--accent-text);
  -webkit-mask: url("icons/mark.svg") center / contain no-repeat;
          mask: url("icons/mark.svg") center / contain no-repeat;
}
.wordmark { font-weight: 700; font-size: 1.05rem; letter-spacing: -0.3px; color: var(--accent-text); }
.bar-date { margin-left: auto; color: var(--dim); font-size: 0.9rem; }
.icon-btn {
  background: none;
  border: none;
  color: var(--dim);
  font-size: 1.4rem;
  padding: 8px;
  margin-right: -8px;
  cursor: pointer;
  display: flex;
  touch-action: manipulation;
}

h2 { font-size: 1.5rem; letter-spacing: -0.4px; margin: 6px 0 2px; }
.sub { color: var(--dim); font-size: 0.9rem; }
.label {
  color: var(--dim);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: 20px 0 8px;
}

/* ── Cards ───────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 16px 18px;
}

/* ── Buttons ─────────────────────────────────────────────────── */
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: var(--r);
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  padding: 15px 20px;
  width: 100%;
  transition: opacity 0.15s, transform 0.1s;
  user-select: none;
  touch-action: manipulation;
  color: var(--text);
}
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled { opacity: 0.35; cursor: default; }
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:not(:disabled):active { background: var(--accent-hi); }
.btn-secondary { background: var(--surface2); border: 1px solid var(--border); }
.btn-ghost {
  background: none;
  color: var(--dim);
  border: 1px solid var(--border);
  font-size: 0.9rem;
  padding: 10px 16px;
  width: auto;
  border-radius: 8px;
}
.btn-large { padding: 18px 20px; font-size: 1.05rem; border-radius: var(--r-lg); }
.btn-danger { color: var(--red); }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; }

/* ── Segmented control (ListenQuiz's mode tabs) ──────────────── */
.seg {
  display: flex;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 3px;
  gap: 3px;
}
.seg button {
  flex: 1;
  background: none;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--dim);
  font-family: inherit;
  padding: 10px 8px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  touch-action: manipulation;
}
.seg b { font-size: 1rem; }
.seg small { font-size: 0.75rem; }
.seg button.on {
  color: var(--text);
  background: color-mix(in srgb, var(--accent) 22%, var(--surface));
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
}

/* ── Plan screen ─────────────────────────────────────────────── */
.win-row { display: flex; align-items: center; gap: 8px; padding: 6px 0; }
.win-row span { color: var(--dim); }
.win-row button { margin-left: auto; }
.tp { display: inline-flex; align-items: center; gap: 2px; }
.tp-colon { color: var(--dim); font-weight: 600; }
.tp select {
  font: inherit;
  font-size: 1.05rem;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 10px;
  -webkit-appearance: none;
  appearance: none;
  text-align: center;
}
.add-win { margin-top: 8px; }

.stepper-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.stepper { display: flex; align-items: center; gap: 4px; }
.stepper button {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
}
.stepper output { min-width: 32px; text-align: center; font-weight: 600; font-size: 1.1rem; }

.summary { margin: 20px 0 14px; }
.summary-main { font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 8px; color: var(--dim); font-size: 0.9rem; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; vertical-align: 0; }
.warn { color: var(--red); font-size: 0.9rem; }
.fine { color: var(--dim); font-size: 0.85rem; margin-top: 12px; text-align: center; }

/* ── Pieces editor ───────────────────────────────────────────── */
.text-in {
  font: inherit;
  font-size: 1.05rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 12px;
  width: 100%;
  min-width: 0;
}
.text-in:focus { outline: 2px solid color-mix(in srgb, var(--accent) 50%, transparent); outline-offset: 1px; }
.swatches { display: flex; gap: 12px; flex-wrap: wrap; }
.swatch {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 3px solid var(--bg);
  box-shadow: 0 0 0 1px var(--border);
  cursor: pointer;
  touch-action: manipulation;
}
.swatch.on { box-shadow: 0 0 0 2px var(--text); }
.hint { color: var(--dim); font-size: 0.85rem; margin-top: 8px; }
.units { display: flex; flex-direction: column; gap: 6px; }
.unit-edit { display: flex; align-items: center; gap: 0; }
.unit-edit .text-in { flex: 1; margin-right: 4px; }
.unit-edit .icon-btn { font-size: 1.15rem; padding: 8px 7px; margin: 0; }
.icon-btn:disabled { opacity: 0.3; }
.row.piece-row { grid-template-columns: 4px 1fr; padding: 12px 14px 12px 12px; }
.row.is-paused { opacity: 0.55; }

/* ── Status card (day screen) ────────────────────────────────── */
.status { margin-bottom: 14px; }
.status-kicker { color: var(--dim); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em; }
.status-title { font-size: 1.6rem; font-weight: 700; letter-spacing: -0.5px; margin: 4px 0 2px; }
.status-line { color: var(--dim); font-size: 0.95rem; }
.status-clock { font-variant-numeric: tabular-nums; font-size: 2.4rem; font-weight: 700; letter-spacing: -1px; margin-top: 6px; }
.status-clock small { font-size: 1rem; font-weight: 600; color: var(--dim); letter-spacing: 0; }
.status .btn { margin-top: 14px; }
.progress { height: 6px; border-radius: 3px; background: var(--surface2); margin-top: 12px; overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); width: 0; transition: width 1s linear; }
.status.is-running { border-color: color-mix(in srgb, var(--accent) 55%, var(--border)); }
.status.is-behind { border-color: color-mix(in srgb, var(--red) 55%, var(--border)); }

/* ── Timeline ────────────────────────────────────────────────── */
.timeline { display: flex; flex-direction: column; gap: 6px; }
.row {
  display: grid;
  grid-template-columns: 46px 4px 1fr auto;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 10px 4px 10px 10px;
  text-align: left;
  font: inherit;
  color: var(--text);
  width: 100%;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.1s;
}
.row:active { transform: scale(0.985); }
.row[data-drag] { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.row.dragging {
  position: relative;
  z-index: 5;
  transition: none;
  box-shadow: 0 10px 28px var(--shadow);
  border-color: var(--accent);
}
.timeline > .drop-before { box-shadow: 0 -4px 0 -1px var(--accent); }
.timeline.drop-end::after { content: ""; height: 3px; border-radius: 2px; background: var(--accent); }
.row-time { font-variant-numeric: tabular-nums; color: var(--dim); font-size: 0.9rem; }
.row-stripe { align-self: stretch; border-radius: 2px; }
.row-main { min-width: 0; }
.row-title { font-weight: 600; font-size: 1.02rem; }
.row-piece { color: var(--dim); font-size: 0.8rem; }
.row-note { color: var(--dim); font-size: 0.8rem; font-style: italic; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.row-end { display: flex; align-items: center; gap: 2px; color: var(--dim); font-size: 0.85rem; }
.row-end .icon-btn { font-size: 1.2rem; padding: 10px 8px; margin: 0; }

.row.is-current {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, var(--surface));
}
.row.is-done { opacity: 0.55; }
.row.is-done .row-title::after { content: " ✓"; color: var(--green); }
.row.is-skipped .row-title { text-decoration: line-through; color: var(--dim); }
.row.is-skipped { opacity: 0.6; }
.row.is-late .row-time { color: var(--red); }

.row-quiet {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--dim);
  font-size: 0.85rem;
  padding: 2px 10px;
}
.row-quiet .row-time { width: 46px; }
.row-quiet.is-now { color: var(--accent-text); font-weight: 600; }

.timeline > .section-label { margin: 16px 0 2px; }
.section-label { color: var(--dim); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em; margin: 22px 0 8px; }
.day-foot { color: var(--dim); font-size: 0.85rem; text-align: center; margin-top: 18px; }

/* ── Bottom sheet (ListenQuiz's confirm overlay, from the bottom) ── */
.sheet-overlay {
  position: fixed;
  inset: 0;
  background: var(--scrim);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 20;
}
.sheet {
  width: 100%;
  max-width: 480px;
  background: var(--surface);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  padding: 20px var(--gutter) calc(env(safe-area-inset-bottom, 0px) + 20px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 85dvh;
  overflow-y: auto;
  box-shadow: 0 -8px 30px var(--shadow);
}
.sheet h3 { font-size: 1.25rem; }
.sheet textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 12px;
  min-height: 110px;
  resize: vertical;
}
.notes { display: flex; flex-direction: column; gap: 10px; margin-top: 6px; }
.note { border-left: 3px solid var(--border); padding-left: 10px; }
.note time { color: var(--dim); font-size: 0.8rem; display: block; }
.about { color: var(--dim); font-size: 0.85rem; line-height: 1.45; margin-top: 6px; }

/* ── Toast ───────────────────────────────────────────────────── */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 18px);
  transform: translateX(-50%);
  width: calc(100% - 2 * var(--gutter));
  max-width: 440px;
  background: var(--text);
  color: var(--bg);
  border-radius: var(--r);
  padding: 12px 14px 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 6px 24px var(--shadow);
  z-index: 30;
  font-size: 0.95rem;
}
.toast span { flex: 1; }
.toast-undo {
  background: none;
  border: none;
  color: inherit;
  font: inherit;
  font-weight: 700;
  text-decoration: underline;
  padding: 6px;
  cursor: pointer;
}

@media (hover: hover) {
  .btn-primary:hover:not(:disabled) { background: var(--accent-hi); }
}
