:root {
  --bg: #0b0d14;
  --bg-2: #11141f;
  --panel: rgba(23, 27, 41, 0.72);
  --panel-border: rgba(255, 255, 255, 0.07);
  --text: #eef0f6;
  --text-dim: #9aa1b5;
  --text-faint: #6b7288;
  --accent: #7c6cff;
  --accent-2: #4dd0ff;
  --accent-3: #ff6ec7;
  --green: #34d399;
  --red: #f87171;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 20px 60px -20px rgba(0, 0, 0, 0.7);
  --grad: linear-gradient(135deg, var(--accent), var(--accent-2));
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
}

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

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", system-ui, sans-serif;
  line-height: 1.5;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* Background layers */
.bg-grid {
  position: fixed; inset: 0; z-index: -3;
  background-image:
    linear-gradient(rgba(255,255,255,0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.025) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: radial-gradient(ellipse 90% 70% at 50% 0%, #000 40%, transparent 100%);
}
.bg-glow {
  position: fixed; z-index: -2; border-radius: 50%;
  filter: blur(120px); opacity: 0.35; pointer-events: none;
}
.bg-glow--1 { width: 520px; height: 520px; top: -180px; left: -120px; background: var(--accent); }
.bg-glow--2 { width: 460px; height: 460px; bottom: -160px; right: -120px; background: var(--accent-2); opacity: 0.22; }

/* Top bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  max-width: 1180px; margin: 0 auto; padding: 22px 28px 8px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 42px; height: 42px; border-radius: 12px;
  background: var(--grad); color: #fff;
  display: grid; place-items: center;
  box-shadow: 0 8px 24px -6px rgba(124, 108, 255, 0.7);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-name { font-weight: 800; font-size: 17px; letter-spacing: -0.02em; }
.brand-name em { font-style: normal; background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.brand-sub { font-size: 12px; color: var(--text-faint); }
.topbar-right { display: flex; align-items: center; gap: 10px; }

.badge-live {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 12.5px; color: var(--text-dim);
  padding: 6px 12px; border-radius: 999px;
  background: rgba(255,255,255,0.04); border: 1px solid var(--panel-border);
}
.badge-live .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-faint); }
.badge-live.ok .dot { background: var(--green); box-shadow: 0 0 10px var(--green); }
.badge-live.err .dot { background: var(--red); box-shadow: 0 0 10px var(--red); }

/* Layout */
.layout {
  display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 0.95fr);
  gap: 22px; max-width: 1180px; margin: 14px auto 80px; padding: 0 28px;
  align-items: start;
}
@media (max-width: 900px) { .layout { grid-template-columns: 1fr; } }

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 26px;
  backdrop-filter: blur(14px);
  box-shadow: var(--shadow);
}

