:root {
  --bg: #0f0f12;
  --panel: #16161b;
  --panel-2: #1e1e25;
  --line: #2a2a33;
  --text: #ececf1;
  --muted: #8d8d9b;
  --accent: #f2b84b;
  --accent-ink: #1a1405;
  --rec: #ff4d4d;
  --wave: #4b4b5a;
  --wave-played: #f2b84b;
  --wave-rec: #ff6b6b;
  --radius: 12px;
  color-scheme: dark;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", system-ui, sans-serif;
  font-size: 15px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body { display: flex; flex-direction: column; height: 100dvh; -webkit-tap-highlight-color: transparent; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
svg { width: 1em; height: 1em; fill: currentColor; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--line); background: var(--panel);
}
.brand { font-weight: 700; letter-spacing: .02em; }
.crumb { flex: 1; min-width: 0; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }


/* ---------- Avvisi ---------- */
.banner { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.banner.error { background: #3a1414; color: #ffb4b4; }
.banner.info { background: #1d2433; color: #c9d6f2; }
.banner-actions { display: flex; gap: 8px; margin-left: auto; }
.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 20;
  max-width: calc(100vw - 32px); background: #2a1a1a; color: #ffd0d0; border: 1px solid #5a2a2a;
  border-radius: 10px; padding: 10px 14px; font-size: 14px; box-shadow: 0 8px 24px rgba(0, 0, 0, .4);
}
.save-state[data-kind="error"] { color: #ff8080; }
.warn { color: var(--accent); }

/* ---------- Accesso ---------- */
body.locked .layout, body.locked .topbar > :not(.brand) { visibility: hidden; }
.login { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); z-index: 10; padding: 20px; }
.login-box { width: min(340px, 100%); display: flex; flex-direction: column; gap: 14px; }
.login-logo { font-size: 24px; font-weight: 700; text-align: center; margin-bottom: 8px; }
.login-error { margin: 0; min-height: 1.4em; color: #ff8080; font-size: 14px; text-align: center; }
#backBtn { display: none; font-size: 22px; }

.banner { padding: 10px 16px; background: #3a2a10; color: #ffd890; font-size: 14px; }

/* ---------- Layout ---------- */
.layout { flex: 1; min-height: 0; display: grid; grid-template-columns: 260px 320px 1fr; }
.pane { min-height: 0; overflow-y: auto; border-right: 1px solid var(--line); }
#projectsPane { background: var(--panel); }
#takePane { border-right: 0; }

.pane-head { display: flex; align-items: center; gap: 8px; padding: 14px 16px 10px; }
.pane-head h2 { margin: 0; font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); flex: 1; }
.pane-pad { padding: 0 16px 12px; }
.empty { color: var(--muted); text-align: center; padding: 60px 20px; line-height: 1.6; }

/* ---------- Lists ---------- */
.search {
  display: block; width: calc(100% - 32px); margin: 0 16px 10px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px;
}
.list { list-style: none; margin: 0; padding: 0 8px 24px; }
.list li > button {
  width: 100%; text-align: left; background: none; border: 0; border-radius: 10px;
  padding: 10px 12px; cursor: pointer; display: flex; align-items: center; gap: 10px;
}
.list li > button:hover { background: var(--panel-2); }
.list li.active > button { background: var(--panel-2); box-shadow: inset 3px 0 0 var(--accent); }
.item-main { flex: 1; min-width: 0; }
.item-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.item-side { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.star { color: var(--accent); }
.list-empty { color: var(--muted); padding: 16px 12px; font-size: 14px; }

/* ---------- Buttons & fields ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 9px 14px; cursor: pointer; text-decoration: none; white-space: nowrap; color: var(--text);
}
.btn:hover { border-color: #3a3a46; }
.btn.small { padding: 6px 10px; font-size: 14px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 600; }
.btn.block { width: 100%; }
.btn.ghost { background: none; }
.btn.danger-ghost { background: none; color: #ff8080; border-color: #4a2626; }
.btn[aria-disabled="true"] { opacity: .4; pointer-events: none; }
.dot { display: inline-block; width: .7em; height: .7em; border-radius: 50%; background: var(--rec); vertical-align: middle; }
.btn.primary .dot { background: var(--accent-ink); }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: 10px; border: 0; background: none; cursor: pointer; color: var(--muted); font-size: 18px; flex: none;
}
.icon-btn:hover { background: var(--panel-2); color: var(--text); }
.icon-btn.danger:hover { color: #ff8080; }
.icon-btn.fav.on { color: var(--accent); }

.title-input {
  flex: 1; min-width: 0; background: none; border: 1px solid transparent; border-radius: 8px;
  padding: 6px 8px; font-size: 18px; font-weight: 700;
}
.title-input:hover { border-color: var(--line); }
.title-input:focus { outline: none; border-color: var(--accent); background: var(--panel-2); }
.title-input.big { font-size: 22px; }

.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); min-width: 0; }
.field input, .field select, .field output {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; color: var(--text); font-size: 15px; min-width: 0; width: 100%;
}
.field.ro output { background: none; border-style: dashed; }
.field b { color: var(--text); font-weight: 600; }
.field input[type=range] { padding: 0; border: 0; background: none; accent-color: var(--accent); height: 36px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }

/* ---------- Take view ---------- */
.take-view { max-width: 900px; margin: 0 auto; padding: 16px 20px 40px; display: flex; flex-direction: column; gap: 14px; }
.take-head { display: flex; align-items: center; gap: 6px; }
.save-state { color: var(--muted); font-size: 13px; min-width: 60px; text-align: right; max-width: 45%; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }

/* ---------- DAW ---------- */
.daw { padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.input-settings summary {
  cursor: pointer; list-style: none; display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 14px; padding: 4px 2px;
}
.input-settings summary::-webkit-details-marker { display: none; }
.input-settings summary::after { content: "Impostazioni ▾"; margin-left: auto; font-size: 13px; }
.input-settings[open] summary::after { content: "Chiudi ▴"; }
.arm-led { width: 9px; height: 9px; border-radius: 50%; background: #444; flex: none; }
.arm-led.on { background: #4ade80; box-shadow: 0 0 8px #4ade80; }
.input-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; padding: 10px 2px 6px; align-items: end; }
.input-grid .wide { grid-column: 1 / -1; }

.meter {
  position: relative; height: 6px; border-radius: 3px; overflow: hidden;
  background: linear-gradient(90deg, #22c55e 0%, #22c55e 70%, #facc15 85%, #ef4444 100%);
}
.meter-cover { position: absolute; top: 0; right: 0; bottom: 0; width: 100%; background: var(--panel-2); }
.meter-clip { position: absolute; top: 0; right: 0; bottom: 0; width: 6px; background: transparent; }
.meter-clip.on { background: #ff2020; }

.wave-wrap { position: relative; height: 140px; background: var(--bg); border-radius: 10px; overflow: hidden; touch-action: none; cursor: pointer; }
.wave-wrap canvas { width: 100%; height: 100%; display: block; }
.wave-empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 14px; pointer-events: none; text-align: center; padding: 0 16px; }

.transport { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.t-btn {
  width: 48px; height: 48px; border-radius: 50%; border: 1px solid var(--line); background: var(--panel-2);
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer; font-size: 20px; flex: none;
}
.t-btn:disabled { opacity: .35; cursor: default; }
.t-btn.play { width: 56px; height: 56px; background: var(--text); color: var(--bg); font-size: 24px; border: 0; }
.t-btn.rec { color: var(--rec); font-size: 26px; }
body.recording .t-btn.rec { background: var(--rec); color: #fff; border-color: var(--rec); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 8px rgba(255, 77, 77, .18); } }
.time { font-variant-numeric: tabular-nums; font-size: 18px; margin-left: 6px; flex: 1; white-space: nowrap; }
.time .sep { color: var(--muted); margin: 0 6px; }
#timeTotal { color: var(--muted); }
body.recording #timeNow { color: var(--rec); }

/* ---------- Tabs & panels ---------- */
.tabs { display: flex; gap: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 4px; }
.tab { flex: 1; border: 0; background: none; padding: 8px 6px; border-radius: 7px; cursor: pointer; color: var(--muted); font-size: 14px; }
.tab.active { background: var(--panel-2); color: var(--text); font-weight: 600; }
.panel { padding: 12px; }
.panel textarea {
  width: 100%; min-height: 260px; resize: vertical; background: none; border: 0; line-height: 1.55; font-size: 15px;
}
.info-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.danger-zone { display: flex; justify-content: flex-end; }

/* Durante la registrazione blocca la navigazione */
body.recording #projectsPane, body.recording #takesPane, body.recording #backBtn { pointer-events: none; opacity: .45; }
body.recording .input-settings select, body.recording #armBtn { pointer-events: none; opacity: .5; }

/* ---------- Tablet / mobile: un pannello alla volta ---------- */
@media (max-width: 999px) {
  .layout { grid-template-columns: 1fr; }
  .pane { display: none; border: 0; }
  body[data-view="projects"] #projectsPane,
  body[data-view="takes"] #takesPane,
  body[data-view="take"] #takePane { display: block; }
  body:not([data-view="projects"]) #backBtn { display: inline-flex; }
  body:not([data-view="projects"]) .brand { display: none; }
  #projectsPane { background: var(--bg); }
  .take-view { padding: 12px 12px calc(40px + env(safe-area-inset-bottom)); }
  input, select, textarea { font-size: 16px !important; } /* evita lo zoom su iOS */
  .list li > button { padding: 14px 12px; }
  .wave-wrap { height: 120px; }
  .transport { justify-content: center; }
  .time { flex-basis: 100%; order: -1; text-align: center; margin: 0; font-size: 22px; }
}
