:root {
  --bg: #0e0f14; --panel: #15161d; --panel2: #1c1e27; --text: #e8e9f0; --dim: #8b8fa3; --line: #2a2c38;
  --accent: #ff4d6d; --accent2: #7c5cff; --radius: 12px; --fs: 14px; --panel-w: 400px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --stage-bg: #07070b;
  color-scheme: dark;
}
body.light { color-scheme: light; }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text); font: var(--fs)/1.45 var(--font);
  overflow: hidden; -webkit-font-smoothing: antialiased;
}
body.caps { text-transform: uppercase; letter-spacing: .04em; }
body.reduce-motion * { transition: none !important; animation: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.ico { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.ico.big { width: 44px; height: 44px; stroke-width: 1.4; }

#app { display: flex; flex-direction: column; height: 100%; }

/* ---------------- top bar */
#topbar {
  display: flex; align-items: center; gap: 12px; padding: 6px 10px 6px 14px;
  background: var(--panel); border-bottom: 1px solid var(--line); min-height: 52px; flex: none;
}
body.no-toolbar #topbar { display: none; }
.brand { display: flex; align-items: baseline; gap: 12px; min-width: 0; flex: 0 1 auto; }
.logo { font-weight: 800; font-size: 1.25em; letter-spacing: -.02em; }
.logo b, .hero-logo b { color: var(--accent); }
.rom-name { color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 28vw; }
.status { color: var(--accent); font-weight: 600; white-space: nowrap; }
#toolbar { display: flex; align-items: center; gap: 2px; flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none; }
#toolbar::-webkit-scrollbar { display: none; }
.tool {
  display: grid; place-items: center; width: 38px; height: 38px; border-radius: calc(var(--radius) * .7);
  border: 0; background: transparent; color: var(--text); cursor: pointer; flex: none;
}
.tool:hover { background: var(--panel2); }
.tool.on { background: color-mix(in srgb, var(--accent) 22%, transparent); color: var(--accent); }
#tb-rec.on { color: #ff3b3b; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .4; } }
.tb-sep { width: 1px; height: 22px; background: var(--line); margin: 0 6px; flex: none; }
.grow { flex: 1; }
.slot-sel { background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 6px; flex: none; }

/* ---------------- main area */
#main { flex: 1; display: flex; min-height: 0; position: relative; }
body[data-side="left"] #main { flex-direction: row-reverse; }
#stage { flex: 1; position: relative; min-width: 0; overflow: hidden; background: var(--stage-bg); }
#stage[data-bg="gradient"] { background: radial-gradient(ellipse at 30% 20%, color-mix(in srgb, var(--accent) 30%, var(--stage-bg)), var(--stage-bg) 60%), radial-gradient(ellipse at 80% 90%, color-mix(in srgb, var(--accent2) 35%, var(--stage-bg)), var(--stage-bg) 55%); }
#screen { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#glow { position: absolute; inset: -10%; width: 120%; height: 120%; pointer-events: none; transition: opacity .4s; }
#stage:fullscreen { background: #000; }
#fps { position: absolute; top: 8px; left: 10px; font: 600 12px ui-monospace, monospace; background: rgba(0,0,0,.55); color: #9f9; padding: 3px 7px; border-radius: 6px; pointer-events: none; }

/* ---------------- landing */
#landing { position: absolute; inset: 0; display: grid; place-items: center; overflow: auto; padding: 24px 16px; background:
  radial-gradient(ellipse at 20% 10%, color-mix(in srgb, var(--accent) 18%, transparent), transparent 60%),
  radial-gradient(ellipse at 90% 100%, color-mix(in srgb, var(--accent2) 20%, transparent), transparent 55%), var(--bg); }
.landing-card { width: min(640px, 100%); }
.hero { text-align: center; margin-bottom: 22px; }
.hero-logo { font-size: clamp(56px, 12vw, 96px); font-weight: 900; letter-spacing: -.05em; line-height: 1; }
.tagline { color: var(--dim); font-size: 1.1em; max-width: 34em; margin: 10px auto 0; }
.dropzone { border: 2px dashed var(--line); border-radius: calc(var(--radius) * 1.4); padding: 26px 16px; text-align: center; background: color-mix(in srgb, var(--panel) 70%, transparent); }
.dropzone p { margin: 8px 0 14px; }
.landing-card h3 { margin: 26px 0 10px; font-size: .85em; text-transform: uppercase; letter-spacing: .08em; color: var(--dim); }
#recent { display: grid; gap: 6px; }
.recent-item { display: flex; gap: 6px; }
.recent-play { flex: 1; display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 14px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--panel); cursor: pointer; text-align: left; }
.recent-play:hover { border-color: var(--accent); }
.recent-play small { color: var(--dim); }
.fine { text-align: center; margin-top: 18px; }

