/* ===== 时空罗盘 · 移动端横屏适配 ===== */
/* 适用于手机横屏 / 平板竖屏 / 窄屏窗口 */
/* 触发条件：max-width: 820px 且为触控设备，或 max-width: 1024px 且横屏 */

body.mobile-app {
  position: fixed;
  inset: 0;
  width: 100vw;
  width: 100dvw;
  height: 100vh;
  height: 100dvh;
  min-width: 0;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

body.mobile-app #map,
body.mobile-app #theme-overlay,
body.mobile-app #deck-canvas,
body.mobile-app #ornament-overlay,
body.mobile-app #ui-root,
body.mobile-app .loading-overlay {
  position: absolute;
  inset: 0;
  max-width: none;
}

body.mobile-app #map,
body.mobile-app #theme-overlay,
body.mobile-app #deck-canvas,
body.mobile-app #ornament-overlay,
body.mobile-app .loading-overlay {
  width: 100vw;
  width: 100dvw;
  height: 100vh;
  height: 100dvh;
}

body.mobile-app #ui-root {
  width: 100%;
  height: 100%;
  overflow: hidden;
  z-index: 20;
  pointer-events: none;
}

@media (max-width: 820px),
       (max-width: 1024px) and (orientation: landscape) and (pointer: coarse) {

  html,
  body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
    position: fixed;
    inset: 0;
  }

  body {
    margin: 0;
    min-height: 100dvh;
    font-family: 'Inter', 'Noto Sans SC', 'Noto Sans JP', 'Noto Sans KR', system-ui, sans-serif;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
  }

  /* ---- 地图 & 图层 ---- */
  #map {
    inset: 0;
    width: 100%;
    height: 100%;
    position: absolute;
  }

  #map,
  #theme-overlay,
  #deck-canvas,
  #ornament-overlay,
  #ui-root,
  .loading-overlay {
    position: absolute;
  }

  #ui-root {
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 20;
    pointer-events: none;
  }

  .maplibregl-ctrl-top-right {
    display: none;
  }

  .maplibregl-ctrl-attrib {
    max-width: 220px !important;
    font-size: 8px !important;
  }

  .corner-fret {
    width: 40px;
    height: 40px;
    opacity: 0.36;
  }

  .vignette {
    background: radial-gradient(
      ellipse at center,
      rgba(120, 100, 70, 0) 48%,
      rgba(70, 55, 30, 0.18) 100%
    );
  }

  /* ---- 顶部标题栏：横屏紧凑布局 ---- */
  #app-header {
    padding: 8px 14px 60px !important;
  }

  #app-header .flex.items-start.justify-between > div:first-child {
    width: auto;
  }

  #app-header .flex.items-center.gap-3 {
    gap: 5px;
    flex-wrap: nowrap;
  }

  #app-header .seal {
    width: 26px !important;
    height: 26px !important;
    border-radius: 7px;
    font-size: 11px !important;
  }

  #app-header h1 {
    color: #876c2b;
    font-size: 16px !important;
    line-height: 1.05;
    text-shadow: 0 1px 2px rgba(255, 252, 244, 0.72);
    white-space: nowrap;
  }

  #app-header p {
    display: none;
  }

  /* ---- 工具栏：横屏靠右竖排，透明背景 ---- */
  .tool-cluster {
    top: 48px;
    right: 10px;
    width: min(160px, calc(100vw - 24px));
    gap: 6px;
  }

  .tool-btn,
  .layer-trigger {
    grid-template-columns: 22px minmax(0, 1fr) auto;
    height: 34px;
    gap: 5px;
    padding: 0 7px 0 9px;
    border-width: 1.5px;
    border-radius: 999px;
    background:
      linear-gradient(180deg, rgba(255, 252, 244, 0.44), rgba(236, 226, 203, 0.28)),
      rgba(247, 244, 236, 0.26);
    color: #2b2118;
    font-family: 'Ma Shan Zheng', 'KaiTi', serif;
    font-size: 13px;
    font-weight: 400;
    letter-spacing: 0.04em;
  }

  .tool-btn .tool-ico,
  .layer-trigger-icon,
  .lang-trigger.tool-btn .lang-ico {
    width: 20px;
    height: 20px;
    background: transparent;
  }
  .tool-btn .tool-ico svg,
  .lang-trigger.tool-btn .lang-ico svg {
    width: 15px;
    height: 15px;
  }

  .tool-badge {
    min-width: 30px;
    padding: 1px 5px 2px;
    font-size: 8px;
  }

  .lang-menu {
    top: 40px;
    width: 144px;
    border-radius: 12px;
  }

  .lang-option {
    padding: 7px 10px;
    font-size: 11px;
  }

  .layer-control {
    top: 170px;
    right: max(10px, calc(100vw - 280px));
    width: min(160px, calc(100vw - 24px));
  }

  .layer-menu {
    max-height: 260px;
    overflow-y: auto;
    border-radius: 12px;
    padding: 6px;
  }

  .layer-item {
    gap: 7px;
    padding: 6px 7px;
  }

  .layer-name {
    font-size: 11px;
  }

  .layer-count {
    font-size: 9px;
  }

  /* ---- 面包屑 ---- */
  #breadcrumb {
    top: 48px;
    max-width: calc(100vw - 300px);
    padding: 6px 9px;
  }

  /* ---- 底部探索按钮：横屏居中底部 ---- */
  .explore-launcher {
    bottom: calc(12px + env(safe-area-inset-bottom));
    min-width: 200px;
    min-height: 48px;
    gap: 10px;
    padding: 8px 30px 8px 14px;
    pointer-events: auto;
    background: transparent;
    font-size: 18px;
    letter-spacing: 0.08em;
  }

  .explore-launcher::after {
    inset: -6px -20px -6px -14px;
    background-size: 100% 56%;
  }

  .explore-ico {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    font-size: 18px;
  }

  /* ---- 信息面板：横屏侧边滑出（不全屏覆盖） ---- */
  #info-panel,
  #compass-panel,
  #foreign-panel {
    top: 0;
    right: 0;
    z-index: 35;
    width: min(100%, 380px) !important;
    height: 100% !important;
    max-height: none;
    max-width: 90vw;
    padding: 14px 12px;
    border-radius: 0;
    border: 0;
    overflow-y: auto;
  }

  .glass-card {
    min-height: calc(100% - 8px);
    padding: 14px 14px 18px;
    border-radius: 20px;
  }

  .panel-close {
    top: 8px;
    right: 8px;
  }

  .panel-kicker {
    padding: 16px 56px 6px 8px;
  }

  .panel-title {
    font-size: 22px;
    line-height: 1.12;
  }

  .panel-subtitle {
    font-size: 14px;
  }

  .panel-image {
    height: 100px;
    border-radius: 8px;
  }

  .panel-desc {
    font-size: 14px;
    line-height: 1.6;
  }

  .panel-visit-card {
    padding: 10px 10px 10px;
    font-size: 11px;
  }

  .episode-enter-card {
    min-height: 56px;
    padding: 10px 6px;
  }

  /* ---- 罗盘探索面板 ---- */
  #compass-panel {
    background: rgba(236, 226, 203, 0.82);
  }

  .compass-card {
    min-height: calc(100% - 6px);
    padding: 14px 12px 14px;
    border-radius: 8px;
  }

  .compass-head {
    margin-bottom: 8px;
    padding-top: 2px;
  }

  .compass-title {
    font-size: inherit;
  }

  .compass-title-main {
    font-size: 18px;
  }

  .compass-title-sub {
    font-size: 9px;
  }

  .compass-tabs {
    gap: 4px;
    padding: 4px;
    border-radius: 10px;
  }

  .compass-tab {
    padding: 7px;
    font-size: 11px;
  }

  .compass-route-bar {
    padding-bottom: 6px;
  }

  .compass-diy-panel {
    padding: 8px 10px;
    margin-bottom: 6px;
  }

  .rt-diy-actions {
    margin-top: 6px;
  }

  .rt-diy-actions .rt-plan-btn {
    min-width: 80px;
    padding: 6px 10px;
  }

  .nearby-item {
    padding: 8px 8px;
  }

  .nearby-name {
    font-size: 13px;
  }

  .nearby-distance {
    font-size: 10px;
  }

  .route-card {
    padding: 8px;
  }

  /* ---- 印章册 ---- */
  #stamp-modal {
    z-index: 60;
  }

  .stamp-card {
    width: min(92vw, 420px);
    max-height: 90vh;
    padding: 16px 14px 18px;
    border-radius: 20px;
  }

  .stamp-header {
    grid-template-columns: 40px 1fr;
  }

  .stamp-seal {
    width: 40px;
    height: 40px;
  }

  .stamp-title {
    font-size: 20px;
  }

  .stamp-total {
    grid-column: 1 / -1;
  }

  .stamp-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
  }

  .stamp-cell {
    min-height: 110px;
  }

  .stamp-cell.just-earned {
    padding-top: 22px;
  }

  .stamp-new-label {
    top: 6px;
    left: 8px;
  }

  /* ---- 剧情副本层 ---- */
  #episode-layer {
    z-index: 55;
  }

  .episode-card {
    width: min(94vw, 420px);
    border-radius: 20px;
  }

  .episode-scroll {
    padding: 16px 14px 18px;
  }

  .ep-title {
    font-size: 20px;
  }

  .ep-question {
    font-size: 15px;
  }

  .ep-option {
    padding: 10px 11px;
  }

  /* ---- Toast ---- */
  .toast {
    bottom: 70px;
    max-width: calc(100vw - 36px);
    font-size: 12px;
  }
}

