:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1f2330;
  --border: #2a2f3d;
  --text: #e6e9ef;
  --text-dim: #9aa3b2;
  --primary: #5b8cff;
  --primary-hover: #7aa1ff;
  --success: #4ade80;
  --danger: #ef4444;
  --warn: #fbbf24;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

body { display: flex; flex-direction: column; min-height: 100vh; }

/* ===== Top bar ===== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

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

.logo {
  font-size: 28px;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #5b8cff, #8b5bff);
  border-radius: 12px;
}

.brand h1 { font-size: 17px; font-weight: 600; }
.subtitle { color: var(--text-dim); font-size: 12px; margin-top: 2px; }

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.engine-badge {
  font-size: 11px;
  color: var(--text-dim);
  padding: 4px 10px;
  background: var(--panel-2);
  border-radius: 999px;
  border: 1px solid var(--border);
}
.engine-badge.ai { color: var(--success); border-color: var(--success); }

.status {
  font-size: 12px;
  color: var(--text-dim);
  padding: 6px 12px;
  background: var(--panel-2);
  border-radius: 999px;
  border: 1px solid var(--border);
}
.status.busy { color: var(--warn); border-color: var(--warn); }
.status.ok   { color: var(--success); border-color: var(--success); }
.status.err  { color: var(--danger); border-color: var(--danger); }

/* ===== Modal ===== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
}
.modal[hidden] { display: none; }
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
}
.modal-panel {
  position: relative;
  width: min(560px, 92vw);
  max-height: 86vh;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.modal-head h3 { font-size: 16px; }
.modal-tip {
  font-size: 12px;
  color: var(--text-dim);
  background: var(--panel-2);
  padding: 10px 12px;
  border-radius: 8px;
  border-left: 3px solid var(--primary);
  margin-bottom: 16px;
  line-height: 1.5;
}
.form-row {
  display: grid;
  grid-template-columns: 100px 1fr;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}
.form-row label { font-size: 13px; color: var(--text-dim); }
.form-row select,
.form-row input {
  width: 100%;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  font-family: inherit;
  font-size: 13px;
}
.form-row select:focus,
.form-row input:focus { outline: none; border-color: var(--primary); }
.form-help {
  grid-column: 2;
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 4px;
}
.form-help.ok { color: var(--success); }
.form-help.err { color: var(--danger); }
.form-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 4px;
}
.help-block {
  margin-top: 16px;
  background: var(--panel-2);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 12px;
  color: var(--text-dim);
}
.help-block summary {
  cursor: pointer;
  color: var(--text);
  font-weight: 500;
  padding: 2px 0;
}
.help-content { padding-top: 10px; line-height: 1.6; }
.help-content ol { padding-left: 20px; margin: 6px 0; }
.help-content a { color: var(--primary); }

/* ===== Layout ===== */
.layout {
  flex: 1;
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 18px;
  padding: 20px;
  min-height: 0;
}
@media (max-width: 1000px) { .layout { grid-template-columns: 1fr; } }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  overflow: hidden;
}

.panel h2 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.muted { color: var(--text-dim); font-weight: 400; text-transform: none; letter-spacing: 0; }

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 4px;
}
.head-actions { display: flex; gap: 8px; }

/* ===== Dropzone ===== */
.dropzone {
  border: 2px dashed var(--border);
  border-radius: 10px;
  min-height: 120px;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: all 0.2s;
  background: var(--panel-2);
  padding: 12px;
}
.dropzone:hover, .dropzone.dragover {
  border-color: var(--primary);
  background: rgba(91, 140, 255, 0.05);
}
.dropzone-inner { text-align: center; color: var(--text-dim); }
.dropzone-inner .icon { font-size: 32px; margin-bottom: 6px; }
.dropzone-inner .hint { font-size: 12px; margin-top: 4px; opacity: 0.7; }

