/* ============================================================
   Mobile / phone enhancements (truedetective)
   - full-screen phone on real mobile devices
   - app screens cover the status-bar area (no wallpaper strip)
   - floating "home" / "exit phone" controls
   - music widget / seek polish
   ============================================================ */

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body.pe-phone-open {
  overflow: hidden !important;
  overscroll-behavior: none;
}

/* .central-panel has backdrop-filter, which turns it into a containing
   block for position:fixed. That broke the full-screen phone overlay. */
body.pe-phone-open .central-panel {
  -webkit-backdrop-filter: none !important;
  backdrop-filter: none !important;
}

/* ---------- keep tap targets comfortable ---------- */
@media (max-width: 900px) {
  #app button,
  #app .app-icon,
  #app .cyber-button {
    -webkit-tap-highlight-color: transparent;
  }
  #app .cyber-button,
  #app .header-back-btn {
    min-height: 48px;
  }
  #app .case-header h1 {
    letter-spacing: 1px;
  }
}

/* ============================================================
   Phone device: make app screens start at the very top of the
   device, behind the status bar / dynamic island.
   ============================================================ */
#app .phone-device {
  --pe-status-h: 50px;
}

#app .screen.screen-app,
#app .screen.screen-notes,
#app .screen.screen-gps,
#app .screen.screen-camera,
#app .screen.screen-photos,
#app .screen.screen-mail {
  margin-top: calc(-1 * var(--pe-status-h)) !important;
  padding-top: var(--pe-status-h) !important;
  box-sizing: border-box !important;
}

#app .screen-mail .mail-container {
  height: auto !important;
  min-height: 0 !important;
}

/* a soft scrim so light app backgrounds keep status text readable */
#app .phone-status-bar {
  text-shadow: 0 1px 3px rgba(0, 0, 0, .45);
}
#app .phone-status-bar.dark-text {
  text-shadow: none;
}

/* LunaMail has a light header: keep status icons readable */
#app .phone-device:has(.screen-mail) .phone-status-bar {
  color: #111 !important;
  text-shadow: none !important;
}
#app .phone-device:has(.screen-mail) .battery {
  border-color: rgba(0, 0, 0, .5) !important;
}
#app .phone-device:has(.screen-mail) .battery::after {
  background: rgba(0, 0, 0, .45) !important;
}
#app .phone-device:has(.screen-mail) .battery-level {
  background: #111 !important;
}

/* ============================================================
   Desktop: show the phone as a proper centered modal
   ============================================================ */
@media (min-width: 1025px) and (pointer: fine) {
  body.pe-phone-open #app .phone-modal-backdrop {
    position: fixed !important;
    inset: 0 !important;
    width: 100% !important;
    height: 100vh !important;
    height: 100dvh !important;
    padding: 16px !important;
    margin: 0 !important;
    background: rgba(2, 7, 11, .88) !important;
    -webkit-backdrop-filter: blur(10px) !important;
    backdrop-filter: blur(10px) !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    overflow: auto !important;
    z-index: 9999 !important;
  }
  body.pe-phone-open #app .phone-modal-container {
    width: min(840px, 100%) !important;
    height: auto !important;
    max-height: none !important;
    margin: 0 !important;
  }
  body.pe-phone-open #app .phone-device {
    height: min(700px, calc(100dvh - 120px)) !important;
    max-height: calc(100dvh - 120px) !important;
  }
  /* the modal header already has a working "back" button */
  #app .pe-controls {
    display: none !important;
  }
}

/* ============================================================
   Full-screen phone on mobile
   ============================================================ */
