/* Page frame: the shader canvas, the grid, and everything the view modes change. */

#visualizer {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: -3;
  display: block;
}

#visualizer.gl-unsupported {
  background:
    radial-gradient(circle at 12% -10%, rgba(77, 224, 232, 0.22), transparent 42%),
    radial-gradient(circle at 88% 8%, rgba(243, 123, 216, 0.18), transparent 44%),
    #05070b;
}

.grain {
  position: fixed;
  inset: -50%;
  z-index: -2;
  pointer-events: none;
  opacity: 0.16;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='140' height='140'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='3'/></filter><rect width='140' height='140' filter='url(%23n)' opacity='0.5'/></svg>");
  animation: grain-drift 7s steps(6) infinite;
}

@keyframes grain-drift {
  0%   { transform: translate(0, 0); }
  20%  { transform: translate(-2%, 1%); }
  40%  { transform: translate(1%, -2%); }
  60%  { transform: translate(-1%, -1%); }
  80%  { transform: translate(2%, 1%); }
  100% { transform: translate(0, 0); }
}

.vignette {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background: radial-gradient(ellipse at 50% 45%, transparent 42%, rgba(2, 4, 8, 0.72) 100%);
}

/* --------------------------------------------------------------------- grid */

.shell {
  position: relative;
  height: 100dvh;
  display: grid;
  gap: var(--gap);
  padding: var(--gap);
  grid-template-columns: var(--queue-width) minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-areas:
    "top   top"
    "queue stage";
  transition: grid-template-columns var(--slow) var(--ease-out);
}

.topbar { grid-area: top; }
.queue-panel { grid-area: queue; }
.stage { grid-area: stage; }

.shell:has(.queue-panel[data-open="false"]) {
  grid-template-columns: var(--queue-rail) minmax(0, 1fr);
}

.stage {
  display: grid;
  gap: var(--gap);
  grid-template-rows: minmax(0, 1fr) auto minmax(0, 1fr);
  min-height: 0;
}

/* ------------------------------------------------------------------- panels */

.panel-surface,
.topbar,
.queue-panel,
.deck,
.mixer {
  background: var(--panel);
  border: 1px solid var(--hairline);
  border-radius: var(--r-lg);
  box-shadow: var(--lift), var(--inner-top);
  backdrop-filter: blur(26px) saturate(150%);
  -webkit-backdrop-filter: blur(26px) saturate(150%);
}

/* ------------------------------------------------------------------- topbar */

.topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 9px 14px;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 7px;
}

.brand-mark {
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.22em;
  background: linear-gradient(96deg, var(--deck-a), #ffffff 44%, var(--deck-b));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.brand-tag {
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--ink-faint);
  border: 1px solid var(--hairline);
  border-radius: var(--r-pill);
  padding: 1px 6px;
}

.master-cluster {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: 4px;
}

.master-meter {
  width: 118px;
  height: 5px;
  display: grid;
  gap: 2px;
}

.master-readout {
  display: flex;
  align-items: center;
  gap: 8px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

/* --------------------------------------------------------------- queue rail */

.queue-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-height: 0;
  overflow: hidden;
  transition: opacity var(--base) var(--ease-out);
}

.queue-panel[data-open="false"] .queue-scroll,
.queue-panel[data-open="false"] .queue-foot,
.queue-panel[data-open="false"] .queue-title,
.queue-panel[data-open="false"] #clearQueue {
  display: none;
}

.queue-panel[data-open="false"] .queue-head {
  height: 100%;
  flex-direction: column;
  justify-content: flex-start;
  padding: 12px 0;
}

.queue-panel[data-open="false"] #toggleQueue svg {
  transform: rotate(180deg);
}

.queue-panel[data-open="false"]::after {
  content: "QUEUE";
  position: absolute;
  left: 50%;
  top: 58%;
  transform: translate(-50%, -50%) rotate(180deg);
  writing-mode: vertical-rl;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.34em;
  color: var(--ink-faint);
  pointer-events: none;
}

.queue-panel { position: relative; }

/* ---------------------------------------------------------------- view mode */

body[data-view="compact"] .deck-extra,
body[data-view="compact"] .wave-overview,
body[data-view="compact"] .cue-readout,
body[data-view="compact"] .deck-expand,
body[data-view="compact"] .q-spark,
body[data-view="compact"] .mixer-controls .segmented-curve {
  display: none !important;
}

body[data-view="compact"] .stage {
  grid-template-rows: minmax(0, 1fr) auto minmax(0, 1fr);
}

body[data-view="compact"] .deck-head {
  padding-bottom: 6px;
}

body[data-view="compact"] .deck-transport {
  padding-top: 4px;
}

body[data-view="compact"] .mixer-live {
  padding: 10px 16px 4px;
}

body[data-view="compact"] .live-block strong {
  font-size: 20px;
}

body[data-view="compact"] .live-count {
  font-size: 42px;
}

/* Compact is the across-the-room view, so the main transport grows rather than shrinks. */
body[data-view="compact"] .tbig {
  width: 54px;
  height: 54px;
}