/* ===== 超窄横屏（手机横屏 < 500px 宽度）的额外优化 ===== */
@media (max-width: 500px) and (orientation: landscape) {
  #app-header h1 {
    font-size: 14px !important;
  }

  .tool-cluster {
    width: min(140px, calc(100vw - 20px));
    right: 8px;
  }

  .tool-btn,
  .layer-trigger {
    height: 30px;
    font-size: 12px;
  }

  .layer-control {
    width: min(140px, calc(100vw - 20px));
    right: 8px;
  }

  #info-panel,
  #compass-panel,
  #foreign-panel {
    width: 100% !important;
    max-width: 100vw;
  }

  .panel-title {
    font-size: 18px;
  }

  .panel-desc {
    font-size: 13px;
  }

  .explore-launcher {
    min-width: 160px;
    min-height: 40px;
    font-size: 15px;
  }

  .stamp-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* ===== 移动端开场云雾动画（仅触控设备 + 窄屏时可见） ===== */
@media (max-width: 820px) {
  #mobile-cloud-intro {
    position: absolute;
    inset: 0;
    z-index: 51;
    overflow: hidden;
    pointer-events: none;
    background:
      radial-gradient(circle at 50% 55%, rgba(247, 244, 236, 0.28), transparent 34%),
      radial-gradient(circle at 50% 50%, rgba(15, 21, 20, 0.18), rgba(15, 21, 20, 0.48) 100%);
    perspective: 900px;
    animation: mobileFlightVanish 3.45s cubic-bezier(0.16, 1, 0.3, 1) 0.08s both;
  }

  #mobile-cloud-intro::before,
  #mobile-cloud-intro::after,
  #mobile-cloud-intro .mist,
  #mobile-cloud-intro .flight-vignette {
    position: absolute;
    display: block;
    border-radius: 999px;
    content: "";
    will-change: transform, opacity;
  }

  #mobile-cloud-intro::before {
    inset: -11% -44% 50% -48%;
    background:
      radial-gradient(circle at 20% 58%, rgba(255, 252, 244, 0.96), transparent 42%),
      radial-gradient(circle at 52% 44%, rgba(236, 226, 203, 0.9), transparent 48%),
      radial-gradient(circle at 82% 62%, rgba(255, 252, 244, 0.68), transparent 40%);
    filter: blur(18px);
    transform-origin: 50% 80%;
    animation: mobileCloudFrontLeft 3.15s cubic-bezier(0.16, 1, 0.3, 1) 0.08s both;
  }

  #mobile-cloud-intro::after {
    inset: 38% -48% -15% -42%;
    background:
      radial-gradient(circle at 22% 42%, rgba(255, 252, 244, 0.8), transparent 44%),
      radial-gradient(circle at 58% 50%, rgba(236, 226, 203, 0.92), transparent 48%),
      radial-gradient(circle at 86% 40%, rgba(255, 252, 244, 0.7), transparent 38%);
    filter: blur(20px);
    transform-origin: 50% 10%;
    animation: mobileCloudFrontRight 3.2s cubic-bezier(0.16, 1, 0.3, 1) 0.1s both;
  }

  #mobile-cloud-intro .mist-a {
    left: -28%; top: 23%; width: 102%; height: 20%;
    background: rgba(255, 252, 244, 0.56);
    filter: blur(14px);
    animation: mobileMistSweepLeft 3.05s cubic-bezier(0.16, 1, 0.3, 1) 0.2s both;
  }
  #mobile-cloud-intro .mist-b {
    right: -30%; top: 9%; width: 98%; height: 18%;
    background: rgba(247, 244, 236, 0.52);
    filter: blur(13px);
    animation: mobileMistSweepRight 2.95s cubic-bezier(0.16, 1, 0.3, 1) 0.18s both;
  }
  #mobile-cloud-intro .mist-c {
    left: -12%; bottom: 7%; width: 124%; height: 19%;
    background: rgba(236, 226, 203, 0.5);
    filter: blur(16px);
    animation: mobileMistSink 3.1s cubic-bezier(0.16, 1, 0.3, 1) 0.16s both;
  }
  #mobile-cloud-intro .mist-d {
    left: 14%; top: 43%; width: 72%; height: 15%;
    border-radius: 50%;
    background: rgba(255, 252, 244, 0.42);
    filter: blur(18px);
    animation: mobileMistTunnel 2.7s cubic-bezier(0.16, 1, 0.3, 1) 0.08s both;
  }

  #mobile-cloud-intro .flight-vignette {
    inset: -12%;
    border-radius: 0;
    background:
      radial-gradient(circle at 50% 55%, transparent 0 22%, rgba(15, 21, 20, 0.08) 40%, rgba(15, 21, 20, 0.54) 100%),
      linear-gradient(180deg, rgba(15, 21, 20, 0.18), transparent 36%, rgba(15, 21, 20, 0.16));
    filter: none;
    animation: mobileVignetteDive 3.15s cubic-bezier(0.16, 1, 0.3, 1) both;
  }

  #mobile-cloud-intro .flight-reticle {
    position: absolute;
    left: 50%; top: 52%;
    width: 158px; height: 158px;
    transform: translate(-50%, -50%);
    opacity: 0;
    animation: mobileReticleLock 2.55s cubic-bezier(0.16, 1, 0.3, 1) 0.38s both;
    will-change: transform, opacity;
  }

  #mobile-cloud-intro .flight-ring {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 1px solid rgba(154, 123, 50, 0.58);
    box-shadow: 0 0 0 1px rgba(255, 252, 244, 0.2) inset;
  }

  #mobile-cloud-intro .flight-ring-b {
    inset: 38px;
    border-color: rgba(178, 58, 46, 0.42);
  }

  #mobile-cloud-intro .flight-cross {
    position: absolute;
    left: 50%; top: 50%;
    background: rgba(154, 123, 50, 0.42);
    transform: translate(-50%, -50%);
  }

  #mobile-cloud-intro .flight-cross-x { width: 118px; height: 1px; }
  #mobile-cloud-intro .flight-cross-y { width: 1px; height: 118px; }

  #mobile-cloud-intro .flight-dot {
    position: absolute;
    left: 50%; top: 50%;
    width: 8px; height: 8px;
    border-radius: 50%;
    background: #b23a2e;
    box-shadow: 0 0 16px rgba(178, 58, 46, 0.62);
    transform: translate(-50%, -50%);
  }

  #mobile-cloud-intro .flight-label {
    position: absolute;
    left: 50%; top: calc(52% + 94px);
    transform: translateX(-50%);
    color: rgba(61, 49, 34, 0.78);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.12em;
    opacity: 0;
    text-shadow: 0 1px 8px rgba(255, 252, 244, 0.82);
    white-space: nowrap;
    animation: mobileLabelLock 2.45s cubic-bezier(0.16, 1, 0.3, 1) 0.54s both;
  }
}

/* PC 端隐藏移动端开场动画 */
@media not all and (pointer: coarse) {
  #mobile-cloud-intro {
    display: none;
  }
}

