/* DAGitty — 2026 Design */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
  --primary:      #6366f1;
  --primary-h:    #4f46e5;
  --primary-bg:   #eef2ff;
  --primary-dim:  #c7d2fe;
  --menu-bg:      #0f172a;
  --menu-hover:   #1e293b;
  --menu-border:  rgba(255,255,255,0.08);
  --sidebar-bg:   #ffffff;
  --surface:      #f8fafc;
  --border:       #e2e8f0;
  --border-h:     #cbd5e1;
  --text:         #0f172a;
  --text-2:       #334155;
  --muted:        #64748b;
  --success:      #059669;
  --success-bg:   #ecfdf5;
  --error:        #dc2626;
  --error-bg:     #fef2f2;
  --warn-bg:      #fffbeb;
  --warn-border:  #fcd34d;
  --radius:       6px;
  --radius-lg:    10px;
  --sidebar-w:    16.5em;
  --menu-h:       36px;
  --shadow-sm:    0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
  --shadow-md:    0 4px 12px rgba(0,0,0,.10), 0 2px 4px rgba(0,0,0,.06);
  --shadow-lg:    0 10px 30px rgba(0,0,0,.14), 0 4px 8px rgba(0,0,0,.08);
  --t:            0.15s ease;
}

/* ── Reset ───────────────────────────────────────────────────────────────── */

html, body { height: 100%; }

body {
  margin: 0; padding: 0;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text);
  background: var(--surface);
  overscroll-behavior: contain;
  -webkit-font-smoothing: antialiased;
}

.dagitty { font-family: inherit; font-size: inherit; }

* { box-sizing: border-box; }

/* ── Layout ──────────────────────────────────────────────────────────────── */

main {
  height: 100%;
  display: flex;
  flex-flow: column;
  /* NO position:relative — dagitty uses canvas.offsetLeft for click math */
}

#canvas {
  background-color: #f1f5f9;
  background-image: radial-gradient(circle, #cbd5e1 1px, transparent 1px);
  background-size: 24px 24px;
  outline: none;
  flex: 1 1 auto;
  overflow: hidden;
}

/* Sidebars */
#llegend {
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  overflow-x: hidden;
}

#rlegend {
  background: var(--sidebar-bg);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  overflow-x: hidden;
}

/* Scrollbars */
#llegend::-webkit-scrollbar, #rlegend::-webkit-scrollbar { width: 3px; }
#llegend::-webkit-scrollbar-thumb, #rlegend::-webkit-scrollbar-thumb { background: var(--border-h); border-radius: 3px; }
#llegend::-webkit-scrollbar-track, #rlegend::-webkit-scrollbar-track { background: transparent; }

/* ── Menu bar ────────────────────────────────────────────────────────────── */

#menu {
  margin: 0;
  list-style: none;
  padding: 0;
  display: flex;
  flex: 0 0 var(--menu-h);
  align-items: stretch;
  background: var(--menu-bg);
  position: relative;
  z-index: 30;
}

#menu > li {
  margin: 0; padding: 0;
  position: relative;
}

#menu > li + li { border-left: 1px solid var(--menu-border); }

#menu > li > a {
  display: flex;
  align-items: center;
  padding: 0 .85em;
  height: 100%;
  color: #cbd5e1;
  font-size: 12.5px;
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
  transition: color var(--t), background var(--t);
  letter-spacing: .01em;
}

#menu > li > a:hover { background: var(--menu-hover); color: #fff; }
#menu > li > a:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; color: #fff; }

/* Dropdowns */
#menu li ul {
  position: absolute;
  display: none;
  left: 0; top: 100%;
  list-style: none;
  margin: 2px 0 0;
  padding: 4px;
  min-width: 15em;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: 100;
}

#menu li ul li { margin: 0; padding: 0; }

#menu li ul li a {
  display: block;
  padding: .38em .75em;
  color: var(--text-2);
  font-size: 12.5px;
  text-decoration: none;
  border-radius: calc(var(--radius-lg) - 2px);
  transition: background var(--t), color var(--t);
  white-space: nowrap;
  font-weight: 400;
  height: auto;
}

