/* Partikles: flat UI in the spirit of macOS dark mode. Grey surfaces, one accent, system type. */
:root {
  --window: #1e1e1e;
  --chrome: #2a2a2b;
  --chrome-2: #323234;
  --sheet: #262628;
  --cell: #2f2f31;
  --sep: rgba(255, 255, 255, .09);
  --fill: rgba(120, 120, 128, .24);
  --fill-2: rgba(120, 120, 128, .36);
  --seg-on: #636366;
  --text: #f5f5f7;
  --text-2: rgba(235, 235, 245, .62);
  --text-3: rgba(235, 235, 245, .38);
  --blue: #0a84ff;
  --green: #30d158;
  --orange: #ff9f0a;
  --red: #ff453a;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Helvetica, Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--window); color: var(--text); font: 400 13px/1.4 var(--font); overflow: hidden; -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; cursor: default; border: 0; background: none; }
button:focus-visible, input:focus-visible + span { outline: 3px solid rgba(10, 132, 255, .55); outline-offset: 1px; }
h1, h2 { margin: 0; font-weight: 600; }
svg { flex-shrink: 0; }
kbd { font: 500 11px/1 var(--font); color: var(--text-2); background: var(--fill); border-radius: 4px; padding: 3px 5px; }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ------------------------------------------------------------------ controls */
.btn { border-radius: 6px; padding: 5px 12px; background: var(--fill); color: var(--text); font-weight: 500; }
.btn:hover { background: var(--fill-2); }
.btn--primary { background: var(--blue); color: #fff; padding: 7px 28px; font-size: 14px; }
.btn--primary:hover { background: #2b95ff; }
.btn--small { padding: 3px 10px; font-size: 12px; }
.link { color: var(--blue); font-weight: 500; font-size: 14px; padding: 2px 4px; }
.segmented { display: inline-flex; background: var(--fill); border-radius: 7px; padding: 2px; gap: 0; flex-shrink: 0; }
.segmented button { border-radius: 5px; padding: 3px 10px; font-size: 12px; font-weight: 500; color: var(--text-2); }
.segmented button.is-on { background: var(--seg-on); color: var(--text); }
.toggle { position: relative; display: inline-block; width: 38px; height: 22px; flex-shrink: 0; }
.toggle input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; }
.toggle span { position: absolute; inset: 0; border-radius: 11px; background: var(--fill-2); transition: background .2s; pointer-events: none; }
.toggle span::after { content: ""; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .2s; }
.toggle input:checked + span { background: var(--green); }
.toggle input:checked + span::after { transform: translateX(16px); }
input[type=range] { -webkit-appearance: none; appearance: none; height: 20px; background: transparent; margin: 0; min-width: 0; }
input[type=range]::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: var(--fill-2); }
input[type=range]::-moz-range-track { height: 4px; border-radius: 2px; background: var(--fill-2); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%; background: #fff; margin-top: -6px; }
input[type=range]::-moz-range-thumb { width: 16px; height: 16px; border: 0; border-radius: 50%; background: #fff; }

/* ------------------------------------------------------------------ start */
.start { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; background: rgba(0, 0, 0, .62); transition: opacity .35s; }
.start.is-gone { opacity: 0; pointer-events: none; }
.start__card { width: 320px; text-align: center; padding: 32px 28px 22px; background: var(--sheet); border-radius: 12px; border: 1px solid var(--sep); }
.start__icon { width: 72px; height: 72px; border-radius: 16px; display: block; margin: 0 auto 14px; }
.start__title { font-size: 22px; letter-spacing: -0.01em; }
.start__lede { margin: 4px 0 22px; color: var(--text-2); }
.start__fine { margin: 16px 0 0; font-size: 11px; color: var(--text-3); }

/* ------------------------------------------------------------------ layout */
.app { position: fixed; inset: 0; display: grid; grid-template-columns: 60px minmax(0, 1fr) 300px; grid-template-rows: 46px minmax(0, 1fr); }
.toolbar { grid-column: 1 / -1; display: flex; align-items: center; gap: 14px; padding: 0 10px 0 14px; background: var(--chrome); border-bottom: 1px solid #111; min-width: 0; }
.toolbar__title { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 13px; padding-right: 8px; }
.toolbar__title img { border-radius: 5px; }
.toolbar__group { display: flex; align-items: center; gap: 2px; min-width: 0; }
.toolbar__spacer { flex: 1; }
.toolbar__sep { width: 1px; height: 18px; background: var(--sep); margin: 0 6px; }
.tb { display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 8px; border-radius: 6px; color: var(--text-2); font-size: 12px; font-weight: 500; white-space: nowrap; }
.tb svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.tb:hover { background: var(--fill); color: var(--text); }
.tb.is-on { background: var(--fill-2); color: var(--text); }
.tb--icon { width: 30px; padding: 0; justify-content: center; }
#playBtn svg { fill: currentColor; stroke: none; }
#soundBtn.is-on { background: none; }
#soundBtn .mute { display: none; }
#soundBtn:not(.is-on) .wave { display: none; }
#soundBtn:not(.is-on) .mute { display: inline; }
.toolbar .segmented { margin-left: 6px; }

/* tool palette */
.toolrail { background: var(--chrome); border-right: 1px solid #111; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0; overflow-y: auto; scrollbar-width: none; }
.tool { width: 48px; height: 46px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; border-radius: 7px; color: var(--text-2); }
.tool svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linejoin: round; stroke-linecap: round; }
.tool span { font-size: 10px; }
.tool:hover { background: var(--fill); color: var(--text); }
.tool.is-on { background: var(--fill-2); color: var(--blue); }
.tool.is-on span { color: var(--text); }
.tool kbd { display: none; }
.toolrail__sep { width: 28px; height: 1px; background: var(--sep); margin: 5px 0; flex-shrink: 0; }

/* stage */
.stage { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; padding: 14px 16px 10px; min-width: 0; min-height: 0; overflow: hidden; background: var(--window); }
.stage__frame { flex-shrink: 0; border-radius: 8px; overflow: hidden; outline: 1px solid rgba(255, 255, 255, .06); }
.stage__screen { position: relative; width: 100%; height: 100%; background: #111; }
#view { display: block; width: 100%; height: 100%; touch-action: none; cursor: crosshair; }
#view.cur-grab { cursor: grab; } #view.cur-grabbing { cursor: grabbing; }
.hud-label { position: absolute; left: 50%; top: 10px; transform: translateX(-50%); font-size: 12px; font-weight: 500; color: #fff; background: rgba(0, 0, 0, .55); border-radius: 6px; padding: 3px 10px; pointer-events: none; }
.status { display: flex; align-items: center; gap: 16px; font-size: 12px; color: var(--text-2); flex-shrink: 0; height: 28px; padding: 0 2px; }
.status__cell { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text); }
.status__cell .sw { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 6px; vertical-align: 0; }
.status__meta { color: var(--text-3); white-space: nowrap; font-variant-numeric: tabular-nums; }

/* drive panel: same row as the status line, never over the play area */
.drivebar { display: flex; align-items: center; gap: 12px; height: 28px; font-size: 12px; color: var(--text-2); flex-shrink: 0; white-space: nowrap; overflow: hidden; }
.drivebar__name { color: var(--text); font-weight: 600; }
.drivebar__keys { display: flex; align-items: center; gap: 4px; flex: 1; min-width: 0; overflow: hidden; }
.drivebar__keys span { margin-right: 8px; }
.drivebar__pad { display: flex; gap: 3px; }
.pad { min-width: 28px; height: 24px; padding: 0 6px; border-radius: 5px; background: var(--fill); color: var(--text); font-size: 11px; touch-action: none; user-select: none; }
.pad--act { background: var(--blue); color: #fff; font-weight: 500; padding: 0 10px; }
.pad.is-down { background: var(--fill-2); }

/* inspector popover */
.inspector { position: absolute; top: 10px; right: 10px; width: 224px; background: rgba(44, 44, 46, .97); border: 1px solid var(--sep); border-radius: 10px; box-shadow: 0 8px 24px rgba(0, 0, 0, .35); padding-bottom: 10px; }
.insp__head { display: flex; align-items: center; gap: 6px; padding: 9px 8px 6px 12px; }
.insp__name { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.insp__x { width: 20px; height: 20px; border-radius: 50%; background: var(--fill); color: var(--text-2); font-size: 13px; line-height: 20px; }
.insp__rows { padding: 2px 12px; display: grid; gap: 6px; }
.insp__row { display: grid; grid-template-columns: 62px 1fr; align-items: center; gap: 8px; font-size: 12px; }
.insp__row > span { color: var(--text-2); }
.insp__row > b { font-weight: 500; }
.bar { height: 4px; border-radius: 2px; background: var(--fill-2); position: relative; overflow: hidden; }
.bar i { position: absolute; inset: 0 auto 0 0; background: var(--green); }
.bar i.is-mid { background: var(--orange); } .bar i.is-low { background: var(--red); }
.insp__actions { display: flex; flex-wrap: wrap; gap: 5px; padding: 10px 12px 0; }
.mini { font-size: 12px; padding: 3px 9px; border-radius: 5px; background: var(--fill); color: var(--text); }
.mini:hover { background: var(--fill-2); }
.mini--go { background: var(--blue); color: #fff; }
.mini--go:hover { background: #2b95ff; }
.mini--on { background: var(--fill-2); }
.mini--del { color: var(--red); }

/* toasts */
.toasts { position: absolute; left: 10px; top: 10px; display: flex; flex-direction: column; gap: 6px; pointer-events: none; max-width: min(340px, 55%); }
.toast { background: rgba(44, 44, 46, .96); color: var(--text-2); border: 1px solid var(--sep); border-radius: 10px; padding: 8px 12px; font-size: 12px; transition: opacity .3s; }
.toast b { display: block; color: var(--text); font-weight: 600; font-size: 13px; }
.toast.is-out { opacity: 0; }

/* ------------------------------------------------------------------ library */
.library { background: var(--chrome); border-left: 1px solid #111; display: flex; flex-direction: column; min-height: 0; }
.library__head { font-weight: 600; padding: 12px 14px 8px; }
.cats { display: flex; flex-wrap: wrap; gap: 2px; padding: 0 10px 10px; border-bottom: 1px solid var(--sep); }
.cat { padding: 3px 8px; border-radius: 6px; font-size: 12px; color: var(--text-2); }
.cat:hover { color: var(--text); }
.cat.is-on { background: var(--fill-2); color: var(--text); }
.tiles { flex: 1; min-height: 0; overflow-y: auto; padding: 10px; display: grid; grid-template-columns: repeat(3, 1fr); grid-auto-rows: max-content; gap: 8px; align-content: start; scrollbar-width: thin; scrollbar-color: var(--fill-2) transparent; }
.tile { position: relative; padding: 0; border-radius: 7px; overflow: hidden; aspect-ratio: 4 / 3; background: var(--cell); }
.tile canvas { display: block; width: 100%; height: 100%; image-rendering: pixelated; }
.tile__name { position: absolute; left: 0; right: 0; bottom: 0; padding: 3px 6px 4px; font-size: 11px; font-weight: 500; color: #fff; background: rgba(0, 0, 0, .58); text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile:hover { box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .25); }
.tile.is-on { box-shadow: inset 0 0 0 2px var(--blue); }
.tile.is-on .tile__name { background: var(--blue); }
.tile--wide { grid-column: span 2; aspect-ratio: auto; }
.library__foot { border-top: 1px solid var(--sep); padding: 10px 14px 12px; display: grid; gap: 8px; }
.sel__name { font-weight: 600; }
.sel__desc { color: var(--text-2); font-size: 12px; min-height: 17px; }
.frow { display: flex; align-items: center; gap: 10px; font-size: 12px; color: var(--text-2); }
.frow label:first-child { flex-shrink: 0; }
.frow input[type=range] { flex: 1; }
.frow .toggle { margin-left: auto; }
.frow__val { width: 32px; text-align: right; color: var(--text); font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------------ sheets */
.modal { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; background: rgba(0, 0, 0, .45); padding: 20px; }
.sheet { width: min(560px, 100%); max-height: 100%; overflow-y: auto; background: var(--sheet); border: 1px solid var(--sep); border-radius: 12px; padding: 0 18px 18px; box-shadow: 0 20px 50px rgba(0, 0, 0, .45); }
.sheet--wide { width: min(620px, 100%); }
.sheet__head { display: flex; align-items: center; justify-content: space-between; padding: 14px 0 10px; position: sticky; top: 0; background: var(--sheet); z-index: 1; }
.sheet__head h2 { font-size: 15px; }
.sheet__note { margin: 0 0 12px; color: var(--text-2); font-size: 12px; }
.scenes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.scene { text-align: left; padding: 0; border-radius: 8px; }
.scene canvas { display: block; width: 100%; aspect-ratio: 16 / 9; border-radius: 7px; background: #111; }
.scene:hover canvas { box-shadow: 0 0 0 2px var(--blue); }
.scene__name { display: block; font-weight: 500; margin-top: 6px; }
.scene__desc { display: block; color: var(--text-2); font-size: 11.5px; margin-top: 1px; }
.group { margin-top: 14px; }
.group__title { font-size: 12px; font-weight: 600; color: var(--text-2); padding: 0 4px 6px; }
.list { background: var(--cell); border-radius: 9px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 9px 12px; min-height: 40px; }
.row + .row { border-top: 1px solid var(--sep); }
.row__text { min-width: 0; }
.row__hint { color: var(--text-3); font-size: 11.5px; }
.row__ctl { display: flex; align-items: center; gap: 8px; width: 220px; }
.row__ctl input { flex: 1; }
.keys .row { font-size: 12px; min-height: 34px; padding: 6px 12px; }
.keys .row > span:first-child { color: var(--text-2); }

/* ------------------------------------------------------------------ smaller screens */
@media (max-width: 1180px) {
  .tb span:not(.sr) { display: none; }
  .tb { width: 30px; padding: 0; justify-content: center; }
}
@media (max-width: 960px) {
  .app { grid-template-columns: 56px minmax(0, 1fr); grid-template-rows: 46px minmax(0, 1fr) 230px; }
  .library { grid-column: 1 / -1; border-left: 0; border-top: 1px solid #111; }
  .library__head, .library__foot { display: none; }
  .cats { padding-top: 8px; }
  .tiles { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); }
  .toolbar__title span, .status__meta { display: none; }
  .scenes { grid-template-columns: 1fr 1fr; }
  .row__ctl { width: 150px; }
}
