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

@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', 'Noto Serif SC', 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 (pointer: coarse) and (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', 'Noto Serif SC', 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); }
}
