:root {
  --bg: #f5f4f2;
  --surface: #ffffff;
  --surface-2: #faf9f7;
  --text: #1c1c1e;
  --muted: #6e6e73;
  --border: #e5e2dd;
  --border-strong: #d4d0c9;
  --brand: #e0503f;
  --brand-hover: #c9412f;
  --brand-grad: linear-gradient(135deg, #ff8a5b 0%, #d64550 100%);
  --brand-soft: rgba(224, 80, 63, 0.1);
  --ok: #1f8f54;
  --err: #cf3b45;
  --err-soft: rgba(207, 59, 69, 0.08);
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 8px 24px rgba(0, 0, 0, 0.05);
  --font: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111214;
    --surface: #1a1c1f;
    --surface-2: #202327;
    --text: #ececee;
    --muted: #9a9ca3;
    --border: #2b2e33;
    --border-strong: #3a3e45;
    --brand: #ff6b55;
    --brand-hover: #ff8572;
    --brand-soft: rgba(255, 107, 85, 0.14);
    --ok: #4cc38a;
    --err: #ff6b74;
    --err-soft: rgba(255, 107, 116, 0.1);
    --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; }

html, body { margin: 0; }
body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

h1, h2, p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; font-weight: 400; }

/* ---------- buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 38px; padding: 0 16px;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  font: inherit; font-weight: 550; text-decoration: none; white-space: nowrap;
  cursor: pointer; transition: background .15s, border-color .15s, color .15s, opacity .15s;
}
.btn:disabled, .btn[aria-disabled="true"] { opacity: .45; cursor: not-allowed; pointer-events: none; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-hover); }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); border-color: var(--border-strong); }
.btn-sm { height: 30px; padding: 0 11px; font-size: 13px; }
.btn-lg { height: 46px; font-size: 16px; }
.btn-block { width: 100%; }
.btn-danger:hover { color: var(--err); border-color: var(--err); }
.link-btn {
  border: 0; background: none; padding: 0; margin-left: auto;
  color: var(--brand); font: inherit; cursor: pointer;
}
.link-btn:hover { text-decoration: underline; }

.input {
  width: 100%; height: 40px; padding: 0 12px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font: inherit;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.textarea { height: auto; padding: 10px 12px; resize: vertical; line-height: 1.5; }
.select { appearance: auto; cursor: pointer; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.input:focus-visible { outline: none; }

.input-group { display: flex; gap: 8px; }
.input-group .btn { height: 40px; flex: none; }

.check { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; color: var(--muted); cursor: pointer; user-select: none; }
.check input { accent-color: var(--brand); width: 15px; height: 15px; margin: 0; }

.field { display: grid; gap: 7px; }
.field-label { display: flex; align-items: baseline; gap: 8px; font-weight: 600; font-size: 14px; }

.form-error { color: var(--err); font-size: 13.5px; white-space: pre-wrap; min-height: 0; }
.form-error:empty { display: none; }

.pill {
  display: inline-flex; align-items: center; height: 22px; padding: 0 9px;
  border-radius: 999px; background: var(--brand-soft); color: var(--brand);
  font-size: 12px; font-weight: 600; letter-spacing: .01em;
}

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: 100%; max-width: 360px; display: grid; gap: 14px; justify-items: center; text-align: center;
  padding: 36px 28px 28px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 20px; box-shadow: var(--shadow);
}
.login-card h1 { font-size: 21px; letter-spacing: -.01em; }
.login-card .input, .login-card .btn { margin-top: 4px; }
.login-logo { border-radius: 14px; }

/* ---------- app shell ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  height: 58px; padding: 0 max(20px, calc((100vw - 1200px) / 2));
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand img { border-radius: 8px; }
.brand-name { font-weight: 700; font-size: 16px; letter-spacing: -.01em; }

.layout {
  max-width: 1200px; margin: 0 auto; padding: 22px 20px 48px;
  display: grid; gap: 20px;
  grid-template-columns: minmax(0, 5fr) minmax(0, 7fr);
  align-items: start;
}
.history-card { grid-column: 1 / -1; }
@media (max-width: 880px) {
  .layout { grid-template-columns: minmax(0, 1fr); padding: 16px 14px 40px; gap: 16px; }
  .topbar { padding: 0 14px; }
  .brand-name { font-size: 15px; }
}

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 22px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.card-head .card-title { margin-bottom: 0; }
.card-title { font-size: 16.5px; font-weight: 700; margin-bottom: 16px; display: flex; align-items: baseline; gap: 10px; }
.actions { display: flex; gap: 8px; }
.stack { display: grid; gap: 18px; }

/* ---------- dropzone ---------- */
.dropzone {
  border: 1.5px dashed var(--border-strong); border-radius: var(--radius);
  background: var(--surface-2); padding: 22px 16px; text-align: center;
  cursor: pointer; transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.dragover { border-color: var(--brand); background: var(--brand-soft); }
.dropzone.has-file { border-style: solid; text-align: left; padding: 14px; cursor: default; }
.dz-icon { width: 30px; height: 30px; fill: var(--brand); margin-bottom: 6px; }
.dz-title { font-weight: 600; }
.dz-hint { font-size: 12.5px; margin-top: 2px; }
.dz-file { display: grid; gap: 10px; }
.dz-file-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.dz-file-info { min-width: 0; }
.dz-file-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dz-file audio { width: 100%; height: 36px; }

/* ---------- language chips ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  height: 30px; padding: 0 12px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-size: 13.5px; cursor: pointer; transition: all .15s;
}
.chip:hover { border-color: var(--border-strong); }
.chip[aria-pressed="true"] { background: var(--brand-soft); border-color: var(--brand); color: var(--brand); font-weight: 600; }
.chip .x { font-size: 15px; line-height: 1; opacity: .7; }

/* ---------- advanced ---------- */
.advanced { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 0 14px; }
.advanced summary { cursor: pointer; padding: 11px 0; font-weight: 600; font-size: 14px; list-style-position: inside; }
.advanced[open] { padding-bottom: 14px; }
.advanced[open] summary { margin-bottom: 4px; }
.advanced .field + .field { margin-top: 14px; }

/* ---------- progress ---------- */
.progress { display: grid; gap: 6px; }
.progress-track { height: 6px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); overflow: hidden; }
.progress-bar { height: 100%; width: 0; background: var(--brand-grad); border-radius: inherit; transition: width .2s; }
.progress.indeterminate .progress-bar { width: 35%; animation: slide 1.2s ease-in-out infinite; }
@keyframes slide { 0% { transform: translateX(-100%); } 100% { transform: translateX(290%); } }

