/* Final layout layer: a stowable teaching drawer on desktop and mobile. */
.site-header {
  position: relative;
  z-index: 100;
}

.app-shell {
  --mobile-drawer-height: 62px;
  --mobile-drawer-expanded-height: min(58vh, 560px);
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

.app-shell.panel-expanded {
  --mobile-drawer-height: var(--mobile-drawer-expanded-height);
}

.map-stage {
  position: absolute;
  z-index: 1;
  inset: 0;
  width: 100%;
  height: 100%;
}

.learning-panel {
  position: absolute;
  z-index: 50;
  top: auto;
  right: auto;
  bottom: calc(10px + env(safe-area-inset-bottom, 0));
  left: 50%;
  display: grid;
  width: min(1120px, calc(100% - 24px));
  height: var(--mobile-drawer-height);
  max-height: none;
  grid-template-rows: 60px 0 minmax(0, 0);
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 17px;
  background: #061721;
  box-shadow: 0 -12px 40px rgba(0, 8, 14, 0.45);
  transform: translateX(-50%);
  transition: height 190ms var(--ease-out);
}

.learning-panel.is-expanded {
  height: var(--mobile-drawer-expanded-height);
  grid-template-rows: 60px auto minmax(0, 1fr);
}

.learning-panel::before {
  display: none;
  content: none;
}

.panel-drawer-toggle {
  z-index: 5;
  display: grid;
  width: 100%;
  min-width: 0;
  min-height: 60px;
  align-items: center;
  grid-column: 1;
  grid-row: 1;
  grid-template-columns: minmax(0, 1fr) auto 20px;
  gap: 10px;
  padding: 8px 16px;
  border-bottom: 1px solid transparent;
  color: var(--text);
  background: linear-gradient(180deg, #0b2b39, #071d28);
  cursor: pointer;
  text-align: left;
}

.learning-panel.is-expanded .panel-drawer-toggle {
  border-bottom-color: var(--line);
}

.panel-drawer-toggle:hover,
.panel-drawer-toggle:focus-visible {
  background: linear-gradient(180deg, #103946, #092530);
}

.panel-drawer-copy {
  display: grid;
  min-width: 0;
  gap: 2px;
}

.panel-drawer-copy .eyebrow {
  margin: 0;
  font-size: 0.52rem;
}

.panel-drawer-copy strong {
  overflow: hidden;
  font-size: 0.88rem;
  line-height: 1.1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.panel-drawer-state {
  color: var(--cyan-300);
  font-size: 0.65rem;
  font-weight: 710;
  white-space: nowrap;
}

.panel-drawer-chevron {
  width: 10px;
  height: 10px;
  border-top: 2px solid var(--cyan-300);
  border-left: 2px solid var(--cyan-300);
  transform: translateY(3px) rotate(45deg);
  transition: transform 190ms var(--ease-out);
}

.learning-panel.is-expanded .panel-drawer-chevron {
  transform: translateY(-3px) rotate(225deg);
}

.panel-tabs {
  grid-column: 1;
  grid-row: 2;
  padding: 7px;
}

.panel-scroll {
  grid-column: 1;
  grid-row: 3;
}

.learning-panel:not(.is-expanded) .panel-tabs,
.learning-panel:not(.is-expanded) .panel-scroll {
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
}

.scale-control,
.map-legend,
.plot-button {
  bottom: calc(var(--mobile-drawer-height) + 22px + env(safe-area-inset-bottom, 0));
  transition: bottom 190ms var(--ease-out);
}

.scale-control {
  z-index: 20;
}

/* Keep point confirmation actionable when the prior location card is present. */
.map-prompt {
  z-index: 30;
}

.plot-button:not(:disabled) {
  border-color: rgba(149, 243, 247, 0.92);
  box-shadow:
    0 0 0 3px rgba(92, 232, 241, 0.16),
    0 12px 30px rgba(0, 7, 13, 0.42);
}

.plot-icon {
  display: none;
}

@media (max-width: 820px) {
  .app-shell {
    --mobile-drawer-expanded-height: min(72dvh, 660px);
  }

  .learning-panel {
    top: auto;
    right: 6px;
    bottom: calc(6px + env(safe-area-inset-bottom, 0));
    left: 6px;
    width: auto;
    transform: none;
  }

  .scale-control,
  .map-legend,
  .plot-button {
    bottom: calc(var(--mobile-drawer-height) + 18px + env(safe-area-inset-bottom, 0));
  }

  .lesson-chip,
  .header-actions .icon-button {
    width: 44px;
    min-width: 44px;
    min-height: 44px;
  }

  .map-prompt-dismiss {
    width: 44px;
    height: 44px;
  }

  .map-confirm-actions button {
    min-height: 44px;
  }
}

@media (max-width: 520px) {
  .trace-key-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .trace-key-wide {
    grid-column: auto;
  }

  .plot-button {
    min-width: 116px;
    justify-content: center;
    padding: 0 11px;
    font-size: 0.64rem;
  }
}

/* Desktop keeps the earlier map-left / teaching-rail-right composition.
   Only the rail width changes; Leaflet remains confined to the map column. */
@media (min-width: 821px) {
  .app-shell {
    --desktop-panel-width: clamp(540px, 41vw, 680px);
    display: grid;
    grid-template-columns: minmax(0, 1fr) 58px;
    grid-template-rows: minmax(0, 1fr);
    transition: grid-template-columns 220ms var(--ease-out);
  }

  .app-shell.panel-expanded {
    grid-template-columns: minmax(0, 1fr) var(--desktop-panel-width);
  }

  .map-stage {
    position: relative;
    inset: auto;
    grid-column: 1;
    grid-row: 1;
    min-width: 0;
    min-height: 0;
  }

  .learning-panel,
  .learning-panel.is-expanded {
    position: relative;
    inset: auto;
    grid-column: 2;
    grid-row: 1;
    width: auto;
    height: 100%;
    max-height: 100%;
    min-width: 0;
    min-height: 0;
    border-width: 0 0 0 1px;
    border-radius: 0;
    box-shadow: -14px 0 38px rgba(0, 8, 13, 0.2);
    transform: none;
    transition: none;
  }

  .learning-panel {
    grid-template-rows: minmax(0, 1fr);
  }

  .learning-panel.is-expanded {
    grid-template-rows: 48px auto minmax(0, 1fr);
  }

  .panel-drawer-toggle {
    display: grid;
    height: 48px;
    min-height: 48px;
    grid-column: 1;
    grid-row: 1;
    grid-template-columns: minmax(0, 1fr) auto 18px;
    gap: 10px;
    padding: 6px 12px;
    border-bottom: 1px solid var(--line);
    background: linear-gradient(180deg, #0b2b39, #071d28);
  }

  .learning-panel.is-expanded .panel-drawer-chevron {
    transform: rotate(135deg);
  }

  .learning-panel:not(.is-expanded) .panel-drawer-toggle {
    display: flex;
    width: 100%;
    height: 100%;
    min-height: 0;
    align-items: center;
    flex-direction: column;
    justify-content: flex-start;
    gap: 14px;
    padding: 18px 8px;
    border-bottom: 0;
  }

  .learning-panel:not(.is-expanded) .panel-drawer-copy {
    display: flex;
    min-height: 0;
    align-items: center;
    flex: 1 1 auto;
  }

  .learning-panel:not(.is-expanded) .panel-drawer-copy .eyebrow,
  .learning-panel:not(.is-expanded) .panel-drawer-state {
    display: none;
  }

  .learning-panel:not(.is-expanded) .panel-drawer-copy strong {
    overflow: visible;
    font-size: 0.75rem;
    letter-spacing: 0.04em;
    text-overflow: clip;
    writing-mode: vertical-rl;
    transform: rotate(180deg);
  }

  .learning-panel:not(.is-expanded) .panel-drawer-chevron {
    flex: 0 0 auto;
    transform: rotate(-45deg);
  }

  .panel-tabs {
    grid-column: 1;
    grid-row: 2;
  }

  .panel-scroll {
    grid-column: 1;
    grid-row: 3;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
  }

  .scale-control,
  .map-legend,
  .plot-button {
    bottom: 18px;
  }
}

@media (min-width: 821px) and (max-width: 1180px) {
  .app-shell {
    --desktop-panel-width: minmax(500px, 48vw);
  }
}

/* Plotted rings remain distinct without competing with the map. */
@keyframes plotted-ring-pulse {
  0%,
  100% {
    stroke-opacity: 0.68;
  }

  50% {
    stroke-opacity: 1;
  }
}

.map-ring {
  animation: plotted-ring-pulse 3.8s ease-in-out infinite;
}

.map-ring-surface {
  animation-delay: -1.25s;
}

.map-ring-bottom {
  animation-delay: -2.5s;
}

.map-legend .legend-body {
  flex-wrap: wrap;
}

.map-legend .legend-body span {
  min-width: 0;
  white-space: normal;
}

.map-legend .legend-body strong {
  color: var(--text);
  font-size: 0.61rem;
  font-style: normal;
}

.map-legend .legend-body em {
  color: var(--muted);
  font-size: 0.59rem;
  font-style: normal;
  font-variant-numeric: tabular-nums;
}

@media (min-width: 821px) {
  .map-legend {
    right: 174px;
    max-width: calc(100% - 332px);
  }

  .map-legend .legend-body {
    gap: 6px 13px;
  }
}

@media (max-width: 820px) {
  .map-legend {
    right: auto;
    bottom: calc(var(--mobile-drawer-height) + 70px + env(safe-area-inset-bottom, 0));
    left: 10px;
    display: block;
    width: min(360px, calc(100% - 20px));
    max-width: calc(100% - 20px);
  }

  .map-legend .legend-toggle {
    display: none;
  }

  .map-legend .legend-body,
  .map-legend.is-collapsed .legend-body {
    display: flex;
    min-height: 0;
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
    padding: 7px 9px;
  }

  .app-shell.panel-expanded .map-status,
  .app-shell.panel-expanded .plot-button {
    display: none;
  }

  .app-shell.panel-expanded .map-legend {
    right: 10px;
    bottom: calc(var(--mobile-drawer-height) + 8px + env(safe-area-inset-bottom, 0));
    left: auto;
    width: min(250px, calc(100% - 130px));
    max-width: calc(100% - 130px);
  }
}

@media (min-width: 821px) and (max-width: 1180px) {
  .app-shell.panel-expanded .map-prompt {
    top: 150px;
    right: 18px;
    left: 18px;
    width: auto;
    max-width: none;
    transform: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .map-ring {
    animation: none;
    stroke-opacity: 0.9;
  }
}
