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

:root {
  --bg:          #0f0f13;
  --bg-card:     #18181f;
  --bg-card2:    #1e1e27;
  --bg-input:    #12121a;
  --border:      #2a2a38;
  --border-focus:#6366f1;
  --primary:     #6366f1;
  --primary-h:   #5254cc;
  --primary-glow:rgba(99,102,241,.35);
  --accent:      #8b5cf6;
  --text:        #e8e8f0;
  --text-muted:  #7a7a9a;
  --text-dim:    #4a4a6a;
  --success:     #22c55e;
  --error:       #ef4444;
  --error-bg:    rgba(239,68,68,.1);
  --radius:      12px;
  --radius-sm:   8px;
  --shadow:      0 4px 24px rgba(0,0,0,.4);
  --font:        'Inter', system-ui, sans-serif;
  --transition:  .2s ease;
}

html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  line-height: 1.6;
}

/* ── Header ──────────────────────────────────────────────── */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(15,15,19,.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  max-width: 900px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo { display: flex; align-items: center; gap: 10px; }
.logo-text { font-size: 1.1rem; letter-spacing: -.01em; }
.logo-text strong { color: var(--primary); }

.header-actions { display: flex; align-items: center; gap: 12px; }

.badge {
  font-size: .72rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  letter-spacing: .03em;
  text-transform: uppercase;
}
.badge--loading { background: rgba(120,120,160,.15); color: var(--text-muted); }
.badge--ok      { background: rgba(34,197,94,.12);  color: var(--success); }
.badge--error   { background: rgba(239,68,68,.12);  color: var(--error); }

.btn-ghost {
  font-size: .85rem;
  color: var(--text-muted);
  text-decoration: none;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  transition: color var(--transition), background var(--transition);
}
.btn-ghost:hover { color: var(--text); background: var(--bg-card2); }

/* ── Layout ──────────────────────────────────────────────── */
.main { flex: 1; padding: 40px 24px 60px; }

.container { max-width: 900px; margin: 0 auto; display: flex; flex-direction: column; gap: 24px; }

/* ── Card ────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  box-shadow: var(--shadow);
}

.card-header { margin-bottom: 28px; }
.card-header h1 { font-size: 1.5rem; font-weight: 700; letter-spacing: -.02em; }
.card-header p  { margin-top: 4px; color: var(--text-muted); font-size: .9rem; }

/* ── Fields ──────────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 8px; }

.field label {
  font-size: .83rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.label-value {
  font-size: .95rem;
  font-weight: 700;
  color: var(--primary);
  text-transform: none;
  letter-spacing: 0;
}

.textarea-wrapper { position: relative; }

textarea {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  font-size: .95rem;
  padding: 14px 16px 36px;
  resize: vertical;
  min-height: 140px;
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}
textarea:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--primary-glow);
}
textarea::placeholder { color: var(--text-dim); }

.char-count {
  position: absolute;
  bottom: 10px;
  right: 14px;
  font-size: .75rem;
  color: var(--text-dim);
  pointer-events: none;
  transition: color var(--transition);
}
.char-count.warn { color: #f59e0b; }
.char-count.danger { color: var(--error); }

select {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  font-size: .93rem;
  padding: 11px 14px;
  cursor: pointer;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%237a7a9a' stroke-width='2'%3E%3Cpolyline points='6,9 12,15 18,9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}
select:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--primary-glow);
}
select option, select optgroup { background: #1a1a24; }

/* ── Controls grid ───────────────────────────────────────── */
.controls-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin: 20px 0;
}
.field--full { grid-column: 1 / -1; }

/* ── Range ───────────────────────────────────────────────── */
.range-wrapper {
  display: flex;
  align-items: center;
  gap: 10px;
}
.range-label { font-size: .78rem; color: var(--text-dim); white-space: nowrap; }

input[type="range"] {
  flex: 1;
  -webkit-appearance: none;
  height: 4px;
  background: var(--bg-card2);
  border-radius: 999px;
  outline: none;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
  transition: box-shadow var(--transition);
}
input[type="range"]:hover::-webkit-slider-thumb {
  box-shadow: 0 0 0 5px var(--primary-glow);
}

.range-ticks {
  display: flex;
  justify-content: space-between;
  padding: 0 4px;
  font-size: .72rem;
  color: var(--text-dim);
  margin-top: 4px;
}

/* ── Buttons ─────────────────────────────────────────────── */
.btn-primary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 14px 24px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), box-shadow var(--transition), transform .1s;
  margin-top: 4px;
}
.btn-primary:hover:not(:disabled) {
  background: var(--primary-h);
  box-shadow: 0 4px 20px var(--primary-glow);
}
.btn-primary:active:not(:disabled) { transform: scale(.98); }
.btn-primary:disabled { opacity: .45; cursor: not-allowed; }

.btn-secondary {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: .85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
}
.btn-secondary:hover { color: var(--text); border-color: var(--text-muted); background: var(--bg-card2); }

/* ── Loading ─────────────────────────────────────────────── */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 20px;
  color: var(--text-muted);
  font-size: .9rem;
}

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Player ──────────────────────────────────────────────── */
.player-section { margin-top: 20px; animation: fadeUp .3s ease; }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

