@import url("https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,600&family=Space+Grotesk:wght@400;500;600&display=swap");

:root {
  --bg: #f7f1e6;
  --bg-accent: #efe4d3;
  --panel-bg: rgba(255, 255, 255, 0.78);
  --panel-border: #e4d3bf;
  --text: #20180f;
  --muted: #6e6154;
  --accent: #ff6b3d;
  --accent-strong: #f2522c;
  --info: #2a9d8f;
  --warn: #f4a261;
  --error: #e63946;
  --glow: rgba(255, 226, 190, 0.35);
  --canvas-bg: #fbf7f2;
  --canvas-grid: rgba(120, 104, 89, 0.12);
  --node-fill: #fff5e8;
  --node-stroke: #cfb39a;
  --node-text: #2b2016;
  --edge-stroke: #b79c87;
  --visited-fill: #ffe3a3;
  --visited-stroke: #e3b35d;
  --current-fill: #ff6b3d;
  --current-stroke: #c13f1f;
  --path-fill: #a8dadc;
  --path-stroke: #2a9d8f;
  --shortest-fill: #d6f5dc;
  --shortest-stroke: #2e7d32;
  --start-stroke: #2a9d8f;
  --end-stroke: #ff6b3d;
  --shadow: 0 18px 40px rgba(31, 24, 15, 0.12);
  --radius: 16px;
  --font-body: "Space Grotesk", "Segoe UI", sans-serif;
  --font-display: "Fraunces", "Times New Roman", serif;
}

[data-theme="dark"] {
  --bg: #121417;
  --bg-accent: #1a1f24;
  --panel-bg: rgba(20, 25, 31, 0.88);
  --panel-border: #2d3640;
  --text: #e8edf2;
  --muted: #9da7b2;
  --accent: #ff8a5b;
  --accent-strong: #ff6b3d;
  --info: #4cc9b0;
  --warn: #f4a261;
  --error: #ff5c5c;
  --glow: rgba(255, 136, 91, 0.12);
  --canvas-bg: #0f1317;
  --canvas-grid: rgba(197, 179, 152, 0.08);
  --node-fill: #1c232a;
  --node-stroke: #3a4652;
  --node-text: #f6f8fa;
  --edge-stroke: #4b5966;
  --visited-fill: #3a2f1a;
  --visited-stroke: #f4a261;
  --current-fill: #ff6b3d;
  --current-stroke: #ffd3b6;
  --path-fill: #1f3b39;
  --path-stroke: #4cc9b0;
  --shortest-fill: #203f27;
  --shortest-stroke: #81c784;
  --start-stroke: #4cc9b0;
  --end-stroke: #ff8a5b;
  --shadow: 0 18px 40px rgba(2, 6, 12, 0.45);
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  color: var(--text);
  font-family: var(--font-body);
  display: flex;
  flex-direction: column;
  background: radial-gradient(circle at 15% 20%, var(--bg-accent), transparent 55%),
    radial-gradient(circle at 80% 10%, var(--glow), transparent 45%),
    linear-gradient(120deg, var(--bg), var(--bg-accent));
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.08) 1px, transparent 1px);
  background-size: 140px 140px;
  opacity: 0.6;
  pointer-events: none;
}

.app {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 24px;
  padding: 24px;
  flex: 1;
  min-height: 0;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 18px;
  overflow-y: auto;
  padding-right: 4px;
}

.brand {
  padding: 8px 6px 4px;
}

.brand-lockup {
  margin-bottom: 10px;
}

.brand-logo-full {
  width: 100%;
  max-width: 300px;
  height: auto;
  display: block;
  filter: drop-shadow(0 6px 16px rgba(31, 24, 15, 0.12));
}

.brand-title {
  font-family: var(--font-display);
  font-size: 1.8rem;
  letter-spacing: 0.02em;
}

.brand-subtitle {
  color: var(--muted);
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.text-link {
  color: var(--accent-strong);
  text-decoration: underline;
  text-underline-offset: 3px;
  padding: 4px 6px;
  border-radius: 8px;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.45);
}

.text-link:hover {
  background: rgba(255, 255, 255, 0.72);
}

.panel-hint-tight {
  margin: 6px 0 0;
}

.panel {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
  animation: rise 0.5s ease both;
}

.panel h2,
.panel h3 {
  margin: 0 0 12px;
  font-family: var(--font-display);
  font-weight: 600;
}

