:root {
  color-scheme: light;
  --bg: #f5f6f8;
  --panel: #ffffff;
  --text: #17212b;
  --muted: #5d6975;
  --line: #d5dae1;
  --accent: #1452cc;
  --support: #d7263d;
  --cycle: #1f8f55;
  --path: #ff8c42;
  --code: #eef2f7;
  --layer-zero: #fff7df;
  --layer-one: #eaf2ff;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: linear-gradient(180deg, #f0f3f7 0%, #f8f9fb 100%);
}

.course-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.65rem 1.5rem;
  border-bottom: 1px solid #d8dde5;
  background: #ffffff;
  font-size: 0.95rem;
}

.course-bar a,
.page-footer a {
  color: #173b75;
  text-decoration: none;
}

.course-bar a:hover,
.page-footer a:hover {
  text-decoration: underline;
}

.course-title {
  font-weight: 800;
}

.course-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.4rem 1rem;
}

.page-header {
  padding: 1.2rem 1.5rem;
  border-bottom: 1px solid var(--line);
  background:
    linear-gradient(90deg, rgba(20, 82, 204, 0.07), rgba(31, 143, 85, 0.07)),
    #fff;
}

.page-footer {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.5rem 1.3rem;
  border-top: 1px solid var(--line);
  background: #ffffff;
  color: var(--muted);
  line-height: 1.45;
}

.kicker {
  margin: 0 0 0.35rem;
  color: #3d5d16;
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

h1, h2, h3 {
  margin: 0 0 0.7rem;
}

h1 {
  font-size: 2rem;
}

.subtitle,
.hint,
.details-box,
.legend-grid {
  color: var(--muted);
  line-height: 1.45;
}

.layout {
  display: grid;
  grid-template-columns: minmax(18rem, 24rem) minmax(44rem, 1fr);
  gap: 1rem;
  padding: 1rem 1.5rem 1.5rem;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 1rem;
  box-shadow: 0 10px 24px rgba(8, 15, 30, 0.04);
}

.controls-panel,
.path-card {
  overflow: auto;
}

.visual-stack {
  display: grid;
  gap: 1rem;
  min-width: 0;
}

.graph-panel {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.original-panel svg {
  max-height: 26rem;
}

.lift-workspace {
  display: grid;
  grid-template-columns: minmax(35rem, 1fr) minmax(18rem, 24rem);
  align-items: start;
  gap: 1rem;
}

.path-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: linear-gradient(180deg, #ffffff 0%, #fbfcfe 100%);
  padding: 0.85rem;
  max-height: min(44rem, calc(100vh - 9rem));
  position: sticky;
  top: 1rem;
}

.path-card h3 {
  font-size: 1rem;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.compact-note {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

textarea,
input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
  padding: 0.75rem 0.85rem;
  font: 0.95rem/1.45 ui-monospace, "SFMono-Regular", Menlo, monospace;
}

textarea {
  min-height: 13rem;
  resize: vertical;
}

.field-label {
  display: block;
  margin: 0.9rem 0 0.35rem;
  font-weight: 700;
}

.button-row {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 0.8rem;
}

button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  border-radius: 999px;
  padding: 0.55rem 0.9rem;
  font-weight: 700;
  cursor: pointer;
}

button.primary {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}

.status-box,
.details-box,
.legend-list {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
  padding: 0.75rem 0.85rem;
  margin-top: 0.8rem;
}

.status-box[data-tone="ok"] {
  border-color: rgba(31, 143, 85, 0.35);
  background: rgba(31, 143, 85, 0.07);
}

.status-box[data-tone="error"] {
  border-color: rgba(180, 35, 24, 0.35);
  background: rgba(180, 35, 24, 0.08);
}

svg {
  width: 100%;
  height: auto;
  background: linear-gradient(180deg, #ffffff 0%, #fbfcfe 100%);
  border: 1px solid var(--line);
  border-radius: 10px;
  touch-action: none;
}

.draggable-node {
  cursor: grab;
}

.draggable-node text {
  pointer-events: none;
  user-select: none;
}

.is-dragging-node,
.is-dragging-node .draggable-node {
  cursor: grabbing;
}

.legend-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr));
  gap: 0.35rem 0.75rem;
  font-size: 0.92rem;
}

.legend-swatch {
  display: inline-block;
  width: 2rem;
  height: 0;
  margin-right: 0.45rem;
  border-top: 4px solid #26323d;
  vertical-align: middle;
}

.support-edge { border-top-color: var(--support); }
.cycle-edge { border-top-color: var(--cycle); }
.path-edge { border-top-color: var(--path); }

.legend-node {
  display: inline-block;
  width: 1rem;
  height: 1rem;
  margin-right: 0.45rem;
  border: 2px solid #1d2733;
  border-radius: 999px;
  vertical-align: -0.15rem;
}

.layer-zero { background: var(--layer-zero); }
.layer-one { background: var(--layer-one); }

.best-badge {
  font-weight: 800;
  color: var(--cycle);
}

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

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

th {
  font-size: 0.78rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

tr {
  cursor: pointer;
}

tr:hover {
  background: #f4f8ff;
}

tr.selected {
  background: rgba(255, 140, 66, 0.2);
  box-shadow: inset 5px 0 0 var(--path);
  outline: 2px solid rgba(255, 140, 66, 0.75);
  outline-offset: -2px;
  font-weight: 900;
}

tr.best:not(.selected) {
  background: rgba(31, 143, 85, 0.1);
}

tr.selected code {
  background: #fff3e8;
  color: #8a3b00;
  font-weight: 900;
}

code {
  background: var(--code);
  border-radius: 5px;
  padding: 0.08rem 0.25rem;
}

.edge-pill {
  display: inline-block;
  margin: 0.1rem 0.15rem 0.1rem 0;
  padding: 0.15rem 0.35rem;
  border-radius: 999px;
  background: var(--code);
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
}

.edge-pill.in-support {
  color: var(--support);
  font-weight: 800;
}

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

  .lift-workspace {
    grid-template-columns: 1fr;
  }

  .path-card {
    max-height: none;
    position: static;
  }

  .page-footer,
  .course-bar {
    flex-direction: column;
    align-items: flex-start;
  }
}
