/* ===========================================================================
   Linear Algebra Demos — shared theme
   All theme values live here as CSS variables so restyling the whole site is
   a one-file change. No build step; plain CSS.
   =========================================================================== */

:root {
  /* palette */
  --bg:        #f6f5f1;   /* warm neutral paper */
  --surface:   #ffffff;
  --surface-2: #faf9f6;
  --ink:       #1d1d22;   /* primary text */
  --ink-soft:  #5b5b66;   /* secondary text */
  --line:      #e3e1da;   /* borders */
  --line-soft: #efeee9;

  --accent:      #e07b25;  /* warm orange (echoes the lecture slide) */
  --accent-dark: #b45f17;
  --accent-soft: #fbeede;

  --pos:      #2563eb;     /* +1 class (blue) */
  --pos-soft: #dbe6ff;
  --neg:      #e0413f;     /* -1 class (coral/red) */
  --neg-soft: #ffe0df;

  --target:      #0e9384;  /* target separator θ* (teal) */
  --target-soft: #d6f0ec;

  /* type */
  --font-ui:   system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;

  /* shape */
  --radius:   14px;
  --radius-sm: 9px;
  --shadow:   0 1px 2px rgba(20, 20, 30, .04), 0 8px 24px rgba(20, 20, 30, .06);
  --shadow-sm: 0 1px 2px rgba(20, 20, 30, .06);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font-ui);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent-dark); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- layout shell ---- */
.wrap { max-width: 1180px; margin: 0 auto; padding: 0 22px; }

.site-header {
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.site-header .wrap {
  display: flex; align-items: center; gap: 14px;
  padding-top: 16px; padding-bottom: 16px;
}
.brand {
  display: flex; align-items: baseline; gap: 10px;
  font-weight: 700; font-size: 1.05rem; color: var(--ink);
}
.brand .dot { color: var(--accent); }
.brand:hover { text-decoration: none; }
.site-nav { margin-left: auto; display: flex; gap: 18px; font-size: .92rem; }
.site-nav a { color: var(--ink-soft); }
.site-nav a:hover { color: var(--ink); text-decoration: none; }

.site-footer {
  margin-top: 48px; padding: 28px 0;
  border-top: 1px solid var(--line);
  color: var(--ink-soft); font-size: .85rem;
}
.site-footer .footer-row {
  display: flex; justify-content: space-between; align-items: baseline;
  gap: 8px 24px; flex-wrap: wrap;
}
.site-footer .copyright { color: var(--ink-soft); white-space: nowrap; }

/* ---- landing hub ---- */
.hero { padding: 52px 0 30px; }
.hero h1 { font-size: 2.1rem; margin: 0 0 10px; letter-spacing: -.01em; }
.hero p { font-size: 1.08rem; color: var(--ink-soft); max-width: 60ch; margin: 0; }
.eyebrow {
  text-transform: uppercase; letter-spacing: .12em; font-size: .72rem;
  font-weight: 700; color: var(--accent-dark); margin: 0 0 10px;
}

.card-grid {
  display: grid; gap: 18px;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  padding-bottom: 10px;
}
.card {
  display: block; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 22px; box-shadow: var(--shadow-sm);
  transition: transform .12s ease, box-shadow .12s ease, border-color .12s ease;
}
.card:hover {
  text-decoration: none; transform: translateY(-2px);
  box-shadow: var(--shadow); border-color: #d8d5cc;
}
.card h3 { margin: 12px 0 6px; font-size: 1.12rem; color: var(--ink); }
.card p { margin: 0; color: var(--ink-soft); font-size: .92rem; }
.card .tag {
  display: inline-block; font-size: .72rem; font-weight: 700; letter-spacing: .04em;
  color: var(--accent-dark); background: var(--accent-soft);
  padding: 3px 9px; border-radius: 999px;
}
.card.soon { opacity: .6; cursor: default; }
.card.soon:hover { transform: none; box-shadow: var(--shadow-sm); border-color: var(--line); }

/* ---- generic page intro ---- */
.page-intro { padding: 30px 0 8px; }
.page-intro h1 { font-size: 1.7rem; margin: 0 0 8px; letter-spacing: -.01em; }
.page-intro p { color: var(--ink-soft); margin: 0; max-width: 72ch; }
.formula {
  font-family: var(--font-mono); font-size: .9rem;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 10px 14px; margin: 14px 0 0;
  color: var(--ink); display: inline-block;
}

/* ===========================================================================
   Perceptron demo
   =========================================================================== */

.demo-grid {
  display: grid; gap: 22px; align-items: start;
  grid-template-columns: minmax(0, 1.15fr) minmax(320px, .85fr);
  padding: 22px 0 0;
}
@media (max-width: 900px) {
  .demo-grid { grid-template-columns: 1fr; }
}

.panel {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow-sm);
}
.panel + .panel { margin-top: 18px; }
.panel-pad { padding: 16px; }
.panel h2 {
  font-size: .82rem; text-transform: uppercase; letter-spacing: .08em;
  color: var(--ink-soft); margin: 0 0 12px;
}