#dropveil { position: absolute; inset: 0; display: grid; place-items: center; background: color-mix(in srgb, var(--accent) 25%, rgba(0,0,0,.6)); font-size: 2em; font-weight: 800; z-index: 20; pointer-events: none; }
#dropveil div { border: 3px dashed #fff; padding: 30px 50px; border-radius: 24px; color: #fff; }

/* ---------------- panel */
#panel {
  width: var(--panel-w); flex: none; display: flex; flex-direction: column; min-height: 0;
  background: var(--panel); border-left: 1px solid var(--line); transition: margin .25s ease, transform .25s ease;
}
body[data-side="left"] #panel { border-left: 0; border-right: 1px solid var(--line); }
body:not(.panel-open) #panel { margin-right: calc(-1 * var(--panel-w)); }
body[data-side="left"]:not(.panel-open) #panel { margin-right: 0; margin-left: calc(-1 * var(--panel-w)); }
.panel-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px 8px; }
.panel-head h2 { margin: 0; font-size: 1.15em; flex: 1; }
.badge { font-size: .75em; padding: 2px 8px; border-radius: 99px; background: var(--panel2); color: var(--dim); border: 1px solid var(--line); }
.icon-btn { border: 0; background: transparent; color: var(--dim); cursor: pointer; width: 32px; height: 32px; border-radius: 8px; flex: none; }
.icon-btn:hover { background: var(--panel2); color: var(--text); }
#panel-tabs { display: grid; grid-template-columns: repeat(auto-fill, minmax(70px, 1fr)); gap: 4px; padding: 4px 10px 10px; border-bottom: 1px solid var(--line); }
.tab { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 7px 2px 6px; border-radius: calc(var(--radius) * .7); border: 1px solid transparent; background: transparent; color: var(--dim); cursor: pointer; font-size: .74em; }
.tab:hover { background: var(--panel2); color: var(--text); }
.tab.on { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent); border-color: color-mix(in srgb, var(--accent) 35%, transparent); }
.tab span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
#panel-body { flex: 1; overflow-y: auto; padding: 10px 12px 40px; scrollbar-width: thin; }

/* sections */
.sec { background: var(--panel2); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 10px; overflow: hidden; }
.sec-head { display: flex; align-items: center; gap: 8px; width: 100%; padding: 10px 12px; border: 0; background: transparent; cursor: pointer; font-weight: 650; text-align: left; }
.sec-head > span:first-child { flex: 1; }
.chev { color: var(--dim); transition: transform .2s; }
.sec.collapsed .chev { transform: rotate(-90deg); }
.sec.collapsed .sec-body { display: none; }
.sec-body { padding: 2px 12px 12px; display: grid; gap: 4px; }
.note { color: var(--dim); font-size: .88em; margin: 2px 0 6px; }
.sub { color: var(--dim); font-size: .85em; margin-top: 8px; }

/* rows */
.row { display: grid; grid-template-columns: minmax(0, 42%) 1fr; align-items: center; gap: 10px; min-height: 32px; }
.row-label { color: var(--text); font-size: .93em; }
.row-label .hint { display: none; }
.ctl { display: flex; align-items: center; justify-content: flex-end; gap: 8px; min-width: 0; }
.ctl.range { justify-content: stretch; }
.ctl select { width: 100%; }
.val { min-width: 54px; text-align: right; font-variant-numeric: tabular-nums; color: var(--dim); font-size: .85em; }
input[type=range] { flex: 1; min-width: 0; accent-color: var(--accent); height: 22px; cursor: pointer; }
select, input[type=text], textarea {
  background: var(--panel); border: 1px solid var(--line); border-radius: calc(var(--radius) * .6); padding: 6px 8px; min-width: 0;
}
select:focus, input:focus-visible, textarea:focus, button:focus-visible { outline: 2px solid color-mix(in srgb, var(--accent) 70%, transparent); outline-offset: 1px; }
input[type=color] { width: 44px; height: 28px; border: 1px solid var(--line); border-radius: 8px; padding: 2px; background: var(--panel); cursor: pointer; }
.switch { appearance: none; width: 38px; height: 22px; border-radius: 99px; background: var(--line); position: relative; cursor: pointer; flex: none; transition: background .15s; margin: 0; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(16px); }