body[data-view="compact"] .tbig svg {
  width: 20px;
  height: 20px;
}

body[data-view="compact"] .tbig-play {
  width: 74px;
  height: 74px;
}

body[data-view="compact"] .tbig-play svg {
  width: 28px;
  height: 28px;
}

body[data-view="compact"] .deck-title {
  font-size: 15px;
}

/* Dynamic expansion: a fade in flight pushes the mixer forward. */
body[data-fading="true"] .mixer {
  border-color: rgba(243, 123, 216, 0.38);
  box-shadow: var(--lift), var(--inner-top), 0 0 0 1px rgba(243, 123, 216, 0.18),
    0 0 46px rgba(243, 123, 216, 0.16);
}

body[data-fading="true"] .live-count {
  color: var(--warn);
}

/* ---------------------------------------------------------------- overlays */

.drop-veil {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--base) var(--ease-out);
  background: rgba(4, 7, 12, 0.62);
  backdrop-filter: blur(6px);
}

.drop-veil[data-visible="true"] {
  opacity: 1;
}

.drop-veil-inner {
  text-align: center;
  padding: 34px 54px;
  border-radius: var(--r-lg);
  border: 2px dashed rgba(77, 224, 232, 0.5);
  background: rgba(10, 14, 21, 0.7);
  box-shadow: 0 0 60px rgba(77, 224, 232, 0.16);
}

.drop-glyph svg {
  width: 40px;
  height: 40px;
  fill: none;
  stroke: var(--deck-a);
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.drop-title {
  margin-top: 10px;
  font-size: 17px;
  font-weight: 650;
}

.drop-sub {
  margin-top: 4px;
  font-size: 12px;
  color: var(--ink-mute);
}

.drag-ghost {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 80;
  pointer-events: none;
  display: grid;
  gap: 1px;
  padding: 8px 14px;
  border-radius: var(--r-md);
  background: rgba(20, 26, 38, 0.94);
  border: 1px solid rgba(77, 224, 232, 0.42);
  box-shadow: 0 18px 42px rgba(0, 0, 0, 0.55), 0 0 24px rgba(77, 224, 232, 0.2);
  opacity: 0;
  transform: translate3d(-999px, -999px, 0);
  transition: opacity var(--fast) linear;
}

.drag-ghost[data-visible="true"] {
  opacity: 1;
}

.drag-ghost strong {
  font-size: 13px;
}

.drag-ghost span {
  font-size: 11px;
  color: var(--ink-mute);
}

.drop-line {
  position: fixed;
  top: 0;
  left: 0;
  height: 2px;
  z-index: 79;
  pointer-events: none;
  border-radius: 2px;
  background: linear-gradient(90deg, transparent, var(--deck-a), transparent);
  box-shadow: 0 0 14px rgba(77, 224, 232, 0.8);
  opacity: 0;
}

.drop-line[data-visible="true"] {
  opacity: 1;
}

body[data-dragging="queue"] {
  cursor: grabbing;
}

.help-sheet {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: grid;
  place-items: center;
  background: rgba(4, 6, 11, 0.66);
  backdrop-filter: blur(10px);
}

.help-sheet[hidden] {
  display: none;
}

.help-card {
  width: min(520px, 92vw);
  padding: 20px 22px 18px;
  border-radius: var(--r-lg);
  background: var(--panel-strong);
  border: 1px solid var(--hairline-strong);
  box-shadow: var(--lift);
  animation: sheet-in var(--base) var(--ease-spring);
}

@keyframes sheet-in {
  from { transform: translateY(10px) scale(0.98); opacity: 0; }
  to   { transform: none; opacity: 1; }
}

.help-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.help-head h2 {
  font-size: 15px;
  letter-spacing: 0.04em;
}

.help-list {
  display: grid;
  gap: 7px;
}

.help-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: var(--ink-soft);
}

.help-list span {
  margin-left: auto;
  color: var(--ink-mute);
}

kbd {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 10.5px;
  padding: 2px 6px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--hairline);
  box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.4);
}

.help-foot {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--hairline);
  font-size: 11.5px;
  color: var(--ink-mute);
}

.help-foot a {
  color: var(--deck-a);
  text-decoration: none;
}

.help-foot a:hover {
  text-decoration: underline;
}

/* ---------------------------------------------------------------- about */

.about-card {
  width: min(580px, 92vw);
  max-height: 88vh;
  overflow-y: auto;
}

.about-lede {
  font-size: 13.5px;
  line-height: 1.55;
  color: var(--ink-soft);
}

.about-block {
  margin-top: 16px;
}

.about-block h3 {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: 6px;
}

.about-block p {
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--ink-mute);
}

.about-privacy {
  padding: 12px 14px;
  border-radius: var(--r-md);
  border: 1px solid rgba(124, 247, 176, 0.24);
  background: rgba(124, 247, 176, 0.06);
}

.about-privacy h3 {
  color: var(--good);
}

.credits {
  display: grid;
  gap: 9px;
}