.panel-head h1 { font-size: 28px; font-weight: 800; letter-spacing: -0.03em; }
.panel-head .grad { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.panel-head p { color: var(--text-dim); font-size: 14px; margin-top: 4px; }

/* Fields */
.field { margin-top: 20px; }
.field label, .field-label label {
  display: block; font-size: 12.5px; font-weight: 600;
  color: var(--text-dim); margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.04em;
}
.field-label { display: flex; align-items: center; justify-content: space-between; }
.field-label label { margin-bottom: 8px; }
.muted { color: var(--text-faint); text-transform: none; letter-spacing: 0; font-weight: 500; }
.field-actions { display: flex; gap: 6px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 560px) { .grid-2 { grid-template-columns: 1fr; } }

select, input[type="text"], input[type="password"] {
  width: 100%; padding: 11px 14px;
  background: rgba(0,0,0,0.28); color: var(--text);
  border: 1px solid var(--panel-border); border-radius: var(--radius-sm);
  font-size: 14px; font-family: inherit; outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
select:focus, input:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(124, 108, 255, 0.18);
}
select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%239aa1b5' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 38px; cursor: pointer; }

/* Textarea */
.textarea-wrap { position: relative; }
textarea {
  width: 100%; min-height: 150px; padding: 14px 14px 34px;
  background: rgba(0,0,0,0.28); color: var(--text);
  border: 1px solid var(--panel-border); border-radius: var(--radius-sm);
  font-size: 15px; font-family: inherit; line-height: 1.55; resize: vertical;
  outline: none; transition: border-color 0.15s, box-shadow 0.15s;
}
.counter {
  position: absolute; right: 12px; bottom: 10px;
  font-size: 11.5px; color: var(--text-faint);
  font-family: "JetBrains Mono", monospace;
}
.counter.warn { color: var(--red); }

.presets { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.preset {
  padding: 6px 13px; font-size: 12.5px; cursor: pointer;
  background: rgba(124,108,255,0.09); color: #bdb6ff;
  border: 1px solid rgba(124,108,255,0.22); border-radius: 999px;
  transition: background 0.15s, transform 0.1s;
}
.preset:hover { background: rgba(124,108,255,0.18); transform: translateY(-1px); }

/* Input source toggle (Manual / From URL) */
.seg {
  display: inline-flex; gap: 4px; padding: 4px; margin-bottom: 10px;
  background: rgba(0,0,0,0.3); border: 1px solid var(--panel-border); border-radius: 999px;
}
.seg-btn {
  padding: 6px 16px; font-size: 12.5px; font-weight: 600; font-family: inherit;
  color: var(--text-dim); background: transparent; border: none; border-radius: 999px;
  cursor: pointer; transition: all 0.15s;
}
.seg-btn:hover { color: var(--text); }
.seg-btn.active {
  color: #fff; background: var(--grad);
  box-shadow: 0 4px 14px -4px rgba(124,108,255,0.7);
}

.url-row { display: flex; gap: 8px; margin-bottom: 10px; }
.url-row input { flex: 1; }
.btn-fetch { flex-shrink: 0; padding: 11px 16px; }
.btn-fetch:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-spinner-sm { width: 14px; height: 14px; border-width: 2px; }

/* Voice grid */
.voice-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; }
.voice-card {
  padding: 9px 6px; text-align: center; cursor: pointer;
  background: rgba(0,0,0,0.22); border: 1px solid var(--panel-border);
  border-radius: var(--radius-sm); font-size: 12.5px; font-weight: 600;
  color: var(--text-dim); transition: all 0.15s; position: relative;
}
.voice-card .swatch {
  width: 22px; height: 22px; border-radius: 50%; margin: 0 auto 6px;
  display: grid; place-items: center;
}
.voice-card:hover { border-color: rgba(124,108,255,0.5); transform: translateY(-1px); }
.voice-card.active {
  border-color: var(--accent); color: #fff;
  background: rgba(124,108,255,0.14);
  box-shadow: 0 0 0 3px rgba(124,108,255,0.16);
}
.voice-card.active::after {
  content: "✓"; position: absolute; top: 5px; right: 7px;
  font-size: 10px; color: var(--green);
}
.voice-custom { margin-top: 10px; }

/* Range */
input[type="range"] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 6px;
  border-radius: 999px; background: linear-gradient(90deg, var(--accent), var(--accent-2));
  outline: none; cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 20px; height: 20px; border-radius: 50%;
  background: #fff; border: 3px solid var(--accent); cursor: pointer;
  box-shadow: 0 2px 10px rgba(0,0,0,0.5); transition: transform 0.1s;
}
input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.12); }
.range-labels { display: flex; justify-content: space-between; font-size: 11px; color: var(--text-faint); margin-top: 6px; }
#speedVal { font-weight: 700; color: var(--accent-2); font-family: "JetBrains Mono", monospace; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 18px; font-size: 14px; font-weight: 600; font-family: inherit;
  border-radius: var(--radius-sm); border: 1px solid transparent; cursor: pointer;
  transition: all 0.15s; color: var(--text);
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary {
  background: var(--grad); color: #fff;
  box-shadow: 0 10px 30px -8px rgba(124,108,255,0.7);
}
.btn-primary:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 14px 34px -8px rgba(124,108,255,0.85); }
.btn-primary:active:not(:disabled) { transform: translateY(0); }
.btn-ghost { background: rgba(255,255,255,0.05); border-color: var(--panel-border); }
.btn-ghost:hover { background: rgba(255,255,255,0.1); }
.btn-generate { width: 100%; margin-top: 24px; padding: 15px; font-size: 15px; }
.chip-chip {
  padding: 4px 10px; font-size: 11.5px; cursor: pointer;
  background: rgba(255,255,255,0.05); color: var(--text-dim);
  border: 1px solid var(--panel-border); border-radius: 999px; transition: background 0.15s;
}
.chip-chip:hover { background: rgba(255,255,255,0.12); color: var(--text); }

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

