:root {
  --bg: #15120e;
  --glow: 214 120 64;
  --pad: clamp(12px, 3vw, 40px);
  --cw: 600px;            /* cassette width, set by JS */
  --ink: #1d2a6b;
  --led: #ffb347;
}

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

html, body {
  height: 100%;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

body {
  font-family: "Archivo Narrow", system-ui, sans-serif;
  color: #eee;
  background:
    radial-gradient(ellipse 70% 60% at 40% 45%, rgb(var(--glow) / .20), transparent 70%),
    radial-gradient(ellipse at 50% 130%, #000 0, transparent 60%),
    var(--bg);
}

button { font: inherit; color: inherit; }

/* ---------- layout ---------- */

#stage {
  height: 100dvh;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  justify-items: center;
  gap: clamp(16px, 3vw, 44px);
  padding: var(--pad);
  padding-left: max(var(--pad), env(safe-area-inset-left));
  padding-right: max(var(--pad), env(safe-area-inset-right));
}

/* ---------- deck ---------- */

.deck {
  position: relative;
  width: min(100%, 1040px, calc((100dvh - 2 * var(--pad) - 190px) / 0.56));
  border-radius: 18px;
  padding: clamp(14px, 2.2vw, 26px);
  color: #2a2722;
  background:
    repeating-linear-gradient(90deg, rgba(255,255,255,.05) 0 1px, rgba(0,0,0,.035) 1px 3px),
    linear-gradient(180deg, #e6e3dc 0%, #c4bfb5 55%, #a7a196 100%);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,.7),
    inset 0 -3px 0 rgba(0,0,0,.25),
    0 34px 70px rgba(0,0,0,.65),
    0 8px 18px rgba(0,0,0,.5);
}

.deck-top {
  display: flex;
  align-items: center;
  gap: clamp(10px, 2vw, 22px);
  margin-bottom: clamp(10px, 1.6vw, 18px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: "Archivo Black", sans-serif;
  letter-spacing: .2em;
  font-size: clamp(14px, 1.8vw, 21px);
  line-height: 1;
  white-space: nowrap;
}
.brand small {
  display: block;
  margin-top: 4px;
  font-family: "Archivo Narrow", sans-serif;
  font-weight: 700;
  font-size: .48em;
  letter-spacing: .32em;
  text-transform: uppercase;
  opacity: .65;
}

.led {
  width: 10px; height: 10px; border-radius: 50%;
  background: #5a1a12;
  box-shadow: inset 0 1px 2px rgba(0,0,0,.6);
  transition: background .3s, box-shadow .3s;
}
.led.on {
  background: #ff4d2e;
  box-shadow: 0 0 8px #ff4d2e, inset 0 -1px 2px rgba(0,0,0,.3);
}

.lcd {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 14px;
  border-radius: 6px;
  background: #0a0d0a;
  box-shadow: inset 0 2px 8px #000, 0 1px 0 rgba(255,255,255,.6);
  font-family: "Share Tech Mono", monospace;
  font-size: clamp(12px, 1.6vw, 17px);
  color: var(--led);
  text-shadow: 0 0 6px rgba(255,170,60,.65);
  white-space: nowrap;
  overflow: hidden;
}
.lcd .mode, .lcd .time { flex: none; }
.lcd .marquee {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 6%, #000 94%, transparent);
          mask-image: linear-gradient(90deg, transparent, #000 6%, #000 94%, transparent);
}
.lcd .marquee span {
  display: inline-block;
  padding-left: 100%;
  animation: marquee var(--dur, 14s) linear infinite;
}
@keyframes marquee { to { transform: translateX(-100%); } }

.menu-btn {
  flex: none;
  display: flex; gap: 3px; align-items: center; justify-content: center;
  width: 34px; height: 34px;
  border: 0; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #f3f1ec, #b4afa5);
  box-shadow: 0 2px 4px rgba(0,0,0,.35), inset 0 -2px 3px rgba(0,0,0,.2);
  cursor: pointer;
}
.menu-btn span { width: 4px; height: 4px; border-radius: 50%; background: #555; }

.bay {
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(90px, 13vw, 150px);
  gap: clamp(10px, 1.6vw, 18px);
}

/* The bay: a static recess in the deck (.well) with the deck's insides (.mech),
   covered by a door hinged at its bottom edge. The cassette rides in the door's holder. */
.well {
  --door-pad: clamp(10px, 2vw, 22px);
  position: relative;
  border-radius: 12px;
  background: radial-gradient(ellipse at 50% 30%, #1d1c1b, #070707 70%);
  box-shadow:
    inset 0 0 0 2px #000,
    inset 0 10px 24px rgba(0,0,0,.95),
    0 1px 0 rgba(255,255,255,.7),
    0 -1px 0 rgba(0,0,0,.3);
  perspective: 1000px;
  perspective-origin: 50% -30%;
}

.mech { position: absolute; inset: var(--door-pad); pointer-events: none; }
.mech .spindle {
  position: absolute; top: 50.8%;
  width: 7%; aspect-ratio: 1;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background:
    radial-gradient(circle, #c9c9c9 0 22%, #6d6d6d 24% 34%, transparent 36%),
    repeating-conic-gradient(#bdbdbd 0 14deg, transparent 14deg 60deg);
  box-shadow: 0 0 0 2px rgba(0,0,0,.6), 0 4px 10px rgba(0,0,0,.8);
}
.mech .spindle.l { left: 29%; }
.mech .spindle.r { left: 71%; }
.mech .head {
  position: absolute; left: 50%; bottom: 3%;
  width: 11%; height: 9%;
  transform: translateX(-50%);
  border-radius: 4px 4px 2px 2px;
  background: linear-gradient(90deg, #6a6a6a, #e6e6e6 45%, #8d8d8d 55%, #555);
  box-shadow: 0 -3px 8px rgba(0,0,0,.8);
}
.mech .capstan {
  position: absolute; bottom: 7%;
  width: 1.6%; aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff, #8c8c8c 60%, #3a3a3a);
}
.mech .capstan.l { left: 29.5%; }
.mech .capstan.r { left: 69%; }

.door {
  position: relative;
  padding: var(--door-pad);
  border-radius: 12px;
  background: linear-gradient(#141415, #1f1e20);
  box-shadow:
    inset 0 0 0 2px #000,
    inset 0 8px 20px rgba(0,0,0,.85),
    0 0 0 rgba(0,0,0,0);
  transform-origin: 50% 100%;
  transform-style: preserve-3d;
  transition: transform .55s cubic-bezier(.25,.8,.35,1.1), box-shadow .55s, filter .55s;
}
.door.open {
  transform: rotateX(-34deg);
  filter: brightness(1.12);
  box-shadow:
    inset 0 0 0 2px #000,
    inset 0 8px 20px rgba(0,0,0,.85),
    0 -18px 30px rgba(0,0,0,.55);
}
.door.closing { transition: transform .3s cubic-bezier(.6,0,.95,.55), box-shadow .3s, filter .3s; }
.door-tab {
  position: absolute; top: 4px; left: 50%;
  transform: translateX(-50%);
  padding: 1px 10px;
  border-radius: 0 0 6px 6px;
  background: rgba(255,255,255,.06);
  color: rgba(255,255,255,.35);
  font: 700 clamp(7px, .8vw, 10px)/1.4 "Archivo Narrow", sans-serif;
  letter-spacing: .25em;
  pointer-events: none;
}

.holder { position: relative; transform-style: preserve-3d; }

.glass {
  position: absolute; inset: 0;
  border-radius: 12px;
  pointer-events: none;
  background:
    linear-gradient(112deg, rgba(255,255,255,.11) 0%, rgba(255,255,255,.03) 28%, transparent 29%,
                    transparent 62%, rgba(255,255,255,.05) 63%, transparent 76%),
    rgba(40,30,20,.10);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.07);
}

.deck.clunk { animation: clunk .22s ease-out; }
@keyframes clunk { 30% { transform: translateY(2px); } 60% { transform: translateY(-1px); } }

/* ---------- cassette ---------- */

.cassette {
  position: relative;
  width: 100%;
  aspect-ratio: 1000 / 640;
  transform-origin: 50% 100%;
  transition: transform .6s cubic-bezier(.45,0,.3,1), opacity .6s;
}
.shell, .shell svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

/* lifted up and out of the open door, toward the viewer */
.cassette.out {
  transform: translateY(-118%) translateZ(60px) rotateX(-6deg);
  opacity: 0;
  transition: transform .65s cubic-bezier(.5,0,.6,1), opacity .35s .3s;
}
.cassette.no-anim { transition: none; }

.label-ink {
  position: absolute;
  left: var(--lx, 8.6%);
  right: var(--rx, 7.5%);
  top: var(--ty, 10.6%);
  height: var(--th, 18.5%);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  color: var(--ink);
  transform: rotate(var(--tilt, 0deg));
  transform-origin: 0 50%;
  pointer-events: none;
}
.label-ink .line1 {
  display: flex;
  align-items: baseline;
  gap: calc(var(--cw) * .02);
  padding-left: calc(var(--cw) * .075);
  min-width: 0;
}
.label-ink .title {
  flex: 1;
  min-width: 0;
  font-family: "Permanent Marker", cursive;
  font-size: calc(var(--cw) * .05);
  line-height: 1.05;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: .92;
}
.label-ink .num {
  flex: none;
  font-family: "Caveat", cursive;
  font-weight: 700;
  font-size: calc(var(--cw) * .045);
  opacity: .85;
}
.label-ink .line2 {
  font-family: "Caveat", cursive;
  font-weight: 700;
  font-size: calc(var(--cw) * .043);
  line-height: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: .88;
}
.label-ink.erase .line1, .label-ink.erase .line2 { opacity: 0; transition: opacity .25s; }
.label-ink.write .line1 { animation: write 1.1s cubic-bezier(.4,.1,.5,1) both; }
.label-ink.write .line2 { animation: write 1.1s cubic-bezier(.4,.1,.5,1) .55s both; }
@keyframes write {
  from { clip-path: inset(-20% 100% -20% 0); }
  to   { clip-path: inset(-20% 0 -20% 0); }
}

/* ---------- VU meters ---------- */

.meters { display: flex; flex-direction: column; gap: clamp(8px, 1.2vw, 14px); }
.vu {
  flex: 1;
  position: relative;
  border-radius: 8px;
  overflow: hidden;
  background: linear-gradient(#f7e9bd, #e6cf8c);
  box-shadow: inset 0 0 0 3px #26231f, inset 0 6px 12px rgba(0,0,0,.35), 0 1px 0 rgba(255,255,255,.6);
}
.vu svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.vu::after { /* backlight + glass */
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(160deg, rgba(255,255,255,.35), transparent 40%),
              radial-gradient(ellipse at 50% 100%, rgba(255,160,40,.0), rgba(255,160,40,.0));
}

/* ---------- keys ---------- */

.keys {
  display: flex;
  gap: clamp(6px, 1vw, 12px);
  margin-top: clamp(12px, 1.8vw, 20px);
  padding: 6px;
  border-radius: 10px;
  background: rgba(0,0,0,.18);
  box-shadow: inset 0 2px 6px rgba(0,0,0,.4), 0 1px 0 rgba(255,255,255,.5);
}
.key {
  position: relative;
  flex: 1;
  height: clamp(50px, 7vw, 72px);
  border: 0;
  border-radius: 5px 5px 9px 9px;
  background: linear-gradient(#45423e, #232220 70%, #1a1918);
  color: #e9e6df;
  box-shadow: 0 7px 0 #0c0b0a, 0 9px 16px rgba(0,0,0,.45), inset 0 1px 0 rgba(255,255,255,.18);
  transition: transform .08s, box-shadow .08s;
  cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
}
.key svg { width: clamp(16px, 2.2vw, 24px); height: auto; fill: currentColor; }
.key .lbl { font-size: clamp(8px, 1vw, 11px); letter-spacing: .22em; font-weight: 700; opacity: .55; }
.key:active, .key.down {
  transform: translateY(6px);
  box-shadow: 0 1px 0 #0c0b0a, 0 2px 4px rgba(0,0,0,.5), inset 0 1px 0 rgba(255,255,255,.1);
}
.key.play::after {
  content: ""; position: absolute; top: 8px; right: 10px;
  width: 6px; height: 6px; border-radius: 50%;
  background: #1f3a1c;
}
.key.play.down::after { background: #64ff5a; box-shadow: 0 0 6px #64ff5a; }

/* ---------- J-card ---------- */

.jcard {
  width: clamp(220px, 24vw, 320px);
  max-height: calc(100dvh - 2 * var(--pad));
  display: flex;
  flex-direction: column;
  background: #f2eee3;
  color: #222;
  border-radius: 3px;
  box-shadow: 0 24px 50px rgba(0,0,0,.55), 0 4px 10px rgba(0,0,0,.4);
  transform: rotate(1.6deg);
  overflow: hidden;
  transition: opacity .6s, transform .6s;
}
.jcard.swap { opacity: 0; transform: rotate(4deg) translateY(16px); }
.jcard .spine {
  flex: none;
  padding: 7px 12px;
  background: var(--stripe, #c0392b);
  color: var(--on-stripe, #fff);
  font-family: "Archivo Black", sans-serif;
  font-size: 11px;
  letter-spacing: .18em;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.jcard .art-wrap { flex: none; aspect-ratio: 1; background: #2a2724; }
.jcard .art { width: 100%; height: 100%; object-fit: cover; display: block; }
.jcard .art:not([src]), .jcard .art[src=""] { visibility: hidden; }
.jcard .jbody { flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 12px 14px 8px; }
.jcard .jtitle {
  font-family: "Permanent Marker", cursive;
  font-size: 20px; line-height: 1.1;
  color: var(--ink);
}
.jcard .jartist { font-family: "Caveat", cursive; font-weight: 700; font-size: 20px; color: #555; margin-bottom: 6px; }
.tracklist {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  list-style: none;
  font-family: "Caveat", cursive;
  font-size: 19px;
  line-height: 1.15;
  color: #333;
  scrollbar-width: none;
  background-image: linear-gradient(transparent calc(100% - 1px), rgba(0,0,0,.1) 0);
  background-size: 100% 1.15em;
  background-attachment: local;
}
.tracklist::-webkit-scrollbar { display: none; }
.tracklist .side {
  font-family: "Archivo Narrow", sans-serif;
  font-weight: 700; font-size: 11px; letter-spacing: .25em;
  color: #888; padding-top: 6px;
}
.tracklist li.trk { display: flex; gap: 6px; white-space: nowrap; }
.tracklist li.trk .n { flex: none; width: 1.4em; text-align: right; color: #999; }
.tracklist li.trk .t { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.tracklist li.trk.now { color: var(--ink); font-weight: 700; }
.tracklist li.trk.now .t {
  background: linear-gradient(transparent 55%, rgb(255 230 80 / .65) 55%, rgb(255 230 80 / .65) 90%, transparent 90%);
}

/* ---------- menu / overlay / toast ---------- */

.menu {
  position: fixed;
  z-index: 20;
  display: flex; flex-direction: column;
  min-width: 190px;
  padding: 6px;
  border-radius: 10px;
  background: #1f1d1a;
  box-shadow: 0 16px 40px rgba(0,0,0,.6);
}
.menu[hidden] { display: none; }
.menu button {
  text-align: left;
  padding: 11px 14px;
  border: 0; border-radius: 6px;
  background: transparent;
  font-size: 15px;
  cursor: pointer;
}
.menu button:hover { background: rgba(255,255,255,.08); }

.overlay {
  position: fixed; inset: 0; z-index: 30;
  display: grid; place-items: center;
  padding: 20px;
  background: rgba(10,8,6,.82);
  -webkit-backdrop-filter: blur(6px);
          backdrop-filter: blur(6px);
  -webkit-user-select: text; user-select: text;
}
.overlay[hidden] { display: none; }
.card {
  width: min(520px, 100%);
  max-height: 100%;
  overflow: auto;
  padding: 28px;
  border-radius: 6px;
  background: #f2eee3;
  color: #222;
  box-shadow: 0 30px 70px rgba(0,0,0,.6);
  font-size: 16px; line-height: 1.45;
}
.card h1 { font-family: "Permanent Marker", cursive; font-weight: 400; font-size: 34px; color: #1d2a6b; margin-bottom: 6px; }
.card .msg { color: #a3261b; font-weight: 700; margin-bottom: 8px; }
.card .msg:empty { display: none; }
.card ol { padding-left: 22px; margin: 10px 0 14px; display: grid; gap: 10px; }
.card a { color: #1d2a6b; }
.copy-row { display: flex; gap: 8px; align-items: center; margin-top: 6px; }
.copy-row code {
  flex: 1; min-width: 0; overflow-x: auto; white-space: nowrap;
  padding: 7px 9px; border-radius: 4px; background: #fff; border: 1px solid #d6d0c2;
  font-size: 13px;
}
.copy-row button, .card .primary {
  border: 0; border-radius: 6px; cursor: pointer;
  padding: 8px 12px; background: #2a2722; color: #fff; font-weight: 700;
}
.card input {
  width: 100%;
  padding: 11px 12px;
  border-radius: 6px;
  border: 1px solid #c9c2b2;
  font: 15px "Share Tech Mono", monospace;
  margin-bottom: 12px;
}
.card .primary { width: 100%; padding: 13px; font-size: 16px; background: #1db954; color: #08260f; }
.card .demo-link { display: block; text-align: center; margin-top: 14px; font-size: 14px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 40;
  transform: translate(-50%, 140%);
  padding: 11px 18px;
  border-radius: 8px;
  background: #222; color: #fff;
  box-shadow: 0 10px 30px rgba(0,0,0,.5);
  font-size: 15px;
  opacity: 0;
  visibility: hidden;
  transition: transform .35s, opacity .35s, visibility .35s;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; visibility: visible; }

/* ---------- responsive ---------- */

/* portrait / narrow: stack the J-card under the deck, side by side art + list */
@media (max-aspect-ratio: 6/5) {
  html, body { overflow: auto; }
  #stage { height: auto; min-height: 100dvh; grid-template-columns: minmax(0, 1fr); align-content: center; }
  .deck { width: min(100%, 900px); }
  .jcard {
    width: min(100%, 900px);
    max-height: none;
    flex-direction: row;
    flex-wrap: wrap;
    transform: rotate(.6deg);
  }
  .jcard .spine { flex-basis: 100%; }
  .jcard .art-wrap { width: 38%; }
  .jcard .jbody { width: 62%; max-height: 38vw; }
}

@media (max-width: 640px) {
  .meters { display: none; }
  .bay { grid-template-columns: 1fr; }
  .brand small { display: none; }
}

#setup-simple p { margin: 4px 0 18px; }
