:root {
  color-scheme: dark;
  --ink: #101418;
  --soil: #20251d;
  --canopy: #29392f;
  --moss: #8fbf72;
  --lichen: #d5e8c7;
  --mist: #f2f5ec;
  --amber: #e8b45d;
  --rose: #d98172;
  --water: #74b7bd;
  --line: rgba(242, 245, 236, 0.16);
  --panel: rgba(16, 20, 24, 0.74);
  --panel-strong: rgba(32, 37, 29, 0.88);
  --mono: "IBM Plex Mono", "SFMono-Regular", "Menlo", monospace;
  --sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

:root[data-theme="light"] {
  color-scheme: light;
  --ink: #f7faf4;
  --soil: #dfe8dc;
  --canopy: #eef5ea;
  --moss: #517f3f;
  --lichen: #254427;
  --mist: #17201c;
  --amber: #9a640e;
  --rose: #a94d42;
  --water: #2f7278;
  --line: rgba(23, 32, 28, 0.18);
  --panel: rgba(255, 255, 252, 0.76);
  --panel-strong: rgba(238, 245, 234, 0.9);
}

* {
  box-sizing: border-box;
}

body {
  position: relative;
  margin: 0;
  min-width: 320px;
  font-family: var(--sans);
  color: var(--mist);
  background:
    linear-gradient(135deg, rgba(116, 183, 189, 0.18), transparent 38%),
    linear-gradient(180deg, #26382f 0%, #101418 72%);
  transition: background 220ms ease, color 220ms ease;
}

:root[data-theme="light"] body {
  background:
    linear-gradient(135deg, rgba(47, 114, 120, 0.14), transparent 40%),
    linear-gradient(180deg, #f1f7ee 0%, #cfdccc 100%);
}

.leaf-growth-background {
  position: fixed;
  inset: 0;
  z-index: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  opacity: 0.82;
  mix-blend-mode: screen;
}

:root[data-theme="light"] .leaf-growth-background {
  opacity: 0.46;
  mix-blend-mode: multiply;
}

a {
  color: inherit;
}

button,
.button-link,
input,
select {
  font: inherit;
}

button,
.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0 16px;
  color: #101418;
  background: var(--moss);
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}

button.secondary,
.button-link.secondary {
  color: var(--mist);
  border-color: var(--line);
  background: rgba(242, 245, 236, 0.08);
}

button:hover,
.button-link:hover {
  filter: brightness(1.08);
}

input,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  color: var(--mist);
  background: rgba(16, 20, 24, 0.62);
}

input[type="checkbox"] {
  width: 18px;
  min-height: 18px;
  accent-color: var(--moss);
}

.page-shell {
  position: relative;
  z-index: 1;
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 22px 0 48px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: 48px;
}

.brand,
.nav-links,
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand {
  color: var(--mist);
  font-weight: 800;
  text-decoration: none;
}

.brand-mark {
  width: 24px;
  aspect-ratio: 1;
  border: 2px solid var(--moss);
  border-radius: 50%;
  box-shadow: inset 0 0 0 5px rgba(143, 191, 114, 0.18);
}

.topbar-actions {
  gap: 8px;
}

.topbar .icon-button {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 42px;
  min-height: 42px;
  border-color: var(--line);
  padding: 0;
  color: var(--mist);
  background: rgba(242, 245, 236, 0.08);
}

:root[data-theme="light"] .topbar .icon-button {
  background: rgba(255, 255, 252, 0.64);
}

.theme-icon {
  position: relative;
  width: 18px;
  aspect-ratio: 1;
  border: 2px solid currentColor;
  border-radius: 50%;
}

.theme-icon::after {
  content: "";
  position: absolute;
  inset: 3px 0 3px 8px;
  border-radius: 0 999px 999px 0;
  background: currentColor;
}

:root[data-theme="light"] .theme-icon::after {
  inset: 6px;
  border-radius: 50%;
}

.settings-icon {
  position: relative;
  width: 20px;
  height: 16px;
  background:
    linear-gradient(currentColor, currentColor) 0 2px / 20px 2px no-repeat,
    linear-gradient(currentColor, currentColor) 0 7px / 20px 2px no-repeat,
    linear-gradient(currentColor, currentColor) 0 12px / 20px 2px no-repeat;
}

.settings-icon::before,
.settings-icon::after {
  content: "";
  position: absolute;
  width: 6px;
  aspect-ratio: 1;
  border: 2px solid currentColor;
  border-radius: 50%;
  background: var(--panel-strong);
}

.settings-icon::before {
  left: 3px;
  top: 0;
}

.settings-icon::after {
  right: 3px;
  bottom: 0;
}

.back-icon {
  position: relative;
  width: 18px;
  height: 18px;
}

.back-icon::before {
  content: "";
  position: absolute;
  inset: 3px 2px 3px 7px;
  border-left: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
}

.back-icon::after {
  content: "";
  position: absolute;
  left: 6px;
  right: 1px;
  top: 8px;
  height: 2px;
  background: currentColor;
}

.settings-toggle[aria-pressed="true"] {
  color: #101418;
  background: var(--moss);
}

.nav-links a {
  color: rgba(242, 245, 236, 0.72);
  font-size: 0.92rem;
  text-decoration: none;
}

.nav-links a:hover {
  color: var(--mist);
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 470px);
  align-items: center;
  gap: 38px;
  min-height: calc(100vh - 118px);
  padding: 42px 0 26px;
}

