:root {
  color-scheme: dark;
  --ink: #eef3f3;
  --muted: #aebec3;
  --ocean: #071522;
  --panel: rgb(7 17 29 / 88%);
  --line: rgb(220 180 91 / 48%);
  --gold: #dfb85f;
  --orange: #ef9a4a;
  --focus: #f6d98d;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: #030914;
  color: var(--ink);
  font-family: ui-serif, "Hiragino Mincho ProN", "Yu Mincho", serif;
}

body {
  min-height: 100vh;
  overflow: auto;
}

button, input { font: inherit; }

button {
  min-width: 44px;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgb(6 19 31 / 84%);
  color: var(--ink);
  cursor: pointer;
}

button:hover { background: rgb(20 42 55 / 92%); }
button:focus-visible, input:focus-visible, canvas:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.atlas-shell {
  min-height: 100vh;
}

.topbar {
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #081421 0%, #07111d 100%);
}

.topbar h1, .observation-card h2, .scene-caption h2 {
  margin: 2px 0 0;
  font-weight: 500;
}

.topbar h1 { font-size: clamp(1.3rem, 2.8vw, 2rem); }

.eyebrow {
  margin: 0;
  color: var(--gold);
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .12em;
}

.topbar-status {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: .82rem;
}

.status-badge {
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--gold);
}

.atlas-stage {
  position: relative;
  height: clamp(520px, 72vh, 780px);
  overflow: hidden;
  background: var(--ocean);
}

#atlas-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: none;
}

#atlas-canvas.is-dragging { cursor: grabbing; }

.map-actions, .layer-actions {
  position: absolute;
  z-index: 2;
  display: flex;
  gap: 8px;
}

.map-actions {
  top: 14px;
  right: 14px;
}
.map-actions button[hidden] { display: none; }

