:root {
  color-scheme: light dark;
  --ink: light-dark(#111, #ededed);
  --muted: light-dark(#8c8c8c, #9a9a9a);
  --soft-ink: light-dark(#595959, #a8a8a8);
  --quiet: light-dark(#999, #7a7a7a);
  --faint: light-dark(#b3b3b3, #676767);
  --line: light-dark(#e4e4e4, #2d2d2d);
  --soft: light-dark(#f5f5f5, #1e1e1e);
  --panel: light-dark(#fff, rgba(22, 22, 22, .96));
  --paper: light-dark(#fff, #111);
  --hairline: light-dark(#ececec, #2a2a2a);
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --radius-control: 6px;
  --radius-panel: 12px;
  font-family: Inter, 'Helvetica Neue', Helvetica, Arial, 'PingFang SC', 'Microsoft YaHei', sans-serif;
  font-synthesis: none;
  background: var(--paper);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }
* { box-sizing: border-box; }
body { margin: 0; overflow-x: hidden; font-size: 13px; display: flex; flex-direction: column; height: 100dvh; padding: 12px; }
button, a { -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: inherit; cursor: pointer; }
a { color: inherit; text-decoration: none; }
button { border: 0; background: none; padding: 0; }
button:disabled { cursor: default; opacity: .35; }
[hidden] { display: none !important; }
button:focus-visible, a:focus-visible, [tabindex]:focus-visible { outline: 2px solid var(--ink); outline-offset: 4px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.4; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
.workspace { position: relative; flex: 1; min-height: 0; border: 1px solid var(--line); border-radius: var(--radius-panel); display: flex; flex-direction: column; overflow: hidden; overflow: clip; background: var(--paper); }
.topbar { position: relative; z-index: 2; display: flex; justify-content: space-between; align-items: center; gap: var(--space-3); padding: var(--space-3); padding-left: 18px; padding-bottom: calc(var(--space-3) - 1px); min-height: 64px; flex-shrink: 0; background: var(--panel); border-bottom: 1px solid var(--line); }
.topbar-actions { display: flex; align-items: center; gap: var(--space-3); }
.header-prefs { display: flex; align-items: center; gap: var(--space-3); }
.wordmark { margin: 0 auto 0 0; font-size: 21px; font-weight: 500; letter-spacing: -.85px; white-space: nowrap; line-height: 1.2; }
.brand-dot { color: var(--ink); }
.button { min-height: 36px; padding: 0 var(--space-4); border-radius: var(--radius-control); display: inline-flex; align-items: center; justify-content: center; gap: var(--space-3); font-weight: 450; font-size: 12px; white-space: nowrap; transition: background 150ms, color 150ms, transform 150ms; }
.button svg { width: 16px; height: 16px; }
.button:active { transform: translateY(1px); }
.ghost { color: var(--ink); }
.primary { color: light-dark(#fff, #111); background: light-dark(#111, #ededed); }
.model-view { margin: 0; position: relative; flex: 1; min-height: 0; touch-action: none; outline-offset: -6px !important; }
.model-view:focus:not(:focus-visible) { outline: none !important; }
.model-view canvas { display: block; width: 100%; height: 100%; cursor: grab; touch-action: none; }
.model-view.is-dragging canvas { cursor: grabbing; }
.touch-hint { display: none; }
.theme-icon-sun { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-icon-sun { display: block; }
  :root:not([data-theme="light"]) .theme-icon-moon { display: none; }
}
:root[data-theme="dark"] .theme-icon-sun { display: block; }
:root[data-theme="dark"] .theme-icon-moon { display: none; }
.theme-caption { position: absolute; left: 16px; bottom: 16px; z-index: 2; pointer-events: none; display: flex; align-items: center; gap: var(--space-3); color: var(--muted); font-size: 11px; }
.mobile-project-row { display: none; }
.theme-contact { pointer-events: auto; color: var(--muted); text-decoration: none; transition: color 150ms; }
.theme-plate { display: inline-flex; align-items: center; padding: 5px 10px; border: 1px solid var(--line); border-radius: var(--radius-control); white-space: nowrap; }
.control-stack, .hardware-stack { position: absolute; top: 50%; transform: translateY(-50%); z-index: 3; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 6px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: none; }
.control-stack { right: 12px; height: 260px; justify-content: space-between; }
.hardware-stack { left: 12px; width: 44px; height: 260px; gap: 10px; padding: 0; background: none; border: 0; }
.hardware-island { display: flex; align-items: center; padding: 6px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }
.lid-island { flex: 1; flex-direction: column; min-height: 0; width: 44px; }
.hardware-stack > .stack-row { flex-shrink: 0; }
.stack-row { display: flex; flex-direction: column; gap: 4px; }
.stack-row .icon-button { width: 32px; height: 32px; border-radius: 4px; }
.stack-row .icon-button[aria-pressed="true"] { background: var(--soft); color: var(--ink); }
#power-toggle[aria-pressed="false"] { background: light-dark(#fff3df, #342c20); color: light-dark(#94703a, #d7b77e); }
#power-toggle[aria-pressed="true"] { background: light-dark(#edf7e9, #253124); color: light-dark(#5b7950, #a3c395); }
.stack-divider { height: 1px; width: 24px; margin: 3px 0; background: var(--line); }
.lid-module { position: relative; flex: 1; min-height: 0; width: 32px; overflow: hidden; border-radius: 4px; background: var(--panel); touch-action: none; user-select: none; }
.lid-fill { position: absolute; inset: auto 0 0; height: calc(16px + (100% - 16px) * var(--lid-progress)); border-radius: 4px; background: light-dark(#e9e9e9, #2b2b2b); pointer-events: none; }
.lid-handle-travel { z-index: 1; position: absolute; inset: 8px 0; pointer-events: none; }
.lid-handle { position: absolute; left: 6px; right: 6px; bottom: calc(100% * var(--lid-progress)); height: 3px; transform: translateY(50%); border-radius: 2px; background: var(--soft-ink); }
.lid-module:has(#lid-angle:active) .lid-handle { background: var(--ink); }
.lid-module:has(#lid-angle:focus-visible) { outline: 2px solid var(--soft-ink); outline-offset: 4px; }
.lid-module:has([aria-disabled="true"]) { opacity: .4; }
#lid-angle { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; outline: none !important; cursor: ns-resize; touch-action: none; }
.status-dot { width: 5px; height: 5px; border-radius: 50%; background: light-dark(#d9d9d9, #3d3d3d); transition: background 180ms; }
.status-dot.is-on { background: var(--ink); }
.version { color: var(--faint); margin-left: 5px; }
.view-actions { display: flex; align-items: center; gap: var(--space-1); }
.icon-button { display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: var(--radius-control); color: var(--soft-ink); transition: background 150ms, color 150ms; }
.icon-button[aria-expanded="true"] { background: var(--soft); color: var(--ink); }
.icon-button svg { width: 18px; height: 18px; }
.loading { position: absolute; inset: 0; display: flex; justify-content: center; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; }
.loading-dot { width: 5px; height: 5px; border-radius: 50%; background: var(--quiet); animation: breathe 1s ease-in-out infinite alternate; }
@keyframes breathe { to { opacity: .25; } }
.screen-fallback { position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 14px; text-align: center; padding: 20px; }
.fallback-screens { display: flex; flex-direction: column; gap: 10px; }
.fallback-screens img { max-width: 100%; width: min(210px, 38vh); height: auto; image-rendering: pixelated; }
.screen-fallback p { color: var(--muted); font-size: 12px; max-width: 300px; line-height: 1.7; }
.preview-message { position: absolute; left: 50%; bottom: 34px; transform: translateX(-50%); max-width: min(90%, 420px); width: max-content; background: var(--soft); border: 1px solid var(--line); padding: 10px var(--space-4); border-radius: 8px; color: var(--soft-ink); line-height: 1.7; font-size: 12px; text-align: center; pointer-events: none; }
/* The gamepad is an independent card below the viewport card. Opening it
   grows its grid row (0fr → 1fr), squeezing the model viewport smoothly. */
.key-dock { display: grid; grid-template-rows: 0fr; margin-top: 0; overflow: hidden; transition: grid-template-rows 280ms ease, margin-top 280ms ease; }
.key-dock.is-open { grid-template-rows: 1fr; margin-top: 12px; }
.key-panel { position: relative; overflow: hidden; min-height: 0; width: 100%; margin: 0; padding: 12px 20px 16px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-panel); transform: translateY(100%); transition: transform 280ms ease, padding-top 280ms ease, padding-bottom 280ms ease, border-top-width 280ms ease, border-bottom-width 280ms ease; }
.key-dock:not(.is-open) .key-panel { padding-top: 0; padding-bottom: 0; border-top-width: 0; border-bottom-width: 0; }
.key-dock.is-open .key-panel { transform: none; }
.shoulder-keys, .key-panel-body, .menu-keys { width: 100%; max-width: 352px; margin-left: auto; margin-right: auto; }
body:has(.key-dock.is-open) .theme-caption { visibility: hidden; }
/* Desktop: unroll the pad horizontally — L/R shoulders on the pad row's top
   corners, then d-pad, SELECT/START (sitting low) and ABXY along the line. */
@media (min-width: 601px) {
  .key-panel { display: flex; justify-content: center; padding: 30px 24px 20px; }
  .pad-row { position: relative; display: flex; align-items: center; gap: 48px; padding-top: 36px; }
  .shoulder-keys, .key-panel-body, .menu-keys { width: auto; max-width: none; margin: 0; }
  .shoulder-keys { position: absolute; top: -18px; left: -6px; right: -6px; }
  .shoulder-keys .key { width: 76px; height: 30px; }
  .pad-row > .key-panel-body { display: contents; }
  .dpad { order: 1; }
  .menu-keys { order: 2; flex-direction: column; gap: 8px; }
  .menu-keys .key { width: 80px; height: 28px; border-radius: 14px; }
  .face-keys { order: 3; }
  .menu-keys .key { width: 80px; height: 28px; border-radius: 14px; }
}
.key-panel-body { display: flex; justify-content: space-between; align-items: center; gap: 24px; padding-block: 12px; }
.key { display: grid; place-items: center; min-width: 0; min-height: 0; border: 1px solid var(--line); background: var(--soft); border-radius: 8px; font-size: 14px; color: var(--soft-ink); touch-action: manipulation; transition: background 100ms, transform 100ms; }
.key:active { background: light-dark(#d9d9d9, #444); transform: translateY(1px); }
.dpad { position: relative; display: grid; grid-template-columns: repeat(3, 40px); grid-template-rows: repeat(3, 40px); flex-shrink: 0; }
.dpad::before { content: ""; grid-area: 2 / 2; background: var(--soft); }
.dpad .key { border: 0; border-radius: 5px; font-size: 16px; }
.key-up { grid-area: 1 / 2; border-radius: 8px 8px 0 0 !important; }.key-left { grid-area: 2 / 1; border-radius: 8px 0 0 8px !important; }.key-right { grid-area: 2 / 3; border-radius: 0 8px 8px 0 !important; }.key-down { grid-area: 3 / 2; border-radius: 0 0 8px 8px !important; }
.shoulder-keys { display: flex; justify-content: space-between; gap: 40px; }
.shoulder-keys .key { width: 120px; height: 36px; border-radius: 10px 10px 6px 6px; font-size: 12px; }
.face-keys { position: relative; width: 132px; height: 132px; flex-shrink: 0; }
.face-keys .key { position: absolute; width: 44px; height: 44px; border-radius: 50%; font-size: 14px; }
.face-keys [data-key="x"] { top: 0; left: calc(50% - 22px); }
.face-keys [data-key="y"] { top: calc(50% - 22px); left: 0; }
.face-keys [data-key="a"] { top: calc(50% - 22px); right: 0; }
.face-keys [data-key="b"] { bottom: 0; left: calc(50% - 22px); }
.menu-keys { display: flex; justify-content: center; gap: 16px; margin-top: 2px; }
.menu-keys .key { width: 76px; height: 36px; border-radius: 18px; font-size: 9px; letter-spacing: .08em; }
/* Installation opens as an overlay panel from the right edge. */
.guide-toggle { padding-inline: 12px; }
.guide-toggle svg { display: none; }
.installation-guide { margin: 0 12px 12px; border: 1px solid var(--line); border-radius: 0; background: var(--panel); scroll-margin-top: 12px; }
.guide-content { max-width: 760px; margin: auto; padding: 64px 32px; }
.eyebrow { color: var(--muted); font-size: 10px; letter-spacing: .14em; margin: 0 0 14px; }
.guide-content h2 { margin: 0 0 20px; font-size: clamp(24px, 4vw, 34px); font-weight: 500; letter-spacing: -.7px; }
.guide-content h3 { font-size: 15px; font-weight: 500; margin: 0 0 10px; color: var(--ink); }
.guide-content p { font-size: 13px; line-height: 1.9; color: var(--soft-ink); margin: 0 0 16px; overflow-wrap: anywhere; }
.guide-content .guide-intro { font-size: 15px; margin-bottom: 40px; }
.guide-note { border-left: 2px solid var(--line); padding: 4px 0 0 20px; margin: 24px 0 40px; }
.guide-steps { list-style: none; counter-reset: step; padding: 0; margin: 0; }
.guide-steps li { counter-increment: step; position: relative; padding: 28px 0 16px 48px; border-top: 1px solid var(--line); }
.guide-steps li::before { content: counter(step, decimal-leading-zero); position: absolute; left: 0; top: 30px; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
code { font-family: 'SFMono-Regular', Consolas, monospace; font-size: 12px; color: var(--ink); overflow-wrap: anywhere; }
.file-path { display: block; padding: 14px 16px; background: var(--soft); border-radius: 6px; margin-bottom: 16px; }
.guide-faq { margin-top: 32px; }
.guide-faq details { padding: 18px 0; border-bottom: 1px solid var(--line); }
.guide-faq summary { cursor: pointer; font-size: 13px; }
.guide-faq details p { margin: 14px 0 0; }
.guide-bottom { display: flex; flex-wrap: wrap; justify-content: flex-start; align-items: center; gap: 12px; margin-top: 36px; }
.theme-plate .dl-count { color: var(--faint); margin-left: 6px; }
@media (pointer: coarse) { .button { min-height: 40px; }.shoulder-keys .key, .menu-keys .key { height: 44px; } }
@media (max-width: 600px) {
  body { padding: calc(8px + env(safe-area-inset-top)) 8px calc(8px + env(safe-area-inset-bottom)); }
  .topbar { padding: 12px; min-height: 60px; }
  .topbar-actions { gap: var(--space-2); }
  .wordmark { font-size: 18px; letter-spacing: -.7px; margin-right: auto; }
  .topbar .button { width: 36px; min-height: 36px; padding-inline: 0; }
  .guide-toggle svg { display: block; }
  .guide-toggle span, .topbar-actions .primary span { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .model-view { margin: 0; }
  .hardware-stack { top: auto; bottom: 12px; left: 50%; transform: translateX(-50%); width: min(320px, calc(100% - 24px)); height: 44px; flex-direction: row; padding: 0; }
  .hardware-island { padding: 4px; }
  .lid-island { flex-direction: row; min-width: 0; width: auto; height: 44px; }
  .lid-module { height: 36px; width: auto; min-width: 36px; }
  .lid-fill { inset: 0 auto 0 0; height: 100%; width: calc(16px + (100% - 16px) * var(--lid-progress)); }
  .lid-handle-travel { inset: 0 8px; }
  .lid-handle, .lid-module[data-snapped="true"] .lid-handle { left: calc(100% * var(--lid-progress)); right: auto; bottom: 8px; top: 8px; height: auto; width: 3px; transform: translateX(-50%); }
  #lid-angle { cursor: ew-resize; }
  .lid-module .lid-stops { inset: 0 8px; }
  .lid-module .lid-stops i { left: var(--stop); bottom: 9px; top: 9px; right: auto; width: 2px; height: auto; transform: translateX(-50%); }
  .control-stack { top: auto; bottom: 66px; right: 50%; transform: translateX(50%); height: 42px; flex-direction: row; padding: 3px; gap: 4px; }
  .stack-row { flex-direction: row; gap: 4px; }
  .stack-row .icon-button { width: 34px; height: 36px; }
  .stack-divider { width: 1px; height: 20px; margin: 0 3px; }
  .theme-caption { display: none; }
  .mobile-project-row { position: absolute; inset: 0 0 auto; z-index: 2; display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 44px; padding: 0 12px; background: none; pointer-events: none; }
  .mobile-project-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 3px 6px; min-width: 0; color: var(--muted); font-size: 11px; line-height: 1.4; }
  .mobile-project-meta > span { white-space: nowrap; }
  .mobile-project-meta .dl-count { font-variant-numeric: tabular-nums; }
  .preview-message { bottom: 116px; max-width: calc(100% - 24px); }
  .view-actions { gap: 4px; }
  .key-panel { padding-inline: 16px; }
  .shoulder-keys { margin-bottom: 10px; }
  .installation-guide { margin: 0 8px 8px; }
  .guide-content { padding: 32px 20px; }
  .guide-steps li { padding-left: 36px; }
}
@media (max-height: 500px) and (min-width: 601px) {
  .topbar { padding: 6px; padding-bottom: 5px; min-height: 48px; }
  .hardware-stack, .control-stack { height: 226px; }
  .key-panel { padding-block: 6px; }
  .key-panel-body { padding-block: 4px; }
  .stack-row { gap: 0; }
  .stack-row .icon-button { height: 26px; }
  .stack-divider { margin: 0; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

@media (max-width: 360px) {
  .topbar { padding: 12px; gap: var(--space-2); }
  .wordmark { font-size: 16px; }
  .header-prefs .icon-button, .topbar .button { width: 32px; }
  .key-panel { padding-inline: 12px; }
  .key-panel-body { gap: 16px; }
  .dpad { grid-template-columns: repeat(3, 36px); grid-template-rows: repeat(3, 36px); }
  .face-keys { width: 120px; height: 120px; }
  .shoulder-keys { gap: 28px; }
}

@media (max-width: 600px) { .key-dock.is-open { margin-top: 8px; } }

.lid-stops { position: absolute; inset: 8px 0; pointer-events: none; }
.lid-stops i { position: absolute; bottom: var(--stop); left: 7px; right: 7px; height: 2px; border-radius: 2px; background: var(--soft-ink); opacity: .12; transform: translateY(50%); }

/* Installation manual opens from the navigation edge. */
.installation-guide { position: absolute; z-index: 5; inset: 64px 0 0 auto; width: min(760px, 100%); margin: 0; display: grid; grid-template-columns: 180px minmax(0, 1fr); border: 0; border-left: 1px solid var(--line); border-top: 1px solid var(--line); border-radius: 0; overflow: hidden; transform: translateX(100%); visibility: hidden; transition: transform 260ms ease, visibility 260ms; }
.installation-guide.is-open { transform: translateX(0); visibility: visible; }
.guide-toc { overflow-y: auto; padding: 28px 16px; border-right: 1px solid var(--line); background: var(--soft); }
.guide-toc p { margin: 0 0 20px; color: var(--muted); font-size: 11px; }
.guide-toc a { display: block; padding: 9px 6px; border-radius: 4px; font-size: 12px; line-height: 1.6; }
.guide-toc a:focus-visible { background: var(--panel); }
.installation-guide .guide-content { overflow-y: auto; overscroll-behavior: contain; width: 100%; margin: 0; padding: 28px; background: light-dark(#fff, #161616); }
.guide-content h3 { scroll-margin-top: 24px; }
.guide-toggle[aria-expanded="true"] { background: var(--soft); color: var(--ink); border: 1px solid var(--line); }
@media (max-width: 600px) {
  .installation-guide { top: 61px; bottom: 0; grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); }
  .guide-toc { display: flex; gap: 4px; padding: 10px 12px; border-right: 0; border-bottom: 1px solid var(--line); overflow-x: auto; }
  .guide-toc p { display: none; }
  .guide-toc a { flex-shrink: 0; white-space: nowrap; }
  .installation-guide .guide-content { padding: 24px 20px; }
}
@media (max-height: 500px) and (min-width: 601px) { .installation-guide { top: 52px; bottom: 0; } }
@media (prefers-reduced-motion: reduce) { .installation-guide { transition: none; } }

/* Hover styles only exist on devices that can actually hover; on touch the
   sticky :hover state read as a stuck selection after lifting the finger. */
@media (hover: hover) {
  .ghost:hover { background: var(--soft); }
  .primary:hover { background: light-dark(#000, #fff); }
  .icon-button:hover { background: var(--soft); color: var(--ink); }
  .key:hover { background: light-dark(#eaeaea, #303030); color: var(--ink); }
  .guide-toc a:hover { background: var(--panel); }
  .theme-contact:hover { color: var(--ink); }
}
