:root {
  --bg: #f5f4f1;
  --card: #ffffff;
  --ink: #17171a;
  --ink-soft: #5c5c66;
  --line: #e4e2dc;
  --accent: #b4532a;
  --accent-soft: #f7ebe4;
  --del: #f8d7d5;
  --del-ink: #8a2b25;
  --ins: #fdf0b4;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 20, 25, 0.05), 0 8px 24px rgba(20, 20, 25, 0.05);
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI Variable Text",
    "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14141a;
    --card: #1c1c23;
    --ink: #ecebe8;
    --ink-soft: #9d9daa;
    --line: #2c2c36;
    --accent: #e08a5f;
    --accent-soft: #33231c;
    --del: #4a2422;
    --del-ink: #f0b1ac;
    --ins: #4a4014;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.25);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.6 var(--sans);
  -webkit-font-smoothing: antialiased;
}

@media (min-height: 620px) {
  body { height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
  main { flex: 1; min-height: 0; }
}

main {
  width: min(760px, 100%);
  margin: 0 auto;
  padding: 0 20px 20px;
  display: flex;
  flex-direction: column;
}

/* --- top bar --- */
.topbar {
  width: min(760px, 100%);
  margin: 0 auto;
  padding: 14px 20px 12px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex: none;
}
.brand { display: flex; align-items: center; gap: 9px; }
.brand h1 { font: 600 18px/1 var(--sans); letter-spacing: -0.01em; margin: 0; }
.brand .tld { color: var(--ink-soft); font-weight: 400; }
.brand .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); }
.topbar-actions { display: flex; gap: 6px; margin-left: auto; }
.count { font-variant-numeric: tabular-nums; color: var(--ink-soft); margin-left: 5px; }
.count:empty { display: none; }

/* step rail */
.steps {
  display: flex; align-items: center; gap: 8px;
  list-style: none; margin: 0; padding: 0;
  font-size: 12.5px; color: var(--ink-soft);
}
.steps li { display: flex; align-items: center; gap: 8px; }
.steps li + li::before {
  content: ""; width: 14px; height: 1px; background: var(--line);
}
.steps li[data-active] { color: var(--ink); font-weight: 600; }
.steps li[data-done] { color: var(--accent); }
@media (max-width: 620px) { .steps { display: none; } }

/* --- stage cards --- */
.stage {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.stage-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex: none; }
.stage-head h2 { margin: 0 0 2px; font-size: 17px; letter-spacing: -0.01em; }

.stage-actions {
  display: flex; align-items: center; gap: 10px;
  flex: none; padding-top: 12px; border-top: 1px solid var(--line);
}
.stage-actions .spacer { flex: 1; }
.stage-actions .hint { margin-right: auto; }

/* --- stage 1: speak --- */
.hero { display: flex; flex-direction: column; align-items: center; gap: 10px; flex: none; padding: 6px 0 2px; }

.record-big {
  display: inline-flex; align-items: center; gap: 12px;
  border: 0; border-radius: 999px;
  background: var(--accent); color: #fff;
  padding: 15px 32px 15px 26px;
  font: 500 17px/1 var(--sans);
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(180, 83, 42, 0.25);
  transition: transform 0.12s ease, filter 0.12s ease;
}
.record-big:hover { filter: brightness(1.06); }
.record-big:active { transform: scale(0.98); }
.record-big:disabled { opacity: 0.45; cursor: not-allowed; box-shadow: none; }
.record-big .mic { width: 13px; height: 13px; border-radius: 50%; background: #fff; }
.record-big.is-recording { background: #b3251f; box-shadow: 0 6px 18px rgba(179, 37, 31, 0.3); }
.record-big.is-recording .mic { animation: pulse 1.1s ease-in-out infinite; }

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.45; transform: scale(0.7); }
}

.hero-meta { display: flex; align-items: center; gap: 12px; height: 22px; }
.timer { font-variant-numeric: tabular-nums; color: var(--ink-soft); font-size: 13.5px; }
.levels { display: flex; align-items: flex-end; gap: 3px; height: 20px; }
.levels i {
  width: 3px; height: 3px; border-radius: 2px;
  background: var(--accent); opacity: 0.35;
  transition: height 0.08s linear, opacity 0.08s linear;
}
.hero-hint { margin: 0; text-align: center; color: var(--ink-soft); font-size: 13px; max-width: 46ch; }
.hero-hint b { color: var(--ink); }