.harbor-primary {
  position: absolute;
  z-index: 3;
  left: 50%;
  bottom: 18px;
  min-width: 170px;
  padding: 11px 20px;
  transform: translateX(-50%);
  border-color: #f0cb75;
  color: #171207;
  background: linear-gradient(180deg, #f6d98d, #d9ad4f);
  box-shadow: 0 10px 32px rgb(0 0 0 / 42%);
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-weight: 700;
}
.harbor-primary:hover { background: #f6d98d; }

.journey-nav {
  position: absolute;
  z-index: 4;
  right: 14px;
  bottom: 14px;
  width: min(238px, calc(100% - 28px));
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgb(3 12 22 / 88%);
  box-shadow: 0 14px 40px rgb(0 0 0 / 46%);
  backdrop-filter: blur(14px);
  font-family: ui-sans-serif, system-ui, sans-serif;
}
.journey-nav[hidden] { display: none; }
.journey-world {
  position: relative;
  display: block;
  width: 100%;
  height: 104px;
  overflow: hidden;
  padding: 0;
  border-radius: 10px;
}
.journey-world img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: .72;
  filter: saturate(.86) brightness(.72);
}
.journey-world::after {
  position: absolute;
  inset: 0;
  content: "";
  background: linear-gradient(180deg, transparent 30%, rgb(2 9 17 / 82%));
}
.journey-world-label {
  position: absolute;
  z-index: 2;
  right: 10px;
  bottom: 8px;
  left: 10px;
  color: #fff7dd;
  font-size: .82rem;
  font-weight: 700;
  text-align: left;
}
.journey-pin {
  position: absolute;
  z-index: 3;
  width: 14px;
  height: 14px;
  transform: translate(-50%, -50%);
  border: 3px solid #fff4ce;
  border-radius: 50%;
  background: #df9f45;
  box-shadow: 0 0 0 5px rgb(223 184 95 / 24%), 0 0 16px #f6d98d;
}
.journey-controls {
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  gap: 6px;
  margin-top: 7px;
}
.journey-controls span {
  overflow: hidden;
  color: var(--muted);
  font-size: .72rem;
  line-height: 1.35;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.layer-actions {
  left: 14px;
  bottom: 74px;
  flex-wrap: wrap;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: .78rem;
  backdrop-filter: blur(10px);
}
.layer-actions[hidden], .poi-directory[hidden] { display: none; }

.layer-actions label {
  display: flex;
  align-items: center;
  gap: 5px;
  min-height: 30px;
}

.layer-note {
  align-self: center;
  color: var(--muted);
  letter-spacing: .02em;
}
.nation-map-chip {
  position: absolute;
  width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap;
}

.observation-card {
  position: absolute;
  z-index: 4;
  top: 74px;
  right: 14px;
  width: min(360px, calc(100% - 28px));
  max-height: calc(100% - 150px);
  overflow: auto;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: 0 16px 45px rgb(0 0 0 / 36%);
  backdrop-filter: blur(16px);
}
.nation-card {
  position: absolute;
  z-index: 5;
  inset: 0;
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(280px, .7fr);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 0;
  background: rgb(3 9 20 / 96%);
  box-shadow: 0 20px 60px rgb(0 0 0 / 65%);
  transform-origin: var(--portal-x, 50%) var(--portal-y, 50%);
}
.nation-card.is-closing { animation: portal-contract .46s cubic-bezier(.55,0,.8,.35) both; }
@keyframes portal-contract {
  from { clip-path: circle(150vmax at var(--portal-x, 50%) var(--portal-y, 50%)); opacity: 1; }
  to { clip-path: circle(0 at var(--portal-x, 50%) var(--portal-y, 50%)); opacity: .5; }
}
.portal-window-transition {
  position: fixed;
  z-index: 20;
  overflow: hidden;
  pointer-events: none;
  -webkit-mask-image: radial-gradient(ellipse at center, #000 56%, rgb(0 0 0 / 92%) 72%, transparent 100%);
  mask-image: radial-gradient(ellipse at center, #000 56%, rgb(0 0 0 / 92%) 72%, transparent 100%);
}
.portal-window-transition > .portal-art-transition {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: fill;
  object-position: top;
  pointer-events: none;
  filter: saturate(1.04) contrast(1.02);
}
.portal-scene-caption {
  position: fixed;
  z-index: 21;
  pointer-events: none;
  color: #fff8e5;
  text-align: center;
  text-shadow: 0 2px 12px rgb(0 0 0 / 90%);
  opacity: 0;
}
.portal-scene-caption strong, .portal-scene-caption span { display: block; }
.portal-scene-caption strong { font-size: 1.25rem; }
.portal-scene-caption span { margin-top: 3px; font: 500 .9rem ui-sans-serif, system-ui; }
.portal-dim {
  position: absolute;
  z-index: 6;
  inset: 0;
  pointer-events: none;
  background: rgb(1 7 14 / 26%);
}
.nation-card.is-landing .nation-copy { opacity: 0; }
.nation-card .nation-copy { transition: opacity .14s ease; }
.nation-card[hidden] { display: none; }
.nation-card > img { width: 100%; height: 100%; min-height: 0; object-fit: contain; background: #050b15; }
.nation-copy { overflow: auto; padding: 26px 20px 20px; }
.nation-copy h2 { margin: 4px 0 10px; font-size: clamp(1.5rem, 3vw, 2.3rem); }
.nation-copy p { color: var(--muted); line-height: 1.65; }
.nation-copy h3 { margin: 20px 0 8px; font-size: 1rem; }
.nation-pager, .nation-neighbors { display: flex; flex-wrap: wrap; gap: 8px; }
.nation-pager button { flex: 1; }
.nation-neighbors button { padding: 8px 10px; }
.nation-card .close-card { position: fixed; z-index: 8; top: 10px; right: 10px; }

.observation-card p { color: var(--muted); line-height: 1.65; }
.observation-card dl {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 7px 12px;
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: .82rem;
}
.observation-card dt { color: var(--gold); }
.observation-card dd { margin: 0; color: var(--muted); }
.close-card, .close-scene {
  position: absolute;
  top: 8px;
  right: 8px;
}
.primary-action {
  width: 100%;
  border-color: var(--gold);
  color: #171207;
  background: var(--gold);
}
.primary-action:hover { background: #f0cb75; }

#scene-dialog {
  width: min(1180px, 94vw);
  max-height: 92vh;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 16px;
  color: var(--ink);
  background: #07111d;
}

#scene-dialog::backdrop {
  background: rgb(0 5 12 / 82%);
  backdrop-filter: blur(8px);
}

#scene-dialog img {
  display: block;
  width: 100%;
  max-height: 70vh;
  object-fit: contain;
  background: #020711;
}

.scene-caption { padding: 16px 20px 20px; }
.scene-caption p:last-child { color: var(--muted); }

.controls-help {
  margin: 0;
  padding: 8px 16px;
  color: var(--muted);
  background: #07111d;
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: .76rem;
  text-align: center;
}
.prototype-notice {
  margin: 0;
  padding: 8px 16px;
  border-top: 1px solid var(--line);
  color: var(--gold);
  background: #07111d;
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: .8rem;
  text-align: center;
}

.poi-directory {
  display: grid;
  grid-template-columns: minmax(220px, .55fr) minmax(0, 1.45fr);
  gap: 18px;
  padding: 16px 20px 22px;
  border-top: 1px solid var(--line);
  background: #07111d;
  font-family: ui-sans-serif, system-ui, sans-serif;
}
.poi-directory h2 { margin: 0 0 6px; font-size: 1.05rem; }
.poi-directory p { margin: 0; color: var(--muted); line-height: 1.6; }
.poi-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 0;
  padding-left: 1.6rem;
}
.poi-list li { padding-left: 2px; }
.poi-select {
  width: 100%;
  min-height: 52px;
  padding: 7px 9px;
  text-align: left;
}
.poi-select span { display: block; }
.poi-select small { display: block; margin-top: 3px; color: var(--muted); }

.nation-directory { padding: 26px 20px 40px; border-top: 1px solid var(--line); background: #050d18; }
.nation-directory p { color: var(--muted); line-height: 1.6; }
.nation-groups { display: grid; gap: 18px; }
.nation-group h3 { color: var(--gold); }
.nation-buttons { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; }
.nation-select { min-height: 52px; padding: 8px; text-align: left; }
.nation-select small { display: block; color: var(--muted); }

@media (max-width: 680px) {
  body { overflow: auto; }
  .atlas-shell { min-height: 100svh; }
  .topbar { align-items: flex-start; padding: 10px 12px; }
  .status-badge { display: none; }
  .map-actions { top: 8px; right: 8px; left: 8px; flex-wrap: wrap; justify-content: flex-end; }
  .map-actions button { padding-inline: 8px; }
  .layer-actions { left: 8px; right: 8px; bottom: 68px; justify-content: center; }
  .journey-nav { right: 8px; bottom: 8px; width: 190px; }
  .journey-world { height: 82px; }
  .observation-card { top: auto; right: 8px; bottom: 58px; width: calc(100% - 16px); max-height: 48%; }
  .controls-help { text-align: left; }
  .atlas-stage { min-height: 70svh; }
  .poi-directory { grid-template-columns: 1fr; padding: 14px 12px 18px; }
  .poi-list { grid-template-columns: 1fr; }
  .nation-card { grid-template-columns: 1fr; overflow: auto; }
  .nation-card > img { height: 172px; min-height: 172px; object-fit: cover; }
  .nation-copy { overflow: visible; padding-top: 12px; }
  .nation-copy #nation-title {
    position: sticky;
    z-index: 6;
    top: 0;
    margin-inline: -20px;
    padding: 10px 56px 10px 20px;
    background: rgb(3 9 20 / 97%);
    border-bottom: 1px solid var(--line);
  }
  .nation-directory { padding-inline: 12px; }
  .nation-buttons { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (min-width: 681px) and (max-width: 960px) {
  .poi-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: .001ms !important;
    transition-duration: .001ms !important;
  }
  .nation-card.is-closing { animation: none; }
  .nation-card .nation-copy { transition: none; }
}

@media (forced-colors: active) {
  button, .layer-actions, .observation-card, .status-badge {
    border: 1px solid ButtonText;
  }
  button:focus-visible, input:focus-visible, canvas:focus-visible {
    outline-color: Highlight;
  }
}
