@media (min-width: 768px) {
  .topbar {
    min-height: calc(72px + var(--safe-top));
    padding-left: max(32px, var(--safe-left));
    padding-right: max(32px, var(--safe-right));
  }

  .topbar--map {
    min-height: calc(60px + var(--safe-top));
    padding-bottom: 4px;
    padding-top: calc(8px + var(--safe-top));
  }

  .map-page { padding: 4px 32px max(12px, var(--safe-bottom)); }
  .map-intro { margin: 2px 2px 12px; }

  .map-shell {
    align-content: start;
    gap: 12px 22px;
    grid-template-areas:
      "controls map"
      "selection map"
      "confirm map";
    grid-template-columns: minmax(300px, 0.46fr) minmax(390px, 1fr);
    grid-template-rows: auto auto auto;
  }

  .location-controls { grid-area: controls; }
  .map-canvas {
    grid-area: map;
    height: clamp(400px, calc(100vh - 190px), 570px);
    height: clamp(400px, calc(100dvh - 190px), 570px);
    min-height: 0;
  }
  .selected-location-card { grid-area: selection; }
  .primary-button {
    grid-area: confirm;
    justify-self: start;
    width: 250px;
  }

  .scene-content {
    padding-left: 5vw;
    padding-right: 5vw;
  }

  .scene-selector,
  .details-panel {
    left: 50%;
    margin-left: -260px;
    right: auto;
    width: 520px;
  }

  .scene-options { grid-template-columns: repeat(4, 1fr); }
  .scene-option { flex-direction: column; gap: 3px; justify-content: center; padding: 9px; text-align: center; }
}

@media (min-width: 1024px) {
  .map-page { padding-top: 2px; }

  .map-intro {
    left: 6px;
    margin-bottom: 12px;
    position: relative;
  }

  .map-shell {
    background: rgba(255, 255, 255, 0.44);
    border: 1px solid rgba(60, 83, 89, 0.08);
    border-radius: var(--radius-large);
    box-shadow: 0 30px 80px rgba(45, 72, 80, 0.09);
    gap: 14px 24px;
    grid-template-columns: minmax(320px, 0.4fr) minmax(520px, 1fr);
    padding: clamp(18px, 2vh, 24px);
    padding: clamp(18px, 2dvh, 24px);
  }

  .map-canvas {
    height: clamp(400px, calc(100vh - 210px), 570px);
    height: clamp(400px, calc(100dvh - 210px), 570px);
  }

  .scene-content {
    padding-bottom: 34px;
  }

  .scene-place { margin-top: 1vh; }
  .experience-controls { max-width: min(860px, 66vw); }

  .details-panel {
    border-radius: 26px 0 0 26px;
    bottom: 22px;
    left: auto;
    margin: 0;
    max-height: calc(100svh - 44px);
    right: 0;
    top: 22px;
    width: min(390px, 38vw);
  }

  .details-panel:not([hidden]) {
    animation-name: panel-in;
  }

  @keyframes panel-in {
    from { opacity: 0; transform: translateX(30px); }
    to { opacity: 1; transform: translateX(0); }
  }

  .scene-selector {
    bottom: 126px;
    left: 5vw;
    margin: 0;
    right: auto;
    width: 470px;
  }
}

@media (max-width: 767px) {
  /* Keep each scene's photographic subject above the controls on portrait screens. */
  .scene-visual[data-scene-type="water"] {
    --scene-position-x: 43%;
    --scene-position-y: 50%;
    --scene-scale: 1.14;
    --scene-translate-y: -7%;
  }

  .scene-visual[data-scene-type="mountain"] {
    --scene-position-x: 60%;
    --scene-position-y: 50%;
    --scene-scale: 1.04;
    --scene-translate-y: 1%;
  }

  .scene-visual[data-scene-type="plain"] {
    --scene-position-x: 50%;
    --scene-position-y: 50%;
    --scene-scale: 1.02;
    --scene-translate-y: -1%;
  }

  .scene-visual[data-scene-type="city"] {
    --scene-position-x: 40%;
    --scene-position-y: 50%;
    --scene-scale: 1.16;
    --scene-translate-y: -7.5%;
  }

  .secondary-actions {
    margin-bottom: 6px;
  }

  .ghost-button {
    background:
      linear-gradient(180deg, rgba(27, 32, 58, 0.50), rgba(16, 21, 44, 0.38));
    border-color: rgba(255, 255, 255, 0.32);
    box-shadow:
      0 9px 26px rgba(4, 8, 20, 0.23),
      inset 0 1px rgba(255, 255, 255, 0.20);
    color: rgba(255, 255, 255, 0.96);
    min-height: 44px;
    -webkit-backdrop-filter: blur(24px) saturate(145%);
    backdrop-filter: blur(24px) saturate(145%);
  }

  .timeline-card {
    background:
      linear-gradient(180deg, rgba(20, 24, 48, 0.38), rgba(14, 18, 40, 0.28));
    border-color: rgba(255, 255, 255, 0.34);
    box-shadow:
      0 16px 42px rgba(3, 7, 18, 0.26),
      inset 0 1px rgba(255, 255, 255, 0.24);
    color: rgba(255, 255, 255, 0.98);
    padding: 12px 14px 8px;
    -webkit-backdrop-filter: blur(28px) saturate(150%);
    backdrop-filter: blur(28px) saturate(150%);
  }

  .timeline-summary,
  .timeline-marks,
  .timeline-hint,
  .ghost-button,
  .details-button {
    text-shadow: 0 1px 6px rgba(3, 7, 18, 0.68);
  }

  .details-button {
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.18), rgba(255, 255, 255, 0.10));
    border-color: rgba(255, 255, 255, 0.34);
    box-shadow:
      0 6px 18px rgba(3, 7, 18, 0.14),
      inset 0 1px rgba(255, 255, 255, 0.22);
    color: rgba(255, 255, 255, 0.98);
    min-height: 44px;
    -webkit-backdrop-filter: blur(10px) saturate(145%);
    backdrop-filter: blur(10px) saturate(145%);
  }

  .timeline-control {
    height: 56px;
    margin-top: 2px;
  }

  .timeline-marks i {
    margin-bottom: 9px;
  }

  .timeline-hint {
    line-height: 1.25;
  }
}

