:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-2: #f0f1f6;
  --border: #e2e4ee;
  --text: #1b1d29;
  --muted: #6a6f85;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eceafe;
  --on-accent: #ffffff;
  --record: #e11d48;
  --record-soft: #ffe4ea;
  --ok: #059669;
  --ok-soft: #dcfce7;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --error: #dc2626;
  --error-soft: #fee2e2;
  --highlight: #fff4c2;
  --shadow: 0 1px 2px rgba(20, 22, 40, .04), 0 4px 16px rgba(20, 22, 40, .06);
  --radius: 14px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1117;
    --surface: #181b24;
    --surface-2: #20242f;
    --border: #2c3140;
    --text: #e8eaf2;
    --muted: #9298ad;
    --accent: #818cf8;
    --accent-hover: #a5b4fc;
    --accent-soft: #272a4a;
    --on-accent: #0f1117;
    --record: #fb7185;
    --record-soft: #3b1d26;
    --ok: #34d399;
    --ok-soft: #133328;
    --warn: #fbbf24;
    --warn-soft: #3a2e12;
    --error: #f87171;
    --error-soft: #3b1a1a;
    --highlight: #3a3415;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.wrap { width: 100%; max-width: 880px; margin: 0 auto; padding: 0 16px; }

svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

[hidden] { display: none !important; }

/* ---------- header / footer */
.site-header { background: var(--surface); border-bottom: 1px solid var(--border); margin-bottom: 24px; }
.site-header .wrap { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 60px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 17px; }
.brand svg { width: 24px; height: 24px; color: var(--accent); }
.server-status { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.server-status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.server-status.online::before { background: var(--ok); }
.server-status.busy::before { background: var(--warn); }
.server-status.offline::before { background: var(--error); }
.site-footer { color: var(--muted); font-size: 13px; text-align: center; padding-top: 8px; padding-bottom: 32px; }

/* ---------- cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 20px;
}
.card h2 { display: flex; align-items: center; gap: 10px; font-size: 16px; margin: 0 0 16px; }
.step {
  display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent); font-size: 13px; font-weight: 700;
}
.muted { color: var(--muted); }

/* ---------- tabs */
.tabs { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 4px; gap: 4px; margin-bottom: 16px; }
.tab {
  display: flex; align-items: center; gap: 8px; border: 0; background: transparent; color: var(--muted);
  font: inherit; font-weight: 550; padding: 8px 14px; border-radius: 7px; cursor: pointer;
}
.tab[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- dropzone */
.dropzone {
  display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center;
  border: 2px dashed var(--border); border-radius: 12px; padding: 32px 16px; cursor: pointer;
  color: var(--muted); transition: border-color .15s, background .15s;
}
.dropzone svg { width: 32px; height: 32px; color: var(--accent); margin-bottom: 4px; }
.dropzone strong { color: var(--text); font-size: 16px; }
.dropzone:hover, .dropzone.dragover { border-color: var(--accent); background: var(--accent-soft); }
.dropzone:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.dropzone input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

/* ---------- recorder */
.recorder { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; padding: 8px 0; }
.record-btn {
  display: inline-flex; align-items: center; gap: 10px; border: 0; cursor: pointer; font: inherit; font-weight: 600;
  background: var(--record-soft); color: var(--record); padding: 12px 20px; border-radius: 999px;
}
.record-btn .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--record); }
.record-btn.recording { background: var(--record); color: #fff; }
.record-btn.recording .dot { background: #fff; border-radius: 2px; animation: pulse 1.2s ease-in-out infinite; }
.record-btn:disabled { opacity: .5; cursor: not-allowed; }
.record-btn:focus-visible { outline: 2px solid var(--record); outline-offset: 3px; }
.record-info { display: flex; align-items: center; gap: 14px; flex: 1; min-width: 180px; }
.record-time { font-variant-numeric: tabular-nums; font-size: 22px; font-weight: 600; min-width: 64px; }
.meter { flex: 1; height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.meter-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--ok), var(--warn) 75%, var(--record)); transition: width .08s linear; }
@keyframes pulse { 50% { opacity: .35; } }

/* ---------- selected audio */
.selected { margin-top: 16px; padding: 14px; background: var(--surface-2); border-radius: 12px; }
.selected-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.selected-head svg { color: var(--accent); }
.selected-name { font-weight: 600; overflow-wrap: anywhere; }
.selected-head .link-btn { margin-left: auto; }
audio { width: 100%; height: 40px; }

/* ---------- form */
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 20px; }
.span-2 { grid-column: span 2; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.label { font-weight: 600; font-size: 14px; }
.hint { color: var(--muted); font-size: 12.5px; }
.hint.warn { color: var(--warn); }
select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 9px; padding: 9px 11px; width: 100%;
}
select:disabled { opacity: .6; }
textarea { resize: vertical; min-height: 44px; }
select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }

.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; min-height: 40px; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.slider { position: relative; width: 40px; height: 22px; border-radius: 99px; background: var(--border); transition: background .15s; flex: none; }
.slider::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider::after { transform: translateX(18px); }
.switch input:focus-visible + .slider { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch.small { min-height: 0; font-size: 14px; }

.advanced { margin-top: 18px; border-top: 1px solid var(--border); padding-top: 14px; }
.advanced summary { cursor: pointer; font-weight: 600; color: var(--accent); width: fit-content; }
.advanced[open] summary { margin-bottom: 16px; }

.actions { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-top: 20px; }

/* ---------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; font: inherit; font-weight: 600;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 9px 16px; border-radius: 9px; cursor: pointer; text-decoration: none;
}
.btn:hover { background: var(--surface-2); }
.btn:focus-visible, .chip:focus-visible, .link-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); padding: 11px 22px; }
.btn.primary:hover { background: var(--accent-hover); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.link-btn { border: 0; background: none; color: var(--accent); font: inherit; font-weight: 600; cursor: pointer; padding: 2px 4px; }

/* ---------- job */
.job-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.job-head h2 { margin: 0; min-width: 0; }
#job-title { overflow-wrap: anywhere; }
.status-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.spinner {
  width: 18px; height: 18px; border-radius: 50%; flex: none;
  border: 2.5px solid var(--accent-soft); border-top-color: var(--accent); animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.status-icon { width: 20px; height: 20px; border-radius: 50%; display: none; place-items: center; font-size: 12px; font-weight: 800; flex: none; }
.status-icon.ok { display: inline-grid; background: var(--ok-soft); color: var(--ok); }
.status-icon.ok::before { content: "✓"; }
.status-icon.bad { display: inline-grid; background: var(--error-soft); color: var(--error); }
.status-icon.bad::before { content: "!"; }
.status-icon.stopped { display: inline-grid; background: var(--surface-2); color: var(--muted); }
.status-icon.stopped::before { content: "■"; font-size: 9px; }

.progress { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin-bottom: 14px; }
.progress-fill { height: 100%; width: 0; background: var(--accent); border-radius: 99px; transition: width .4s ease; }
.progress.indeterminate .progress-fill {
  width: 35%; animation: slide 1.4s ease-in-out infinite;
}
.progress.done .progress-fill { background: var(--ok); }
@keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(290%); } }

.stats { display: flex; flex-wrap: wrap; gap: 8px 22px; margin: 0 0 14px; font-size: 13.5px; }
.stats div { display: flex; gap: 6px; }
.stats dt { color: var(--muted); }
.stats dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; }

.notice { padding: 12px 14px; border-radius: 10px; font-size: 14px; margin-bottom: 14px; }
.notice.warn { background: var(--warn-soft); color: var(--warn); }
.notice.error { background: var(--error-soft); color: var(--error); }

.result-tools { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.tool-group { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.download-group { display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.chip {
  font-size: 12.5px; font-weight: 700; letter-spacing: .02em; padding: 5px 10px; border-radius: 99px;
  background: var(--accent-soft); color: var(--accent); text-decoration: none; cursor: pointer;
}
.chip:hover { background: var(--accent); color: var(--on-accent); }
#result-audio { margin-bottom: 12px; }

.transcript { border-top: 1px solid var(--border); }
.transcript:empty { border-top: 0; }
.seg { display: flex; align-items: baseline; gap: 14px; padding: 8px 6px; border-bottom: 1px solid var(--border); border-radius: 6px; }
.seg:last-child { border-bottom: 0; }
.seg.active { background: var(--highlight); }
.seg.new { animation: fadein .5s ease; }
.seg-time {
  flex: none; border: 0; background: none; color: var(--accent); font: inherit; font-size: 12.5px;
  font-variant-numeric: tabular-nums; padding: 2px 0; cursor: pointer; min-width: 56px; text-align: left;
}
.seg-time:disabled { color: var(--muted); cursor: default; }
.seg-text { margin: 0; overflow-wrap: anywhere; }
.transcript.no-ts .seg { display: inline; border: 0; padding: 0; }
.transcript.no-ts .seg-time { display: none; }
.transcript.no-ts .seg-text { display: inline; }
.transcript.no-ts .seg-text::after { content: " "; }
.transcript.no-ts { padding-top: 12px; line-height: 1.75; }
@keyframes fadein { from { background: var(--accent-soft); } }

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

@media (max-width: 640px) {
  .card { padding: 16px; }
  .grid { grid-template-columns: minmax(0, 1fr); }
  .span-2 { grid-column: auto; }
  .tabs { display: flex; }
  .tab { flex: 1; justify-content: center; }
  .btn.primary { width: 100%; }
  .seg { gap: 10px; }
}
