:root {
  color-scheme: light;
  --paper: #f6f8fb;
  --paper-deep: #ebf0f6;
  --surface: #ffffff;
  --ink: #1b2638;
  --ink-soft: #54657e;
  --ink-muted: #72839b;
  --line: #d6e0ec;
  --line-strong: #b2c2d8;
  --brand: #1e5296;
  --brand-dark: #153c70;
  --brand-mid: #2c67b3;
  --brand-wash: #e7eff9;
  --brand-tint: #f1f6fc;
  --teal: #1d6b87;
  --teal-wash: #e6f3f7;
  --slate-fill: #f3f6fa;
  --amber-ink: #7a5219;
  --amber-wash: #fbf4e6;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: transparent;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

html.is-standalone,
html.is-standalone body {
  background: var(--paper);
}

html.is-standalone body {
  padding: 24px;
}

html.is-standalone #figure-app {
  max-width: 1280px;
  margin: 0 auto;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  box-shadow: 0 18px 50px rgb(21 44 78 / 8%);
}

html.is-embedded,
html.is-embedded body {
  overflow: hidden;
}

#figure-app {
  width: 100%;
  background: var(--surface);
  overflow: hidden;
}

button,
select,
summary {
  font: inherit;
}

button:focus-visible,
a:focus-visible,
select:focus-visible,
summary:focus-visible,
[data-node]:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

/* Top Interactive Bar (RELIC style, Institutional Blue palette) */
.explore-heading {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 16px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--line);
  background: #f3f7fc;
}

.explore-heading__left span {
  display: block;
  color: var(--brand);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.explore-heading__left p {
  margin: 2px 0 0;
  color: var(--ink-soft);
  font-size: 12px;
  line-height: 1.4;
}

.explore-heading__actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.explore-lang-toggle {
  display: none;
  padding: 6px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink-soft);
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
}

html.is-standalone .explore-lang-toggle {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.explore-lang-toggle:hover {
  border-color: var(--brand);
  color: var(--brand-dark);
}

.explore-watch {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 13px;
  border: 1px solid var(--brand);
  border-radius: 6px;
  background: var(--brand);
  color: #ffffff;
  font-size: 11.5px;
  font-weight: 700;
  cursor: pointer;
  transition: background 150ms ease, border-color 150ms ease;
}

.explore-watch:hover {
  background: var(--brand-dark);
  border-color: var(--brand-dark);
}

.explore-reset {
  padding: 7px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--brand-dark);
  font-size: 11.5px;
  font-weight: 700;
  cursor: pointer;
  transition: background 150ms ease, border-color 150ms ease;
}

.explore-reset:hover {
  background: var(--brand-wash);
  border-color: var(--brand);
}

/* Area / View Tabs */
.explore-areas {
  display: grid;
  grid-template-columns: repeat(var(--area-count, 4), minmax(0, 1fr));
  gap: 1px;
  border-bottom: 1px solid var(--line);
  background: var(--line);
}

.explore-areas button {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  padding: 10px 14px 11px;
  border: 0;
  background: #f9fbfe;
  color: var(--ink-soft);
  text-align: left;
  cursor: pointer;
  transition: background 160ms ease, color 160ms ease;
}

.explore-areas button small {
  color: var(--brand);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.explore-areas button strong {
  font-size: 12.5px;
  font-weight: 700;
  line-height: 1.3;
  color: inherit;
}

.explore-areas button::after {
  position: absolute;
  right: 12px;
  bottom: 0;
  left: 12px;
  height: 3px;
  border-radius: 3px 3px 0 0;
  background: var(--brand);
  content: "";
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 220ms ease;
}

.explore-areas button:hover,
.explore-areas button.has-current {
  background: #eef4fc;
  color: var(--brand-dark);
}

.explore-areas button.is-selected {
  background: var(--brand-wash);
  color: var(--brand-dark);
}

.explore-areas button.is-selected::after {
  transform: scaleX(1);
}

/* SVG Stage */
.explore-stage {
  position: relative;
  width: 100%;
  background:
    radial-gradient(circle at 50% 0%, rgb(30 82 150 / 4%), transparent 68%),
    #ffffff;
  padding: 14px 18px 12px;
}

.figure-svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
  user-select: none;
}

.figure-svg[hidden],
.figure-svg.is-hidden {
  display: none !important;
}

/* SVG Interactive Primitives */
.svg-panel-bg {
  transition: stroke 180ms ease, fill 180ms ease, opacity 220ms ease;
}

.svg-node {
  cursor: pointer;
  transition: opacity 220ms ease, filter 180ms ease;
}

.svg-node .node-box {
  transition: stroke 160ms ease, stroke-width 160ms ease, fill 160ms ease;
}

.svg-node:hover .node-box,
.svg-node.is-active .node-box {
  stroke: var(--brand) !important;
  stroke-width: 2.3px !important;
}

.svg-node.is-active {
  filter: drop-shadow(0 6px 14px rgb(21 60 112 / 13%));
}

.figure-svg.has-focus .svg-node:not(.is-active):not(.is-related) {
  opacity: 0.36;
}

.figure-svg.has-focus .svg-node.is-related {
  opacity: 0.86;
}

.svg-edge {
  transition: opacity 220ms ease, stroke 180ms ease, stroke-width 180ms ease;
}