@media (max-width: 374px) {
  .map-page { padding-left: 12px; padding-right: 12px; }
  .quick-controls { grid-template-columns: minmax(0, 1fr) minmax(0, 1.32fr); }
  .soft-button,
  .date-control { font-size: 0.75rem; }
  .date-control input { font-size: 0.68rem; min-width: 0; }
  .scene-content { padding-left: 12px; padding-right: 12px; }
  .timeline-card { padding-left: 12px; padding-right: 12px; }
  .timeline-summary strong { font-size: 1.05rem; }
  .timeline-marks b { font-size: 0.55rem; }
  .ghost-button { padding-left: 10px; padding-right: 10px; }
  .details-panel { padding-left: 14px; padding-right: 14px; }
  .twilight-table .time-column { width: 52px; }
  .twilight-table .elapsed-column { width: 76px; }
  .twilight-table th,
  .twilight-table td { padding-left: 3px; padding-right: 3px; }
  .twilight-table tbody th { font-size: 0.68rem; }
  .event-time,
  .event-elapsed { font-size: 0.64rem; }
}

@media (max-width: 767px) and (max-height: 800px) {
  .topbar--map {
    min-height: calc(48px + var(--safe-top));
    padding-bottom: 2px;
    padding-top: calc(6px + var(--safe-top));
  }

  .map-page {
    padding-bottom: max(6px, var(--safe-bottom));
    padding-top: 0;
  }

  .map-intro { margin-bottom: 6px; margin-top: 0; }
  .map-shell { gap: 6px; }
  .location-controls { gap: 4px; }
  .map-canvas {
    height: clamp(190px, 27vh, 260px);
    height: clamp(190px, 27dvh, 260px);
    min-height: 190px;
  }
  .selected-location-card {
    min-height: 54px;
    padding-bottom: 6px;
    padding-top: 6px;
  }
  .primary-button { min-height: 46px; }
}

@media (max-width: 767px) and (max-height: 700px) {
  .topbar--map {
    min-height: calc(46px + var(--safe-top));
    padding-top: calc(4px + var(--safe-top));
  }

  .map-page { padding-bottom: max(4px, var(--safe-bottom)); }
  .map-intro { margin-bottom: 5px; }
  .kicker { font-size: 0.64rem; }
  .map-intro h1 {
    font-size: clamp(1.12rem, 5.4vw, 1.45rem);
    font-size: clamp(1.12rem, min(5.4vw, 3.5dvh), 1.45rem);
  }
  .map-shell { gap: 5px; }
  .inline-status {
    font-size: 0.62rem;
    line-height: 1.2;
    min-height: 2.4em;
  }
  .map-canvas {
    height: clamp(180px, 25vh, 210px);
    height: clamp(180px, 25dvh, 210px);
    min-height: 180px;
  }
  .selected-location-card {
    min-height: 50px;
    padding-bottom: 5px;
    padding-top: 5px;
  }
  .selected-location-card strong { font-size: 0.84rem; }
  .card-label,
  .coordinates { font-size: 0.64rem; }
  .primary-button { min-height: 44px; }
}

@media (min-width: 768px) and (max-height: 800px) {
  .topbar--map {
    min-height: calc(56px + var(--safe-top));
    padding-top: calc(6px + var(--safe-top));
  }
  .map-page { padding-bottom: max(8px, var(--safe-bottom)); padding-top: 0; }
  .map-intro { margin-bottom: 8px; margin-top: 0; }
  .map-shell { padding-bottom: 16px; padding-top: 16px; }
  .map-canvas {
    height: clamp(360px, calc(100vh - 190px), 510px);
    height: clamp(360px, calc(100dvh - 190px), 510px);
  }
}

@media (orientation: landscape) and (max-height: 600px) {
  .topbar { min-height: 50px; padding-bottom: 4px; padding-top: max(8px, var(--safe-top)); }
  .scene-content { padding-bottom: max(10px, var(--safe-bottom)); padding-top: 6px; }
  .scene-place h1 { font-size: 1.45rem; }
  .scene-date, .phase-label { margin-top: 1px; margin-bottom: 2px; }
  .time-focus { align-items: flex-start; left: 24px; margin: 0; position: absolute; top: 45%; }
  .time-focus strong { font-size: 3rem; }
  .experience-controls { margin-left: auto; margin-right: 0; max-width: 62vw; }
  .timeline-hint { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 1ms !important;
  }
}
