/* ==========================================================
   Audio Editor — Browser Edition
   ========================================================== */

:root {
  --bg-0: #07090f;
  --bg-1: #0b1120;
  --bg-2: #111a2e;
  --bg-3: #182441;
  --line: #1e2a47;
  --line-2: #2a3a5e;
  --text: #e6edf7;
  --text-dim: #93a3c0;
  --text-mute: #64748b;
  --accent: #5b8cff;
  --accent-2: #7c5bff;
  --accent-grad: linear-gradient(135deg, #5b8cff 0%, #7c5bff 100%);
  --good: #34d399;
  --warn: #fbbf24;
  --danger: #f87171;
  --wave: #5b8cff;
  --wave-sel: #ffd166;
  --selection: rgba(255, 209, 102, 0.18);
  --shadow-1: 0 8px 24px rgba(0,0,0,.35);
  --radius: 10px;
  --radius-lg: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg-0);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Inter", system-ui, sans-serif;
  font-size: 14px;
  overflow: hidden;
}

button { font-family: inherit; cursor: pointer; }

/* ===================== TOP BAR ===================== */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px;
  background: linear-gradient(180deg, var(--bg-2) 0%, var(--bg-1) 100%);
  border-bottom: 1px solid var(--line);
  height: 56px; z-index: 10;
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 36px; height: 36px;
  border-radius: 10px;
  display: grid; place-items: center;
  color: white;
  background: var(--accent-grad);
  box-shadow: 0 4px 12px rgba(91,140,255,.35);
}
.brand-name { font-size: 15px; font-weight: 600; letter-spacing: -0.01em; }
.brand-sub { font-size: 11px; color: var(--text-mute); margin-top: 1px; }

.topbar-actions { display: flex; gap: 8px; }

.btn {
  border: 1px solid var(--line-2);
  background: var(--bg-3);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  transition: transform .05s ease, background .15s ease, border-color .15s ease;
}
.btn:hover { background: #1f2c4d; }
.btn:active { transform: scale(.98); }
.btn.primary {
  background: var(--accent-grad);
  border-color: transparent;
  color: white;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(91,140,255,.3);
}
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: var(--bg-3); }

#btn-record.recording {
  background: linear-gradient(135deg, #f87171, #ef4444);
  border-color: transparent;
  color: white;
  animation: pulseRec 1.4s ease infinite;
}
@keyframes pulseRec {
  0%,100% { box-shadow: 0 0 0 0 rgba(248,113,113,.6);}
  50%     { box-shadow: 0 0 0 10px rgba(248,113,113,0);}
}

/* ===================== WORKSPACE ===================== */
.workspace {
  display: grid;
  grid-template-columns: 320px 1fr;
  height: calc(100vh - 56px);
}

/* ===================== SIDEBAR ===================== */
.sidebar {
  background: var(--bg-1);
  border-right: 1px solid var(--line);
  overflow-y: auto;
  padding: 14px;
}
.sidebar::-webkit-scrollbar { width: 8px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 4px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }

.panel {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 14px;
  margin-bottom: 14px;
}