/* ---------- result ---------- */
.result-card { min-height: 420px; display: flex; flex-direction: column; }
.meta { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 13px; color: var(--muted); margin: -4px 0 12px; }
.meta:empty { display: none; }
.meta b { color: var(--text); font-weight: 600; }
.transcript {
  flex: 1; min-height: 300px; max-height: 68vh; overflow: auto;
  padding: 16px 18px; border-radius: var(--radius-sm);
  background: var(--surface-2); border: 1px solid var(--border);
  white-space: pre-wrap; word-break: break-word; line-height: 1.85; font-size: 15.5px;
}
.transcript.live::after {
  content: ""; display: inline-block; width: 2px; height: 1.1em; margin-left: 2px;
  vertical-align: text-bottom; background: var(--brand); animation: blink 1s step-end infinite;
}
@keyframes blink { 50% { opacity: 0; } }
.empty {
  flex: 1; display: grid; place-content: center; gap: 6px; text-align: center;
  min-height: 160px; padding: 24px; color: var(--muted);
  border: 1px dashed var(--border); border-radius: var(--radius-sm);
}
.result-card .empty { min-height: 300px; }

/* ---------- history ---------- */
.history-list { list-style: none; margin: 0; padding: 0; display: grid; }
.history-item {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 16px; align-items: center;
  padding: 12px 4px; border-top: 1px solid var(--border);
}
.history-item:first-child { border-top: 0; }
.history-item.active .h-name { color: var(--brand); }
.h-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.h-sub { grid-column: 1; font-size: 12.5px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 12px; }
.h-actions { grid-column: 2; grid-row: 1 / span 2; display: flex; gap: 6px; }
@media (max-width: 560px) {
  .history-item { grid-template-columns: minmax(0, 1fr); }
  .h-actions { grid-column: 1; grid-row: auto; margin-top: 6px; }
}

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
  padding: 10px 16px; border-radius: 10px; font-size: 14px;
  background: var(--text); color: var(--bg); box-shadow: var(--shadow); z-index: 50;
}

/* ---------- responsive tweaks ---------- */
.brand-name, .pill { white-space: nowrap; }
@media (min-width: 881px) {
  .result-card { position: sticky; top: 78px; }
}
@media (max-width: 880px) {
  .result-card { min-height: 0; }
  .result-card .empty { min-height: 140px; }
  .transcript { min-height: 180px; max-height: 60vh; }
}
@media (max-width: 480px) {
  .topbar .pill { display: none; }
}

.format-hint { margin: 0; font-size: 12.5px; line-height: 1.6; color: var(--muted); }
.format-hint #formatList { color: var(--text); font-weight: 600; letter-spacing: .02em; }
