:root {
  --bg: #eef1f4;
  --surface: #ffffff;
  --ink: #18212f;
  --muted: #5a6577;
  --rule: #d5dbe3;
  --accent: #2446c7;
  --accent-ink: #ffffff;
  --rec: #d3203b;
  --soft: #e3e8ef;
  --s1: #0e7c70;
  --s2: #4b4fd1;
  --s3: #a86a00;
  --s4: #9a3a8c;
  --s5: #3c7a1e;
  --s6: #b8461f;
  --s7: #3d6e8f;
  --s8: #b4365c;
  --sans: 'Noto Sans TC', 'Microsoft JhengHei UI', 'PingFang TC', system-ui, sans-serif;
  --serif: 'Noto Serif TC', 'PMingLiU', 'Songti TC', serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #10151d;
    --surface: #18202b;
    --ink: #e6ebf2;
    --muted: #97a3b4;
    --rule: #2a3442;
    --accent: #7d95ff;
    --accent-ink: #0d1430;
    --rec: #ff5468;
    --soft: #222c39;
    --s1: #3cc4b2;
    --s2: #9497ff;
    --s3: #e2a83a;
    --s4: #e07fd0;
    --s5: #8bc96a;
    --s6: #f08a62;
    --s7: #7fb2d6;
    --s8: #f07a9c;
    color-scheme: dark;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.6 var(--sans);
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

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

[hidden] {
  display: none !important;
}

/* ---------- 頂列 ---------- */
.bar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 24px;
  border-bottom: 1px solid var(--rule);
  background: var(--surface);
}

.brand {
  font-weight: 700;
  font-size: 18px;
  color: var(--ink);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand::before {
  content: '';
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--rec);
}

.ai-status {
  margin-left: auto;
  font-size: 14px;
  color: var(--muted);
}

.ai-status.bad {
  color: var(--rec);
}

main {
  max-width: 1240px;
  margin: 0 auto;
  padding: 24px;
}

h1,
h2,
h3 {
  line-height: 1.3;
  margin: 0 0 12px;
}

h1 {
  font-size: 26px;
}

h2 {
  font-size: 19px;
}

h3 {
  font-size: 16px;
}

.hint {
  margin: 4px 0 0;
  font-size: 14px;
  color: var(--muted);
}

/* ---------- 按鈕 ---------- */
.btn {
  border: 1px solid var(--rule);
  background: var(--surface);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  white-space: nowrap;
}

.btn:hover {
  border-color: var(--muted);
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
  padding: 12px 22px;
}

.btn.rec {
  background: var(--rec);
  border-color: var(--rec);
  color: #fff;
  font-weight: 700;
}

.btn.quiet {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}

.btn.quiet:hover {
  color: var(--ink);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ---------- 首頁 ---------- */
.home {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
  gap: 32px;
  align-items: start;
}

.setup {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 14px;
  padding: 28px;
}

.field {
  margin: 0 0 22px;
  border: 0;
  padding: 0;
}

.field > .label,
.field > legend {
  display: block;
  font-weight: 700;
  margin-bottom: 8px;
  padding: 0;
}

.field input[type='text'],
.field textarea,
.field select {
  width: 100%;
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--bg);
}

.field textarea {
  min-height: 92px;
  resize: vertical;
}

.check {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin: 6px 0;
}

