/*
 * Touch controls for the 3D laboratory (touch-controls.js).
 * Everything here applies only when <html> has the .touch-controls class
 * (phones and tablets, or ?touch=1). "Playing" = #game-screen.pointer-active.
 */

/* Hidden unless touch mode is on. */
.key-guide--touch, .touch-rotate-tip, .touch-toolbar, .touch-layer, .touch-close { display: none; }

.touch-controls .key-guide--keyboard { display: none; }
.touch-controls .key-guide--touch { display: flex; }
.touch-controls .enter-3d .mouse-icon { display: none; }
@media (orientation: portrait) {
  .touch-controls .touch-rotate-tip { display: block; margin: -14px 20px 18px; color: #f5c451; font: 600 13px Manrope, sans-serif; }
}

/* No page scrolling, zooming, text selection or long-press menus over the 3D view. */
.touch-controls #game-screen { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.touch-controls #three-container canvas { touch-action: none; }
.touch-controls #game-screen button { touch-action: manipulation; }

/* ---- Top bar ---- */
/* Above the start / paused screen too: there is no Q key, so LEVELS must stay tappable. */
.touch-controls .game-hud { z-index: 16; height: 56px; padding: 0 12px; }
.touch-controls .hud-status { display: none; }
.touch-controls #exit-game kbd { display: none; }
.touch-controls #exit-game span { display: inline; }
.touch-controls #exit-game { min-height: 42px; padding: 0 14px; }
.touch-controls .mission-title strong { font-size: 15px; }
.touch-controls .touch-toolbar { display: flex; gap: 8px; margin-left: auto; }
.touch-tool { width: 42px; height: 42px; display: grid; place-items: center; padding: 0; color: #e9ffff; background: rgba(5,18,28,.78); border: 1px solid rgba(84,223,215,.45); border-radius: 50%; font: 700 14px Manrope, sans-serif; cursor: pointer; }
.touch-tool:active { background: rgba(84,223,215,.25); }
.touch-tool--full.is-on { border-color: #f5c451; color: #f5c451; }

/* ---- The layer with the stick and the buttons (only while playing) ---- */
.touch-controls #game-screen.pointer-active:not(.level-menu-background) .touch-layer { display: block; }
.touch-layer { position: absolute; z-index: 13; inset: 0; pointer-events: none; }

.touch-stick { position: absolute; left: max(14px, env(safe-area-inset-left)); bottom: max(14px, env(safe-area-inset-bottom)); padding: 14px; display: grid; justify-items: center; gap: 4px; pointer-events: auto; touch-action: none; }
.touch-stick__base { position: relative; width: 124px; height: 124px; display: grid; place-items: center; border-radius: 50%; background: radial-gradient(circle, rgba(84,223,215,.08), rgba(5,18,28,.55) 70%); border: 2px solid rgba(84,223,215,.4); box-shadow: inset 0 0 22px rgba(84,223,215,.12); }
.touch-stick__knob { width: 54px; height: 54px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #b8fff9, var(--cyan, #54dfd7) 55%, #239c95); box-shadow: 0 6px 16px rgba(0,0,0,.4); }
.touch-stick small { color: rgba(184,206,208,.75); font: 500 9px DM Mono, monospace; letter-spacing: .18em; }
.touch-stick.is-active .touch-stick__base { border-color: var(--cyan, #54dfd7); }

.touch-actions { position: absolute; right: max(18px, env(safe-area-inset-right)); bottom: max(20px, env(safe-area-inset-bottom)); display: flex; align-items: flex-end; gap: 14px; pointer-events: auto; }
.touch-action { display: grid; place-items: center; align-content: center; gap: 1px; padding: 0; color: #06151b; border: 0; border-radius: 50%; cursor: pointer; -webkit-tap-highlight-color: transparent; transition: transform .08s; }
.touch-action b { font: 800 26px/1 Manrope, sans-serif; }
.touch-action small { font: 700 8px DM Mono, monospace; letter-spacing: .08em; }
.touch-action--e { width: 82px; height: 82px; background: radial-gradient(circle at 35% 30%, #c7fffa, var(--cyan, #54dfd7) 60%, #20948e); box-shadow: 0 5px 0 #187570, 0 12px 26px rgba(0,0,0,.4); }
.touch-action--f { width: 64px; height: 64px; margin-bottom: 30px; background: radial-gradient(circle at 35% 30%, #fff1c4, #f5c451 60%, #c08a1d); box-shadow: 0 5px 0 #8f6513, 0 12px 26px rgba(0,0,0,.4); }
.touch-action--f b { font-size: 21px; }
.touch-action.is-down { transform: translateY(4px) scale(.96); box-shadow: 0 1px 0 rgba(0,0,0,.35), 0 6px 12px rgba(0,0,0,.35); }
.touch-action.is-wanted { animation: touch-wanted 1.1s ease-in-out infinite; }
@keyframes touch-wanted { 0%, 100% { filter: none; } 50% { filter: brightness(1.18) drop-shadow(0 0 14px rgba(255,255,255,.75)); } }

.touch-look-hint { position: absolute; left: 50%; top: 58%; transform: translateX(-50%); padding: 7px 14px; color: #dff; background: rgba(5,18,28,.7); border: 1px solid rgba(84,223,215,.3); border-radius: 999px; font: 600 12px Manrope, sans-serif; white-space: nowrap; animation: touch-hint-fade 6s forwards; }
.touch-layer.has-looked .touch-look-hint { display: none; }
@keyframes touch-hint-fade { 0%, 75% { opacity: 1; } 100% { opacity: 0; visibility: hidden; } }

/* ---- Panels made smaller so the 3D view stays visible ---- */
.touch-controls .objective-panel { top: 66px; left: 12px; width: min(250px, 38vw); padding: 10px 12px; }
.touch-controls .objective-panel h3 { margin: 5px 0; font-size: 15px; }
.touch-controls .objective-panel p { font-size: 12px; line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.touch-controls .objective-progress { margin-top: 8px; }
.touch-controls .instruction-popup { top: 64px; }

/* z-index 8: above the scanner message card, which would otherwise cover the answer choices. */
.touch-controls .level5-panel, .touch-controls .ph-meter-panel { z-index: 8; top: 66px; right: 12px; left: auto; width: min(370px, 46vw); max-height: calc(100% - 66px - 124px); padding: 10px 14px; }
.touch-controls .level5-panel__text { font-size: 14px; margin-bottom: 8px; }
.touch-controls .level5-panel__head strong { font-size: 16px; }
.touch-controls .level5-choice { min-height: 44px; font-size: 14px; padding: 8px 10px; }
.touch-controls .level5-feedback { font-size: 14px; }
.touch-controls .level6-pass { top: 70px; }
.touch-controls .level6-pass-hint { display: none; }

/* Prompts sit between the stick and the buttons, and can be tapped. */
.touch-controls .interaction-prompt { bottom: 26px; max-width: calc(100vw - 380px); }
.touch-controls .interaction-prompt strong { white-space: normal; font-size: 13px; }
.touch-controls .interaction-prompt.show { pointer-events: auto; cursor: pointer; }
.touch-controls .scanner-stack { bottom: 112px; }
.touch-controls .orientation-subtitle { top: 66px; bottom: auto; max-height: calc(100% - 66px - 170px); overflow: auto; cursor: pointer; padding: 12px 15px; }
.touch-controls .orientation-subtitle p { font-size: 13px; line-height: 1.45; margin: 6px 0 8px; }

/* The voice-over dock and the 🏆 button move to the top bar while playing. */
.touch-controls body:has(#game-screen.pointer-active:not(.level-menu-background)) .board-button { top: 7px; bottom: auto; left: 132px; right: auto; width: 42px; height: 42px; font-size: 20px; box-shadow: 0 3px 0 #a8761f, 0 6px 14px rgba(0,0,0,.35); }
.touch-controls body:has(#game-screen.pointer-active:not(.level-menu-background)) .narrator.is-folded,
.touch-controls body:has(#game-screen.pointer-active:not(.level-menu-background)) .narrator.is-empty:not(.is-open) { top: 5px; bottom: auto; left: 182px; }
.touch-controls body:has(#game-screen.pointer-active:not(.level-menu-background)) .narrator:not(.is-folded):not(.is-empty) { top: 62px; bottom: auto; left: 12px; }
.touch-controls body:has(#game-screen.pointer-active:not(.level-menu-background)) .admin-badge { bottom: 6px; right: auto; left: 50%; transform: translateX(-50%); padding: 4px 10px; font-size: 9px; }

/* ---- Video and tablet windows ---- */
.touch-controls .touch-close { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 0 16px; color: #06151b; background: var(--cyan, #54dfd7); border: 0; border-radius: 999px; font: 800 14px Manrope, sans-serif; cursor: pointer; }
.touch-controls .fire-training-card .touch-close { float: right; margin: -8px -8px 6px 10px; }
.touch-controls .tablet-bar .touch-close { margin-left: auto; }
.touch-controls .modal-key-hint, .touch-controls .tablet-frame > p { display: none; }

/* ---- Short screens (a phone held sideways) ---- */
@media (max-height: 520px) {
  .touch-controls .enter-3d h2 { font-size: 34px; margin: 4px 0; }
  .touch-controls .enter-3d .key-guide { margin: 14px 0; gap: 14px; }
  .touch-controls .enter-3d .eyebrow { margin: 0; }
  .touch-controls .game-hud { height: 52px; }
  .touch-controls .objective-panel, .touch-controls .level5-panel, .touch-controls .ph-meter-panel { top: 60px; }
  .touch-controls .level5-panel, .touch-controls .ph-meter-panel { max-height: calc(100% - 60px - 112px); }
  .touch-controls .objective-panel p { -webkit-line-clamp: 2; }
  .touch-stick { padding: 10px; }
  .touch-stick__base { width: 110px; height: 110px; }
  .touch-stick small { display: none; }
  .touch-action--e { width: 74px; height: 74px; }
  .touch-action--f { width: 58px; height: 58px; margin-bottom: 24px; }
  .touch-controls .fire-extinguisher-modal { padding: 8px; }
  .touch-controls .fire-training-card { padding: 14px 16px; }
  .touch-controls .fire-training-card h2 { margin: 2px 0 8px; font-size: 22px; }
  .touch-controls .fire-training-card .eyebrow { display: none; }
  .touch-controls .training-video-screen { height: calc(100vh - 110px); border-width: 4px; }
}

/* ---- Narrow screens (a phone held upright) ---- */
@media (max-width: 620px) {
  .touch-controls .mission-title { display: none; }
  .touch-controls .objective-panel { top: 62px; left: 12px; right: 12px; width: auto; }
  .touch-controls .level5-panel, .touch-controls .ph-meter-panel { top: 62px; left: 12px; right: 12px; width: auto; max-height: calc(100% - 62px - 250px); }
  .touch-controls #game-screen:has(#level5-panel:not([hidden])) .objective-panel,
  .touch-controls #game-screen:has(#level6-panel:not([hidden])) .objective-panel,
  .touch-controls #game-screen:has(#ph-meter-panel:not([hidden])) .objective-panel { display: none; }
  .touch-controls .interaction-prompt { bottom: 172px; max-width: calc(100vw - 32px); }
  .touch-controls .scanner-stack { bottom: 226px; }
  .touch-controls .orientation-subtitle { max-height: calc(100% - 66px - 200px); }
  .touch-look-hint { top: 45%; }
}
