/* PJ-09: quiet surround, native game layout, compact header and controls. */
body:has(.arcade-viewport) {
  margin: 0;
  padding: 8px max(8px, env(safe-area-inset-right)) 8px max(8px, env(safe-area-inset-left));
  background: #080b12;
  height: 100dvh;
  box-sizing: border-box;
  overflow: hidden;
}
body:has(.arcade-viewport) > main { height: 100%; display: grid; grid-template-rows: minmax(0, 1fr) auto; gap: 8px; }
.arcade-viewport { width: 100%; max-width: 1100px; height: 100%; min-height: 0; margin: auto; }
.arcade-cabinet { height: 100%; display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: 64px minmax(0, 1fr) 48px; gap: 6px; }
.cabinet-marquee, .cabinet-deck { grid-column: 1; position: relative; overflow: hidden; pointer-events: none; }
.cabinet-marquee img { position: absolute; width: 560px; max-width: none; height: auto; left: 50%; top: -10px; transform: translateX(-50%); }
.cabinet-deck img { position: absolute; width: 700px; max-width: none; height: auto; left: 50%; top: -270px; transform: translateX(-50%); filter: saturate(.4) brightness(.7); }
/* Blend decorative art into the backdrop rather than leaving purple blocks. */
.cabinet-marquee, .cabinet-deck { mask-image: linear-gradient(to right, transparent, black 25%, black 75%, transparent); }
.game-screen-cutout { grid-column: 1; grid-row: 2; min-width: 0; min-height: 0; background: #04060f; border: 1px solid #303642; border-radius: 5px; overflow: hidden; }
.game-screen-cutout #game, .game-screen-cutout .level-view, .game-screen-cutout .intro { height: 100%; box-sizing: border-box; max-width: none; margin: 0; }
.game-screen-cutout .level-view { border: 0; border-radius: 0; }
.game-screen-cutout .cover { height: 100%; box-sizing: border-box; display: flex; flex-direction: column; padding: 10px; margin: 0; max-width: none; border: 0; border-radius: 0; background: #0b1019; }
.game-screen-cutout .cover-art { flex: 1; min-height: 0; aspect-ratio: auto; }
.game-screen-cutout .cover-bg { object-fit: contain; background: #04060f; }
.game-screen-cutout .cover p { margin: 5px 0; font-size: 12px; color: #c3cbd8; }
.game-screen-cutout .cover a { color: #69d1f9; }
.game-screen-cutout .cover-music { flex-shrink: 0; align-self: center; }
.arcade-toolbar { display: flex; align-items: center; justify-content: center; gap: 16px; color: #b9c6df; }
.arcade-toolbar .ai-credit { margin: 0; color: inherit; font-size: 12px; }
.arcade-toolbar a { color: #69d1f9; }
#feedback-open { padding: 8px 12px; border: 1px solid #596476; background: #10151e; color: #fff; border-radius: 4px; cursor: pointer; flex-shrink: 0; }
body:has(#cover:not([hidden])) .arcade-toolbar .ai-credit { display: none; }
@media (max-width: 768px) {
  .arcade-cabinet { grid-template-rows: minmax(0, 1fr); gap: 0; }
  .cabinet-marquee, .cabinet-deck { display: none; }
  .game-screen-cutout { grid-row: 1; border: 0; }
  .arcade-toolbar { gap: 8px; }
  .arcade-toolbar .ai-credit { font-size: 10px; }
  #feedback-open { font-size: 12px; padding: 8px; }
  .game-screen-cutout .cover p { font-size: 10px; }
}
@media (max-height: 700px) and (min-width: 769px) {
  .arcade-cabinet { grid-template-rows: 40px minmax(0, 1fr) 30px; }
}

/* Float the checkpoint card over the lower screen. Only the UI layer
   expands; the playfield, scenery and character coordinates stay fixed. */
#phase-window:has(#question-card:not([hidden])) {
  inset: 0;
  height: auto;
  display: grid;
  justify-items: center;
  align-items: end;
  padding: 8px;
  box-sizing: border-box;
}
#question-card {
  position: relative;
  inset: auto;
  width: min(100%, 770px);
  max-height: 76%;
  min-height: 0;
  box-sizing: border-box;
  padding: 0;
  border: 1px solid #617796;
  border-radius: 9px;
  box-shadow: 0 6px 20px #03091499;
  background: #101b2d;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  overflow: hidden;
  font: 16px/1.45 system-ui, sans-serif;
}
.question-reading { overflow-y: auto; overscroll-behavior: contain; padding: 10px 16px; }
#question-card .dimension { font: 600 13px/1.4 system-ui, sans-serif; text-transform: none; }
#question-card #q-text { font-size: clamp(18px, 2vw, 23px); line-height: 1.25; }
#question-card #anchors { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
#question-card .anchor { margin: 0; padding: 7px 10px; font: inherit; }
#question-card .anchor-body small { color: #d3dfef; font-size: 14px; line-height: 1.35; }
.question-actions { display: flex; align-items: center; justify-content: space-between; padding: 5px 16px; border-top: 1px solid #35455e; }
.question-actions .nav { margin: 0; }
#question-card .question-actions button { font: 600 15px/1.3 system-ui, sans-serif; padding: 7px 12px; }
@media (max-width: 640px) {
  #question-card { max-height: 78%; }
  #question-card #anchors { grid-template-columns: 1fr; }
  .question-reading, .question-actions { padding-inline: 10px; }
}
.question-actions .ask-row { margin: 0; }
.question-hint { font-size: 13px; color: #c1cfe2; margin: 6px 0 0; }

#phone-settings { display: none; }
@media (pointer: coarse) and (orientation: landscape) and (max-height: 540px) {
  body:has(.arcade-viewport) { padding-block: 2px; }
  body:has(.arcade-viewport) > main { gap: 2px; }
  .arcade-cabinet { grid-template-rows: minmax(0, 1fr); gap: 0; }
  .cabinet-marquee, .cabinet-deck, .hud #xp, .hud .progress, .hud #combo { display: none; }
  .game-screen-cutout { grid-row: 1; }
  .game-screen-cutout .level-view { --ui-strip: 0px; }
  .world, .plx { top: 36px; }
  .rocket { transition: none; }
  #phase-window { height: 100%; }
  #phase-window .phase { max-height: 45%; }
  #phase-window #question-card { max-height: calc(100% - 36px); }
  .game-screen-cutout .level-view::after { display: none; }
  .arcade-toolbar { gap: 8px; }
  .arcade-toolbar .ai-credit { font-size: 10px; }
  #feedback-open { padding: 4px 8px; }
}

@media (pointer: coarse) and (max-width: 540px), (pointer: coarse) and (max-height: 540px) {
  .hud #xp, .hud .progress, .hud #combo { display:none; }
  .hud { box-sizing: border-box; height: 36px; padding: 0 8px; flex-wrap: nowrap; gap: 12px; }
  .hud .energy { width: 56px; height: 9px; }
  .hud #warn { position: absolute; top: 100%; right: 4px; background: #101b2d; }
  #phone-settings { display: block; margin-left: auto; order: 1; position: relative; }
  #phone-settings summary { cursor: pointer; padding: 11px 8px; }
  #phone-settings div { position: absolute; top: 100%; right: 0; width: max-content; padding: 6px; background: #101b2d; border: 1px solid #8bdcf5; }
  #phone-settings button { display: block; width: 100%; min-height: 40px; }
}
/* Portrait duel worlds: reserve the lower deck even between encounters. */
@media (pointer: coarse) and (orientation: portrait) and (max-width: 540px) {
  .level-view.handheld-deck { --ui-strip: 50%; }
  .handheld-deck :is(.world, .plx) { top: 36px; }
  .handheld-deck #phase-window,
  .handheld-deck #phase-window:has(#question-card:not([hidden])) {
    inset: auto 0 0; height: var(--ui-strip); box-sizing: border-box;
    display: block; padding: 8px; background: #111925; border-top: 3px solid #435367;
  }
  .handheld-deck #phase-window > .phase {
    position:relative; inset:auto; width:100%; height:100%; max-height:100%;
    box-sizing:border-box; margin:0;
  }
  .handheld-deck .tactical-actions { grid-template-columns:repeat(3,minmax(0,1fr)); gap:6px; }
  .handheld-deck .tactical-actions button { min-height:46px; padding:6px 2px; box-shadow:0 3px 0 #070c19; }
  .handheld-deck #skip-tactical { grid-column:1 / -1; justify-self:center; }
  .handheld-deck .duel-result { top:52%; z-index:5; }
  .handheld-deck .question-hint { display:none; }
  .handheld-deck .rocket { transition:none; }
}

@media (pointer: coarse) and (orientation: portrait) and (max-width: 540px) {
  /* Match setCamera's two-viewport coordinate system in the handheld world. */
  .handheld-deck .world.tactical-world {
    width: 200%;
    transform: translateX(var(--camera-offset, 0%)) !important;
  }
  .handheld-deck .rocket { left: var(--ship-exit) !important; }
  .handheld-deck .rocket.landing .ship-sheet { animation: none; }
  .handheld-deck .traveler.aboard { opacity: 1; }
  .level-view.handheld-deck:has(#question-card:not([hidden])) { --ui-strip: 57%; }
  .handheld-deck #phase-window { container-type: size; }
  .handheld-deck #question-card .question-reading { min-height: 0; padding: 4px 8px; }
  .handheld-deck #question-card #q-text { font-size: clamp(16px, 4.6cqi, 21px); line-height: 1.2; margin: 4px 0; }
  .handheld-deck #question-card .anchor { font-size: clamp(14px, 3.8cqi, 17px); line-height: 1.18; padding: 4px 6px; }
  .handheld-deck #question-card .anchor-body small { font-size: clamp(13px, 3.4cqi, 16px); line-height: 1.22; }
  .handheld-deck .guide-say, .handheld-deck #battle-status { font-size: clamp(10px, 3cqi, 13px); line-height: 1.45; }
}

@media (pointer: coarse) and (orientation: portrait) and (max-width: 540px) {
  .handheld-deck :is(#enemy-intent, #guess-target) { font-size: clamp(10px, 2.8cqi, 12px); line-height: 1.5; }
  .handheld-deck :is(#battle-status, #guess-status) { font: clamp(14px, 3.6cqi, 16px)/1.4 system-ui, sans-serif; }
  .handheld-deck :is(.tactical-actions, .guess-actions) button { font: 10px/1.4 "Press Start 2P", monospace; }
  .handheld-deck .guess-actions { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 5px; }
  .handheld-deck .guess-actions button { min-width: 0; min-height: 44px; padding-inline: 2px; }
  .handheld-deck #skip-guess { grid-column: 1 / -1; justify-self: center; padding-inline: 12px; }
}

/* Give touch players a compact language row beneath the artwork. */
@media (pointer: coarse) and (max-width: 1024px), (pointer: coarse) and (max-height: 540px) {
  .cover-art { display: grid; grid-template-rows: minmax(0, 1fr) auto; background: #04060f; }
  .cover-art .cover-bg { min-height: 0; }
  .cover-art .cover-buttons { position: static; padding: 4px; gap: 8px; flex-wrap: nowrap; }
  .cover-buttons button { flex: 1; min-width: 0; min-height: 44px; padding: 4px 6px; font: 700 clamp(13px, 2vw, 15px)/1.2 system-ui, sans-serif; }
  .cover-art .cover-robot { bottom: 54px; }
}