.check input {
  margin-top: 6px;
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.check .hint {
  margin-top: 0;
}

.tier-model {
  margin-left: 8px;
  color: var(--muted);
  font-size: 13px;
}

.tier-cost {
  margin-left: 10px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.mic-row {
  margin: 4px 0 0 28px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  position: relative;
}

.chip input {
  position: absolute;
  opacity: 0;
  inset: 0;
  cursor: pointer;
}

.chip span {
  display: inline-block;
  padding: 6px 14px;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: var(--bg);
}

.chip input:checked + span {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--surface);
}

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

.range-row {
  display: flex;
  align-items: center;
  gap: 14px;
}

.range-row input {
  flex: 1;
  accent-color: var(--accent);
}

.range-row output {
  min-width: 52px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.start-row {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.history ul {
  list-style: none;
  margin: 0;
  padding: 0;
  border-top: 1px solid var(--rule);
}

.history li a {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 16px;
  padding: 14px 4px;
  border-bottom: 1px solid var(--rule);
  color: inherit;
  text-decoration: none;
}

.history li a:hover .h-title {
  color: var(--accent);
}

.h-title {
  font-weight: 700;
}

.h-meta {
  font-size: 14px;
  color: var(--muted);
  grid-column: 1 / -1;
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
}

.h-flag {
  font-size: 13px;
  color: var(--rec);
}

.empty {
  color: var(--muted);
  padding: 18px 0;
}

/* ---------- 錄製中 ---------- */
.live-head {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 14px;
  padding: 14px 18px;
}

.rec-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--rec);
  animation: pulse 1.6s ease-in-out infinite;
  flex: none;
}

.rec-dot.off {
  animation: none;
  background: var(--muted);
}

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

.clock {
  font-size: 24px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.live-title {
  font-weight: 500;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 280px;
}

.level {
  width: 90px;
  height: 6px;
  border-radius: 3px;
  background: var(--soft);
  overflow: hidden;
}

.level i {
  display: block;
  height: 100%;
  width: 0;
  background: var(--s1);
  transition: width 80ms linear;
}

.live-chunk {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--muted);
  margin-left: auto;
}

.live-chunk input {
  width: 110px;
  accent-color: var(--accent);
}

.live-chunk output {
  color: var(--ink);
  font-weight: 700;
  min-width: 40px;
  font-variant-numeric: tabular-nums;
}

/* 分段帶：每一段錄音一格，寬度 = 秒數 */
.tape-wrap {
  margin: 14px 0 6px;
}

.tape {
  display: flex;
  gap: 3px;
  height: 34px;
  align-items: stretch;
}

.tape .cell {
  position: relative;
  min-width: 6px;
  border-radius: 4px;
  background: var(--soft);
  overflow: hidden;
  display: flex;
}

.tape .cell.queued {
  background: repeating-linear-gradient(135deg, var(--soft) 0 6px, var(--rule) 6px 12px);
}

.tape .cell.working {
  background: var(--accent);
  opacity: 0.55;
  animation: pulse 1.2s ease-in-out infinite;
}

.tape .cell.silent {
  background: transparent;
  border: 1px dashed var(--rule);
}

.tape .cell.failed {
  background: transparent;
  border: 2px solid var(--rec);
}

.tape .cell.growing {
  background: transparent;
  border: 1px solid var(--rule);
}

.tape .cell.growing i {
  background: var(--soft);
}

.tape .cell i {
  display: block;
  height: 100%;
}

.tape-meta {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  font-size: 13px;
  color: var(--muted);
}

.notice {
  margin: 12px 0;
  padding: 10px 14px;
  border-left: 3px solid var(--s3);
  background: var(--surface);
  border-radius: 0 8px 8px 0;
  font-size: 15px;
}

.notice.bad {
  border-left-color: var(--rec);
}

/* ---------- 登入、額度（對外服務） ---------- */
.account {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 14px;
  color: var(--muted);
  min-width: 0;
}

.ai-status:not([hidden]) + .account {
  margin-left: 0;
}

.acct-left {
  color: var(--ink);
  font-weight: 500;
  white-space: nowrap;
}

.acct-left.low {
  color: var(--rec);
}

.acct-who {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 18ch;
}

.link {
  border: 0;
  background: none;
  padding: 0;
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.login h1 {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 30px;
  margin-bottom: 14px;
  text-wrap: balance;
}

.login .lead {
  margin: 0 0 10px;
  font-size: 17px;
  max-width: 34em;
}

.login .free {
  margin: 0 0 22px;
  font-weight: 700;
}

.g-btn {
  min-height: 44px;
  margin-bottom: 8px;
}

.login #dev-login {
  margin-top: 4px;
}

.privacy-note {
  margin-top: 26px;
  padding-top: 16px;
  border-top: 1px solid var(--rule);
  font-size: 14px;
  color: var(--muted);
}

.privacy-note p {
  margin: 0 0 6px;
  max-width: 40em;
}

.privacy-note a {
  color: var(--accent);
}

.quota-line {
  margin: 0 0 14px;
  font-size: 15px;
  color: var(--muted);
}

.quota-line strong {
  color: var(--ink);
}

label.btn.disabled {
  opacity: 0.5;
  pointer-events: none;
}

/* ---------- 說話者 ---------- */
.speakers {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin: 14px 0;
}

.spk {
  --c: var(--s1);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--rule);
  border-radius: 999px;
  padding: 4px 12px 4px 6px;
  background: var(--surface);
  cursor: pointer;
}

.spk::before {
  content: attr(data-id);
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--c);
  color: var(--surface);
  font-size: 12px;
  font-weight: 700;
}

.spk-edit {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  padding: 12px 14px;
  border: 1px solid var(--rule);
  border-radius: 10px;
  background: var(--surface);
  margin-bottom: 14px;
}

.spk-edit input,
.spk-edit select {
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 6px 10px;
  background: var(--bg);
}

/* ---------- 逐字稿 ---------- */
.feed {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 14px;
  padding: 8px 0;
}

.feed:empty::before {
  content: '開始說話後，大約一段秒數加上 10 秒，逐字稿就會出現在這裡。';
  display: block;
  padding: 28px 24px;
  color: var(--muted);
}

.line {
  --c: var(--s1);
  display: grid;
  grid-template-columns: 56px 120px minmax(0, 1fr);
  gap: 4px 14px;
  padding: 10px 20px;
  border-left: 3px solid transparent;
}

.line.now {
  border-left-color: var(--c);
  background: var(--bg);
}

.line .t {
  border: 0;
  background: none;
  padding: 2px 0 0;
  color: var(--muted);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  text-align: left;
  cursor: pointer;
  align-self: start;
}

