:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --bg: #0b1220;
  --panel: #101827;
  --panel-2: #152237;
  --panel-3: #1b2a42;
  --line: #2b3c57;
  --muted: #92a4bd;
  --text: #eff6ff;
  --accent: #5eead4;
  --danger: #f87171;
  --radius: 18px;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

* { box-sizing: border-box; }

html, body, #app {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
}

button, input, select { font: inherit; }
button { border: 0; cursor: pointer; }
button:disabled { opacity: .45; cursor: not-allowed; }
input, select { user-select: text; -webkit-user-select: text; }

.app-shell {
  height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 10px;
  padding:
    max(10px, env(safe-area-inset-top))
    max(10px, env(safe-area-inset-right))
    max(10px, env(safe-area-inset-bottom))
    max(10px, env(safe-area-inset-left));
  background:
    radial-gradient(circle at 10% 0%, rgba(45, 212, 191, .12), transparent 30%),
    linear-gradient(180deg, #0b1220, #0a111d);
}

.topbar, .bottom-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: rgba(16, 24, 39, .94);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo {
  width: 42px; height: 42px; display: grid; place-items: center;
  border-radius: 14px; background: linear-gradient(135deg, var(--accent), #22c55e);
  color: #06221f; font-size: 22px;
}
.brand h1 { margin: 0; font-size: clamp(18px, 3vw, 24px); }
.brand p {
  margin: 2px 0 0; color: var(--muted); font-size: 12px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.toolbar, .actions { display: flex; gap: 7px; align-items: center; flex-wrap: wrap; }

.main {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(250px, 340px) minmax(0, 1fr);
  gap: 10px;
}

.panel {
  min-height: 0;
  background: rgba(16, 24, 39, .95);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.panel-header {
  min-height: 58px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px; border-bottom: 1px solid var(--line);
}
.panel-header h2 { margin: 0; font-size: 16px; }
.scroll-area {
  height: calc(100% - 58px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 10px;
}
.project-list, .record-list { display: grid; gap: 9px; }
.project-card, .record-card {
  border: 1px solid var(--line);
  background: var(--panel-2);
  border-radius: 15px;
  padding: 11px;
  display: grid;
  gap: 8px;
}
.project-card.active {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}
.card-row {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.card-title {
  min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-weight: 750;
}
.meta { color: var(--muted); font-size: 12px; }
.btn {
  min-height: 40px; padding: 8px 12px; border-radius: 12px;
  background: var(--panel-3); color: var(--text); border: 1px solid var(--line);
}
.btn.primary { background: var(--accent); color: #06221f; border-color: transparent; font-weight: 800; }
.btn.danger { color: #ffd4d4; border-color: rgba(248,113,113,.45); }
.btn.icon { width: 40px; padding: 0; display: inline-grid; place-items: center; }

.workspace { height: 100%; display: grid; grid-template-rows: auto minmax(0, 1fr); }
.empty-state {
  height: 100%; display: grid; place-items: center; text-align: center;
  padding: 30px; color: var(--muted);
}
.empty-state strong { display: block; color: var(--text); font-size: 19px; margin-bottom: 5px; }
.record-card audio { width: 100%; height: 38px; }
.record-button {
  width: 64px; height: 64px; border-radius: 50%;
  display: grid; place-items: center; background: var(--danger);
  color: white; font-size: 25px;
  box-shadow: 0 0 0 8px rgba(248,113,113,.12);
}
.record-button.recording { animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 18px rgba(248,113,113,0); } }
.status {
  flex: 1; min-width: 0; color: var(--muted); font-size: 13px;
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}
.badge {
  display: inline-flex; align-items: center; min-height: 25px;
  padding: 3px 8px; border-radius: 999px;
  background: #20304a; color: #bfdbfe; font-size: 11px;
}

dialog {
  width: min(720px, calc(100vw - 20px));
  max-height: calc(100dvh - 24px);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--panel);
  color: var(--text);
  padding: 0;
  box-shadow: 0 30px 90px rgba(0,0,0,.55);
}
dialog::backdrop { background: rgba(2,6,15,.78); backdrop-filter: blur(5px); }
.modal {
  max-height: calc(100dvh - 24px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}
.modal-header, .modal-footer {
  padding: 12px; display: flex; align-items: center; justify-content: space-between;
  gap: 9px; border-bottom: 1px solid var(--line);
}
.modal-footer { border-top: 1px solid var(--line); border-bottom: 0; justify-content: flex-end; }
.modal-header h3 { margin: 0; }
.modal-body { overflow-y: auto; padding: 14px; overscroll-behavior: contain; }
.form-grid { display: grid; gap: 12px; }
label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }
input {
  width: 100%; min-height: 44px; padding: 9px 11px;
  border-radius: 12px; border: 1px solid var(--line);
  background: #0d1625; color: var(--text); outline: none;
}
input:focus { border-color: var(--accent); }

.editor-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 250px;
  gap: 12px;
}
.wave-wrap { min-height: 260px; display: grid; grid-template-rows: 180px auto auto; gap: 10px; }
#waveform {
  width: 100%; height: 180px; border-radius: 14px; border: 1px solid var(--line);
}
.range-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.controls { display: grid; gap: 10px; align-content: start; }
.control {
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 13px; padding: 10px;
}
.control-head { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
.control strong { font-size: 13px; }
input[type="range"] { min-height: 30px; padding: 0; }

.toast {
  position: fixed; left: 50%; bottom: 90px;
  transform: translateX(-50%) translateY(25px);
  opacity: 0; pointer-events: none; z-index: 100;
  max-width: min(420px, calc(100vw - 28px));
  padding: 10px 14px; border-radius: 12px;
  background: #e5eefb; color: #0b1220;
  transition: .2s ease; text-align: center; font-weight: 700;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 760px) {
  .app-shell { gap: 7px; padding: 7px; }
  .main {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(115px, 31%) minmax(0, 1fr);
    gap: 7px;
  }
  .brand p { display: none; }
  .editor-grid { grid-template-columns: 1fr; }
  dialog { width: calc(100vw - 12px); max-height: calc(100dvh - 12px); }
}
