/* Kylo's Studio: a friendly dark studio. Big buttons, bright track colors.
   Layout: top bar, play bar, then the Tracks view with the note editor under it. On a phone the page stacks and scrolls
   (stage 2 adds the bottom tabs). */
:root {
  --bg: #14111f; --panel: #1e1a30; --panel2: #272240; --line: #3a3460; --ink: #f3f0ff; --dim: #a9a2cc;
  --accent: #ff7ab8; --accent2: #7c5cff; --good: #5eead4; --warn: #ffd43b; --bad: #ff6b6b;
  --hw: 190px; --rh: 28px;
  --pr-black: #181530; --pr-white: #221e3b; --pr-inkey: #2c2650;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(1200px 600px at 20% -10%, #2a1f55 0%, var(--bg) 60%) fixed;
  color: var(--ink); font: 15px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex; flex-direction: column; min-height: 100dvh; height: 100dvh; overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; color: inherit; }

/* ----- buttons ----- */
.btn { background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; padding: 8px 14px; min-height: 40px; cursor: pointer; font-weight: 600; white-space: nowrap; touch-action: manipulation; }
.btn:hover { border-color: var(--accent2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .35; cursor: default; }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent2)); border-color: transparent; color: #fff; }
.btn.icon { width: 44px; padding: 0; font-size: 20px; }
.btn.small { min-height: 32px; padding: 4px 10px; font-size: 13px; border-radius: 9px; }
.btn.icon.small { width: 32px; font-size: 16px; }
.btn.on { background: var(--accent2); border-color: var(--accent2); color: #fff; }
.btn.play.on { background: var(--good); color: #052; border-color: var(--good); }
.btn.rec { color: var(--bad); }
.btn.danger { color: var(--bad); }
.chip { display: inline-block; padding: 3px 10px; border-radius: 99px; background: var(--panel2); color: var(--dim); font-size: 13px; }
.chip.good { color: var(--good); } .chip.warn { color: var(--warn); }
.chip:empty { display: none; }
.check { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; color: var(--dim); white-space: nowrap; }
.small-select, select { background: var(--panel2); border: 1px solid var(--line); border-radius: 9px; padding: 5px 8px; min-height: 32px; }

/* ----- top + play bars ----- */
.topbar { display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: rgba(20, 17, 31, .85); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brand { font-weight: 800; font-size: 19px; letter-spacing: .2px; white-space: nowrap; }
.song-name { flex: 1 1 140px; min-width: 120px; max-width: 260px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; font-size: 17px; font-weight: 700; }
.top-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.top-actions .btn { padding: 6px 10px; }
.undo-redo { display: flex; gap: 6px; margin-left: auto; }
.transport { display: flex; align-items: center; gap: 14px; padding: 8px 12px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.tgroup { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.clock { font: 700 22px/1 ui-monospace, Consolas, monospace; padding: 8px 14px; background: #0c0a16; border: 1px solid var(--line); border-radius: 10px; color: var(--good); min-width: 150px; text-align: center; }
.field { display: inline-flex; align-items: center; gap: 6px; color: var(--dim); font-size: 13px; }
.stepper { display: inline-flex; align-items: center; gap: 4px; }
.stepper input { width: 62px; text-align: center; background: var(--panel2); border: 1px solid var(--line); border-radius: 9px; padding: 5px; min-height: 32px; font-weight: 700; }

/* ----- the workspace ----- */
.workspace { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 8px; padding: 8px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; min-height: 0; }
#tracks { flex: 1 1 40%; min-height: 120px; display: flex; flex-direction: column; }

/* ----- the Tracks view ----- */
.tl-toolbar { display: flex; gap: 6px; padding: 6px 8px; border-bottom: 1px solid var(--line); flex-wrap: wrap; align-items: center; }
.tl-toolbar .spacer { flex: 1; }
.tl-scroll { flex: 1; min-height: 0; overflow: auto; position: relative; overscroll-behavior: contain; }
.tl-inner { display: grid; grid-template-columns: var(--hw) auto; grid-template-rows: var(--rh) auto; width: max-content; min-width: 100%; }
.tl-corner { position: sticky; top: 0; left: 0; z-index: 6; background: var(--panel2); border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); display: flex; align-items: center; padding: 0 6px; }
.add-track { width: 100%; min-height: 24px; padding: 0 6px; font-size: 13px; border-radius: 8px; }
.tl-ruler { position: sticky; top: 0; z-index: 4; height: var(--rh); background: var(--panel2); border-bottom: 1px solid var(--line); touch-action: none; cursor: pointer; overflow: hidden;
  background-image: linear-gradient(90deg, rgba(255,255,255,.22) 1px, transparent 1px); background-size: var(--bar) 100%; }
.tl-ruler .mark { position: absolute; top: 5px; padding-left: 4px; font-size: 12px; color: var(--dim); pointer-events: none; }
.tl-loopbar { position: absolute; top: 14px; height: 14px; border-radius: 7px; background: rgba(255, 212, 59, .22); border: 1px solid rgba(255, 212, 59, .5); cursor: grab; }
.tl-loopbar.on { background: rgba(255, 212, 59, .8); }
.tl-loopbar .lh { position: absolute; top: -2px; width: 14px; height: 18px; cursor: ew-resize; }
.tl-loopbar .lh-l { left: -4px; } .tl-loopbar .lh-r { right: -4px; }
.tl-heads { position: sticky; left: 0; z-index: 3; background: var(--panel); border-right: 1px solid var(--line); }
.tl-head { height: var(--row-h, 88px); padding: 5px 7px; border-bottom: 1px solid var(--line); border-left: 6px solid var(--c, #888); display: flex; flex-direction: column; justify-content: space-between; gap: 3px; background: var(--panel); }
.tl-head.selected { background: var(--panel2); }
.tl-head.muted { opacity: .6; }
.hrow { display: flex; gap: 4px; align-items: center; }
.hname { flex: 1; min-width: 0; background: transparent; border: 1px solid transparent; border-radius: 7px; padding: 2px 5px; font-weight: 700; font-size: 14px; }
.hname:focus, .hname:hover { border-color: var(--line); background: var(--bg); }
.hpick { width: 100%; min-height: 26px; padding: 2px 6px; font-size: 13px; }
.icon-btn { width: 28px; height: 26px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel2); cursor: pointer; font-weight: 800; font-size: 12px; padding: 0; flex: none; }
.icon-btn.m.on { background: var(--warn); color: #331; } .icon-btn.s.on { background: var(--good); color: #052; }
.icon-btn.del { border-color: transparent; background: transparent; color: var(--dim); }
.hvol { flex: 1; min-width: 0; accent-color: var(--accent); height: 20px; }
.tl-rows { position: relative; z-index: 1; touch-action: pan-x pan-y; }   /* z-index: the playhead slides under the sticky track names */
.tl-row { position: absolute; left: 0; right: 0; border-bottom: 1px solid var(--line);
  background-image: linear-gradient(90deg, rgba(255,255,255,.2) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.07) 1px, transparent 1px);
  background-size: var(--bar) 100%, var(--ppb) 100%; }
.tl-row:nth-child(even) { background-color: rgba(255, 255, 255, .02); }
.region { position: absolute; top: 6px; bottom: 6px; border-radius: 9px; background: color-mix(in srgb, var(--c) 62%, #17132b); border: 2px solid var(--c); overflow: hidden; touch-action: none; cursor: grab; user-select: none; }
.region.selected { outline: 3px solid #fff; z-index: 2; box-shadow: 0 0 0 5px color-mix(in srgb, var(--c) 40%, transparent); }
.region .thumb { position: absolute; left: 0; top: 18px; width: 100%; height: calc(100% - 22px); pointer-events: none; }
.region .rname { position: absolute; left: 7px; top: 2px; font-size: 11px; font-weight: 700; color: rgba(255,255,255,.9); pointer-events: none; white-space: nowrap; }
.region .h { position: absolute; top: 0; bottom: 0; width: 14px; cursor: ew-resize; }
.region .h-l { left: 0; } .region .h-r { right: 0; }
.region.selected .h { background: rgba(255,255,255,.18); }
.tl-playhead { position: absolute; left: -1px; top: 0; bottom: 0; width: 2px; background: var(--accent); z-index: 5; pointer-events: none; box-shadow: 0 0 8px var(--accent); will-change: transform; }

/* ----- the note editor ----- */
.pr-bar { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.pr-title { font-weight: 800; margin-right: 6px; max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pr-bar .btn.small { padding: 3px 8px; }
.pr-body { flex: 1; min-height: 0; display: flex; }
.pr-keys { flex: none; background: #0c0a16; }
.pr-scroll { flex: 1; min-width: 0; overflow: auto; position: relative; overscroll-behavior: contain; }
.pr-spacer { position: absolute; left: 0; top: 0; pointer-events: none; }
.pr-cv { position: sticky; left: 0; top: 0; display: block; touch-action: none; }
.pr-playhead { position: absolute; left: -1px; top: 0; width: 2px; background: var(--accent); pointer-events: none; z-index: 2; will-change: transform; }
.pr-velwrap { position: relative; border-top: 1px solid var(--line); flex: none; background: #0f0c1d; }
.pr-vel { display: block; touch-action: none; cursor: ns-resize; }
.pr-vellabel { position: absolute; left: 6px; top: 4px; font-size: 11px; color: var(--dim); width: 60px; pointer-events: none; }
.pr-empty { margin: auto; padding: 30px; color: var(--dim); text-align: center; font-size: 16px; }

/* ----- menus, dialogs, toast ----- */
.menu { position: fixed; z-index: 50; background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; padding: 6px; width: 220px; max-height: 70vh; overflow: auto; box-shadow: 0 10px 30px rgba(0,0,0,.5); }
.menu-h { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--dim); padding: 8px 8px 2px; }
.menu-i { display: block; width: 100%; text-align: left; background: transparent; border: 0; border-radius: 8px; padding: 9px 10px; cursor: pointer; font-size: 15px; }
.menu-i:hover { background: var(--accent2); }
.dlg { background: var(--panel); color: var(--ink); border: 1px solid var(--line); border-radius: 18px; padding: 20px; width: min(420px, 92vw); }
.dlg.wide { width: min(560px, 94vw); }
.dlg::backdrop { background: rgba(5, 3, 15, .7); }
.dlg h2 { margin: 0 0 8px; }
.dlg input[type=password] { width: 100%; font-size: 26px; letter-spacing: .3em; text-align: center; background: var(--bg); border: 2px solid var(--line); border-radius: 12px; padding: 10px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.error { color: var(--bad); min-height: 1.3em; margin: 6px 0 0; }
.songs-list { max-height: 55vh; overflow: auto; display: flex; flex-direction: column; gap: 8px; }
.song-row { display: flex; align-items: center; gap: 8px; background: var(--panel2); padding: 8px 10px; border-radius: 12px; }
.song-row > div { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.song-row small { color: var(--dim); }
.toast { position: fixed; left: 50%; bottom: 22px; transform: translate(-50%, 30px); background: var(--accent2); color: #fff; padding: 10px 18px; border-radius: 99px; font-weight: 700; opacity: 0; pointer-events: none; transition: .25s; z-index: 60; max-width: 92vw; text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ----- bigger touch targets on touch screens ----- */
@media (pointer: coarse) {
  .btn { min-height: 44px; } .btn.small { min-height: 40px; } .btn.icon.small { width: 40px; }
  .icon-btn { width: 36px; height: 34px; } .hpick { min-height: 32px; }
  .region .h { width: 22px; }
}


[hidden] { display: none !important; }

/* ===== stage 2: tabs, dock and the new panels ===== */
.workspace { gap: 4px; }
.dock { flex: 1 1 60%; min-height: 230px; display: flex; flex-direction: column; min-width: 0; }
.dock > .panel { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.ed { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.tabs { display: flex; gap: 6px; padding: 0 2px; flex: none; }
.tab { display: inline-flex; align-items: center; gap: 6px; background: var(--panel); border: 1px solid var(--line); border-bottom: 0; border-radius: 12px 12px 0 0; padding: 6px 16px; min-height: 36px; cursor: pointer; font-weight: 700; color: var(--dim); touch-action: manipulation; }
.tab.on { background: var(--panel2); color: var(--ink); border-color: var(--accent2); }
.tab[data-tab="tracks"] { display: none; }
.btn.rec.on { background: var(--bad); color: #fff; border-color: var(--bad); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .65; } }
.countin { position: fixed; inset: 0; display: grid; place-items: center; font: 800 min(40vw, 260px)/1 system-ui; color: #fff; text-shadow: 0 0 40px var(--accent), 0 6px 0 rgba(0,0,0,.4); background: rgba(10, 6, 25, .45); z-index: 40; pointer-events: none; }
.drop-hint { position: fixed; inset: 10px; display: grid; place-items: center; border: 4px dashed var(--accent); border-radius: 24px; background: rgba(20, 17, 31, .85); font-size: 28px; font-weight: 800; z-index: 45; pointer-events: none; text-align: center; }
.lib { padding: 20px; overflow: auto; }
.lib h2 { margin-top: 0; }
.dim { color: var(--dim); }
.btn.big { min-height: 48px; font-size: 17px; padding: 8px 20px; }
.ask-fields { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
.ask-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.ask-row input[type=number] { width: 90px; text-align: center; background: var(--bg); border: 2px solid var(--line); border-radius: 10px; padding: 8px; font-size: 18px; font-weight: 700; }
.ask-row input[type=checkbox] { width: 22px; height: 22px; flex: none; accent-color: var(--accent2); }
.ask-row:has(input[type=checkbox]) { justify-content: flex-start; }
.dlg p { margin: 6px 0; }

/* drum machine */
.dr-bar { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.dr-body { flex: 1; min-height: 0; display: flex; overflow: auto; padding: 8px; gap: 6px; }
.dr-labels { display: grid; grid-template-rows: repeat(9, minmax(26px, 1fr)); gap: 3px; width: 84px; flex: none; }
.dr-label { display: flex; align-items: center; font-size: 12px; font-weight: 700; color: var(--dim); padding-left: 4px; }
.dr-gridwrap { position: relative; flex: 1; min-width: 360px; }
.dr-grid { display: grid; grid-template-rows: repeat(9, minmax(26px, 1fr)); height: 100%; gap: 3px; }
.dr-row { display: grid; grid-template-columns: repeat(var(--steps), 1fr); gap: 3px; }
.dr-step { background: var(--pr-white); border-radius: 6px; border: 1px solid rgba(255,255,255,.08); cursor: pointer; touch-action: manipulation; min-width: 14px; }
.dr-step.beat { background: var(--pr-inkey); }
.dr-step.bar { border-left: 2px solid rgba(255,255,255,.35); }
.dr-step.on { background: var(--c); border-color: #fff; opacity: .95; }
.dr-step.soft { opacity: .5; }
.dr-step.loud { box-shadow: 0 0 0 2px #fff inset; }
.dr-playhead { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--accent); pointer-events: none; box-shadow: 0 0 8px var(--accent); }

/* play panel */
.keys-stage { flex: 1; min-height: 120px; padding: 10px; display: flex; }
.keys-hint { padding: 6px 12px 10px; color: var(--dim); font-size: 13px; }
.piano { position: relative; flex: 1; min-height: 140px; max-height: 340px; touch-action: none; user-select: none; }
.pk { position: absolute; top: 0; touch-action: none; }
.pk.white { height: 100%; background: linear-gradient(#fff, #e9e5ff); border: 1px solid #8c84b8; border-radius: 0 0 10px 10px; color: #443c70; display: flex; align-items: flex-end; justify-content: center; font-size: 12px; padding-bottom: 6px; }
.pk.black { height: 62%; background: linear-gradient(#2b2650, #0b0918); border-radius: 0 0 8px 8px; z-index: 2; border: 1px solid #000; }
.pk.down { background: var(--accent); color: #fff; }
.pk.black.down { background: var(--accent2); }
.pads { flex: 1; display: grid; grid-template-columns: repeat(4, 1fr); grid-template-rows: repeat(4, minmax(48px, 1fr)); gap: 8px; touch-action: none; max-width: 640px; margin: 0 auto; }
.pad { display: grid; place-items: center; background: var(--panel2); border: 2px solid var(--line); border-radius: 14px; font-weight: 800; font-size: 14px; text-align: center; user-select: none; touch-action: none; }
.pad.down { background: var(--accent); border-color: #fff; transform: scale(.97); }

/* sound clip editor */
.ac-wave { display: block; width: 100%; height: 110px; background: #0c0a16; border-bottom: 1px solid var(--line); flex: none; }
.ac-sliders { padding: 10px 14px; display: grid; gap: 4px 24px; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); overflow: auto; }
.ac-row { display: grid; grid-template-columns: 76px 1fr 56px; align-items: center; gap: 10px; min-height: 44px; }
.ac-name { font-weight: 700; } .ac-val { color: var(--dim); text-align: right; font-variant-numeric: tabular-nums; }
.ac-row input[type=range] { width: 100%; accent-color: var(--accent); height: 32px; }

/* mixer: one row per track (a flat slider each for volume, pan and the four effects) */
.mixer { gap: 6px; padding: 8px; overflow: hidden; }
.mx-strips { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 6px; overflow: auto; padding-right: 2px; }
.mx-strip { flex: none; display: grid; grid-template-columns: 120px 76px 1.5fr 1fr repeat(4, 1fr); align-items: center; gap: 4px 12px; background: var(--panel2); border-radius: 12px; padding: 6px 10px; border-left: 6px solid var(--c, var(--accent2)); }
.mx-strip.master { border-left-color: var(--accent); grid-template-columns: 120px 76px 1.5fr 2fr; }
.mx-strip.muted { opacity: .65; }
.mx-name { font-weight: 800; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mx-ms { display: flex; gap: 6px; }
.mx-ms .icon-btn { width: 34px; height: 32px; font-size: 14px; }
.mx-cell { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.mx-lab { font-size: 11px; color: var(--dim); }
.fader { position: relative; background: #0c0a16; border: 1px solid var(--line); border-radius: 14px; touch-action: none; cursor: pointer; outline-offset: 2px; height: 28px; }
.fader .fill { position: absolute; left: 0; top: 0; bottom: 0; background: linear-gradient(135deg, var(--accent), var(--accent2)); border-radius: 13px; opacity: .8; }
.fader .thumb { position: absolute; top: -1px; width: 28px; height: 28px; border-radius: 50%; background: #fff; box-shadow: 0 2px 6px rgba(0,0,0,.5); }
.meter { height: 28px; background: #0c0a16; border: 1px solid var(--line); border-radius: 14px; position: relative; overflow: hidden; }
.meter .fill { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: linear-gradient(90deg, var(--good), var(--warn)); }
.meter .fill.hot { background: linear-gradient(90deg, var(--warn), var(--bad)); }

/* ===== phone: one panel at a time, tab bar at the bottom ===== */
@media (max-width: 760px) {
  :root { --hw: 128px; }
  body { overflow: hidden; }
  .logo { font-size: 20px; } .brand-text { display: none; }
  .topbar { gap: 6px 8px; padding: 6px 8px; flex-wrap: wrap; }
  .brand { order: 1; }
  .song-name { order: 2; flex: 1 1 100px; min-width: 0; max-width: none; }
  .undo-redo { order: 3; margin-left: 0; }
  .top-actions { order: 4; flex-basis: 100%; gap: 6px; justify-content: space-between; }
  .top-actions .btn { flex: 1; padding: 4px 6px; min-height: 44px; font-size: 20px; }
  .top-actions .lbl { display: none; }
  .transport { gap: 6px 10px; padding: 6px 8px; }
  .tgroup { gap: 6px; }
  .btn.icon { width: 44px; min-height: 44px; font-size: 19px; }
  .clock { min-width: 0; font-size: 17px; padding: 6px 10px; }
  .field .btn.icon.small { width: 40px; min-height: 40px; }
  .workspace { padding: 6px 6px 0; gap: 0; padding-bottom: calc(62px + env(safe-area-inset-bottom, 0px)); }
  #tracks { flex: 1 1 0; }
  .dock { flex: 1 1 0; min-height: 0; }
  .tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: rgba(20, 17, 31, .97); border-top: 1px solid var(--line); padding: 4px 4px calc(4px + env(safe-area-inset-bottom, 0px)); gap: 2px; }
  .tab, .tab[data-tab="tracks"] { display: flex; flex: 1; flex-direction: column; align-items: center; justify-content: center; gap: 0; border: 0; border-radius: 12px; padding: 4px 0; min-height: 52px; font-size: 12px; background: transparent; }
  .tab .ti { font-size: 22px; line-height: 1.1; }
  .tab.on { background: var(--panel2); color: var(--accent); }
  .pr-bar .btn.small, .dr-bar .btn.small { min-height: 44px; }
  .hvol { display: none; }   /* the Mix tab has the volume sliders on a phone */
  .mx-strip, .mx-strip.master { grid-template-columns: 1fr 1fr; }
  .mx-name { grid-column: 1; } .mx-ms { grid-column: 2; justify-self: end; }
  .mx-ms .icon-btn { width: 44px; height: 40px; }
  .fader { height: 36px; border-radius: 18px; } .fader .thumb { width: 36px; height: 36px; }
  .dr-labels { width: 66px; }
  .dr-gridwrap { min-width: 0; }
  .dr-grid { min-width: calc(var(--steps) * 36px); }
  .dr-labels, .dr-grid { grid-template-rows: repeat(9, 40px); }
}

/* ===== stage 3: divider, library, welcome ===== */
.divider { flex: none; height: 14px; margin: -2px 0; cursor: row-resize; touch-action: none; display: grid; place-items: center; z-index: 2; }
.divider span { width: 70px; height: 5px; border-radius: 3px; background: var(--line); }
.divider:hover span, .divider.drag span { background: var(--accent); }
@media (pointer: coarse) { .divider { height: 22px; } }
@media (min-width: 761px) { #tracks.sized { flex: 0 0 var(--split); } }

.lib { overflow: auto; padding: 0; }
.lib-head { position: sticky; top: 0; z-index: 3; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 10px 14px; background: var(--panel); border-bottom: 1px solid var(--line); }
.lib-head h2 { margin: 0; font-size: 20px; }
.lib-search { flex: 1 1 180px; min-width: 120px; background: var(--bg); border: 2px solid var(--line); border-radius: 12px; padding: 8px 12px; font-size: 16px; min-height: 44px; }
.lib-body { padding: 4px 14px 24px; }
.lib-sec h3 { margin: 18px 0 4px; font-size: 18px; }
.lib-sec p.dim { margin: 0 0 8px; font-size: 13px; }
.lib-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; margin: 8px 0; }
.lib-card { display: flex; flex-direction: column; background: var(--panel2); border: 2px solid var(--line); border-top: 6px solid var(--c, var(--accent2)); border-radius: 14px; overflow: hidden; }
.lib-card-main { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: left; background: transparent; border: 0; padding: 12px; cursor: pointer; min-height: 88px; touch-action: manipulation; }
.lib-card-main:hover { background: rgba(255,255,255,.05); }
.lib-emoji { font-size: 30px; line-height: 1.1; }
.lib-name { font-weight: 800; font-size: 16px; }
.lib-sub { color: var(--accent); font-size: 12px; font-weight: 700; }
.lib-desc { padding: 0 12px 10px; font-size: 12px; color: var(--dim); display: flex; flex-direction: column; gap: 4px; }
.lib-del { margin: 0 12px 10px; align-self: flex-start; }
.lib-group { margin: 8px 0; background: rgba(255,255,255,.03); border-radius: 12px; padding: 0 10px; }
.lib-group summary { cursor: pointer; font-weight: 800; padding: 12px 4px; min-height: 44px; }
.lib-msg { background: var(--panel2); border-radius: 12px; padding: 12px 14px; margin: 8px 0; }
.lib-msg p { margin: 0 0 8px; }

.welcome { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); width: min(440px, 92vw); background: var(--panel2); border: 2px solid var(--accent); border-radius: 18px; padding: 16px 18px; z-index: 50; box-shadow: 0 20px 60px rgba(0,0,0,.6); }
.welcome p { margin: 8px 0; }
.welcome .btn { margin-top: 4px; }
.credits { padding-left: 18px; } .credits li { margin: 6px 0; }
#about-dialog h3 { margin: 12px 0 4px; }

@media (max-width: 760px) {
  .divider { display: none; }
  .lib-grid { grid-template-columns: 1fr; }
  .lib-head { padding: 8px 10px; }
  .lib-body { padding: 4px 10px 24px; }
  .welcome { bottom: 74px; }
}

/* YouTube -> 8-bit window */
.yt-url { width: 100%; margin: 8px 0; background: var(--bg); border: 2px solid var(--line); border-radius: 12px; padding: 12px; font-size: 16px; min-height: 48px; }
.yt-lib { margin: 4px 0; }
.yt-spin { font-size: 56px; text-align: center; animation: pulse 1.2s infinite; }
.yt-msg { text-align: center; font-size: 19px; font-weight: 800; min-height: 1.6em; }
.yt-bar { height: 10px; border-radius: 5px; background: var(--bg); overflow: hidden; margin: 10px 0; }
.yt-bar span { display: block; height: 100%; width: 40%; border-radius: 5px; background: linear-gradient(90deg, var(--accent), var(--accent2)); animation: slide 1.6s ease-in-out infinite; }
@keyframes slide { 0% { margin-left: -40%; } 100% { margin-left: 100%; } }