#menu li ul li a:hover { background: var(--primary-bg); color: var(--primary-h); }
#menu li ul li a:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; }

.menu-sep { height: 1px; background: var(--border); margin: 3px 4px; }

/* Toolbar buttons (Undo/Redo) */
.menu-tools {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 0 .6em;
  border-left: 1px solid var(--menu-border);
}

.menu-tools button {
  background: transparent;
  color: #94a3b8;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: .18em .55em;
  font-size: 11.5px;
  font-family: inherit;
  cursor: pointer;
  transition: all var(--t);
  white-space: nowrap;
  line-height: 1.6;
}

.menu-tools button:hover:not(:disabled) { background: var(--menu-hover); color: #e2e8f0; border-color: rgba(255,255,255,.1); }
.menu-tools button:disabled { opacity: .3; cursor: default; }

/* Mode toggle */
#menu-mode-li {
  display: flex;
  align-items: center;
  padding: 0 .6em;
  border-left: 1px solid var(--menu-border);
}

#btn-beginner-mode {
  background: rgba(99,102,241,.2);
  color: #a5b4fc;
  border: 1px solid rgba(99,102,241,.35);
  border-radius: 20px;
  padding: .18em .75em;
  font-size: 11.5px;
  font-family: inherit;
  cursor: pointer;
  transition: all var(--t);
  white-space: nowrap;
  font-weight: 500;
}

#btn-beginner-mode:hover { background: rgba(99,102,241,.3); color: #c7d2fe; }
#btn-beginner-mode[aria-pressed="true"] { background: var(--primary); color: #fff; border-color: var(--primary); }

.app-title {
  margin-left: auto;
  padding: 0 1em;
  color: #475569;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: .04em;
  text-transform: uppercase;
  pointer-events: none;
  display: flex;
  align-items: center;
}

/* ── Section headers ─────────────────────────────────────────────────────── */

h3 {
  margin: 0;
  padding: .6em .75em .55em;
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--muted);
  background: none;
  border: none;
  border-top: 1px solid var(--border);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: .4em;
  user-select: none;
  transition: color var(--t);
}

h3:first-child { border-top: none; }
h3:hover { color: var(--text); }

/* Chevron */
.chev {
  display: inline-block;
  font-style: normal;
  font-size: 10px;
  width: 14px;
  text-align: center;
  transition: transform var(--t);
  flex-shrink: 0;
  color: var(--border-h);
}

.chev::before { content: '›'; }
.chev[data-open="1"] { transform: rotate(90deg); }

/* ── Sidebar content ─────────────────────────────────────────────────────── */

form { margin: 0; padding: 0; }
p { margin: 0 0 .35em; line-height: 1.5; }

/* Variable form rows */
#llegend form { padding: .45em .75em; }
#llegend form p {
  display: flex;
  align-items: center;
  gap: .45em;
  margin-bottom: .28em;
}

/* Inputs */
input[type="checkbox"],
input[type="radio"] {
  accent-color: var(--primary);
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  cursor: pointer;
}

label {
  cursor: pointer;
  font-size: 12.5px;
  color: var(--text-2);
  font-weight: 400;
}

/* Variable name display */
.var-name-row {
  padding: .35em 0 .3em;
  margin-bottom: .45em !important;
  border-bottom: 1px solid var(--border);
}

#variable_label {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -.01em;
}

.var-btn-row { margin-top: .5em !important; gap: .4em !important; }

/* ── Help tips ───────────────────────────────────────────────────────────── */

.help-tip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  background: var(--primary-dim);
  color: var(--primary-h);
  border-radius: 50%;
  font-size: 9px;
  font-weight: 700;
  cursor: help;
  flex-shrink: 0;
  transition: background var(--t);
  line-height: 1;
}

