/* MemeGraph · Atlas · the whole sealed file as a star chart.
   Ink-night ground, halo gold for receipts, brass for our reads.
   Loads after site.css and reuses its tokens, nav, buttons, chips. */

@import url("tokens.css");

body.atlas-page {
  background: var(--ink);
  color: var(--paper);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}
.atlas-page .site-header .wrap { padding: 0.4rem 0; }

/* --- main frame --- */
.atlas {
  flex: 1 0 auto;
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 3.6rem);
  min-height: calc(100dvh - 3.6rem);
  min-width: 0;
  outline: none;
}
.atlas-head {
  display: grid;
  gap: 0.75rem 1.5rem;
  grid-template-columns: minmax(0, 1fr);
  align-items: end;
  padding: 0.9rem var(--gutter) 0.8rem;
  border-bottom: 1px solid var(--ink-line);
  min-width: 0;
}
@media (min-width: 1000px) {
  .atlas-head { grid-template-columns: minmax(0, 1fr) minmax(0, 27rem) minmax(15rem, 20rem); }
}
.atlas-title-block { min-width: 0; }
.atlas-title-block .beat-tag { margin-bottom: 0.15rem; }
.atlas-head h1 {
  font-size: clamp(1.7rem, 3.4vw, 2.6rem);
  line-height: 1.02;
  letter-spacing: -0.03em;
  color: var(--paper);
}
.atlas-counts {
  margin: 0.35rem 0 0;
  color: var(--muted-dark);
  font-size: 0.82rem;
  overflow-wrap: anywhere;
}
.atlas-counts .on-chain { color: var(--halo); }

/* Truth Harness two-stop control (same grammar as the main page dial) */
.atlas-harness { display: grid; gap: 0.35rem; min-width: 0; }
.atlas-harness-label {
  margin: 0; color: var(--brass); font-size: 0.72rem; font-weight: 600;
  letter-spacing: 0.14em; text-transform: uppercase;
}
.atlas-seg {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 0.4rem;
}
.atlas-seg button {
  min-width: 0; min-height: 2.5rem; cursor: pointer;
  border: 1px solid var(--ink-line); background: var(--ink-raised); color: var(--muted-dark);
  border-radius: var(--radius-sm); padding: 0.45rem 0.75rem;
  font-weight: 600; font-size: 0.86rem; line-height: 1.2; white-space: normal;
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease);
}
.atlas-seg button:hover { border-color: var(--brass); color: var(--paper); }
.atlas-seg button[aria-checked="true"] {
  background: var(--paper); color: var(--ink); border-color: var(--paper);
  box-shadow: inset 0 -3px 0 var(--brass);
}
.atlas-harness[data-tau="0"] .atlas-seg button[aria-checked="true"] { box-shadow: inset 0 -3px 0 var(--halo); }
.atlas-seg button:disabled { opacity: 0.45; cursor: not-allowed; }
.atlas-counter { margin: 0; font-size: 0.8rem; color: var(--paper); min-height: 2.7em; }
.atlas-counter .sub { display: block; color: var(--muted-dark); }

