:root {
  color-scheme: light;
  --ink: #172033;
  --muted: #667085;
  --line: #d8e0eb;
  --paper: #f4f7fb;
  --panel: #ffffff;
  --blue: #1769e0;
  --green: #0f766e;
  --amber: #d97706;
  --purple: #7c3aed;
  --red: #dc2626;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--paper);
}

button,
input {
  font: inherit;
}

.shell {
  width: min(1680px, 100%);
  margin: 0 auto;
  padding: 18px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 10px 0 16px;
}

.topbar-actions {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.topbar h1,
.selected-header h2,
.panel-head h2,
.relation-card h3 {
  margin: 0;
  letter-spacing: 0;
}

.topbar h1 {
  font-size: clamp(28px, 4vw, 44px);
  line-height: 1.05;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--blue);
  font-size: 12px;
  font-weight: 850;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.graph-count {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 6px 10px;
  border-radius: 999px;
  background: #e9f2ff;
  color: var(--blue);
  font-size: 13px;
  font-weight: 850;
  white-space: nowrap;
}

.nav-link {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--blue);
  color: #ffffff;
  font-size: 13px;
  font-weight: 850;
  text-decoration: none;
  white-space: nowrap;
}

.mobile-view-switch {
  display: none;
}

.explorer-layout {
  display: grid;
  grid-template-columns: clamp(320px, 21vw, 360px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.explorer-layout > * {
  min-width: 0;
}

.search-panel,
.detail-panel,
.relation-card,
.local-map-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.search-panel {
  position: sticky;
  top: 14px;
}

.search-panel {
  overflow: hidden;
}

.search-box {
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.search-box label {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 850;
}

input[type="search"] {
  width: 100%;
  min-height: 40px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
}

.class-list {
  max-height: calc(100vh - 154px);
  overflow: auto;
  padding: 7px;
}

.class-list button,
.relation-list button {
  display: block;
  width: 100%;
  padding: 8px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.class-list button {
  overflow: hidden;
  font-size: 12px;
  font-weight: 750;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.class-list button:hover,
.class-list button.active,
.relation-list button:hover {
  background: #eef4ff;
}

.math-infinity {
  display: inline-block;
  font-size: 1.28em;
  line-height: 0;
  transform: translateY(0.03em);
}

.detail-panel {
  padding: 16px;
  min-width: 0;
  scroll-margin-top: 12px;
}

.selected-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 8px;
}

.selected-header h2 {
  font-size: clamp(24px, 3vw, 36px);
  line-height: 1.12;
}

.property-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 9px;
}

.property-tags span {
  padding: 4px 8px;
  border: 1px solid #dbe4ef;
  border-radius: 999px;
  background: #ffffff;
  color: #344054;
  font-size: 12px;
  font-weight: 800;
}

.selected-summary {
  margin: 0 0 14px;
  padding: 11px 12px;
  border: 1px solid #e7edf5;
  border-radius: 8px;
  background: #fbfcff;
  color: #344054;
  font-size: 14px;
  font-weight: 750;
  line-height: 1.45;
}

.relation-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.relation-card {
  min-height: 160px;
  padding: 13px;
}

.relation-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  gap: 10px;
  margin-bottom: 9px;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
}

.relation-card h3 {
  font-size: 17px;
}

.relation-card-head span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}

.relation-list {
  display: grid;
  gap: 5px;
  max-height: 220px;
  overflow: auto;
}

.relation-list.empty {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.relation-list button {
  border: 1px solid #e7edf5;
  background: #fbfcff;
  font-size: 13px;
  font-weight: 750;
}

.local-map-card {
  margin-top: 14px;
  overflow: hidden;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.panel-head h2 {
  font-size: 20px;
}

.graph-actions {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.graph-actions button {
  min-height: 34px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  font-weight: 850;
  cursor: pointer;
}

.graph-actions button:hover {
  background: #f1f5fb;
}

.graph-actions button.active {
  border-color: var(--blue);
  background: #e9f2ff;
  color: var(--blue);
}

#fit-graph {
  border-color: var(--blue);
  background: var(--blue);
  color: #ffffff;
}

#fit-graph:hover {
  background: #145bc4;
}

#reset-graph {
  border-color: var(--red);
  background: #fee2e2;
  color: #b91c1c;
}

#reset-graph:hover {
  background: #fecaca;
}

.zoom-control {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}

.zoom-control input {
  width: 120px;
  accent-color: var(--blue);
  cursor: pointer;
}