.hero-copy {
  max-width: 690px;
}

.eyebrow,
label,
.peer-kind,
.reference-kind,
.globe-readout,
summary,
.output {
  font-family: var(--mono);
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--amber);
  font-size: 0.76rem;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 16px;
  font-size: clamp(4rem, 14vw, 9.4rem);
  line-height: 0.82;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 8px;
  font-size: 1.25rem;
}

h3 {
  margin-bottom: 6px;
  font-size: 1rem;
}

h4 {
  margin: 0 0 8px;
  font-size: 0.98rem;
}

.lede {
  max-width: 650px;
  color: rgba(242, 245, 236, 0.78);
  font-size: clamp(1.08rem, 2vw, 1.32rem);
  line-height: 1.56;
}

:root[data-theme="light"] .lede {
  color: rgba(23, 32, 28, 0.72);
}

blockquote {
  margin: 28px 0;
  max-width: 680px;
  border-left: 3px solid var(--moss);
  padding-left: 18px;
  color: var(--lichen);
  font-size: clamp(1.2rem, 2.3vw, 1.7rem);
  line-height: 1.35;
}

.hero-actions,
.button-row,
.input-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.globe-stage {
  position: relative;
  z-index: 2;
  display: grid;
  justify-items: center;
  gap: 18px;
  user-select: none;
}

.globe-stage.is-zoom-expanded {
  z-index: 20;
}

.globe {
  position: relative;
  width: min(76vw, 430px);
  aspect-ratio: 1;
  border: 0;
  border-radius: 0;
  overflow: visible;
  background: transparent;
  box-shadow: none;
  cursor: grab;
  transform-style: preserve-3d;
  transition: border-radius 700ms ease;
  user-select: none;
}

.globe::before {
  content: none;
  position: absolute;
  inset: -16%;
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 50%,
      rgba(3, 8, 21, 0.42) 0%,
      rgba(3, 8, 21, 0.24) 54%,
      rgba(116, 183, 189, 0.1) 72%,
      transparent 100%);
  pointer-events: none;
}

.globe-stage.is-zoom-expanded .globe {
  overflow: visible;
  background: transparent;
  box-shadow: none;
}

.globe-stage.is-zoom-expanded .globe::before {
  inset: -22%;
  background:
    radial-gradient(circle at 50% 50%,
      rgba(3, 8, 21, 0.3) 0%,
      rgba(3, 8, 21, 0.14) 58%,
      transparent 100%);
}

.globe-stage.is-zoom-expanded .space-core-globe {
  border-radius: 0;
}