.btn { padding: 7px 12px; border-radius: calc(var(--radius) * .6); border: 1px solid var(--line); background: var(--panel); cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.1); }
.btn.danger:hover { border-color: #ff4040; color: #ff6060; }
.btn.small { padding: 4px 9px; font-size: .85em; }
.btn.icon { padding: 3px 8px; }
.btn.chip { padding: 3px 9px; font-size: .82em; border-radius: 99px; }
.btnrow { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.btnrow.center { justify-content: center; }
.chips { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; }
.chip.dot { width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--line); cursor: pointer; padding: 0; }
.preset-bar select { width: 100%; padding: 9px 10px; margin-bottom: 8px; font-weight: 600; }

/* palette */
.palgrid { display: grid; grid-template-columns: repeat(16, 1fr); gap: 2px; }
.swatch { aspect-ratio: 1; border: 0; border-radius: 3px; cursor: pointer; padding: 0; min-width: 0; box-shadow: inset 0 0 0 1px rgba(255,255,255,.06); }
.swatch:hover { transform: scale(1.25); position: relative; z-index: 2; box-shadow: 0 0 0 2px var(--text); }
.swatch.sel { box-shadow: 0 0 0 2px var(--accent); position: relative; z-index: 1; }
.palram { display: grid; grid-template-columns: repeat(16, 1fr); gap: 2px; margin-top: 4px; }
.swatch.small { aspect-ratio: 1.4; }
.pal-info { font-size: .85em; color: var(--dim); margin-top: 6px; font-variant-numeric: tabular-nums; }
.ghost-picker { position: fixed; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

/* waves & scopes */
.waveedit { margin: 4px 0; }
.wavecv { width: 100%; height: 100px; background: var(--panel); border: 1px solid var(--line); border-radius: calc(var(--radius) * .6); touch-action: none; cursor: crosshair; display: block; }
.scope { width: 100%; height: 46px; background: var(--panel); border: 1px solid var(--line); border-radius: calc(var(--radius) * .6); display: block; }
.spectrum { width: 100%; height: 64px; display: block; background: var(--panel2); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 10px; }
.strip { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.strip .row { grid-template-columns: auto auto; justify-content: start; }

/* shader stack */
.add-effect { width: 100%; margin: 8px 0; padding: 9px; font-weight: 600; border-style: dashed; }
.stack { display: grid; gap: 6px; }
.pass { border: 1px solid var(--line); border-radius: calc(var(--radius) * .8); background: var(--panel); }
.pass.off { opacity: .55; }
.pass-head { display: flex; align-items: center; gap: 8px; padding: 6px 6px 6px 10px; }
.pass-name { flex: 1; min-width: 0; text-align: left; background: none; border: 0; cursor: pointer; display: flex; flex-direction: column; padding: 2px 0; }
.pass-name small { color: var(--dim); font-size: .8em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pass-tools { display: flex; gap: 2px; }
.pass-tools .btn { border: 0; background: transparent; color: var(--dim); }
.pass-tools .btn:hover { color: var(--text); background: var(--panel2); }
.pass-body { display: none; padding: 4px 10px 10px; gap: 4px; }
.pass.open .pass-body { display: grid; }
.code { width: 100%; font: 12px/1.45 ui-monospace, "Cascadia Code", Consolas, monospace; resize: vertical; tab-size: 2; white-space: pre; }
.errors pre.err { background: color-mix(in srgb, #ff3030 15%, var(--panel)); color: #ff8080; border-radius: 8px; padding: 8px; white-space: pre-wrap; font-size: 11px; margin: 4px 0; }

/* bindings */
.bindtable { display: grid; gap: 3px; }
.bt-head, .bt-row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; align-items: center; }
.bt-row.two { grid-template-columns: 1.4fr 1fr; }
.bt-head { color: var(--dim); font-size: .8em; text-transform: uppercase; letter-spacing: .06em; }
.bind { padding: 5px 6px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); cursor: pointer; font: 600 .85em ui-monospace, monospace; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bind:hover { border-color: var(--accent); }
.bind.listening { border-color: var(--accent); color: var(--accent); animation: pulse .8s infinite; }

/* saves, cheats, profiles */
.slots { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.slot { border: 1px solid var(--line); border-radius: calc(var(--radius) * .8); background: var(--panel); overflow: hidden; display: flex; flex-direction: column; }
.slot.cur { border-color: var(--accent); }
.slot img, .slot .empty { width: 100%; aspect-ratio: 8 / 7; object-fit: cover; display: block; background: #000; }
.slot .empty { display: grid; place-items: center; color: var(--dim); font-size: .85em; background: var(--panel2); }
.slot-meta { padding: 6px 8px 0; display: flex; flex-direction: column; }
.slot-meta small { color: var(--dim); font-size: .75em; }
.slot-btns { display: flex; gap: 4px; padding: 6px 8px 8px; }
.cheat-add { display: grid; grid-template-columns: 1.4fr 1fr auto; gap: 6px; }
.cheats { display: grid; gap: 4px; margin-top: 8px; }
.cheat { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
.cheat-code { font: 600 .9em ui-monospace, monospace; }
.cheat-label { flex: 1; color: var(--dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.profiles { display: grid; gap: 5px; }
.profile { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); }
.profile.cur { border-color: var(--accent); }
.profile small { color: var(--accent); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; font-size: .9em; }
.kv span { color: var(--dim); }
.kv b { font-weight: 600; overflow-wrap: anywhere; }

/* toasts */
#toasts { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); display: grid; gap: 6px; z-index: 50; pointer-events: none; justify-items: center; }
.toast { background: color-mix(in srgb, var(--panel) 92%, transparent); border: 1px solid var(--line); padding: 8px 14px; border-radius: 99px; box-shadow: 0 8px 30px rgba(0,0,0,.35); backdrop-filter: blur(8px); animation: tin .2s ease; transition: opacity .4s, transform .4s; }
.toast.err { border-color: #ff4a4a; color: #ff9090; }
.toast.out { opacity: 0; transform: translateY(8px); }
@keyframes tin { from { opacity: 0; transform: translateY(8px); } }

/* touch pad */
#touch { position: absolute; inset: auto 0 0 0; height: calc(190px * var(--tsize, 1)); display: flex; justify-content: space-between; align-items: center; padding: 0 calc(16px + env(safe-area-inset-left)) calc(12px + env(safe-area-inset-bottom)); touch-action: none; user-select: none; -webkit-user-select: none; z-index: 5; }
.dpad { display: grid; grid-template-columns: repeat(3, calc(48px * var(--tsize, 1))); grid-template-rows: repeat(3, calc(48px * var(--tsize, 1))); }
.d { background: rgba(255,255,255,.12); }
.d.u, .d.dn, .d.l, .d.r, .d.c { background: rgba(255,255,255,.28); }
.d.ul, .d.ur, .d.dl, .d.dr { background: transparent; }
.d.u { border-radius: 10px 10px 0 0; } .d.dn { border-radius: 0 0 10px 10px; } .d.l { border-radius: 10px 0 0 10px; } .d.r { border-radius: 0 10px 10px 0; }
.d.on, .round.on, .pill.on { background: var(--accent) !important; }
.mid { display: flex; gap: 12px; align-self: flex-end; margin-bottom: 8px; }
.pill { padding: 6px 12px; border-radius: 99px; background: rgba(255,255,255,.25); font: 700 calc(11px * var(--tsize, 1)) system-ui; color: #fff; }
.ab { display: flex; gap: calc(14px * var(--tsize, 1)); align-items: center; transform: rotate(-18deg); }
.round { width: calc(64px * var(--tsize, 1)); height: calc(64px * var(--tsize, 1)); border-radius: 50%; background: rgba(255,255,255,.28); display: grid; place-items: center; font: 800 calc(20px * var(--tsize, 1)) system-ui; color: #fff; }
.round:last-child { transform: translateY(-18px); }

.fatal { display: grid; place-items: center; height: 100%; padding: 24px; text-align: center; font-size: 1.2em; }

/* ---------------- small screens: panel becomes a sheet over the game */
@media (max-width: 820px) {
  #panel { position: absolute; inset: auto 0 0 0; width: 100%; height: 62%; border: 0; border-top: 1px solid var(--line); border-radius: 18px 18px 0 0; z-index: 10; box-shadow: 0 -10px 40px rgba(0,0,0,.4); }
  body:not(.panel-open) #panel, body[data-side="left"]:not(.panel-open) #panel { margin: 0; transform: translateY(105%); }
  #panel-tabs { grid-template-columns: none; grid-auto-flow: column; grid-auto-columns: 74px; overflow-x: auto; }
  .rom-name { display: none; }
  .row { grid-template-columns: minmax(0, 38%) 1fr; }
}

.panel-toggle { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); }
.icowrap { display: grid; place-items: center; }
@media (max-width: 820px) {
  body.panel-open #stage { flex: none; width: 100%; height: 38%; align-self: flex-start; }
}

/* ================= round 2: modes, studio, pins, chaos, debug, multiplayer ================= */
.seg { display: inline-flex; background: var(--panel2); border: 1px solid var(--line); border-radius: 99px; padding: 2px; }
.seg button { border: 0; background: transparent; padding: 4px 10px; border-radius: 99px; cursor: pointer; font-size: .82em; color: var(--dim); }
.seg button.on { background: var(--accent); color: #fff; font-weight: 600; }
body.simple-mode #panel-tabs { display: none; }
.mono { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; }
.pixel { image-rendering: pixelated; }
.inline { display: inline-flex; align-items: center; gap: 6px; font-size: .88em; color: var(--dim); }
.sw { display: inline-block; width: 16px; height: 16px; border-radius: 4px; vertical-align: middle; margin-right: 3px; box-shadow: inset 0 0 0 1px rgba(255,255,255,.15); }
.big-sw { width: 34px; height: 34px; border-radius: 8px; border: 2px solid var(--line); cursor: pointer; display: inline-grid; place-items: center; font: 700 .8em ui-monospace, monospace; color: #fff; text-shadow: 0 1px 2px #000; padding: 0; }
.big-sw.on { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.colorpick { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin: 6px 0; }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.chips.big .chip { padding: 7px 12px; font-size: .9em; }
#stage.picking, #stage.picking * { cursor: crosshair !important; }

/* simple mode cards */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 8px; }
.cards.small { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); }
.card { border: 1px solid var(--line); background: var(--panel); border-radius: calc(var(--radius) * .8); padding: 0 0 6px; cursor: pointer; overflow: hidden; display: flex; flex-direction: column; gap: 5px; font-size: .82em; text-align: center; }
.card img, .card-ph { width: 100%; aspect-ratio: 8 / 7; object-fit: cover; display: block; background: #000; }
.card.on { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.card:hover { border-color: var(--accent); }
.strip8 { display: grid; grid-template-columns: repeat(8, 1fr); height: 26px; }
.strip8 i { display: block; }
.fun-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.fun { border: 1px solid var(--line); background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 18%, var(--panel)), var(--panel)); border-radius: var(--radius); padding: 12px; cursor: pointer; text-align: left; display: flex; flex-direction: column; gap: 3px; }
.fun small { color: var(--dim); }
.fun:hover { border-color: var(--accent); }

/* modal */
.modal-veil { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: grid; place-items: center; z-index: 60; padding: 16px; }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px 14px; width: min(440px, 100%); max-height: 90vh; overflow: auto; box-shadow: 0 20px 60px rgba(0,0,0,.5); }
.modal.wide { width: min(760px, 100%); }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.modal h4 { margin: 12px 0 4px; }
.palgrid.choose { grid-template-columns: repeat(16, 1fr); }
.pinrow { display: flex; gap: 10px; margin: 6px 0; }
.pinbtn { display: flex; flex-direction: column; align-items: center; gap: 3px; background: none; border: 0; cursor: pointer; color: var(--dim); }
.pinhead { display: flex; gap: 10px; align-items: center; }
.tileprev { width: 48px; height: 48px; border-radius: 6px; border: 1px solid var(--line); flex: none; }
.pinlist { display: grid; gap: 4px; max-height: 240px; overflow: auto; }
.pin { display: flex; align-items: center; gap: 8px; padding: 4px 6px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); font-size: .88em; }
.pin .tileprev { width: 26px; height: 26px; }

/* debug */
.dbg-canvas { width: 100%; height: auto; display: block; background: #000; border-radius: 6px; cursor: pointer; }
.sprlist { white-space: pre; max-height: 160px; overflow: auto; font-size: 11px; }
.dbg-cpu { font-size: 11px; white-space: pre; overflow-x: auto; background: var(--panel); padding: 8px; border-radius: 8px; margin: 0; }
.hexgrid { display: grid; grid-template-columns: auto repeat(16, 1fr); gap: 1px 3px; font-size: 11px; }
.hexgrid.flow { display: flex; flex-wrap: wrap; gap: 2px 4px; }
.hexgrid .addr { color: var(--dim); }
.hexgrid .cell { outline: none; border-radius: 3px; padding: 0 1px; text-align: center; }
.hexgrid .cell:focus { background: var(--accent); color: #fff; }
.hexgrid .cell.hot { color: var(--accent); font-weight: 700; }
.inspect .kv { margin: 8px 0; }

/* chaos */
.chaos-big { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 8px 0 4px; }
.chaos-btn { font: 900 1.25em var(--font); letter-spacing: .06em; padding: 14px 28px; border-radius: 99px; border: 2px solid var(--accent); background: transparent; color: var(--accent); cursor: pointer; }
.chaos-big.on .chaos-btn { background: var(--accent); color: #fff; animation: chaosglow 1.2s infinite alternate; }
@keyframes chaosglow { to { box-shadow: 0 0 26px var(--accent); filter: hue-rotate(40deg); } }
.chaos-big small { color: var(--dim); text-align: center; }
.chaos-log { display: grid; gap: 2px; font-size: 11px; max-height: 260px; overflow: auto; }
.chaos-entry { display: flex; justify-content: space-between; gap: 8px; padding: 3px 6px; border-radius: 5px; background: var(--panel); }
.chaos-entry small { color: var(--dim); white-space: nowrap; }
.chaos-entry.crashed { opacity: .6; text-decoration: line-through; }

/* studio */
body.studio-open #touch { display: none; }
.studio { position: absolute; inset: 0; z-index: 15; background: var(--bg); display: flex; flex-direction: column; }
.studio-head { display: flex; align-items: center; gap: 12px; padding: 8px 12px; border-bottom: 1px solid var(--line); background: var(--panel); flex-wrap: wrap; }
.studio-game { color: var(--dim); }
.studio-tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.studio-tabs .tab { flex-direction: row; font-size: .88em; padding: 6px 12px; }
.studio-main { flex: 1; display: flex; min-height: 0; }
.studio-body { flex: 1; overflow: auto; padding: 14px 16px 40px; min-width: 0; }
.studio-body h3 { margin: 4px 0 8px; }
.studio-side { width: 300px; flex: none; border-left: 1px solid var(--line); padding: 12px; display: flex; flex-direction: column; gap: 8px; background: var(--panel); }
.studio-preview { width: 100%; height: auto; image-rendering: pixelated; border-radius: 8px; background: #000; }
.studio-cols { display: grid; grid-template-columns: minmax(220px, 340px) 1fr; gap: 18px; }
.col-left, .col-mid { min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.browser-scroll { max-height: 52vh; overflow: auto; border-radius: 8px; background: #000; }
.tilebrowser { width: 100%; display: block; cursor: pointer; }
.palchip { display: inline-flex; align-items: center; gap: 5px; }
.palchip .mini { display: inline-flex; }
.palchip .mini i { width: 9px; height: 12px; display: block; }
.painter { display: flex; flex-direction: column; gap: 8px; }
.paint { position: relative; width: min(100%, 512px); aspect-ratio: 1; border-radius: 8px; overflow: hidden; border: 1px solid var(--line); }
.paint-cv, .paint-grid { position: absolute; inset: 0; width: 100%; height: 100%; image-rendering: pixelated; }
.paint-grid { cursor: crosshair; touch-action: none; }
.paint-tools { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.paint-tools .brush { display: inline-flex; align-items: center; gap: 4px; font-size: .82em; color: var(--dim); }
.palresults { display: grid; gap: 6px; margin: 10px 0; }
.palrow { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
.palrow small { color: var(--dim); min-width: 90px; }
.roll { width: 100%; max-width: 900px; height: auto; border-radius: 8px; display: block; }
.musicregions { display: grid; gap: 8px; margin-top: 8px; }
.musicrun { padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
.export-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.export-card { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; background: var(--panel); display: flex; flex-direction: column; gap: 6px; }
.export-card .btn { align-self: flex-start; }
.row.wide { grid-template-columns: 140px 1fr; }
@media (max-width: 900px) {
  .studio-main { flex-direction: column; }
  .studio-side { width: 100%; border-left: 0; border-top: 1px solid var(--line); flex-direction: row; flex-wrap: wrap; }
  .studio-preview { width: 160px; }
  .studio-cols { grid-template-columns: 1fr; }
}

/* multiplayer */
.mp-win { position: absolute; top: 12px; right: 12px; width: min(380px, calc(100% - 24px)); max-height: calc(100% - 24px); overflow: auto; z-index: 16; background: color-mix(in srgb, var(--panel) 96%, transparent); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 20px 60px rgba(0,0,0,.5); backdrop-filter: blur(10px); }
.mp-head { display: flex; align-items: center; padding: 10px 12px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); z-index: 1; }
.mp-body { padding: 10px 12px 12px; display: grid; gap: 10px; }
.mp-id { font-size: .9em; display: grid; gap: 6px; }
.mp-id input, .mp-card input { width: 100%; }
.mp-card { border: 1px solid var(--line); border-radius: calc(var(--radius) * .8); padding: 10px; background: var(--panel2); display: grid; gap: 6px; }
.mp-card.on { border-color: var(--accent); }
.mp-card h4 { margin: 0; }
.mp-row { display: flex; align-items: center; justify-content: space-between; }
.mp-status { color: var(--accent); font-weight: 600; font-size: .9em; }
.mp-servers { display: grid; gap: 5px; max-height: 220px; overflow: auto; }
.mp-server { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); cursor: pointer; text-align: left; }
.mp-server:hover { border-color: var(--accent); }
.mp-server small { color: var(--dim); }
.mp-players { display: grid; gap: 4px; }
.mp-player { display: flex; align-items: center; gap: 8px; justify-content: space-between; font-size: .9em; }
.mp-player small { color: var(--dim); }
.mp-chat { max-height: 140px; overflow: auto; font-size: .88em; display: grid; gap: 2px; }
.mp-error { color: #ff8080; font-size: .88em; }
.mp-log { font-size: 10.5px; max-height: 160px; overflow: auto; white-space: pre-wrap; margin: 6px 0 0; color: var(--dim); }
.mp-details summary { cursor: pointer; color: var(--dim); font-size: .85em; }
#chatfeed { position: absolute; left: 12px; bottom: 12px; display: grid; gap: 4px; z-index: 6; pointer-events: none; max-width: 60%; }
.chatline { background: rgba(0,0,0,.6); color: #fff; padding: 5px 10px; border-radius: 10px; font-size: .9em; transition: opacity .6s; }
.chatline.out { opacity: 0; }

.mp-bring { border: 1px dashed var(--accent); border-radius: 8px; padding: 8px; display: grid; gap: 4px; }
.mp-net .mp-card { margin-top: 6px; }

/* XIO colour + motion layer: <html data-xio="xnes"> + /xio/motion/. Settings
   writes --accent/--bg inline, so a visitor's own colours still win. The
   moving field shows behind the landing screen on the dark themes only. */
html[data-xio] .logo b { color: var(--accent); }
html[data-xio] #stage:has(#landing:not([hidden])) { background: transparent; }
html.xn-light.x-has-field { background: var(--bg); }
html.xn-light::before,
html.xn-light .x-field:not(.local) { display: none; }
.xn-opt { display: inline-grid; place-items: center; }
.xn-opt svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.4; }
.xn-opt:hover, .xn-opt[aria-expanded="true"] { color: var(--accent); }
html[data-xio]:not(.xn-light) #landing { background:
  radial-gradient(ellipse at 20% 10%, color-mix(in srgb, var(--accent) 12%, transparent), transparent 60%),
  radial-gradient(ellipse at 90% 100%, color-mix(in srgb, var(--accent2) 12%, transparent), transparent 55%); }
html[data-xio]:not(.xn-light) #stage:has(#landing:not([hidden])) :is(#glow, #screen) { visibility: hidden; }