.panel-hint {
  margin: -6px 0 10px;
  color: var(--muted);
  font-size: 0.85rem;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.selection {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.selection-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.badge {
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.4);
  font-weight: 600;
}

.badge-select {
  flex: 1;
  text-align: left;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.badge-select.is-active {
  border-color: var(--accent-strong);
  background: rgba(255, 255, 255, 0.78);
  box-shadow: inset 0 0 0 1px rgba(242, 82, 44, 0.2);
}

.badge-clear {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid rgba(230, 57, 70, 0.35);
  background: rgba(230, 57, 70, 0.1);
  color: var(--error);
  font-size: 1.2rem;
  line-height: 1;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease, background 0.2s ease, border-color 0.2s ease;
}

.badge-clear:hover {
  background: rgba(230, 57, 70, 0.2);
  border-color: rgba(230, 57, 70, 0.55);
  transform: translateY(-1px);
}

.badge-clear:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.label {
  display: block;
  margin-bottom: 8px;
  font-size: 0.85rem;
  color: var(--muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.btn {
  appearance: none;
  border: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.65);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.08);
}

.btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #fff;
  border-color: transparent;
}

.btn.ghost {
  background: transparent;
  border-color: var(--panel-border);
  font-size: 0.85rem;
}

.btn.seg.is-active {
  background: var(--accent);
  color: #fff;
  border-color: transparent;
}

.btn.toggle.is-active {
  background: var(--accent);
  color: #fff;
  border-color: transparent;
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.6;
  transform: none;
}

.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 10px;
}

.button-row.single {
  grid-template-columns: 1fr;
}

.control {
  margin-bottom: 12px;
}

.control.is-hidden {
  display: none;
}

.range-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.range-value {
  font-weight: 600;
  color: var(--muted);
}

.paths-list {
  display: grid;
  gap: 8px;
  max-height: 180px;
  overflow-y: auto;
  padding-right: 4px;
}

.paths-empty {
  padding: 10px;
  border-radius: 10px;
  border: 1px dashed var(--panel-border);
  color: var(--muted);
  font-size: 0.84rem;
}

.path-item {
  border-radius: 10px;
}

.path-link {
  width: 100%;
  text-align: left;
  border: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.48);
  color: var(--text);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 0.82rem;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.path-link:hover {
  background: rgba(255, 255, 255, 0.8);
}

.path-link.is-active {
  border-color: var(--accent-strong);
  box-shadow: inset 0 0 0 1px rgba(242, 82, 44, 0.22);
}

