:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-strong: #eef3f6;
  --ink: #151923;
  --muted: #5f6b78;
  --line: #d8e1ea;
  --accent: #007f73;
  --accent-soft: #dff4ef;
  --coral: #d86f45;
  --blue: #3d73c5;
  --gold: #b98517;
  --violet: #6f61c7;
  --shadow: 0 18px 50px rgba(17, 24, 39, 0.1);
  --radius: 8px;
  --max-width: 1280px;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111419;
  --surface: #1a1f27;
  --surface-strong: #232a35;
  --ink: #f5f7fb;
  --muted: #b5bfcb;
  --line: #323b48;
  --accent: #45c7b5;
  --accent-soft: #143a36;
  --coral: #ff9b70;
  --blue: #9dbbff;
  --gold: #ffd27c;
  --violet: #b8adff;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

html {
  scroll-padding-top: 96px;
}

body {
  margin: 0;
  min-width: 320px;
  background:
    linear-gradient(90deg, rgba(0, 127, 115, 0.07), transparent 34%),
    linear-gradient(180deg, rgba(216, 111, 69, 0.07), transparent 36%),
    var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.55;
}

a {
  color: inherit;
}

button,
input {
  font: inherit;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem max(1rem, calc((100vw - var(--max-width)) / 2));
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface), transparent 8%);
  backdrop-filter: blur(16px);
}

.brand,
.app-header nav {
  display: flex;
  align-items: center;
  gap: 0.7rem;
}

.brand,
.app-header a {
  text-decoration: none;
}

.brand span {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: var(--radius);
  background: var(--ink);
  color: var(--surface);
  font-weight: 900;
}

.app-header nav a,
.theme-toggle,
.filter-bar button,
.map-tools button {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  font-weight: 800;
  min-height: 38px;
  padding: 0.55rem 0.75rem;
  text-decoration: none;
}

.filter-bar button.is-active,
.map-tools button:hover,
.filter-bar button:hover {
  border-color: var(--accent);
}

.filter-bar button.is-active {
  background: var(--accent);
  color: #ffffff;
}

.app-shell {
  width: min(var(--max-width), calc(100% - 2rem));
  margin: 0 auto;
  padding: 4rem 0 5rem;
}

.intro {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 420px);
  gap: 1rem;
  align-items: end;
  margin-bottom: 1.2rem;
}

.intro > div:first-child {
  max-width: 860px;
}

.eyebrow {
  margin: 0 0 0.7rem;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 1rem;
  font-size: clamp(2.25rem, 5vw, 4.4rem);
  line-height: 0.98;
}

h2 {
  margin-bottom: 0.5rem;
  font-size: 1.35rem;
}

h3 {
  margin: 1rem 0 0.55rem;
  font-size: 1rem;
}

.intro p,
.detail-panel p,
.metric-grid p,
.lineage-list,
td,
.panel-heading span,
.map-search span,
.map-hint {
  color: var(--muted);
}

.metric-grid,
.workspace-grid,
.data-grid {
  display: grid;
  gap: 1rem;
}

.metric-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.metric-grid article,
.map-panel,
.detail-panel,
.lineage-panel,
.dictionary-panel {
  scroll-margin-top: 96px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--surface), transparent 2%);
  box-shadow: var(--shadow);
}

.metric-grid article {
  padding: 1rem;
}

.metric-grid span {
  display: block;
  color: var(--coral);
  font-size: 2rem;
  font-weight: 900;
  line-height: 1;
}

.metric-grid p {
  margin: 0.45rem 0 0;
}

.workspace-grid {
  grid-template-columns: minmax(0, 1fr) 360px;
  align-items: start;
  margin-bottom: 1rem;
}

.data-grid {
  grid-template-columns: 360px minmax(0, 1fr);
}

.map-panel,
.detail-panel,
.lineage-panel,
.dictionary-panel {
  padding: 1rem;
}

.panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.8rem;
}

