/* ===== Reset & Variables ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f0f13;
  --card: #1a1a24;
  --card-hover: #222230;
  --border: #2e2e40;
  --accent: #6c63ff;
  --accent-hover: #857cff;
  --accent-dark: #4a44cc;
  --text: #e2e2f0;
  --text-muted: #888899;
  --danger: #ff4f6a;
  --success: #4cde9e;
  --warning: #ffb84c;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0,0,0,.45);
  --font: "PingFang TC", "Microsoft JhengHei", "Noto Sans TC", system-ui, sans-serif;
}

html { font-size: 16px; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  min-height: 100vh;
  line-height: 1.6;
}

/* ===== Header ===== */
.header {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.header-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0.85rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.logo {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  background: linear-gradient(135deg, #a89cff 0%, #6c63ff 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* ===== Badge ===== */
.badge {
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.3rem 0.75rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--card-hover);
  white-space: nowrap;
}
.badge--loading { color: var(--text-muted); }
.badge--cuda  { color: #4cde9e; border-color: #4cde9e44; background: #4cde9e11; }
.badge--mps   { color: #ff9a4c; border-color: #ff9a4c44; background: #ff9a4c11; }
.badge--cpu   { color: var(--text-muted); }
.badge--rocm  { color: #ff6363; border-color: #ff636344; background: #ff636311; }
.badge--xpu   { color: #4cb3ff; border-color: #4cb3ff44; background: #4cb3ff11; }

/* ===== Layout ===== */
.layout {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1.75rem 1.5rem 3rem;
  display: grid;
  grid-template-columns: 1fr 1fr 0.75fr;
  gap: 1.5rem;
  align-items: start;
}
@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr 1fr; }
  #panelPolyphone { grid-column: 1 / -1; }
}
@media (max-width: 768px) {
  .layout { grid-template-columns: 1fr; }
  #panelPolyphone { grid-column: auto; }
}

/* ===== Panel ===== */
.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
}
.panel-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
  padding-bottom: 0.6rem;
  border-bottom: 1px solid var(--border);
}
.sub-title {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: 0.25rem;
}

/* ===== Drop Zone ===== */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 2rem 1.5rem;
  text-align: center;
  cursor: pointer;
  transition: border-color .2s, background .2s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}
.drop-zone:hover, .drop-zone.drag-over {
  border-color: var(--accent);
  background: #6c63ff0f;
}
.drop-icon { width: 40px; height: 40px; color: var(--accent); }
.drop-text { font-size: 0.9rem; color: var(--text-muted); }
.drop-text span { font-size: 0.8rem; }

.selected-file {
  font-size: 0.85rem;
  color: var(--success);
  background: #4cde9e11;
  border: 1px solid #4cde9e33;
  border-radius: var(--radius-sm);
  padding: 0.45rem 0.75rem;
}

/* ===== Forms ===== */
.form-row { display: flex; flex-direction: column; gap: 0.35rem; }
.form-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.form-input, .form-select, .form-textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.93rem;
  padding: 0.55rem 0.85rem;
  outline: none;
  transition: border-color .2s;
  width: 100%;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--accent);
}
.form-textarea { resize: vertical; min-height: 120px; }
.form-select option { background: var(--card); }

.char-count { font-size: 0.78rem; font-weight: 400; color: var(--text-muted); }
.char-count.warn { color: var(--warning); }
.char-count.danger { color: var(--danger); }

.form-label-hint { font-size: 0.72rem; font-weight: 400; color: var(--text-muted); }
.form-textarea--sm { min-height: 56px; }

.transcribe-row {
  display: flex;
  gap: 0.4rem;
  margin-top: 0.35rem;
  align-items: stretch;
}
.transcribe-model-select {
  flex: 0 0 auto;
  width: auto;
  font-size: 0.8rem;
  padding: 0.35rem 0.55rem;
}
.btn--transcribe {
  display: inline-flex;
  flex: 1;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 0.82rem;
  font-weight: 500;
  padding: 0.4rem 0.85rem;
  cursor: pointer;
  transition: color .15s, border-color .15s, background .15s;
}
.btn--transcribe:not(:disabled):hover {
  color: var(--accent);
  border-color: var(--accent);
  background: #6c63ff0d;
}
.btn--transcribe:disabled { opacity: 0.4; cursor: not-allowed; }