/* --- stage 2: shape --- */
.choices { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; flex: none; }
.choice {
  display: grid; gap: 4px; text-align: left;
  padding: 13px 14px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--bg); color: var(--ink);
  cursor: pointer; font: inherit;
  transition: border-color 0.12s ease, background 0.12s ease, box-shadow 0.12s ease;
}
.choice b { font-size: 14.5px; font-weight: 600; }
.choice em { font-style: normal; font-size: 12.5px; line-height: 1.45; color: var(--ink-soft); }
.choice:hover { border-color: var(--accent); }
.choice.is-selected {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px var(--accent);
}
@media (max-width: 620px) { .choices { grid-template-columns: 1fr; } }

/* The middle of the shape stage scrolls, so opening Fine tune can never push
   the run button off the screen or strand a slider below the fold. */
.stage-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-right: 2px;
}

.options { display: grid; gap: 8px; flex: none; }
.opt {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 11px 13px; border: 1px solid var(--line); border-radius: 11px;
  background: var(--bg); cursor: pointer;
}
.opt:hover { border-color: var(--accent); }
.opt input { margin: 2px 0 0; accent-color: var(--accent); width: 16px; height: 16px; }
.opt span { display: grid; gap: 2px; }
.opt b { font-size: 14px; font-weight: 600; }
.opt em { font-style: normal; font-size: 12.5px; color: var(--ink-soft); }

.length-row { display: flex; gap: 8px; padding-left: 26px; flex-wrap: wrap; }
.pill {
  display: grid; gap: 1px; text-align: left;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--card); color: var(--ink);
  padding: 7px 13px; cursor: pointer; font: inherit; font-size: 13.5px;
}
.pill span { font-size: 11.5px; color: var(--ink-soft); }
.pill:hover { border-color: var(--accent); }
.pill.is-selected { border-color: var(--accent); background: var(--accent-soft); }

.fine { flex: none; border-top: 1px solid var(--line); padding-top: 10px; }
.fine summary {
  cursor: pointer; color: var(--ink-soft); font-size: 13px;
  list-style: none; display: inline-flex; align-items: center; gap: 6px;
}
.fine summary::-webkit-details-marker { display: none; }
.fine summary::before { content: "▸"; font-size: 10px; }
.fine[open] summary::before { content: "▾"; }
.fine-body { display: flex; flex-wrap: wrap; gap: 10px; padding-top: 10px; }

/* On a phone, a 150px slider in a wrapping row is unusable — give each control
   the full width so the thumb has room to travel. */
@media (max-width: 620px) {
  .fine-body { display: grid; grid-template-columns: 1fr; gap: 12px; }
  .fine-body .field.slider,
  .fine-body .field.grow,
  .fine-body .field { flex: none; width: 100%; }
  .fine-body input[type="range"] { height: 32px; }
}

/* --- stage 3: result --- */
.view { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 8px; }
.prose {
  flex: 1;
  min-height: 120px;
  overflow: auto;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--bg);
  font: 16px/1.65 var(--sans);
  white-space: pre-wrap;
  word-break: break-word;
}
.prose[contenteditable]:empty::before { content: attr(data-placeholder); color: var(--ink-soft); }
textarea.raw {
  width: 100%;
  flex: 1;
  resize: none;
  font: 15px/1.7 var(--sans);
}
.diff del { background: var(--del); color: var(--del-ink); text-decoration: line-through; padding: 1px 2px; border-radius: 3px; }
.diff ins { background: var(--ins); text-decoration: none; padding: 1px 2px; border-radius: 3px; }

.legend { display: flex; gap: 16px; font-size: 12px; color: var(--ink-soft); flex: none; }
.swatch { display: inline-block; width: 11px; height: 11px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.swatch.del { background: var(--del); }
.swatch.ins { background: var(--ins); }

.notes { list-style: none; margin: 0; padding: 0; display: grid; gap: 5px; flex: none; max-height: 92px; overflow: auto; }
.notes li { font-size: 12.5px; color: var(--ink-soft); padding-left: 16px; position: relative; }
.notes li::before { content: "·"; position: absolute; left: 5px; color: var(--accent); font-weight: 700; }

/* --- tabs --- */
.tabs { display: flex; gap: 4px; background: var(--bg); padding: 3px; border-radius: 10px; border: 1px solid var(--line); }
.tab {
  border: 0; background: transparent; color: var(--ink-soft);
  padding: 5px 13px; border-radius: 8px; cursor: pointer; font: inherit; font-size: 13.5px;
}
.tab.is-active { background: var(--card); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,0.08); }

