:root {
  color-scheme: light;
  --bg: #f4f7fc;
  --bg-gradient-top: #f7f9fd;
  --bg-gradient-bottom: #edf2fb;
  --panel: #ffffff;
  --border: #d6dfef;
  --text: #14213d;
  --muted: #64748b;
  --primary: #166534;
  --primary-hover: #18713a;
  --danger: #d6455d;
  --surface-subtle: rgba(20, 33, 61, 0.04);
  --shadow: 0 18px 42px rgba(8, 15, 30, 0.12);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: linear-gradient(180deg, var(--bg-gradient-top) 0%, var(--bg-gradient-bottom) 100%);
  color: var(--text);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.wgcna-app {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 18px;
  padding: 24px;
  background: url('../background.png') center center / cover no-repeat;
}

.portal-header {
  width: min(1180px, 100%);
  justify-self: center;
  display: flex;
  flex-direction: column;
  gap: 10px;
  position: relative;
  z-index: 2;
}

.portal-hero {
  position: relative;
  text-align: center;
}

.portal-hero-content {
  position: relative;
  max-width: 960px;
  margin: 0 auto;
  padding: 4px 16px 2px;
  color: #12203b;
}

.portal-hero h1 {
  margin: 0;
  font-size: 32px;
  line-height: 1.08;
  font-weight: 800;
  letter-spacing: 0;
}

.portal-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 58px;
  padding: 8px;
  overflow-x: auto;
  border: 1px solid rgba(255, 255, 255, 0.46);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.52);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px) saturate(150%);
  scrollbar-width: thin;
}

.portal-nav-item {
  flex: 0 0 auto;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 16px;
  border: 1px solid rgba(22, 101, 52, 0.18);
  border-radius: 8px;
  color: #17324d;
  background: rgba(255, 255, 255, 0.62);
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0;
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
  transition: background 140ms ease, border-color 140ms ease, color 140ms ease, box-shadow 140ms ease;
}

.portal-nav-item:hover {
  border-color: rgba(22, 101, 52, 0.34);
  background: rgba(255, 255, 255, 0.84);
}

.portal-nav-item.active {
  border-color: rgba(22, 101, 52, 0.58);
  color: #ffffff;
  background: #166534;
  box-shadow: 0 10px 24px rgba(22, 101, 52, 0.28);
}

.portal-nav-item:disabled {
  cursor: default;
  opacity: 0.58;
  color: rgba(23, 50, 77, 0.72);
  background: rgba(255, 255, 255, 0.38);
}

.wgcna-main {
  width: min(1680px, 100%);
  min-height: 0;
  justify-self: center;
  display: grid;
  grid-template-columns: minmax(300px, 360px) minmax(0, 1fr);
  gap: 14px;
}

.query-panel,
.viewer-panel {
  min-height: 0;
  border: 1px solid rgba(214, 223, 239, 0.82);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: 0 16px 36px rgba(8, 15, 30, 0.1);
  backdrop-filter: blur(16px) saturate(140%);
}

.query-panel {
  padding: 16px;
  overflow: auto;
}

.viewer-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
}

.query-heading {
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  margin-bottom: 16px;
}

h2,
h3 {
  margin: 0;
  letter-spacing: 0;
}

h2 {
  font-size: 23px;
  line-height: 1.15;
}

h3 {
  font-size: 15px;
  line-height: 1.25;
}

.query-form,
.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.query-form {
  gap: 14px;
}

.field span,
.network-filter legend,
.toggle span {
  color: #334155;
  font-size: 12px;
  font-weight: 800;
}

textarea,
input,
select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.92);
  outline: none;
}

textarea {
  min-height: 92px;
  resize: vertical;
  padding: 10px 12px;
  line-height: 1.35;
}

input,
select {
  min-height: 38px;
  padding: 0 10px;
}

textarea:focus,
input:focus,
select:focus {
  border-color: rgba(22, 101, 52, 0.58);
  box-shadow: 0 0 0 3px rgba(22, 101, 52, 0.12);
}

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

.toggle {
  min-height: 38px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.68);
}

.toggle input {
  width: 16px;
  min-height: 16px;
}

.network-filter {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.58);
}

.network-filter label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 700;
}

.network-filter input {
  width: 16px;
  min-height: 16px;
}

.query-actions {
  display: flex;
  gap: 10px;
}

.primary,
.ghost,
.icon-button {
  min-height: 38px;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 0 14px;
  font-weight: 800;
}

.primary {
  color: #ffffff;
  background: var(--primary);
}

.primary:hover {
  background: var(--primary-hover);
}

.ghost,
.icon-button {
  color: #17324d;
  border-color: var(--border);
  background: rgba(255, 255, 255, 0.78);
}

.ghost:hover,
.icon-button:hover {
  background: #ffffff;
}

.viewer-toolbar {
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}

.graph-title {
  color: var(--text);
  font-size: 16px;
  font-weight: 850;
}

.graph-summary {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.export-actions {
  display: flex;
  gap: 8px;
}

.icon-button {
  min-width: 54px;
  padding: 0 10px;
  font-size: 12px;
}

.export-data-button {
  min-width: 142px;
}

.graph-stage {
  position: relative;
  min-height: 620px;
  background:
    linear-gradient(rgba(20, 33, 61, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(20, 33, 61, 0.04) 1px, transparent 1px),
    rgba(255, 255, 255, 0.68);
  background-size: 36px 36px;
}

#cy {
  position: absolute;
  inset: 0;
}

.graph-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-weight: 800;
  pointer-events: none;
}

.selection-panel {
  display: grid;
  gap: 9px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid rgba(214, 223, 239, 0.9);
}

.detail-body {
  font-size: 13px;
  line-height: 1.45;
}

.muted {
  color: var(--muted);
}

.kv {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  gap: 6px 10px;
}

.kv dt {
  color: var(--muted);
  font-weight: 800;
}

.detail-key {
  position: relative;
  display: inline-flex;
  max-width: 100%;
  border-bottom: 1px dotted rgba(100, 116, 139, 0.72);
  cursor: help;
  outline: none;
}

.detail-key::after {
  content: attr(data-tooltip);
  position: absolute;
  left: 0;
  top: calc(100% + 7px);
  z-index: 20;
  width: max-content;
  max-width: 220px;
  padding: 6px 8px;
  border-radius: 6px;
  color: #ffffff;
  background: rgba(15, 23, 42, 0.94);
  box-shadow: 0 10px 24px rgba(8, 15, 30, 0.22);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.3;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-2px);
  transition: opacity 120ms ease 500ms, transform 120ms ease 500ms;
}

.detail-key:hover::after,
.detail-key:focus-visible::after {
  opacity: 1;
  transform: translateY(0);
}

.kv dd {
  margin: 0;
  min-width: 0;
  overflow-wrap: anywhere;
}

@media (max-width: 1280px) {
  .wgcna-main {
    grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
  }
}

@media (max-width: 860px) {
  .wgcna-app {
    padding: 16px;
    overflow: auto;
  }

  .portal-hero h1 {
    font-size: 24px;
  }

  .wgcna-main {
    grid-template-columns: minmax(0, 1fr);
  }

  .graph-stage {
    min-height: 520px;
  }

  .viewer-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }
}