.path-item.is-shortest .path-link {
  color: var(--shortest-stroke);
  border-color: color-mix(in srgb, var(--shortest-stroke) 45%, var(--panel-border));
  font-weight: 700;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

textarea {
  width: 100%;
  border-radius: 12px;
  border: 1px solid var(--panel-border);
  padding: 10px;
  font-family: "Consolas", "Courier New", monospace;
  background: rgba(255, 255, 255, 0.7);
  color: var(--text);
  resize: vertical;
}

input[type="text"] {
  width: 100%;
  border-radius: 12px;
  border: 1px solid var(--panel-border);
  padding: 10px;
  font-family: var(--font-body);
  background: rgba(255, 255, 255, 0.7);
  color: var(--text);
}

input[type="number"] {
  width: 100%;
  border-radius: 12px;
  border: 1px solid var(--panel-border);
  padding: 10px;
  font-family: var(--font-body);
  background: rgba(255, 255, 255, 0.7);
  color: var(--text);
}

input,
textarea {
  outline: none;
}

.info-box {
  border-left: 3px solid var(--accent);
  padding: 12px;
  background: rgba(255, 255, 255, 0.55);
  border-radius: 12px;
  min-height: 64px;
  line-height: 1.4;
  white-space: pre-line;
}

.trace-panel {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.trace-item {
  display: grid;
  gap: 6px;
}

.trace-label {
  font-size: 0.75rem;
  color: var(--muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.trace-box {
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px dashed var(--panel-border);
  background: rgba(255, 255, 255, 0.45);
  font-family: "Consolas", "Courier New", monospace;
  font-size: 0.85rem;
  min-height: 36px;
  line-height: 1.4;
}

.info-box[data-status="warn"] {
  border-left-color: var(--warn);
}

.info-box[data-status="error"] {
  border-left-color: var(--error);
}

.info-box[data-status="success"] {
  border-left-color: var(--info);
}

.error {
  color: var(--error);
  font-weight: 600;
  min-height: 18px;
}

.log {
  max-height: 180px;
  overflow-y: auto;
  display: grid;
  gap: 8px;
  font-size: 0.85rem;
}

.log-popup {
  max-height: min(62vh, 640px);
  padding-right: 4px;
}

.log-popup:empty::before {
  content: "No traversal steps yet. Run BFS/DFS to populate this log.";
  color: var(--muted);
  font-size: 0.9rem;
}

.log-entry {
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.5);
  border: 1px solid var(--panel-border);
  white-space: pre-line;
}

.learn-grid {
  display: grid;
  gap: 16px;
}

.learn-card {
  border-radius: 14px;
  border: 1px dashed var(--panel-border);
  padding: 12px;
  background: rgba(255, 255, 255, 0.45);
}

.learn-card h4 {
  margin: 0 0 8px;
  font-family: var(--font-display);
  font-weight: 600;
}

.learn-list {
  margin: 0 0 10px;
  padding-left: 18px;
  color: var(--muted);
  font-size: 0.85rem;
}

.learn-list li {
  margin-bottom: 4px;
}

.learn-example {
  display: grid;
  gap: 8px;
}

.mini-flow {
  display: grid;
  grid-auto-flow: column;
  align-items: center;
  gap: 8px;
}

.mini-step {
  display: grid;
  gap: 6px;
  justify-items: center;
}

.mini-step.single {
  grid-auto-rows: min-content;
}

.mini-node {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid var(--node-stroke);
  background: var(--node-fill);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--node-text);
}

.mini-link {
  width: 22px;
  height: 2px;
  background: var(--edge-stroke);
}

.mini-text {
  font-size: 0.82rem;
  color: var(--muted);
}

.mono {
  margin: 0;
  font-size: 0.85rem;
  white-space: pre-wrap;
  font-family: "Consolas", "Courier New", monospace;
}

.workspace {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 0;
}

.workspace-header {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: center;
  justify-content: space-between;
}

.workspace-mark {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.74);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow);
}

.workspace-mark-img {
  width: 32px;
  height: 32px;
  object-fit: contain;
}

.workspace-tool-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
  margin-left: auto;
}

.workspace-hint {
  margin-top: -4px;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--muted);
}

.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  display: inline-block;
  border: 2px solid transparent;
}

.legend-dot.start {
  border-color: var(--start-stroke);
}

.legend-dot.end {
  border-color: var(--end-stroke);
}

.legend-dot.visited {
  background: var(--visited-fill);
  border-color: var(--visited-stroke);
}

.legend-dot.current {
  background: var(--current-fill);
  border-color: var(--current-stroke);
}

.legend-dot.path {
  background: var(--path-fill);
  border-color: var(--path-stroke);
}

.hint {
  color: var(--muted);
  font-size: 0.9rem;
}

.graph {
  position: relative;
  flex: 1;
  min-height: 480px;
  height: auto;
  max-height: none;
  border-radius: var(--radius);
  border: 1px solid var(--panel-border);
  background: var(--canvas-bg);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.site-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 24px 18px;
  border-top: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.55);
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.4;
  white-space: nowrap;
  overflow: auto;
}

.site-footer a {
  color: var(--accent-strong);
  font-weight: 600;
}

.footer-left {
  flex: 0 0 auto;
}

.footer-right {
  margin-left: auto;
  text-align: right;
}

.graph::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image: radial-gradient(var(--canvas-grid) 1px, transparent 1px);
  background-size: 28px 28px;
  pointer-events: none;
}

.modal {
  position: fixed;
  inset: 0;
  display: block;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 40;
}

.modal.is-visible {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.modal-backdrop {
  display: block;
  position: absolute;
  inset: 0;
  background: rgba(20, 24, 30, 0.28);
  backdrop-filter: blur(2px);
}

#stepModal .modal-backdrop {
  background: transparent;
  backdrop-filter: none;
}

/* Keep step popup visible, but don't block interaction with the graph outside it. */
#stepModal {
  pointer-events: none;
}

#stepModal .modal-content {
  pointer-events: auto;
}

.modal-content {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(980px, 94vw);
  max-height: min(86vh, 940px);
  overflow: auto;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 18px;
  padding: 18px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 12px;
  pointer-events: auto;
  z-index: 1;
}

.relation-top-actions {
  margin-bottom: 6px;
}

.relation-inline-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
}

.relation-advanced-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.relation-advanced-field {
  display: grid;
  gap: 6px;
}

