:root {
  --bg: #090914; --panel: #13132b; --panel2: #1c1c3d; --line: rgba(255, 255, 255, .09);
  --txt: #f1f4ff; --muted: #9aa3c7; --a: #22d3ee; --b: #f472b6;
  --loop: #4ade80; --fx: #fb923c; --smp: #a78bfa; --hot: #facc15;
  --pa: 0; --pb: 0;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--txt); min-height: 100vh;
  font-family: ui-rounded, "SF Pro Rounded", "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent; overflow-x: hidden;
}
body::before {
  content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background:
    radial-gradient(55% 45% at 12% 35%, rgba(34, 211, 238, calc(var(--pa) * .38)), transparent 70%),
    radial-gradient(55% 45% at 88% 35%, rgba(244, 114, 182, calc(var(--pb) * .38)), transparent 70%),
    radial-gradient(80% 60% at 50% 110%, rgba(167, 139, 250, .12), transparent 70%);
}
header, main { position: relative; z-index: 1; }
button { font: inherit; color: inherit; }
.mini { font-size: 11px; letter-spacing: .08em; color: var(--muted); text-transform: uppercase; }
.center { text-align: center; }

/* intestazione */
.top { display: flex; align-items: center; gap: 12px; padding: 10px 16px; flex-wrap: wrap; }
.brand { font-weight: 800; font-size: 20px; letter-spacing: .02em; display: flex; align-items: center; gap: 8px; }
.logo { font-size: 24px; }
.status { display: flex; gap: 8px; flex-wrap: wrap; flex: 1; }
.chip { font-size: 13px; padding: 5px 10px; border-radius: 999px; background: var(--panel); border: 1px solid var(--line); color: var(--muted); }
.chip[data-kind="ok"] { color: #86efac; border-color: rgba(134, 239, 172, .35); }
.chip[data-kind="warn"] { color: #fcd34d; border-color: rgba(252, 211, 77, .35); }
.actions { display: flex; gap: 8px; }

/* bottoni */
.btn {
  background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px;
  font-weight: 800; letter-spacing: .04em; cursor: pointer; user-select: none; touch-action: manipulation;
  transition: transform .06s, box-shadow .15s, background .15s; text-decoration: none; display: inline-block;
}
.btn:active { transform: scale(.96); }
.btn:focus-visible, .knob:focus-visible, .pad:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }
.btn.icon { width: 42px; padding: 10px 0; text-align: center; }
.btn.small { padding: 7px 10px; font-size: 12px; }
.btn.on { background: #fff; color: #111; }
.btn.rec.on { background: #ef4444; color: #fff; box-shadow: 0 0 18px rgba(239, 68, 68, .7); }
.btn.big { font-size: 20px; padding: 16px 26px; border-radius: 16px; background: linear-gradient(135deg, var(--a), var(--b)); color: #0b0b18; border: 0; }

/* console */
main { padding: 0 16px 32px; max-width: 1500px; margin: 0 auto; }
.console { display: grid; grid-template-columns: 1fr minmax(230px, 280px) 1fr; gap: 14px; align-items: start; }
.deck, .mixer { background: linear-gradient(180deg, var(--panel), #0f0f22); border: 1px solid var(--line); border-radius: 20px; padding: 14px; position: relative; }
.deck-0, .mix-col[data-deck="0"] { --c: var(--a); }
.deck-1, .mix-col[data-deck="1"] { --c: var(--b); }
.track.mine { --tc: #fde047; }
.deck { --tc: var(--c); box-shadow: 0 0 0 1px color-mix(in srgb, var(--c) 25%, transparent), 0 10px 40px rgba(0, 0, 0, .35); min-width: 0; }
.deck-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.deck-num { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; font-weight: 900; background: var(--c); color: #0b0b18; flex: none; }
.deck-title { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.deck-title > div { min-width: 0; }
.t-emoji { font-size: 28px; }
.t-name { display: block; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.t-sub { color: var(--muted); font-size: 12px; }
.deck-bpm { text-align: right; flex: none; }
.deck-bpm b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; color: var(--tc); }
.deck-bpm small { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
canvas { display: block; width: 100%; border-radius: 10px; background: rgba(0, 0, 0, .35); }
.overview { height: 34px; cursor: pointer; margin-bottom: 6px; }
.zoom { height: 84px; }

.deck-body { display: flex; align-items: center; gap: 12px; margin: 12px 0; }
.deck-0 .deck-body { flex-direction: row-reverse; }
.platter-wrap { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.platter {
  width: clamp(150px, 17vw, 230px); aspect-ratio: 1; border-radius: 50%; padding: 6px; cursor: grab; touch-action: none;
  background: conic-gradient(from 0deg, var(--c), transparent 30%, var(--c) 60%, transparent 90%, var(--c));
  box-shadow: 0 0 calc(10px + 30px * var(--glow, 0)) color-mix(in srgb, var(--c) 60%, transparent);
}
.deck-0 .platter { --glow: var(--pa); }
.deck-1 .platter { --glow: var(--pb); }
.platter:active { cursor: grabbing; }
.vinyl {
  width: 100%; height: 100%; border-radius: 50%; position: relative; display: grid; place-items: center;
  background: repeating-radial-gradient(circle, #151515 0 2px, #222 2px 4px); will-change: transform;
}
.label { width: 38%; aspect-ratio: 1; border-radius: 50%; background: var(--tc); display: grid; place-items: center; box-shadow: inset 0 0 0 4px rgba(0, 0, 0, .25); }
.label-emoji { font-size: clamp(22px, 3vw, 38px); }
.marker { position: absolute; top: 4%; left: calc(50% - 3px); width: 6px; height: 22%; border-radius: 3px; background: #fff; opacity: .9; }
.time { font-variant-numeric: tabular-nums; font-weight: 800; font-size: 18px; }

.tempo { display: flex; flex-direction: column; align-items: center; gap: 6px; flex: none; }
.rate { writing-mode: vertical-lr; direction: rtl; height: 170px; width: 30px; accent-color: var(--c); cursor: ns-resize; }
.tempo-hint { font-size: 9px; text-transform: none; letter-spacing: 0; }

.transport { display: grid; grid-template-columns: 1fr 1fr 1.4fr; gap: 8px; }
.transport .btn { padding: 14px 0; font-size: 16px; }
.btn.play.on { background: #22c55e; color: #052e16; box-shadow: 0 0 22px rgba(34, 197, 94, .6); }
.btn.cue.on { background: #f59e0b; color: #1f1300; }
.btn.sync.on { background: var(--c); color: #0b0b18; box-shadow: 0 0 18px var(--c); }

.pad-tabs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; margin: 12px 0 8px; }
.tab { background: transparent; border: 1px solid var(--line); border-radius: 8px; padding: 6px 0; font-size: 11px; font-weight: 800; letter-spacing: .04em; color: var(--muted); cursor: pointer; }
.tab.on { color: #0b0b18; background: var(--pc, var(--hot)); border-color: transparent; }
.tab[data-mode="0"] { --pc: var(--hot); } .tab[data-mode="1"] { --pc: var(--loop); }
.tab[data-mode="2"] { --pc: var(--fx); } .tab[data-mode="3"] { --pc: var(--smp); }
.pads { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; --pc: var(--hot); }
.pads[data-mode="1"] { --pc: var(--loop); } .pads[data-mode="2"] { --pc: var(--fx); } .pads[data-mode="3"] { --pc: var(--smp); }
.pad {
  height: 66px; border-radius: 14px; border: 1px solid color-mix(in srgb, var(--pc) 45%, transparent);
  background: color-mix(in srgb, var(--pc) 10%, #101024); cursor: pointer; touch-action: none; user-select: none;
  display: flex; flex-direction: column; align-items: flex-start; justify-content: space-between; padding: 8px 10px; text-align: left;
  transition: background .1s, box-shadow .1s, transform .05s;
}
.pad:active { transform: scale(.97); }
.pad.on { background: var(--pc); color: #0b0b18; box-shadow: 0 0 22px color-mix(in srgb, var(--pc) 70%, transparent); }
.pad-n { font-weight: 900; font-size: 13px; opacity: .7; }
.pad-l { font-weight: 800; font-size: 14px; }

.loading { position: absolute; inset: 0; border-radius: 20px; background: rgba(9, 9, 20, .82); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; font-weight: 800; z-index: 3; }
.loading[hidden] { display: none; }
.spinner { width: 46px; height: 46px; border-radius: 50%; border: 5px solid rgba(255, 255, 255, .15); border-top-color: var(--c); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.deck.empty .platter, .deck.empty .transport, .deck.empty .pads { opacity: .45; }

/* mixer */
.mix-cols { display: grid; grid-template-columns: 1fr auto 1fr; gap: 6px; align-items: start; }
.mix-col { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.mix-mid { display: flex; flex-direction: column; align-items: center; gap: 10px; padding-top: 4px; }
.knob { display: flex; flex-direction: column; align-items: center; gap: 4px; cursor: ns-resize; touch-action: none; user-select: none; border-radius: 12px; }
.knob-dial {
  width: 52px; height: 52px; border-radius: 50%; position: relative;
  background: radial-gradient(circle at 35% 30%, #3a3a5c, #15152a 70%); border: 2px solid var(--c, #888);
  box-shadow: 0 4px 10px rgba(0, 0, 0, .5);
}
#masterKnob .knob-dial { border-color: #fff; }
.knob-ind { position: absolute; left: calc(50% - 2px); top: 4px; width: 4px; height: 16px; border-radius: 2px; background: #fff; }
.knob-lbl { font-size: 10px; font-weight: 800; letter-spacing: .08em; color: var(--muted); }
.vu { width: 14px; height: 110px; border-radius: 7px; background: rgba(255, 255, 255, .06); position: relative; overflow: hidden; }
.vu-fill {
  position: absolute; inset: 0; background: linear-gradient(to top, #22c55e 0 60%, #facc15 60% 85%, #ef4444 85%);
  clip-path: inset(calc((1 - var(--v, 0)) * 100%) 0 0 0);
}
.btn.pfl { padding: 8px 12px; font-size: 18px; }
.btn.pfl.on { background: var(--c); }
.xf-wrap { display: flex; align-items: center; gap: 8px; margin-top: 16px; font-weight: 900; color: var(--muted); }
#xfader { flex: 1; -webkit-appearance: none; appearance: none; height: 34px; background: transparent; cursor: ew-resize; }
#xfader::-webkit-slider-runnable-track { height: 10px; border-radius: 5px; background: linear-gradient(90deg, var(--a), #444 50%, var(--b)); }
#xfader::-moz-range-track { height: 10px; border-radius: 5px; background: linear-gradient(90deg, var(--a), #444 50%, var(--b)); }
#xfader::-webkit-slider-thumb { -webkit-appearance: none; width: 26px; height: 40px; margin-top: -15px; border-radius: 6px; background: #eee; border: 3px solid #555; }
#xfader::-moz-range-thumb { width: 22px; height: 36px; border-radius: 6px; background: #eee; border: 3px solid #555; }

/* libreria */
.lib h2, .recbox h2 { font-size: 18px; margin: 26px 0 10px; }
.lib h2 small { font-size: 13px; color: var(--muted); font-weight: 500; margin-left: 8px; }
.library { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.track {
  display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: 16px; background: var(--panel);
  border: 1px solid var(--line); border-left: 6px solid var(--tc); position: relative;
}
.track.loaded::after { content: "sul deck " attr(data-on); position: absolute; top: -8px; right: 10px; font-size: 10px; font-weight: 800; background: var(--tc); color: #0b0b18; padding: 2px 7px; border-radius: 999px; }
.tr-emoji { font-size: 30px; }
.tr-txt { flex: 1; min-width: 0; }
.tr-txt b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tr-txt small { color: var(--muted); font-size: 12px; }
.tr-btns { display: flex; gap: 6px; }
.tr-btns button, .tr-btns label {
  width: 38px; height: 38px; border-radius: 10px; border: 0; font-weight: 900; cursor: pointer; display: grid; place-items: center;
  background: var(--a); color: #0b0b18;
}
.tr-btns > :last-child { background: var(--b); }

.recbox { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.recbox h2 { width: 100%; }
.recbox[hidden] { display: none; }
.recbox audio { flex: 1; min-width: 240px; }

/* schermata iniziale */
.start { position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; padding: 16px; background: rgba(5, 5, 14, .86); backdrop-filter: blur(8px); }
.start[hidden] { display: none; }
.start-card { max-width: 440px; text-align: center; }
.start-card h1 { font-size: 40px; margin: 6px 0; background: linear-gradient(90deg, var(--a), var(--b)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.start-card p { color: var(--muted); line-height: 1.45; }
.start-disc { font-size: 72px; animation: spin 3s linear infinite; display: inline-block; }
.err { color: #fca5a5 !important; font-weight: 700; }

/* finestre */
dialog { background: var(--panel); color: var(--txt); border: 1px solid var(--line); border-radius: 18px; max-width: min(620px, calc(100vw - 32px)); padding: 18px 20px; }
dialog::backdrop { background: rgba(0, 0, 0, .6); }
dialog h2 { margin-top: 0; }
.help { padding-left: 20px; line-height: 1.5; }
.help li { margin-bottom: 6px; }
.row { display: flex; align-items: center; gap: 10px; margin: 12px 0; }
.row select { font: inherit; padding: 6px; border-radius: 8px; background: var(--panel2); color: var(--txt); border: 1px solid var(--line); }
.row input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--a); }

.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translate(-50%, 30px); opacity: 0; z-index: 20; pointer-events: none;
  background: #fff; color: #111; font-weight: 700; padding: 10px 16px; border-radius: 12px; transition: .25s; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 1000px) {
  .console { grid-template-columns: 1fr; }
  .mixer { order: 0; }
  .platter { width: clamp(150px, 42vw, 230px); }
}
@media (max-width: 480px) {
  .rate { height: 140px; }
  .pad { height: 58px; }
  .pad-l { font-size: 12px; }
}
@media (prefers-reduced-motion: reduce) { .start-disc { animation: none; } }
