* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  user-select: none;
}

#playerApp {
  position: relative;
  width: 100%;
  height: 100%;
  height: calc(100dvh - 88px);
}

#playerApp:fullscreen,
#playerApp:-webkit-full-screen,
#playerApp.is-fullscreen-fallback {
  height: 100%;
  height: 100dvh;
  background: var(--bg);
  overflow: hidden;
}

#playerApp.is-fullscreen-fallback {
  position: fixed;
  inset: 0;
  z-index: 9999;
  padding:
    env(safe-area-inset-top)
    env(safe-area-inset-right)
    env(safe-area-inset-bottom)
    env(safe-area-inset-left);
}

.main-grid {
  display: grid;
  grid-template-columns: 5fr 5fr 3fr 3fr 5fr 5fr;
  grid-template-rows: 13fr 7fr;
  height: 100%;
  gap: 8px;
  padding: 8px;
  background: var(--bg);
}

#deckAPanel { grid-column: 1 / 3; grid-row: 1; }
.ascii-panel { grid-column: 3 / 5; grid-row: 1; }
#deckBPanel { grid-column: 5 / 7; grid-row: 1; }
.deck-viz-stack-a { grid-column: 1 / 2; grid-row: 2; }
.drumline-panel { grid-column: 2 / 6; grid-row: 2; }
.deck-viz-stack-b { grid-column: 6 / 7; grid-row: 2; }

#playerApp:fullscreen .main-grid,
#playerApp:-webkit-full-screen .main-grid,
#playerApp.is-fullscreen-fallback .main-grid {
  height: 100%;
  padding: 8px;
}

.panel {
  background: rgba(10, 15, 20, 0.75);
  background-image: var(--glass-gradient);
  border: var(--glass-border);
  box-shadow: var(--glass-shadow);
  border-radius: var(--radius);
  backdrop-filter: blur(12px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.panel-header {
  padding: 10px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.15);
  font-size: 15px;
  color: rgba(255, 255, 255, 0.65);
  flex-shrink: 0;
}

.panel-content {
  flex: 1;
  overflow: auto;
  padding: 12px;
}

.panel-content::-webkit-scrollbar { width: 10px; }
.panel-content::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.3);
  border-radius: 5px;
}
.panel-content::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, #555, #333);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
}

.deck-panel .panel-content {
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.deck-now { display: flex; gap: 10px; align-items: center; }

.deck-viz {
  width: 44px;
  height: 44px;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 3px;
  padding-bottom: 6px;
  flex-shrink: 0;
}

.deck-bar { width: 3px; background: var(--fg); border-radius: 2px; }
.deck-bar:nth-child(1) { animation: db 0.8s steps(8) infinite; }
.deck-bar:nth-child(2) { animation: db 0.6s steps(8) infinite 0.1s; }
.deck-bar:nth-child(3) { animation: db 0.7s steps(8) infinite 0.2s; }
.deck-bar:nth-child(4) { animation: db 0.5s steps(8) infinite 0.15s; }

@keyframes db {
  0%, 100% { height: 4px; }
  50% { height: 26px; }
}

.deck-viz:not(.playing) .deck-bar { animation: none; height: 4px; }

.deck-info { flex: 1; min-width: 0; }
.deck-label { font-size: 13px; color: rgba(255, 255, 255, 0.55); }
.deck-track { font-size: 16px; margin: 2px 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.deck-meta { font-size: 14px; color: rgba(255, 255, 255, 0.55); }

.deck-prog { display: flex; align-items: center; gap: 8px; padding: 6px 0; }
.deck-time { font-size: 13px; color: rgba(255, 255, 255, 0.55); min-width: 32px; font-variant-numeric: tabular-nums; }

.deck-prog-bar {
  flex: 1;
  height: 12px;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  position: relative;
}

.deck-prog-bg {
  position: absolute;
  width: 100%;
  height: 3px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 2px;
  pointer-events: none;
}

.deck-prog-fill {
  position: absolute;
  height: 3px;
  background: var(--fg);
  border-radius: 2px;
  width: 0%;
  pointer-events: none;
  box-shadow: 0 0 6px rgba(255, 255, 255, 0.4);
}

.deck-ctrls { display: flex; align-items: center; justify-content: center; gap: 6px; }

.deck-btn {
  width: 32px;
  height: 32px;
  background: transparent;
  border: 1px solid transparent;
  box-shadow: none;
  border-radius: 50%;
  color: rgba(255, 255, 255, 0.75);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  font-family: inherit;
  text-shadow: 0 1px 2px black;
}

.deck-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.3);
  color: var(--fg);
  box-shadow: 0 0 10px var(--accent);
  text-shadow: 0 0 5px var(--accent);
  transform: translateY(-1px);
}

