:root {
  color-scheme: light;
  --bg: #f3efe6;
  --bg-2: #e6dfd3;
  --panel: rgba(255, 255, 255, 0.78);
  --panel-strong: rgba(255, 250, 242, 0.92);
  --panel-border: rgba(44, 34, 24, 0.12);
  --text: #1e1a16;
  --muted: #6d6256;
  --accent: #c55a11;
  --accent-2: #2f6f71;
  --violet: #6e5ab8;
  --good: #1f7a46;
  --bad: #a33a2a;
  --edge: #4d4338;
  --node: #fffaf2;
  --node-border: #3c342c;
  --highlight: #d55c12;
  --selected: #8f4bd6;
  --shadow: 0 24px 60px rgba(54, 43, 31, 0.16);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: "Georgia", "Times New Roman", "Songti SC", serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.72), transparent 28%),
    linear-gradient(135deg, var(--bg), var(--bg-2));
}

body {
  min-height: 100vh;
}

button,
input,
select {
  font: inherit;
}

button,
select,
input {
  border: 1px solid rgba(60, 52, 44, 0.18);
}

button {
  background: rgba(255, 255, 255, 0.72);
  color: var(--text);
  padding: 10px 13px;
  border-radius: 14px;
  cursor: pointer;
  transition: transform 140ms ease, background 140ms ease, border-color 140ms ease, box-shadow 140ms ease;
}

button:hover {
  transform: translateY(-1px);
  border-color: rgba(60, 52, 44, 0.32);
  box-shadow: 0 10px 24px rgba(42, 34, 26, 0.08);
}

button.active,
button.primary {
  background: var(--accent-2);
  color: white;
  border-color: transparent;
}

button.module.active {
  background: var(--accent);
}

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

.shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 18px;
  padding: 18px;
}

.panel,
.stage,
.card,
.inspector {
  background: var(--panel);
  backdrop-filter: blur(18px);
  border: 1px solid var(--panel-border);
  box-shadow: var(--shadow);
}

.panel {
  border-radius: 28px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

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

h1 {
  font-size: clamp(2.4rem, 4vw, 3.7rem);
  line-height: 0.92;
  margin-top: 6px;
}

.subtitle {
  color: var(--muted);
  line-height: 1.55;
  margin-top: 10px;
}

.back-link {
  display: inline-block;
  margin-top: 12px;
  color: var(--accent);
  text-decoration: none;
  font-size: 0.9rem;
  transition: opacity 0.2s;
}

.back-link:hover {
  opacity: 0.7;
}

.card {
  border-radius: 22px;
  padding: 16px;
}

.card h2 {
  color: var(--accent-2);
  font-size: 1rem;
  margin-bottom: 12px;
}

.module-list,
.actions,
.sample-grid,
.control-row,
.color-dock,
.matrix-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

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

.module {
  min-height: 42px;
}

.sample-grid {
  margin-top: 10px;
}

.hint {
  margin-top: 12px;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.5;
}

.module-card {
  display: none;
}

.module-card.visible {
  display: block;
}

.control-row label,
.matrix-actions label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
}

select,
input {
  background: rgba(255, 255, 255, 0.82);
  color: var(--text);
  border-radius: 12px;
  padding: 8px 10px;
}

select {
  min-width: 74px;
}

.swatch {
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: 50%;
  background: var(--swatch);
  border: 3px solid rgba(255, 255, 255, 0.92);
  box-shadow: 0 0 0 1px rgba(60, 52, 44, 0.18);
}

.swatch.active {
  background: var(--swatch);
  border-color: var(--text);
  box-shadow: 0 0 0 3px var(--text);
  color: transparent;
}

.result-card {
  margin-top: 0;
}

.result-title {
  font-weight: 700;
  font-size: 1.08rem;
}

.result-path {
  margin-top: 10px;
  color: var(--accent);
  line-height: 1.6;
  word-break: break-word;
}