/* ===== 开场动画 keyframes ===== */
@keyframes mobileFlightVanish {
  0%, 74% { opacity: 1; visibility: visible; }
  100% { opacity: 0; visibility: hidden; }
}
@keyframes mobileCloudFrontLeft {
  0% { opacity: 0.98; transform: translate3d(0, 0, 80px) scale(1.18); }
  46% { opacity: 0.92; transform: translate3d(-10%, 2%, 50px) scale(1.08); }
  100% { opacity: 0; transform: translate3d(-58%, -14%, 0) scale(1.18); }
}
@keyframes mobileCloudFrontRight {
  0% { opacity: 0.96; transform: translate3d(0, 0, 90px) scale(1.18); }
  46% { opacity: 0.86; transform: translate3d(8%, -2%, 50px) scale(1.08); }
  100% { opacity: 0; transform: translate3d(56%, 16%, 0) scale(1.18); }
}
@keyframes mobileMistSweepLeft {
  0% { opacity: 0.68; transform: translate3d(0, 0, 60px) scale(1.18); }
  100% { opacity: 0; transform: translate3d(-44%, -12%, 0) scale(1.02); }
}
@keyframes mobileMistSweepRight {
  0% { opacity: 0.62; transform: translate3d(0, 0, 50px) scale(1.14); }
  100% { opacity: 0; transform: translate3d(46%, -8%, 0) scale(1.02); }
}
@keyframes mobileMistSink {
  0% { opacity: 0.58; transform: translate3d(0, 0, 70px) scale(1.18); }
  100% { opacity: 0; transform: translate3d(0, 42%, 0) scale(1.08); }
}
@keyframes mobileMistTunnel {
  0% { opacity: 0.72; transform: translate3d(0, 0, 120px) scale(1.8); }
  56% { opacity: 0.46; transform: translate3d(0, -1%, 48px) scale(1.05); }
  100% { opacity: 0; transform: translate3d(0, -5%, 0) scale(0.34); }
}
@keyframes mobileVignetteDive {
  0% { opacity: 0.88; transform: scale(1); }
  76% { opacity: 0.42; transform: scale(1.12); }
  100% { opacity: 0; transform: scale(1.16); }
}
@keyframes mobileReticleLock {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(1.42) rotate(-10deg); }
  24% { opacity: 0.78; }
  62% { opacity: 0.72; transform: translate(-50%, -50%) scale(0.82) rotate(0); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(0.54) rotate(0); }
}
@keyframes mobileLabelLock {
  0%, 16% { opacity: 0; transform: translateX(-50%) translateY(6px); }
  36%, 68% { opacity: 0.88; transform: translateX(-50%) translateY(0); }
  100% { opacity: 0; transform: translateX(-50%) translateY(-6px); }
}

@media (prefers-reduced-motion: reduce) {
  #mobile-cloud-intro,
  #mobile-cloud-intro::before,
  #mobile-cloud-intro::after,
  #mobile-cloud-intro .mist,
  #mobile-cloud-intro .flight-vignette,
  #mobile-cloud-intro .flight-reticle,
  #mobile-cloud-intro .flight-label {
    animation: none !important;
    transform: none !important;
    filter: none;
    opacity: 0;
    visibility: hidden;
  }
}

/* ===== 竖屏旋转引导遮罩 ===== */
/* PC 端永远隐藏 */
#rotate-hint {
  display: none;
}

/* 移动端竖屏时全屏覆盖 */
@media (pointer: coarse) and (orientation: portrait) {
  #rotate-hint {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 18px;
    background:
      radial-gradient(circle at 50% 42%, rgba(247, 244, 236, 0.12), transparent 50%),
      linear-gradient(180deg, #1a1612 0%, #2b2318 100%);
    color: #f7f4ec;
    text-align: center;
    padding: 40px;
  }

  #rotate-hint .rotate-hint__icon {
    width: 72px;
    height: 72px;
    color: #c9a84c;
    animation: rotateNudge 2.4s ease-in-out infinite;
  }

  #rotate-hint .rotate-hint__icon svg {
    width: 100%;
    height: 100%;
  }

  #rotate-hint .rotate-hint__text {
    font-family: 'Ma Shan Zheng', 'KaiTi', serif;
    font-size: 22px;
    letter-spacing: 0.08em;
    color: #f7f4ec;
    margin: 0;
  }

  #rotate-hint .rotate-hint__sub {
    font-size: 13px;
    color: rgba(247, 244, 236, 0.5);
    margin: 0;
  }
}

@keyframes rotateNudge {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(-90deg); }
}

/* ===== 手机端整体适配：竖屏可用 + 触控底部抽屉 ===== */
@media (max-width: 820px) {
  :root {
    --mobile-edge: max(10px, env(safe-area-inset-left));
    --mobile-edge-r: max(10px, env(safe-area-inset-right));
    --mobile-bottom-nav: calc(70px + env(safe-area-inset-bottom));
    --mobile-sheet-radius: 14px;
  }

  html,
  body {
    height: 100dvh;
  }

  body {
    min-width: 320px;
  }

  #ui-root {
    overflow: hidden;
  }

  #ornament-overlay,
  #mobile-cloud-intro {
    max-width: 100vw;
    overflow: hidden;
    contain: paint;
  }

  #ui-root .bgm-toggle {
    pointer-events: auto;
  }

  #app-header {
    padding: calc(8px + env(safe-area-inset-top)) var(--mobile-edge-r) 54px var(--mobile-edge) !important;
  }

  #app-header .flex.items-start.justify-between {
    align-items: flex-start;
    gap: 10px;
  }

  #app-header h1 {
    display: block;
    max-width: calc(100vw - 188px);
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .tool-cluster {
    top: calc(50px + env(safe-area-inset-top));
    right: var(--mobile-edge-r);
    width: min(172px, calc(100vw - 24px));
    gap: 7px;
  }

  .tool-btn,
  .layer-trigger,
  .lang-option,
  .close-btn,
  .memory-close,
  .episode-close,
  .stamp-cell,
  .route-anchor-info,
  .route-anchor-select,
  .compass-anchor-info,
  .compass-anchor-select,
  .rt-select-action,
  .rt-plan-btn,
  .rec-plan-btn {
    min-height: 44px;
  }

  .tool-btn,
  .layer-trigger {
    grid-template-columns: 24px minmax(0, 1fr) auto;
    height: 44px;
    font-size: 13px;
    letter-spacing: 0.03em;
  }

  .lang-menu {
    top: calc(100% + 8px);
    width: min(178px, calc(100vw - 24px));
    max-height: min(58dvh, 360px);
    overflow-y: auto;
  }

  .layer-control {
    top: auto;
    right: var(--mobile-edge-r);
    bottom: calc(var(--mobile-bottom-nav) + 12px);
    width: min(172px, calc(100vw - 24px));
  }

  .layer-menu {
    position: absolute;
    right: 0;
    bottom: calc(100% + 8px);
    width: min(220px, calc(100vw - 20px));
    max-height: min(46dvh, 320px);
    overflow-y: auto;
    margin-top: 0;
  }

  .layer-item {
    min-height: 40px;
    padding: 8px 9px;
  }

  #breadcrumb {
    top: calc(108px + env(safe-area-inset-top));
    left: var(--mobile-edge);
    right: var(--mobile-edge-r);
    max-width: none;
    transform: none;
    padding: 7px 10px;
  }

  .bgm-toggle {
    left: var(--mobile-edge);
    bottom: calc(var(--mobile-bottom-nav) + 14px);
    width: 44px;
    height: 44px;
  }

  .main-actions {
    left: var(--mobile-edge);
    right: var(--mobile-edge-r);
    bottom: max(8px, env(safe-area-inset-bottom));
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    width: auto;
    gap: 6px;
    transform: none;
  }

  body.info-panel-open #ui-root .main-actions,
  body.compass-panel-open #ui-root .main-actions,
  body:has(#route-planner-panel.open) #ui-root .main-actions {
    opacity: 0;
    pointer-events: none;
    transform: translateY(12px);
  }

  body.info-panel-open #ui-root .tool-cluster,
  body.compass-panel-open #ui-root .tool-cluster,
  body:has(#route-planner-panel.open) #ui-root .tool-cluster {
    opacity: 0;
    pointer-events: none;
    transform: translateY(-8px);
  }

  .main-actions .main-action-btn {
    min-width: 0;
    min-height: 54px;
    gap: 5px;
    padding: 7px 5px;
    font-size: 14px;
    letter-spacing: 0.04em;
  }

  .main-actions .main-action-btn .explore-ico,
  .explore-ico {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    font-size: 17px;
  }

  .main-actions .main-action-btn > span:not(.explore-ico) {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .maplibregl-ctrl-bottom-left,
  .maplibregl-ctrl-bottom-right {
    bottom: calc(var(--mobile-bottom-nav) + 6px) !important;
  }

  .toast,
  #geofence-toast {
    bottom: calc(var(--mobile-bottom-nav) + 12px);
  }
}