.panel h3 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-dim);
  margin: 0 0 12px;
  font-weight: 600;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.tool {
  background: var(--bg-3);
  border: 1px solid var(--line-2);
  color: var(--text);
  padding: 9px 10px;
  border-radius: 8px;
  font-size: 12.5px;
  font-weight: 500;
  text-align: center;
  transition: background .12s ease;
}
.tool:hover { background: #233156; }
.tool:active { background: #2a3a64; }
.tool[disabled] { opacity: .4; cursor: not-allowed; }
.tool.wide { width: 100%; margin-top: 8px; }

.row {
  display: flex; align-items: center; gap: 10px;
  margin-top: 10px;
}
.row label {
  flex: 0 0 56px;
  font-size: 12px;
  color: var(--text-dim);
}
.row .val {
  font-size: 11.5px;
  color: var(--text-dim);
  width: 56px; text-align: right;
  font-variant-numeric: tabular-nums;
}
.row.btns { gap: 6px; }
.row.btns .tool { flex: 1; margin-top: 0; }

input[type="range"] {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  background: var(--line-2);
  border-radius: 2px;
  outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 2px 6px rgba(0,0,0,.4);
  cursor: pointer;
  border: 2px solid white;
}
input[type="range"]::-moz-range-thumb {
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid white;
  cursor: pointer;
}

/* EQ bands */
.eq-bands {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 4px;
  height: 110px;
  margin-bottom: 10px;
}
.eq-band {
  display: flex; flex-direction: column; align-items: center;
  gap: 4px;
}
.eq-band input[type="range"] {
  -webkit-appearance: slider-vertical;
  writing-mode: bt-lr;
  width: 18px;
  height: 80px;
  background: var(--line-2);
  padding: 0 6px;
}
.eq-band-label { font-size: 9px; color: var(--text-mute); }

/* ===================== EDITOR ===================== */
.editor {
  display: flex; flex-direction: column;
  background: var(--bg-0);
  min-width: 0;
}

.editor-toolbar {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 14px;
  background: var(--bg-1);
  border-bottom: 1px solid var(--line);
  height: 48px;
}

.t-btn {
  background: var(--bg-3);
  border: 1px solid var(--line-2);
  color: var(--text);
  width: 36px; height: 32px;
  border-radius: 8px;
  font-size: 13px;
  display: grid; place-items: center;
}
.t-btn:hover { background: #233156; }
#play-btn { background: var(--accent-grad); border-color: transparent; color: white; }

.separator { width: 1px; height: 24px; background: var(--line); margin: 0 4px; }
.separator.flex { width: auto; flex: 1; background: transparent; }

.time {
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  color: var(--text);
  font-weight: 500;
  min-width: 78px; text-align: center;
}
.time-sep { color: var(--text-mute); }

.vol {
  display: flex; align-items: center; gap: 8px;
  font-size: 11.5px;
  color: var(--text-dim);
}
.vol input[type="range"] { width: 100px; }

/* Waveform */
.waveform-wrap {
  flex: 1;
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(800px 400px at 50% 50%, rgba(91,140,255,.05), transparent 70%),
    var(--bg-0);
}

.ruler {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 24px;
  background: var(--bg-1);
  border-bottom: 1px solid var(--line);
  font-size: 10px;
  color: var(--text-mute);
  font-variant-numeric: tabular-nums;
  overflow: hidden;
  z-index: 2;
}
.ruler-tick {
  position: absolute;
  top: 0;
  height: 100%;
  border-left: 1px solid var(--line-2);
  padding-left: 4px;
  display: flex;
  align-items: center;
  white-space: nowrap;
}

.waveform {
  position: absolute;
  top: 24px; left: 0; right: 0; bottom: 0;
  width: 100%;
  cursor: crosshair;
  touch-action: none;
}

.empty-state {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  text-align: center; padding: 40px;
  pointer-events: none;
}
.empty-state.dragover {
  background: rgba(91,140,255,.07);
  outline: 2px dashed var(--accent);
  outline-offset: -16px;
}
.empty-state * { pointer-events: auto; }
.empty-state .empty-art { color: var(--line-2); margin-bottom: 14px; }
.empty-state h3 { margin: 0 0 6px; font-size: 18px; font-weight: 600; }
.empty-state p { margin: 0 0 18px; color: var(--text-dim); max-width: 360px; }

.status-bar {
  display: flex; align-items: center; gap: 14px;
  padding: 6px 14px;
  background: var(--bg-1);
  border-top: 1px solid var(--line);
  font-size: 11.5px;
  color: var(--text-dim);
  height: 28px;
  font-variant-numeric: tabular-nums;
}
.status-bar .flex { flex: 1; }

/* ===================== MODAL ===================== */
.modal[hidden] { display: none !important; }
.modal {
  position: fixed; inset: 0;
  background: rgba(7,9,15,.7);
  backdrop-filter: blur(6px);
  display: grid; place-items: center;
  z-index: 100;
  animation: fadeIn .12s ease;
}
@keyframes fadeIn { from {opacity: 0;} to {opacity: 1;} }

.modal-card {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  width: 420px; max-width: calc(100vw - 32px);
  box-shadow: var(--shadow-1);
  overflow: hidden;
}
.modal-card header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}
.modal-card header h3 { margin: 0; font-size: 15px; }
.modal-card .x {
  background: none; border: none; color: var(--text-dim);
  font-size: 22px; line-height: 1; padding: 4px 8px;
  border-radius: 6px;
}
.modal-card .x:hover { background: var(--bg-3); color: var(--text); }
.modal-body { padding: 16px 18px; }
.modal-card footer {
  padding: 12px 18px;
  background: var(--bg-1);
  display: flex; gap: 8px; justify-content: flex-end;
  border-top: 1px solid var(--line);
}

.field {
  display: flex; flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}
.field span {
  font-size: 12px; color: var(--text-dim);
  font-weight: 500;
}
.field select, .field input[type="text"] {
  background: var(--bg-3);
  border: 1px solid var(--line-2);
  color: var(--text);
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
}
.field select:focus, .field input[type="text"]:focus {
  border-color: var(--accent);
}

/* ===================== TOAST ===================== */
.toast[hidden] { display: none !important; }
.toast {
  position: fixed;
  bottom: 24px; left: 50%;
  transform: translateX(-50%);
  background: var(--bg-2);
  border: 1px solid var(--line-2);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 13px;
  box-shadow: var(--shadow-1);
  z-index: 200;
  animation: toastIn .2s ease;
}
@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, 12px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

/* ===================== RESPONSIVE ===================== */
@media (max-width: 900px) {
  .workspace { grid-template-columns: 1fr; }
  .sidebar {
    border-right: none;
    border-bottom: 1px solid var(--line);
    max-height: 40vh;
  }
  .vol input[type="range"] { width: 70px; }
  .topbar-actions .btn { padding: 7px 10px; font-size: 12px; }
  .brand-sub { display: none; }
}