.deck-btn.play {
  width: 38px;
  height: 38px;
  background: linear-gradient(180deg, #fff, #dddddd);
  border: none;
  box-shadow: 0 0 10px rgba(255, 255, 255, 0.4);
  text-shadow: none;
}

.deck-btn.play svg { fill: #000; }
.deck-btn.play:hover {
  background: linear-gradient(180deg, #fff, #dddddd);
  border: none;
  box-shadow: 0 0 10px rgba(255, 255, 255, 0.4);
  filter: brightness(1.1);
  transform: none;
  text-shadow: none;
}
.deck-btn svg { width: 14px; height: 14px; fill: currentColor; }
.deck-btn.active { border-color: var(--accent); color: var(--fg); }

.deck-vol,
.deck-pitch {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: center;
}

.deck-vol svg { width: 14px; height: 14px; fill: rgba(255, 255, 255, 0.55); }

.deck-vol-slider,
.deck-pitch-slider {
  flex: 1;
  max-width: 100px;
  height: 3px;
  -webkit-appearance: none;
  background: rgba(255, 255, 255, 0.25);
  border-radius: 2px;
}

.deck-vol-slider::-webkit-slider-thumb,
.deck-pitch-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  background: var(--fg);
  border-radius: 50%;
  box-shadow: 0 0 6px rgba(255, 255, 255, 0.4);
}

.deck-pitch-label,
.deck-pitch-value {
  font-size: 13px;
  color: rgba(255, 255, 255, 0.55);
  min-width: 36px;
}

.deck-pitch-value {
  min-width: 40px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.deck-sync {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.deck-sync-label {
  font-size: 13px;
  color: rgba(255, 255, 255, 0.55);
  min-width: 36px;
}

.deck-sync-btn {
  min-width: 44px;
  height: 24px;
  padding: 0 8px;
  background: transparent;
  border: 1px solid transparent;
  box-shadow: none;
  border-radius: 12px;
  color: rgba(255, 255, 255, 0.75);
  cursor: pointer;
  font-family: inherit;
  font-size: 11px;
  letter-spacing: 0.02em;
  transition: var(--transition);
  text-shadow: 0 1px 2px black;
}

.deck-sync-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.3);
  color: var(--fg);
  box-shadow: 0 0 10px var(--accent);
  text-shadow: 0 0 5px var(--accent);
  transform: translateY(-1px);
}

.deck-eq {
  display: flex;
  gap: 4px;
  justify-content: center;
}

.deck-eq-band {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
}

.deck-eq-label {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.55);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.deck-eq-knob {
  position: relative;
  width: 36px;
  height: 36px;
  cursor: ns-resize;
  touch-action: none;
}

.deck-eq-knob-dial {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background:
    radial-gradient(circle at 35% 28%, rgba(255, 255, 255, 0.22), transparent 45%),
    radial-gradient(circle at 50% 55%, rgba(40, 48, 58, 0.95), rgba(12, 16, 22, 0.98));
  border: 1px solid rgba(255, 255, 255, 0.28);
  box-shadow:
    inset 0 1px 2px rgba(255, 255, 255, 0.12),
    inset 0 -2px 4px rgba(0, 0, 0, 0.45),
    0 0 8px rgba(255, 255, 255, 0.08);
  transform: rotate(var(--knob-angle, 0deg));
  transition: box-shadow 0.15s ease;
}

.deck-eq-knob:hover .deck-eq-knob-dial,
.deck-eq-knob:focus-within .deck-eq-knob-dial {
  box-shadow:
    inset 0 1px 2px rgba(255, 255, 255, 0.16),
    inset 0 -2px 4px rgba(0, 0, 0, 0.45),
    0 0 10px rgba(255, 255, 255, 0.22);
}

.deck-eq-knob-mark {
  position: absolute;
  top: 5px;
  left: 50%;
  width: 2px;
  height: 9px;
  margin-left: -1px;
  border-radius: 1px;
  background: var(--fg);
  box-shadow: 0 0 5px rgba(255, 255, 255, 0.45);
}

.deck-eq-slider {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  opacity: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  pointer-events: none;
}

.deck-eq-value {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.55);
  font-variant-numeric: tabular-nums;
  min-width: 24px;
  text-align: center;
}

.deck-list { flex: 1; overflow: auto; display: flex; flex-direction: column; gap: 4px; }

.deck-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  cursor: grab;
  font-size: 14px;
  transition: transform 0.1s, opacity 0.1s, background 0.1s, border-color 0.1s;
}

.deck-item:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.2);
}

.deck-item.active {
  border-left: 3px solid var(--fg);
  box-shadow: 0 0 8px rgba(255, 255, 255, 0.15);
}

