:root {
  --background: #e8e8e8; --ink: #292929; --muted: #666666; --primary: #ffc600; --yellow: var(--primary);
  --surface: #f7f7f7; --device-control: #ffdc72; --lcd: #d5d4c9; --lcd-ink: #303029;
  --control-shadow: #b59020; --control-edge: #c59e2e; --control-pressed: #ffe697; --control-highlight: #fff0b0;
  --dpad-size: 248px; --game-button-size: 112px;
  --error: #a42e20; --line: #c8c8c8; --scroll-thumb: #929292; --radius: 18px;
  --font-body: 'Segoe UI', 'Microsoft YaHei', Arial, sans-serif;
  --font-utility: 'Consolas', 'Microsoft YaHei', monospace;
  font-family: var(--font-body); color: var(--ink); background: var(--background);
  scrollbar-color: var(--scroll-thumb) var(--background); scrollbar-width: thin;
}
* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; }
[hidden] { display: none !important; }
button, a { -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: inherit; cursor: pointer; border: 1px solid var(--line); background: var(--surface); border-radius: 10px; min-height: 44px; padding: 10px 16px; transition: background .16s, transform .12s; }
button:hover:not(:disabled) { background: var(--yellow); border-color: var(--ink); }
button:active:not(:disabled) { transform: translateY(2px); }
button:disabled { opacity: .45; cursor: not-allowed; }
button:focus-visible, a:focus-visible, [tabindex]:focus-visible { outline: 3px solid var(--ink); outline-offset: 4px; }
button[aria-pressed="true"], button[aria-expanded="true"] { background: var(--ink); color: var(--yellow); border-color: var(--ink); }
button[aria-pressed="true"]:hover, button[aria-expanded="true"]:hover { background: #414141; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--background); }
::-webkit-scrollbar-thumb { background: var(--scroll-thumb); border-radius: 8px; border: 2px solid var(--background); }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }
::-webkit-scrollbar-thumb:active { background: var(--ink); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
.toolbar { position: relative; z-index: 3; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: max(18px, env(safe-area-inset-top)) max(28px, env(safe-area-inset-right)) 12px max(28px, env(safe-area-inset-left)); min-height: 78px; }
.brand { color: var(--ink); text-decoration: none; font-size: 25px; font-weight: 700; letter-spacing: -.8px; display: flex; gap: 10px; align-items: center; }
.brand-device { width: 27px; height: 30px; background: var(--yellow); border-radius: 6px; position: relative; }
.brand-device::before { content: ''; position: absolute; inset: 5px 4px 11px; border: 2px solid var(--ink); }
.brand-device::after { content: '+'; position: absolute; left: 4px; bottom: 1px; font-size: 13px; }
.edition { font: 10px var(--font-utility); letter-spacing: 1px; background: var(--ink); color: var(--yellow); padding: 4px 6px; border-radius: 4px; align-self: flex-start; margin-top: 2px; }
.actions { display: flex; gap: 7px; }
.actions button { font-size: 13px; white-space: nowrap; min-width: 66px; }
.stage { min-height: 420px; height: calc(100dvh - 130px); position: relative; display: grid; place-items: center; }
#model-host { width: 100%; height: 100%; min-width: 0; position: relative; }
#intro-canvas { display: block; width: 100%; height: 100%; touch-action: none; cursor: grab; }
#intro-canvas:active { cursor: grabbing; }
.model-message { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); pointer-events: none; }
.session-bar { min-height: 52px; display: flex; align-items: center; gap: 20px; padding: 12px max(28px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)); font-size: 12px; color: var(--muted); }
.session-title { display: flex; align-items: center; gap: 8px; color: var(--ink); }
.session-title strong { font-weight: 600; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.status-dot.running { background: #447138; }
.keyboard-hint { margin-left: auto; font: 11px var(--font-utility); }
body[data-mode="immersive"] { background: var(--yellow); }
body[data-mode="immersive"] .toolbar { background: var(--yellow); }
body[data-mode="immersive"] .stage { height: auto; min-height: max(420px, calc(100dvh - 130px)); }
body[data-mode="immersive"] .brand-device { background: var(--ink); }
body[data-mode="immersive"] .brand-device::before { border-color: var(--yellow); }
body[data-mode="immersive"] .brand-device::after { color: var(--yellow); }
body[data-mode="immersive"] .actions button { background: var(--device-control); border-color: #b08b19; }
body[data-mode="immersive"] .actions button[aria-pressed="true"], body[data-mode="immersive"] .actions button[aria-expanded="true"] { background: var(--ink); color: var(--yellow); }
.play-surface { width: min(1080px, calc(100% - 48px)); min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 28px; justify-items: center; padding: 12px 0 20px; }
.display-shell { width: 100%; max-width: 880px; border: 12px solid var(--ink); border-radius: 16px; background: var(--lcd); box-shadow: 0 3px 0 #b59020; overflow: hidden; }
#game-screen { display: block; width: 100%; height: auto; aspect-ratio: 5 / 3; image-rendering: pixelated; touch-action: none; cursor: ns-resize; }
.game-controls { width: 100%; max-width: 800px; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); grid-template-rows: auto auto; gap: 12px 30px; align-items: center; justify-items: center; }
.dpad { width: var(--dpad-size); height: var(--dpad-size); position: relative; grid-row: 1 / 3; touch-action: none; --tilt-x: 0deg; --tilt-y: 0deg; }
.dpad-body { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; transform: perspective(600px) rotateX(var(--tilt-x)) rotateY(var(--tilt-y)); transition: transform .1s ease-out; overflow: visible; }
.dpad-shadow { fill: var(--control-shadow); }
.dpad-face { fill: var(--device-control); stroke: var(--control-edge); stroke-width: 1.5px; transform: translateY(0); transition: transform .1s ease-out, fill .1s; }
.dpad.held .dpad-face { transform: translateY(4px); fill: var(--control-pressed); }
.dpad button { position: absolute; width: 34%; height: 34%; border: 0; border-radius: 16px; background: transparent; color: var(--ink); font-size: calc(var(--dpad-size) * .125); padding: 0; touch-action: none; user-select: none; box-shadow: none; }
.dpad button:hover:not(:disabled), .dpad button:active:not(:disabled) { background: transparent; transform: none; }
.dpad button span { display: block; transition: transform .1s ease-out; pointer-events: none; }
.dpad button.held span { transform: translateY(4px); }
.dpad button:focus-visible { outline-offset: -8px; }
.dpad .up { top: 0; left: 33%; }.dpad .down { bottom: 0; left: 33%; }.dpad .left { left: 0; top: 33%; }.dpad .right { right: 0; top: 33%; }
.ab-buttons { display: flex; gap: 16px; align-items: center; }
.game-button { width: var(--game-button-size); height: var(--game-button-size); padding: calc(var(--game-button-size) * .16); border: 1.5px solid var(--control-edge); border-radius: 50%; background: var(--device-control); box-shadow: 0 6px 0 var(--control-shadow), inset 0 2px 0 var(--control-highlight); touch-action: none; user-select: none; transition: transform .1s ease-out, box-shadow .1s, background .1s; }
.game-button span { display: grid; place-items: center; width: 100%; height: 100%; background: var(--surface); border-radius: 50%; font-size: calc(var(--game-button-size) * .43); font-weight: 700; line-height: 1; pointer-events: none; }
.game-button:hover:not(:disabled) { background: var(--control-pressed); border-color: var(--control-edge); }
.game-button.held, .game-button:active:not(:disabled) { background: var(--control-pressed); transform: translateY(5px); box-shadow: 0 1px 0 var(--control-shadow), inset 0 1px 3px var(--control-edge); }
.dial-wrap { display: grid; justify-items: center; gap: 5px; }
.crank-dial { width: 146px; height: 146px; border-radius: 28px; background: var(--ink); position: relative; touch-action: none; cursor: grab; border: 1px solid #786d3b; box-shadow: 0 3px 0 #b59020; }
.crank-dial:active { cursor: grabbing; }
.dial-marks { position: absolute; inset: 12px; border: 2px solid #555957; border-radius: 50%; background: repeating-conic-gradient(from 0deg, #9b8736 0deg 2deg, transparent 2deg 30deg); mask-image: radial-gradient(transparent 58%, black 59%, black 68%, transparent 69%); }
.dial-hand { position: absolute; left: calc(50% - 2px); top: 16%; width: 4px; height: 34%; background: var(--yellow); border-radius: 3px; transform-origin: 50% 100%; transform: rotate(0deg); }
.dial-center { position: absolute; width: 12px; height: 12px; border: 3px solid var(--yellow); border-radius: 50%; left: calc(50% - 6px); top: calc(50% - 6px); }
#dock-toggle { padding: 4px 12px; min-height: 32px; font-size: 12px; background: transparent; border-color: transparent; color: var(--ink); }
#dock-toggle:hover { border-color: var(--ink); }
.panel { position: absolute; z-index: 5; top: 16px; right: 28px; width: min(340px, calc(100% - 32px)); max-height: calc(100% - 32px); overflow: auto; scrollbar-gutter: stable; padding: 22px; border: 1px solid #c4c4c4; border-radius: var(--radius); background: var(--surface); box-shadow: 0 12px 44px #00000026; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 20px; }
.panel-heading h1, .panel-heading h2 { margin: 4px 0 0; font-size: 22px; font-weight: 700; letter-spacing: -.5px; }
.panel-heading button { width: 44px; padding: 0; font-size: 25px; background: transparent; }
.eyebrow { font-size: 11px; color: var(--muted); }
.game-list { display: grid; gap: 16px; }
.game-card { padding: 0; width: 100%; text-align: left; overflow: hidden; border-radius: 13px; background: var(--surface); }
.game-card[aria-current="true"] { border: 2px solid var(--ink); }
.game-art { display: flex; align-items: center; justify-content: center; height: 108px; width: 100%; background: var(--lcd); overflow: hidden; }
.mahjong-art { gap: 5px; }
.mahjong-art span { background: var(--surface); border: 1px solid var(--ink); border-radius: 5px; padding: 8px 11px; font-family: 'Microsoft YaHei', sans-serif; font-size: 28px; box-shadow: 2px 4px 0 var(--ink); transform: rotate(-9deg); }
.mahjong-art span:nth-child(2) { transform: translateY(-4px) rotate(3deg); }
.mahjong-art span:nth-child(3) { transform: rotate(12deg); }
.music-art { background: var(--yellow); position: relative; }
.music-art span { font-size: 66px; transform: rotate(-9deg); }
.music-art i { width: 82px; height: 82px; position: absolute; border: 1px solid #9c7b0e; border-radius: 50%; right: 20px; }
.game-copy { display: grid; gap: 6px; padding: 15px; }
.game-copy strong { font-size: 15px; }.game-copy > span { font-size: 12px; color: var(--muted); }.game-copy small { margin-top: 6px; font-size: 12px; font-weight: 600; }
.library-note { font-size: 11px; color: var(--muted); line-height: 1.7; margin: 18px 0 0; }
#history-empty { color: var(--muted); font-size: 14px; line-height: 1.8; }
#clear-history { margin-top: 14px; font-size: 12px; }
.game-copy strong { overflow-wrap: anywhere; }
.error-banner p { max-height: 30vh; overflow: auto; overflow-wrap: anywhere; white-space: pre-wrap; }
.load-state { display: grid; gap: 8px; font-size: 12px; margin-top: 16px; }
progress { width: 100%; height: 8px; accent-color: var(--ink); }
.system-menu { display: grid; gap: 10px; }.system-menu .panel-heading { margin-bottom: 6px; }
#custom-menu { display: grid; gap: 8px; }.menu-option { display: flex; width: 100%; justify-content: space-between; gap: 12px; text-align: left; }
.error-banner { position: fixed; z-index: 8; bottom: 70px; left: 50%; transform: translateX(-50%); width: min(650px, calc(100% - 32px)); display: flex; align-items: center; gap: 16px; padding: 14px 18px; border-radius: 12px; border: 1px solid var(--error); color: var(--error); background: var(--surface); box-shadow: 0 8px 24px #0000001a; }
.error-banner p { flex: 1; margin: 0; font-size: 13px; line-height: 1.6; }.error-banner button { white-space: nowrap; }
@media (min-width: 1100px) and (min-aspect-ratio: 3 / 2) {
  .play-surface { width: calc(100% - 64px); max-width: 1500px; grid-template-columns: 248px minmax(0, 1fr) 248px; gap: 28px; }
  .display-shell { grid-column: 2; grid-row: 1; max-width: 960px; }
  .game-controls { display: contents; }.dpad { grid-column: 1; grid-row: 1; }.ab-buttons { grid-column: 3; grid-row: 1; align-self: start; margin-top: 26px; }.dial-wrap { grid-column: 3; grid-row: 1; align-self: end; margin-bottom: 16px; }
}
@media (max-width: 700px) {
  .toolbar { flex-wrap: wrap; padding: max(12px, env(safe-area-inset-top)) 16px 10px; gap: 12px; min-height: 112px; }
  .brand { font-size: 21px; }.brand-device { width: 23px; height: 26px; }
  .actions { width: 100%; justify-content: space-between; gap: 5px; }.actions button { padding: 8px 7px; min-width: 0; flex: 1; font-size: 12px; }
  .stage { height: calc(100dvh - 182px); min-height: 420px; }
  body[data-mode="immersive"] .stage { min-height: calc(100dvh - 182px); }
  .play-surface { width: calc(100% - 24px); gap: 24px; }.display-shell { border-width: 9px; border-radius: 12px; }
  .game-controls { gap: 14px 12px; --dpad-size: clamp(156px, 49vw, 212px); --game-button-size: clamp(68px, 21vw, 92px); }.ab-buttons { gap: 10px; }.crank-dial { width: 138px; height: 138px; }
  .panel { right: 16px; padding: 18px; width: min(320px, calc(100% - 32px)); }
  .session-bar { padding: 10px 16px max(10px, env(safe-area-inset-bottom)); flex-wrap: wrap; gap: 4px 12px; }.keyboard-hint { display: none; }.session-title { width: 100%; }
}
@media (max-height: 600px) and (min-aspect-ratio: 6 / 5) {
  .toolbar { min-height: 62px; padding: 8px 16px; flex-wrap: nowrap; }.brand { font-size: 19px; }.actions { width: auto; }.actions button { flex: none; min-height: 40px; padding: 7px 10px; }
  .stage { min-height: 240px; height: calc(100dvh - 100px); }
  body[data-mode="immersive"] .stage { min-height: calc(100dvh - 100px); }
  .session-bar { min-height: 38px; padding: 7px 16px; }.session-title { width: auto; }
  .play-surface { grid-template-columns: 160px minmax(0, 1fr) 174px; width: calc(100% - 24px); gap: 14px; padding: 0; max-width: 1180px; --dpad-size: 158px; --game-button-size: 78px; }
  .display-shell { grid-column: 2; grid-row: 1; max-width: min(670px, calc((100dvh - 130px) * 5 / 3)); border-width: 8px; }
  .game-controls { display: contents; --dpad-size: inherit; --game-button-size: inherit; }
  .dpad { grid-column: 1; grid-row: 1; }.dpad button { min-height: 44px; border-radius: 12px; }
  .ab-buttons { grid-column: 3; grid-row: 1; align-self: start; gap: 12px; }
  .dial-wrap { grid-column: 3; grid-row: 1; align-self: end; }.crank-dial { width: 114px; height: 114px; border-radius: 22px; }
  #dock-toggle { min-height: 28px; padding: 3px 6px; font-size: 11px; }.panel { top: 4px; max-height: calc(100% - 8px); }.error-banner { bottom: 45px; }
}
@media (max-width: 740px) and (max-height: 600px) and (min-aspect-ratio: 6 / 5) {
  .play-surface { grid-template-columns: 132px minmax(0, 1fr) 146px; gap: 10px; --dpad-size: 132px; --game-button-size: 66px; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; } }
@media (forced-colors: active) { :root { scrollbar-color: auto; }.game-art { border: 1px solid CanvasText; }.dpad-face { fill: ButtonFace; stroke: ButtonText; }.dpad-shadow { fill: ButtonText; }.status-dot { background: CanvasText; } }