.credits li {
  display: grid;
  gap: 1px;
  padding-left: 11px;
  border-left: 2px solid var(--hairline-strong);
}

.credits strong {
  font-size: 12.5px;
  font-weight: 620;
  color: var(--ink);
}

.credits span {
  font-size: 11.5px;
  line-height: 1.45;
  color: var(--ink-mute);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  z-index: 100;
  transform: translate(-50%, 14px);
  padding: 9px 18px;
  border-radius: var(--r-pill);
  background: rgba(18, 24, 35, 0.94);
  border: 1px solid var(--hairline-strong);
  box-shadow: var(--lift-sm);
  font-size: 12.5px;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--base) var(--ease-out), transform var(--base) var(--ease-out);
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ------------------------------------------------------------- narrow decks */

@media (max-width: 1180px) {
  :root { --queue-width: 300px; }
  .deck-stats .stat-remain { display: none; }
}

/* ------------------------------------------------------------------- phone */

/* One column, and the queue takes the leftover height because on a phone the
   queue IS the way tracks get loaded — there is no dragging files in. */
@media (max-width: 780px) {
  :root {
    --gap: 8px;
    --r-lg: 13px;
  }

  /* A phone scrolls. Trying to fit three panels into 100dvh is what crushed the
     decks to a header strip — here the column takes its natural height instead. */
  body {
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior-y: contain;
  }

  .shell {
    height: auto;
    min-height: 100dvh;
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "top" "stage" "queue";
    grid-template-rows: auto auto auto;
    padding: 8px;
  }

  .shell:has(.queue-panel[data-open="false"]) {
    grid-template-columns: minmax(0, 1fr);
  }

  .queue-panel {
    min-height: 46vh;
  }

  /* The old desktop rule pushed the action group off-screen with margin-left:auto
     and no wrapping, which put Add Tracks outside the viewport entirely. */
  .topbar {
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 10px;
  }

  .topbar-actions {
    margin-left: 0;
    width: 100%;
    gap: 6px;
    flex-wrap: wrap;
  }

  .add-tracks {
    flex: 1 1 140px;
    justify-content: center;
    min-height: 40px;
  }

  .master-cluster,
  .brand-tag,
  .topbar-actions .segmented:not(.segmented-curve) {
    display: none;
  }

  .topbar-actions .btn {
    min-height: 36px;
  }

  /* Decks size to their content instead of fighting the mixer for a 1fr share.
     min-height matters: `min-height: 0` on the base rule lets a grid item shrink
     below its own content, which is exactly what collapsed them before. */
  .stage {
    grid-template-rows: auto auto auto;
  }

  .deck {
    padding: 8px 10px 10px;
    grid-template-rows: auto auto auto auto;
    min-height: 168px;
  }

  .deck-extra,
  .wave-overview,
  .deck-expand,
  .deck-meter,
  .cue-readout {
    display: none !important;
  }

  .wave-stack {
    grid-template-rows: minmax(84px, 1fr);
    min-height: 84px;
    max-height: 116px;
  }

  .wave-playhead {
    height: 100%;
  }

  .deck-head {
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 10px;
    padding-bottom: 7px;
  }

  /* [data-view] matches whichever mode is set, so these beat the compact-view
     rules above on specificity+order instead of losing to them on a phone. */
  body[data-view] .deck-title { font-size: 14px; }
  .deck-sub { display: none; }
  .deck-stats { gap: 12px; }
  .deck-stats .stat-remain { display: grid; }
  .stat-value { font-size: 13px; }

  .deck-transport {
    gap: 5px;
    padding-top: 7px;
  }

  .tbtn {
    min-height: 38px;
    padding: 6px 10px;
  }

  /* "Set In"/"Set Out"/"Reset" are desk work, not phone work. */
  .tbtn[data-action="set-in"],
  .tbtn[data-action="set-out"],
  .tbtn[data-action="reset-cues"] {
    display: none;
  }

  .mixer {
    padding: 9px 10px 10px;
  }

  /* The deck headers already carry title, elapsed and time-to-cue, and the queue
     foot says what is next — so on a phone the mixer keeps only the countdown and
     hands the height back to the decks. */
  .mixer-live {
    grid-template-columns: auto;
    justify-items: center;
    gap: 0;
  }

  .live-block { display: none; }

  body[data-view] .live-count { font-size: 26px; }

  .mixer-controls {
    justify-content: center;
    gap: 10px;
  }

  .crossfade-rig { flex: 1 1 100%; }
  .mixer-secondary { justify-content: center; }
  .segmented-curve { display: none; }

  /* The running commentary is desktop nicety; the deck badges and countdown carry
     the same information in a fraction of the height. */
  .mixer-status { display: none; }
  .mixer-foot { justify-content: center; }
  .mixer { gap: 8px; }

  .help-card,
  .about-card {
    width: min(94vw, 520px);
    padding: 16px;
  }
}

/* Very small phones: drop the fade-length slider too. */
@media (max-width: 430px) {
  .fade-len { display: none; }
  body[data-view] .live-count { font-size: 23px; }
}
