/* Phone layout is selected from viewport and pointing-device capabilities. */
.mobile-only { display: none; }
#primary-touch-surface { display: none; position: absolute; inset: 0; z-index: 2; touch-action: none; -webkit-user-select: none; user-select: none; }
[data-mobile="true"][data-ds-primary="lower"][data-ds-view="split"] #primary-touch-surface { display: block; }
.touch-controls { -webkit-user-select: none; user-select: none; }
[data-mobile="true"] .mobile-only { display: flex; }
[data-mobile="true"].pixel-app { height: 100svh; height: 100dvh; min-height: 0; padding: max(6px,env(safe-area-inset-top)) max(6px,env(safe-area-inset-right)) max(6px,env(safe-area-inset-bottom)) max(6px,env(safe-area-inset-left)); overflow: hidden; }
[data-mobile="true"] .app-shell { height: 100%; min-height: 0; border-width: 1px; box-shadow: none; }
[data-mobile="true"] .home-screen { height: 100%; min-height: 0; padding: 80px 16px 24px; }
[data-mobile="true"] .home-brand { gap: 10px; margin-top: -16px; margin-bottom: 28px; }
[data-mobile="true"] .home-brand img { width: 52px; height: auto; }
[data-mobile="true"] .brand-wordmark { font-size: clamp(36px,12.2vw,52px); }
[data-mobile="true"] .menu-options { gap: 18px; }
[data-mobile="true"] .language-options { grid-template-columns: repeat(2,minmax(0,1fr)); gap: 8px; }
[data-mobile="true"] .language-option:last-child { grid-column: 1 / -1; }
[data-mobile="true"] .language-option > span { min-height: 46px; padding: 8px; }
[data-mobile="true"] .console-options { grid-template-columns: 1fr; gap: 12px; }
[data-mobile="true"] .console-card { flex-direction: row; min-height: 80px; padding: 10px 16px; gap: 16px; justify-content: flex-start; text-align: left; }
[data-mobile="true"] .console-card > svg { width: 84px; height: 56px; }
/* Reserve the reading area before the first capture. Its content must never
   take height away from the game while loading, succeeding or failing. */