.reasons {
  margin: 10px 0 0;
  padding-left: 20px;
  color: var(--muted);
  line-height: 1.55;
}

.workspace {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}

.stage-header {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 16px;
  padding: 8px 8px 0;
}

.stage-header h2 {
  font-size: 2rem;
}

.stage-header p,
.meta {
  color: var(--muted);
  line-height: 1.45;
}

.meta {
  flex: 0 0 auto;
}

.stage {
  position: relative;
  overflow: hidden;
  border-radius: 28px;
  min-height: 520px;
  flex: 1;
}

#graphSvg {
  width: 100%;
  height: 100%;
  min-height: 520px;
  display: block;
  cursor: crosshair;
  background:
    linear-gradient(rgba(255, 255, 255, 0.22), rgba(255, 255, 255, 0.22)),
    radial-gradient(circle at 18% 22%, rgba(255, 255, 255, 0.5), transparent 14%),
    radial-gradient(circle at 82% 18%, rgba(47, 111, 113, 0.14), transparent 18%),
    radial-gradient(circle at 54% 78%, rgba(197, 90, 17, 0.13), transparent 20%);
}

.edge {
  stroke: var(--edge);
  stroke-width: 5;
  stroke-linecap: round;
  transition: stroke 150ms ease, stroke-width 150ms ease, opacity 150ms ease;
}

.edge.selected {
  stroke: var(--selected);
}

.edge.highlight {
  stroke: var(--highlight);
  stroke-width: 8;
}

.edge.temp {
  stroke-dasharray: 8 8;
  opacity: 0.65;
}

.edge-weight {
  fill: var(--accent-2);
  stroke: rgba(255, 250, 242, 0.95);
  stroke-width: 6px;
  paint-order: stroke;
  font-weight: 700;
  font-size: 18px;
  pointer-events: none;
}

.node circle {
  fill: var(--node-fill, var(--node));
  stroke: var(--node-border);
  stroke-width: 2.5;
  transition: fill 150ms ease, stroke 150ms ease, stroke-width 150ms ease;
}

.node text {
  fill: var(--text);
  font-weight: 700;
  font-size: 14px;
  user-select: none;
  pointer-events: none;
  stroke: rgba(255, 250, 242, 0.72);
  stroke-width: 3px;
  paint-order: stroke;
}

.node.selected circle {
  stroke: var(--selected);
  fill: #f4eafe;
}

.node.highlight circle {
  stroke: var(--highlight);
  stroke-width: 4;
}

.node.bad circle {
  stroke: var(--bad);
  stroke-width: 5;
}

.node.dragging circle {
  fill: #f6f1ea;
}

.inspector {
  border-radius: 24px;
  padding: 16px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 0.9fr);
  gap: 16px;
}

.inspector-main {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}

.info-block {
  background: rgba(255, 255, 255, 0.42);
  border: 1px solid rgba(60, 52, 44, 0.1);
  border-radius: 16px;
  padding: 14px;
}

.info-label {
  color: var(--accent-2);
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-bottom: 6px;
}

.info-block h3 {
  font-size: 1.2rem;
  margin-bottom: 6px;
}

.info-block p,
.matrix-head p {
  color: var(--muted);
  line-height: 1.5;
}

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

.stat-card {
  min-height: 92px;
  border-radius: 16px;
  padding: 12px;
  background: var(--panel-strong);
  border: 1px solid rgba(60, 52, 44, 0.12);
}

.stat-card span {
  display: block;
  color: var(--muted);
  font-size: 0.85rem;
}

.stat-card strong {
  display: block;
  margin-top: 5px;
  color: var(--accent);
  font-size: 1.55rem;
  line-height: 1.1;
  word-break: break-word;
}

.stat-card em {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 0.82rem;
  font-style: normal;
  line-height: 1.3;
}

.matrix-panel {
  min-width: 0;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.42);
  border: 1px solid rgba(60, 52, 44, 0.1);
  padding: 14px;
}

.matrix-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
}

