/**
 * Two-scale navigation shell — Pre-Build 004.1
 * Native <dialog> + resting key control
 */

.pyramid-shell {
  position: relative;
  font-family: var(--lj-sans, system-ui, sans-serif);
  /* Focus ring meets ≥3:1 against light paper */
  --shell-focus: #1a1a1a;
  --shell-focus-ring: #8a7020;
}

/* —— RESTING —— */
.shell-open {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 44px;
  min-width: 44px;
  padding: 0.35rem 0.65rem 0.35rem 0.35rem;
  border: 1px solid var(--lj-border, #d4cfc6);
  background: var(--lj-paper, #faf8f4);
  color: var(--lj-ink, #1a1a1a);
  cursor: pointer;
  border-radius: 2px;
}

.shell-open:hover {
  border-color: var(--lj-ink, #1a1a1a);
}

.shell-open:focus-visible {
  outline: 3px solid var(--shell-focus-ring);
  outline-offset: 3px;
}

.shell-open-visual {
  width: 40px;
  height: 35px;
  flex-shrink: 0;
}

.shell-resting-svg {
  width: 100%;
  height: 100%;
  display: block;
}

.shell-rest-region polygon {
  fill: #e8e4da;
  stroke: var(--lj-ink, #1a1a1a);
  stroke-width: 1.5;
}

.shell-rest-region.is-active polygon {
  fill: var(--lj-lemon-soft, #e8d48a);
  stroke-width: 2;
}

.shell-rest-outline {
  stroke: var(--lj-ink, #1a1a1a);
  stroke-width: 1.25;
  opacity: 0.4;
}

.shell-open-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  line-height: 1.2;
}

.shell-open-side {
  font-family: var(--lj-serif, Georgia, serif);
  font-size: 1rem;
  font-weight: 700;
}

.shell-open-hint {
  font-family: var(--lj-mono, monospace);
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--lj-muted, #6b6560);
}

/* —— NATIVE DIALOG —— */
.shell-panel {
  padding: 0;
  border: 1px solid var(--lj-border, #d4cfc6);
  background: var(--lj-paper, #faf8f4);
  color: var(--lj-ink, #1a1a1a);
  max-width: min(920px, calc(100vw - 1.5rem));
  width: 100%;
  max-height: min(90vh, 90dvh);
  overflow: hidden;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.14);
}

.shell-panel::backdrop {
  background: rgba(20, 24, 28, 0.4);
}

.shell-panel-inner {
  padding: 1.25rem 1.25rem 1.5rem;
  max-height: min(90vh, 90dvh);
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.shell-panel-header {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.35rem 1rem;
  margin-bottom: 1.25rem;
  align-items: start;
}

.shell-panel-title {
  margin: 0;
  font-family: var(--lj-serif, Georgia, serif);
  font-size: 1.35rem;
  font-weight: 400;
  grid-column: 1;
}

.shell-panel-sub {
  margin: 0;
  font-size: 0.8125rem;
  color: var(--lj-muted, #6b6560);
  grid-column: 1;
}

.shell-close {
  grid-column: 2;
  grid-row: 1 / span 2;
  align-self: start;
  min-height: 44px;
  min-width: 44px;
  padding: 0.45rem 0.9rem;
  border: 1px solid var(--lj-ink, #1a1a1a);
  background: transparent;
  cursor: pointer;
  font-size: 0.875rem;
  color: inherit;
  font-family: inherit;
}

.shell-close:hover {
  background: var(--lj-ink, #1a1a1a);
  color: var(--lj-off-white, #f5f2eb);
}

.shell-close:focus-visible,
.shell-dest:focus-visible {
  outline: 3px solid var(--shell-focus-ring);
  outline-offset: 2px;
}

.shell-panel-body {
  display: grid;
  grid-template-columns: minmax(220px, 1.1fr) minmax(180px, 1fr);
  gap: 1.5rem;
  align-items: start;
}

/* Destinations first in DOM for mobile order; desktop: dest left, pyramid right */
.shell-destinations {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  order: 1;
}

.shell-pyramid-mount {
  width: 100%;
  max-width: 300px;
  max-height: min(42vh, 320px);
  margin: 0 auto;
  order: 2;
  overflow: hidden;
}

.shell-pyramid-mount .pyramid-status {
  font-size: 0.7rem;
}

.shell-pyramid-mount .pyramid-visual {
  max-height: min(36vh, 280px);
}

.shell-dest {
  display: flex;
  gap: 0.75rem;
  text-align: left;
  width: 100%;
  min-height: 52px;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--lj-border, #d4cfc6);
  background: transparent;
  cursor: pointer;
  color: inherit;
  font-family: inherit;
}

.shell-dest:hover {
  border-color: var(--lj-ink, #1a1a1a);
}

.shell-dest.is-current,
.shell-dest[aria-current="true"] {
  border-color: var(--lj-ink, #1a1a1a);
  background: rgba(0, 0, 0, 0.04);
}

.shell-dest-letter {
  font-family: var(--lj-serif, Georgia, serif);
  font-size: 1.35rem;
  font-weight: 700;
  line-height: 1;
  min-width: 1.5rem;
}

.shell-dest-name {
  display: block;
  font-size: 0.9375rem;
  font-weight: 600;
  margin-bottom: 0.15rem;
}

.shell-dest-desc {
  display: block;
  font-size: 0.75rem;
  color: var(--lj-muted, #6b6560);
  line-height: 1.4;
}

@media (prefers-reduced-motion: reduce) {
  .shell-panel,
  .shell-panel::backdrop {
    transition: none !important;
  }
}

/* —— Mobile: destinations before graphic, safe areas, 100dvh —— */
@media (max-width: 640px) {
  .shell-panel {
    max-width: 100%;
    width: 100%;
    max-height: 100%;
    height: 100%;
    height: 100dvh;
    margin: 0;
    border: none;
    border-radius: 0;
  }

  .shell-panel-inner {
    padding:
      max(1rem, env(safe-area-inset-top, 0px))
      max(0.85rem, env(safe-area-inset-right, 0px))
      max(1.25rem, env(safe-area-inset-bottom, 0px))
      max(0.85rem, env(safe-area-inset-left, 0px));
    max-height: 100dvh;
  }

  .shell-panel-body {
    grid-template-columns: 1fr;
  }

  .shell-destinations {
    order: 1;
  }

  .shell-pyramid-mount {
    order: 2;
    max-width: 220px;
    max-height: 28vh;
  }

  .shell-open-hint {
    display: none;
  }

  .shell-dest-name {
    font-size: 0.875rem;
  }
}

@media (max-width: 390px) and (orientation: landscape) {
  .shell-panel-body {
    grid-template-columns: 1.2fr 0.8fr;
  }

  .shell-destinations {
    order: 1;
  }

  .shell-pyramid-mount {
    order: 2;
    max-height: 50vh;
    max-width: 160px;
  }

  .shell-panel-inner {
    max-height: 100dvh;
  }
}

@media (max-width: 360px) {
  .shell-dest {
    min-height: 48px;
  }
}