[data-mobile="true"] .workspace { --mobile-reader-height: clamp(160px,34dvh,300px); height: 100%; min-height: 0; display: grid; grid-template-columns: minmax(0,1fr); grid-template-rows: auto minmax(96px,1fr) var(--mobile-reader-height) auto; overflow: hidden; }
[data-mobile="true"][data-reader-folded="true"] .workspace { --mobile-reader-height: auto; }
[data-mobile="true"] #mobile-toolbar { grid-row: 1; min-width: 0; }
[data-mobile="true"] .play-panel { grid-row: 2; border: 0; min-height: 0; }
[data-mobile="true"] .console-stage { flex: 1; min-height: 0; height: 100%; aspect-ratio: auto; padding: 10px 12px; }
[data-mobile="true"] .ds-display { box-shadow: 0 0 0 2px var(--shadow),0 0 0 3px var(--edge-light); }
[data-mobile="true"] .empty-actions { gap: 8px; padding: 8px; }
[data-mobile="true"] .empty-art { width: 72px; height: 48px; }
[data-mobile="true"] .empty-actions .text-button { font-size: 12px; min-height: 28px; }
[data-mobile="true"] .empty-actions .pixel-button { min-height: 42px; }
[data-mobile="true"] .player-dock { width: 100%; padding: 5px 8px 7px; border-top: 0; border-bottom: 1px solid var(--edge); }
[data-mobile="true"] .main-actions { display: flex; flex-wrap: nowrap; justify-content: space-between; gap: 6px; }
[data-mobile="true"] .control-group, [data-mobile="true"] .checkpoint-actions { display: contents; }
[data-mobile="true"] .main-actions > *, [data-mobile="true"] .main-actions .pixel-button { flex: 1; }
[data-mobile="true"] .main-actions .pixel-button { min-height: 42px; width: auto; padding: 8px; gap: 0; font-size: 0; }
[data-mobile="true"] .main-actions .pixel-button span { font-size: 0; }
[data-mobile="true"] .main-actions .icon { width: 18px; height: 18px; }
[data-mobile="true"] .volume-control { flex: 1; }
[data-mobile="true"] .volume-popover { top: 100%; bottom: auto; right: 0; padding: 10px 0 0; }
[data-mobile="true"] .mode-test-indicator { position: absolute; right: 8px; bottom: -15px; z-index: 2; margin: 0; font-size: 12px; pointer-events: none; }
[data-mobile="true"] .game-notice { top: calc(100% + 6px); bottom: auto; font-size: 18px; z-index: 30; }
[data-mobile="true"] .translation-panel { grid-row: 3; display: flex; padding: 6px 10px 8px; border-top: 1px solid var(--edge); min-height: 0; overflow: hidden; }
[data-mobile="true"] .mobile-reader-toolbar { flex: none; display: grid; grid-template-columns: minmax(0,1fr) 44px; gap: 8px; padding-bottom: 8px; }
[data-mobile="true"] #mobile-translate-slot { min-width: 0; }
[data-mobile="true"] .capture-button { width: 100%; min-height: 44px; margin: 0; font-size: 24px; }
[data-mobile="true"] .capture-button kbd { display: none; }
[data-mobile="true"] #toggle-mobile-reader { width: 44px; min-height: 44px; }
[data-mobile="true"] #toggle-mobile-reader .icon { transform: rotate(180deg); }
[data-mobile="true"][data-reader-folded="true"] #toggle-mobile-reader .icon { transform: none; }
[data-mobile="true"][data-reader-folded="true"] .translation-body { display: none; }
[data-mobile="true"][data-reader-folded="true"] .translation-status { display: none; }
[data-mobile="true"][data-reader-folded="true"] .translation-panel { padding-bottom: 0; }
[data-mobile="true"] .translation-body { overflow-y: auto; min-height: 0; padding: 0 3px 2px 0; }
[data-mobile="true"] .translation-intro { display: none; }
[data-mobile="true"] .reading-card { padding: 8px 10px; box-shadow: none; border-width: 1px; }
[data-mobile="true"] .translation-status { font-size: 12px; line-height: 1.5; margin-bottom: 6px; max-height: 54px; overflow-y: auto; }
[data-mobile="true"] .guest-trial-status { margin: 0 0 6px; font-size: 14px; }
[data-mobile="true"] .read-aloud { width: 44px; min-height: 44px; margin-top: 0; }
[data-mobile="true"] .history-panel { margin-top: 6px; }
[data-mobile="true"] .history-panel > summary, [data-mobile="true"] .capture-details > summary { min-height: 40px; }
[data-mobile="true"] .history-panel > summary { font-size: 18px; }
[data-mobile="true"] .translation-note { margin-block: 6px; }
[data-mobile="true"] .capture-details { margin-top: 8px; padding-top: 2px; }
[data-mobile="true"] .touch-controls { --pad-size: clamp(104px,30vw,132px); grid-row: 4; padding: 8px 10px 6px; border-top: 2px solid var(--edge); background: var(--surface); touch-action: none; -webkit-touch-callout: none; }
.touch-shoulders { display: grid; grid-template-columns: 1fr auto 1fr; gap: 12px; align-items: center; margin-bottom: 6px; }
.touch-key { display: grid; place-items: center; padding: 0; border: 2px solid var(--edge-light); border-radius: 0; background: var(--raised); color: var(--ink); box-shadow: inset 2px 2px 0 #ffffff0b,0 3px 0 var(--shadow); font: inherit; font-size: 24px; line-height: 1; touch-action: none; -webkit-user-select: none; user-select: none; }
.touch-key:disabled { opacity: .4; }
.touch-key[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); box-shadow: inset 0 3px 0 #0002; }
.touch-shoulder { width: min(100%,104px); min-height: 36px; }
.touch-shoulder:last-child { justify-self: end; }
#touch-swap-slot:empty { width: 84px; }
[data-mobile="true"] #swap-screens { min-height: 36px; padding: 6px 8px; font-size: 18px; box-shadow: none; }
.touch-main { display: grid; grid-template-columns: calc(var(--pad-size) + 12px) minmax(0,1fr) var(--pad-size); align-items: center; gap: 8px; }
.touch-dpad { width: calc(var(--pad-size) + 8px); height: calc(var(--pad-size) + 8px); margin: 4px 0 0 4px; display: grid; grid-template-columns: repeat(3,1fr); grid-template-rows: repeat(3,1fr); touch-action: none; }
.touch-dpad .touch-key { box-shadow: none; border-color: var(--edge); }
.touch-up { grid-area: 1 / 2; border-bottom: 0; }
.touch-down { grid-area: 3 / 2; border-top: 0; }
.touch-left { grid-area: 2 / 1; border-right: 0; }
.touch-right { grid-area: 2 / 3; border-left: 0; }
.touch-up .icon { transform: rotate(180deg); }
.touch-left .icon { transform: rotate(90deg); }
.touch-right .icon { transform: rotate(-90deg); }
.touch-dpad-center { grid-area: 2 / 2; background: var(--raised); display: grid; place-items: center; pointer-events: none; }
.touch-dpad-center::after { content: ''; width: 8px; height: 8px; border: 2px solid var(--edge-light); }
.touch-center { min-width: 0; display: grid; place-items: center; }
.touch-face { position: relative; width: var(--pad-size); height: var(--pad-size); }
.touch-face .touch-key { position: absolute; width: 44px; height: 44px; clip-path: polygon(8px 0,calc(100% - 8px) 0,100% 8px,100% calc(100% - 8px),calc(100% - 8px) 100%,8px 100%,0 calc(100% - 8px),0 8px); }
.touch-x { top: 0; left: calc(50% - 22px); }
.touch-y { left: 0; top: calc(50% - 22px); }
.touch-b { bottom: 0; left: calc(50% - 22px); }
.touch-a { right: 0; top: calc(50% - 22px); background: var(--device-edge); }
.touch-system { display: flex; justify-content: center; gap: 16px; margin-top: 5px; }
.touch-system .touch-key { min-width: 70px; min-height: 36px; padding: 6px 10px; font-size: 18px; }
[data-console="gbc"] .touch-shoulders { display: none; }
[data-console]:not([data-console="ds"]) .touch-x, [data-console]:not([data-console="ds"]) .touch-y { display: none; }
[data-console]:not([data-console="ds"]) .touch-b { left: 0; bottom: 12px; }
[data-console]:not([data-console="ds"]) .touch-a { top: 14px; }
[data-mobile="true"] .secondary-screen { width: 100%; order: initial; align-self: auto; margin: 0; padding: 2px; border-width: 1px; box-shadow: none; }
[data-mobile="true"] .mobile-session-actions { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 18px; }
[data-mobile="true"] .mobile-session-actions .pixel-button { min-height: 44px; }
[data-mobile="true"] #open-controls { width: auto; gap: 8px; }
[data-mobile="true"] #open-controls::after { content: 'Commandes'; }
[data-mobile="true"] dialog { width: calc(100% - 28px); max-height: calc(100dvh - 40px); font-size: 20px; padding: 18px; }
[data-mobile="true"] dialog select { font-size: 18px; min-height: 44px; }
[data-mobile="true"] dialog .text-button { min-height: 44px; }
[data-mobile="true"] .workspace:fullscreen { height: 100dvh; padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); overflow: hidden; }
@media (max-height: 700px) and (orientation: portrait) {
  [data-mobile="true"] .touch-controls { --pad-size: 104px; padding-block: 5px; }
  [data-mobile="true"] .workspace { --mobile-reader-height: clamp(100px,calc(100dvh - 380px),180px); }
}
@media (orientation: portrait) {
  /* Width determines the native game screen first. The reading area receives
     the remaining height, independently of its text and of Safari's toolbar.
     On unusually short displays, scrolling is preferable to shrinking the game. */
  [data-mobile="true"] .workspace { grid-template-rows: auto max-content minmax(104px,1fr) max-content; overflow-y: auto; scrollbar-width: none; }
  [data-mobile="true"] .workspace::-webkit-scrollbar { display: none; }
  [data-mobile="true"] .play-panel { display: block; }
  [data-mobile="true"] .console-stage { flex: none; box-sizing: content-box; width: calc(100% - 8px); height: auto; aspect-ratio: 4/3; padding: 4px; }
  [data-mobile="true"][data-console="gbc"] .console-stage { aspect-ratio: 10/9; }
  [data-mobile="true"][data-console="gba"] .console-stage { aspect-ratio: 3/2; }
  [data-mobile="true"][data-ds-view="stacked"] .console-stage { aspect-ratio: 2/3; }
  [data-mobile="true"][data-reader-folded="true"] .workspace { grid-template-rows: auto max-content auto minmax(min-content,1fr); }
  [data-mobile="true"][data-reader-folded="true"] .touch-controls { display: grid; align-content: end; }
  /* GBC has no shoulders: keep the pad and A aligned, with Select/Start
     below A/B instead of reserving a separate full-width bottom row. */
  [data-mobile="true"][data-console="gbc"] .touch-controls { display: grid; grid-template-columns: calc(var(--pad-size) + 12px) minmax(0,1fr) max(148px,var(--pad-size)); grid-template-rows: calc(var(--pad-size) - 36px) 36px; gap: 8px 4px; }
  [data-mobile="true"][data-console="gbc"] .touch-main { display: contents; }
  [data-mobile="true"][data-console="gbc"] .touch-dpad { grid-column: 1; grid-row: 1 / 3; margin-block: 0; }
  [data-mobile="true"][data-console="gbc"] .touch-center { display: none; }
  [data-mobile="true"][data-console="gbc"] .touch-face { grid-column: 3; grid-row: 1; justify-self: end; height: 100%; }
  [data-mobile="true"][data-console="gbc"] .touch-a { top: 0; }
  [data-mobile="true"][data-console="gbc"] .touch-b { bottom: 0; }
  [data-mobile="true"][data-console="gbc"] .touch-system { grid-column: 3; grid-row: 2; justify-content: flex-end; gap: 8px; margin: 0; }
}
@media (orientation: landscape) {
  [data-mobile="true"] .workspace { grid-template-columns: 54px minmax(0,1fr) clamp(300px,44vw,420px); grid-template-rows: minmax(0,1fr) auto; }
  [data-mobile="true"] #mobile-toolbar { grid-area: 1 / 1 / -1 / 2; }
  [data-mobile="true"] .player-dock { display: flex; align-items: center; height: 100%; padding: 6px 4px; border-bottom: 0; border-right: 1px solid var(--edge); }
  [data-mobile="true"] .main-actions { width: 100%; flex-direction: column; justify-content: center; gap: 8px; }
  [data-mobile="true"] .main-actions .pixel-button, [data-mobile="true"] .volume-control { flex: none; width: 44px; }
  [data-mobile="true"] .volume-popover { top: 0; left: 100%; right: auto; padding: 0 0 0 8px; }
  [data-mobile="true"] .game-notice { top: 6px; left: calc(100% + 6px); bottom: auto; right: auto; width: min(280px,60vw); }
  [data-mobile="true"] .play-panel { grid-area: 1 / 2 / -1 / 3; }
  [data-mobile="true"] .translation-panel { grid-area: 1 / 3 / 2 / 4; max-height: none; border-left: 1px solid var(--edge); border-top: 0; padding-block: 4px; }
  [data-mobile="true"] .mobile-reader-toolbar { padding-bottom: 5px; }
  [data-mobile="true"] .touch-controls { --pad-size: 104px; grid-area: 2 / 3 / 3 / 4; padding: 5px 10px; border-left: 1px solid var(--edge); }
  [data-mobile="true"] .touch-shoulders { margin-bottom: 4px; }
  [data-mobile="true"] .touch-system { margin-top: 3px; }
  [data-mobile="true"][data-reader-folded="true"] .workspace { grid-template-rows: var(--mobile-reader-height) minmax(0,1fr); }
  [data-mobile="true"][data-reader-folded="true"] .touch-controls { align-content: center; display: grid; }
  [data-mobile="true"] .home-screen { padding: 48px 24px 18px; }
  [data-mobile="true"] .menu-options { gap: 14px; max-width: 850px; }
  [data-mobile="true"] .home-brand { margin: 0; }
  [data-mobile="true"] .brand-wordmark { font-size: 36px; }
  [data-mobile="true"] .home-brand img { width: 36px; height: auto; }
  [data-mobile="true"] .language-options { grid-template-columns: repeat(5,minmax(0,1fr)); }
  [data-mobile="true"] .language-option:last-child { grid-column: auto; }
  [data-mobile="true"] .console-options { grid-template-columns: repeat(3,minmax(0,1fr)); }
  [data-mobile="true"] .console-card { gap: 8px; min-height: 76px; padding: 10px; font-size: 18px; }
  [data-mobile="true"] .console-card > svg { width: 60px; height: 40px; }
}

