:root {
  color-scheme: dark;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #e6e9ec;
  background: #111217;
  --surface: #1a1c22;
  --surface-raised: #242730;
  --line: #353a43;
  --text-muted: #9aA2ae;
  --accent: #98ddd3;
  --accent-strong: #58b9ad;
  --rail: clamp(144px, 18vw, 208px);
}
* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; background: #111217; }
button, input, select { font: inherit; }
button, .rom-picker {
  min-height: 44px; border: 0; border-radius: 50%; background: transparent;
  color: inherit; cursor: pointer; touch-action: manipulation;
}
button { padding: .65rem; }
@media (hover: hover) { button:hover, .rom-picker:hover { background: #ffffff0d; color: #fff; } }
button:focus-visible, .rom-picker:focus-within, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
button:disabled { opacity: .28; cursor: not-allowed; }
button[aria-pressed="true"] { color: var(--accent); background: #98ddd30c; }
[hidden] { display: none !important; }
.icon { width: 22px; height: 22px; display: block; flex: 0 0 auto; pointer-events: none; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
/* Held controls must never enter the browser's selection / callout gesture. */
button, .rom-picker, .touch-controls, .toolbar, canvas {
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
.app-shell {
  position: relative; isolation: isolate; display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: 56px minmax(0, 1fr) auto;
  grid-template-areas: "toolbar" "game" "controls";
  width: 100%; height: 100vh; height: 100dvh;
  padding: env(safe-area-inset-top) max(8px, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(8px, env(safe-area-inset-left));
}
.toolbar { grid-area: toolbar; display: flex; align-items: center; justify-content: center; gap: 8px; z-index: 5; transition: opacity .2s; }
.toolbar-actions { display: flex; align-items: center; gap: 8px; }
.toolbar button, .rom-picker { display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; padding: 10px; flex: 0 0 auto; color: #929ba8; }
.toolbar button[aria-pressed="true"] { color: var(--accent); }
.rom-picker { position: relative; color: #d7e2e1; }
.rom-picker input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
#audio-button[data-muted="true"] { opacity: .55; }
#audio-button[data-muted="true"]::after { content: ""; position: absolute; width: 24px; height: 2px; background: currentColor; transform: rotate(-45deg); }
.more-menu { position: absolute; z-index: 9; inset: 64px 12px auto auto; width: min(340px, calc(100vw - 24px)); border: 1px solid var(--line); border-radius: 18px; padding: 20px; background: #1a1c22; color: inherit; box-shadow: 0 20px 60px #0008; }
.menu-heading, .eyebrow { color: var(--text-muted); font-size: 10px; font-weight: 650; letter-spacing: .16em; text-transform: uppercase; }
.session-actions { display: flex; justify-content: space-between; margin: 12px 0; }
.session-actions button { touch-action: none; }
.record-button { color: #dd7381; }
.record-button.recording { color: #ff7589; background: #ff75891a; }
#recording-status, .menu-hint { color: var(--text-muted); font-size: 12px; line-height: 1.8; }
.status-toast { position: fixed; z-index: 12; bottom: max(16px, env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); width: max-content; max-width: calc(100vw - 32px); margin: 0; padding: 10px 18px; border-radius: 12px; color: #dce5e8; background: #242730f5; box-shadow: 0 4px 20px #0005; text-align: center; font-size: 12px; pointer-events: none; opacity: 0; transition: opacity .2s; }
.status-toast.is-visible { opacity: 1; }
.motion-status { position: fixed; z-index: 4; top: max(64px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); max-width: min(90vw, 540px); margin: 0; padding: 8px 14px; border-radius: 12px; background: #1a1c22eb; color: var(--text-muted); font-size: 12px; text-align: center; pointer-events: none; }
.game-panel { grid-area: game; position: relative; display: flex; align-items: center; justify-content: center; min-width: 0; min-height: 0; overflow: hidden; }
.screen-wrap { --rim-padding: 3px; position: relative; width: 100%; max-width: 100%; padding: var(--rim-padding); isolation: isolate; }
.app-shell:not(.has-rom) .screen-wrap { visibility: hidden; }
.welcome { position: absolute; z-index: 3; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 16px; text-align: center; }
.has-rom .welcome { display: none; }
.welcome-mark { color: var(--accent); font-size: clamp(36px, 7vw, 72px); letter-spacing: -.09em; font-weight: 800; }
.welcome-mark span { color: #e5e7eb; }
.welcome h1 { margin: 22px 0 6px; font-size: clamp(20px, 3vw, 32px); font-weight: 500; letter-spacing: -.04em; }
.welcome p { margin: 0 0 24px; color: var(--text-muted); font-size: 14px; }
.welcome button { display: flex; align-items: center; gap: 12px; padding: 12px 22px; border-radius: 30px; background: #98ddd312; color: var(--accent); font-size: 14px; }
.welcome small { margin-top: 16px; color: #707986; font-size: 11px; }
.screen-wrap::before {
  content: "";
  position: absolute;
  z-index: -1;
  inset: calc(var(--rim-padding) * (1 - var(--rim-width, .02)));
  border-radius: var(--rim-radius-x, 0px) / var(--rim-radius-y, 0px);
  background: var(--rim-face-color, #24252a);
  transform: var(--rim-transform, none);
  transform-origin: 50% 50%;
  pointer-events: none;
}
.screen-wrap[data-rim="false"]::before { display: none; }

#screen-stage {
  position: relative;
  z-index: 0;
  width: 100%;
  aspect-ratio: 256 / 240;
  margin: 0 auto;
  overflow: hidden;
  background: #000;
}
#screen-stage[data-depth="true"] { background: transparent; }
#screen-scene { position: absolute; inset: 0; transform-origin: center; }
#screen-scene > #screen {
  position: relative;
  z-index: 0;
  display: block;
  width: 100%;
  height: 100%;
  margin: 0;
  aspect-ratio: 256 / 240;
  image-rendering: pixelated;
  background: #000;
}
#depth-stack { position: absolute; z-index: 1; inset: 0; pointer-events: none; }
#depth-stack canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  margin: 0;
  background: transparent;
  backface-visibility: hidden;
}
#depth-stack canvas:not(:first-child) { image-rendering: auto; }
#depth-stack canvas.depth-front { image-rendering: pixelated; }
#depth-stack .diorama-box[hidden] { display: none; }
#screen-stage[data-depth="false"] #depth-stack,
#screen-stage[data-depth="false"] #depth-ghosts { display: none; }
#screen-stage[data-depth="true"] #screen { visibility: hidden; }
#depth-ghosts { position: absolute; z-index: 2; inset: 0; display: block; width: 100%; height: 100%; margin: 0; background: transparent; pointer-events: none; }


.touch-controls { grid-area: controls; display: none; width: min(100%, 600px); margin: 0 auto; padding: 12px 8px 16px; touch-action: none; }
.app-shell[data-touch="true"] .touch-controls { display: block; }
.controller-hitboxes { display: grid; grid-template-columns: 1fr 1fr; grid-template-areas: "dpad face" "dpad menu"; align-items: center; justify-items: center; gap: 12px; }
.dpad-hitbox { grid-area: dpad; display: grid; grid-template-columns: repeat(3, 46px); grid-template-rows: repeat(3, 46px); gap: 0; touch-action: none; }
.dpad-hitbox button { width: 46px; height: 46px; padding: 0; border-radius: 14px; color: #c0c7d0; background: #ffffff06; font-size: 15px; }
.dpad-hitbox .hit-up { grid-column: 2; grid-row: 1; border-radius: 14px 14px 4px 4px; }
.dpad-hitbox .hit-left { grid-column: 1; grid-row: 2; border-radius: 14px 4px 4px 14px; }
.dpad-hitbox .hit-right { grid-column: 3; grid-row: 2; border-radius: 4px 14px 14px 4px; }
.dpad-hitbox .hit-down { grid-column: 2; grid-row: 3; border-radius: 4px 4px 14px 14px; }
.menu-hitbox { grid-area: menu; display: flex; gap: 16px; }
.menu-hitbox button { display: grid; place-items: center; width: 48px; height: 44px; color: #9da7b5; padding: 8px; }
.face-hitbox { grid-area: face; display: flex; align-items: center; gap: 20px; padding: 12px 0; }
.face-hitbox button { width: 60px; height: 60px; border-radius: 50%; background: #e494a20d; color: #e6a1ac; font-size: 18px; font-weight: 550; }
.face-hitbox button:last-child { transform: translateY(-12px); }
.controller-hitboxes button, #rewind-button { touch-action: none; }
.controller-hitboxes button.is-held { background: #98ddd325; color: #c2fff6; }
#rewind-button.is-held { color: var(--accent); background: #98ddd325; }
.presentation-panel { width: min(720px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); margin: auto; padding: 24px; border: 1px solid var(--line); border-radius: 24px; background: var(--surface); color: inherit; overscroll-behavior: contain; scrollbar-width: thin; }
.presentation-panel::backdrop { background: #0009; }
.settings-header { position: sticky; top: -24px; z-index: 4; background: var(--surface); margin-inline: -24px; padding: 8px 24px; display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; }
.settings-header h2 { margin: 5px 0 0; font-size: 24px; font-weight: 500; letter-spacing: -.04em; }
.settings-header button { display: grid; place-items: center; }
.look-picker { margin-bottom: 24px; }
.look-heading { display: flex; align-items: baseline; justify-content: space-between; flex-wrap: wrap; gap: 8px; }
.look-heading h3 { margin: 0; font-size: 15px; font-weight: 550; }
#settings-change-summary { color: var(--accent); font-size: 11px; }
#settings-action-status { color: var(--accent); font-size: 11px; line-height: 1.5; }
#settings-action-status:empty { display: none; }
#look-picker-hint { color: var(--text-muted); font-size: 11px; line-height: 1.5; }
.look-grid { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 12px; }
.look-card { min-width: 0; padding: 5px; border: 1px solid transparent; border-radius: 12px; text-align: left; }
.look-card[aria-pressed="true"] { border-color: var(--accent-strong); }
.look-card canvas { image-rendering: pixelated; display: block; width: 100%; height: auto; aspect-ratio: 256/240; border-radius: 7px; background: #111217; }
.look-card strong { display: block; margin: 8px 4px 3px; font-size: 12px; font-weight: 550; }
.look-card small { display: block; margin: 0 4px 5px; font-size: 10px; color: var(--text-muted); line-height: 1.4; }
#save-defaults-button { margin-top: 12px; border-radius: 8px; color: var(--accent); font-size: 12px; }
.setting-toggle { flex-wrap: wrap; }
.setting-toggle .setting-default { flex: 0 0 100%; padding-left: 25px; }
.setting-default { color: var(--accent) !important; font-size: 11px !important; font-weight: 400; line-height: 1.5; }
.is-modified output { color: var(--accent) !important; }
.play-settings { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 24px; }
.play-settings label { display: grid; gap: 8px; font-size: 12px; color: var(--text-muted); }
.play-settings select { min-width: 0; width: 100%; min-height: 44px; padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: #111217; color: #e6e9ec; }
.play-settings .shading-control { grid-column: 1/-1; }
.shading-control > span { display: flex; justify-content: space-between; color: #e6e9ec; }
.shading-control output { color: var(--accent); font-variant-numeric: tabular-nums; }
.shading-control input { width: 100%; min-height: 44px; margin: 0; accent-color: var(--accent-strong); cursor: pointer; }
.shading-control small { font-size: 11px; line-height: 1.5; }
.play-settings p { grid-column: 1/-1; margin: 0; color: #8a969f; font-size: 11px; }
.presentation-controls { display: grid; grid-template-columns: minmax(0, 1fr); gap: .8rem; }
.settings-group { min-width: 0; margin: 0; padding: .7rem; border: 1px solid #343b48; border-radius: 9px; }
.settings-group legend { padding: 0 .4rem; color: #eaf1f8; font-size: .9rem; font-weight: 700; }
.group-controls { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .75rem 1.2rem; min-width: 0; }
.presentation-controls label { min-width: 0; color: #e7eaf0; font-size: .82rem; }
.presentation-controls label > span { display: flex; flex-wrap: wrap; justify-content: space-between; gap: .2rem .6rem; font-weight: 650; }
.presentation-controls output { flex: 0 0 auto; color: #b8d9e6; font-weight: 450; font-variant-numeric: tabular-nums; }
.presentation-controls input[type="range"] { display: block; width: 100%; min-height: 44px; margin: .15rem 0; accent-color: var(--accent-strong); cursor: pointer; }
.presentation-controls small { display: block; color: var(--text-muted); font-size: .72rem; line-height: 1.35; overflow-wrap: anywhere; }
.settings-footer { position: sticky; bottom: -24px; z-index: 3; background: var(--surface); margin-inline: -24px; padding-inline: 24px; padding-bottom: 12px; display: flex; justify-content: flex-end; gap: 12px; flex-wrap: wrap; margin-top: .65rem; padding-top: .55rem; border-top: 1px solid #343b48; }
.settings-footer #save-defaults-button { margin: 0; }
.settings-footer #settings-action-status { flex-basis: 100%; margin: 0; }
.settings-footer button { min-height: 44px; padding: .35rem .65rem; font-size: .76rem; }
.surface-options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); align-content: start; align-items: center; gap: .1rem .6rem; min-width: 0; }
.surface-options label { display: flex; align-items: center; gap: .55rem; min-height: 44px; cursor: pointer; }
.surface-options input[type="checkbox"] { display: inline-block; width: 20px; height: 20px; margin: 0; accent-color: var(--accent-strong); }
.surface-options > small { grid-column: 1 / -1; }
.surface-options .sprite-relief-style { grid-column: 1 / -1; display: flex; flex-direction: column; align-items: stretch; gap: .3rem; margin: .25rem 0; cursor: default; }
.sprite-relief-style select, .viewing-profile select { width: 100%; min-width: 0; min-height: 44px; padding: .4rem; border: 1px solid var(--line); border-radius: 7px; background: #11141a; color: inherit; }
.viewing-profile select { margin: .35rem 0; }
.sprite-relief-style select:disabled { opacity: .55; }
.lighting-toggle { display: flex; align-items: center; gap: .55rem; min-height: 44px; cursor: pointer; }
.lighting-toggle input[type="checkbox"] { width: 20px; height: 20px; margin: 0; accent-color: var(--accent-strong); }

.settings-footer button { border-radius: 8px; color: var(--accent); }
.play-hint { display: none; }
.app-shell.is-immersive { grid-template-rows: 0 minmax(0, 1fr) auto; }
.is-immersive .toolbar { position: absolute; inset: 8px 0 auto; width: max-content; max-width: 100%; margin: auto; padding: 4px 8px; border-radius: 40px; background: #1a1c22f2; }
.is-immersive:not(.chrome-visible) .toolbar { opacity: 0; pointer-events: none; }
.is-immersive:not(.chrome-visible) { cursor: none; }
.is-immersive .toolbar:focus-within { opacity: 1; pointer-events: auto; }
@media (hover: hover) { .is-immersive .toolbar:hover { opacity: 1; pointer-events: auto; } }
@media (orientation: landscape) {
  .app-shell[data-touch="true"] { grid-template-columns: var(--rail) minmax(0, 1fr) var(--rail); grid-template-rows: 56px minmax(0, 1fr); grid-template-areas: "toolbar toolbar toolbar" ". game ."; }
  .app-shell[data-touch="true"].is-immersive { grid-template-rows: 0 minmax(0, 1fr); }
  .app-shell[data-touch="true"] .touch-controls { display: grid; grid-column: 1/-1; grid-row: 2; grid-template-columns: var(--rail) minmax(0, 1fr) var(--rail); grid-template-rows: minmax(0, 1fr) 60px; width: 100%; min-height: 0; margin: 0; padding: 0; pointer-events: none; }
  .controller-hitboxes { display: contents; }
  .dpad-hitbox { grid-area: auto; grid-column: 1; grid-row: 1/-1; justify-self: center; align-self: center; pointer-events: auto; }
  .face-hitbox { grid-area: auto; grid-column: 3; grid-row: 1; justify-self: center; align-self: center; gap: 12px; pointer-events: auto; }
  .menu-hitbox { grid-area: auto; grid-column: 3; grid-row: 2; justify-self: center; align-self: start; gap: 12px; pointer-events: auto; }
}
@media (max-width: 600px) {
  .toolbar, .toolbar-actions { gap: 2px; }
  .toolbar button, .rom-picker { width: 40px; padding: 9px; }
  .presentation-panel { padding: 18px; border-radius: 18px; }
  .group-controls, .surface-options { grid-template-columns: minmax(0, 1fr); }
  .surface-options > small { grid-column: auto; }
  .play-settings { grid-template-columns: minmax(0, 1fr); }
  .look-grid { grid-template-columns: minmax(0,1fr); }
  .settings-header { top: -18px; margin-inline: -18px; padding-inline: 18px; }
  .settings-footer { bottom: -18px; margin-inline: -18px; padding-inline: 18px; gap: 4px 10px; }
}
@media (max-height: 380px) and (orientation: landscape) {
  .app-shell { grid-template-rows: 48px minmax(0, 1fr) auto; }
  .app-shell[data-touch="true"] { grid-template-rows: 48px minmax(0, 1fr); }
  .welcome-mark, .welcome small { display: none; }
  .welcome h1 { margin-top: 0; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
:root .vr-demo-link { display: block; padding: 10px 8px; color: #9ed5ce; font-size: 13px; text-decoration: none; }
:root .vr-demo-link:focus-visible { outline: 2px solid currentColor; border-radius: 6px; }
/* Every depth view uses the same GPU stage; flat mode displays untouched RGBA. */
#stage { display: block; width: 100%; height: 100%; min-width: 0; min-height: 0; touch-action: none; }
.app-shell[data-view="flat"] #stage, .app-shell:not([data-view]) #stage { display: none; }
.app-shell:not([data-view="flat"]) .screen-wrap, .app-shell:not([data-view="flat"]) .welcome { display: none; }
.screen-wrap { padding: 0; }
.screen-wrap::before { display: none; }
#fatal { position: absolute; z-index: 3; max-width: 90%; padding: 16px; background: var(--surface); border-radius: 12px; font-size: 12px; }
.look-card img { display: block; width: 100%; height: auto; aspect-ratio: 256/240; object-fit: cover; border-radius: 7px; background: #202a2c; }
.presentation-controls select { width: 100%; min-height: 44px; padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: #111217; color: inherit; }
.in-vr .toolbar { opacity: 1; pointer-events: auto; }
#fps { position: absolute; bottom: 4px; left: 8px; z-index: 2; margin: 0; padding: 4px 7px; border-radius: 6px; background: #111217bb; font-size: 10px; font-variant-numeric: tabular-nums; pointer-events: none; }

.play-settings .play-toggle { display: flex; align-items: center; min-height: 44px; gap: 10px; }
.play-toggle input { width: 18px; height: 18px; margin: 0; accent-color: var(--accent-strong); }

.view-controls { display: flex; align-items: center; gap: 2px; padding-inline: 3px; border-inline: 1px solid #ffffff0a; }
#fullscreen-more-button { display: none; }
.session-actions { flex-wrap: wrap; }
@media (max-width: 600px) {
  .toolbar #fullscreen-button { display: none; }
  #more-menu #fullscreen-more-button { display: inline-flex; align-items: center; justify-content: center; }
}

.view-transition { position: absolute; inset: 0; z-index: 3; width: 100%; height: 100%; pointer-events: none; }

.toolbar button[aria-pressed="true"] { background: transparent; }
.game-panel canvas:focus { outline: none; }