.player-card {
  background: var(--bg-card2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.player-info {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-muted);
}
.player-info svg { flex-shrink: 0; }
.player-label { font-weight: 600; color: var(--text); font-size: .9rem; }
.player-duration { font-size: .8rem; color: var(--text-muted); }

audio {
  width: 100%;
  height: 36px;
  filter: invert(1) hue-rotate(180deg) brightness(.8);
  border-radius: 4px;
}

/* ── Error banner ────────────────────────────────────────── */
.error-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 16px;
  padding: 14px 16px;
  background: var(--error-bg);
  border: 1px solid rgba(239,68,68,.25);
  border-radius: var(--radius-sm);
  color: var(--error);
  font-size: .88rem;
  animation: fadeUp .25s ease;
}

/* ── Info grid ───────────────────────────────────────────── */
.info-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}

.info-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
  transition: border-color var(--transition), transform var(--transition);
}
.info-card:hover { border-color: var(--primary); transform: translateY(-2px); }

.info-icon { font-size: 1.6rem; margin-bottom: 10px; }
.info-card h3 { font-size: .95rem; font-weight: 600; margin-bottom: 6px; }
.info-card p { font-size: .8rem; color: var(--text-muted); line-height: 1.5; }
.info-card code {
  background: var(--bg-input);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: .78rem;
  color: var(--primary);
}

/* ── Code card ───────────────────────────────────────────── */
.code-card { position: relative; }
.code-card h3 { font-size: 1rem; font-weight: 600; margin-bottom: 16px; }

pre {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px 18px;
  overflow-x: auto;
  font-size: .82rem;
  line-height: 1.7;
}
code { font-family: 'Fira Code', 'Cascadia Code', monospace; color: #a5b4fc; }

.btn-copy {
  position: absolute;
  top: 28px;
  right: 28px;
  background: var(--bg-card2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  padding: 5px 12px;
  font-size: .78rem;
  font-family: var(--font);
  cursor: pointer;
  transition: all var(--transition);
}
.btn-copy:hover { color: var(--text); border-color: var(--text-muted); }

/* ── Footer ──────────────────────────────────────────────── */
.footer {
  text-align: center;
  padding: 20px 24px;
  border-top: 1px solid var(--border);
  font-size: .8rem;
  color: var(--text-dim);
}
.footer a { color: var(--text-muted); text-decoration: none; }
.footer a:hover { color: var(--primary); }

/* ── Tabs ────────────────────────────────────────────────── */
.tabs {
  display: flex;
  gap: 2px;
  margin-bottom: 24px;
  border-bottom: 1px solid var(--border);
}
.tab {
  background: none;
  border: none;
  color: var(--text-muted);
  font-family: var(--font);
  font-size: .88rem;
  font-weight: 600;
  padding: 8px 20px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color var(--transition), border-color var(--transition);
  letter-spacing: .01em;
}
.tab:hover { color: var(--text); }
.tab--active { color: var(--primary); border-bottom-color: var(--primary); }

/* ── Mode panels ─────────────────────────────────────────── */
.mode-desc {
  font-size: .85rem;
  color: var(--text-muted);
  margin-bottom: 16px;
  line-height: 1.55;
}

/* ── Segments list ───────────────────────────────────────── */
.segments-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 10px;
}

.segment-item {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  transition: border-color var(--transition);
}
.segment-item:focus-within { border-color: var(--border-focus); }

.segment-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 12px;
  background: var(--bg-card2);
  border-bottom: 1px solid var(--border);
  gap: 10px;
  flex-wrap: wrap;
}

.segment-num {
  font-size: .72rem;
  font-weight: 700;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: .07em;
  white-space: nowrap;
}

.segment-meta {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
}

.seg-voice, .seg-lang {
  font-size: .82rem;
  padding: 4px 28px 4px 9px;
  height: 30px;
  background-size: 10px;
  background-position: right 8px center;
}

.seg-remove {
  background: none;
  border: 1px solid transparent;
  color: var(--text-dim);
  border-radius: 6px;
  padding: 4px 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  transition: all var(--transition);
  line-height: 0;
}
.seg-remove:hover {
  color: var(--error);
  border-color: rgba(239,68,68,.3);
  background: rgba(239,68,68,.08);
}

.seg-text {
  width: 100%;
  background: transparent;
  border: none;
  border-radius: 0;
  color: var(--text);
  font-family: var(--font);
  font-size: .9rem;
  padding: 12px 14px;
  resize: vertical;
  min-height: 80px;
  outline: none;
}
.seg-text:focus { box-shadow: none; }
.seg-text::placeholder { color: var(--text-dim); }

/* ── Add segment button ──────────────────────────────────── */
.btn-add-segment {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  width: 100%;
  padding: 10px;
  background: transparent;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-family: var(--font);
  font-size: .85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  margin-bottom: 20px;
}
.btn-add-segment:hover {
  color: var(--primary);
  border-color: var(--primary);
  background: rgba(99,102,241,.05);
}

/* ── Multi controls ──────────────────────────────────────── */
.multi-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

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

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 700px) {
  .controls-grid { grid-template-columns: 1fr; }
  .multi-controls { grid-template-columns: 1fr; }
  .info-grid { grid-template-columns: 1fr 1fr; }
  .card { padding: 20px; }
  .btn-copy { position: static; margin-top: 12px; width: 100%; }
  .segment-header { flex-direction: column; align-items: flex-start; }
  .segment-meta { width: 100%; }
  .seg-voice, .seg-lang { flex: 1; }
}

@media (max-width: 420px) {
  .info-grid { grid-template-columns: 1fr; }
  .header-inner { flex-direction: column; gap: 10px; }
}