/* canvas */
.plot-wrap { padding: 12px; }
#plot {
  width: 100%; height: auto; display: block;
  background: var(--surface-2); border-radius: var(--radius-sm);
  border: 1px solid var(--line-soft); cursor: crosshair; touch-action: none;
}

/* status line */
.status {
  display: flex; flex-wrap: wrap; gap: 8px 18px;
  padding: 12px 16px; border-top: 1px solid var(--line-soft);
  font-family: var(--font-mono); font-size: .85rem; color: var(--ink-soft);
}
.status b { color: var(--ink); font-weight: 600; }
.status .pill {
  font-family: var(--font-ui); font-size: .76rem; font-weight: 700;
  padding: 2px 10px; border-radius: 999px;
}
.pill.run     { background: var(--accent-soft); color: var(--accent-dark); }
.pill.done    { background: #def7e6; color: #1f7a44; }
.pill.maxed   { background: var(--neg-soft); color: #a51f1d; }

/* controls */
.controls { display: flex; flex-direction: column; gap: 16px; }
.ctrl-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.ctrl-label {
  font-size: .74rem; text-transform: uppercase; letter-spacing: .07em;
  color: var(--ink-soft); font-weight: 700; width: 100%; margin-bottom: -4px;
}

button.btn, .seg button, .toggle {
  font-family: var(--font-ui); font-size: .9rem; font-weight: 600;
  border: 1px solid var(--line); background: var(--surface);
  color: var(--ink); padding: 9px 14px; border-radius: var(--radius-sm);
  cursor: pointer; transition: background .1s ease, border-color .1s ease, transform .05s ease;
}
button.btn:hover { border-color: #cfccc3; background: var(--surface-2); }
button.btn:active { transform: translateY(1px); }
button.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
button.btn.primary {
  background: var(--accent); border-color: var(--accent); color: #fff;
}
button.btn.primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
button.btn.ghost { background: transparent; }

/* segmented control */
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; }
.seg button {
  border: 0; border-radius: 0; background: var(--surface);
  padding: 8px 13px; color: var(--ink-soft); font-size: .85rem;
}
.seg button + button { border-left: 1px solid var(--line); }
.seg button.active { background: var(--accent-soft); color: var(--accent-dark); }
.seg button.pos.active { background: var(--pos-soft); color: var(--pos); }
.seg button.neg.active { background: var(--neg-soft); color: var(--neg); }
.seg.muted { opacity: .4; pointer-events: none; }

/* numeric add */
.num-add { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.num-add input[type="number"] {
  width: 78px; font-family: var(--font-mono); font-size: .88rem;
  padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface);
}
.num-add label { font-family: var(--font-mono); font-size: .85rem; color: var(--ink-soft); }

/* point-count input + preset picker */
.num-inline { display: flex; align-items: center; gap: 6px; font-size: .85rem; color: var(--ink-soft); }
.num-inline input {
  width: 64px; font-family: var(--font-mono); font-size: .88rem;
  padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface);
}
select.select {
  width: 100%; font-family: var(--font-ui); font-size: .88rem;
  padding: 9px 11px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink); cursor: pointer;
}
select.select:hover { border-color: #cfccc3; }

/* speed slider */
.speed { display: flex; align-items: center; gap: 10px; width: 100%; }
.speed input[type="range"] { flex: 1; accent-color: var(--accent); }
.speed span { font-size: .8rem; color: var(--ink-soft); min-width: 48px; }

.hint { font-size: .82rem; color: var(--ink-soft); margin: 0; }

/* iteration table — fixed layout so it always fits the panel (no sideways scroll) */
.table-scroll { max-height: 360px; overflow-y: auto; overflow-x: hidden; border-radius: var(--radius-sm); }
table.iter {
  width: 100%; table-layout: fixed;
  border-collapse: collapse; font-family: var(--font-mono); font-size: .73rem;
}
.iter .c-t { width: 7%; } .iter .c-i { width: 7%; } .iter .c-x { width: 24%; }
.iter .c-y { width: 9%; } .iter .c-s { width: 17%; } .iter .c-u { width: 9%; }
.iter .c-th { width: 27%; }
table.iter thead th {
  position: sticky; top: 0; background: var(--surface-2);
  text-align: right; padding: 7px 6px; color: var(--ink-soft); font-weight: 600;
  border-bottom: 1px solid var(--line); white-space: nowrap; z-index: 1;
}
/* wrap rather than clip, so nothing is ever cut off */
table.iter tbody td {
  text-align: right; padding: 6px 6px; border-bottom: 1px solid var(--line-soft);
  color: var(--ink); overflow-wrap: break-word; word-break: normal;
}
table.iter tbody tr.updated { background: var(--accent-soft); }
table.iter tbody tr.updated td { color: var(--accent-dark); }
table.iter tbody tr.current td { box-shadow: inset 2px 0 0 var(--accent); }
.yp { color: var(--pos); font-weight: 700; }
.yn { color: var(--neg); font-weight: 700; }
.empty-row td { text-align: center; color: var(--ink-soft); padding: 20px; font-family: var(--font-ui); }

.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: .82rem; color: var(--ink-soft); padding: 0 16px 14px; }
.legend .sw { display: inline-block; width: 11px; height: 11px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.sw.pos { background: var(--pos); }
.sw.neg { background: var(--neg); }
.sw.bound { width: 16px; height: 0; border-top: 2px solid var(--ink); border-radius: 0; }
.sw.theta { width: 16px; height: 0; border-top: 2px solid var(--accent); border-radius: 0; }
.sw.target { width: 16px; height: 0; border-top: 2px dashed var(--target); border-radius: 0; }

/* "This step" panel */
#step-detail { font-size: .86rem; }
.sd-empty { color: var(--ink-soft); margin: 4px 0; }
.sd-line { margin-bottom: 8px; }
.sd-tag {
  display: inline-block; font-size: .7rem; font-weight: 700; letter-spacing: .04em;
  text-transform: uppercase; padding: 2px 8px; border-radius: 999px; margin-right: 6px;
}
.sd-tag.mistake { background: var(--accent-soft); color: var(--accent-dark); }
.sd-tag.ok { background: #def7e6; color: #1f7a44; }
.sd-math { font-family: var(--font-mono); font-size: .82rem; line-height: 1.75; color: var(--ink); }
.sd-math b { font-weight: 600; }
.sd-term { color: var(--accent-dark); }
.sd-good { color: #1f7a44; }
.sd-mut { color: var(--ink-soft); }
.sd-note { font-size: .82rem; color: var(--ink-soft); margin: 10px 0 0; }
.sd-align {
  margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line-soft);
  font-family: var(--font-mono); font-size: .82rem; color: var(--ink);
}
.sd-align b { color: var(--target); font-weight: 600; }