.help-tip:hover { background: var(--primary); color: #fff; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */

button {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: .32em .8em;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--t), box-shadow var(--t), transform var(--t);
  font-family: inherit;
  letter-spacing: .01em;
}

button:hover { background: var(--primary-h); box-shadow: var(--shadow-sm); }
button:active { transform: translateY(1px); }
button:disabled { opacity: .38; cursor: default; transform: none; box-shadow: none; }

button.btn-danger { background: var(--error); }
button.btn-danger:hover { background: #b91c1c; }

.btn-secondary {
  background: var(--surface);
  color: var(--text-2);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--border); box-shadow: none; }

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--surface); color: var(--text); }

/* ── Select ──────────────────────────────────────────────────────────────── */

select {
  background: var(--sidebar-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .38em .55em;
  font-size: 12.5px;
  font-family: inherit;
  color: var(--text);
  cursor: pointer;
  width: 100%;
  transition: border-color var(--t);
  appearance: auto;
}

select:focus { outline: 2px solid var(--primary); outline-offset: 1px; border-color: var(--primary); }

/* ── Textarea ────────────────────────────────────────────────────────────── */

textarea {
  font-family: 'SFMono-Regular', 'Fira Code', Consolas, monospace;
  font-size: 11px;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .5em .55em;
  resize: vertical;
  background: var(--surface);
  color: var(--text);
  line-height: 1.6;
  transition: border-color var(--t), background var(--t);
}

textarea:focus {
  outline: none;
  border-color: var(--primary);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(99,102,241,.12);
}

/* ── Right sidebar text ──────────────────────────────────────────────────── */

.rlegend-hint {
  font-size: 11.5px;
  color: var(--muted);
  margin: .4em .75em .3em;
  line-height: 1.5;
}

/* ── Adjustment sets / implications ──────────────────────────────────────── */

#causal_effect {
  padding: .25em .75em .4em;
  font-size: 12.5px;
}

#causal_effect p { margin-bottom: .3em; }

#testable_implications {
  padding: .15em .75em .4em;
  font-size: 12px;
}

#adjustmentsets ul, #testable_implications ul {
  padding: 0 0 0 1.1em;
  margin: .3em .5em;
}

#testable_implications li {
  padding: .1em 0;
  font-family: 'SFMono-Regular', Consolas, monospace;
  font-size: 11px;
  color: var(--primary-h);
  cursor: help;
}

.impl-explainer {
  font-size: 11px !important;
  color: var(--muted) !important;
  padding: .2em 0 .3em !important;
  margin: 0 !important;
  font-style: italic;
}

/* ── Status pills ────────────────────────────────────────────────────────── */

p.warning {
  display: flex;
  align-items: flex-start;
  gap: .4em;
  background: var(--error-bg);
  color: var(--error);
  border: 1px solid #fca5a5;
  border-radius: var(--radius);
  padding: .3em .55em;
  font-size: 12px;
  font-weight: 500;
}

p.assurance {
  display: flex;
  align-items: flex-start;
  gap: .4em;
  background: var(--success-bg);
  color: var(--success);
  border: 1px solid #6ee7b7;
  border-radius: var(--radius);
  padding: .3em .55em;
  font-size: 12px;
  font-weight: 500;
}

/* ── Legend ──────────────────────────────────────────────────────────────── */

#legend { padding: .5em .75em; }
#legend p {
  display: flex;
  align-items: center;
  gap: .5em;
  margin-bottom: .3em;
  font-size: 12px;
  color: var(--text-2);
}

/* ── Summary table ───────────────────────────────────────────────────────── */

#info_summary {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  margin: .2em 0 .5em;
}

#info_summary td { padding: .22em .75em; }
#info_summary td:first-child { color: var(--muted); width: 55%; }
.info { font-weight: 700; color: var(--primary-h); }

/* ── Quick start ─────────────────────────────────────────────────────────── */

.qs-card {
  margin: .5em;
  background: linear-gradient(135deg, var(--primary-bg) 0%, #f5f3ff 100%);
  border: 1px solid var(--primary-dim);
  border-radius: var(--radius-lg);
  padding: .65em .85em .75em;
}

.qs-card ol {
  margin: .3em 0 .45em 1.15em;
  padding: 0;
}

.qs-card li {
  font-size: 12.5px;
  margin-bottom: .3em;
  line-height: 1.5;
  color: var(--text-2);
}

.qs-term { font-weight: 700; color: var(--primary-h); }

.qs-shortcuts {
  font-size: 11px;
  color: var(--muted);
  margin: .45em 0 0 !important;
  line-height: 1.8;
}

kbd {
  display: inline-block;
  padding: .05em .38em;
  font-family: inherit;
  font-size: .9em;
  background: #fff;
  border: 1px solid var(--border-h);
  border-bottom-width: 2px;
  border-radius: 4px;
  color: var(--text-2);
  font-weight: 600;
  line-height: 1.4;
}

/* ── Model code actions ──────────────────────────────────────────────────── */

.model-code-actions {
  display: flex;
  gap: .4em;
  padding: .2em .75em .4em;
}

#model_refresh {
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  border-radius: var(--radius);
  padding: .35em .65em;
  font-size: 12px;
  margin: .1em .6em .35em;
  display: flex;
  align-items: center;
  gap: .5em;
}

/* ── Canvas empty-state hint ─────────────────────────────────────────────── */

/* Fixed, so it doesn't affect main's layout or dagitty's offsetLeft math */
#canvas-hint {
  position: fixed;
  top: var(--menu-h);
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 4;
}

@media (min-width: 60em) {
  #canvas-hint {
    left: var(--sidebar-w);
    right: var(--sidebar-w);
  }
}

.canvas-hint-inner {
  text-align: center;
  padding: 2.2em 2.8em;
  background: rgba(255,255,255,.92);
  border: 2px dashed var(--primary-dim);
  border-radius: 14px;
  max-width: 26em;
  box-shadow: var(--shadow-md);
  backdrop-filter: blur(8px);
}

.canvas-hint-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--primary-h);
  margin-bottom: .55em !important;
  letter-spacing: -.01em;
}

.canvas-hint-sub {
  font-size: 12.5px;
  color: var(--muted);
  margin: .2em 0 !important;
  line-height: 1.5;
}

/* ── Dialog window ───────────────────────────────────────────────────────── */