.hint { margin-top: 10px; font-size: 12.5px; color: var(--text-faint); text-align: center; min-height: 18px; }
.hint.error { color: var(--red); }

/* Player */
.player { position: sticky; top: 20px; }
.player-empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 18px; min-height: 300px; color: var(--text-faint);
}
.orb { display: flex; align-items: center; gap: 5px; height: 56px; }
.orb .bar {
  width: 7px; height: 14px; border-radius: 999px; background: var(--accent);
  animation: bounce 1.2s ease-in-out infinite;
}
.orb .bar:nth-child(2) { animation-delay: 0.1s; background: var(--accent-2); }
.orb .bar:nth-child(3) { animation-delay: 0.2s; }
.orb .bar:nth-child(4) { animation-delay: 0.3s; background: var(--accent-2); }
.orb .bar:nth-child(5) { animation-delay: 0.4s; }
@keyframes bounce { 0%,100% { height: 14px; } 50% { height: 46px; } }

.player-ready { display: flex; flex-direction: column; gap: 16px; }
#waveform {
  width: 100%; height: 120px; border-radius: var(--radius-sm);
  background: rgba(0,0,0,0.3); border: 1px solid var(--panel-border);
}
audio { width: 100%; }
.player-meta { font-size: 12.5px; color: var(--text-dim); }
.player-meta strong { color: var(--text); }
.player-actions { display: flex; gap: 10px; }

/* History */
.history { margin-top: 26px; }
.history-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.history-head h2 { font-size: 16px; font-weight: 700; }
.history-list { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.history-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  background: rgba(0,0,0,0.2); border: 1px solid var(--panel-border);
  border-radius: var(--radius-sm); cursor: pointer; transition: all 0.15s;
}
.history-item:hover { border-color: rgba(124,108,255,0.4); background: rgba(124,108,255,0.06); }
.history-item .play-icon {
  width: 30px; height: 30px; border-radius: 50%; flex-shrink: 0;
  background: var(--grad); color: #fff; display: grid; place-items: center; font-size: 12px;
}
.history-item .hi-text { flex: 1; min-width: 0; }
.history-item .hi-text .t { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 13px; }
.history-item .hi-text .m { font-size: 11px; color: var(--text-faint); }
.history-item .hi-del {
  background: none; border: none; color: var(--text-faint); cursor: pointer; font-size: 15px; padding: 4px;
}
.history-item .hi-del:hover { color: var(--red); }

/* Modal */
.modal { position: fixed; inset: 0; z-index: 50; 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-card {
  position: relative; width: min(440px, calc(100vw - 40px));
  background: #161a28; border: 1px solid var(--panel-border); border-radius: var(--radius);
  padding: 24px; box-shadow: var(--shadow); animation: pop 0.18s ease;
}
@keyframes pop { from { transform: scale(0.96); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.modal-head h2 { font-size: 18px; font-weight: 700; }
.modal-close { background: none; border: none; color: var(--text-dim); font-size: 26px; cursor: pointer; line-height: 1; }
.modal-close:hover { color: #fff; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }
.key-row { display: flex; gap: 8px; }
.key-row input { flex: 1; }

/* Toast */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #1c2130; border: 1px solid var(--panel-border); color: var(--text);
  padding: 12px 20px; border-radius: 999px; font-size: 13.5px;
  box-shadow: var(--shadow); z-index: 60; animation: pop 0.2s ease;
}
.toast[hidden] { display: none; }

a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }
