:root {
  --bg: #0c0b0a;
  --panel: #1c1a17;
  --line: #3a342c;
  --text: #f4efe6;
  --muted: #9a9184;
  --amber: #f0a330;
  --amber-dim: #8a5a14;
  --red: #e03737;
  --red-dim: #7a1d1d;
  --green: #3dcf7a;
  --blue: #4aa3ff;
  --pink: #ee6ec0;
  --orange: #ff8a3d;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  font-synthesis: none;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Avenir Next", "Segoe UI", "Helvetica Neue", sans-serif;
  min-height: 100%;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; color: inherit; }
button {
  background: var(--metal, #2c3138);
  border: 1px solid #3a4048;
  border-radius: 12px;
  color: var(--text);
  padding: 10px 14px;
  min-height: 48px;
  cursor: pointer;
  touch-action: manipulation;
  font-size: 1rem;
}
button:active { transform: translateY(1px); }
button.primary { background: #3a2a14; border-color: var(--amber-dim); color: var(--amber); }
button.danger { background: var(--red-dim); border-color: var(--red); }
button.on { box-shadow: inset 0 0 0 2px var(--amber); }
button:disabled { opacity: 0.45; cursor: default; transform: none; }

#app {
  padding: calc(8px + var(--safe-t)) calc(12px + var(--safe-r)) calc(12px + var(--safe-b)) calc(12px + var(--safe-l));
  max-width: 1400px;
  margin: 0 auto;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  margin-bottom: 6px;
}
.brand { flex: 1; min-width: 0; }
.brand h1 {
  margin: 0;
  font-size: 1.05rem;
  letter-spacing: 0.02em;
  font-weight: 700;
}
.brand .sub {
  margin: 0;
  font-size: 0.78rem;
  color: var(--muted);
}
.topbar-actions { display: flex; gap: 6px; flex-shrink: 0; }

#booth { display: flex; flex-direction: column; gap: 10px; }

.deck, .mixer {
  background: linear-gradient(180deg, var(--panel) 0%, #141210 100%);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 10px 12px;
  box-shadow: var(--shadow);
}
.deck-head, .mixer-head {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.deck-label {
  font-weight: 700;
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  background: #2a2118;
  color: var(--amber);
  padding: 4px 8px;
  border-radius: 999px;
}
.song-name {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 650;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.status-line {
  margin: 2px 0 8px;
  text-align: center;
  color: var(--muted);
  font-size: 0.95rem;
  min-height: 1.3em;
  line-height: 1.3;
}

.simple-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}
.simple-actions .btn-big { flex: 1; }
.btn-big {
  min-height: 52px;
  font-size: 1.05rem;
  font-weight: 700;
  padding: 10px 12px;
}
.btn-play {
  width: 100%;
  min-height: 56px;
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  background: #153321;
  border-color: var(--green);
  color: var(--green);
}
[data-role="play"].playing, .btn-play.playing {
  background: #3a1515;
  border-color: var(--red);
  color: #ffd0d0;
}

.help-dot {
  min-width: 48px;
  min-height: 48px;
  width: 48px;
  height: 48px;
  padding: 0;
  border-radius: 50%;
  background: #2a2622;
  color: var(--muted);
  font-weight: 700;
  flex-shrink: 0;
}
#helpHome.help-dot { min-width: 44px; min-height: 44px; width: 44px; height: 44px; }

.deck-body { display: grid; gap: 10px; align-items: center; }
.simple-mode .simple-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.simple-mode .simple-body .deck-controls {
  width: 100%;
}

.platter-wrap { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.platter {
  --size: 58vw;
  width: min(var(--size), 260px);
  height: min(var(--size), 260px);
  position: relative;
  border-radius: 50%;
  touch-action: none;
  user-select: none;
  cursor: grab;
  filter: drop-shadow(0 8px 16px rgba(0,0,0,0.55));
}
.platter.grabbed, .platter:active { cursor: grabbing; }
.platter.grabbed { filter: drop-shadow(0 0 16px rgba(240,163,48,0.45)) brightness(1.08); }
.vinyl {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  position: relative;
  background: radial-gradient(circle at 50% 50%, #222 0 14%, #0a0a0a 15%, #0a0a0a 100%);
  overflow: hidden;
  transform: rotate(0deg);
  will-change: transform;
}
.vinyl::before {
  content: "";
  position: absolute;
  inset: 6%;
  border-radius: 50%;
  background: repeating-radial-gradient(circle at 50% 50%,
    rgba(255,255,255,0.035) 0 1px,
    transparent 1px 5px);
  pointer-events: none;
}
.vinyl .label {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 38%;
  height: 38%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #d9b56a, #8a5a18 55%, #4a300c);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 6px;
  box-shadow: inset 0 0 0 3px rgba(0,0,0,0.25);
}
.vinyl .label span {
  font-size: 0.62rem;
  line-height: 1.15;
  color: #1a1004;
  font-weight: 700;
  overflow: hidden;
  max-height: 100%;
  word-break: break-word;
}
.spindle {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 8%;
  height: 8%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: #c5c8ce;
  box-shadow: 0 0 0 2px #666, inset 0 1px 2px #fff;
  z-index: 2;
}
.ghost-hand {
  position: absolute;
  width: 48px;
  height: 48px;
  right: 8%;
  top: 18%;
  z-index: 3;
  pointer-events: none;
  background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64'><path fill='%23f4d7b0' stroke='%23331' stroke-width='2' d='M22 34V16a4 4 0 0 1 8 0v10m0 0V14a4 4 0 0 1 8 0v14m0 0V16a4 4 0 0 1 8 0v18m0-8a4 4 0 0 1 8 0v16c0 10-8 18-20 18h-2c-11 0-18-6-22-14l-6-12a4 4 0 0 1 7-4l5 8V34z'/></svg>") center/contain no-repeat;
  opacity: 0;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.7));
}
.guide-on .ghost-hand { opacity: 0.95; }
.guide-baby .ghost-hand { animation: scratchBaby 1s ease-in-out infinite; }
.guide-scribble .ghost-hand { animation: scratchBaby 0.28s ease-in-out infinite; }
.guide-forward .ghost-hand { animation: scratchFwd 0.8s ease-in-out infinite; }
.guide-hand-hold .ghost-hand { animation: handHold 1.6s ease-in-out infinite; opacity: 0.95; }
.guide-chirp .ghost-hand, .guide-transformer .ghost-hand, .guide-xfader-sweep .ghost-hand { display: none; }

@keyframes scratchBaby {
  0% { transform: translate(0, 0) rotate(-18deg); }
  50% { transform: translate(-10px, 14px) rotate(16deg); }
  100% { transform: translate(0, 0) rotate(-18deg); }
}
@keyframes scratchFwd {
  0%, 15% { transform: translate(6px, -4px) rotate(-8deg); opacity: 0.95; }
  45% { transform: translate(-18px, 16px) rotate(20deg); opacity: 0.95; }
  55%, 100% { transform: translate(6px, -4px) rotate(-8deg); opacity: 0.35; }
}
@keyframes handHold {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(0.96); }
}

.time-row {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: center;
  font-variant-numeric: tabular-nums;
  font-size: 0.9rem;
  color: var(--muted);
  width: 100%;
}
.scratch-hint {
  color: var(--amber);
  font-weight: 650;
  font-size: 0.95rem;
}
.scratch-hint.live { color: var(--green); }
.scratch-hint.back { color: #8ecbff; }

.waveform {
  width: 100%;
  height: 40px;
  border-radius: 8px;
  background: #0a0908;
  display: block;
  touch-action: manipulation;
  cursor: pointer;
}
.simple-mode #deckA .waveform { height: 36px; }

.transport, .hotcues { display: flex; gap: 6px; flex-wrap: wrap; }
.transport button { flex: 1; min-width: 64px; font-weight: 700; }
[data-role="cue"] { background: #3a1515; }
.hotcues button { flex: 1; min-width: 48px; font-weight: 700; }
.hotcues button.set-0 { background: #14331f; border-color: var(--green); }
.hotcues button.set-1 { background: #132c4a; border-color: var(--blue); }
.hotcues button.set-2 { background: #3a2410; border-color: var(--orange); }
.hotcues button.set-3 { background: #3a1430; border-color: var(--pink); }

.pitch-wrap {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  gap: 6px;
  align-items: center;
  font-size: 0.85rem;
  color: var(--muted);
}
.pitch-wrap input[type="range"] { width: 100%; }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  height: 48px;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 8px;
  background: #3a342c;
  border-radius: 99px;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 28px;
  height: 28px;
  margin-top: -10px;
  border-radius: 6px;
  background: linear-gradient(#efe6d6, #c4b090);
  border: 1px solid #6a5a3a;
  box-shadow: 0 2px 4px rgba(0,0,0,0.4);
}
input[type="range"].vert {
  writing-mode: vertical-lr;
  direction: rtl;
  width: 48px;
  height: 130px;
  padding: 0;
}
input[type="range"].vert::-webkit-slider-runnable-track { width: 8px; height: 100%; }
input[type="range"].vert::-webkit-slider-thumb {
  margin-top: 0;
  margin-left: -10px;
}

.auto-row { display: flex; flex-direction: column; gap: 8px; }
#makeScratches { width: 100%; min-height: 52px; font-size: 1.1rem; }
#previewRow { display: flex; gap: 8px; }
#previewRow[hidden] { display: none !important; }
#previewRow .btn-big { flex: 1; }
.simple-nav { display: flex; gap: 8px; }
.simple-nav button { flex: 1; min-height: 48px; }

/* Hide advanced controls until More tools is on. Keep them in the DOM. */
.simple-mode .tools-only { display: none !important; }
body.tools-on .tools-only { display: revert !important; }
body.tools-on .hotcues.tools-only,
body.tools-on .pitch-wrap.tools-only,
body.tools-on .transport.tools-only { display: flex !important; }
body.tools-on .faders { display: flex !important; }
body.tools-on #mixer.tools-only,
body.tools-on #deckB.tools-only { display: block !important; }

.mixer-head { justify-content: space-between; }
.faders {
  display: flex;
  justify-content: space-around;
  align-items: flex-end;
  gap: 8px;
  padding: 4px 0 8px;
}
.faders label {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  color: var(--muted);
}
.vu {
  height: 8px;
  background: #222;
  border-radius: 99px;
  overflow: hidden;
  margin: 0 8px 8px;
}
.vu > i {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--green), var(--amber) 70%, var(--red));
}
.xf-wrap {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
}
#xfader { width: 100%; height: 52px; }
#xfader::-webkit-slider-runnable-track { height: 16px; background: #2a2e33; }
#xfader::-webkit-slider-thumb {
  width: 36px;
  height: 36px;
  margin-top: -10px;
  border-radius: 4px;
  background: linear-gradient(#f0ece3, #9a9ea6);
}
.mix-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.mix-actions button { flex: 1; }
#recordBtn.rec { background: var(--red-dim); border-color: var(--red); animation: recPulse 1s infinite; }
@keyframes recPulse { 50% { opacity: 0.7; } }

#learnDrawer, #helpSheet, #libSheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: #161410;
  border-top: 1px solid var(--line);
  border-radius: 16px 16px 0 0;
  padding: 16px 16px calc(16px + var(--safe-b));
  z-index: 40;
  max-height: 70vh;
  overflow: auto;
  box-shadow: 0 -12px 40px rgba(0,0,0,0.5);
  transform: translateY(110%);
  transition: transform 0.22s ease;
}
#learnDrawer.open, #helpSheet.open, #libSheet.open { transform: translateY(0); }
.drawer-title { margin: 0 0 8px; font-size: 1.2rem; }
.lesson-step { color: var(--muted); font-size: 0.85rem; margin: 0 0 6px; }
.lesson-body { font-size: 1.05rem; line-height: 1.45; margin: 0 0 12px; }
.lesson-feedback {
  min-height: 1.5em;
  color: var(--green);
  font-weight: 700;
  font-size: 1.15rem;
  margin-bottom: 10px;
}
.lesson-feedback.warn { color: var(--amber); }
.drawer-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.drawer-actions button { flex: 1; }
.lesson-list { display: none; }

.xf-guide {
  height: 28px;
  position: relative;
  background: #2a2e33;
  border-radius: 6px;
  margin: 0 0 10px;
  display: none;
}
.guide-chirp .xf-guide, .guide-transformer .xf-guide, .guide-xfader-sweep .xf-guide { display: block; }
.xf-guide i {
  position: absolute;
  top: 2px;
  width: 18px;
  height: 24px;
  border-radius: 3px;
  background: #ddd;
  left: 50%;
}
.guide-xfader-sweep .xf-guide i { animation: xfSweep 2s ease-in-out infinite; }
.guide-chirp .xf-guide i { animation: xfChirp 0.7s ease-in-out infinite; }
.guide-transformer .xf-guide i { animation: xfChirp 0.4s linear infinite; }
@keyframes xfSweep {
  0% { left: 4%; }
  50% { left: 90%; }
  100% { left: 4%; }
}
@keyframes xfChirp {
  0%, 55% { left: 88%; }
  70% { left: 20%; }
  100% { left: 88%; }
}

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + var(--safe-b));
  transform: translateX(-50%) translateY(20px);
  background: #2a241c;
  border: 1px solid var(--amber-dim);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 12px;
  opacity: 0;
  pointer-events: none;
  z-index: 50;
  transition: opacity 0.2s, transform 0.2s;
  max-width: 90vw;
  font-size: 1rem;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

#undoBar {
  display: none;
  position: sticky;
  bottom: 0;
  background: #2a1c10;
  border: 1px solid var(--orange);
  border-radius: 10px;
  padding: 8px;
  margin-top: 8px;
  align-items: center;
  gap: 8px;
  z-index: 5;
}
#undoBar.show { display: flex; }

.hl-flash { outline: 2px solid var(--amber); outline-offset: 2px; border-radius: 10px; }
.tip { font-size: 0.85rem; color: var(--muted); padding: 6px 2px 0; }

/* Simple mode: one column, no page scroll on a 390x844 phone. */
.simple-mode #app { max-width: 560px; }
.simple-mode { overflow: hidden; }
.simple-mode #app { overflow: hidden; }
.tools-on { overflow-x: hidden; overflow-y: auto; }
.tools-on #app { overflow: visible; max-width: 1400px; }

/* PC detection class still applied; simple flow stays the same. */
.layout-pc.simple-mode .platter { --size: 320px; width: 320px; height: 320px; }
.layout-pc.simple-mode #app { max-width: 560px; }
.layout-pc #learnDrawer, .layout-pc #helpSheet, .layout-pc #libSheet {
  left: auto;
  right: 16px;
  top: 70px;
  bottom: auto;
  width: 400px;
  max-height: calc(100vh - 90px);
  border-radius: 16px;
  border: 1px solid var(--line);
  transform: translateX(120%);
}
.layout-pc #learnDrawer.open, .layout-pc #helpSheet.open, .layout-pc #libSheet.open { transform: translateX(0); }

/* More tools on a wide screen: two songs beside the mixer. */
.layout-pc.tools-on #booth {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 230px minmax(0, 1fr);
  align-items: start;
  gap: 12px;
}
.layout-pc.tools-on .auto-row,
.layout-pc.tools-on .simple-nav { grid-column: 1 / -1; }
.layout-pc.tools-on #deckA { grid-column: 1; grid-row: 1; }
.layout-pc.tools-on #mixer { grid-column: 2; grid-row: 1; }
.layout-pc.tools-on #deckB { grid-column: 3; grid-row: 1; }
.layout-pc.tools-on .platter { --size: 280px; width: 280px; height: 280px; }
.layout-pc .faders label input.vert { height: 180px; }
.layout-pc .waveform { height: 56px; }

@media (max-width: 400px) {
  .brand h1 { font-size: 0.98rem; }
  .song-name { font-size: 1.05rem; }
  .simple-mode .platter { --size: 52vw; }
}

/* Prevent the main simple screen from forcing scroll on iPhone-sized viewports. */
@media (max-height: 860px) {
  .simple-mode .platter { --size: min(52vw, 230px); }
  .simple-mode #deckA .waveform { height: 32px; }
}