.filter-bar {
  display: flex;
  gap: 0.45rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.map-search {
  margin-bottom: 0.8rem;
}

.map-search label {
  display: grid;
  gap: 0.35rem;
}

.map-search span,
dt {
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.map-search input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  min-height: 42px;
  padding: 0.6rem 0.75rem;
}

.map-tools {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.45rem;
  margin-bottom: 0.8rem;
  flex-wrap: wrap;
}

.map-tools span {
  min-width: 64px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 900;
  text-align: center;
}

.map-tools button {
  min-width: 38px;
  padding: 0.45rem 0.65rem;
}

.rotation-control {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  min-height: 38px;
  min-width: min(320px, 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 0.35rem 0.65rem;
}

.rotation-control span,
.rotation-control strong {
  min-width: auto;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
}

.rotation-control strong {
  min-width: 52px;
  color: var(--ink);
  text-align: right;
}

.rotation-control input {
  flex: 1 1 150px;
  min-width: 120px;
  accent-color: var(--accent);
  cursor: pointer;
}

.map-viewport {
  position: relative;
  height: clamp(560px, 72vh, 820px);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    radial-gradient(circle at center, color-mix(in srgb, var(--accent), transparent 88%), transparent 34%),
    linear-gradient(90deg, color-mix(in srgb, var(--line), transparent 82%) 1px, transparent 1px),
    linear-gradient(180deg, color-mix(in srgb, var(--line), transparent 82%) 1px, transparent 1px),
    var(--surface-strong);
  background-size: auto, 46px 46px, 46px 46px;
  cursor: grab;
  touch-action: none;
  user-select: none;
}

.map-viewport.is-dragging {
  cursor: grabbing;
}

.radial-graph {
  display: block;
  width: 100%;
  height: 100%;
}

.sector-band {
  fill: var(--branch-color, var(--accent));
  opacity: 0.055;
  pointer-events: none;
  transition: opacity 180ms ease, fill 180ms ease;
}

.sector-band.is-selected {
  opacity: 0.13;
}

.sector-band.is-dimmed {
  opacity: 0.018;
}

.radial-link {
  fill: none;
  stroke: color-mix(in srgb, var(--branch-color, var(--muted)), transparent 20%);
  stroke-linecap: round;
  stroke-width: 1.2;
  opacity: 0.42;
  pointer-events: none;
  transition: opacity 180ms ease, stroke 180ms ease, stroke-width 180ms ease;
}

.radial-link.is-selected {
  stroke: var(--branch-color, var(--coral));
  stroke-width: 2.3;
  opacity: 0.96;
}

.radial-link.is-dimmed {
  opacity: 0.08;
}

.radial-link.is-hidden {
  opacity: 0;
}

.radial-node {
  cursor: pointer;
  outline: none;
  transition: opacity 180ms ease;
}

.radial-node circle {
  stroke: var(--surface);
  stroke-width: 3;
  transition: fill 180ms ease, stroke 180ms ease, r 180ms ease, opacity 180ms ease;
}

.radial-node text {
  fill: var(--ink);
  font-size: 17px;
  font-weight: 850;
  paint-order: stroke;
  stroke: color-mix(in srgb, var(--surface-strong), transparent 5%);
  stroke-width: 5px;
  stroke-linejoin: round;
  user-select: none;
  transition: opacity 180ms ease, fill 180ms ease, font-size 180ms ease;
}

.radial-node[data-type="root"] text {
  font-size: 25px;
  font-weight: 950;
  text-anchor: middle;
}

.radial-node[data-type="instrument"] text {
  font-size: 21px;
  fill: var(--branch-color, var(--accent));
}

.radial-node[data-type="application"] text {
  font-size: 15px;
  fill: var(--branch-color, var(--blue));
}

.radial-node[data-type="output"] text {
  font-size: 12px;
  fill: var(--muted);
}

.radial-node[data-type="root"] circle {
  fill: var(--ink);
}

.radial-node[data-type="instrument"] circle {
  fill: var(--branch-color, var(--accent));
}

.radial-node[data-type="application"] circle {
  fill: color-mix(in srgb, var(--branch-color, var(--blue)), #ffffff 18%);
}

.radial-node[data-type="output"] circle {
  fill: color-mix(in srgb, var(--branch-color, var(--gold)), #ffffff 42%);
  stroke-width: 2;
}

.radial-node.is-selected circle {
  fill: var(--coral);
  stroke: var(--ink);
}

.radial-node.is-selected text {
  fill: var(--coral);
}

.radial-node.is-dimmed {
  opacity: 0.16;
}

.radial-node.is-hidden {
  opacity: 0;
  pointer-events: none;
}

.radial-node.is-label-hidden text {
  opacity: 0;
}

.radial-node.is-emphasized circle {
  stroke: var(--ink);
  stroke-width: 4;
}

.radial-node.is-emphasized text {
  font-size: 19px;
}

.map-hint {
  margin: 0.75rem 0 0;
  font-size: 0.92rem;
  font-weight: 800;
}

.detail-list {
  display: grid;
  gap: 0.65rem;
  margin: 1rem 0;
}

.detail-list div {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
  padding: 0.7rem;
}

dt,
dd {
  margin: 0;
}

dd {
  margin-top: 0.25rem;
  font-weight: 800;
}

.chip-list,
.field-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.chip-list span,
.field-list span {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.86rem;
  font-weight: 900;
  padding: 0.42rem 0.55rem;
}

.lineage-list {
  display: grid;
  gap: 0.55rem;
  margin: 0;
  padding-left: 1.2rem;
}

.lineage-list li {
  padding-left: 0.2rem;
}

.lineage-list strong {
  color: var(--ink);
}

.table-wrap {
  max-height: 520px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 0.58rem 0.65rem;
  text-align: left;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--ink);
  color: var(--surface);
  font-size: 0.78rem;
}

tbody tr:nth-child(even) td {
  background: color-mix(in srgb, var(--surface-strong), transparent 45%);
}

tbody tr.is-highlighted td {
  background: color-mix(in srgb, var(--accent-soft), transparent 20%);
  color: var(--ink);
}

@media (max-width: 1080px) {
  .intro,
  .workspace-grid,
  .data-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .app-header,
  .app-header nav,
  .panel-heading,
  .metric-grid {
    align-items: stretch;
    flex-direction: column;
    grid-template-columns: 1fr;
  }

  .app-shell {
    padding-top: 2.5rem;
  }

  h1 {
    font-size: 2.35rem;
  }

  .filter-bar {
    justify-content: stretch;
  }

  .filter-bar button,
  .map-tools button {
    flex: 1 1 auto;
  }

  .map-tools {
    justify-content: stretch;
  }

  .map-viewport {
    height: 520px;
  }

  th,
  td {
    white-space: normal;
  }
}