.engine-hint {
  font-size: 0.78rem;
  margin-top: 0.2rem;
  padding: 0.3rem 0.6rem;
  border-radius: var(--radius-sm);
  border-left: 3px solid;
}
.engine-hint--xtts { color: var(--text-muted); border-left-color: var(--accent); background: #6c63ff0a; }
.engine-hint--f5   { color: var(--success);    border-left-color: var(--success); background: #4cde9e0a; }

.voice-f5-badge {
  font-size: 0.62rem;
  font-weight: 700;
  padding: 0.1rem 0.3rem;
  border-radius: 3px;
  background: #6c63ff22;
  color: var(--accent);
  margin-left: 0.3rem;
  vertical-align: middle;
  letter-spacing: .02em;
}

/* ===== Radio group ===== */
.radio-group { display: flex; gap: 0.75rem; flex-wrap: wrap; }
.radio-label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.9rem;
  cursor: pointer;
  color: var(--text-muted);
  transition: color .15s;
}
.radio-label:has(input:checked) { color: var(--accent); }
.radio-label input[type="radio"] { accent-color: var(--accent); cursor: pointer; }

/* ===== Slider ===== */
.slider {
  width: 100%;
  accent-color: var(--accent);
  cursor: pointer;
  height: 4px;
}
.slider-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
}
.speed-value { font-size: 0.85rem; color: var(--accent); font-weight: 600; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.93rem;
  font-weight: 600;
  padding: 0.65rem 1.5rem;
  cursor: pointer;
  transition: background .2s, transform .1s, opacity .2s;
  width: 100%;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn--primary { background: var(--accent); color: #fff; }
.btn--primary:not(:disabled):hover { background: var(--accent-hover); }

.btn--accent { background: linear-gradient(135deg, #6c63ff 0%, #a89cff 100%); color: #fff; }
.btn--accent:not(:disabled):hover { background: linear-gradient(135deg, #857cff 0%, #bab3ff 100%); }

.btn--outline { background: transparent; border: 1px solid var(--accent); color: var(--accent); margin-top: 0.5rem; }
.btn--outline:not(:disabled):hover { background: #6c63ff15; }

.voice-actions { display: flex; align-items: center; gap: 0.4rem; flex-shrink: 0; }

.btn--preview {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--accent);
  border-radius: var(--radius-sm);
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background .15s, border-color .15s;
  flex-shrink: 0;
}
.btn--preview:hover { background: #6c63ff20; border-color: var(--accent); }

.btn--danger-sm {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--danger);
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  padding: 0.25rem 0.6rem;
  cursor: pointer;
  font-family: var(--font);
  transition: background .15s;
  white-space: nowrap;
}
.btn--danger-sm:hover { background: #ff4f6a15; border-color: var(--danger); }

/* ===== Spinner ===== */
.spinner {
  width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Progress ===== */
.progress-wrap { padding: 0.1rem 0; }
.progress-bar { background: var(--border); border-radius: 999px; height: 5px; overflow: hidden; }
.progress-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent) 0%, #a89cff 100%);
  transition: width .4s ease;
  width: 0%;
}

/* ===== Voice list ===== */
.voice-list { list-style: none; display: flex; flex-direction: column; gap: 0.5rem; }
.voice-empty { font-size: 0.85rem; color: var(--text-muted); text-align: center; padding: 0.75rem 0; }
.voice-item {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.85rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  transition: border-color .15s;
}
.voice-item:hover { border-color: var(--accent); }
.voice-item.selected { border-color: var(--accent); background: #6c63ff0d; }
.voice-info { display: flex; flex-direction: column; gap: 0.1rem; overflow: hidden; }
.voice-name { font-size: 0.92rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.voice-meta { font-size: 0.75rem; color: var(--text-muted); }

/* ===== Result section ===== */
.result-section { display: flex; flex-direction: column; gap: 0.75rem; }

/* ===== Custom audio player ===== */
.custom-player {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.65rem 0.9rem;
}
.player-btn {
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: 0.2rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color .15s, background .15s;
  flex-shrink: 0;
}
.player-btn:hover { color: var(--accent); background: #6c63ff18; }
.player-btn--sm { color: var(--text-muted); }
.player-time {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
  min-width: 2.4rem;
  text-align: center;
}
.player-track {
  flex: 1;
  height: 4px;
  background: var(--border);
  border-radius: 999px;
  position: relative;
  cursor: pointer;
}
.player-track:hover .player-thumb { opacity: 1; transform: translateX(-50%) scale(1); }
.player-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  width: 0%;
  pointer-events: none;
}
.player-thumb {
  position: absolute;
  top: 50%;
  left: 0%;
  transform: translateX(-50%) scale(0);
  width: 12px;
  height: 12px;
  background: var(--accent);
  border-radius: 50%;
  pointer-events: none;
  opacity: 0;
  transition: opacity .15s, transform .15s;
  margin-top: -6px;
}

/* ===== Toast ===== */
.toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  z-index: 999;
  pointer-events: none;
}
.toast {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.7rem 1rem;
  font-size: 0.88rem;
  max-width: 300px;
  box-shadow: var(--shadow);
  pointer-events: auto;
  transform: translateX(120%);
  animation: slideIn .3s ease forwards;
}
.toast.out { animation: slideOut .3s ease forwards; }
.toast--success { border-left: 3px solid var(--success); }
.toast--error   { border-left: 3px solid var(--danger); }
.toast--info    { border-left: 3px solid var(--accent); }

@keyframes slideIn { to { transform: translateX(0); } }
@keyframes slideOut { to { transform: translateX(120%); } }

/* ===== Panel title row (title + inline toggle) ===== */
.panel-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 0.6rem;
  border-bottom: 1px solid var(--border);
}
.panel-title-row .panel-title {
  padding-bottom: 0;
  border-bottom: none;
}

/* ===== Toggle pill ===== */
.toggle-pill {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.2rem 0.7rem;
  border-radius: 999px;
  border: 1px solid;
  cursor: pointer;
  transition: all .15s;
  font-family: var(--font);
  background: transparent;
  flex-shrink: 0;
}
.toggle-pill--on  { border-color: var(--success); color: var(--success); background: #4cde9e10; }
.toggle-pill--off { border-color: var(--border);  color: var(--text-muted); }

/* Dim panel body when polyphone is disabled */
#panelPolyphone.polyphone-disabled > *:not(.panel-title-row) {
  opacity: 0.4;
  pointer-events: none;
}

/* ===== Inline rename ===== */
.rename-form {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex: 1;
  min-width: 0;
}
.rename-input {
  flex: 1;
  min-width: 0;
  background: var(--bg);
  border: 1px solid var(--accent);
  border-radius: 4px;
  color: var(--text);
  font-family: var(--font);
  font-size: 0.85rem;
  padding: 0.15rem 0.4rem;
  outline: none;
}
.rename-ext {
  font-size: 0.82rem;
  color: var(--text-muted);
  flex-shrink: 0;
}
.btn--rename-ok { color: var(--success) !important; border-color: var(--success) !important; }
.btn--rename-ok:hover { background: #4cde9e18 !important; }

/* ===== Polyphone rules ===== */
.rule-form { display: flex; flex-direction: column; gap: 0.5rem; }
.rule-form-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.rule-input { flex: 1; min-width: 0; }
.rule-arrow { color: var(--text-muted); flex-shrink: 0; }

.rule-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.rule-actions .btn { flex: 1; }
.toggle-label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.82rem;
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}
.toggle-label input[type="checkbox"] { accent-color: var(--accent); cursor: pointer; }

.rule-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.rule-list { list-style: none; display: flex; flex-direction: column; gap: 0.45rem; }
.rule-item {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  transition: border-color .15s;
}
.rule-item:hover { border-color: var(--accent); }
.rule-item-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}
.rule-pair {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.88rem;
  overflow: hidden;
}
.rule-orig { color: var(--warning); font-weight: 600; }
.rule-sep  { color: var(--text-muted); font-size: 0.78rem; }
.rule-repl { color: var(--success); font-weight: 600; }
.rule-note { font-size: 0.75rem; color: var(--text-muted); padding-left: 0.1rem; }
.rule-del {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0 0.2rem;
  flex-shrink: 0;
  transition: color .15s;
}
.rule-del:hover { color: var(--danger); }

/* ===== Remove result button ===== */
.btn--remove {
  background: transparent;
  border: 1px solid var(--danger);
  color: var(--danger);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.88rem;
  font-weight: 600;
  padding: 0.5rem 1rem;
  cursor: pointer;
  transition: background .15s;
  width: 100%;
}
.btn--remove:hover { background: #ff4f6a18; }

/* ===== Output manager ===== */
.output-manager-wrap {
  max-width: 1400px;
  margin: 0 auto 2.5rem;
  padding: 0 1.5rem;
}
.output-manager-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.65rem 1rem;
  cursor: pointer;
  width: 100%;
  transition: border-color .2s;
}
.output-manager-toggle:hover { border-color: var(--accent); }
.output-count {
  background: var(--accent);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  border-radius: 999px;
  padding: 0.1rem 0.45rem;
  min-width: 1.4rem;
  text-align: center;
}
#outputChevron { margin-left: auto; transition: transform .2s; }
.output-manager-toggle.open #outputChevron { transform: rotate(180deg); }

.output-manager-panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.output-toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
}
.btn--icon {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  transition: color .15s, border-color .15s;
}
.btn--icon:hover { color: var(--accent); border-color: var(--accent); }

.output-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  max-height: 360px;
  overflow-y: auto;
}
.output-item {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.85rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  transition: border-color .15s;
}
.output-item:hover { border-color: var(--accent); }
.output-info { flex: 1; display: flex; flex-direction: column; gap: 0.1rem; overflow: hidden; min-width: 0; }
.output-name { font-size: 0.85rem; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.output-meta { font-size: 0.73rem; color: var(--text-muted); }
.output-actions { display: flex; gap: 0.35rem; flex-shrink: 0; }

.output-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.2rem;
  margin: 0.1rem 0;
}
.output-tag {
  font-size: 0.64rem;
  font-weight: 600;
  padding: 0.08rem 0.32rem;
  border-radius: 3px;
  border: 1px solid var(--border);
  background: var(--card-hover);
  color: var(--text-muted);
  white-space: nowrap;
  letter-spacing: .02em;
}
.output-tag--voice  { color: var(--accent);   background: #6c63ff12; border-color: #6c63ff35; }
.output-tag--engine { color: var(--success);  background: #4cde9e10; border-color: #4cde9e30; }
.output-tag--fmt    { color: var(--warning);  background: #ffb84c10; border-color: #ffb84c30; }
.output-tag--speed  { color: var(--text-muted); }

/* ===== Polyphone check result ===== */
.check-result {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.check-none {
  font-size: 0.83rem;
  color: var(--success);
  text-align: center;
  padding: 0.5rem 0;
}
.check-item {
  background: var(--bg);
  border: 1px solid var(--border);
  border-left: 3px solid var(--warning);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.75rem;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
}
.check-item-info { display: flex; flex-direction: column; gap: 0.15rem; overflow: hidden; }
.check-char { font-size: 1.1rem; font-weight: 700; color: var(--warning); }
.check-readings { font-size: 0.75rem; color: var(--text-muted); line-height: 1.4; }
.check-count { font-size: 0.72rem; color: var(--text-muted); margin-top: 0.1rem; }
.btn--add-rule {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--accent);
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  padding: 0.2rem 0.5rem;
  cursor: pointer;
  font-family: var(--font);
  transition: background .15s, border-color .15s;
  white-space: nowrap;
  flex-shrink: 0;
  align-self: center;
}
.btn--add-rule:hover { background: #6c63ff18; border-color: var(--accent); }

/* ===== Utility ===== */
.hidden { display: none !important; }