.globe-stage.is-zoom-expanded .globe-ring {
  display: none;
}

.globe-stage.is-zoom-expanded .globe-readout {
  z-index: 2;
}

.globe-ring {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  display: none;
}

.space-core-globe {
  position: fixed;
  inset: 0;
  z-index: 1;
  width: 100vw;
  height: 100svh;
  border-radius: 0;
  outline: none;
  pointer-events: none;
  touch-action: none;
  user-select: none;
}

.space-core-globe.is-dragging {
  cursor: grabbing;
}

body:has(.space-core-globe.is-dragging) {
  user-select: none;
}

.globe:has(.space-core-globe.is-dragging) {
  cursor: grabbing;
}

.space-core-globe:focus-visible {
  box-shadow: none;
}

.space-cube-tooltip {
  position: fixed;
  z-index: 28;
  display: grid;
  gap: 4px;
  width: min(260px, calc(100vw - 24px));
  border: 1px solid rgba(242, 245, 236, 0.22);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--mist);
  background: rgba(16, 20, 24, 0.9);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.32);
  pointer-events: none;
}

.space-cube-tooltip[hidden] {
  display: none;
}

.space-cube-tooltip strong,
.space-cube-tooltip span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.space-cube-tooltip strong {
  font-size: 0.86rem;
  line-height: 1.2;
}

.space-cube-tooltip span {
  color: rgba(242, 245, 236, 0.7);
  font-family: var(--mono);
  font-size: 0.68rem;
  line-height: 1.25;
}

.space-drill-hud {
  position: fixed;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 29;
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) 34px;
  align-items: center;
  gap: 8px;
  width: min(420px, calc(100vw - 24px));
  border: 1px solid rgba(242, 245, 236, 0.18);
  border-radius: 8px;
  padding: 8px;
  color: var(--mist);
  background: rgba(16, 20, 24, 0.88);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.3);
  pointer-events: auto;
  transform: translateX(-50%);
}

.space-drill-hud[hidden] {
  display: none;
}

.space-drill-button {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  min-height: 0;
  border-color: rgba(242, 245, 236, 0.18);
  border-radius: 8px;
  padding: 0;
  color: var(--mist);
  background: rgba(242, 245, 236, 0.08);
  font-size: 1.2rem;
  line-height: 1;
}

.space-drill-button:hover,
.space-drill-button:focus-visible {
  border-color: rgba(143, 191, 114, 0.58);
  background: rgba(143, 191, 114, 0.2);
  filter: none;
}

.space-drill-text {
  display: grid;
  min-width: 0;
  gap: 2px;
}

.space-drill-text strong,
.space-drill-text span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.space-drill-text strong {
  font-size: 0.78rem;
  line-height: 1.15;
}

.space-drill-text span {
  color: rgba(242, 245, 236, 0.68);
  font-family: var(--mono);
  font-size: 0.64rem;
  line-height: 1.2;
}

.globe-ring {
  border: 1px solid rgba(213, 232, 199, 0.16);
  mix-blend-mode: screen;
  opacity: 0.7;
  pointer-events: none;
}

.globe-ring-a {
  transform: rotate(24deg) scaleX(0.54);
}

.globe-ring-b {
  transform: rotate(-26deg) scaleX(0.72);
}

.globe-ring-c {
  transform: rotate(90deg) scaleX(0.46);
}

.globe-readout {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  color: rgba(242, 245, 236, 0.72);
  font-size: 0.82rem;
}

.globe-readout span,
.peer-kind,
.reference-kind,
.status-pill {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 9px;
  background: rgba(16, 20, 24, 0.42);
}

:root[data-theme="light"] .globe-readout {
  color: rgba(23, 32, 28, 0.7);
}

:root[data-theme="light"] .globe-readout span,
:root[data-theme="light"] .peer-kind,
:root[data-theme="light"] .reference-kind,
:root[data-theme="light"] .status-pill {
  background: rgba(255, 255, 252, 0.48);
}

.branch-console {
  width: min(100%, 430px);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: rgba(16, 20, 24, 0.48);
  backdrop-filter: blur(14px);
}