.matrix-actions input {
  width: 66px;
}

.matrix-wrap {
  overflow: auto;
  padding-bottom: 4px;
}

.matrix-grid {
  display: grid;
  gap: 6px;
  width: max-content;
}

.matrix-cell {
  width: 42px;
  height: 42px;
  padding: 0;
  border-radius: 10px;
  text-align: center;
}

.matrix-label {
  display: grid;
  place-items: center;
  min-width: 42px;
  min-height: 42px;
  color: var(--accent-2);
  font-weight: 700;
}

@media (max-width: 1180px) {
  .shell {
    grid-template-columns: 1fr;
  }

  .panel {
    order: 2;
  }

  .workspace {
    order: 1;
  }

  .inspector {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .shell {
    padding: 10px;
  }

  .panel,
  .stage,
  .inspector {
    border-radius: 20px;
  }

  .stage-header,
  .matrix-head {
    flex-direction: column;
    align-items: start;
  }

  .module-list,
  .analysis-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .stage,
  #graphSvg {
    min-height: 430px;
  }
}

/* ── Knowledge Modal ── */
.stage-header-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
}

.knowledge-btn {
  width: 36px;
  height: 36px;
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.72);
  color: var(--accent-2);
  border: 1px solid rgba(60, 52, 44, 0.14);
  cursor: pointer;
  transition: transform 140ms ease, background 140ms ease, box-shadow 140ms ease;
}

.knowledge-btn:hover {
  transform: translateY(-1px);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 6px 16px rgba(42, 34, 26, 0.1);
}

.knowledge-btn svg {
  display: block;
}

.knowledge-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  background: rgba(42, 34, 26, 0.34);
  backdrop-filter: blur(6px);
  animation: fadeIn 180ms ease;
}

.knowledge-overlay.hidden {
  display: none;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.knowledge-modal {
  width: min(90vw, 720px);
  max-height: min(85vh, 800px);
  background: var(--panel);
  backdrop-filter: blur(24px);
  border: 1px solid var(--panel-border);
  border-radius: 28px;
  box-shadow: 0 32px 80px rgba(42, 34, 26, 0.28);
  display: flex;
  flex-direction: column;
  animation: slideUp 200ms ease;
}

@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.knowledge-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 12px;
  border-bottom: 1px solid rgba(60, 52, 44, 0.08);
}

.knowledge-header h2 {
  font-size: 1.25rem;
  color: var(--accent-2);
  letter-spacing: 0.02em;
}

.knowledge-close {
  width: 36px;
  height: 36px;
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: 50%;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--muted);
  background: transparent;
  border: none;
  cursor: pointer;
  transition: background 140ms ease, color 140ms ease;
}

.knowledge-close:hover {
  background: rgba(60, 52, 44, 0.08);
  color: var(--text);
}

.knowledge-body {
  padding: 16px 24px 24px;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.knowledge-body section {
  background: rgba(255, 255, 255, 0.42);
  border: 1px solid rgba(60, 52, 44, 0.08);
  border-radius: 16px;
  padding: 14px 16px;
}

.knowledge-body section h3 {
  font-size: 1rem;
  color: var(--accent);
  margin-bottom: 8px;
  font-weight: 700;
}

.knowledge-body section p {
  color: var(--text);
  line-height: 1.65;
  font-size: 0.92rem;
  margin-bottom: 4px;
}

.knowledge-body section p:last-child {
  margin-bottom: 0;
}

.knowledge-body section em {
  color: var(--accent-2);
  font-style: normal;
  font-weight: 600;
}

.knowledge-body section strong {
  color: var(--text);
  font-weight: 700;
}

/* scrollbar styling */
.knowledge-body::-webkit-scrollbar {
  width: 6px;
}

.knowledge-body::-webkit-scrollbar-track {
  background: transparent;
}

.knowledge-body::-webkit-scrollbar-thumb {
  background: rgba(60, 52, 44, 0.14);
  border-radius: 3px;
}