.line .t:hover {
  color: var(--accent);
}

.line .who {
  border: 0;
  background: none;
  padding: 1px 0 0;
  text-align: left;
  color: var(--c);
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
  align-self: start;
  overflow-wrap: anywhere;
}

.line select.who-pick {
  font-size: 14px;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: var(--bg);
  align-self: start;
}

.orig {
  margin: 0;
  font-family: var(--serif);
  font-size: 18px;
  line-height: 1.75;
}

.tr {
  margin: 2px 0 0;
  font-size: 15px;
  color: var(--muted);
}

.tr b {
  font-weight: 500;
  font-size: 12px;
  margin-right: 6px;
  padding: 0 6px;
  border-radius: 4px;
  background: var(--soft);
  color: var(--muted);
}

.hide-tr .tr {
  display: none;
}

/* ---------- 即時草稿字 ---------- */
.drafts {
  margin-top: 12px;
  border: 1px dashed var(--rule);
  border-radius: 14px;
  padding: 6px 0 8px;
}

.drafts-head {
  margin: 0;
  padding: 6px 20px 4px;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
}

.drafts-head span {
  font-weight: 400;
  margin-left: 10px;
}

.drafts.empty #draft-lines::before {
  content: '開始說話，字會馬上出現在這裡。';
  display: block;
  padding: 8px 20px;
  color: var(--muted);
  font-size: 14px;
}

.drafts #draft-status {
  padding: 0 20px;
}

.line.draft {
  padding-top: 6px;
  padding-bottom: 6px;
}

.line.draft .who {
  color: var(--muted);
  font-weight: 500;
  font-size: 13px;
  cursor: default;
}

.line.draft .orig {
  color: var(--muted);
}

.line.draft.interim .orig {
  color: var(--ink);
  opacity: 0.75;
}

.line.draft.orphan .who {
  color: var(--rec);
}

.pending {
  padding: 8px 20px 8px 90px;
  color: var(--muted);
  font-size: 14px;
}

.pending.failed {
  color: var(--rec);
}

.pending .btn {
  margin-left: 10px;
  padding: 2px 10px;
  font-size: 13px;
}

/* ---------- 單場紀錄 ---------- */
.detail-head {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.title-edit {
  font-size: 26px;
  font-weight: 700;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  padding: 2px 8px;
  margin-left: -9px;
  width: min(640px, 100%);
}

.title-edit:hover,
.title-edit:focus {
  border-color: var(--rule);
  background: var(--surface);
}

.meta {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 14px;
}

.head-actions {
  margin-left: auto;
  display: flex;
  gap: 8px;
  position: relative;
}

.menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 10;
  min-width: 230px;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 6px;
  box-shadow: 0 12px 30px rgb(20 30 50 / 0.16);
}

.menu button {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  background: none;
  padding: 9px 12px;
  border-radius: 6px;
  cursor: pointer;
}

.menu button:hover {
  background: var(--bg);
}

.detail-grid {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
  gap: 28px;
  align-items: start;
}

.detail-side {
  position: sticky;
  top: 16px;
  display: grid;
  gap: 18px;
}

.player video,
.player audio {
  width: 100%;
  border-radius: 12px;
  background: #000;
  display: block;
}

.player audio {
  background: transparent;
}

.card {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 14px;
  padding: 20px 22px;
}

.summary p {
  margin: 0 0 12px;
}

.summary ul {
  margin: 0 0 16px;
  padding-left: 20px;
}

.summary li {
  margin: 4px 0;
}

.todos {
  width: 100%;
  border-collapse: collapse;
  font-size: 15px;
}

.todos th,
.todos td {
  text-align: left;
  padding: 7px 8px;
  border-bottom: 1px solid var(--rule);
  vertical-align: top;
}

.todos th {
  font-weight: 500;
  color: var(--muted);
  font-size: 13px;
}

.usage {
  font-size: 14px;
  color: var(--muted);
}

.usage strong {
  color: var(--ink);
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}

.toolbar .check {
  margin: 0;
  font-size: 14px;
}

.toolbar .check input {
  margin-top: 3px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--surface);
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 15px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.toast.show {
  opacity: 1;
}

@media (max-width: 900px) {
  .home,
  .detail-grid {
    grid-template-columns: 1fr;
  }

  .detail-side {
    position: static;
  }
}

@media (max-width: 640px) {
  main {
    padding: 16px;
  }

  .bar {
    padding: 12px 16px;
    flex-wrap: wrap;
    row-gap: 6px;
  }

  .acct-who {
    display: none;
  }

  .setup {
    padding: 20px 16px;
  }

  .line {
    grid-template-columns: 48px minmax(0, 1fr);
    padding: 10px 14px;
  }

  .line .body {
    grid-column: 1 / -1;
  }

  .pending {
    padding-left: 14px;
  }

  .live-chunk {
    margin-left: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .rec-dot,
  .tape .cell.working {
    animation: none;
  }

  .level i,
  .toast {
    transition: none;
  }
}