@media (max-width: 640px) and (orientation: portrait) {
  #app-header h1 {
    max-width: calc(100vw - 166px);
    font-size: 18px !important;
  }

  .tool-cluster {
    width: 152px;
  }

  .tool-btn,
  .layer-trigger {
    grid-template-columns: 22px minmax(0, 1fr) auto;
    padding: 0 8px;
  }

  .tool-badge {
    min-width: 24px;
    padding-inline: 4px;
  }

  .corner-fret {
    width: 34px;
    height: 34px;
    opacity: 0.28;
  }

  #mobile-cloud-intro {
    display: none !important;
  }

  .main-actions .main-action-btn {
    font-size: 13px;
  }
}

@media (max-width: 360px) {
  .tool-cluster,
  .layer-control {
    width: 142px;
  }

  .tool-btn,
  .layer-trigger {
    font-size: 12px;
  }

  .main-actions {
    gap: 4px;
  }

  .main-actions .main-action-btn {
    min-height: 50px;
    font-size: 12px;
  }

  .main-actions .main-action-btn .explore-ico {
    width: 25px;
    height: 25px;
    font-size: 15px;
  }
}

/* 侧边抽屉在手机竖屏上统一改为底部抽屉，避免横向挤压地图。 */
@media (max-width: 640px) and (orientation: portrait) {
  #info-panel,
  #compass-panel,
  #route-planner-panel,
  #nearby-drawer {
    top: auto !important;
    right: 0 !important;
    bottom: 0 !important;
    left: 0 !important;
    width: 100% !important;
    max-width: none !important;
    height: auto !important;
    max-height: calc(100dvh - max(18px, env(safe-area-inset-top))) !important;
    padding: 8px 8px max(8px, env(safe-area-inset-bottom)) !important;
    opacity: 0;
    transform: translateY(105%) !important;
  }

  #info-panel,
  #route-planner-panel {
    z-index: 38;
  }

  #compass-panel,
  #nearby-drawer {
    z-index: 37;
  }

  #info-panel.open,
  #compass-panel.open,
  #route-planner-panel.open,
  #nearby-drawer.open {
    opacity: 1;
    transform: translateY(0) !important;
    pointer-events: auto;
  }

  .glass-card,
  .compass-card,
  .route-planner-card,
  .nearby-card {
    height: auto !important;
    min-height: 0 !important;
    max-height: calc(100dvh - 18px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    border-radius: var(--mobile-sheet-radius) var(--mobile-sheet-radius) 0 0 !important;
    padding: 16px 14px max(16px, env(safe-area-inset-bottom)) !important;
    overflow: hidden;
  }

  .glass-card {
    overflow-y: auto;
  }

  .compass-content,
  .route-planner-content,
  .nearby-list {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .compass-content,
  .route-planner-content {
    max-height: calc(100dvh - 160px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  }

  .nearby-list {
    max-height: calc(100dvh - 154px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  }

  .close-btn,
  .memory-close,
  .episode-close {
    width: 44px !important;
    height: 44px !important;
  }

  .panel-close,
  .close-btn {
    top: 10px;
    right: 10px;
  }

  .impact-brief {
    gap: 10px;
    padding: 14px 12px 12px;
    border-radius: 12px;
  }

  .impact-kicker {
    flex-wrap: wrap;
    gap: 6px;
    letter-spacing: 0.08em;
  }

  .impact-era {
    margin-left: 0;
  }

  .impact-place,
  .panel-place-title {
    font-size: 28px;
    line-height: 1.12;
  }

  .impact-title {
    font-size: 17px;
  }

  .impact-story,
  .panel-description {
    font-size: 15px;
    line-height: 1.72;
  }

  .impact-brief .panel-image,
  .panel-image {
    height: auto;
    min-height: 0;
    max-height: 34dvh;
    aspect-ratio: 16 / 9;
  }

  .panel-want-card {
    grid-template-columns: 1fr;
  }

  .want-toggle {
    width: 100%;
    min-height: 44px;
  }

  .episode-enter-btn {
    min-height: 54px;
  }

  .compass-head,
  .route-planner-head,
  .nearby-head {
    gap: 10px;
    margin-bottom: 10px;
    padding-bottom: 10px;
  }

  .compass-title-main,
  .route-planner-title,
  .nearby-title {
    font-size: 20px;
  }

  .route-planner-head p {
    display: none;
  }

  .compass-tabs,
  .route-planner-tabs {
    position: sticky;
    top: 0;
    z-index: 3;
  }

  .compass-tab,
  .route-planner-tab {
    min-height: 44px;
    font-size: 13px;
  }

  .route-plan-bar,
  .route-result-head,
  .route-result-footer,
  .route-card-head,
  .route-actions,
  .compass-diy-meta,
  .rt-diy-actions {
    display: grid;
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .route-plan-actions,
  .rt-selection-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .route-plan-actions .rt-plan-btn,
  .route-plan-actions .rt-select-action,
  .rt-diy-actions .rt-plan-btn,
  .rt-diy-actions .rt-select-action {
    width: 100%;
  }

  .route-anchor-row,
  .route-result-stop {
    grid-template-columns: minmax(0, 1fr) 44px;
  }

  .route-result-stop {
    grid-template-columns: auto minmax(0, 1fr) auto;
  }

  .route-recommend-card {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .route-recommend-nav {
    width: 100%;
  }

  .route-anchor-copy > span:last-child,
  .route-recommend-copy em,
  .cn-title {
    white-space: normal;
  }

  .compass-anchor-info,
  .route-anchor-info {
    padding-block: 10px;
  }

  .compass-anchor-select,
  .route-anchor-select {
    width: 36px;
    height: 36px;
  }

  .cn-top {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .cn-name {
    white-space: normal;
  }

  .cn-dist {
    margin-left: 0;
  }
}

/* 弹窗和任务页：手机竖屏上尽量吃满可用高度，内容自身滚动。 */
@media (max-width: 640px) and (orientation: portrait) {
  #stamp-modal,
  #episode-layer,
  #clue-complete-modal {
    align-items: flex-end;
    overflow: hidden;
    padding: 8px 8px max(8px, env(safe-area-inset-bottom));
  }

  .stamp-card,
  .episode-scroll,
  .clue-complete-card {
    width: 100%;
    max-width: none;
    max-height: calc(100dvh - 16px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    border-radius: var(--mobile-sheet-radius) var(--mobile-sheet-radius) 0 0;
  }

  .stamp-card {
    overflow-x: hidden;
    padding: 18px 14px max(18px, env(safe-area-inset-bottom));
  }

  #stamp-modal .stamp-modal-close {
    position: fixed !important;
    top: max(10px, env(safe-area-inset-top));
    right: max(10px, env(safe-area-inset-right));
    z-index: 90;
    width: 44px !important;
    height: 44px !important;
    margin: 0;
    background: rgba(255, 252, 244, 0.88);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
  }

  .stamp-header {
    display: grid;
    grid-template-columns: 42px minmax(0, 1fr);
    gap: 10px;
    padding-right: 52px;
  }

  .stamp-title {
    font-size: 21px;
  }

  .stamp-total {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 8px;
  }

  .stamp-grid {
    grid-template-columns: repeat(auto-fit, minmax(88px, 1fr));
    gap: 8px;
  }

  .stamp-section,
  .stamp-sections,
  .stamp-grid,
  .stamp-cell {
    min-width: 0;
  }

  .stamp-cell {
    overflow: hidden;
    min-height: 104px;
    padding: 12px 6px;
  }

  .stamp-onsite {
    right: 2px;
    bottom: 2px;
  }

  .stamp-section-head {
    flex-wrap: wrap;
  }

  .episode-scroll {
    padding: 18px 14px max(20px, env(safe-area-inset-bottom));
  }

  .episode-progress {
    gap: 0;
    overflow-x: auto;
    padding: 0 48px 2px 0;
  }

  .ep-dot {
    width: 24px;
    height: 24px;
  }

  .ep-title,
  .ep-question {
    font-size: 20px;
    line-height: 1.45;
  }

  .ep-characters {
    gap: 10px;
    justify-content: flex-start;
    overflow-x: auto;
  }

  .ep-option {
    min-height: 50px;
    padding: 12px;
  }

  .ep-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .ep-btn,
  .rpg-next-btn,
  .rpg-ghost-btn,
  .clue-complete-actions button {
    min-height: 44px;
  }

  .clue-complete-actions {
    display: grid;
    grid-template-columns: 1fr;
  }
}

/* RPG 副本竖屏兜底：保留可玩性，不再强制横屏。 */
@media (orientation: portrait) and (max-width: 640px) {
  .episode-scroll.is-rpg-dialogue {
    width: 100vw !important;
    height: 100dvh !important;
    max-width: 100vw !important;
    max-height: 100dvh !important;
    border: 0 !important;
    border-radius: 0 !important;
    padding: 0 !important;
  }

  .episode-scroll.is-rpg-dialogue .episode-close {
    right: 10px;
    top: max(10px, env(safe-area-inset-top));
    z-index: 50;
  }

  .rpg-episode {
    height: 100dvh;
    overflow: hidden;
  }

  .rpg-hud {
    left: 12px !important;
    right: 58px !important;
    top: max(10px, env(safe-area-inset-top)) !important;
    width: auto !important;
    max-width: none !important;
    gap: 4px;
  }

  .rpg-scene-title {
    font-size: 20px;
    line-height: 1.12;
  }

  .rpg-progress {
    flex-wrap: wrap;
  }

  .rpg-task,
  .rpg-clue-meter {
    font-size: 10px;
    line-height: 1.35;
  }

  .rpg-npc {
    right: -12% !important;
    bottom: 44dvh !important;
    width: 52% !important;
    height: 34dvh !important;
    opacity: 0.72;
  }

  .rpg-hotspots {
    inset: 86px 0 42dvh;
  }

  .rpg-hotspot {
    min-height: 34px;
    padding: 6px 8px;
    font-size: 10px;
  }

  .rpg-hotspot-label {
    max-width: 110px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .rpg-dialogue,
  .rpg-dialogue-player,
  .rpg-dialogue-narration {
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100% !important;
    min-height: 0 !important;
    max-height: 50dvh !important;
    border: 0 !important;
    border-radius: 14px 14px 0 0 !important;
    padding: 26px 14px max(14px, env(safe-area-inset-bottom)) !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
  }

  .rpg-dialogue-copy,
  .rpg-clue-dialogue-copy,
  .rpg-options {
    max-width: 100% !important;
  }

  .rpg-dialogue-copy p {
    font-size: 13px;
    line-height: 1.72;
    overflow-wrap: anywhere;
  }

  .rpg-options {
    grid-template-columns: 1fr !important;
    gap: 7px;
  }

  .rpg-option {
    padding: 9px 10px;
  }

  .rpg-clue-panel {
    left: 0 !important;
    right: 0 !important;
    bottom: 50dvh !important;
    width: 100% !important;
    max-height: 26dvh;
    overflow-y: auto;
    border-radius: 0;
  }

  .rpg-reward-panel {
    width: min(100% - 24px, 420px);
    max-height: calc(100dvh - 32px);
    overflow-y: auto;
    padding: 18px 14px;
  }
}

/* 记忆、好友、账号等二级面板的手机安全区与小屏排版。 */
@media (max-width: 640px) and (orientation: portrait) {
  .memory-panel,
  .friends-panel,
  .friend-detail-panel {
    right: 8px !important;
    bottom: max(8px, env(safe-area-inset-bottom)) !important;
    left: 8px !important;
    width: auto !important;
    max-height: calc(100dvh - 16px - env(safe-area-inset-top) - env(safe-area-inset-bottom)) !important;
    padding: 16px !important;
  }

  #memory-shell.memory-mode-auth .memory-panel,
  #memory-shell.memory-mode-auth.memory-shell-open .memory-panel {
    top: auto !important;
    right: 8px !important;
    bottom: max(8px, env(safe-area-inset-bottom)) !important;
    left: 8px !important;
    transform: translateY(0) !important;
  }

  .memory-panel-head {
    padding-right: 46px;
  }

  .memory-create-media-combined {
    min-height: 132px;
  }

  .memory-create-media-combined .memory-create-media-preview {
    max-height: 150px;
  }

  .memory-create-media-combined .memory-create-media-actions,
  .memory-create-voice-bar,
  .memory-pinned-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .memory-create-media-combined .memory-create-media-btn,
  .memory-create-voice-btn,
  .memory-create-voice-play,
  .memory-create-voice-delete,
  .memory-pinned-another,
  .memory-pinned-browse,
  .memory-pinned-exit,
  .memory-primary,
  .memory-danger,
  .friend-search-btn,
  .friend-add-btn,
  .friend-accept-btn,
  .friend-reject-btn,
  .friend-remove-btn {
    min-height: 44px;
  }

  .memory-list-item {
    grid-template-columns: 52px minmax(0, 1fr);
  }

  .memory-list-item img,
  .memory-list-thumb-fallback {
    width: 52px;
    height: 52px;
  }

  .auth-phone-row,
  .friend-add-form {
    grid-template-columns: 1fr;
  }

  .account-overlay {
    align-items: flex-end;
    padding: 8px 8px max(8px, env(safe-area-inset-bottom));
  }

  .account-content {
    width: 100%;
    max-height: calc(100dvh - 16px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    overflow-y: auto;
  }
}

@media (max-height: 520px) and (orientation: landscape) {
  html,
  body,
  #ui-root {
    overflow: hidden;
  }

  #info-panel,
  #compass-panel,
  #route-planner-panel,
  #nearby-drawer {
    padding: 6px !important;
  }

  .glass-card,
  .compass-card,
  .route-planner-card,
  .nearby-card {
    max-height: calc(100dvh - 12px);
    padding: 12px !important;
  }

  .compass-content,
  .route-planner-content,
  .nearby-list {
    max-height: calc(100dvh - 112px);
  }

  .main-actions {
    bottom: max(6px, env(safe-area-inset-bottom));
  }

  .tool-cluster {
    top: calc(44px + env(safe-area-inset-top));
  }
}

@media (prefers-reduced-motion: reduce) {
  #info-panel,
  #compass-panel,
  #route-planner-panel,
  #nearby-drawer,
  .main-actions,
  .tool-cluster,
  .layer-menu,
  .lang-menu {
    transition: none !important;
  }
}

/* 触控横屏：iPhone / iPad 浏览器工具栏会吃掉高度，副本和右侧面板不能沿用桌面密度。 */
@media (orientation: landscape) and (max-width: 1180px) {
  body.mobile-app #episode-layer {
    align-items: stretch !important;
    justify-content: stretch !important;
    padding: 0 !important;
    transition: none !important;
  }

  body.mobile-app #episode-layer.open {
    opacity: 1 !important;
  }

  body.mobile-app:has(#episode-layer.open) #app-header,
  body.mobile-app:has(#episode-layer.open) #breadcrumb,
  body.mobile-app:has(#episode-layer.open) #ui-root .tool-cluster,
  body.mobile-app:has(#episode-layer.open) #ui-root .layer-control,
  body.mobile-app:has(#episode-layer.open) #ui-root .main-actions,
  body.mobile-app:has(#episode-layer.open) #ui-root .bgm-toggle {
    opacity: 0 !important;
    pointer-events: none !important;
    transition: none !important;
  }

  body.mobile-app:has(#episode-layer.open) {
    overflow: hidden !important;
  }

  body.mobile-app:has(#episode-layer.open) #info-panel,
  body.mobile-app:has(#episode-layer.open) #compass-panel,
  body.mobile-app:has(#episode-layer.open) #route-planner-panel,
  body.mobile-app:has(#episode-layer.open) #nearby-drawer,
  body.mobile-app:has(#episode-layer.open) #memory-panel,
  body.mobile-app:has(#episode-layer.open) .memory-panel,
  body.mobile-app:has(#episode-layer.open) .friends-panel,
  body.mobile-app:has(#episode-layer.open) .friend-detail-panel,
  body.mobile-app:has(#episode-layer.open) .account-overlay {
    display: none !important;
  }

  body.mobile-app .episode-scroll.is-rpg-dialogue {
    width: 100vw !important;
    max-width: 100vw !important;
    height: 100svh !important;
    height: 100dvh !important;
    max-height: 100svh !important;
    max-height: 100dvh !important;
    border: 0 !important;
    border-radius: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
    transform: none !important;
    transition: none !important;
  }

  body.mobile-app #stamp-modal.open .stamp-card {
    transform: none !important;
  }

  body.mobile-app #stamp-modal.open .stamp-modal-close {
    position: fixed !important;
    top: max(10px, env(safe-area-inset-top)) !important;
    right: max(10px, env(safe-area-inset-right)) !important;
    z-index: 90;
    width: 44px !important;
    height: 44px !important;
    margin: 0 !important;
    background: rgba(255, 252, 244, 0.9);
    box-shadow: 0 10px 24px -18px rgba(40, 30, 16, 0.75);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
  }

  body.mobile-app .episode-scroll.is-rpg-dialogue .episode-body,
  body.mobile-app .rpg-episode {
    height: 100%;
    min-height: 0;
    overflow: hidden;
  }

  body.mobile-app .episode-scroll.is-rpg-dialogue .episode-close {
    top: max(8px, env(safe-area-inset-top)) !important;
    right: max(8px, env(safe-area-inset-right)) !important;
    width: 34px !important;
    height: 34px !important;
    z-index: 50;
  }

  body.mobile-app .rpg-bg {
    transform: none;
  }

  body.mobile-app .rpg-hud {
    top: max(8px, env(safe-area-inset-top)) !important;
    left: max(12px, env(safe-area-inset-left)) !important;
    right: auto !important;
    width: min(52vw, 430px) !important;
    max-width: min(52vw, 430px) !important;
    gap: 3px !important;
  }

  body.mobile-app .rpg-kicker,
  body.mobile-app .rpg-act-title,
  body.mobile-app .rpg-chapter {
    font-size: 9px;
  }

  body.mobile-app .rpg-progress {
    gap: 3px;
  }

  body.mobile-app .rpg-chapter {
    padding: 2px 5px;
  }

  body.mobile-app .rpg-scene-title {
    margin: 0;
    font-size: clamp(17px, 2.8vw, 24px);
    line-height: 1.08;
  }

  body.mobile-app .rpg-task,
  body.mobile-app .rpg-clue-meter {
    max-width: min(52vw, 430px);
    padding: 4px 7px;
    border-radius: 8px;
    font-size: 10px;
    line-height: 1.35;
  }

  body.mobile-app .rpg-npc {
    right: max(28px, calc(3vw + env(safe-area-inset-right))) !important;
    bottom: clamp(112px, 29dvh, 190px) !important;
    width: clamp(190px, 29vw, 340px) !important;
    height: min(70dvh, 520px) !important;
    opacity: 0.98;
    z-index: 3;
  }

  body.mobile-app .rpg-dialogue,
  body.mobile-app .rpg-dialogue-player,
  body.mobile-app .rpg-dialogue-narration {
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100% !important;
    min-height: 0 !important;
    max-height: min(46dvh, 230px) !important;
    border: 0 !important;
    border-radius: 12px 12px 0 0 !important;
    padding: 62px 16px max(12px, env(safe-area-inset-bottom)) !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    box-sizing: border-box;
  }

  body.mobile-app .rpg-dialogue::before {
    inset: 5px;
    border-radius: 8px;
  }

  body.mobile-app .rpg-dialogue-npc {
    padding-top: 62px !important;
  }

  body.mobile-app .rpg-speaker-tab {
    left: 14px;
    top: 8px !important;
    min-width: 0;
    max-width: calc(100% - 72px);
    gap: 6px;
    padding: 5px 9px 5px 5px;
    border-radius: 8px 8px 5px 5px;
  }

  body.mobile-app .rpg-speaker-tab-npc {
    top: 8px !important;
  }

  body.mobile-app .rpg-speaker-avatar-mini {
    width: 28px;
    height: 28px;
    font-size: 13px;
  }

  body.mobile-app .rpg-record-mark {
    width: 20px;
    height: 20px;
    font-size: 12px;
  }

  body.mobile-app .rpg-speaker-tab strong {
    font-size: 12px;
  }

  body.mobile-app .rpg-speaker-tab span {
    font-size: 9px;
  }

  body.mobile-app .rpg-dialogue-copy,
  body.mobile-app .rpg-clue-dialogue-copy,
  body.mobile-app .rpg-options {
    max-width: 100% !important;
  }

  body.mobile-app .rpg-dialogue-copy p {
    font-size: clamp(12px, 1.6vw, 14px);
    line-height: 1.62;
    overflow-wrap: anywhere;
  }

  body.mobile-app .rpg-clue-dialogue-copy {
    padding-right: 0;
    padding-bottom: 20px;
  }

  body.mobile-app .rpg-options {
    grid-template-columns: 1fr !important;
    gap: 5px;
    margin-top: 6px;
  }

  body.mobile-app .rpg-option {
    min-height: 34px;
    padding: 6px 9px;
  }

  body.mobile-app .rpg-option b {
    font-size: 11px;
    line-height: 1.35;
  }

  body.mobile-app .rpg-dialogue-actions {
    position: sticky;
    bottom: 0;
    justify-content: flex-end;
    margin-top: 7px;
  }

  body.mobile-app .rpg-next-btn,
  body.mobile-app .rpg-ghost-btn {
    min-height: 36px;
    padding: 7px 14px;
    font-size: 12px;
  }

  body.mobile-app .rpg-hotspot {
    min-height: 32px;
    padding: 5px 7px;
    font-size: 10px;
  }

  body.mobile-app .rpg-hotspot-label {
    display: inline-block !important;
    max-width: 96px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  body.mobile-app .rpg-clue-panel {
    left: max(10px, env(safe-area-inset-left)) !important;
    right: max(10px, env(safe-area-inset-right)) !important;
    bottom: min(46dvh, 230px) !important;
    width: auto !important;
    max-height: 28dvh;
    overflow-y: auto;
  }

  body.mobile-app #info-panel,
  body.mobile-app #compass-panel,
  body.mobile-app #route-planner-panel,
  body.mobile-app #nearby-drawer {
    width: min(43vw, 420px) !important;
    max-width: min(43vw, 420px) !important;
    padding: 8px !important;
  }

  body.mobile-app .glass-card,
  body.mobile-app .compass-card,
  body.mobile-app .route-planner-card,
  body.mobile-app .nearby-card {
    max-height: calc(100dvh - 16px);
    padding: 14px !important;
    border-radius: 14px !important;
  }

  body.mobile-app #memory-shell:not(.memory-shell-open) .memory-panel {
    display: none !important;
  }

  body.mobile-app .impact-brief {
    gap: 8px;
    padding: 12px;
    border-radius: 13px;
  }

  body.mobile-app .impact-kicker {
    gap: 6px;
    font-size: 9px;
    letter-spacing: 0.08em;
  }

  body.mobile-app .impact-era {
    font-size: 9px;
  }

  body.mobile-app .impact-place,
  body.mobile-app .panel-place-title {
    font-size: clamp(22px, 3.2vw, 30px) !important;
    line-height: 1.1;
  }

  body.mobile-app .impact-title,
  body.mobile-app .panel-story-title {
    font-size: clamp(15px, 2vw, 18px);
    line-height: 1.35;
  }

  body.mobile-app .impact-story,
  body.mobile-app .panel-description {
    font-size: 14px !important;
    line-height: 1.58;
  }

  body.mobile-app .impact-brief .panel-image,
  body.mobile-app .panel-image {
    height: clamp(92px, 22dvh, 150px) !important;
    min-height: 0 !important;
    max-height: 150px !important;
    aspect-ratio: 16 / 8;
  }

  body.mobile-app .impact-facts {
    gap: 6px;
  }

  body.mobile-app .impact-facts span {
    gap: 6px;
    padding: 6px 8px;
    font-size: 11px;
    line-height: 1.32;
  }

  body.mobile-app .episode-enter-btn {
    grid-template-columns: 34px minmax(0, 1fr) 28px;
    gap: 10px;
    min-height: 52px;
    padding: 9px 11px;
    border-radius: 14px;
  }

  body.mobile-app .episode-enter-btn::before {
    width: 32px;
    height: 32px;
  }

  body.mobile-app .episode-enter-btn .ee-icon {
    width: 34px;
    height: 34px;
    border-radius: 10px;
  }

  body.mobile-app .episode-enter-btn .ee-icon svg {
    width: 20px;
    height: 20px;
  }

  body.mobile-app .episode-enter-btn .ee-copy {
    font-size: 13px;
    line-height: 1.35;
  }

  body.mobile-app .episode-enter-btn .ee-arrow {
    width: 28px;
    height: 28px;
    font-size: 18px;
  }

  body.mobile-app .compass-head,
  body.mobile-app .route-planner-head,
  body.mobile-app .nearby-head {
    gap: 7px;
    margin-bottom: 8px;
    padding-bottom: 8px;
  }

  body.mobile-app .compass-title-main,
  body.mobile-app .route-planner-title,
  body.mobile-app .nearby-title {
    font-size: 18px !important;
  }

  body.mobile-app .compass-title-sub,
  body.mobile-app .route-planner-head p {
    font-size: 10px;
    line-height: 1.35;
  }

  body.mobile-app .compass-tabs,
  body.mobile-app .route-planner-tabs {
    gap: 4px;
    padding: 3px;
  }

  body.mobile-app .compass-tab,
  body.mobile-app .route-planner-tab {
    min-height: 34px;
    padding: 6px;
    font-size: 11px;
  }

  body.mobile-app .compass-content,
  body.mobile-app .route-planner-content,
  body.mobile-app .nearby-list {
    max-height: calc(100dvh - 112px);
  }

  body.mobile-app .route-anchor-list-full,
  body.mobile-app .compass-near-list {
    gap: 6px;
  }

  body.mobile-app .route-anchor-row,
  body.mobile-app .compass-near-item {
    border-radius: 9px;
  }

  body.mobile-app .route-anchor-row {
    gap: 7px;
    padding: 7px;
  }

  body.mobile-app .compass-anchor-info,
  body.mobile-app .route-anchor-info {
    min-height: 36px;
    padding-block: 7px;
  }

  body.mobile-app .compass-anchor-info {
    padding-left: 9px;
    padding-right: 6px;
  }

  body.mobile-app .cn-name,
  body.mobile-app .route-anchor-top b {
    font-size: 14px !important;
  }

  body.mobile-app .cn-title,
  body.mobile-app .cn-hero,
  body.mobile-app .route-anchor-copy > span:last-child {
    font-size: 10px;
    line-height: 1.3;
  }

  body.mobile-app .cn-rank {
    width: 20px;
    height: 20px;
    font-size: 11px;
  }

  body.mobile-app .compass-anchor-select,
  body.mobile-app .route-anchor-select {
    width: 28px;
    height: 28px;
    min-height: 28px;
  }
}

@media (orientation: landscape) and (max-height: 430px) and (max-width: 1180px) {
  body.mobile-app .rpg-dialogue,
  body.mobile-app .rpg-dialogue-player,
  body.mobile-app .rpg-dialogue-narration {
    max-height: min(49dvh, 190px) !important;
    padding: 62px 12px max(9px, env(safe-area-inset-bottom)) !important;
  }

  body.mobile-app .rpg-npc {
    bottom: clamp(92px, 27dvh, 132px) !important;
    width: clamp(170px, 27vw, 260px) !important;
    height: min(68dvh, 300px) !important;
  }

  body.mobile-app .rpg-dialogue-copy p {
    font-size: 12px;
    line-height: 1.52;
  }

  body.mobile-app .impact-brief .panel-image,
  body.mobile-app .panel-image {
    height: clamp(82px, 20dvh, 118px) !important;
  }
}

/* ════════════════════════════════════════════════════════════════
   横屏全局紧凑模式 · 手游级信息密度
   覆盖：记忆面板 / 好友面板 / 账号面板 / 信息面板 / 指南针面板
   策略：窄侧栏 + 微型字号 + 极限压缩留白 + 水平按钮排列
   ════════════════════════════════════════════════════════════════ */
@media (orientation: landscape) and (max-height: 600px) {

  /* ═══ 记忆面板 ═══ */
  body.mobile-app .memory-panel,
  .memory-panel {
    right: 6px !important;
    bottom: max(6px, env(safe-area-inset-bottom)) !important;
    left: auto !important;
    top: max(6px, env(safe-area-inset-top)) !important;
    width: min(300px, 40vw) !important;
    max-width: min(300px, 40vw) !important;
    max-height: calc(100dvh - 12px) !important;
    padding: 8px 10px !important;
    border-radius: 8px !important;
    border-width: 1px !important;
    transform: none !important;
    box-shadow: 0 4px 12px -8px rgba(23,26,32,0.5) !important;
    overscroll-behavior: contain !important;
    -webkit-overflow-scrolling: touch;
    font-size: 11px !important;
  }

  /* 认证模式面板也紧凑 */
  #memory-shell.memory-mode-auth .memory-panel,
  #memory-shell.memory-mode-auth.memory-shell-open .memory-panel {
    right: 6px !important;
    bottom: max(6px, env(safe-area-inset-bottom)) !important;
    left: auto !important;
    top: max(6px, env(safe-area-inset-top)) !important;
    transform: none !important;
    width: min(300px, 40vw) !important;
    max-height: calc(100dvh - 12px) !important;
  }

  /* 标题栏 */
  body.mobile-app .memory-panel-head,
  .memory-panel-head {
    min-height: 20px !important;
    padding: 0 26px 4px 0 !important;
    margin-bottom: 4px !important;
    border-bottom-width: 1px !important;
  }
  .memory-panel-seal {
    width: 18px !important;
    height: 18px !important;
    font-size: 11px !important;
    border-radius: 3px !important;
  }
  .memory-panel-title,
  .memory-panel-head h2 {
    font-size: 13px !important;
    font-weight: 700 !important;
  }
  .memory-close {
    top: 4px !important;
    right: 4px !important;
    width: 22px !important;
    height: 22px !important;
    min-height: 22px !important;
    font-size: 12px !important;
    border-radius: 5px !important;
    border-width: 1px !important;
  }

  /* 提示文字 */
  .memory-hint,
  .memory-count,
  .auth-message {
    margin: 4px 0 0 !important;
    font-size: 10px !important;
    line-height: 1.4 !important;
  }

  /* 入口按钮 */
  .memory-create-list-entry {
    margin: 3px 0 0 !important;
  }
  .memory-create-list-entry button {
    min-height: 22px !important;
    font-size: 10px !important;
    padding: 0 6px !important;
    border-radius: 5px !important;
  }

  /* 表单整体 */
  .memory-form,
  .auth-form,
  .memory-detail {
    gap: 5px !important;
    margin-top: 5px !important;
  }
  .memory-form {
    overflow-y: auto !important;
    max-height: calc(100dvh - 56px) !important;
    overscroll-behavior: contain !important;
    padding-right: 2px !important;
  }

  /* 媒体区域：极限压缩 */
  .memory-create-media-combined {
    min-height: 48px !important;
    border-radius: 5px !important;
    border-width: 1px !important;
  }
  .memory-create-media-combined .memory-create-media-empty {
    gap: 2px !important;
    padding: 4px 4px 2px !important;
    font-size: 9px !important;
  }
  .memory-create-media-combined .memory-create-media-empty .ink-cam-icon {
    width: 18px !important;
    height: 12px !important;
    border-width: 1px !important;
    border-radius: 3px !important;
  }
  .memory-create-media-combined .memory-create-media-empty .ink-cam-icon::before {
    left: 4px !important;
    top: 2px !important;
    width: 6px !important;
    height: 6px !important;
    border-width: 1px !important;
  }
  .memory-create-media-combined .memory-create-media-empty .ink-cam-icon::after {
    left: 2px !important;
    top: -2px !important;
    width: 6px !important;
    height: 3px !important;
  }
  .memory-create-media-combined .memory-create-media-preview {
    max-height: 52px !important;
  }

  /* 媒体按钮：水平排列 */
  .memory-create-media-combined .memory-create-media-actions {
    display: flex !important;
    flex-wrap: nowrap !important;
    gap: 3px !important;
    padding: 3px 4px !important;
    margin-top: 0 !important;
  }
  .memory-create-media-combined .memory-create-media-btn {
    flex: 1 !important;
    min-width: 0 !important;
    min-height: 20px !important;
    border-radius: 4px !important;
    font-size: 9px !important;
    padding: 0 3px !important;
    border-width: 1px !important;
  }

  /* 录音栏 */
  .memory-create-voice-bar {
    display: flex !important;
    flex-wrap: nowrap !important;
    align-items: center !important;
    gap: 4px !important;
    padding: 3px 5px !important;
    border-radius: 5px !important;
    border-width: 1px !important;
  }
  .memory-create-voice-btn {
    min-height: 20px !important;
    font-size: 9px !important;
    border-radius: 4px !important;
    padding: 0 5px !important;
  }
  .memory-create-voice-play,
  .memory-create-voice-delete {
    min-height: 20px !important;
    font-size: 9px !important;
    border-radius: 4px !important;
    padding: 0 5px !important;
  }
  .memory-create-voice-timer,
  .memory-create-voice-max {
    font-size: 8px !important;
  }

  /* 文本输入 */
  .memory-field > span {
    font-size: 9px !important;
  }
  .memory-field textarea,
  .memory-field input {
    min-height: 32px !important;
    font-size: 10px !important;
    border-radius: 5px !important;
    padding: 4px 6px !important;
    border-width: 1px !important;
  }

  /* 坐标行 */
  .memory-meta-line,
  .memory-detail-meta {
    font-size: 8px !important;
    padding-top: 3px !important;
    border-top-width: 1px !important;
  }

  /* 发布按钮 */
  .memory-create-publish {
    min-height: 26px !important;
    font-size: 11px !important;
    border-radius: 5px !important;
    margin-top: 2px !important;
    border-width: 1px !important;
  }

  /* 固定锚点按钮 */
  .memory-pinned-actions {
    display: flex !important;
    flex-wrap: nowrap !important;
    gap: 3px !important;
  }
  .memory-pinned-another,
  .memory-pinned-browse,
  .memory-pinned-exit {
    flex: 1 !important;
    min-height: 20px !important;
    font-size: 9px !important;
    border-radius: 4px !important;
    padding: 0 3px !important;
  }

  /* 记忆列表项 */
  .memory-list {
    gap: 4px !important;
    margin-top: 6px !important;
  }
  .memory-list-item {
    grid-template-columns: 40px minmax(0, 1fr) !important;
    gap: 6px !important;
    min-height: 40px !important;
    padding: 4px !important;
    border-radius: 5px !important;
    border-width: 1px !important;
  }
  .memory-list-item img,
  .memory-list-thumb-fallback {
    width: 40px !important;
    height: 36px !important;
    border-radius: 4px !important;
  }
  .memory-list-copy b {
    font-size: 10px !important;
  }
  .memory-list-copy small {
    font-size: 9px !important;
  }

  /* 空状态 */
  .memory-empty {
    padding: 8px !important;
    font-size: 10px !important;
    border-radius: 5px !important;
    border-width: 1px !important;
  }

  /* 回忆统计 */
  .recollect-summary {
    gap: 6px !important;
    margin: 4px 0 6px !important;
  }
  .recollect-stat {
    padding: 4px 3px !important;
    border-radius: 6px !important;
    border-width: 1px !important;
  }
  .recollect-stat-num {
    font-size: 16px !important;
  }
  .recollect-stat-label {
    font-size: 8px !important;
  }

  /* ═══ 好友面板 ═══ */
  body.mobile-app .friends-panel,
  .friends-panel,
  body.mobile-app .friend-detail-panel,
  .friend-detail-panel {
    right: 6px !important;
    bottom: max(6px, env(safe-area-inset-bottom)) !important;
    left: auto !important;
    top: max(6px, env(safe-area-inset-top)) !important;
    width: min(300px, 40vw) !important;
    max-width: min(300px, 40vw) !important;
    max-height: calc(100dvh - 12px) !important;
    padding: 8px 10px !important;
    border-radius: 8px !important;
    overflow-y: auto !important;
    overscroll-behavior: contain !important;
  }
  .friend-search-btn,
  .friend-add-btn,
  .friend-accept-btn,
  .friend-reject-btn,
  .friend-remove-btn {
    min-height: 22px !important;
    font-size: 9px !important;
    border-radius: 4px !important;
    padding: 0 6px !important;
  }
  .auth-phone-row,
  .friend-add-form {
    grid-template-columns: 1fr !important;
    gap: 4px !important;
  }

  /* ═══ 账号面板：横屏居中、宽度合理、文字不被截断 ═══ */
  .account-overlay {
    align-items: center !important;
    justify-content: center !important;
    padding: 12px !important;
  }
  .account-content {
    width: min(420px, 88vw) !important;
    max-height: calc(100dvh - 24px) !important;
    border-radius: 14px !important;
    padding: 28px 26px !important;
    overflow-y: auto !important;
  }

  /* ═══ 信息面板 / 指南针面板 / 路线规划 ═══ */
  #info-panel,
  #compass-panel,
  #route-planner-panel,
  #nearby-drawer {
    right: 6px !important;
    left: auto !important;
    width: min(300px, 40vw) !important;
    max-width: min(300px, 40vw) !important;
    padding: 6px !important;
    border-radius: 8px !important;
  }
  .glass-card,
  .compass-card,
  .route-planner-card,
  .nearby-card {
    max-height: calc(100dvh - 24px) !important;
    padding: 8px 10px !important;
    border-radius: 6px !important;
  }
  .compass-content,
  .route-planner-content,
  .nearby-list {
    max-height: calc(100dvh - 80px) !important;
  }
}

/* 最后一层手机横屏兜底：文本优先，避免探索面板一次性加载多张背景图。 */
@media (orientation: landscape) and (max-width: 1180px) and (max-height: 620px) {
  body.mobile-app .tool-cluster {
    width: min(148px, calc(100vw - 20px)) !important;
  }

  body.mobile-app .tool-btn,
  body.mobile-app .layer-trigger {
    height: 32px !important;
    min-height: 32px !important;
    font-size: 12px !important;
    padding: 0 7px !important;
  }

  body.mobile-app #info-panel,
  body.mobile-app #compass-panel,
  body.mobile-app #route-planner-panel,
  body.mobile-app #nearby-drawer {
    width: min(340px, 40vw) !important;
    max-width: min(340px, 40vw) !important;
  }

  body.mobile-app .glass-card,
  body.mobile-app .compass-card,
  body.mobile-app .route-planner-card,
  body.mobile-app .nearby-card {
    padding: 10px 11px !important;
  }

  body.mobile-app .compass-head,
  body.mobile-app .route-planner-head,
  body.mobile-app .nearby-head {
    margin-bottom: 6px !important;
    padding: 4px 2px 8px !important;
  }

  body.mobile-app .compass-title-main,
  body.mobile-app .route-planner-title,
  body.mobile-app .nearby-title {
    font-size: 17px !important;
    line-height: 1.08 !important;
  }

  body.mobile-app .compass-title-sub,
  body.mobile-app .route-planner-head p {
    font-size: 9px !important;
  }

  body.mobile-app .clue-brief {
    margin-bottom: 7px !important;
    padding-bottom: 8px !important;
  }

  body.mobile-app .clue-brief p {
    font-size: 11px !important;
    line-height: 1.45 !important;
  }

  body.mobile-app .nearby-clue-list {
    gap: 8px !important;
  }

  body.mobile-app .clue-card::after {
    background-image:
      linear-gradient(135deg, rgba(255, 252, 244, 0.96), rgba(232, 222, 196, 0.9)),
      radial-gradient(circle at 100% 0, color-mix(in srgb, var(--clue-task-accent, #3f7d6e) 16%, transparent), transparent 42%),
      var(--clue-cover-image),
      var(--clue-bg-image, url('../public/assets/clues/fallback-cover.webp')),
      url('../public/assets/clues/fallback-cover.webp') !important;
    background-position: center, center, center right, center right, center right !important;
    background-size: cover, cover, cover, cover, cover !important;
    opacity: 1 !important;
    filter: none !important;
  }

  body.mobile-app .clue-card::before {
    inset: 5px !important;
    opacity: 0.55 !important;
  }

  body.mobile-app .clue-card-open {
    gap: 5px !important;
    padding: 11px 12px 8px !important;
  }

  body.mobile-app .clue-type,
  body.mobile-app .clue-distance {
    min-height: 18px !important;
    font-size: 9px !important;
  }

  body.mobile-app .clue-type {
    padding: 3px 6px !important;
  }

  body.mobile-app .clue-place-title {
    font-size: 17px !important;
    line-height: 1.12 !important;
  }

  body.mobile-app .clue-mission {
    font-size: 11px !important;
    line-height: 1.35 !important;
  }

  body.mobile-app .clue-description {
    display: -webkit-box !important;
    overflow: hidden !important;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    font-size: 11px !important;
    line-height: 1.48 !important;
  }

  body.mobile-app .clue-cta {
    width: calc(100% - 24px) !important;
    margin: 0 12px 11px !important;
    padding-top: 8px !important;
    font-size: 11px !important;
  }

  body.mobile-app .impact-brief {
    gap: 7px !important;
    padding: 10px !important;
  }

  body.mobile-app .impact-place,
  body.mobile-app .panel-place-title {
    font-size: clamp(20px, 2.7vw, 26px) !important;
  }

  body.mobile-app .impact-title,
  body.mobile-app .panel-story-title {
    font-size: 14px !important;
  }

  body.mobile-app .impact-story,
  body.mobile-app .panel-description {
    font-size: 12px !important;
    line-height: 1.55 !important;
  }

  body.mobile-app .impact-brief .panel-image,
  body.mobile-app .panel-image {
    height: clamp(78px, 18dvh, 112px) !important;
    max-height: 112px !important;
  }
}