.figure-svg.has-focus .svg-edge:not(.is-active) {
  opacity: 0.22;
}

.svg-edge.is-active {
  opacity: 1;
  stroke-width: 2.4px !important;
}

.svg-edge.is-flowing {
  stroke-dasharray: 7 5;
  animation: edge-flow 0.9s linear infinite;
}

@keyframes edge-flow {
  from {
    stroke-dashoffset: 24;
  }
  to {
    stroke-dashoffset: 0;
  }
}

/* SVG Typography */
.svg-serif {
  font-family: Georgia, "Iowan Old Style", "Noto Serif SC", "Songti SC", serif;
}

.svg-sans {
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

.svg-mono {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
}

/* Bottom Reading Drawer */
.explore-reading {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(230px, 0.65fr);
  gap: 14px 22px;
  min-height: 138px;
  padding: 15px 20px 17px;
  border-top: 1px solid var(--line);
  background: linear-gradient(120deg, #f3f7fc 0%, #f8fafd 100%);
}

.explore-reading[hidden],
.explore-story[hidden] {
  display: none;
}

.explore-reading__kicker {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--brand);
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

.explore-reading__badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--surface);
  color: var(--brand-dark);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: none;
}

.explore-reading__copy h2 {
  margin: 5px 0 6px;
  color: var(--ink);
  font-family: Georgia, "Iowan Old Style", "Noto Serif SC", "Songti SC", serif;
  font-size: 19px;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.28;
}

.explore-reading__copy p {
  max-width: 820px;
  margin: 0;
  color: var(--ink-soft);
  font-size: 13.5px;
  line-height: 1.64;
}

.explore-reading__actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  margin-top: 10px;
}

.explore-reading__actions:empty {
  display: none;
}

.explore-chip {
  padding: 4px 9px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--surface);
  color: var(--brand-dark);
  font-size: 11px;
  font-weight: 650;
  cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease;
}

.explore-chip:hover {
  border-color: var(--brand);
  background: var(--brand-wash);
}

.explore-jump-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 11px;
  border: 1px solid var(--brand);
  border-radius: 6px;
  background: var(--brand);
  color: #ffffff;
  font-size: 11.5px;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}

.explore-jump-link:hover {
  background: var(--brand-dark);
  border-color: var(--brand-dark);
}

/* Collapsible Element Index */
.explore-objects {
  align-self: start;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
}

.explore-objects summary {
  padding: 9px 12px;
  color: var(--brand-dark);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  user-select: none;
}

.explore-index {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  padding: 0 11px 11px;
}

.explore-index button {
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #f9fbfe;
  color: var(--ink-soft);
  font-size: 11px;
  font-weight: 600;
  line-height: 1.25;
  text-align: left;
  cursor: pointer;
}

.explore-index button:hover,
.explore-index button.is-selected {
  border-color: var(--brand);
  background: var(--brand-wash);
  color: var(--brand-dark);
}

/* Guided Explanation Story Bar */
.explore-story {
  min-height: 138px;
  padding: 14px 20px 16px;
  border-top: 1px solid var(--line);
  background: linear-gradient(120deg, #edf3fb 0%, #f7fafe 100%);
}

.explore-story__top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 14px;
}

.explore-story__label {
  color: var(--brand);
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.explore-story__controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}

.explore-story__controls button,
.explore-story__controls select {
  padding: 5px 9px;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  background: var(--surface);
  color: var(--brand-dark);
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
}

.explore-story__controls button:hover:not([disabled]) {
  border-color: var(--brand);
  background: var(--brand-wash);
}

.explore-story__controls button[disabled] {
  opacity: 0.42;
  cursor: default;
}

.explore-story__controls label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--ink-soft);
  font-size: 11px;
  font-weight: 600;
}

.explore-story__close {
  padding: 5px 8px;
  border: 0;
  background: transparent;
  color: var(--brand-dark);
  font-size: 11.5px;
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.explore-story__body {
  margin-top: 8px;
}

.explore-story__step {
  color: var(--brand);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 11px;
  font-weight: 700;
}

.explore-story__body h2 {
  margin: 3px 0 5px;
  color: var(--ink);
  font-family: Georgia, "Iowan Old Style", "Noto Serif SC", "Songti SC", serif;
  font-size: 19px;
  font-weight: 600;
  line-height: 1.28;
}

.explore-story__copy {
  max-width: 900px;
  margin: 0;
  color: var(--ink-soft);
  font-size: 13.5px;
  line-height: 1.62;
}

.explore-story__progress {
  display: flex;
  gap: 6px;
  margin-top: 12px;
}

.explore-story__progress button {
  position: relative;
  flex: 1;
  height: 7px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: #cfdaea;
  overflow: hidden;
  cursor: pointer;
}

.explore-story__progress button::after {
  position: absolute;
  inset: 0;
  background: var(--brand);
  content: "";
  transform: scaleX(var(--progress, 0));
  transform-origin: left;
  transition: transform 100ms linear;
}

@media (max-width: 820px) {
  html.is-standalone body {
    padding: 10px;
  }
  .explore-areas {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .explore-stage {
    padding: 10px 8px 8px;
  }
  .explore-reading {
    grid-template-columns: 1fr;
    padding: 13px 14px 15px;
  }
  .explore-story {
    padding: 13px 14px 15px;
  }
}

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