:root {
  color-scheme: light dark;
  --ui-bg: rgba(245, 248, 249, .95);
  --ui-solid: #f5f8f9;
  --ui-ink: #1d2a30;
  --ui-muted: #5b6b72;
  --ui-line: rgba(29, 42, 48, .16);
  --ui-field: rgba(29, 42, 48, .055);
  --ui-accent: #236d7f;
  --ui-danger: #b83434;
  --page: #15191c;
  font-family: "Instrument Sans", system-ui, -apple-system, sans-serif;
  color: var(--ui-ink);
}
@media (prefers-color-scheme: dark) {
  :root {
    --ui-bg: rgba(21, 29, 34, .95); --ui-solid: #151d22; --ui-ink: #e3edf0;
    --ui-muted: #a1b1bb; --ui-line: rgba(210, 233, 245, .15); --ui-field: rgba(210, 233, 245, .06);
    --ui-accent: #86d2e6; --ui-danger: #ff8d8d;
  }
}
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; width: 100%; height: 100%; overflow: hidden; }
body { background: var(--page); font-size: 13px; line-height: 1.45; }
canvas#bg { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: var(--ui-ink); }
button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--ui-field); border: 1px solid var(--ui-line); border-radius: 7px;
  min-height: 32px; padding: 5px 10px; cursor: pointer;
}
button:hover { border-color: var(--ui-muted); background: var(--ui-line); }
button:disabled { opacity: .4; cursor: default; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, summary:focus-visible, a:focus-visible {
  outline: 2px solid var(--ui-accent); outline-offset: 2px;
}
input, select, textarea { min-width: 0; background: var(--ui-field); border: 1px solid var(--ui-line); border-radius: 6px; padding: 6px 8px; }
input[type="checkbox"] { width: 17px; height: 17px; accent-color: var(--ui-accent); }
input[type="range"] { width: 100%; accent-color: var(--ui-accent); padding: 0; border: 0; margin: 5px 0; }
input[type="color"] { width: 36px; height: 30px; padding: 2px; cursor: pointer; }
textarea { width: 100%; min-height: 160px; resize: vertical; font: 12px/1.5 ui-monospace, monospace; }
#shareText { min-height: 44px; max-height: 132px; }
.ui-icon { width: 17px; height: 17px; flex: none; display: block; }
.workspace-bar {
  position: fixed; top: calc(12px + env(safe-area-inset-top, 0px)); left: 12px; right: 12px; z-index: 40;
  display: flex; align-items: center; gap: 16px; padding: 8px 12px;
  border: 1px solid var(--ui-line); border-radius: 12px; background: var(--ui-bg);
  backdrop-filter: blur(16px); box-shadow: 0 5px 24px #0002;
}
.brand { display: flex; gap: 4px; font-weight: 600; color: var(--ui-ink); text-decoration: none; white-space: nowrap; }
.brand span { font-weight: 400; color: var(--ui-muted); }
.workspace-tools { display: flex; flex: 1; gap: 4px; }
.workspace-tools button { background: transparent; border-color: transparent; white-space: nowrap; }
.workspace-tools button[aria-expanded="true"] { background: var(--ui-field); border-color: var(--ui-line); color: var(--ui-accent); }
#hide { background: transparent; border-color: transparent; white-space: nowrap; }
.studio-panel {
  position: fixed; top: calc(78px + env(safe-area-inset-top, 0px)); left: 12px; z-index: 30;
  width: 350px; max-height: calc(100dvh - 285px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
  display: flex; flex-direction: column; overflow: clip;
  border: 1px solid var(--ui-line); border-radius: 12px; background: var(--ui-bg);
  backdrop-filter: blur(16px); box-shadow: 0 8px 30px #0002;
}
.studio-panel.front { z-index: 31; }
#panel { width: 320px; }
@media (min-width: 761px) {
  #compositionPanel, #galleryPanel, #themesPanel { left: auto; right: 12px; }
}
.panel-head { display: flex; flex-shrink: 0; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--ui-line); cursor: grab; touch-action: none; user-select: none; }
.panel-head h2 { flex: 1; font-size: 14px; font-weight: 600; margin: 0; }
.panel-close { padding: 3px 5px; min-height: 26px; border: 0; background: none; color: var(--ui-muted); }
.panel-close span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.grip { padding: 0; min-height: 26px; width: 16px; border: 0; background: none; color: var(--ui-muted); cursor: grab; }
.dragging, .dragging .panel-head { cursor: grabbing; user-select: none; }
.panel-body { min-height: 0; padding: 0 14px 14px; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; }
.scope-note { margin: 12px 0; font-size: 11px; color: var(--ui-accent); letter-spacing: .025em; }
.hint { font-size: 12px; color: var(--ui-muted); margin: 8px 0; }
.hint:empty { display: none; }
.group { border: 0; border-top: 1px solid var(--ui-line); padding: 10px 0 0; margin: 12px 0 0; }
.group > summary { list-style: none; display: flex; align-items: center; gap: 8px; cursor: pointer; padding: 2px 0; }
.group > summary::-webkit-details-marker { display: none; }
.group > summary::before { content: ""; width: 6px; height: 6px; border-right: 1.5px solid var(--ui-muted); border-bottom: 1.5px solid var(--ui-muted); transform: rotate(-45deg); }
.group[open] > summary::before { transform: rotate(45deg); }
.group h3 { margin: 0; font-size: 13px; font-weight: 600; }
.group[open] > summary { margin-bottom: 10px; }
.row { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 5px 10px; margin: 10px 0; }
.row label { color: var(--ui-muted); }
.row input[type="range"] { grid-column: 1 / -1; }
.row select { max-width: 180px; }
.row input[type="text"]:not(.hex-value), .row textarea { grid-column: 1 / -1; width: 100%; }
.row .number-value { width: 80px; padding: 4px 6px; font-variant-numeric: tabular-nums; text-align: right; }
.color-inputs { display: flex; gap: 5px; align-items: center; }
.hex-value { width: 86px; font: 12px ui-monospace, monospace; }
.row output { color: var(--ui-muted); }
.lab { display: inline-flex; align-items: center; gap: 5px; min-width: 0; }
.info { padding: 0; min-height: 18px; height: 18px; width: 18px; border-radius: 50%; font-size: 10px; color: var(--ui-muted); background: transparent; }
.layers { display: flex; flex-direction: column; gap: 4px; }
.layer-row { display: flex; align-items: center; gap: 3px; padding: 4px; border-radius: 7px; border: 1px solid transparent; }
.layer-row.active { border-color: var(--ui-line); background: var(--ui-field); }
.layer-row .name { flex: 1; min-width: 0; justify-content: flex-start; text-align: left; border: 0; background: transparent; padding: 4px; overflow: hidden; }
.layer-row.active .name { color: var(--ui-accent); }
.layer-row.hidden-layer .name { color: var(--ui-muted); text-decoration: line-through; }
.icon { padding: 2px; min-height: 26px; width: 23px; border: 0; background: none; }
.add-row { display: flex; gap: 6px; margin-top: 10px; }
.add-row select { flex: 1; width: 0; }
.selected-layer { border-top: 1px solid var(--ui-line); margin-top: 18px; padding-top: 14px; }
.eyebrow { font-size: 10px; text-transform: uppercase; letter-spacing: .1em; color: var(--ui-muted); }
.selected-name { margin: 3px 0 0; font-size: 15px; }
.pattern-group { border: 0; min-width: 0; margin: 10px 0 0; padding: 0; }
.pattern-group legend { padding: 0; margin-bottom: 4px; font-size: 11px; color: var(--ui-muted); }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
.seg button { font-size: 12px; padding: 5px 4px; color: var(--ui-muted); }
.seg button[aria-pressed="true"] { color: var(--ui-accent); border-color: var(--ui-accent); background: var(--ui-field); }
.pattern-note { font-size: 11px; }
.wide { width: 100%; margin-top: 6px; }
.pulse { border: 1px solid var(--ui-line); border-radius: 8px; padding: 10px; margin: 8px 0; }
.pulse-head { display: flex; align-items: center; gap: 6px; }
.pulse-head span { flex: 1; font-weight: 500; }
.add-pulse { width: 100%; }
.filter-block { border: 1px solid var(--ui-line); border-radius: 8px; padding: 9px; margin: 7px 0; }
.filter-head { display: flex; justify-content: space-between; align-items: center; font-weight: 500; }
.filter-block .row:last-child { margin-bottom: 0; }
.palettes { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin: 8px 0; }
.palette { position: relative; height: 32px; padding: 0; overflow: hidden; background: var(--bg); }
.palette .line { position: absolute; left: 18%; right: 34%; top: 38%; height: 2px; background: var(--fg); }
.palette .dot { position: absolute; right: 16%; bottom: 22%; width: 6px; height: 6px; border-radius: 50%; background: var(--ac); }
.palette[aria-checked="true"] { outline: 2px solid var(--ui-accent); outline-offset: 1px; }
.preset-save, .theme-save, .preset-edit, .theme-edit { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.preset-save input, .theme-save input, .preset-edit input, .theme-edit input { flex: 1; width: 130px; }
.search-field { width: 100%; margin: 6px 0; }
.gallery-section + .gallery-section { border-top: 1px solid var(--ui-line); margin-top: 16px; padding-top: 7px; }
.gallery-section h3 { margin: 10px 0 4px; font-size: 13px; }
.preset-list { list-style: none; margin: 10px 0 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.preset { min-width: 0; border: 1px solid var(--ui-line); border-radius: 8px; overflow: hidden; }
.preset-open { display: flex; flex-direction: column; align-items: stretch; width: 100%; padding: 5px; border: 0; background: transparent; }
.preset-thumb { width: 100%; height: auto; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 4px; background: var(--ui-field); }
.preset-thumb.failed { opacity: .25; }
.preset-name { min-width: 0; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 3px 2px; }
.preset-description { margin: 0 7px 8px; color: var(--ui-muted); font-size: 11px; line-height: 1.4; }
.preset-actions, .theme-actions { display: flex; flex-wrap: wrap; gap: 3px; padding: 4px; }
.preset-actions button { flex: 1; padding: 4px; min-width: 30px; }
.preset-confirm, .theme-confirm { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px; border: 1px solid var(--ui-line); border-radius: 6px; }
.preset-confirm span, .theme-confirm span { width: 100%; overflow-wrap: anywhere; }
.preset-edit, .theme-edit { padding: 5px; }
.danger { color: var(--ui-danger); }
.empty { grid-column: 1 / -1; color: var(--ui-muted); padding: 16px 4px; }
.theme-section { margin-top: 14px; }
.theme-section h3 { font-size: 13px; }
.theme-colors { display: flex; flex-direction: column; gap: 8px; }
.theme-color { display: flex; align-items: center; gap: 7px; }
.theme-color label { flex: 1; color: var(--ui-muted); }
.theme-color input[type="text"] { width: 86px; font-family: ui-monospace, monospace; }
.theme-list { display: flex; flex-direction: column; list-style: none; padding: 0; gap: 8px; }
.theme-card { padding: 7px; border: 1px solid var(--ui-line); border-radius: 8px; }
.theme-swatches { display: flex; overflow: hidden; width: 66px; height: 24px; border-radius: 4px; flex: none; }
.theme-swatch { flex: 1; min-width: 0; height: 24px; }
.theme-heading { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.theme-current { font-size: 11px; color: var(--ui-muted); }
.theme-load[aria-pressed="true"], .preset-open[aria-current="true"] { outline: 1px solid var(--ui-accent); outline-offset: -1px; }
.preset-confirm p, .theme-confirm p, .preset-edit .status, .theme-edit .status { flex-basis: 100%; margin: 0; }
.status { font-size: 12px; color: var(--ui-muted); }
.theme-card > button { width: 100%; justify-content: flex-start; }
.json-actions, .preset-files { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.video-settings { border: 0; padding: 0; margin: 0; min-width: 0; }
.video-dimensions { display: flex; gap: 10px; }
.video-dimensions label { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; color: var(--ui-muted); }
.video-dimensions input { width: 76px; }
#videoSize { max-width: 220px; }
#videoProgress, #videoPreview { width: 100%; margin-top: 12px; }
#videoPreview { max-height: 280px; border-radius: 6px; background: #000; }
.download-button { display: inline-block; border: 1px solid var(--ui-line); border-radius: 7px; padding: 7px 12px; color: var(--ui-accent); text-decoration: none; }
.preset-files button { flex: 1; }
#exportResult textarea { min-height: 65px; }
#msg { font-size: 12px; color: var(--ui-muted); }
.transport-panel {
  top: auto; bottom: calc(12px + env(safe-area-inset-bottom, 0px)); left: 50%; transform: translateX(-50%);
  width: min(680px, calc(100% - 24px)); max-height: 230px;
}
.transport-panel .panel-head { padding: 7px 12px; cursor: default; touch-action: auto; }
.transport-panel .grip { display: none; }
.transport-panel .panel-body { padding: 10px 12px; }
.transport-controls { display: flex; align-items: center; gap: 8px; }
#play { color: var(--ui-accent); min-width: 84px; }
.time-field { display: flex; align-items: center; gap: 4px; margin-left: auto; color: var(--ui-muted); font-size: 12px; }
.time-field input { width: 70px; padding: 4px; font-variant-numeric: tabular-nums; }
#timeline { display: block; margin: 10px 0; }
#playbackSettings .row { display: flex; margin: 0; gap: 8px; }
#playbackSettings .lab { flex: none; }
#playbackSettings .number-value { width: 64px; }
#playbackSettings input[type="range"] { flex: 1; width: 100px; }
.keys { font-size: 10px; margin: 8px 0 0; }
.fps { position: fixed; bottom: 16px; left: 14px; z-index: 35; background: var(--ui-bg); padding: 5px 8px; border-radius: 6px; font: 11px ui-monospace, monospace; }
.tip { position: fixed; z-index: 60; display: flex; flex-direction: column; gap: 4px; max-width: 280px; padding: 10px; border-radius: 8px; border: 1px solid var(--ui-line); background: var(--ui-solid); box-shadow: 0 4px 20px #0003; font-size: 12px; pointer-events: none; }
.tip small { color: var(--ui-muted); font-size: 11px; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
@media (max-width: 1050px) {
  .brand { flex-direction: column; gap: 0; line-height: 1.1; font-size: 11px; }
  .workspace-bar { gap: 8px; }
  .workspace-tools { overflow-x: auto; scrollbar-width: none; }
  .workspace-tools button { padding: 5px 7px; font-size: 12px; }
  #hide span { display: none; }
}
@media (max-width: 760px) {
  .workspace-bar { left: 8px; right: 8px; top: calc(8px + env(safe-area-inset-top, 0px)); padding: 7px; gap: 5px; }
  .brand { display: none; }
  .workspace-tools { gap: 2px; }
  .workspace-tools button { flex: 1; flex-direction: column; gap: 2px; padding: 4px 3px; font-size: 10px; }
  #hide { padding: 5px; }
  .studio-panel, #panel { top: auto; left: 8px; right: 8px; bottom: calc(198px + env(safe-area-inset-bottom, 0px)); width: auto; max-height: min(52dvh, calc(100dvh - 285px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px))); }
  .panel-head { cursor: default; touch-action: auto; }
  .grip { display: none; }
  .panel-body { padding: 0 12px 12px; }
  .row input[type="number"], .row input[type="text"], .search-field, .preset-save input, .theme-save input, .theme-color input[type="text"], .time-field input, .preset-edit input, .theme-edit input { font-size: 16px; }
  .video-dimensions input { font-size: 16px; }
  .row { margin: 14px 0; }
  .row input[type="range"] { min-height: 24px; }
  button { min-height: 36px; }
  .info { width: 24px; height: 24px; min-height: 24px; }
  .transport-panel { left: 8px; right: 8px; bottom: calc(8px + env(safe-area-inset-bottom, 0px)); transform: none; width: auto; max-height: 185px; }
  .transport-panel .panel-head { display: none; }
  .transport-panel .panel-body { padding: 10px; }
  .transport-controls { gap: 5px; flex-wrap: wrap; }
  .transport-controls button { padding: 5px 7px; }
  .time-field { gap: 2px; font-size: 10px; }
  .time-field input { width: 57px; }
  .time-field:last-child { margin-left: 0; }
  #play { min-width: 68px; }
  .keys { display: none; }
  .fps { top: 78px; bottom: auto; left: 8px; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto; } }

.hyperlayer-list { display: flex; flex-direction: column; gap: 4px; }
.hyperlayer-row { display: flex; align-items: center; gap: 5px; padding: 4px; border: 1px solid transparent; border-radius: 7px; }
.hyperlayer-row.active { border-color: var(--ui-line); background: var(--ui-field); }
.hyperlayer-pick { flex: 1; min-width: 0; justify-content: flex-start; border: 0; background: transparent; text-align: left; }
.hyperlayer-pick span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hyperlayer-pick[aria-pressed="true"] { color: var(--ui-accent); }
.hyperlayer-row > .icon { padding: 5px; }
.hyperlayer-editor { border: 1px solid var(--ui-line); border-radius: 8px; margin-top: 12px; padding: 10px; }
.hyperlayer-editor h4 { margin: 0 0 8px; font-size: 12px; overflow-wrap: anywhere; }
.hyperlayer-editor .row:last-child { margin-bottom: 0; }
.hyper-influence { border: 1px solid var(--ui-line); border-radius: 8px; padding: 9px; margin: 8px 0; }
.hyper-influence .row { margin-top: 0; }
.hyper-influence label { overflow-wrap: anywhere; }
.hyper-influence-footer { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.hyper-influence-footer .status { font-size: 11px; }
.hyper-influence-footer button { flex: none; }