/* --- form controls --- */
.field { display: grid; gap: 4px; font-size: 11.5px; color: var(--ink-soft); }
.field.grow { flex: 1 1 200px; min-width: 0; }
.field.slider { flex: 0 1 150px; }
.field.slider span { display: flex; justify-content: space-between; gap: 8px; }
.field.slider output { color: var(--accent); font-variant-numeric: tabular-nums; }
select, input[type="text"], input[type="password"], textarea {
  font: inherit;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 7px 9px;
  max-width: 100%;
}
input[type="range"] { width: 100%; height: 22px; margin: 0; accent-color: var(--accent); cursor: pointer; }
select:focus-visible, input:focus-visible, textarea:focus-visible,
[contenteditable]:focus-visible, button:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

button { font: inherit; }
.primary, .ghost {
  border-radius: 9px; padding: 8px 15px; cursor: pointer;
  border: 1px solid var(--line); white-space: nowrap;
  transition: background 0.12s ease, color 0.12s ease;
}
.primary { background: var(--ink); color: var(--card); border-color: var(--ink); }
.primary:hover:not(:disabled) { filter: brightness(1.2); }
.primary.big { padding: 10px 22px; font-size: 15.5px; font-weight: 500; }
.ghost { background: transparent; color: var(--ink); }
.ghost:hover:not(:disabled) { background: var(--accent-soft); }
.ghost.small { padding: 5px 11px; font-size: 13px; }
button:disabled { opacity: 0.4; cursor: not-allowed; }

.hint { color: var(--ink-soft); font-size: 12.5px; margin: 0; }

/* --- dialogs --- */
dialog {
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--card); color: var(--ink);
  padding: 0; max-width: 520px; width: calc(100% - 32px);
  max-height: min(80dvh, 640px); box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(10, 10, 15, 0.4); }
.dialog-body { padding: 18px; display: grid; gap: 16px; overflow: auto; max-height: inherit; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.dialog-head h2 { margin: 0; font-size: 17px; }
.dialog-section { display: grid; gap: 8px; }
.dialog-section h3 {
  margin: 0; font-size: 11.5px; letter-spacing: 0.04em;
  text-transform: uppercase; color: var(--ink-soft);
}
.row { display: flex; gap: 8px; }
.row input { flex: 1; min-width: 0; }
.row-tight { display: flex; gap: 6px; }

.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip {
  display: inline-flex; align-items: center; gap: 7px;
  background: var(--accent-soft); color: var(--ink);
  border-radius: 999px; padding: 4px 6px 4px 12px; font-size: 13px;
}
.chip button {
  border: 0; background: transparent; color: var(--ink-soft);
  cursor: pointer; line-height: 1; padding: 2px 5px; border-radius: 50%;
}
.chip button:hover { background: rgba(0,0,0,0.08); color: var(--ink); }

.archive-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.archive-list li {
  display: flex; align-items: center; gap: 10px;
  border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 10px; background: var(--bg);
}
.archive-list .snippet {
  flex: 1; min-width: 0; margin: 0; font-size: 14px; cursor: pointer;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.archive-list time { color: var(--ink-soft); font-size: 12px; white-space: nowrap; flex: none; }
.archive-list .drop {
  border: 0; background: transparent; color: var(--ink-soft);
  cursor: pointer; padding: 2px 6px; border-radius: 6px; line-height: 1; flex: none;
}
.archive-list .drop:hover { background: var(--accent-soft); color: var(--ink); }

.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%);
  background: var(--ink); color: var(--card);
  padding: 10px 18px; border-radius: 999px; font-size: 14px;
  box-shadow: var(--shadow); z-index: 10;
}
.toast[data-tone="error"] { background: #a92a22; color: #fff; }

@media (max-width: 560px) {
  .stage-actions { flex-wrap: wrap; }
  .stage-actions .primary, .stage-actions .ghost { flex: 1; }
}