.dialogwin {
  position: absolute;
  inset: 0;
  background: rgba(15,23,42,.45);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.dialogwin form {
  background: #fff;
  border-radius: var(--radius-lg);
  padding: 2em 2.5em;
  box-shadow: var(--shadow-lg);
  max-width: 90%;
  min-width: 18em;
  text-align: center;
}

.dialogwin input, .dialogwin button {
  border: 1px solid var(--border);
  background: #fff;
  padding: .55em 1em;
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 13px;
}

.dialogwin button { background: var(--primary); color: #fff; border-color: var(--primary); cursor: pointer; }
.dialogwin button:hover { background: var(--primary-h); }
.dialogwin .err { color: var(--error); font-size: 12px; }
.dialogwin p { margin: .8em 0; }

/* ── Modal (Data Discovery) ──────────────────────────────────────────────── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,.5);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5em;
}

.modal-dialog {
  background: #fff;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: min(560px, 96vw);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: modal-in .18s ease;
}

@keyframes modal-in {
  from { opacity: 0; transform: scale(.97) translateY(8px); }
  to   { opacity: 1; transform: scale(1)  translateY(0); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .85em 1.1em .8em;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.modal-header h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  cursor: default;
  display: block;
  background: none;
  border: none;
  padding: 0;
  text-transform: none;
  letter-spacing: -.01em;
  pointer-events: none;
  user-select: text;
}

.modal-header h2:hover { background: none; color: var(--text); }

.modal-close {
  background: none;
  color: var(--muted);
  border: none;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  transition: background var(--t), color var(--t);
  padding: 0;
}

.modal-close:hover { background: var(--error-bg); color: var(--error); }

.modal-body {
  padding: 1em 1.1em;
  overflow-y: auto;
  flex: 1 1 auto;
}

.modal-intro {
  font-size: 12.5px;
  color: var(--muted);
  margin-bottom: .85em;
  line-height: 1.55;
}

/* Links inside the data-discovery modal (e.g. the LiNGAM reference) */
.modal-body a, .modal-label a {
  color: var(--primary-h);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.modal-body a:hover, .modal-label a:hover { color: var(--primary); }

.modal-callout {
  display: flex;
  gap: .6em;
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  border-radius: var(--radius);
  padding: .55em .75em;
  font-size: 12px;
  margin-bottom: .9em;
  line-height: 1.5;
  color: #92400e;
}

.modal-field { margin-bottom: .85em; }

.modal-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: .35em;
}

.modal-label-hint { font-weight: 400; color: var(--muted); }

.modal-label-inline {
  display: flex;
  align-items: center;
  gap: .45em;
  font-weight: 400;
  cursor: pointer;
  margin-bottom: 0;
}

.modal-status {
  min-height: 1.6em;
  font-size: 12px;
  padding: .35em .6em;
  border-radius: var(--radius);
  line-height: 1.45;
  transition: background var(--t);
}

.modal-status.status-running { background: #eff6ff; color: #1d4ed8; }
.modal-status.status-error   { background: var(--error-bg); color: var(--error); font-weight: 600; }
.modal-status.status-success { background: var(--success-bg); color: var(--success); font-weight: 600; }

/* Progress bar (shown inside .modal-status while running) */
.progress-label {
  font-size: 11.5px;
  margin-bottom: .35em;
  color: #1d4ed8;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.progress-track {
  height: 6px;
  background: #bfdbfe;
  border-radius: 99px;
  overflow: hidden;
  margin-bottom: .3em;
}

.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, #6366f1, #818cf8);
  border-radius: 99px;
  transition: width 0.25s ease;
  min-width: 4px;
}

.progress-pct {
  font-size: 10.5px;
  color: #3b82f6;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

@media (prefers-color-scheme: dark) {
  .progress-track { background: #1e3a5f; }
  .progress-label { color: #93c5fd; }
  .progress-pct   { color: #60a5fa; }
}

/* Variable selection grid */
.var-select-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: .25em .6em;
  max-height: 140px;
  overflow-y: auto;
  padding: .4em .5em;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 12px;
}
.var-select-grid label {
  display: flex; align-items: center; gap: .3em;
  cursor: pointer; padding: .15em .2em; border-radius: 3px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.var-select-grid label:hover { background: var(--primary-bg); }
.var-select-grid label.var-dropped {
  color: var(--muted); text-decoration: line-through;
  cursor: default; opacity: .6;
}
.var-select-grid input[type="checkbox"] { margin: 0; flex-shrink: 0; }

/* Edge strength badges */
.edge-strength {
  display: inline-block; font-size: 10px; padding: .05em .35em;
  border-radius: 3px; margin-left: .4em; font-weight: 600;
}
.edge-strength.strong   { background: #dcfce7; color: #166534; }
.edge-strength.moderate { background: #fef9c3; color: #854d0e; }
.edge-strength.weak     { background: #fee2e2; color: #991b1b; }

.modal-preview {
  margin-top: .75em;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .6em .75em;
  background: var(--surface);
  max-height: 220px;
  overflow-y: auto;
}

.modal-preview-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  margin-bottom: .4em !important;
}

.modal-preview-edge {
  font-family: 'SFMono-Regular', Consolas, monospace;
  font-size: 11.5px;
  color: var(--primary-h);
  padding: .1em 0;
}

.modal-footer {
  display: flex;
  gap: .5em;
  padding: .8em 1.1em;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  justify-content: flex-end;
  flex-wrap: wrap;
}

/* ── Beginner mode ───────────────────────────────────────────────────────── */

body.beginner-mode #viewmode,
body.beginner-mode #effects,
body.beginner-mode #dagstyle { display: none !important; }

body.beginner-mode h3[onclick*="'viewmode'"],
body.beginner-mode h3[onclick*="'effects'"],
body.beginner-mode h3[onclick*="'dagstyle'"] { display: none !important; }

/* ── Dark mode ───────────────────────────────────────────────────────────── */

@media (prefers-color-scheme: dark) {
  :root {
    --primary:     #818cf8;
    --primary-h:   #6366f1;
    --primary-bg:  #1e1b4b;
    --primary-dim: #312e81;
    --menu-bg:     #020617;
    --menu-hover:  #0f172a;
    --menu-border: rgba(255,255,255,.07);
    --sidebar-bg:  #0f172a;
    --surface:     #1e293b;
    --border:      #334155;
    --border-h:    #475569;
    --text:        #f1f5f9;
    --text-2:      #cbd5e1;
    --muted:       #94a3b8;
    --success:     #34d399;
    --success-bg:  #022c22;
    --error:       #f87171;
    --error-bg:    #2d0a0a;
    --warn-bg:     #1c1400;
    --warn-border: #92400e;
  }

  body { background: #0f172a; }
  #canvas { background-color: #0f172a; background-image: radial-gradient(circle, #1e293b 1px, transparent 1px); }
  textarea { background: #1e293b; color: var(--text); }
  textarea:focus { background: #162032; }
  select { background: #1e293b; color: var(--text); }
  #menu li ul { background: #0f172a; border-color: var(--border); }
  #menu li ul li a { color: var(--text-2); }
  #menu li ul li a:hover { background: var(--primary-bg); color: var(--primary); }
  .modal-dialog { background: #0f172a; }
  .modal-preview { background: #1e293b; }
  .var-select-grid { background: #1e293b; }
  .edge-strength.strong   { background: #064e3b; color: #6ee7b7; }
  .edge-strength.moderate { background: #422006; color: #fbbf24; }
  .edge-strength.weak     { background: #450a0a; color: #fca5a5; }
  .btn-secondary { background: #1e293b; color: var(--text-2); border-color: var(--border); }
  .btn-secondary:hover { background: #334155; }
  kbd { background: #1e293b; border-color: var(--border); color: var(--text-2); }
  .qs-card { background: linear-gradient(135deg, #1e1b4b 0%, #1a1333 100%); border-color: #312e81; }
  .canvas-hint-inner { background: rgba(15,23,42,.93); border-color: var(--primary-dim); }
  .dialogwin form { background: #0f172a; }
  .dialogwin input { background: #1e293b; color: var(--text); border-color: var(--border); }
}

/* ── Responsive ──────────────────────────────────────────────────────────── */

@media (max-width: 40em) {
  :root { --menu-h: 80px; }

  #menu { flex-wrap: wrap; height: auto; }
  .app-title { display: none; }
  #canvas-hint { top: 80px; left: 0; right: 0; }
  #canvas { min-height: 45vh; }

  #llegend, #rlegend {
    width: 100%;
    max-height: 35vh;
    overflow-y: auto;
    border-right: none;
    border-left: none;
  }

  aside { display: flex; flex-wrap: wrap; }
  #llegend { flex: 1 1 50%; border-bottom: 1px solid var(--border); }
  #rlegend { flex: 1 1 50%; border-left: 1px solid var(--border); border-bottom: 1px solid var(--border); }

  input[type="checkbox"], input[type="radio"] { width: 17px; height: 17px; }
  label { font-size: 13px; }

  .modal-dialog { width: 100vw; max-height: 100vh; border-radius: 0; }
  .modal-footer { justify-content: stretch; }
  .modal-footer button { flex: 1 1 auto; }
}

@media (min-width: 40em) and (max-width: 60em) {
  aside { position: absolute; top: 0; left: 0; width: var(--sidebar-w); height: 100%; overflow-y: auto; box-shadow: var(--shadow-md); }
  main { margin-left: calc(var(--sidebar-w) + 1px); }
  #canvas-hint { left: var(--sidebar-w); right: 0; }
}

@media (min-width: 60em) {
  #llegend { position: absolute; top: 0; left: 0; width: var(--sidebar-w); height: 100%; box-shadow: var(--shadow-sm); }
  #rlegend { position: absolute; top: 0; right: 0; width: var(--sidebar-w); height: 100%; box-shadow: var(--shadow-sm); }
  main { margin-left: calc(var(--sidebar-w) + 1px); margin-right: calc(var(--sidebar-w) + 1px); }
}

/* ── Methods / assumptions panel ─────────────────────────────────────────── */

#methods_block { padding-bottom: .3em; }

#methods_text {
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--text-2);
  background: var(--surface);
  white-space: pre-wrap;
  cursor: text;
}
#methods_text:focus { box-shadow: 0 0 0 3px rgba(99,102,241,.12); }

#methods_copy_btn.copied { background: var(--success); }
#methods_copy_btn.copied:hover { background: var(--success); }

/* ── Guided tour ─────────────────────────────────────────────────────────── */

#tour-root { display: none; }
#tour-root.on { display: block; }

#tour-backdrop {
  position: fixed; inset: 0; z-index: 9000;
  background: transparent; cursor: default;
}

#tour-spot {
  position: fixed; z-index: 9001;
  border-radius: 8px;
  box-shadow: 0 0 0 9999px rgba(15,23,42,.55);
  outline: 2px solid var(--primary);
  outline-offset: 0;
  pointer-events: none;
  transition: top .2s ease, left .2s ease, width .2s ease, height .2s ease;
}

#tour-card {
  position: fixed; z-index: 9002;
  width: 340px; max-width: calc(100vw - 16px);
  background: var(--sidebar-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 1.05em 1.15em 0.9em;
  animation: tour-pop .16s ease;
}

@keyframes tour-pop { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

#tour-x {
  position: absolute; top: .5em; right: .5em;
  width: 24px; height: 24px; padding: 0;
  background: none; color: var(--muted);
  border: none; border-radius: 6px; cursor: pointer;
  font-size: 13px; line-height: 1;
}
#tour-x:hover { background: var(--surface); color: var(--text); box-shadow: none; }

#tour-title {
  font-size: 15px; font-weight: 700; color: var(--text);
  margin: 0 1.4em .45em 0; letter-spacing: -.01em; line-height: 1.3;
}
#tour-body {
  font-size: 12.5px; color: var(--text-2); line-height: 1.55; margin: 0 0 .9em;
}
#tour-body strong { color: var(--text); font-weight: 600; }

#tour-foot {
  display: flex; align-items: center; justify-content: space-between;
  border-top: 1px solid var(--border); padding-top: .7em; gap: .5em;
}
#tour-progress { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
#tour-btns { display: flex; gap: .4em; }

.tour-ghost {
  background: transparent; color: var(--muted);
  border: 1px solid var(--border);
}
.tour-ghost:hover { background: var(--surface); color: var(--text); box-shadow: none; }

/* ── First-run tour prompt ───────────────────────────────────────────────── */

#tour-prompt {
  position: fixed; z-index: 8000;
  left: 50%; bottom: 18px; transform: translateX(-50%);
  display: flex; align-items: center; gap: .65em;
  background: var(--sidebar-bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: var(--shadow-lg);
  padding: .5em .7em .5em 1em;
  max-width: calc(100vw - 24px);
  animation: tour-pop .2s ease;
}
#tour-prompt .tp-wave { font-size: 16px; }
#tour-prompt .tp-txt { font-size: 12.5px; color: var(--text-2); }
#tour-prompt button { white-space: nowrap; }

@media (max-width: 40em) {
  #tour-prompt { flex-wrap: wrap; justify-content: center; border-radius: var(--radius-lg); text-align: center; }
  #tour-card { width: calc(100vw - 16px); }
}
