/* VoxMorph — studio dark theme, RTL/LTR aware */
:root {
  --bg: #0f1117;
  --bg2: #131722;
  --panel: #171b26;
  --panel2: #1e2331;
  --line: #2a3142;
  --text: #e9ecf3;
  --muted: #9aa4b8;
  --accent: #7c5cff;
  --accent2: #22d3ee;
  --accent-grad: linear-gradient(135deg, #7c5cff 0%, #22d3ee 100%);
  --danger: #ff5c7a;
  --ok: #34d399;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  --font: "Segoe UI", "Segoe UI Variable Text", Tahoma, system-ui, -apple-system, "Noto Sans Arabic", "Noto Naskh Arabic", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font-family: var(--font); }
body { min-height: 100vh; display: flex; flex-direction: column; -webkit-font-smoothing: antialiased; }
button, input, select { font-family: inherit; font-size: inherit; color: inherit; }
h1, h2, h3 { margin: 0; font-weight: 700; }
h2 { font-size: 1.05rem; color: var(--muted); letter-spacing: .02em; margin-bottom: 14px; }
h3 { font-size: .95rem; color: var(--muted); margin: 14px 0 8px; }
p { margin: 0; }
a { color: var(--accent2); text-decoration: none; }
[hidden] { display: none !important; }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 22px; border-bottom: 1px solid var(--line); background: var(--bg2); position: sticky; top: 0; z-index: 5; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand h1 { font-size: 1.35rem; background: var(--accent-grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.logo { border-radius: 10px; }
.tagline { color: var(--muted); font-size: .85rem; }
.topbar-actions { display: flex; gap: 8px; }

.layout { display: grid; align-content: start; grid-template-columns: 1.15fr 1fr; grid-template-areas: "source voice" "music export"; gap: 18px; padding: 18px 22px; max-width: 1400px; margin: 0 auto; width: 100%; flex: 1; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); min-width: 0; }
.panel.source { grid-area: source; }
.panel.voice { grid-area: voice; }
.panel.export { grid-area: export; }
.panel.music { grid-area: music; }
@media (max-width: 980px) { .layout { grid-template-columns: 1fr; grid-template-areas: "source" "voice" "music" "export"; padding: 14px 16px; } }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--line); background: var(--panel2); color: var(--text); padding: 9px 14px; border-radius: 10px; cursor: pointer; transition: transform .08s ease, background .15s ease, border-color .15s ease, opacity .15s; white-space: nowrap; }
.btn:hover { border-color: #3a4358; background: #242a3a; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent-grad); border: none; color: #fff; font-weight: 600; box-shadow: 0 6px 18px rgba(124, 92, 255, .35); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.secondary { border-color: #3a4358; }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 10px; font-size: .85rem; }
.btn.big { padding: 12px 18px; font-size: 1rem; }
.btn .ic { width: 20px; height: 20px; }
.btn.recording { background: linear-gradient(135deg, #ff5c7a, #ff9a5c); box-shadow: 0 6px 18px rgba(255, 92, 122, .4); }
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: #fff; box-shadow: 0 0 0 3px rgba(255, 255, 255, .25); }
.btn.recording .rec-dot { animation: pulse 1s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .3; } }
.rec-time { font-variant-numeric: tabular-nums; font-weight: 600; }

.source-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.hint { color: var(--muted); font-size: .85rem; margin-top: 8px; }
.hint.small { font-size: .78rem; }

.mic-row { display: flex; align-items: center; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.mic-row label { color: var(--muted); font-size: .85rem; }
select, input[type="text"] { background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; color: var(--text); min-width: 120px; }
select:focus, input[type="text"]:focus { outline: 2px solid rgba(124, 92, 255, .6); outline-offset: 1px; }
.meter { position: relative; flex: 1; min-width: 120px; height: 10px; border-radius: 6px; background: #0b0e15; border: 1px solid var(--line); overflow: hidden; }
.meter-fill { position: absolute; inset-block: 0; inset-inline-start: 0; width: 0%; background: linear-gradient(90deg, #34d399, #fbbf24 70%, #ff5c7a); transition: width .05s linear; }
.meter-peak { position: absolute; inset-block: 0; width: 2px; background: #fff; inset-inline-start: 0; opacity: .8; }

.wave-wrap { direction: ltr; position: relative; margin-top: 14px; border-radius: 12px; background: #0b0e15; border: 1px solid var(--line); overflow: hidden; height: 180px; }
.wave-wrap canvas { width: 100%; height: 100%; display: block; }
.wave-empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: .9rem; text-align: center; padding: 12px; pointer-events: none; }
.playhead { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--accent2); box-shadow: 0 0 8px var(--accent2); pointer-events: none; left: 0; }
.trim-shade { position: absolute; top: 0; bottom: 0; background: rgba(15, 17, 23, .72); pointer-events: none; }
.trim-shade.start { left: 0; width: 0; }
.trim-shade.end { right: 0; width: 0; }
.wave-wrap.dragging { cursor: ew-resize; }

.trim-row { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-top: 10px; font-size: .85rem; color: var(--muted); }
.trim-row label { display: inline-flex; align-items: center; gap: 6px; }
.trim-row input[type="range"] { width: 140px; direction: ltr; }
.trim-row output { font-variant-numeric: tabular-nums; color: var(--text); min-width: 52px; }
.trim-label { font-weight: 600; }
.duration { margin-inline-start: auto; }

.transport { display: flex; align-items: center; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.transport .time { font-variant-numeric: tabular-nums; color: var(--muted); min-width: 60px; }
.status-chip { font-size: .78rem; color: var(--muted); padding: 4px 8px; border-radius: 999px; background: var(--panel2); border: 1px solid var(--line); }
.status-chip.busy { color: var(--accent2); border-color: rgba(34, 211, 238, .4); }
.status-chip.ok { color: var(--ok); border-color: rgba(52, 211, 153, .4); }
.status-chip:empty { display: none; }

.live-row { margin-top: 16px; padding-top: 12px; border-top: 1px dashed var(--line); }

/* Switch */
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .slider { width: 42px; height: 24px; border-radius: 999px; background: #2a3142; position: relative; transition: background .2s; flex: none; }
.switch .slider::after { content: ""; position: absolute; top: 3px; inset-inline-start: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .2s; }
.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider::after { transform: translateX(18px); }
[dir="rtl"] .switch input:checked + .slider::after { transform: translateX(-18px); }
.switch input:focus-visible + .slider { outline: 2px solid var(--accent2); }

/* Presets */
.presets { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
@media (max-width: 560px) { .presets { grid-template-columns: repeat(2, 1fr); } }
.preset { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 14px 8px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel2); cursor: pointer; text-align: center; color: var(--text); transition: border-color .15s, transform .08s, background .15s; }
.preset:hover { border-color: #3a4358; transform: translateY(-1px); }
.preset .pic { width: 40px; height: 40px; color: var(--accent2); }
.preset .pname { font-weight: 700; }
.preset .pdesc { color: var(--muted); font-size: .72rem; line-height: 1.3; }
.preset[aria-checked="true"] { border-color: var(--accent); background: linear-gradient(180deg, rgba(124, 92, 255, .22), rgba(124, 92, 255, .08)); box-shadow: 0 0 0 1px var(--accent) inset; }
.preset[aria-checked="true"] .pic { color: #fff; }

.control-row { display: flex; align-items: center; gap: 12px; margin-top: 16px; }
.control-row label { color: var(--muted); font-size: .9rem; min-width: 90px; }
.control-row input[type="range"] { flex: 1; }
.control-row output { min-width: 48px; text-align: center; font-variant-numeric: tabular-nums; }
.auto-row { justify-content: space-between; flex-wrap: wrap; }
.detected { font-size: .8rem; color: var(--accent2); }

input[type="range"] { -webkit-appearance: none; appearance: none; height: 6px; border-radius: 999px; background: #2a3142; outline: none; }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; border-radius: 50%; background: #fff; border: 3px solid var(--accent); cursor: pointer; box-shadow: 0 2px 6px rgba(0, 0, 0, .4); }
input[type="range"]:focus-visible::-webkit-slider-thumb { outline: 2px solid var(--accent2); }
input[type="range"]:disabled { opacity: .4; }

details.fine { margin-top: 16px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg2); }
details.fine summary { cursor: pointer; padding: 10px 14px; font-weight: 600; color: var(--muted); list-style: none; display: flex; align-items: center; gap: 8px; }
details.fine summary::before { content: "▸"; transition: transform .15s; display: inline-block; }
[dir="rtl"] details.fine summary::before { content: "◂"; }
details.fine[open] summary::before { transform: rotate(90deg); }
[dir="rtl"] details.fine[open] summary::before { transform: rotate(-90deg); }
details.fine > *:not(summary) { padding: 0 14px; }
details.fine > .fine-grid:last-of-type, details.fine .fine-actions { padding-bottom: 14px; }
.fine-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 18px; }
@media (max-width: 560px) { .fine-grid { grid-template-columns: 1fr; } }
.fine-grid > label { display: grid; grid-template-columns: 1fr auto; grid-template-areas: "name val" "range range"; gap: 4px 8px; font-size: .82rem; color: var(--muted); }
.fine-grid > label > span:first-child { grid-area: name; }
.fine-grid > label > input[type="range"] { grid-area: range; width: 100%; }
.fine-grid > label > output { grid-area: val; color: var(--text); font-variant-numeric: tabular-nums; }
.fine-grid > label > select { grid-area: range; }
.fine-grid > label.switch.inline { display: inline-flex; align-self: end; padding: 6px 0; }
.fine-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }

/* Export */
.export-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; align-items: end; }
.export-grid .wide { grid-column: 1 / 3; }
.export-grid .btn { grid-column: 3; min-width: 0; }
@media (max-width: 560px) { .export-grid { grid-template-columns: 1fr 1fr; } .export-grid .wide, .export-grid .btn { grid-column: 1 / -1; } }
.export-grid label { display: flex; flex-direction: column; gap: 6px; font-size: .82rem; color: var(--muted); }
.export-grid select, .export-grid input { width: 100%; }
.progress { position: relative; margin-top: 12px; height: 26px; border-radius: 8px; background: #0b0e15; border: 1px solid var(--line); overflow: hidden; }
.progress .bar { position: absolute; inset-block: 0; inset-inline-start: 0; width: 0%; background: var(--accent-grad); transition: width .15s; }
.progress span { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: .8rem; }

.foot { display: flex; gap: 18px; justify-content: center; align-items: center; padding: 12px; color: var(--muted); font-size: .78rem; border-top: 1px solid var(--line); flex-wrap: wrap; }

.toast { position: fixed; bottom: 22px; inset-inline-start: 50%; transform: translateX(-50%); background: #242a3a; color: var(--text); border: 1px solid var(--line); padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); z-index: 20; font-size: .9rem; max-width: 90vw; }
[dir="rtl"] .toast { transform: translateX(50%); }
.toast.error { border-color: var(--danger); }
.toast.ok { border-color: var(--ok); }

dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 14px; padding: 22px; max-width: 480px; box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(0, 0, 0, .6); }
dialog p { color: var(--muted); margin: 10px 0 16px; line-height: 1.6; }

.drop-overlay { position: fixed; inset: 0; background: rgba(15, 17, 23, .85); z-index: 30; display: flex; align-items: center; justify-content: center; }
.drop-card { border: 2px dashed var(--accent2); border-radius: 18px; padding: 40px 60px; font-size: 1.2rem; display: flex; flex-direction: column; gap: 10px; align-items: center; color: var(--accent2); }
.drop-icon { font-size: 2.4rem; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* Preset category tabs */
.preset-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.preset-tabs button { border: 1px solid var(--line); background: var(--panel2); color: var(--muted); padding: 7px 14px; border-radius: 999px; cursor: pointer; font-weight: 600; font-size: .88rem; display: inline-flex; align-items: center; gap: 6px; }
.preset-tabs button:hover { color: var(--text); border-color: #3a4358; }
.preset-tabs button[aria-selected="true"] { background: var(--accent-grad); color: #fff; border-color: transparent; }
.preset-tabs button .count { font-size: .7rem; opacity: .75; }
.presets .preset .pdesc { min-height: 2.6em; }
.preset .badge { position: absolute; top: 8px; inset-inline-end: 8px; font-size: .62rem; padding: 2px 6px; border-radius: 999px; background: var(--accent); color: #fff; }
.preset { position: relative; }

/* Music panel */
.music-top { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.music-name { color: var(--muted); font-size: .85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 260px; }
.music-name.set { color: var(--accent2); }
.music-grid { margin-top: 14px; }
.panel.music.disabled .music-grid { opacity: .45; pointer-events: none; }
#mixStatus { display: inline-block; margin-top: 10px; }