.relation-advanced {
  display: none;
  border: 1px dashed var(--panel-border);
  border-radius: 12px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.38);
  gap: 10px;
}

.relation-advanced.is-open {
  display: grid;
}

.relation-results-grid {
  display: grid;
  grid-template-columns: 1fr 1.6fr 1fr;
  gap: 12px;
}

.relation-result-panel {
  border-radius: 12px;
  border: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.48);
  padding: 10px;
}

#relationsPreview,
#relationProof,
#adjacencyList {
  min-height: 170px;
}

#relationsInput {
  min-height: 170px;
}

.relation-result-panel > .btn {
  margin-top: 10px;
}

.modal-content.modal-compact {
  top: 24px;
  right: 24px;
  left: auto;
  transform: none;
  width: min(420px, 92vw);
  max-height: calc(100vh - 48px);
}

.modal-content.modal-log {
  width: min(760px, 94vw);
  max-height: min(82vh, 860px);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.modal-header-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.btn-compact {
  padding: 7px 11px;
  font-size: 0.8rem;
}

#stepClose:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.modal-header h3 {
  margin: 0;
  font-family: var(--font-display);
}

.modal-body {
  display: grid;
  gap: 8px;
}

.modal-section-title {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.modal-text {
  white-space: pre-line;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.55);
  border: 1px dashed var(--panel-border);
  font-size: 0.9rem;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.hasse-svg {
  width: 100%;
  height: 100%;
  cursor: crosshair;
}

.hasse-svg:active {
  cursor: crosshair;
}

.svg-bg {
  fill: var(--canvas-bg);
}

.arrow-head {
  fill: var(--edge-stroke);
}

.hasse-edge {
  stroke: var(--edge-stroke);
  stroke-width: 2px;
  fill: none;
  transition: stroke 0.2s ease, stroke-width 0.2s ease;
}

.hasse-edge.active {
  stroke: var(--accent);
  stroke-width: 3px;
  stroke-dasharray: 6 4;
  animation: edgePulse 0.8s ease-in-out infinite;
}

.hasse-edge.path {
  stroke: var(--path-stroke);
  stroke-width: 3px;
}

.hasse-edge.path.shortest-path {
  stroke: var(--shortest-stroke);
  stroke-width: 4px;
}

.hasse-node {
  cursor: pointer;
  transition: transform 0.2s ease;
}

.hasse-node circle {
  fill: var(--node-fill);
  stroke: var(--node-stroke);
  stroke-width: 2px;
  transition: fill 0.2s ease, stroke 0.2s ease;
}

.hasse-node text {
  fill: var(--node-text);
  font-size: 15px;
  font-weight: 600;
  pointer-events: none;
}

.hasse-node text.visit-order {
  font-size: 14px;
  font-weight: 700;
  fill: var(--accent-strong);
  stroke: var(--canvas-bg);
  stroke-width: 3px;
  paint-order: stroke;
}

.hasse-node.visited circle {
  fill: var(--visited-fill);
  stroke: var(--visited-stroke);
}

.hasse-node.current circle {
  fill: var(--current-fill);
  stroke: var(--current-stroke);
}

.hasse-node.path circle {
  fill: var(--path-fill);
  stroke: var(--path-stroke);
}

.hasse-node.path.shortest-path circle {
  fill: var(--shortest-fill);
  stroke: var(--shortest-stroke);
}

.hasse-node.start circle {
  stroke: var(--start-stroke);
  stroke-width: 3px;
}

.hasse-node.end circle {
  stroke: var(--end-stroke);
  stroke-width: 3px;
}

.noscript {
  margin-top: 12px;
  color: var(--error);
  font-weight: 600;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes edgePulse {
  0% {
    opacity: 0.5;
  }
  50% {
    opacity: 1;
  }
  100% {
    opacity: 0.6;
  }
}

@media (max-width: 980px) {
  .app {
    grid-template-columns: 1fr;
  }

  .brand-logo-full {
    max-width: 240px;
  }

  .graph {
    min-height: 360px;
  }

  .relation-inline-row,
  .relation-advanced-row,
  .relation-results-grid {
    grid-template-columns: 1fr;
  }

  .workspace-tools {
    justify-content: flex-start;
    margin-left: 0;
  }

  .site-footer {
    white-space: normal;
    align-items: flex-start;
    flex-direction: column;
  }

  .footer-right {
    margin-left: 0;
    text-align: left;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