.deck-item.dragging { opacity: 0.5; cursor: grabbing; }
.deck-item.drag-over { background: rgba(255, 255, 255, 0.1); border-top-color: var(--fg); }
.deck-item .drag-handle { color: rgba(255, 255, 255, 0.45); cursor: grab; padding: 0 4px; font-size: 12px; }
.deck-num { color: rgba(255, 255, 255, 0.45); width: 18px; font-size: 13px; }
.deck-name { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.deck-bpm {
  color: rgba(255, 255, 255, 0.5);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  min-width: 52px;
  text-align: right;
}
.deck-dur { color: rgba(255, 255, 255, 0.45); font-size: 13px; }
.deck-del { opacity: 0; background: none; border: none; color: rgba(255, 255, 255, 0.45); cursor: pointer; font-size: 14px; font-family: inherit; }
.deck-item:hover .deck-del { opacity: 1; }
.deck-del:hover { color: #f66; }

.deck-add {
  padding: 8px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px dashed rgba(255, 255, 255, 0.25);
  border-radius: 8px;
  color: rgba(255, 255, 255, 0.65);
  cursor: pointer;
  text-align: center;
  font-size: 14px;
  font-family: inherit;
  margin-top: 6px;
  transition: var(--transition);
}

.deck-add:hover {
  border-color: rgba(255, 255, 255, 0.45);
  color: var(--fg);
  box-shadow: 0 0 10px rgba(255, 255, 255, 0.15);
}

.ascii-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  min-height: 0;
  padding: 8px;
}

.drumline-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 0;
  padding: 8px;
  overflow: hidden;
}

.ascii-art {
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.35rem;
  line-height: 1;
  color: var(--fg);
  white-space: pre;
  font-weight: 400;
}

.crossfader-section { display: flex; flex-direction: column; align-items: center; width: 80%; }
.crossfader-track {
  width: 100%;
  --crossfader-thumb: 22px;
}
.crossfader-labels {
  position: relative;
  display: flex;
  justify-content: space-between;
  width: calc(100% - var(--crossfader-thumb));
  margin: 0 auto 6px;
}
.crossfader-label {
  font-size: 14px;
  color: rgba(255, 255, 255, 0.55);
  user-select: none;
  line-height: 1;
}
.crossfader-labels .crossfader-label:nth-child(2) {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
}

.crossfader {
  flex: 1;
  width: 100%;
  height: 4px;
  -webkit-appearance: none;
  background: rgba(255, 255, 255, 0.25);
  border-radius: 2px;
  cursor: pointer;
}

.crossfader::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  background: var(--fg);
  border-radius: 50%;
  box-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
  cursor: grab;
}

.crossfader::-webkit-slider-thumb:active { cursor: grabbing; }

.deck-viz-stack {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 1;
  max-height: 100%;
  align-self: center;
  padding: 0;
  overflow: hidden;
}

.deck-viz-stack canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

@keyframes rotate-saw-a {
  from { transform: translate(-50%, -50%) rotate(0deg); }
  to { transform: translate(-50%, -50%) rotate(360deg); }
}

@keyframes rotate-saw-b {
  from { transform: translate(50%, -50%) rotate(0deg); }
  to { transform: translate(50%, -50%) rotate(360deg); }
}

.deck-circlesaw {
  position: absolute;
  top: 50%;
  width: 80%;
  height: auto;
  max-width: none;
  z-index: 1;
  pointer-events: none;
  opacity: 0.3;
  filter: grayscale(100%) contrast(1.2);
  mix-blend-mode: screen;
  transition: opacity 0.5s;
  animation-duration: 2s;
  animation-timing-function: linear;
  animation-iteration-count: infinite;
  animation-play-state: paused;
}

.deck-circlesaw-a {
  left: 0;
  transform: translate(-50%, -50%);
  animation-name: rotate-saw-a;
}

.deck-circlesaw-b {
  right: 0;
  transform: translate(50%, -50%);
  animation-name: rotate-saw-b;
}

.deck-circlesaw.active {
  opacity: 1;
  animation-play-state: running;
}

.toast {
  position: fixed;
  bottom: 5.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  padding: 8px 16px;
  background: rgba(10, 15, 20, 0.9);
  background-image: var(--glass-gradient);
  border: var(--glass-border);
  box-shadow: var(--glass-shadow);
  border-radius: 20px;
  color: var(--fg);
  font-size: 15px;
  opacity: 0;
  transition: all 0.2s;
  z-index: 1000;
  backdrop-filter: blur(10px);
}

.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }

.rotate-prompt {
  display: none;
}

@media (orientation: portrait) and (max-width: 900px) {
  html.ktn-player .rotate-prompt {
    display: flex;
    position: fixed;
    inset: 0;
    z-index: 10000;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: #000;
    color: var(--fg);
    text-align: center;
    font-size: 22px;
    line-height: 1.4;
  }

  html.ktn-player #playerApp,
  html.ktn-player .bottom-menu {
    visibility: hidden;
    pointer-events: none;
  }
}
