:root {
  --bg: #05060b; --bg2: #0a0d15; --panel: #0d111b; --card: #121726; --line: #1e2638; --line2: #2a3550;
  --text: #e7e9f2; --muted: #8890a6; --accent: #a88bff; --accent2: #5fd3ff; --hot: #ff5577; --ok: #6dffb3;
  --r: 10px; --font: 'Space Grotesk', system-ui, sans-serif; --mono: 'JetBrains Mono', ui-monospace, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 14px/1.45 var(--font); }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
code, kbd { font-family: var(--mono); font-size: 11.5px; background: #1a2133; border: 1px solid var(--line2); border-radius: 4px; padding: 0 4px; }

#app {
  display: grid; height: 100vh; height: 100dvh;
  grid-template-columns: minmax(0, 1fr) 380px;
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-areas: "top top" "stage panel";
}
.top { grid-area: top; display: flex; align-items: center; gap: 16px; padding: 10px 16px; border-bottom: 1px solid var(--line); background: linear-gradient(180deg, #0b0f1a, var(--bg)); }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; letter-spacing: .02em; white-space: nowrap; }
.brand svg { width: 26px; height: 26px; color: var(--accent); filter: drop-shadow(0 0 6px #a88bff99); }
.now { flex: 1; min-width: 0; }
#songTitle { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#songMeta { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.stage { grid-area: stage; display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--line); }
#viewport { position: relative; flex: 1; min-height: 240px; overflow: hidden; background: radial-gradient(ellipse at 50% 30%, #10142a 0%, var(--bg) 70%); }
#view3d { position: absolute; inset: 0; }
#view3d canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.viewtools { position: absolute; top: 10px; right: 10px; display: flex; gap: 6px; }
#hud { position: absolute; top: 10px; left: 10px; display: flex; flex-direction: column; gap: 6px; pointer-events: none; max-width: calc(100% - 200px); }
.hc { background: #070a12cc; border: 1px solid var(--line2); border-left: 3px solid var(--c); border-radius: 8px; padding: 6px 9px; font: 11px/1.35 var(--mono); backdrop-filter: blur(4px); min-width: 210px; }
.hc .h { display: flex; justify-content: space-between; gap: 8px; color: var(--c); font-weight: 600; }
.hc .notes { color: var(--text); min-height: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hc .nums { color: var(--muted); display: flex; gap: 10px; }
.hc .nums b { color: var(--text); font-weight: 600; }
.hc canvas { display: block; width: 100%; height: 22px; margin-top: 3px; }
.hc.warn .nums .dr b { color: var(--hot); }

#hint { position: absolute; left: 50%; bottom: 14%; transform: translateX(-50%); text-align: center; display: flex; flex-direction: column; align-items: center; gap: 6px; text-shadow: 0 2px 10px #000; }
.bigplay { width: 64px; height: 64px; border-radius: 50%; border: 1px solid #b9a4ff88; background: radial-gradient(circle at 40% 35%, #b49cff, #6a4ddb); color: #fff; font-size: 24px; cursor: pointer; box-shadow: 0 0 30px #8a6dff88, inset 0 1px 0 #fff4; padding-left: 5px; }
.bigplay:hover { transform: scale(1.05); }
#dropOverlay { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; text-align: center; font-size: 20px; font-weight: 600; background: #0a0d1acc; border: 2px dashed var(--accent); border-radius: 12px; margin: 10px; }
body.dragging #dropOverlay { display: flex; }
#busy { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: #04060cb3; backdrop-filter: blur(2px); }
.busybox { background: var(--card); border: 1px solid var(--line2); border-radius: 12px; padding: 18px 20px; width: min(340px, 86%); display: flex; flex-direction: column; gap: 12px; align-items: stretch; }
.bar { height: 6px; background: #1b2236; border-radius: 99px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent2)); transition: width .15s; }
#toast { position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%) translateY(20px); opacity: 0; background: #1a2135; border: 1px solid var(--line2); padding: 8px 14px; border-radius: 8px; transition: .25s; pointer-events: none; max-width: 90%; text-align: center; }
#toast.show { opacity: 1; transform: translateX(-50%); }
#toast.err { border-color: var(--hot); }

.transport { padding: 8px 12px 6px; border-top: 1px solid var(--line); background: var(--bg2); display: flex; flex-direction: column; gap: 6px; }
.transport .row { display: flex; align-items: center; gap: 10px; }
.transport .row.extra { flex-wrap: wrap; gap: 6px 16px; color: var(--muted); font-size: 12px; }
.transport .row.extra label { display: flex; align-items: center; gap: 6px; }
.transport .row.extra input[type=range] { width: 100px; }
#seek { flex: 1; }
.tbtn { width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--line2); background: var(--card); cursor: pointer; font-size: 14px; flex: none; }
.tbtn.play { width: 46px; height: 46px; font-size: 18px; background: linear-gradient(180deg, #9a7dff, #6b4fe0); border-color: #b6a3ff; box-shadow: 0 0 16px #8a6dff66; }
.tbtn:hover { filter: brightness(1.15); }
#roll { display: block; width: 100%; height: 86px; background: #070910; border-top: 1px solid var(--line); cursor: pointer; }

input[type=range] { -webkit-appearance: none; appearance: none; height: 22px; background: transparent; cursor: pointer; min-width: 60px; }
input[type=range]::-webkit-slider-runnable-track { height: 4px; background: #232c43; border-radius: 99px; }
input[type=range]::-moz-range-track { height: 4px; background: #232c43; border-radius: 99px; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 14px; margin-top: -5px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 8px #a88bff99; border: 0; }
input[type=range]::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: var(--accent); border: 0; }

.btn { background: var(--card); border: 1px solid var(--line2); border-radius: 8px; padding: 7px 12px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: #3d4b70; background: #182035; }
.btn.primary { background: linear-gradient(180deg, #8f72ff, #6a4ee0); border-color: #a690ff; color: #fff; }
.btn.primary:hover { filter: brightness(1.1); }
.btn.small { padding: 4px 9px; font-size: 12.5px; }
.btn.wide { width: 100%; }
.btn.rec { border-color: var(--hot); color: #ffd0d9; background: #3a1220; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 4px #ff557733; } }
.btn:disabled { opacity: .45; cursor: default; }
.chip { background: #0b0f1acc; border: 1px solid var(--line2); border-radius: 99px; padding: 4px 10px; font-size: 12px; cursor: pointer; color: var(--muted); }
.chip.on { color: var(--text); border-color: var(--accent); background: #2a1f55cc; }
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--line2); border-radius: 7px; overflow: hidden; }
.stepper button { background: var(--card); border: 0; padding: 3px 8px; cursor: pointer; font-size: 12px; }
.stepper button:hover { background: #1c2540; }
.stepper b { min-width: 34px; text-align: center; color: var(--text); padding: 0 4px; }

.panel { grid-area: panel; display: flex; flex-direction: column; min-height: 0; background: var(--panel); }
.tabs { display: flex; border-bottom: 1px solid var(--line); padding: 0 6px; flex: none; overflow-x: auto; }
.tab { flex: 1; background: none; border: 0; padding: 11px 6px 9px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; font-weight: 500; }
.tab.on { color: var(--text); border-bottom-color: var(--accent); }
.tabbody { padding: 14px; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 12px; }
h3 { margin: 0 0 4px; font-size: 13px; letter-spacing: .04em; text-transform: uppercase; color: #b9bfd3; font-weight: 600; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 12px; display: flex; flex-direction: column; gap: 9px; }
.card p { margin: 0; }
details.card summary { cursor: pointer; font-weight: 600; }
details.card[open] summary { margin-bottom: 4px; }
.field { display: flex; align-items: center; gap: 8px; }
.field.wrap { flex-wrap: wrap; }
.field > span:first-child { min-width: 118px; color: var(--muted); font-size: 12.5px; }
.field input[type=range] { flex: 1; }
.field b.mono { min-width: 52px; text-align: right; font-size: 12px; }
select { background: #0b0f1a; border: 1px solid var(--line2); border-radius: 7px; padding: 5px 8px; }
textarea { width: 100%; min-height: 120px; resize: vertical; background: #080b13; border: 1px solid var(--line2); border-radius: 8px; padding: 8px; font: 12px/1.4 var(--mono); }
.seg { display: inline-flex; border: 1px solid var(--line2); border-radius: 8px; overflow: hidden; }
.seg button { background: #0b0f1a; border: 0; padding: 5px 10px; cursor: pointer; color: var(--muted); font-size: 12.5px; }
.seg button + button { border-left: 1px solid var(--line2); }
.seg button.on { background: #2b2160; color: #fff; }
.check { display: flex; gap: 8px; align-items: center; cursor: pointer; }
.demos { display: grid; gap: 6px; }
.demo { text-align: left; background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; cursor: pointer; display: flex; justify-content: space-between; gap: 8px; }
.demo:hover { border-color: var(--accent); }
.demo .f { font: 10.5px var(--mono); color: var(--accent2); border: 1px solid #2c4a5e; border-radius: 4px; padding: 1px 5px; align-self: center; }

.track { display: grid; grid-template-columns: 10px 1fr auto; gap: 10px; align-items: center; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); }
.track .sw { width: 10px; height: 30px; border-radius: 3px; background: var(--c); }
.track .nm { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.track .meta { font-size: 11.5px; color: var(--muted); }
.track.off { opacity: .5; }
.badge { font: 10px var(--mono); border: 1px solid var(--line2); border-radius: 4px; padding: 0 4px; margin-left: 6px; color: var(--accent2); }

.coilcard { border-left: 3px solid var(--c); }
.coilcard .hd { display: flex; align-items: center; gap: 8px; }
.coilcard .hd b { flex: 1; color: var(--c); }
.coilcard input[type=color] { width: 28px; height: 24px; border: 1px solid var(--line2); border-radius: 6px; background: none; padding: 0; cursor: pointer; }
.presets { display: flex; gap: 6px; flex-wrap: wrap; }

.piano { position: relative; height: 120px; overflow-x: auto; overflow-y: hidden; border-radius: 8px; border: 1px solid var(--line2); background: #000; touch-action: none; user-select: none; -webkit-user-select: none; }
.piano .keys { position: relative; height: 100%; }
.piano .k { position: absolute; top: 0; border: 1px solid #222; border-top: 0; border-radius: 0 0 5px 5px; }
.piano .w { height: 100%; background: linear-gradient(180deg, #d9dbe3, #fff); z-index: 1; }
.piano .b { height: 62%; background: linear-gradient(180deg, #111, #2a2a2e); z-index: 2; border-color: #000; }
.piano .k.on { background: linear-gradient(180deg, #b9a5ff, var(--accent)); box-shadow: 0 0 14px #a88bffaa; }
.piano .lbl { position: absolute; bottom: 4px; width: 100%; text-align: center; font: 9px var(--mono); color: #667; pointer-events: none; }

#recPreview video, #recPreview audio { width: 100%; border-radius: 8px; background: #000; }

@media (max-width: 860px) {
  #app { display: flex; flex-direction: column; height: auto; min-height: 100dvh; }
  .top { padding: 8px 10px; gap: 10px; position: sticky; top: 0; z-index: 5; }
  .brand span { display: none; }
  .stage { border-right: 0; }
  #viewport { height: 50vh; height: 50dvh; flex: none; min-height: 260px; }
  .hc { min-width: 0; padding: 4px 7px; font-size: 10px; }
  .hc canvas { display: none; }
  #hud { max-width: calc(100% - 120px); }
  .viewtools { flex-direction: column; align-items: flex-end; }
  .transport .row.extra input[type=range] { width: 80px; }
  .panel { min-height: 60vh; }
  .tabbody { overflow: visible; }
  .field > span:first-child { min-width: 100px; }
}

/* ---------------------------------------------------------------- song picker */
.sheet { position: fixed; inset: 0; z-index: 50; background: #03040acc; backdrop-filter: blur(6px); display: flex; align-items: center; justify-content: center; padding: 16px; }
.sheetbox { width: min(860px, 100%); max-height: 100%; overflow: auto; background: var(--panel); border: 1px solid var(--line2); border-radius: 16px; padding: 16px 18px 20px; box-shadow: 0 20px 60px #000a; }
.sheethead { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.sheethead h2 { margin: 0; font-size: 20px; }
.sheetx { background: var(--card); border: 1px solid var(--line2); color: var(--text); width: 40px; height: 40px; border-radius: 50%; cursor: pointer; font-size: 16px; }
.sheet h4 { margin: 14px 0 8px; font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.songgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; }
.songcard { text-align: left; border: 1px solid var(--line2); border-radius: 14px; padding: 14px; cursor: pointer; color: var(--text); min-height: 96px; display: flex; flex-direction: column; justify-content: space-between; gap: 8px;
  background: linear-gradient(150deg, color-mix(in srgb, var(--c) 32%, #10131f), #0e1220 70%); }
.songcard:hover, .songcard:focus-visible { border-color: var(--c); transform: translateY(-1px); outline: none; }
.songcard .st { font-weight: 600; font-size: 15px; line-height: 1.25; }
.songcard .ss { font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; gap: 8px; }
.songcard .ic { width: 32px; height: 32px; border-radius: 50%; background: var(--c); color: #0b0d16; display: grid; place-items: center; font-size: 16px; font-weight: 700; }
.songcard.now { box-shadow: 0 0 0 2px var(--c) inset; }

/* ---------------------------------------------------------------- kids mode */
.kidsbar, .kidskeys { display: none; }
body.kids #app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }
body.kids .top, body.kids .transport, body.kids #roll, body.kids .panel, body.kids #hud, body.kids .viewtools, body.kids #hint { display: none !important; }
body.kids .stage { flex: 1; min-height: 0; border: 0; }
body.kids #viewport { flex: 1; height: auto; min-height: 0; }
body.kids .kidsbar { display: flex; position: absolute; top: 0; left: 0; right: 0; align-items: center; gap: 12px; padding: 12px 14px; background: linear-gradient(180deg, #05060bcc, transparent); z-index: 4; }
.kbig { font: 700 20px/1 var(--font); padding: 14px 22px; border-radius: 999px; border: 2px solid #ffffff30; background: #1a1f35e6; color: #fff; cursor: pointer; white-space: nowrap; touch-action: manipulation; }
.kbig:active { transform: scale(.96); }
.kplay { background: linear-gradient(180deg, #8f72ff, #6a4ee0); border-color: #b6a3ff; box-shadow: 0 0 22px #8a6dff88; }
.kplay.on { background: linear-gradient(180deg, #ff6b8a, #d63c62); border-color: #ff9fb3; box-shadow: 0 0 22px #ff557788; }
.ktitle { flex: 1; min-width: 0; font: 600 18px var(--font); color: #fff; text-shadow: 0 2px 8px #000; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kexit { position: relative; overflow: hidden; border: 1px solid #ffffff30; background: #0b0f1acc; color: var(--muted); border-radius: 999px; padding: 9px 14px; font-size: 12px; cursor: pointer; user-select: none; -webkit-user-select: none; touch-action: none; white-space: nowrap; }
.kexit i { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: #a88bff55; }
.kexit.holding i { width: 100%; transition: width 1.5s linear; }
.kexit span { position: relative; }
body.kids .kidskeys { display: block; position: relative; height: 36vh; height: 36dvh; min-height: 170px; max-height: 340px; background: #000; touch-action: none; user-select: none; -webkit-user-select: none; flex: none; }
.kk { position: absolute; top: 0; border-radius: 0 0 14px 14px; display: flex; align-items: flex-end; justify-content: center; padding-bottom: 12px; font: 800 22px var(--font); transition: filter .06s, transform .06s; }
.kk.w { height: 100%; background: linear-gradient(180deg, color-mix(in srgb, var(--kc) 55%, #fff) 0%, var(--kc) 100%); color: #ffffffee; text-shadow: 0 1px 3px #0006; border: 2px solid #000; border-top: 0; z-index: 1; }
.kk.b { height: 58%; background: linear-gradient(180deg, #2b2b34, #0d0d12); border: 2px solid #000; border-top: 0; z-index: 2; }
.kk.on { filter: brightness(1.45) saturate(1.2); transform: translateY(3px); box-shadow: 0 0 30px var(--kc), inset 0 0 20px #fff8; }
.kk.b.on { background: linear-gradient(180deg, var(--kc), #2a1f55); }
.kk.lit:not(.on) { filter: brightness(1.25) saturate(1.15); box-shadow: inset 0 -16px 0 var(--lc), 0 0 26px var(--lc); }
@media (max-width: 600px) {
  .kbig { font-size: 16px; padding: 11px 15px; }
  .ktitle { display: none; }
  body.kids .kidskeys { height: 40dvh; }
  .kk { font-size: 17px; }
}
@media (max-height: 500px) and (orientation: landscape) {
  body.kids .kidskeys { height: 44dvh; min-height: 140px; }
  .kbig { padding: 9px 16px; font-size: 16px; }
}
@media (max-width: 600px) {
  .songgrid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .songcard { padding: 11px; min-height: 88px; }
  .songcard .st { font-size: 14px; }
}
@media (max-width: 600px) {
  .top .lg { display: none; }
  .top { gap: 8px; }
  .top .btn { padding: 7px 10px; }
}
