/* CALLORIA v6.80 — mobile state, viewport and control-layer repair.
   Additive override. Existing application and gameplay modules remain in place. */

:root {
  --calloria-v680-visible-height: 100dvh;
  --calloria-v680-safe-bottom: env(safe-area-inset-bottom, 0px);
  --calloria-v680-safe-top: env(safe-area-inset-top, 0px);
}

/* The game launch card must only exist in the explicit launch state.
   It must not survive when assessment or normal application views are active. */
#gameLaunchScreen {
  display: none !important;
  visibility: hidden !important;
  pointer-events: none !important;
}

body.calloria-game-launch:not(.calloria-game-playing):not(.calloria-assessment-mode) #gameLaunchScreen {
  display: grid !important;
  visibility: visible !important;
  pointer-events: auto !important;
}

body:not(.calloria-game-launch) #gameLaunchScreen,
body.calloria-assessment-mode #gameLaunchScreen,
body.calloria-game-launch.calloria-assessment-mode #gameLaunchScreen,
body.calloria-game-playing #gameLaunchScreen {
  display: none !important;
  visibility: hidden !important;
  pointer-events: none !important;
}

/* Keep phone layouts inside the visible viewport as browser chrome expands/collapses. */
@media (max-width: 760px), (pointer: coarse) {
  html,
  body {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    overflow-x: clip;
  }

  body.calloria-immersive {
    height: var(--calloria-v680-visible-height, 100dvh) !important;
    min-height: 0 !important;
    overflow: hidden !important;
    overscroll-behavior: none;
    touch-action: manipulation;
  }

  body.calloria-immersive .app-shell,
  body.calloria-immersive .main-area {
    width: 100vw !important;
    height: var(--calloria-v680-visible-height, 100dvh) !important;
    min-width: 0 !important;
    min-height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
  }

  body.calloria-immersive .world-panel.is-immersive {
    position: fixed !important;
    inset: 0 auto auto 0 !important;
    z-index: 50 !important;
    display: block !important;
    width: 100vw !important;
    height: var(--calloria-v680-visible-height, 100dvh) !important;
    min-height: 0 !important;
    max-height: none !important;
    margin: 0 !important;
    border: 0 !important;
    border-radius: 0 !important;
    overflow: hidden !important;
    contain: layout paint size;
  }

  body.calloria-immersive .world-panel.is-immersive #worldCanvas {
    position: absolute !important;
    inset: 0 !important;
    display: block !important;
    width: 100vw !important;
    height: var(--calloria-v680-visible-height, 100dvh) !important;
    min-height: 0 !important;
    max-height: none !important;
    overflow: hidden !important;
    touch-action: none;
  }

  body.calloria-immersive .world-panel.is-immersive #worldCanvas > canvas {
    display: block !important;
    width: 100% !important;
    height: 100% !important;
    max-width: none !important;
    max-height: none !important;
    touch-action: none;
  }

  body.calloria-immersive .world-panel.is-immersive .world-vignette {
    position: absolute !important;
    inset: 0 !important;
    pointer-events: none !important;
  }

  /* The developer diagnostic card covered most of the playable scene on phones.
     Full model diagnostics remain available from /asset-inspector.html. */
  body.calloria-immersive #calloriaGlbAudit {
    display: none !important;
    visibility: hidden !important;
    pointer-events: none !important;
  }

  /* Remove the desktop Graphics tuning overlay from the limited mobile HUD. */
  body.calloria-immersive .world-panel.is-immersive > button[aria-expanded],
  body.calloria-immersive .world-panel.is-immersive > button[aria-expanded] + section {
    display: none !important;
    visibility: hidden !important;
    pointer-events: none !important;
  }

  body.calloria-immersive #immersiveHud {
    position: absolute !important;
    inset: 0 !important;
    z-index: 20 !important;
    width: 100% !important;
    height: 100% !important;
    min-height: 0 !important;
    pointer-events: none;
  }

  body.calloria-immersive .immersive-topline {
    position: absolute !important;
    top: max(8px, var(--calloria-v680-safe-top)) !important;
    left: 10px !important;
    right: 10px !important;
    display: flex !important;
    align-items: flex-start !important;
    justify-content: space-between !important;
    gap: 8px !important;
    pointer-events: none;
  }

  body.calloria-immersive .immersive-location {
    min-width: 0 !important;
    max-width: calc(100% - 120px) !important;
    overflow: hidden;
  }

  body.calloria-immersive .immersive-location strong,
  body.calloria-immersive .immersive-location small {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  body.calloria-immersive .immersive-exit {
    flex: 0 0 auto !important;
    min-width: 104px !important;
    min-height: 44px !important;
    padding: 8px 11px !important;
    pointer-events: auto !important;
    touch-action: manipulation;
  }

  body.calloria-immersive .immersive-bottomline {
    display: none !important;
  }

  body.calloria-immersive #touchControls {
    position: absolute !important;
    inset: auto 0 0 0 !important;
    z-index: 25 !important;
    display: flex !important;
    align-items: flex-end !important;
    justify-content: space-between !important;
    gap: 8px !important;
    width: 100% !important;
    box-sizing: border-box !important;
    padding: 0 14px calc(12px + var(--calloria-v680-safe-bottom)) !important;
    pointer-events: none;
  }

  body.calloria-immersive .touch-movement,
  body.calloria-immersive .touch-actions,
  body.calloria-immersive .touch-joystick,
  body.calloria-immersive .touch-game-button {
    pointer-events: auto !important;
    touch-action: none;
  }

  body.calloria-immersive .touch-movement {
    display: flex !important;
    flex: 0 0 auto !important;
    flex-direction: column !important;
    align-items: center !important;
    gap: 5px !important;
    min-width: 0 !important;
  }

  body.calloria-immersive .touch-joystick {
    width: clamp(104px, 28vw, 132px) !important;
    height: clamp(104px, 28vw, 132px) !important;
    max-width: 34vw !important;
    max-height: 34vw !important;
  }

  body.calloria-immersive .touch-joystick-knob {
    width: 44% !important;
    height: 44% !important;
  }

  body.calloria-immersive .touch-control-caption {
    font-size: 9px !important;
    line-height: 1.2 !important;
    letter-spacing: 1px !important;
  }

  body.calloria-immersive .touch-look-caption {
    display: none !important;
  }

  body.calloria-immersive .touch-actions {
    display: flex !important;
    flex: 0 0 auto !important;
    align-items: flex-end !important;
    gap: 9px !important;
    min-width: 0 !important;
  }

  body.calloria-immersive .touch-game-button {
    width: clamp(66px, 18vw, 82px) !important;
    height: clamp(66px, 18vw, 82px) !important;
    min-width: 66px !important;
    min-height: 66px !important;
    max-width: 22vw !important;
    max-height: 22vw !important;
    padding: 6px !important;
    border-radius: 20px !important;
    box-sizing: border-box !important;
    font-size: 10px !important;
  }

  body.calloria-immersive .touch-game-button.interact span {
    font-size: 25px !important;
    line-height: 1 !important;
  }

  body.calloria-immersive .touch-game-button.interact small {
    font-size: 9px !important;
    line-height: 1.1 !important;
  }

  body.calloria-immersive .station-hint {
    position: absolute !important;
    left: 10px !important;
    right: 10px !important;
    bottom: calc(156px + var(--calloria-v680-safe-bottom)) !important;
    z-index: 28 !important;
    width: auto !important;
    max-width: none !important;
    box-sizing: border-box !important;
  }

  body.calloria-immersive .station-panel {
    position: absolute !important;
    left: 10px !important;
    right: 10px !important;
    bottom: calc(156px + var(--calloria-v680-safe-bottom)) !important;
    z-index: 30 !important;
    width: auto !important;
    max-width: none !important;
    max-height: min(48%, 380px) !important;
    box-sizing: border-box !important;
    overflow: auto !important;
    overscroll-behavior: contain;
  }

  body.calloria-immersive #mouseLookNote {
    position: absolute !important;
    top: calc(62px + var(--calloria-v680-safe-top)) !important;
    left: 10px !important;
    right: 10px !important;
    z-index: 27 !important;
    width: auto !important;
    max-width: none !important;
  }

  body.calloria-assessment-mode .content-wrap,
  body.calloria-assessment-mode .view-root {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    overflow-x: clip !important;
  }

  body.calloria-assessment-mode .assessment-footer,
  body.calloria-assessment-mode .assessment-actions,
  body.calloria-assessment-mode .question-actions {
    position: sticky !important;
    bottom: 0 !important;
    z-index: 12 !important;
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 8px !important;
    width: 100% !important;
    box-sizing: border-box !important;
    padding: 10px 0 calc(10px + var(--calloria-v680-safe-bottom)) !important;
    background: linear-gradient(180deg, rgba(7,18,29,0), rgba(7,18,29,.97) 28%) !important;
  }
}

@media (max-width: 390px) {
  body.calloria-immersive .immersive-location strong {
    font-size: 9px !important;
  }
  body.calloria-immersive .immersive-exit {
    min-width: 96px !important;
    font-size: 9px !important;
  }
  body.calloria-immersive #touchControls {
    padding-left: 10px !important;
    padding-right: 10px !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  body.calloria-immersive *,
  body.calloria-immersive *::before,
  body.calloria-immersive *::after {
    scroll-behavior: auto !important;
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
}