/* ===== Thumbs ===== */
.thumbs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  min-height: 0;
}
.thumb {
  position: relative;
  width: 80px;
  height: 80px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--panel-2);
  flex-shrink: 0;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb .badge {
  position: absolute;
  left: 4px;
  top: 4px;
  background: rgba(0,0,0,0.7);
  color: white;
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 999px;
}
.thumb .status-dot {
  position: absolute;
  right: 4px;
  top: 4px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--text-dim);
}
.thumb.done .status-dot { background: var(--success); }
.thumb.processing .status-dot { background: var(--warn); animation: pulse 1s infinite; }
.thumb.error .status-dot { background: var(--danger); }
.thumb .remove {
  position: absolute;
  right: 2px;
  bottom: 2px;
  background: rgba(0,0,0,0.7);
  color: white;
  border: 0;
  width: 20px;
  height: 20px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  display: grid;
  place-items: center;
  padding: 0;
}
.thumb .remove:hover { background: var(--danger); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ===== Buttons ===== */
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

button {
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  padding: 9px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s;
}
button.small { padding: 6px 10px; font-size: 12px; }
button:hover:not(:disabled) { background: #262b3a; }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.primary { background: var(--primary); border-color: var(--primary); color: white; }
button.primary:hover:not(:disabled) { background: var(--primary-hover); border-color: var(--primary-hover); }
button.ghost { background: transparent; }

/* ===== Progress ===== */
.progress { display: flex; flex-direction: column; gap: 4px; }
.progress-bar { height: 5px; background: var(--panel-2); border-radius: 999px; overflow: hidden; }
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), #8b5bff);
  width: 0%;
  transition: width 0.2s;
}
.progress-text { font-size: 11px; color: var(--text-dim); text-align: center; }

/* ===== Sentences list ===== */
.sentences {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-right: 4px;
  min-height: 200px;
}
.sentences::-webkit-scrollbar { width: 6px; }
.sentences::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.empty {
  color: var(--text-dim);
  text-align: center;
  padding: 40px 20px;
  font-size: 13px;
}

.sentence {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  transition: all 0.15s;
}
.sentence:hover { border-color: var(--primary); }
.sentence.playing {
  border-color: var(--primary);
  background: rgba(91, 140, 255, 0.08);
  box-shadow: 0 0 0 1px var(--primary);
}
.sentence .idx {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  background: var(--panel);
  border-radius: 6px;
  font-size: 12px;
  color: var(--text-dim);
  font-weight: 600;
}
.sentence .text {
  flex: 1;
  font-size: 14px;
  line-height: 1.55;
  color: var(--text);
  word-break: break-word;
}
.sentence .text .src { color: var(--text-dim); font-size: 11px; margin-left: 6px; }
.sentence .speak-btn {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  padding: 0;
  display: grid;
  place-items: center;
  font-size: 16px;
  border-radius: 8px;
}
.sentence .speak-btn.playing-btn { background: var(--primary); border-color: var(--primary); }

/* ===== Voice controls ===== */
.voice-controls {
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--panel-2);
  padding: 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
}
.control-row {
  display: grid;
  grid-template-columns: 110px 1fr;
  align-items: center;
  gap: 12px;
}
.control-row label { font-size: 13px; color: var(--text-dim); }
.checkbox-row { display: flex; }
.check-label { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text); cursor: pointer; }
.check-label input { accent-color: var(--primary); }

.voice-hint {
  display: none;
  font-size: 12px;
  color: var(--text-dim);
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 3px solid var(--primary);
  padding: 8px 10px;
  border-radius: 6px;
  line-height: 1.5;
}
.voice-hint b { color: var(--primary); }

select, input[type="number"], textarea {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  font-family: inherit;
  font-size: 13px;
}
input[type="range"] { width: 100%; accent-color: var(--primary); }
select:focus, input:focus, textarea:focus { outline: none; border-color: var(--primary); }

textarea {
  width: 100%;
  min-height: 180px;
  font-size: 13px;
  line-height: 1.5;
  resize: vertical;
}

.meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-dim);
}

/* ===== Footer ===== */
.footer {
  text-align: center;
  padding: 10px;
  color: var(--text-dim);
  font-size: 11px;
  border-top: 1px solid var(--border);
}
