:root {
  --paper: #fbfbf9;
  --surface: #ffffff;
  --ink: #16242e;
  --slate: #5b7a8c;
  --line: #e4e6e2;
  --blue: #1c5d80;       /* 藍鵲藍 — primary accent */
  --blue-deep: #16485f;
  --blue-wash: #eef3f6;
  --coral: #d9544d;      /* 藍鵲喙紅 — record only */
  --radius: 10px;
  --shadow: 0 1px 2px rgba(22, 36, 46, .04), 0 8px 24px rgba(22, 36, 46, .05);
}

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

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: "Noto Sans TC", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

main { max-width: 720px; margin: 0 auto; padding: 0 1.25rem 4rem; }

/* ---------- masthead ---------- */
.masthead { max-width: 720px; margin: 0 auto; padding: 3.5rem 1.25rem 1.75rem; }
.wordmark {
  font-family: "Noto Serif TC", serif;
  font-weight: 700;
  font-size: clamp(1.9rem, 5vw, 2.6rem);
  letter-spacing: .01em;
  display: flex;
  align-items: baseline;
  gap: .6rem;
}
.wordmark .latin {
  font-family: "Noto Sans TC", sans-serif;
  font-weight: 500;
  font-size: .8rem;
  letter-spacing: .28em;
  text-transform: uppercase;
  color: var(--slate);
}
.eyebrow {
  margin: .5rem 0 0;
  font-size: .82rem;
  letter-spacing: .04em;
  color: var(--slate);
}
/* the magpie's long tail — a thin graded rule */
.tail-rule {
  height: 3px;
  margin-top: 1.4rem;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--blue) 0%, var(--blue) 18%, var(--line) 18%, var(--line) 100%);
}

/* ---------- panel ---------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
}

/* segmented control */
.seg {
  display: inline-flex;
  padding: 4px;
  gap: 2px;
  background: var(--blue-wash);
  border-radius: 8px;
  margin-bottom: 1.4rem;
}
.seg button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--slate);
  font: inherit;
  font-weight: 500;
  padding: .45rem .95rem;
  border-radius: 6px;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.seg button:hover { color: var(--blue-deep); }
.seg button.active {
  background: var(--surface);
  color: var(--blue-deep);
  box-shadow: 0 1px 2px rgba(22, 36, 46, .08);
}

.field-label {
  display: block;
  font-size: .8rem;
  font-weight: 500;
  letter-spacing: .02em;
  color: var(--slate);
  margin-bottom: .45rem;
}

textarea {
  width: 100%;
  font-family: inherit;
  font-size: 1.05rem;
  line-height: 1.7;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .8rem .9rem;
  resize: vertical;
}
textarea:focus-visible,
select:focus-visible { outline: 2px solid var(--blue); outline-offset: 1px; border-color: var(--blue); }

select {
  font: inherit;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .55rem .7rem;
  min-width: 12rem;
}

/* ---------- example chips ---------- */
.examples { display: flex; align-items: baseline; gap: .6rem; margin-top: .7rem; flex-wrap: wrap; }
.examples-label { font-size: .78rem; color: var(--slate); flex-shrink: 0; }
.chips { display: flex; gap: .4rem; flex-wrap: wrap; }
.chip {
  font: inherit;
  font-size: .82rem;
  color: var(--blue-deep);
  background: var(--blue-wash);
  border: 1px solid transparent;
  border-radius: 999px;
  padding: .28rem .8rem;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.chip:hover { border-color: var(--blue); }
.chip:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

/* preset speaker row */
.speaker-row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }

/* sub-panels (preset / clone) shown per-mode via .show */
.subpanel { display: none; margin-top: 1.25rem; }
.subpanel.show { display: block; }

/* ---------- clone: script card ---------- */
.script-card {
  border: 1px solid var(--line);
  border-left: 3px solid var(--blue);
  background: var(--blue-wash);
  border-radius: 8px;
  padding: 1rem 1.1rem;
}
.script-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: .5rem; }
.script-head .eyebrow {
  margin: 0;
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--blue-deep);
}
.script-text {
  font-family: "Noto Serif TC", serif;
  font-size: 1.18rem;
  line-height: 1.85;
  margin: 0;
  color: var(--ink);
}
.hint { font-size: .82rem; color: var(--slate); margin: .55rem 0 0; }

/* ---------- clone: record card ---------- */
.record-card {
  margin-top: 1rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 1.1rem;
}

/* the tail-bar level meter — the page's signature element */
.meter {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 46px;
  padding: 0 2px;
  margin-bottom: 1rem;
}
.meter .bar {
  flex: 1;
  min-width: 2px;
  height: 8%;
  background: linear-gradient(var(--blue), var(--blue-deep));
  border-radius: 2px;
  transition: height .07s linear, background .2s;
  opacity: .35;
}
.meter.live .bar { opacity: 1; }

.rec-controls { display: flex; align-items: center; gap: .6rem; }
.timer {
  margin-left: auto;
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
  font-size: .95rem;
  color: var(--slate);
  font-variant-numeric: tabular-nums;
}
.rec-status { font-size: .85rem; color: var(--slate); margin: .8rem 0 0; }
.rec-status.warn { color: var(--coral); }
.rec-status.ok { color: var(--blue-deep); }
#rec-playback { display: block; margin-top: .8rem; width: 100%; }