/* Portrait: commands overlay the game; only the reading area gains the space.
   Opening either panel never participates in the game's sizing grid. */
.menu-close-icon { display: none; }
[data-mobile-menu="true"] .workspace { grid-template-rows: max-content minmax(104px,1fr) max-content; }
[data-mobile-menu="true"] .play-panel { grid-row: 1; position: relative; }
[data-mobile-menu="true"] .translation-panel { grid-row: 2; overflow: visible; position: relative; }
[data-mobile-menu="true"] .touch-controls { grid-row: 3; }
[data-mobile-menu="true"][data-reader-folded="true"] .workspace { grid-template-rows: max-content auto minmax(min-content,1fr); }
[data-mobile-menu="true"] .mobile-reader-toolbar { position: relative; z-index: 3; grid-template-columns: 44px minmax(0,1fr) 44px; }
[data-mobile-menu="true"] .capture-button { gap: 10px; }
[data-mobile-menu="true"] .translation-actions:has(.study-reminder:not([hidden])) .capture-button { gap: 6px; padding-inline: 4px; font-size: 20px; }
[data-mobile-menu="true"] #mobile-menu-toggle { width: 44px; min-height: 44px; }
[data-mobile-menu="true"] #mobile-menu-toggle .icon { width: 18px; height: 18px; }
[data-mobile-menu-open="true"] #mobile-menu-toggle { color: var(--accent); border-color: var(--accent); background: var(--surface); }
[data-mobile-menu-open="true"] #mobile-menu-toggle .menu-open-icon { display: none; }
[data-mobile-menu-open="true"] #mobile-menu-toggle .menu-close-icon { display: block; }
[data-mobile-menu="true"] #mobile-toolbar { position: absolute; bottom: calc(100% + 6px); left: -4px; right: -4px; display: block; border: 2px solid var(--edge-light); background: var(--surface); box-shadow: 0 4px 0 var(--shadow); opacity: 0; visibility: hidden; transform: translateY(6px); transition: opacity 120ms ease,transform 120ms ease,visibility 120ms; }
[data-mobile-menu="true"][data-mobile-menu-open="true"] #mobile-toolbar { opacity: 1; visibility: visible; transform: translateY(0); }
[data-mobile-menu="true"] .player-dock { padding: 7px; border: 0; }
[data-mobile-menu="true"] .main-actions { gap: 6px; }
[data-mobile-menu="true"] .main-actions .pixel-button { min-height: 44px; }
[data-mobile-menu="true"] .main-actions .volume-control { min-width: 0; }
[data-mobile-menu="true"] #mobile-volume-toggle[aria-expanded="true"] { color: var(--accent); border-color: var(--accent); }
[data-mobile-menu="true"] #mobile-volume-toggle[data-muted="true"] .icon { opacity: .4; }
[data-mobile-menu="true"] .volume-popover { display: block; position: static; width: 100%; padding: 0 4px 10px; margin-bottom: 8px; border-bottom: 1px solid var(--edge); }
[data-mobile-menu="true"] .volume-panel { padding: 0; border: 0; box-shadow: none; background: var(--surface); font-size: 18px; grid-template-columns: 44px minmax(0,1fr) auto; gap: 6px 12px; }
[data-mobile-menu="true"] .volume-panel label { grid-row: 1; grid-column: 1 / 3; }
[data-mobile-menu="true"] .volume-panel output { grid-row: 1; grid-column: 3; color: var(--accent); }
[data-mobile-menu="true"] .volume-panel #mute-game { grid-row: 2; grid-column: 1; width: 44px; min-height: 44px; }
[data-mobile-menu="true"] .volume-panel input { grid-row: 2; grid-column: 2 / -1; height: 44px; border: 0; background: transparent; padding: 0; touch-action: pan-y; }
[data-mobile-menu="true"] .volume-panel input::-webkit-slider-runnable-track { height: 8px; background: var(--shadow); border: 1px solid var(--edge-light); }
[data-mobile-menu="true"] .volume-panel input::-webkit-slider-thumb { width: 18px; height: 26px; margin-top: -10px; border-radius: 0; }
[data-mobile-menu="true"] .volume-panel input::-moz-range-track { height: 6px; background: var(--shadow); border: 1px solid var(--edge-light); }
[data-mobile-menu="true"] .volume-panel input::-moz-range-thumb { width: 14px; height: 22px; border-radius: 0; }
[data-mobile-menu="true"] .play-panel > .game-notice { top: 8px; bottom: auto; }
@media (prefers-reduced-motion: reduce) { [data-mobile-menu="true"] #mobile-toolbar { transition: none; } }
@media (max-width: 360px) { [data-mobile-menu="true"] .translation-actions:has(.study-reminder:not([hidden])) .capture-button .icon { display: none; } }
