/* Touch controls belong to the game canvas, including its letterboxed bounds. */
html, body { overscroll-behavior: none; }
#stage, html.touch-enabled #stage { inset: 0; width: 100%; height: 100%; }
html.touch-enabled canvas#view { touch-action: none; }
canvas#view:focus { outline: none; }
.touch-controls[hidden], .touch-controls [hidden], .touch-settings [hidden] { display: none !important; }
:root { --touch-canvas-left: 0px; --touch-canvas-top: 0px; --touch-canvas-right: 0px; --touch-canvas-bottom: 0px; --touch-canvas-width: 100vw; --touch-canvas-height: 100vh; --touch-font: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Heiti SC", system-ui, sans-serif; }
.touch-controls { position: fixed; inset: 0; z-index: 11; pointer-events: none; -webkit-user-select: none; user-select: none; --touch-stick-size: 104px; font-family: var(--touch-font); }
.touch-control-body, .touch-actions, .touch-primary, .touch-secondary { display: contents; }
.touch-context-title, .touch-context-hint { display: none; }
.touch-navigation { position: fixed; left: calc(var(--touch-canvas-left) + 18px); bottom: calc(var(--touch-canvas-bottom) + 22px); }
.touch-dpad { position: relative; width: var(--touch-stick-size); height: var(--touch-stick-size); border-radius: 50%; border: 1px solid #d8cda528; background: #20221d0b; touch-action: none; pointer-events: auto; outline-offset: 3px; opacity: .3; transition: opacity .15s; }
.touch-stick { position: absolute; left: 50%; top: 50%; width: 34px; height: 34px; border: 1px solid #d8cda559; border-radius: 50%; background: #b6af9114; transform: translate(-50%, -50%); pointer-events: none; }
.touch-dpad.is-pressed { opacity: 1; border-color: #d8cda56b; background: #1c241f25; }.touch-dpad.is-pressed .touch-stick { background: #c0b8942e; border-color: #e7d8aa99; }
.touch-controls[data-layout="world"] .touch-dpad { opacity: 0; pointer-events: none; }.touch-controls[data-layout="world"] .touch-dpad.is-pressed, .touch-controls[data-layout="world"] .touch-dpad:focus-visible { opacity: 1; }
.touch-button, .touch-settings-toggle { display: grid; place-items: center; width: 44px; min-width: 40px; height: 40px; min-height: 40px; padding: 5px; border: 1px solid #c5ba8f55; border-radius: 2px; background: #202721b8; color: #ddd5b8; font: 600 12px/1.2 var(--touch-font); text-align: center; text-shadow: 0 1px #07110d; box-shadow: inset 0 0 0 2px #0e151026; touch-action: none; pointer-events: auto; -webkit-tap-highlight-color: transparent; cursor: pointer; }
.touch-primary .touch-button { position: fixed; right: calc(var(--touch-canvas-right) + 22px); bottom: calc(var(--touch-canvas-bottom) + 28px); width: 76px; height: 46px; border-color: #cabc8387; background: #242a20cc; color: #e6d6a3; font-size: 15px; letter-spacing: .1em; box-shadow: inset 3px 0 #b4a16a66; }
.touch-primary .touch-button[data-action="interact"]::before { content: '◇'; position: absolute; left: -13px; color: #d2bd83; font-size: 12px; text-shadow: 0 1px 3px #0c1109; }
.touch-secondary .touch-button { position: fixed; width: 48px; height: 42px; }
.touch-secondary .touch-button:nth-child(1) { right: calc(var(--touch-canvas-right) + 108px); bottom: calc(var(--touch-canvas-bottom) + 30px); }
.touch-secondary .touch-button:nth-child(2) { right: calc(var(--touch-canvas-right) + 108px); bottom: calc(var(--touch-canvas-bottom) + 80px); }
.touch-secondary .touch-button:nth-child(3) { right: calc(var(--touch-canvas-right) + 22px); bottom: calc(var(--touch-canvas-bottom) + 84px); }
.touch-secondary .touch-button:nth-child(4) { right: calc(var(--touch-canvas-right) + 164px); bottom: calc(var(--touch-canvas-bottom) + 30px); }
.touch-secondary .touch-button:nth-child(5) { right: calc(var(--touch-canvas-right) + 164px); bottom: calc(var(--touch-canvas-bottom) + 80px); }
.touch-utilities { position: fixed; top: calc(var(--touch-canvas-top) + 8px); left: calc(var(--touch-canvas-left) + 8px); display: flex; gap: 4px; }
.touch-utilities .touch-button { width: 40px; background: #18221991; border-color: #b7b19740; }
.touch-utilities .touch-button[data-action="auto"] { position: fixed; left: auto; top: auto; right: calc(var(--touch-canvas-right) + 24px); bottom: calc(var(--touch-canvas-bottom) + 12px); height: 32px; min-height: 32px; width: 50px; border: 0; box-shadow: none; background: transparent; color: #a9ad95; font-size: 11px; letter-spacing: .12em; }
.touch-utilities .touch-button[data-action="auto"]::before { content: '▷'; margin-right: 4px; position: absolute; left: -2px; }
.touch-utilities .touch-button[data-action="auto"].is-selected::before { content: 'Ⅱ'; }.touch-utilities .touch-button[data-action="auto"].is-selected { color: #e0d29f; }
.touch-button.is-pressed { background: #716c466b; border-color: #e0c98599; }.touch-button.is-selected { border-color: #d5c591aa; color: #ecddad; }
.touch-button:focus-visible, .touch-dpad:focus-visible, .touch-settings button:focus-visible, .touch-reader-close:focus-visible { outline: 2px solid #e7ce81; outline-offset: 3px; }
.touch-reader { position: fixed; left: calc(var(--touch-canvas-left) + 64px); right: calc(var(--touch-canvas-right) + 64px); top: calc(var(--touch-canvas-top) + 58px); max-width: 640px; margin: 0 auto; padding: 0 16px 16px; border: 1px solid #a69f795e; border-radius: 2px; background: #17211cf5; box-shadow: 0 5px 24px #0007; pointer-events: auto; z-index: 2; }
.touch-reader header { display: flex; align-items: center; gap: 8px; min-height: 42px; }.touch-reader-title { flex: 1; min-width: 0; color: #e1d2a5; font-size: 13px; font-weight: 600; }
.touch-reader-cue { margin-bottom: 6px; color: #d9c18b; font-size: 25px; line-height: 1.3; font-weight: 700; text-align: center; }
.touch-reader-close { min-width: 40px; min-height: 40px; padding: 4px 8px; border: 0; background: transparent; color: #bebc9f; font: 12px var(--touch-font); touch-action: manipulation; }
.touch-reader-text { max-height: calc(var(--touch-canvas-height) - 134px); overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; color: #dedfce; font-size: 15px; line-height: 1.75; letter-spacing: .015em; touch-action: pan-y; -webkit-user-select: text; user-select: text; overscroll-behavior: contain; scrollbar-width: thin; }
.touch-settings { position: fixed; z-index: 30; top: calc(var(--touch-canvas-top) + 8px); left: calc(var(--touch-canvas-left) + var(--touch-settings-offset, 96px)); }
.touch-settings-toggle { width: 40px; background: #18221991; border-color: #b7b19740; }
.touch-settings-panel { position: absolute; left: 0; top: 46px; width: min(278px, calc(var(--touch-canvas-width) - 112px)); max-height: calc(var(--touch-canvas-height) - 70px); overflow-y: auto; padding: 16px; border: 1px solid #a69f7966; border-radius: 2px; background: #17211cf5; box-shadow: 0 5px 24px #0007; color: #ddd5b8; }
.touch-settings-panel strong { font-size: 14px; }.touch-setting-modes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; margin-top: 14px; }
.touch-settings-panel button { min-height: 40px; border: 1px solid #9b98734d; border-radius: 2px; background: #ffffff06; color: #c8ccb4; font: 13px var(--touch-font); }
.touch-setting-modes .is-selected { border-color: #d4c18a8f; background: #c4b77a26; color: #eddeb2; }
.touch-settings-panel p { margin-top: 12px; color: #a3aa94; font-size: 11px; line-height: 1.65; }.touch-settings-close, .touch-reading-entry { width: 100%; margin-top: 12px; }
.touch-first-hint { position: fixed; left: calc(var(--touch-canvas-left) + var(--touch-canvas-width) / 2); bottom: calc(var(--touch-canvas-bottom) + 12px); transform: translateX(-50%); padding: 7px 12px; color: #d3cdad; background: #1b231ab3; border-top: 1px solid #b8ac7145; font: 11px var(--touch-font); white-space: nowrap; text-shadow: 0 1px 2px #000; }
.mobile-keys { display: none; } html.touch-enabled .desktop-keys { display: none; } html.touch-enabled .mobile-keys { display: block; }
#boot { padding: 24px; text-align: center; } #boot .mobile-keys { max-width: 340px; color: #a6b7c1; font-size: 14px; line-height: 1.85; letter-spacing: .03em; }
/* Native menus and text already accept taps on the canvas. */
.touch-controls[data-context="title"] .touch-navigation, .touch-controls[data-context="title"] .touch-primary,
.touch-controls[data-context="choice"] .touch-navigation, .touch-controls[data-context="choice"] .touch-primary,
.touch-controls[data-context="cards"] .touch-primary, .touch-controls[data-context="menu"] .touch-navigation, .touch-controls[data-context="menu"] .touch-primary { display: none; }
.touch-controls[data-layout="panel"] .touch-dpad { opacity: .62; }
.touch-controls[data-layout="panel"] .touch-navigation { left: calc(var(--touch-canvas-left) + 12px); }
@media (max-height: 360px) { .touch-controls { --touch-stick-size: 88px; }.touch-navigation { bottom: calc(var(--touch-canvas-bottom) + 16px); }.touch-settings-panel { top: 44px; padding: 12px; }.touch-settings-panel p { display: none; } }
/* A portrait phone pauses behind this gate; orientation uses viewport dimensions. */
.touch-orientation-gate[hidden] { display: none !important; }
.touch-orientation-gate { position: fixed; inset: 0; z-index: 1000; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; padding: 32px max(24px, env(safe-area-inset-right, 0px)) 32px max(24px, env(safe-area-inset-left, 0px)); background: radial-gradient(ellipse at 50% 42%, #1b2e2c, #07110f 75%); color: #edf2df; text-align: center; touch-action: none; user-select: none; }
.touch-orientation-gate h2 { font-size: 22px; font-weight: 600; letter-spacing: .06em; }.touch-orientation-gate p { font-size: 14px; color: #adc3b9; }
.touch-rotate-icon { position: relative; width: 110px; height: 110px; margin-bottom: 8px; }
.touch-rotate-phone { position: absolute; left: 31px; top: 20px; width: 44px; height: 72px; border: 3px solid #d4dfc4; border-radius: 9px; transform: rotate(-35deg); box-shadow: inset 0 0 0 4px #819c7c1a; }
.touch-rotate-phone::after { content: ''; position: absolute; width: 12px; height: 3px; bottom: 6px; left: 13px; border-radius: 2px; background: #d4dfc4; }
.touch-rotate-arrow { position: absolute; right: 1px; top: -9px; color: #d7c88c; font-size: 49px; line-height: 1; }
html.touch-portrait-blocked canvas, html.touch-portrait-blocked .touch-controls, html.touch-portrait-blocked .branch-controls { pointer-events: none; }