/* search */
.atlas-search { position: relative; display: grid; gap: 0.3rem; min-width: 0; }
.atlas-search-label {
  color: var(--brass); font-size: 0.72rem; font-weight: 600;
  letter-spacing: 0.14em; text-transform: uppercase;
}
.atlas-search input {
  width: 100%; min-width: 0; min-height: var(--tap);
  font: inherit; font-size: 0.95rem; color: var(--paper);
  background: var(--ink-raised); border: 1px solid var(--ink-line);
  border-radius: 999px; padding: 0.5rem 1rem;
}
.atlas-search input::placeholder { color: var(--muted-dark); opacity: 0.8; }
.atlas-search input:focus-visible { outline: 3px solid var(--halo); outline-offset: 2px; }
.atlas-search input:disabled { opacity: 0.5; }
.atlas-results {
  position: absolute; z-index: 45; top: calc(100% + 0.35rem); left: 0; right: 0;
  margin: 0; padding: 0.3rem; list-style: none;
  background: var(--ink-raised); border: 1px solid var(--ink-line); border-radius: var(--radius-sm);
  box-shadow: 0 18px 40px #000000aa;
  max-height: min(22rem, 60vh); overflow-y: auto;
}
.atlas-results button {
  width: 100%; min-height: var(--tap); text-align: left; cursor: pointer;
  display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 0.6rem; align-items: center;
  background: transparent; border: 0; border-radius: 0.35rem; color: var(--paper);
  padding: 0.4rem 0.55rem; font-size: 0.9rem;
}
.atlas-results button:hover, .atlas-results button:focus-visible { background: #ffffff10; }
.atlas-results .r-main { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.atlas-results .r-sub { display: block; color: var(--muted-dark); font-family: var(--mono); font-size: 0.74rem; overflow: hidden; text-overflow: ellipsis; }
.atlas-results .r-none { color: var(--muted-dark); padding: 0.6rem; font-size: 0.9rem; }

/* --- stage --- */
.atlas-body {
  position: relative;
  flex: 1 1 auto;
  display: flex;
  min-height: 24rem;
  min-width: 0;
}
.atlas-stage {
  position: relative; flex: 1 1 auto; min-width: 0; overflow: hidden;
  background:
    radial-gradient(1100px 700px at 60% 40%, #1a2a3166, transparent 65%),
    radial-gradient(800px 600px at 15% 85%, #e0782810, transparent 60%),
    var(--ink);
}
.atlas-canvas-wrap {
  position: absolute; inset: 0;
  touch-action: none; cursor: grab;
  outline: none;
}
.atlas-canvas-wrap.is-dragging { cursor: grabbing; }
.atlas-canvas-wrap.is-over-node { cursor: pointer; }
.atlas-canvas-wrap:focus-visible { box-shadow: inset 0 0 0 3px var(--halo); }
.atlas-canvas-wrap canvas { display: block; width: 100%; height: 100%; }
.atlas-reticle {
  position: absolute; left: 50%; top: 50%; width: 1.6rem; height: 1.6rem;
  margin: -0.8rem 0 0 -0.8rem; border-radius: 50%;
  border: 1px dashed var(--halo); opacity: 0; pointer-events: none;
}
.atlas-canvas-wrap:focus-visible .atlas-reticle { opacity: 0.7; }

.atlas-empty {
  position: absolute; inset: 0; display: grid; place-items: center;
  padding: 2rem; text-align: center; color: var(--muted-dark); pointer-events: none;
}
.atlas-empty.is-fail { pointer-events: auto; }
.atlas-empty-inner { display: grid; gap: 0.9rem; justify-items: center; max-width: 30rem; }
.atlas-empty p { margin: 0; font-size: 1rem; }
.atlas-empty.is-fail p { color: var(--paper); font-family: var(--serif); font-size: clamp(1.2rem, 2.6vw, 1.6rem); line-height: 1.25; }
.atlas-empty.is-fail .atlas-spinner { display: none; }
.atlas-spinner {
  width: 2rem; height: 2rem; border-radius: 50%;
  border: 2px solid var(--ink-line); border-top-color: var(--brass);
  animation: atlas-spin 1s linear infinite;
}
@keyframes atlas-spin { to { transform: rotate(360deg); } }

/* controls */
.atlas-tools {
  position: absolute; top: 0.75rem; left: 0.75rem; z-index: 5;
  display: flex; flex-wrap: wrap; gap: 0.35rem; max-width: calc(100% - 1.5rem);
}
.atlas-tool {
  min-width: 2.5rem; min-height: 2.5rem; padding: 0.3rem 0.6rem; cursor: pointer;
  border: 1px solid var(--ink-line); border-radius: 999px;
  background: color-mix(in srgb, var(--ink-raised) 88%, transparent); color: var(--paper);
  font-size: 1.05rem; font-weight: 600; line-height: 1;
  backdrop-filter: blur(6px);
}
.atlas-tool-wide { font-size: 0.82rem; padding-inline: 0.85rem; }
.atlas-tool:hover { border-color: var(--brass); }
.atlas-tool[aria-pressed="true"] { border-color: var(--brass); color: var(--halo); }
.atlas-tool:disabled { opacity: 0.4; cursor: not-allowed; }

.atlas-hint {
  position: absolute; bottom: 0.8rem; right: 0.9rem; z-index: 4; margin: 0;
  font-size: 0.78rem; color: var(--muted-dark); pointer-events: none;
  background: color-mix(in srgb, var(--ink) 70%, transparent); padding: 0.2rem 0.55rem; border-radius: 999px;
}
.atlas-body.has-panel .atlas-hint { display: none; }

/* legend */
.atlas-legend {
  position: absolute; left: 0.75rem; bottom: 0.75rem; z-index: 6;
  max-width: min(26rem, calc(100% - 1.5rem));
  background: color-mix(in srgb, var(--ink-raised) 94%, transparent);
  border: 1px solid var(--ink-line); border-radius: var(--radius);
  backdrop-filter: blur(8px);
  font-size: 0.88rem;
}
.atlas-legend > summary {
  cursor: pointer; list-style: none; min-height: 2.6rem;
  display: flex; align-items: center; gap: 0.5rem; padding: 0.2rem 0.9rem;
  font-weight: 600; color: var(--paper);
}
.atlas-legend > summary::-webkit-details-marker { display: none; }
.atlas-legend > summary::before {
  content: "+"; display: inline-grid; place-items: center; width: 1.3rem; height: 1.3rem;
  border: 1px solid var(--ink-line); border-radius: 50%; color: var(--brass); font-size: 0.85rem;
}
.atlas-legend[open] > summary::before { content: "\2212"; }
.atlas-legend-body {
  padding: 0 0.95rem 0.9rem; max-height: min(26rem, 55vh); overflow-y: auto;
  color: #d9d2bd;
}
.atlas-legend-body p { margin: 0.5rem 0 0; }
.legend-h {
  font-family: var(--sans); font-size: 0.72rem; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--brass); margin: 0.9rem 0 0;
}
.legend-muted { color: var(--muted-dark); }
ul.legend-muted { margin: 0.35rem 0 0; padding-left: 1.1rem; }
.legend-keys { list-style: none; margin: 0.6rem 0 0; padding: 0; display: grid; gap: 0.4rem; }
.legend-keys li { display: grid; grid-template-columns: 1.4rem minmax(0, 1fr); gap: 0.5rem; align-items: start; }
.legend-keys strong { color: var(--paper); font-weight: 600; }
.sw { display: block; width: 0.7rem; height: 0.7rem; border-radius: 50%; margin: 0.3rem auto 0; }
.sw-observed { background: var(--halo); box-shadow: 0 0 0 3px #ffd45a33, 0 0 8px #ffd45a88; }
.sw-inferred { background: var(--brass); }
.sw-claimed { background: var(--claimed); }
.sw-unknown { background: var(--unknown); }
.sw-token { background: var(--paper); }
.sw-addr { background: transparent; border: 1.5px solid var(--paper); }
.sw-line-observed, .sw-line-read { width: 1.2rem; height: 0; border-radius: 0; margin-top: 0.65rem; }
.sw-line-observed { border-top: 1.5px solid var(--halo); }
.sw-line-read { border-top: 1px solid var(--brass); opacity: 0.6; }

/* --- side panel (drawer on wide, bottom sheet on phones) --- */
.atlas-panel {
  position: absolute; z-index: 20; top: 0.75rem; right: 0.75rem; bottom: 0.75rem;
  width: min(25rem, 42%);
  overflow-y: auto; overscroll-behavior: contain;
  background: var(--ink-raised); border: 1px solid var(--ink-line); border-radius: var(--radius);
  box-shadow: 0 24px 60px #000000aa;
  padding: 1rem 1.1rem 1.25rem;
  color: var(--paper);
  animation: ap-in var(--t-scene) var(--ease);
}
@keyframes ap-in { from { opacity: 0; transform: translateX(1rem); } }
.ap-head { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; }
.ap-kind { font-size: 0.78rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted-dark); }
.ap-close {
  min-height: 2.5rem; padding: 0.3rem 0.85rem; cursor: pointer; border-radius: 999px;
  border: 1px solid var(--ink-line); background: transparent; color: var(--paper); font-size: 0.85rem; font-weight: 600;
}
.ap-close:hover { border-color: var(--brass); }
.ap-title {
  margin: 0.55rem 0 0.5rem; font-size: 1.45rem; line-height: 1.1; color: var(--paper);
  overflow-wrap: anywhere; outline: none;
}
.ap-badge-row { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; margin: 0; }
.ap-id { margin: 0.6rem 0 0; color: var(--muted-dark); font-size: 0.76rem; overflow-wrap: anywhere; }
.ap-report-row { margin: 0.45rem 0 0; }
.ap-report {
  display: inline-block; min-height: 2.2rem; padding: 0.3rem 0.8rem;
  border: 1px solid var(--ink-line); border-radius: 999px;
  color: var(--paper); font-size: 0.82rem; font-weight: 600; text-decoration: none;
}
.ap-report:hover { border-color: var(--brass); color: var(--halo); }

.badge {
  display: inline-flex; align-items: center; gap: 0.4rem;
  font-size: 0.74rem; font-weight: 700; letter-spacing: 0.08em;
  padding: 0.24rem 0.65rem 0.24rem 0.55rem; border-radius: 999px; border: 1px solid currentColor;
  white-space: nowrap; line-height: 1.2;
}
.badge-small { font-size: 0.66rem; padding: 0.12rem 0.45rem; gap: 0.3rem; }
.badge .glyph { font-size: 1em; letter-spacing: 0; }
.b-observed { color: var(--halo); background: #ffd45a14; }
.b-inferred { color: var(--brass); background: #d0a55914; border-style: dashed; }
.b-claimed { color: var(--claimed); background: #d9993b14; }
.b-unknown { color: var(--muted-dark); border-style: dotted; background: repeating-linear-gradient(135deg, #7c8a8622 0 4px, transparent 4px 8px); }
.b-synthetic { color: #c7b4ee; background: #8a6bb81a; }
.ap-badge-line { flex-basis: 100%; margin: 0.35rem 0 0; color: #d9d2bd; font-size: 0.9rem; }

.ap-sec { margin-top: 1rem; padding-top: 0.8rem; border-top: 1px dashed var(--ink-line); font-size: 0.93rem; }
.ap-sec h3 {
  font-family: var(--sans); font-size: 0.72rem; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--brass); margin: 0 0 0.4rem; font-weight: 600;
}
.ap-sec p { margin: 0; color: #e6ddc6; }
.ap-sec ul { margin: 0; padding-left: 1.1rem; color: #e6ddc6; }
.ap-sec li + li { margin-top: 0.25rem; }
.ap-sec .muted { color: var(--muted-dark); }
.ap-links { list-style: none; padding: 0 !important; display: grid; gap: 0.35rem; }
.ap-links li + li { margin-top: 0; }
.ap-links button {
  width: 100%; min-height: var(--tap); text-align: left; cursor: pointer;
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 0.2rem 0.6rem; align-items: center;
  background: var(--ink); border: 1px solid var(--ink-line); border-radius: var(--radius-sm);
  color: var(--paper); padding: 0.45rem 0.65rem; font-size: 0.88rem;
}
.ap-links button:hover { border-color: var(--brass); }
.ap-links button.is-dim { opacity: 0.6; }
.ap-links .l-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.ap-links .l-why { grid-column: 1 / -1; color: var(--muted-dark); font-size: 0.8rem; }
.ap-more { color: var(--muted-dark); font-size: 0.85rem; padding-left: 0.2rem; }
.ap-src { display: grid; gap: 0.35rem; }
.ap-src-card { border: 1px solid var(--ink-line); border-radius: var(--radius-sm); padding: 0.45rem 0.65rem; background: var(--ink); }
.ap-src-card code { color: var(--muted-dark); overflow-wrap: anywhere; font-size: 0.78rem; }
.ap-src-card strong { color: var(--paper); font-weight: 600; }
.ap-note { margin-top: 0.4rem !important; color: var(--muted-dark) !important; font-size: 0.82rem; }
.ap-error { border: 1px dashed var(--failure); border-radius: var(--radius-sm); padding: 0.7rem 0.8rem; color: var(--paper); }

/* skeleton while a detail shard loads */
.sk { display: grid; gap: 0.55rem; margin-top: 1rem; }
.sk span {
  display: block; height: 0.8rem; border-radius: 999px;
  background: linear-gradient(90deg, #ffffff0a 0%, #ffffff1c 40%, #ffffff0a 80%);
  background-size: 200% 100%;
  animation: sk-shimmer 1.2s linear infinite;
}
.sk span:nth-child(1) { width: 60%; }
.sk span:nth-child(2) { width: 92%; }
.sk span:nth-child(3) { width: 78%; }
.sk span:nth-child(4) { width: 85%; height: 2.4rem; border-radius: var(--radius-sm); }
.sk span:nth-child(5) { width: 85%; height: 2.4rem; border-radius: var(--radius-sm); }
@keyframes sk-shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }

@media (prefers-reduced-motion: reduce) {
  .atlas-spinner, .sk span, .atlas-panel { animation: none !important; }
}

/* footer */
.atlas-footer { padding: 1.5rem 0 2rem; }
.atlas-footer code { font-size: 0.82em; overflow-wrap: anywhere; }
.atlas-nojs { margin: 1rem var(--gutter); }

/* --- phones --- */
@media (max-width: 640px) {
  .atlas { min-height: auto; }
  /* Compact head: a phone shows the map on the first screen, not after it. */
  .atlas-head { padding-top: 0.6rem; padding-bottom: 0.6rem; gap: 0.5rem 1rem; }
  .atlas-head h1 { font-size: 1.5rem; }
  .atlas-title-block .beat-tag { display: none; }
  .atlas-counts { font-size: 0.76rem; margin-top: 0.2rem; }
  .atlas-harness { gap: 0.25rem; }
  .atlas-seg button { min-height: 2.2rem; font-size: 0.8rem; padding: 0.35rem 0.5rem; }
  .atlas-counter { font-size: 0.76rem; min-height: 0; }
  .atlas-search input { min-height: 2.5rem; font-size: 0.88rem; padding-block: 0.35rem; }
  .atlas-body { min-height: 0; height: 64vh; height: 64dvh; flex: 0 0 auto; }
  .atlas-hint { display: none; }
  .atlas-tools { top: 0.5rem; left: 0.5rem; }
  .atlas-legend { left: 0.5rem; bottom: 0.5rem; max-width: calc(100% - 1rem); }
  .atlas-legend-body { max-height: 45vh; }
  .atlas-panel {
    position: fixed; top: auto; left: 0; right: 0; bottom: 0; z-index: 60;
    width: auto; max-height: 64vh; max-height: 64dvh;
    border-radius: 1.1rem 1.1rem 0 0; border-bottom: 0;
    padding-bottom: calc(1.25rem + env(safe-area-inset-bottom, 0px));
    animation-name: ap-up;
  }
  .atlas-panel::before {
    content: ""; display: block; width: 2.5rem; height: 0.25rem; border-radius: 999px;
    background: var(--ink-line); margin: -0.35rem auto 0.6rem;
  }
}
@keyframes ap-up { from { opacity: 0; transform: translateY(2rem); } }

/* observatory band — borrowed Provenance Observatory language */
.obv-band { position: relative; height: 300px; margin: 0 0 1rem; overflow: hidden;
  border: 1px solid var(--ink-line, #1d262e); border-radius: 8px;
  background: radial-gradient(circle at 50% 60%, #0e1820, var(--ink, #0b1114) 72%); }
#obv-canvas, #obv-stage { position: absolute; inset: 0; width: 100%; height: 100%; }
#obv-stage canvas { width: 100% !important; height: 100% !important; display: block; }
.obv-caption { position: absolute; left: 18px; bottom: 14px; z-index: 1; max-width: 340px; }
.obv-tag { color: var(--seal-amber, #e8b45f); font-size: 0.68rem; letter-spacing: 0.14em;
  text-transform: uppercase; margin: 0 0 0.25rem; }
.obv-line { color: var(--paper-dim, #b9c2c7); font-size: 0.78rem; line-height: 1.45; margin: 0; }
@media (max-width: 640px) { .obv-band { height: 190px; } .obv-line { display: none; } }

/* brand line — $MemeGraph visible on the Graph page itself */
.atlas-brandline { color: var(--brass, #d0a559); font-size: 0.78rem;
  letter-spacing: 0.04em; margin: 0.3rem 0 0; opacity: 0.9; }