.class-graph {
  height: 480px;
  background:
    linear-gradient(90deg, rgba(24, 32, 47, 0.055) 1px, transparent 1px),
    linear-gradient(180deg, rgba(24, 32, 47, 0.055) 1px, transparent 1px),
    #fbfcff;
  background-size: 34px 34px;
}

@media (max-width: 1150px) {
  .explorer-layout {
    grid-template-columns: 320px minmax(0, 1fr);
  }
}

@media (max-width: 820px) {
  body {
    overflow-x: hidden;
  }

  .shell {
    width: 100%;
    padding: 10px;
  }

  .topbar,
  .explorer-layout,
  .relation-grid {
    grid-template-columns: 1fr;
  }

  .topbar {
    display: grid;
    gap: 10px;
    padding: 8px 0 12px;
  }

  .topbar h1 {
    font-size: 30px;
    line-height: 1.08;
  }

  .topbar-actions {
    width: 100%;
    justify-content: start;
  }

  .mobile-view-switch {
    position: sticky;
    top: 0;
    z-index: 20;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    margin-bottom: 10px;
    padding: 6px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.94);
    backdrop-filter: blur(10px);
  }

  .mobile-view-switch button {
    min-height: 38px;
    border: 1px solid transparent;
    border-radius: 6px;
    background: transparent;
    color: var(--muted);
    font-size: 13px;
    font-weight: 850;
    cursor: pointer;
  }

  .mobile-view-switch button.active {
    border-color: var(--blue);
    background: #e9f2ff;
    color: var(--blue);
  }

  .nav-link,
  .graph-count {
    min-height: 30px;
    padding: 5px 9px;
    font-size: 12px;
  }

  .search-panel {
    position: static;
  }

  body:not(.mobile-detail-open) .detail-panel {
    display: none;
  }

  body.mobile-detail-open .search-panel {
    display: none;
  }

  .search-box {
    padding: 12px;
  }

  input[type="search"] {
    min-height: 42px;
    font-size: 16px;
  }

  .class-list {
    max-height: none;
    padding: 6px;
  }

  .class-list button {
    min-height: 38px;
    padding: 9px 8px;
    font-size: 13px;
  }

  .detail-panel {
    padding: 12px;
  }

  .selected-header {
    display: block;
  }

  .selected-header h2 {
    font-size: 28px;
  }

  .selected-summary {
    font-size: 13px;
  }

  .relation-card {
    min-height: 0;
    padding: 12px;
  }

  .relation-card-head {
    display: grid;
    min-height: 34px;
    margin-bottom: 0;
    cursor: pointer;
    grid-template-columns: minmax(0, 1fr) auto auto;
  }

  .relation-card-head::after {
    content: "+";
    flex: 0 0 auto;
    display: inline-grid;
    place-items: center;
    width: 24px;
    height: 24px;
    border-radius: 999px;
    background: #eef4ff;
    color: var(--blue);
    font-size: 17px;
    font-weight: 850;
  }

  .relation-card.open .relation-card-head {
    margin-bottom: 9px;
  }

  .relation-card.open .relation-card-head::after {
    content: "−";
  }

  .relation-card:not(.open) .relation-list {
    display: none;
  }

  .relation-list {
    max-height: 180px;
  }

  .panel-head {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    padding: 12px;
  }

  .panel-head h2 {
    font-size: 18px;
    overflow-wrap: anywhere;
  }

  .graph-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
    justify-content: stretch;
  }

  .graph-actions button {
    width: 100%;
    min-height: 38px;
    padding: 7px 8px;
    font-size: 12px;
  }

  .zoom-control {
    grid-column: 1 / -1;
    justify-content: space-between;
    width: 100%;
  }

  .zoom-control input {
    width: min(220px, 62vw);
  }

  .class-graph {
    width: 100%;
    height: min(62vh, 520px);
    min-height: 360px;
  }
}

@media (max-width: 430px) {
  .shell {
    padding: 8px;
  }

  .topbar h1 {
    font-size: 27px;
  }

  .topbar-actions {
    gap: 7px;
  }

  .graph-count {
    white-space: normal;
  }

  .selected-header h2 {
    font-size: 24px;
  }

  .graph-actions {
    grid-template-columns: 1fr 1fr;
    gap: 6px;
  }

  .graph-actions button {
    font-size: 11px;
  }

  .class-graph {
    height: 420px;
    min-height: 420px;
  }
}