@media (max-width: 1024px), (pointer: coarse) {
  #app .phone-modal-backdrop {
    position: fixed !important;
    inset: 0 !important;
    width: 100% !important;
    height: 100vh !important;
    height: 100dvh !important;
    max-height: none !important;
    padding: 0 !important;
    margin: 0 !important;
    background: #000 !important;
    z-index: 99999 !important;
    display: block !important;
    overflow: hidden !important;
  }

  #app .phone-modal-container {
    display: block !important;
    width: 100% !important;
    max-width: none !important;
    height: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    gap: 0 !important;
  }

  #app .phone-modal-header {
    display: none !important;
  }

  #app .phone-device {
    --pe-status-h: calc(env(safe-area-inset-top, 0px) + 30px);
    width: 100% !important;
    max-width: none !important;
    height: 100vh !important;
    height: 100dvh !important;
    max-height: none !important;
    border: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    box-sizing: border-box !important;
  }

  #app .phone-status-bar {
    height: var(--pe-status-h) !important;
    padding: calc(env(safe-area-inset-top, 0px) + 7px) 22px 4px !important;
    box-sizing: border-box !important;
  }

  /* a real phone already has its own notch / island */
  #app .dynamic-island {
    display: none !important;
  }

  #app .screen-home {
    padding-top: calc(var(--pe-status-h) + 12px) !important;
  }

  #app .chat-input-fake {
    padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 10px) !important;
    box-sizing: border-box !important;
  }
  #app .camera-bottom-bar {
    padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 30px) !important;
    box-sizing: border-box !important;
  }
}

/* ============================================================
   Floating controls inside the phone
   ============================================================ */
#app .pe-controls {
  position: absolute;
  right: calc(10px + env(safe-area-inset-right, 0px));
  bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 300;
}

#app .pe-btn {
  width: 42px;
  height: 42px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid rgba(0, 234, 255, .45);
  background: rgba(6, 16, 23, .74);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  color: #00eaff;
  display: grid;
  place-items: center;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .55), inset 0 0 12px rgba(0, 234, 255, .12);
  -webkit-tap-highlight-color: transparent;
  transition: transform .15s ease, background .2s ease, opacity .2s ease;
}

#app .pe-btn:active {
  transform: scale(.9);
  background: rgba(0, 234, 255, .18);
}

#app .pe-btn svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#app .pe-exit {
  color: rgba(255, 255, 255, .75);
  border-color: rgba(255, 255, 255, .22);
  width: 36px;
  height: 36px;
  font: 400 18px/1 -apple-system, Arial, sans-serif;
}

#app .pe-home {
  display: none;
}

#app .phone-device.pe-app-open .pe-home {
  display: grid;
  animation: pe-pop .18s ease-out;
}

@keyframes pe-pop {
  from { opacity: 0; transform: scale(.8); }
  to   { opacity: 1; transform: scale(1); }
}

#app .pe-toast {
  position: absolute;
  left: 50%;
  bottom: calc(22px + env(safe-area-inset-bottom, 0px));
  transform: translate(-50%, 8px);
  z-index: 320;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid rgba(0, 234, 255, .3);
  background: rgba(4, 12, 18, .82);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  color: #d9f7ff;
  font: 500 12px/1 -apple-system, Arial, sans-serif;
  letter-spacing: .3px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .5);
}

#app .pe-toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ============================================================
   Music widget polish + smooth seek
   ============================================================ */
#app .music-widget {
  border-radius: 20px;
}

#app .m-seek-row {
  gap: 10px;
  margin-top: 6px;
  padding-top: 6px;
}

#app .m-seek {
  height: 24px;
  accent-color: #00eaff;
  touch-action: none;
}

#app .m-seek-time {
  min-width: 34px;
  font-size: 10.5px;
  letter-spacing: .2px;
}

@media (max-width: 420px) {
  #app .music-widget {
    padding: 10px 12px;
  }
  #app .m-title {
    font-size: .88rem;
  }
  #app .m-artist {
    font-size: .72rem;
  }
  #app .m-volume {
    height: 22px;
  }
}

/* ============================================================
   Case menu on phones
   The menu used to overflow its flex container and slide over the
   decorative case footer ("УРОВЕНЬ ДОСТУПА" / "ПОСЛЕДНЯЯ
   АКТИВНОСТЬ"), making the text show through the translucent
   buttons. Let the menu take its natural height and hide the HUD
   footer on narrow screens where there is no room for it.
   ============================================================ */
@media (max-width: 900px) {
  #app .case-layout:has(.menu-column) {
    height: auto !important;
    min-height: 0 !important;
  }

  #app .case-layout:has(.menu-column) .game-container {
    flex: 1 0 auto !important;
    min-height: 0 !important;
  }

  #app .case-layout:has(.menu-column) .game-content,
  #app .case-layout:has(.menu-column) .panel-content-grid {
    height: auto !important;
  }

  #app .case-layout:has(.menu-column) .case-footer {
    display: none !important;
  }

  #app .case-layout:has(.menu-column) .menu-column {
    gap: 12px;
    padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px));
  }
}
