html,
body,
#root {
  width: 100%;
  height: 100%;
  height: 100dvh;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: #173d34;
}

body {
  position: fixed;
  inset: 0;
  -webkit-text-size-adjust: 100%;
}

.game-shell {
  height: 100%;
  min-height: 0 !important;
  isolation: isolate;
  overscroll-behavior: none;
  touch-action: none;
  background-color: #4f9470;
}

.game-shell,
.game-shell *:not(input):not(textarea) {
  -webkit-user-select: none !important;
  user-select: none !important;
  -webkit-touch-callout: none !important;
  -webkit-tap-highlight-color: transparent !important;
}

.game-shell img,
.game-shell svg {
  -webkit-user-drag: none;
  user-drag: none;
  pointer-events: none;
}

.game-shell button,
.game-shell a,
.control-button,
.control-button * {
  touch-action: none !important;
  -webkit-appearance: none;
  appearance: none;
}

@media (max-width: 680px), (pointer: coarse) {
  .game-shell {
    min-height: 0 !important;
    height: 100svh;
    height: 100dvh;
    transition: none !important;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
  }

  .game-shell::before,
  .game-shell::after {
    transition: none !important;
    will-change: transform;
  }

  .host-tree {
    will-change: auto !important;
    transition: none !important;
  }

  .host-tree-layer {
    transform: translateZ(0);
  }

  .world-bug,
  .explorer-asset,
  .habitat-rock,
  .habitat-flower,
  .habitat-cover {
    transition-duration: 0.22s !important;
  }

  /* Keep the play field visually separate from the touch controls. */
  .controls-left,
  .controls-right {
    bottom: max(6px, env(safe-area-inset-bottom)) !important;
    gap: 8px !important;
    z-index: 22 !important;
  }

  .controls-left::before {
    content: "";
    position: fixed;
    z-index: -1;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100vw;
    height: calc(76px + env(safe-area-inset-bottom));
    pointer-events: none;
    background:
      linear-gradient(180deg, rgba(255,255,255,.18), transparent 8px),
      linear-gradient(180deg, rgba(49,105,65,.94), rgba(29,74,54,.98));
    border-top: 2px solid rgba(255,245,205,.72);
    box-shadow: 0 -6px 16px rgba(19,57,43,.2), inset 0 2px 0 rgba(255,255,255,.18);
  }

  .control-button {
    width: 46px !important;
    height: 46px !important;
    border-radius: 14px !important;
    font-size: 22px !important;
    box-shadow: 0 5px #b9a878, 0 8px 14px rgba(32,69,49,.16) !important;
  }

  .control-button small {
    margin-top: -5px !important;
    font-size: 9px !important;
  }

  .mobile-jump-button {
    min-width: 46px !important;
    min-height: 46px !important;
    font-size: 22px !important;
  }

  .pause-button {
    width: 46px !important;
    height: 46px !important;
    margin-right: 0 !important;
    font-size: 20px !important;
    border-width: 2px !important;
    box-shadow: 0 4px #7c592f, 0 7px 12px rgba(32,69,49,.14) !important;
  }

  .game-shell::after {
    height: 24% !important;
    bottom: calc(58px + env(safe-area-inset-bottom)) !important;
    opacity: .9 !important;
    background-size: auto 94% !important;
  }

  .explorer-asset {
    margin-bottom: 10px !important;
  }

  .world-caption {
    bottom: calc(88px + env(safe-area-inset-bottom)) !important;
  }

  /* Mobile: hide sun sprite entirely; darken with reliable normal-blend shade. */
  .game-shell:not(.time-night):not(.time-dusk) {
    --daylight: 0;
    --sun-opacity: 0;
  }

  .game-shell.time-dusk {
    --daylight: 0.08;
    --sun-opacity: 0;
  }

  .field-sun {
    display: none !important;
  }

  .daylight-shade {
    mix-blend-mode: normal !important;
    background: rgba(20, 30, 38, calc(var(--daylight) * .22)) !important;
  }

  .game-shell.zone-flower {
    filter: saturate(1.02) brightness(1.02) !important;
  }

  .game-shell.zone-flower::before,
  .game-shell.zone-flower::after {
    opacity: 0.78 !important;
    filter: saturate(1.02) brightness(1.02) !important;
  }

  /* Insect catalog — fit inside mobile viewport without clipping */
  .modal-backdrop {
    padding: 6px !important;
    align-items: center !important;
  }

  .notebook-modal,
  .field-book.field-book-catalog {
    width: min(calc(100vw - 12px), 460px) !important;
    max-height: min(
      78dvh,
      calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 12px)
    ) !important;
    padding: 12px 10px 8px !important;
    transform: none !important;
    border-radius: 14px !important;
    overflow: hidden !important;
    display: flex !important;
    flex-direction: column !important;
  }

  .notebook-modal .close-book,
  .field-book.field-book-catalog .close-book {
    top: 4px !important;
    right: 6px !important;
    font-size: 22px !important;
  }

  .notebook-modal .book-kicker,
  .field-book.field-book-catalog .book-kicker {
    font-size: 9px !important;
    margin-bottom: 0 !important;
  }

  .notebook-modal h1,
  .field-book.field-book-catalog h1 {
    font-size: 17px !important;
    margin: 0 0 2px !important;
    line-height: 1.1 !important;
  }

  .notebook-modal > p,
  .field-book.field-book-catalog > p {
    font-size: 10px !important;
    margin: 0 0 2px !important;
    line-height: 1.25 !important;
  }

  .notebook-modal .bug-grid.catalog-grid,
  .field-book.field-book-catalog .bug-grid.catalog-grid {
    margin-top: 4px !important;
    gap: 5px !important;
    grid-template-columns: 1fr 1fr !important;
    flex: 1 1 auto !important;
    min-height: 0 !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
  }

  .notebook-modal .catalog-card,
  .field-book.field-book-catalog .catalog-card {
    min-height: 0 !important;
    padding: 5px 4px 4px !important;
    gap: 2px !important;
    border-radius: 9px !important;
  }

  .notebook-modal .catalog-bug-image,
  .field-book.field-book-catalog .catalog-bug-image {
    width: 38px !important;
    border-radius: 8px !important;
    font-size: 24px !important;
  }

  .notebook-modal .catalog-copy b,
  .field-book.field-book-catalog .catalog-copy b {
    font-size: 11px !important;
  }

  .notebook-modal .catalog-copy em,
  .field-book.field-book-catalog .catalog-copy em {
    font-size: 8px !important;
  }

  .notebook-modal .catalog-copy small,
  .field-book.field-book-catalog .catalog-copy small {
    font-size: 8px !important;
    line-height: 1.2 !important;
  }

  .notebook-modal .catalog-copy i,
  .field-book.field-book-catalog .catalog-copy i {
    font-size: 8px !important;
    margin-top: 0 !important;
    padding-top: 2px !important;
  }

  .notebook-modal .catalog-card::after,
  .field-book.field-book-catalog .catalog-card::after {
    font-size: 7px !important;
  }

  .notebook-modal .book-nav,
  .field-book.field-book-catalog .book-nav {
    margin-top: 4px !important;
    padding: 4px 0 0 !important;
    gap: 8px !important;
  }

  .notebook-modal .book-nav button,
  .field-book.field-book-catalog .book-nav button {
    min-width: 60px !important;
    padding: 5px 8px !important;
    font-size: 10px !important;
  }

  .field-book.field-book-catalog .book-nav strong {
    font-size: 11px !important;
  }
}