/* record button — the only coral element on the page */
.rec-btn {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  font: inherit;
  font-weight: 500;
  color: #fff;
  background: var(--coral);
  border: 0;
  border-radius: 7px;
  padding: .5rem 1rem;
  cursor: pointer;
}
.rec-btn .dot { width: 9px; height: 9px; border-radius: 50%; background: #fff; }
.rec-btn.recording { background: var(--blue-deep); }
.rec-btn.recording .dot { background: var(--coral); animation: pulse 1.1s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .25; } }

/* ---------- consent / ethics ---------- */
.consent {
  display: flex;
  gap: .55rem;
  align-items: flex-start;
  margin-top: 1.1rem;
  font-size: .9rem;
}
.consent input { margin-top: .25rem; accent-color: var(--blue); }
.ethics { font-size: .8rem; color: var(--slate); margin: .55rem 0 0; padding-left: .1rem; }

/* ---------- controls / cfg / synth ---------- */
.controls {
  display: flex;
  align-items: flex-end;
  gap: 1.5rem;
  margin-top: 1.5rem;
  padding-top: 1.4rem;
  border-top: 1px solid var(--line);
}
.cfg { flex: 1; }
.cfg .mono {
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
  color: var(--blue-deep);
  font-weight: 700;
}
input[type="range"] {
  width: 100%;
  margin: .2rem 0 .35rem;
  accent-color: var(--blue);
}

.primary-btn {
  font: inherit;
  font-weight: 700;
  color: #fff;
  background: var(--blue);
  border: 0;
  border-radius: 8px;
  padding: .7rem 1.6rem;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s;
}
.primary-btn:hover { background: var(--blue-deep); }

.ghost-btn {
  font: inherit;
  font-weight: 500;
  color: var(--blue-deep);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: .45rem .9rem;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  transition: border-color .15s, background .15s;
}
.ghost-btn:hover { border-color: var(--blue); background: var(--blue-wash); }
.ghost-btn.small { padding: .25rem .65rem; font-size: .8rem; }

button:focus-visible, .ghost-btn:focus-visible, .seg button:focus-visible {
  outline: 2px solid var(--blue); outline-offset: 2px;
}
button[disabled] { opacity: .4; cursor: not-allowed; }

/* ---------- status / result ---------- */
.status { min-height: 1.2rem; margin: 1rem 0 0; font-size: .9rem; color: var(--slate); }
.status.error { color: var(--coral); }
.status.busy { color: var(--blue-deep); }
.status.done { color: var(--blue-deep); font-weight: 500; }

.result {
  margin-top: 1.1rem;
  padding-top: 1.1rem;
  border-top: 1px dashed var(--line);
}
.result-meta { font-size: .82rem; color: var(--blue-deep); font-weight: 500; margin-bottom: .55rem; }
.result-player { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; }
.result-player audio { flex: 1; min-width: 220px; }

/* ---------- live GPU panel ---------- */
.gpu {
  margin-top: 1.1rem;
  padding: .9rem 1rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  transition: border-color .2s, background .2s;
}
.gpu.live { border-color: var(--blue); background: var(--blue-wash); }
.gpu-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; margin-bottom: .55rem; }
.gpu-head .eyebrow {
  margin: 0;
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--slate);
}
.gpu.live .gpu-head .eyebrow { color: var(--blue-deep); }
.gpu-readout { font-size: .82rem; color: var(--slate); }
.gpu-bar {
  position: relative;
  height: 22px;
  border-radius: 6px;
  background: var(--line);
  overflow: hidden;
}
.gpu-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--blue), var(--blue-deep));
  border-radius: 6px;
  transition: width .35s ease;
}
.gpu-pct {
  position: absolute;
  top: 50%;
  right: .6rem;
  transform: translateY(-50%);
  font-size: .78rem;
  font-weight: 700;
  color: var(--ink);
}

/* ---------- history (comparable past clips) ---------- */
.history { margin-top: 1.4rem; padding-top: 1.2rem; border-top: 1px solid var(--line); }
.history-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: .9rem; }
.history-head .eyebrow {
  margin: 0;
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--slate);
}
.clip-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .8rem .9rem;
  margin-bottom: .65rem;
}
.clip-item:last-child { margin-bottom: 0; }
.clip-meta { font-size: .8rem; color: var(--slate); margin-bottom: .5rem; }
.clip-player { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }
.clip-player audio { flex: 1; min-width: 200px; height: 38px; }

/* ---------- footer ---------- */
.foot {
  margin-top: 1.6rem;
  font-size: .78rem;
  color: var(--slate);
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
}
.foot .dotsep { opacity: .5; }
.foot-link { color: var(--blue-deep); font-weight: 500; text-decoration: none; }
.foot-link:hover { text-decoration: underline; }

@media (max-width: 540px) {
  .controls { flex-direction: column; align-items: stretch; gap: 1rem; }
  .primary-btn { width: 100%; }
  .masthead { padding-top: 2.25rem; }
}

@media (prefers-reduced-motion: reduce) {
  .meter .bar { transition: none; }
  .rec-btn.recording .dot { animation: none; }
}
