html, body { overflow: hidden; }

.studio {
  --dock-h: 360px;
  height: 100vh;
  display: grid;
  grid-template-columns: 272px minmax(0, 1fr) 340px;
  grid-template-rows: 54px minmax(0, 1fr) var(--dock-h) 28px;
  grid-template-areas:
    'top top top'
    'left center right'
    'dock dock right'
    'status status status';
  gap: 8px;
  padding: 0 8px;
  background:
    radial-gradient(900px 400px at 15% -10%, rgba(124, 108, 255, 0.1), transparent 60%),
    radial-gradient(800px 400px at 95% -10%, rgba(59, 130, 246, 0.08), transparent 60%),
    var(--bg);
}
.area-left { grid-area: left; display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.area-center { grid-area: center; display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.area-right { grid-area: right; display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.area-dock { grid-area: dock; display: flex; flex-direction: column; min-height: 0; overflow: hidden; }

.topbar { grid-area: top; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px; padding: 0 6px; }
.topbar .group { display: flex; align-items: center; gap: 6px; }
.topbar .group.right { justify-content: flex-end; }
.project-name { width: 220px; height: 30px; margin-left: 10px; background: transparent; border: 1px solid transparent; border-radius: 7px; padding: 0 9px; font-weight: 600; }
.project-name:hover { border-color: var(--line); background: var(--panel); }
.project-name:focus { outline: none; border-color: var(--accent); background: var(--panel); }
.transport { display: flex; gap: 6px; padding: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; }
.transport .btn { height: 30px; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--good); box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.2); }

.viewbar { display: flex; align-items: center; gap: 6px; height: 40px; padding: 0 8px; border-bottom: 1px solid var(--line); }
.viewbar .spacer { flex: 1; }
.viewtabs { display: flex; gap: 2px; padding: 3px; background: var(--bg-2); border: 1px solid var(--line); border-radius: 9px; }
.viewtab { height: 26px; padding: 0 12px; border: 0; border-radius: 6px; background: none; color: var(--muted); cursor: pointer; font-weight: 500; display: inline-flex; align-items: center; gap: 6px; }
.viewtab[aria-selected='true'] { background: var(--panel-3); color: var(--text); }
.zoom-label { color: var(--muted); font-variant-numeric: tabular-nums; min-width: 46px; text-align: right; }

.stage { position: relative; flex: 1; min-height: 0; background: #07080c; }
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#sceneCanvas { touch-action: none; }
#playCanvas { object-fit: contain; outline: none; }
.stage-note { position: absolute; left: 12px; bottom: 10px; padding: 6px 10px; border-radius: 8px; background: rgba(10, 12, 18, 0.78); color: var(--muted); font-size: 12px; pointer-events: none; }
.stage-note:empty { display: none; }

.tree-search { padding: 8px 10px; border-bottom: 1px solid var(--line); }
.tree { flex: 1; min-height: 0; overflow: auto; padding: 6px; }
.tree-group { display: flex; align-items: center; gap: 8px; margin: 10px 6px 4px; font-size: 11px; font-weight: 600; letter-spacing: 0.07em; text-transform: uppercase; color: var(--faint); }
.tree-row { display: flex; align-items: center; gap: 9px; height: 30px; padding: 0 8px; border-radius: 7px; cursor: pointer; border: 1px solid transparent; }
.tree-row:hover { background: var(--panel-2); }
.tree-row.is-selected { background: var(--accent-soft); border-color: rgba(124, 108, 255, 0.45); }
.tree-name { font-weight: 500; }
.tree-sub { margin-left: auto; color: var(--faint); font-size: 12px; font-variant-numeric: tabular-nums; }
.tree-actions { display: none; gap: 2px; margin-left: 6px; }
.tree-row:hover .tree-actions, .tree-row.is-selected .tree-actions { display: flex; }
.tree-row:hover .tree-sub, .tree-row.is-selected .tree-sub { display: none; }
/* hidden/locked row */
.tree-row.is-hidden { opacity: 0.45; }
.tree-row.is-hidden:hover, .tree-row.is-hidden.is-selected { opacity: 1; }
.tree-lock-badge { display: inline-flex; align-items: center; color: var(--warn, #f59e0b); margin: 0 2px; }
/* collapsible group headers */
.tree-group { cursor: pointer; user-select: none; }
.tree-group:hover { color: var(--muted); }
.tree-group-arrow { display: inline-flex; transition: transform 0.15s; color: var(--faint); }
.tree-group.is-collapsed .tree-group-arrow { transform: rotate(-90deg); }

.pane-body { flex: 1; min-height: 0; overflow: auto; }
.empty-state { display: grid; place-items: center; text-align: center; gap: 6px; padding: 34px 20px; color: var(--muted); }
.empty-state strong { color: var(--text); font-size: 14px; }
.obj-head { display: flex; align-items: center; gap: 10px; padding: 14px 12px 12px; border-bottom: 1px solid var(--line); }
.obj-head .obj-title { font-size: 15px; font-weight: 700; }
.obj-head .grow { flex: 1; }
.behavior { display: flex; align-items: flex-start; gap: 10px; padding: 7px 0; cursor: pointer; }
.behavior strong { display: block; font-weight: 600; }
.behavior span.d { color: var(--muted); font-size: 12px; }
.rule-card { padding: 10px; margin-bottom: 8px; background: var(--bg-2); border: 1px solid var(--line); border-radius: 9px; }
.rule-card .field { grid-template-columns: 48px 1fr; margin-bottom: 6px; }
.rule-card .rule-foot { display: flex; justify-content: space-between; align-items: center; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { height: 26px; padding: 0 10px; border-radius: 13px; background: var(--panel-2); border: 1px solid var(--line); color: var(--muted); cursor: pointer; font-size: 12.5px; }
.chip:hover { color: var(--text); border-color: var(--line-2); }

.dock-pane { flex: 1; min-height: 0; overflow: auto; padding: 12px; }
.problem { display: flex; gap: 10px; align-items: flex-start; padding: 8px 10px; margin-bottom: 6px; background: var(--bg-2); border: 1px solid var(--line); border-radius: 8px; cursor: pointer; }
.problem:hover { border-color: var(--line-2); }
.problem.error .ico { color: var(--bad); }
.problem.warn .ico { color: var(--warn); }
.problem.ok .ico { color: var(--good); }
.json-box { width: 100%; height: calc(100% - 44px); min-height: 120px; resize: none; }
.ai-grid { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 14px; }
.bar-row { display: grid; grid-template-columns: 76px minmax(0, 1fr) 48px 96px; gap: 10px; align-items: center; margin: 6px 0; }
.bar-row > span:first-child { text-transform: capitalize; }
.bar-row .num { font-variant-numeric: tabular-nums; text-align: right; }
.bar { height: 8px; background: var(--panel-3); border-radius: 4px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--grad); border-radius: 4px; transition: width 0.3s; }
.assets-pane { display: block; }
.drop { display: flex; gap: 12px; align-items: center; padding: 12px 14px; border: 1.5px dashed var(--line-2); border-radius: 12px; color: var(--muted); cursor: pointer; background: var(--bg-2); transition: border-color 0.15s, background 0.15s; }
.drop:hover, .drop:focus-visible, .drop.over { border-color: var(--accent); background: var(--accent-soft); color: var(--text); outline: none; }
.drop strong { display: block; color: var(--text); font-size: 13.5px; }
.drop span { font-size: 12.5px; }
.usage { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 10px; align-items: center; margin: 10px 0 12px; font-size: 12.5px; color: var(--muted); }
.asset-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 10px; }
.asset { display: flex; gap: 12px; padding: 10px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; min-width: 0; }
.asset-thumb { flex: none; width: 84px; height: 84px; border-radius: 8px; display: grid; place-items: center; overflow: hidden; border: 1px solid var(--line); background: repeating-conic-gradient(#20242f 0 25%, #171a22 0 50%) 0 0 / 14px 14px; }
.asset-thumb img { max-width: 100%; max-height: 100%; object-fit: contain; }
.asset-thumb.pixel img { image-rendering: pixelated; }
.asset-thumb.sound { cursor: pointer; color: var(--accent); background: var(--bg-2); }
.asset-thumb.sound:hover { border-color: var(--accent); }
.asset-body { min-width: 0; flex: 1; }
.asset-name { font-weight: 600; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.asset-meta { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; font-variant-numeric: tabular-nums; }
.asset-opts { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; margin-top: 8px; }
.asset-opts label { display: flex; gap: 6px; align-items: center; color: var(--muted); font-size: 12px; }
.asset-opts .input { width: 58px; height: 26px; padding: 0 6px; }
.asset-opts .check { cursor: pointer; }
.slot-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 8px 14px; margin-top: 6px; }
.slot { display: grid; grid-template-columns: 112px minmax(0, 1fr); gap: 8px; align-items: center; font-size: 12.5px; color: var(--muted); }
.slot .select { height: 28px; }
.trace { font-size: 12.5px; color: var(--muted); max-height: 150px; overflow: auto; }
.trace div { padding: 3px 0; border-bottom: 1px solid var(--line); }
.trace .ok { color: var(--good); }
.trace .no { color: var(--bad); }

.statusbar { grid-area: status; display: flex; align-items: center; gap: 14px; padding: 0 6px; color: var(--muted); font-size: 12px; }
.statusbar .spacer { flex: 1; }
.statusbar .num { font-variant-numeric: tabular-nums; }
.status-pill { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.status-pill.good { color: var(--good); }
.status-pill.bad { color: var(--bad); }
.status-pill.warn { color: var(--warn); }

.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px; }
.card { display: flex; flex-direction: column; gap: 8px; padding: 10px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; cursor: pointer; text-align: left; color: inherit; }
.card:hover { border-color: var(--accent); transform: translateY(-1px); }
.card canvas { width: 100%; aspect-ratio: 16 / 9; border-radius: 8px; background: #07080c; display: block; }
.card strong { font-size: 14px; }
.card span { color: var(--muted); font-size: 12.5px; }
.publish-link { display: flex; gap: 8px; margin-top: 12px; }

@media (max-width: 1100px) {
  .studio { grid-template-columns: 230px minmax(0, 1fr) 290px; }
}

/* ---------- tiles ---------- */
.tool-row { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.tool-row .kbd { margin-left: 4px; }
.tile-layout { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 16px; align-items: start; }
.palette-wrap { overflow: auto; max-height: 100%; padding: 8px; background: repeating-conic-gradient(#20242f 0 25%, #171a22 0 50%) 0 0 / 14px 14px; border: 1px solid var(--line); border-radius: 10px; }
.palette { display: block; image-rendering: pixelated; cursor: pointer; max-width: none; }
.tile-opts { display: grid; gap: 10px; }
.tile-opts .two { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.f { display: grid; gap: 4px; color: var(--muted); font-size: 12px; }
.check-row { display: flex; gap: 8px; align-items: center; color: var(--text); font-size: 12.5px; cursor: pointer; }
.tile-setup { display: grid; gap: 10px; max-width: 360px; }
.tile-setup p { margin: 4px 0 0; }
.empty-tiles { display: grid; gap: 8px; justify-items: center; text-align: center; padding: 20px; color: var(--muted); max-width: 420px; margin: 0 auto; }
.empty-tiles strong { color: var(--text); font-size: 15px; }

/* ---------- animation clips ---------- */
.asset-cell { min-width: 0; display: grid; gap: 0; }
.asset-cell.wide { grid-column: 1 / -1; }
.asset-cell .asset { height: 100%; }
.asset-cell.wide .asset { border-bottom-left-radius: 0; border-bottom-right-radius: 0; }
.anim-editor { padding: 12px 14px 14px; background: var(--panel-2); border: 1px solid var(--line); border-top: 0; border-radius: 0 0 12px 12px; }
.anim-strip-wrap { margin-bottom: 10px; overflow-x: auto; }
.anim-body { display: grid; grid-template-columns: minmax(0, 1fr) 140px; gap: 16px; align-items: start; }
.anim-prev { position: sticky; top: 0; }
.anim-strip { display: block; max-width: 100%; image-rendering: pixelated; background: repeating-conic-gradient(#20242f 0 25%, #171a22 0 50%) 0 0 / 12px 12px; border: 1px solid var(--line); border-radius: 8px; }
.anim-prev { display: grid; justify-items: center; }
.anim-preview { width: 120px; height: 120px; display: block; image-rendering: pixelated; background: repeating-conic-gradient(#20242f 0 25%, #171a22 0 50%) 0 0 / 12px 12px; border: 1px solid var(--line); border-radius: 10px; }
.clip-head, .clip-row { display: grid; grid-template-columns: 22px minmax(120px, 1fr) 64px 64px 64px 40px; gap: 8px; align-items: center; }
.clip-head { color: var(--faint); font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; padding: 0 8px 4px; }
.clip-row { padding: 3px 8px; border-radius: 8px; border: 1px solid transparent; }
.clip-row.is-selected { background: var(--accent-soft); border-color: rgba(124, 108, 255, 0.45); }
.clip-row.is-off .clip-name { color: var(--muted); }
.clip-row .input { height: 26px; padding: 0 6px; }
.clip-row .dash { color: var(--faint); text-align: center; }
.clip-name { display: grid; text-align: left; background: none; border: 0; color: var(--text); cursor: pointer; font-weight: 600; padding: 0; }
.clip-name span { color: var(--muted); font-weight: 400; font-size: 11.5px; }

/* ---------- phones ---------- */
.only-mobile, .mobile-nav, .fab, .sel-bar, .tile-strip { display: none; }

@media (max-width: 640px), (max-width: 860px) and (pointer: coarse) {
  html, body { overscroll-behavior: none; }
  .studio { height: 100dvh; display: flex; flex-direction: column; gap: 0; padding: 0; background: var(--bg); }
  .desktop-only { display: none !important; }
  .only-mobile { display: inline-flex; }

  .topbar { display: flex; flex: none; height: calc(54px + env(safe-area-inset-top)); padding: env(safe-area-inset-top) 8px 0; gap: 6px; border-bottom: 1px solid var(--line); background: var(--panel); }
  .topbar .group { gap: 6px; }
  .topbar .group:first-child { flex: 1; min-width: 0; }
  .topbar .group.right { flex: none; }
  .topbar .label { display: none; }
  .project-name { width: auto; flex: 1; min-width: 0; margin-left: 4px; font-size: 16px; height: 40px; }
  .transport { padding: 2px; gap: 2px; }
  .topbar .btn, .viewbar .btn { min-height: 40px; }
  .topbar .btn-icon, .topbar .btn:not(.btn-ghost), .viewbar .btn-icon { min-width: 40px; justify-content: center; padding: 0 10px; }

  .area-left, .area-center, .area-right, .area-dock { display: none; flex: 1; min-height: 0; margin: 0; border-radius: 0; border-left: 0; border-right: 0; border-top: 0; }
  .studio[data-tab='scene'] .area-center { display: flex; }
  .studio[data-tab='objects'] .area-left { display: flex; }
  .studio[data-tab='inspect'] .area-right { display: flex; }
  .studio[data-tab='tools'] .area-dock { display: flex; }
  .statusbar { display: none; }

  .mobile-nav { display: flex; flex: none; border-top: 1px solid var(--line); background: var(--panel); padding-bottom: env(safe-area-inset-bottom); }
  .nav-btn { flex: 1; display: grid; justify-items: center; gap: 3px; padding: 9px 0 7px; background: none; border: 0; border-top: 2px solid transparent; color: var(--muted); font: 600 11px/1 Inter, system-ui, sans-serif; cursor: pointer; }
  .nav-btn[aria-selected='true'] { color: var(--text); border-top-color: var(--accent); }

  .viewbar { height: 50px; padding: 0 6px; gap: 4px; overflow-x: auto; scrollbar-width: none; }
  .viewbar .zoom-label, .viewbar .spacer { display: none; }
  .viewbar::after { content: ''; flex: 1; }
  .viewtab { height: 34px; padding: 0 14px; }
  .stage-note { display: none; }

  .fab { display: grid; place-items: center; position: absolute; right: 14px; top: 14px; width: 52px; height: 52px; border-radius: 50%; border: 0; color: #fff; background: var(--grad); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5); z-index: 5; cursor: pointer; }
  .sel-bar, .tile-strip { display: flex; align-items: center; gap: 8px; position: absolute; left: 10px; right: 10px; bottom: 10px; padding: 8px 10px; background: rgba(20, 22, 29, 0.95); border: 1px solid var(--line-2); border-radius: 14px; backdrop-filter: blur(8px); z-index: 5; }
  .sel-bar .grow { flex: 1; }
  .tile-strip { justify-content: center; }
  .fab[hidden], .sel-bar[hidden], .tile-strip[hidden] { display: none; }
  .sel-bar .btn, .tile-strip .btn { min-height: 40px; }
  .sel-bar .btn-icon, .tile-strip .btn-icon { min-width: 40px; justify-content: center; }

  .tabs { overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; }
  .tab { flex: none; min-height: 46px; }
  .dock-pane { padding: 12px; }
  .ai-grid, .tile-layout, .anim-body { grid-template-columns: 1fr; }
  .asset-grid { grid-template-columns: 1fr; }
  .slot-grid { grid-template-columns: 1fr; }
  .clip-head, .clip-row { grid-template-columns: 22px minmax(70px, 1fr) 50px 50px 50px 30px; gap: 6px; }
  .clip-name span { display: none; }
  .anim-prev { position: static; justify-items: start; }
  .bar-row { grid-template-columns: 62px minmax(0, 1fr) 42px; }
  .bar-row > :nth-child(4) { display: none; }

  .tree-row { height: 46px; }
  .tree-actions { display: flex; }
  .tree-row:hover .tree-sub, .tree-row.is-selected .tree-sub { display: inline; }
  .panel-head { min-height: 48px; }
  .field { grid-template-columns: 1fr; gap: 4px; }
  .field-row { gap: 8px; }
  .behavior { padding: 10px 0; }
  .behavior input[type='checkbox'], .check-row input, .asset-opts input[type='checkbox'] { width: 20px; height: 20px; }

  dialog { width: calc(100vw - 20px); max-width: none; max-height: 90dvh; }
  .gallery { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .menu { max-width: calc(100vw - 16px); }
  .menu-item { min-height: 46px; }
  .toasts { bottom: calc(76px + env(safe-area-inset-bottom)); }
}

/* ---------- pixel painter ---------- */
body.painting { overflow: hidden; }
.paint { position: fixed; inset: 0; z-index: 200; display: flex; flex-direction: column; background: var(--bg); color: var(--text); padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); }
.paint-top { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-bottom: 1px solid var(--line); background: var(--panel); }
.paint-top .grow { flex: 1; }
.paint-top .btn { min-height: 40px; }
.paint-top .btn-icon { min-width: 40px; justify-content: center; }
.paint-name { flex: 1; min-width: 80px; max-width: 280px; height: 40px; padding: 0 10px; font-size: 16px; font-weight: 600; background: transparent; border: 1px solid transparent; border-radius: 8px; }
.paint-name:hover, .paint-name:focus { border-color: var(--line-2); background: var(--panel-2); outline: none; }
.paint-stage { position: relative; flex: 1; min-height: 0; overflow: hidden; touch-action: none; background: #0b0c11; cursor: crosshair; user-select: none; -webkit-user-select: none; }
.paint-board { position: absolute; background: repeating-conic-gradient(#2a2e3b 0 25%, #1d202a 0 50%) 0 0 / 16px 16px; box-shadow: 0 0 0 1px var(--line-2), 0 16px 50px rgba(0, 0, 0, 0.5); }
.paint-view { position: absolute; inset: 0; width: 100%; height: 100%; image-rendering: pixelated; }
.paint-grid { position: absolute; inset: 0; pointer-events: none; background-image: linear-gradient(to right, rgba(255, 255, 255, 0.16) 1px, transparent 1px), linear-gradient(to bottom, rgba(255, 255, 255, 0.16) 1px, transparent 1px); }
.paint-status { position: absolute; left: 10px; bottom: 8px; padding: 4px 9px; border-radius: 8px; background: rgba(10, 12, 18, 0.78); color: var(--muted); font-size: 12px; pointer-events: none; font-variant-numeric: tabular-nums; }
.paint-tools { display: flex; gap: 4px; padding: 8px; overflow-x: auto; border-top: 1px solid var(--line); background: var(--panel); scrollbar-width: none; }
.paint-tools .tool { flex: none; width: 46px; height: 46px; justify-content: center; padding: 0; }
.tool-sep { flex: none; width: 1px; margin: 4px 6px; background: var(--line-2); }
.paint-colors { display: flex; gap: 8px; align-items: center; padding: 8px; background: var(--panel); border-top: 1px solid var(--line); }
.swatch-current { flex: none; width: 48px; height: 48px; padding: 0; border: 2px solid var(--line-2); border-radius: 12px; background: none; cursor: pointer; }
.paint-palette { display: flex; gap: 6px; flex: 1; overflow-x: auto; padding: 4px 2px; scrollbar-width: none; }
.swatch { flex: none; width: 38px; height: 38px; border-radius: 9px; border: 2px solid rgba(255, 255, 255, 0.25); cursor: pointer; }
.swatch.is-on { outline: 3px solid var(--accent); outline-offset: 1px; }
.paint-framebar { display: flex; gap: 10px; align-items: center; padding: 8px; background: var(--panel); border-top: 1px solid var(--line); }
.paint-frames { display: flex; gap: 6px; flex: 1; align-items: center; overflow-x: auto; padding: 3px 2px; scrollbar-width: none; }
.frame { flex: none; position: relative; width: 50px; height: 50px; padding: 0; display: grid; place-items: center; border-radius: 9px; border: 2px solid var(--line-2); background: repeating-conic-gradient(#2a2e3b 0 25%, #1d202a 0 50%) 0 0 / 8px 8px; color: var(--text); cursor: pointer; }
.frame canvas { width: 100%; height: 100%; image-rendering: pixelated; object-fit: contain; }
.frame i { position: absolute; right: 3px; bottom: 1px; font: 700 10px/1 Inter, system-ui, sans-serif; font-style: normal; color: #fff; text-shadow: 0 0 3px #000; }
.frame.is-on { border-color: var(--accent); }
.frame.add { background: var(--panel-2); border-style: dashed; }
.frame:disabled { opacity: 0.35; cursor: default; }
.flipx svg { transform: scaleX(-1); }
.frame-tools { flex: none; display: grid; justify-items: center; gap: 4px; }
.paint-preview { width: 56px; height: 56px; image-rendering: pixelated; border-radius: 8px; border: 1px solid var(--line-2); background: repeating-conic-gradient(#2a2e3b 0 25%, #1d202a 0 50%) 0 0 / 8px 8px; }
.fps { display: flex; align-items: center; gap: 4px; color: var(--muted); font-size: 12px; }
.fps .input { width: 54px; height: 28px; padding: 0 6px; }
.paint-choose { position: absolute; inset: 0; z-index: 2; display: flex; flex-direction: column; overflow: auto; background: var(--bg); }
.preset-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; padding: 16px; }
.preset { display: grid; gap: 4px; padding: 14px; text-align: left; color: inherit; background: var(--panel-2); border: 1px solid var(--line); border-radius: 14px; cursor: pointer; }
.preset:hover, .preset:active { border-color: var(--accent); }
.preset strong { font-size: 15px; }
.preset span { color: var(--muted); font-size: 12.5px; }
.custom-size { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px; padding: 0 16px 12px; }
.custom-size strong { width: 100%; }
.custom-size label { display: grid; gap: 4px; color: var(--muted); font-size: 12px; }
.custom-size .input { width: 84px; }
@media (max-width: 640px), (max-width: 860px) and (pointer: coarse) {
  .paint-tools .tool { width: 48px; height: 48px; }
  .frame { width: 52px; height: 52px; }
}

.add-row { margin-bottom: 10px; }
.draw-btn { width: 100%; height: 44px; justify-content: center; font-size: 14px; }

/* ---------- hosted AI ---------- */
.ai-seg { margin-bottom: 8px; width: fit-content; }
.ai-source-line { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 8px; color: var(--muted); font-size: 12.5px; }
.ai-source-line .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--faint); flex: none; }
.ai-source-line .dot.on { background: var(--good); box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.2); }
.ai-source-line .dot.off { background: var(--warn); }
.own-box[hidden] { display: none; }

.seg { display: flex; gap: 2px; padding: 3px; background: var(--panel); border: 1px solid var(--line); border-radius: 9px; }
.seg button { height: 30px; padding: 0 12px; border: 0; border-radius: 6px; background: none; color: var(--muted); cursor: pointer; font-weight: 500; }
.seg button[aria-pressed="true"] { background: var(--panel-3); color: var(--text); }
@media (max-width: 640px), (max-width: 860px) and (pointer: coarse) { .seg button { height: 38px; } }

/* A narrow desktop window keeps the real editor, just tighter: smaller side panels and icon-only top bar buttons. */
@media (min-width: 641px) and (max-width: 1100px) {
  .studio { --dock-h: 320px; grid-template-columns: 212px minmax(0, 1fr) 270px; grid-template-rows: 54px minmax(0, 1fr) var(--dock-h) 28px; }
  .project-name { width: 130px; }
  .topbar { gap: 6px; }
  .topbar .desktop-only .label, .topbar .group.right .label { display: none; }
  .topbar .btn-ghost.desktop-only { padding: 0 8px; }
}

/* =============================================================================
   STUDIO CHROME POLISH
   ============================================================================= */

/* Richer body gradient — deeper purple/blue radials */
.studio {
  background:
    radial-gradient(ellipse 55% 45% at 18% -8%, rgba(124, 108, 255, 0.13), transparent 60%),
    radial-gradient(ellipse 55% 45% at 82% -8%, rgba(59, 130, 246, 0.10), transparent 60%),
    radial-gradient(ellipse 35% 35% at 50% 108%, rgba(168, 85, 247, 0.07), transparent 55%),
    var(--bg) !important;
}

/* Stage: subtle spotlight from above */
.stage::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse 70% 45% at 50% 0%, rgba(124, 108, 255, 0.07), transparent 55%);
  pointer-events: none;
  z-index: 1;
}

/* Better logo — gradient icon mark + tighter lettering */
.logo {
  gap: 8px !important;
  font-weight: 800 !important;
  letter-spacing: -0.015em;
  text-decoration: none;
  color: var(--text) !important;
}
.logo-mark {
  background: linear-gradient(135deg, #7c6cff, #a855f7);
  border-radius: 8px;
  padding: 4px;
  color: #fff !important;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 10px rgba(124, 108, 255, 0.4);
}

/* Transport Play button — green pulse when available */
.transport .btn.btn-play {
  background: linear-gradient(135deg, #22c55e, #16a34a) !important;
  color: #fff !important;
  animation: play-pulse 2.8s ease-out infinite;
  box-shadow: 0 2px 10px rgba(34, 197, 94, 0.3);
}
@keyframes play-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.45); }
  70%  { box-shadow: 0 0 0 9px rgba(34, 197, 94, 0); }
  100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}
.transport .btn.btn-play:disabled { animation: none; opacity: 0.4; }


/* =============================================================================
   LAUNCHPAD  — full-screen first-run / home screen
   ============================================================================= */

.launchpad {
  position: fixed;
  inset: 0;
  z-index: 900;
  opacity: 0;
  transform: scale(0.985);
  transition: opacity 0.26s cubic-bezier(.4,0,.2,1), transform 0.26s cubic-bezier(.4,0,.2,1);
  overflow: hidden;
  font-family: inherit;
  /* Opaque base blocks all studio content — game canvas renders on top of this */
  background: #06070f;
}

/* ── Background ── */
.lp-bg {
  position: absolute;
  inset: 0;
  overflow: hidden;
}
.lp-bg-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}
.lp-bg-veil {
  position: absolute;
  inset: 0;
  /* Cinematic dark veil: game canvas shows through, text reads clearly on the content above.
     Studio is blocked by the launchpad's own opaque background — this veil only darkens the game. */
  background:
    radial-gradient(ellipse 100% 65% at 50% 100%, rgba(6, 7, 18, 0.95) 0%, transparent 60%),
    linear-gradient(to bottom,
      rgba(6, 7, 18, 0.60) 0%,
      rgba(6, 7, 18, 0.20) 25%,
      rgba(6, 7, 18, 0.20) 65%,
      rgba(6, 7, 18, 0.90) 100%);
}

/* ── Scroll container ── */
.lp-scroll {
  position: relative;
  z-index: 1;
  height: 100%;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 52px 24px 72px;
  scrollbar-width: none;
}
.lp-scroll::-webkit-scrollbar { display: none; }

/* ── Main glass panel ── */
.lp-panel {
  width: min(640px, 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  text-align: center;
}

/* ── Logo row ── */
.lp-logo-row {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: rgba(255, 255, 255, 0.45);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-size: 11px;
  font-weight: 700;
}
.lp-logo-row .ico { opacity: 0.6; }
.lp-brand {
  background: linear-gradient(90deg, #c4b5fd, #818cf8);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* ── Headline ── */
.lp-headline {
  margin: 0;
  font-size: clamp(38px, 6vw, 70px);
  font-weight: 900;
  letter-spacing: -0.03em;
  line-height: 1.07;
  color: #fff;
}
.lp-hl-accent {
  background: linear-gradient(135deg, #a78bfa 0%, #60a5fa 50%, #c084fc 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* ── Subline ── */
.lp-sub {
  margin: 0;
  font-size: 16px;
  color: rgba(255, 255, 255, 0.46);
  line-height: 1.55;
}

/* ── Prompt ring (animated gradient border) ── */
.lp-prompt-ring {
  width: 100%;
  position: relative;
  border-radius: 18px;
  padding: 2px;
  background: linear-gradient(135deg, #7c6cff, #38bdf8, #a855f7, #7c6cff);
  background-size: 300% 300%;
  animation: lp-ring-shift 5s ease infinite;
  box-shadow:
    0 0 28px rgba(124, 108, 255, 0.40),
    0 0 80px rgba(124, 108, 255, 0.12);
}
@keyframes lp-ring-shift {
  0%   { background-position: 0% 50%; }
  50%  { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}
.lp-prompt-ring:focus-within {
  box-shadow:
    0 0 36px rgba(124, 108, 255, 0.60),
    0 0 100px rgba(124, 108, 255, 0.20);
}

.lp-prompt {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  background: rgba(7, 9, 20, 0.94);
  backdrop-filter: blur(24px) saturate(1.4);
  border-radius: 16px;
  border: 1px solid rgba(124, 108, 255, 0.20);
}
.lp-prompt > .ico { flex: none; color: rgba(167, 139, 250, 0.65); }

.lp-input {
  flex: 1;
  background: none;
  border: 0;
  outline: none;
  font-size: 16px;
  color: #fff;
  caret-color: #a78bfa;
  min-width: 0;
  font-family: inherit;
}
.lp-input::placeholder { color: rgba(255, 255, 255, 0.28); }

/* ── Create-with-AI button ── */
.lp-btn-primary {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 36px;
  padding: 0 18px;
  border-radius: 10px;
  border: 0;
  font-weight: 700;
  font-size: 13.5px;
  cursor: pointer;
  color: #fff;
  background: linear-gradient(135deg, #7c6cff 0%, #a855f7 100%);
  box-shadow: 0 2px 14px rgba(124, 108, 255, 0.50);
  transition: box-shadow 0.15s, opacity 0.15s;
  white-space: nowrap;
  font-family: inherit;
}
.lp-btn-primary:hover:not(:disabled) { box-shadow: 0 2px 28px rgba(124, 108, 255, 0.80); }
.lp-btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── AI status line ── */
.lp-ai-status {
  min-height: 1.5em;
  font-size: 13px;
  color: rgba(167, 139, 250, 0.70);
  text-align: center;
}
.lp-ai-status--warn { color: rgba(251, 191, 36, 0.80); }

/* ── Action tiles ── */
.lp-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}
.lp-action {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.10);
  background: rgba(255, 255, 255, 0.055);
  backdrop-filter: blur(14px);
  color: rgba(255, 255, 255, 0.78);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.15s;
  font-family: inherit;
}
.lp-action:hover {
  background: rgba(124, 108, 255, 0.18);
  border-color: rgba(124, 108, 255, 0.55);
  transform: translateY(-2px);
}
.lp-action > .ico { opacity: 0.75; }

/* ── World section ── */
.lp-world-section {
  width: 100%;
  max-width: 1100px;
  margin-top: 44px;
  align-self: flex-start;
}
.lp-section-label {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.28);
  margin-bottom: 14px;
  padding: 0 4px;
}

/* ── Cards row ── */
.lp-cards {
  display: flex;
  gap: 16px;
  overflow-x: auto;
  padding: 4px 4px 20px;
  scrollbar-width: thin;
  scrollbar-color: rgba(124, 108, 255, 0.28) transparent;
}
.lp-cards::-webkit-scrollbar { height: 5px; }
.lp-cards::-webkit-scrollbar-track { background: transparent; }
.lp-cards::-webkit-scrollbar-thumb { background: rgba(124, 108, 255, 0.28); border-radius: 3px; }

.lp-card {
  flex: none;
  width: 230px;
  display: flex;
  flex-direction: column;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(10, 11, 24, 0.75);
  backdrop-filter: blur(10px);
  cursor: pointer;
  color: inherit;
  text-align: left;
  transition: border-color 0.2s, transform 0.2s, box-shadow 0.2s;
}
.lp-card:hover {
  border-color: rgba(124, 108, 255, 0.60);
  transform: translateY(-4px) scale(1.015);
  box-shadow:
    0 14px 48px rgba(124, 108, 255, 0.28),
    0 2px 8px rgba(0, 0, 0, 0.5);
}

.lp-card-canvas {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #060810;
}
.lp-card-info {
  padding: 10px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.lp-card-info strong { font-size: 13px; color: #fff; font-weight: 700; }
.lp-card-info span { font-size: 11.5px; color: rgba(255, 255, 255, 0.38); }

/* ── Esc hint ── */
.lp-esc-hint {
  margin-top: 24px;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.18);
}

/* ── Phone: strip world cards, opaque veil (game too small to appreciate), tighten layout ── */
@media (max-width: 640px), (max-width: 860px) and (pointer: coarse) {
  .lp-world-section { display: none; }
  .lp-panel { gap: 14px; }
  .lp-headline { font-size: clamp(28px, 9vw, 42px); }
  .lp-sub { font-size: 14px; }
  .lp-prompt { padding: 12px 14px; }
  .lp-input { font-size: 15px; }
  .lp-btn-primary { padding: 0 14px; font-size: 13px; }
  .lp-actions { gap: 8px; }
  .lp-action { padding: 10px 14px; font-size: 13px; }
  .lp-scroll { padding: 36px 16px 60px; }
  /* On phone the game background is too small to look cinematic; use a solid veil instead
     so studio panels don't show through — keep a subtle purple radial for depth */
  .lp-bg-canvas { opacity: 0.12; }
  .lp-bg-veil {
    background:
      radial-gradient(ellipse 100% 55% at 20% 0%, rgba(90, 50, 200, 0.35), transparent 60%),
      radial-gradient(ellipse 80% 50% at 85% 90%, rgba(40, 60, 180, 0.25), transparent 55%),
      rgba(6, 7, 18, 0.96);
  }
}

/* ═══════════════════════════════════════════════════════════════════
   Electron desktop app — titlebar drag regions & window controls
   ═══════════════════════════════════════════════════════════════════ */

/* Entire topbar becomes the native drag region */
html[data-electron] .topbar {
  -webkit-app-region: drag;
}

/* All interactive elements inside the topbar must opt out of dragging */
html[data-electron] .topbar button,
html[data-electron] .topbar input,
html[data-electron] .topbar a,
html[data-electron] .topbar [role="button"],
html[data-electron] .topbar .menu-popup {
  -webkit-app-region: no-drag;
}

/* macOS: shift the left group right to clear the native traffic lights (at x=16) */
html[data-electron][data-platform="darwin"] .topbar .group:first-child {
  padding-left: 76px;
}

/* Windows / Linux custom window control buttons */
.electron-wc {
  display: none;
  align-items: stretch;
  flex-shrink: 0;
  -webkit-app-region: no-drag;
}

html[data-electron]:not([data-platform="darwin"]) .electron-wc {
  display: flex;
}

.electron-wc__btn {
  width: 46px;
  height: 100%;
  border: none;
  background: transparent;
  color: rgba(255 255 255 / 0.5);
  cursor: default;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border-radius: 0;
  flex-shrink: 0;
  transition: background 100ms, color 100ms;
}

.electron-wc__btn:hover {
  background: rgba(255 255 255 / 0.1);
  color: rgba(255 255 255 / 0.9);
}

.electron-wc__btn:active {
  background: rgba(255 255 255 / 0.06);
}

.electron-wc__btn--close:hover {
  background: #e81123;
  color: #fff;
}

.electron-wc__btn--close:active {
  background: #c01020;
}

.electron-wc__btn svg {
  width: 10px;
  height: 10px;
  overflow: visible;
  pointer-events: none;
}

/* ═══════════════════════════════════════════════════════════════════
   Rule Graph — node-based rule editor
   ═══════════════════════════════════════════════════════════════════ */

.rg-panel {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  padding: 0 !important;
  gap: 0 !important;
}

.rg-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  border-bottom: 1px solid rgba(255,255,255,0.07);
  flex-shrink: 0;
}

.rg-toolbar-sep {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.3);
  margin-left: 8px;
  margin-right: 2px;
  padding-left: 8px;
  border-left: 1px solid rgba(255,255,255,0.1);
}
.rg-toolbar-sep:first-child { border-left: none; margin-left: 0; padding-left: 0; }

.rg-node--action .rg-node-title { font-style: italic; }

.rg-add-btn {
  border: 1px solid color-mix(in srgb, var(--rg-add-color) 50%, transparent) !important;
  color: var(--rg-add-color) !important;
  font-size: 11px !important;
  padding: 2px 10px !important;
}
.rg-add-btn:hover {
  background: color-mix(in srgb, var(--rg-add-color) 12%, transparent) !important;
  border-color: var(--rg-add-color) !important;
}

.rg-workspace {
  flex: 1;
  position: relative;
  overflow: hidden;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  min-height: 0;
}
.rg-workspace:active { cursor: grabbing; }

.rg-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  display: block;
}

.rg-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: visible;
}

.rg-content {
  position: absolute;
  inset: 0;
  transform-origin: 0 0;
}

.rg-nodes {
  position: absolute;
  inset: 0;
}

/* ── Edges ── */
.rg-edge {
  fill: none;
  stroke-width: 2.5;
  stroke-linecap: round;
  opacity: 0.85;
  cursor: pointer;
  pointer-events: stroke;
  transition: stroke-width 0.1s, opacity 0.1s;
}
.rg-edge:hover { opacity: 1; stroke-width: 4; }

.rg-edge-preview {
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-dasharray: 7 5;
  opacity: 0.6;
  pointer-events: none;
  animation: rg-dash 0.6s linear infinite;
}
@keyframes rg-dash { to { stroke-dashoffset: -24; } }

/* ── Nodes ── */
.rg-node {
  position: absolute;
  width: 230px;
  background: rgba(16, 18, 36, 0.97);
  border: 1.5px solid var(--nc, #666);
  border-radius: 10px;
  box-shadow: 0 6px 28px rgba(0,0,0,0.55);
  cursor: default;
  transition: box-shadow 0.15s;
  backdrop-filter: blur(4px);
}
.rg-node:hover {
  box-shadow: 0 6px 32px rgba(0,0,0,0.6), 0 0 22px -6px var(--nc, #666);
  z-index: 10;
}

.rg-node-hd {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px 7px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  cursor: move;
  border-radius: 9px 9px 0 0;
  background: color-mix(in srgb, var(--nc) 8%, transparent);
}

.rg-node-title {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--nc, #ccc);
  flex: 1;
}

.rg-node-del {
  width: 18px;
  height: 18px;
  border: none;
  background: transparent;
  color: rgba(255,255,255,0.25);
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  padding: 0;
  flex-shrink: 0;
}
.rg-node-del:hover { background: rgba(255,255,255,0.09); color: rgba(255,255,255,0.75); }

.rg-node-body {
  padding: 9px 10px 11px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.rg-row {
  display: flex;
  align-items: center;
  gap: 5px;
}

.rg-lbl {
  font-size: 10px;
  color: rgba(255,255,255,0.35);
  min-width: 46px;
  flex-shrink: 0;
}

.rg-sel {
  flex: 1;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 5px;
  color: rgba(255,255,255,0.82);
  font-size: 11px;
  padding: 3px 5px;
  min-width: 0;
  outline: none;
}
.rg-sel:focus { border-color: var(--nc, rgba(255,255,255,0.3)); }

.rg-num {
  flex: 1;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 5px;
  color: rgba(255,255,255,0.82);
  font-size: 11px;
  padding: 3px 5px;
  min-width: 0;
  width: 70px;
  outline: none;
}
.rg-num:focus { border-color: var(--nc, rgba(255,255,255,0.3)); }

.rg-hint {
  font-size: 10px;
  color: rgba(255,255,255,0.3);
  font-style: italic;
  text-align: center;
  padding: 4px 0;
}

/* ── Ports ── */
.rg-port {
  position: absolute;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--nc, #888);
  border: 2.5px solid rgba(16, 18, 36, 0.97);
  top: 50%;
  transform: translateY(-50%);
  cursor: crosshair;
  transition: transform 0.1s, box-shadow 0.1s;
  z-index: 5;
}
.rg-port--out { right: -8px; }
.rg-port--in  { left: -8px; }

.rg-port:hover,
.rg-port--hover {
  transform: translateY(-50%) scale(1.5);
  box-shadow: 0 0 10px var(--nc, #888);
}

/* ── Footer ── */
.rg-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-top: 1px solid rgba(255,255,255,0.07);
  flex-shrink: 0;
}

/* ── Dock resize handle ── */
.dock-resizer {
  flex: none;
  height: 6px;
  cursor: ns-resize;
  position: relative;
  user-select: none;
  touch-action: none;
}
.dock-resizer:hover::after,
.dock-resizer.is-dragging::after {
  content: '';
  position: absolute;
  left: 10%; right: 10%;
  top: 50%; transform: translateY(-50%);
  height: 2px;
  border-radius: 2px;
  background: var(--accent);
  opacity: 0.7;
  transition: opacity 0.1s;
}

/* ── Command palette ── */
.cp-overlay {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 80px;
  z-index: 10000;
}
.cp-modal {
  width: 540px;
  max-width: calc(100vw - 32px);
  background: var(--panel-3, #1a1d2e);
  border: 1px solid var(--line-2, rgba(255,255,255,0.12));
  border-radius: 14px;
  box-shadow: 0 24px 72px rgba(0,0,0,0.65);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.cp-input {
  display: block;
  width: 100%;
  box-sizing: border-box;
  padding: 14px 16px;
  background: none;
  border: none;
  border-bottom: 1px solid var(--line, rgba(255,255,255,0.08));
  color: var(--text, #e8eaf4);
  font-size: 15px;
  font-family: inherit;
  outline: none;
}
.cp-input::placeholder { color: var(--faint, rgba(255,255,255,0.3)); }
.cp-list {
  max-height: 360px;
  overflow-y: auto;
  padding: 6px;
}
.cp-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text, #e8eaf4);
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font-size: 13.5px;
  font-family: inherit;
}
.cp-item:hover, .cp-item.is-active {
  background: var(--accent-soft, rgba(124,108,255,0.12));
}
.cp-item .cp-keys {
  margin-left: auto;
  color: var(--faint, rgba(255,255,255,0.3));
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
  background: var(--bg-2, #12141f);
  border: 1px solid var(--line, rgba(255,255,255,0.08));
  border-radius: 5px;
  padding: 2px 6px;
}
.cp-empty {
  padding: 20px 16px;
  color: var(--muted, rgba(255,255,255,0.45));
  font-size: 13.5px;
  text-align: center;
}

/* ============================================================
   iPHONE 18 PRO — HIGH PERFORMANCE MOBILE POLISH
   ============================================================ */

/* Full-bleed play mode: canvas fills the whole safe-area viewport.
   On iPhone 18 Pro this is 393×852 CSS px (or 430×932 for the larger model). */
@media (max-width: 640px), (max-width: 860px) and (pointer: coarse) {

  /* During play the game canvas should fill the entire screen, with touch controls overlaid. */
  .studio[data-mode='play'] .area-center { position: fixed; inset: 0; z-index: 50; background: #000; border-radius: 0; }
  .studio[data-mode='play'] .stage { background: #000; }

  /* Stop button floats in top-right corner during play so the thumb can reach it. */
  .studio[data-mode='play'] .topbar { position: fixed; top: 0; left: 0; right: 0; z-index: 51; background: rgba(10,11,15,0.72); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); height: calc(44px + env(safe-area-inset-top)); }

  /* Play canvas: crisp pixel rendering for 2D pixel art, ProMotion 120Hz via CSS content-visibility. */
  #playCanvas {
    image-rendering: -webkit-optimize-contrast; /* Safari/iOS: crisp edges */
    image-rendering: pixelated;
  }

  /* Scene canvas: disable default iOS tap highlight and callout. */
  #sceneCanvas {
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
  }

  /* Nav buttons: larger hit area for iPhone — Apple HIG recommends 44×44pt minimum. */
  .nav-btn { min-height: 52px; padding: 10px 0 8px; gap: 4px; }

  /* Transport: larger tap targets when on mobile. */
  .transport .btn { min-height: 44px; min-width: 44px; padding: 0 12px; }

  /* FAB: bring to 56px for comfortable one-thumb reach on Pro models. */
  .fab { width: 56px; height: 56px; right: 16px; bottom: calc(72px + env(safe-area-inset-bottom)); }

  /* Selection bar: raise above the bottom nav. */
  .sel-bar, .tile-strip { bottom: calc(66px + env(safe-area-inset-bottom)); }

  /* Toasts: raise above nav + safe area. */
  .toasts { bottom: calc(80px + env(safe-area-inset-bottom)) !important; }

  /* Viewbar: hide zoom label to save space, keep the essential buttons. */
  .viewbar .zoom-label { display: none; }

  /* Dialogs: full-width on small phone screens with no side overflow. */
  dialog { border-radius: 20px 20px 0 0; position: fixed; bottom: 0; left: 0; right: 0; top: auto; width: 100%; max-width: 100%; margin: 0; border: none; }
}

/* Landscape phone: a slim horizontal layout so the canvas gets maximum height. */
@media (max-width: 860px) and (pointer: coarse) and (orientation: landscape) {
  .studio { flex-direction: row; }
  .topbar { width: calc(44px + env(safe-area-inset-left)); height: 100dvh; flex-direction: column; padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom); }
  .mobile-nav { flex-direction: column; width: calc(52px + env(safe-area-inset-right)); height: 100dvh; border-top: none; border-left: 1px solid var(--line); padding-right: env(safe-area-inset-right); }
  .nav-btn { flex: 1; }
  /* In landscape the canvas uses the full height so the game is wider. */
  .area-center { flex: 1; min-width: 0; }
}

/* ProMotion adaptive frame rate hint: tell the browser this element changes every frame
   so it can schedule at 120 Hz on ProMotion displays. */
@supports (animation-duration: 0.001s) {
  #playCanvas, #sceneCanvas { will-change: contents; }
}