:root[data-theme="light"] .branch-console {
  background: rgba(255, 255, 252, 0.58);
}

.branch-console-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.branch-console-header .eyebrow,
.branch-console-header h2 {
  margin: 0;
}

.branch-console-header h2 {
  font-size: 0.98rem;
}

.branch-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.branch-button {
  display: grid;
  justify-items: start;
  min-height: 58px;
  border-color: rgba(242, 245, 236, 0.14);
  padding: 9px 10px;
  color: var(--mist);
  background: rgba(242, 245, 236, 0.07);
  text-align: left;
}

.branch-button:hover,
.branch-button[aria-pressed="true"] {
  border-color: rgba(143, 191, 114, 0.52);
  background: rgba(143, 191, 114, 0.18);
  filter: none;
}

.branch-button[aria-pressed="true"] {
  box-shadow: inset 3px 0 0 var(--moss);
}

.branch-label {
  overflow: hidden;
  max-width: 100%;
  font-size: 0.86rem;
  font-weight: 800;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.branch-meta {
  overflow: hidden;
  max-width: 100%;
  color: rgba(242, 245, 236, 0.64);
  font-family: var(--mono);
  font-size: 0.68rem;
  font-weight: 600;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

:root[data-theme="light"] .branch-button {
  border-color: rgba(23, 32, 28, 0.12);
  background: rgba(23, 32, 28, 0.045);
}

:root[data-theme="light"] .branch-button:hover,
:root[data-theme="light"] .branch-button[aria-pressed="true"] {
  border-color: rgba(81, 127, 63, 0.44);
  background: rgba(81, 127, 63, 0.12);
}

:root[data-theme="light"] .branch-meta {
  color: rgba(23, 32, 28, 0.62);
}

.app-view[hidden],
.settings-panel[hidden] {
  display: none;
}

.surface-grid {
  display: grid;
  grid-template-columns: minmax(0, 0.95fr) minmax(0, 1.05fr);
  gap: 18px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 20px;
  background: var(--panel);
}

.panel-primary,
.doctrine-panel {
  background: var(--panel-strong);
}

.panel-header p {
  margin-bottom: 4px;
}

.peer-form {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
}

.corpus-settings-form {
  display: grid;
  gap: 12px;
}

.settings-view {
  min-height: calc(100vh - 92px);
  padding: 46px 0 20px;
}

:root[data-view="settings"] .space-core-globe {
  opacity: 0.18;
}

.settings-shell {
  display: grid;
  gap: 22px;
}

.settings-header {
  display: flex;
  align-items: center;
  gap: 14px;
  max-width: 760px;
}

.settings-header h2 {
  margin-bottom: 0;
  font-size: clamp(1.7rem, 4vw, 3rem);
  line-height: 1;
}

.settings-layout {
  display: grid;
  grid-template-columns: minmax(180px, 230px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.settings-nav {
  position: sticky;
  top: 18px;
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: var(--panel);
}

.settings-tab {
  justify-content: flex-start;
  width: 100%;
  border-color: transparent;
  color: var(--mist);
  background: transparent;
  text-align: left;
}

.settings-tab.is-active {
  color: #101418;
  background: var(--moss);
}

.settings-panels {
  min-width: 0;
}

.settings-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 20px;
  background: var(--panel);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.settings-form,
.settings-stack {
  display: grid;
  gap: 14px;
}

.settings-subsection {
  border: 1px solid rgba(242, 245, 236, 0.12);
  border-radius: 8px;
  padding: 16px;
  background: rgba(242, 245, 236, 0.055);
}

:root[data-theme="light"] .settings-subsection,
:root[data-theme="light"] .peer-card,
:root[data-theme="light"] .reference-card,
:root[data-theme="light"] .role-card,
:root[data-theme="light"] .corpus-book-card,
:root[data-theme="light"] .doctrine-list article,
:root[data-theme="light"] .human-list article {
  border-color: rgba(23, 32, 28, 0.12);
  background: rgba(255, 255, 252, 0.4);
}

.setting-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.book-setting-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 42px;
  align-items: center;
  gap: 12px;
  min-height: 46px;
}

.book-setting-toggle {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--mist);
  font-family: var(--sans);
  font-size: 1.05rem;
  font-weight: 800;
  text-transform: none;
}

:root[data-theme="light"] .book-setting-toggle {
  color: var(--mist);
}

.details-toggle {
  color: var(--mist);
  border-color: var(--line);
  background: transparent;
}

.chevron-icon {
  width: 10px;
  height: 10px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg) translateY(-2px);
  transition: transform 160ms ease;
}

.details-toggle[aria-expanded="true"] .chevron-icon {
  transform: rotate(225deg) translate(-2px, -1px);
}

.book-setting-details {
  display: grid;
  gap: 12px;
  padding-top: 14px;
}

.book-setting-details[hidden] {
  display: none;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.corpus-book-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

label {
  color: rgba(242, 245, 236, 0.7);
  font-size: 0.74rem;
  letter-spacing: 0;
  text-transform: uppercase;
}

:root[data-theme="light"] label {
  color: rgba(23, 32, 28, 0.7);
}

.input-row {
  flex-wrap: nowrap;
}

.icon-button {
  width: 42px;
  flex: 0 0 auto;
  padding: 0;
  font-size: 1.4rem;
}

.peer-list,
.reference-list,
.role-list,
.doctrine-list,
.human-list {
  display: grid;
  gap: 12px;
}

.peer-card,
.reference-card,
.role-card,
.corpus-book-card,
.doctrine-list article,
.human-list article {
  border: 1px solid rgba(242, 245, 236, 0.12);
  border-radius: 8px;
  padding: 14px;
  background: rgba(242, 245, 236, 0.055);
}

.peer-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

.peer-card h3,
.reference-card h3,
.role-card h3 {
  margin-bottom: 4px;
}

.peer-card p,
.reference-card p,
.role-card p,
.doctrine-list p,
.human-list p {
  margin-bottom: 0;
  color: rgba(242, 245, 236, 0.7);
  line-height: 1.45;
}

:root[data-theme="light"] .role-card p,
:root[data-theme="light"] .doctrine-list p,
:root[data-theme="light"] .human-list p {
  color: rgba(23, 32, 28, 0.72);
}

.peer-meta,
.reference-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
  color: rgba(242, 245, 236, 0.68);
  font-size: 0.78rem;
}

:root[data-theme="light"] .peer-meta,
:root[data-theme="light"] .reference-meta {
  color: rgba(23, 32, 28, 0.68);
}

.status-ok {
  color: var(--lichen);
}

.status-error {
  color: var(--rose);
}

.reference-card a {
  color: var(--mist);
  text-decoration-color: rgba(143, 191, 114, 0.6);
  text-underline-offset: 3px;
}

.doctrine-panel,
.trading-panel {
  grid-column: 1 / -1;
}

summary {
  cursor: pointer;
  color: var(--lichen);
  font-weight: 700;
}

.field-grid {
  display: grid;
  gap: 12px;
  margin-top: 16px;
}

.output {
  margin: 14px 0 0;
  max-height: 360px;
  overflow: auto;
  border-radius: 8px;
  padding: 14px;
  background: rgba(0, 0, 0, 0.32);
  color: rgba(242, 245, 236, 0.78);
  font-size: 0.8rem;
  line-height: 1.5;
}

@media (max-width: 860px) {
  .nav-links {
    align-items: flex-start;
  }

  .topbar {
    align-items: center;
    flex-direction: row;
    flex-wrap: wrap;
  }

  .hero,
  .surface-grid,
  .settings-layout {
    grid-template-columns: 1fr;
  }

  .hero {
    min-height: auto;
  }

  .peer-card {
    grid-template-columns: 1fr;
  }

  .branch-console {
    width: 100%;
  }

  .settings-nav {
    position: static;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 520px) {
  .branch-list {
    grid-template-columns: 1fr;
  }
}
