:root {
  --bg: #0b0e14;
  --card: #111827;
  --muted: #9aa4b2;
  --text: #e5e7eb;
  --accent: #22c55e;
  --accent2: #38bdf8;
  --warn: #fbbf24;
  --border: rgba(255, 255, 255, 0.08);
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

/* ── Global polish ──────────────────────────────────────────────────────── */

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

::selection {
  background: rgba(34, 197, 94, 0.3);
  color: #fff;
}

:focus-visible {
  outline: 2px solid var(--accent2);
  outline-offset: 2px;
  border-radius: 4px;
}

/* Page load fade-in */
@keyframes pageIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji",
    "Segoe UI Emoji";
  font-size: 14px;
  line-height: 1.55;
  background: radial-gradient(800px 500px at 10% 0%, rgba(56, 189, 248, 0.12), transparent 55%),
    radial-gradient(800px 500px at 90% 10%, rgba(34, 197, 94, 0.12), transparent 55%), var(--bg);
  color: var(--text);
  animation: pageIn 0.6s ease-out both;
}

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

.wrap {
  max-width: 980px;
  margin: 0 auto;
  padding: 0 16px 60px;
}

/* ── Top bar ────────────────────────────────────────────────────────────── */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  max-width: 980px;
  margin: 0 auto;
}

.topbar-brand {
  font-weight: 800;
  font-size: 15px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.topbar-version {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(34, 197, 94, 0.12);
  color: var(--accent);
  border: 1px solid rgba(34, 197, 94, 0.2);
}

/* ── Hero ───────────────────────────────────────────────────────────────── */

.hero {
  padding: 10px 0 10px;
}

h1 {
  margin: 0 0 8px;
  font-size: 36px;
  letter-spacing: -0.025em;
  line-height: 1.15;
}

h2 {
  margin: 0 0 12px;
  font-size: 18px;
  letter-spacing: -0.01em;
  line-height: 1.3;
}

h3 {
  margin: 18px 0 8px;
  font-size: 13px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  line-height: 1.4;
}

.sub {
  margin: 0 0 12px;
  color: var(--muted);
  line-height: 1.55;
}

/* ── Pills ──────────────────────────────────────────────────────────────── */

.pill-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.pill {
  border: 1px solid var(--border);
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.03);
  transition: background 0.2s ease, border-color 0.2s ease;
}

.pill:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.14);
}

.pill-link {
  color: var(--accent2);
  text-decoration: none;
  cursor: pointer;
}
.pill-link:hover {
  text-decoration: underline;
  background: rgba(56, 189, 248, 0.08);
}

.muted {
  color: var(--muted);
}

.back {
  display: inline-block;
  margin-bottom: 8px;
  color: var(--accent2);
  text-decoration: none;
  font-size: 14px;
}
.back:hover {
  text-decoration: underline;
}

.how-footer {
  margin-top: 28px;
  text-align: center;
}

/* ── Diagram (how.html) ─────────────────────────────────────────────────── */

.diagram {
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 20px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
  line-height: 1.7;
  color: var(--muted);
  overflow-x: auto;
  margin: 12px 0;
  white-space: pre;
}
.diagram b {
  color: var(--text);
}
.diagram .acc {
  color: var(--accent);
}
.diagram .acc2 {
  color: var(--accent2);
}

/* ── Section (how.html) ─────────────────────────────────────────────────── */

.section {
  margin-top: 28px;
}
.section h2 {
  font-size: 22px;
  margin-bottom: 6px;
}
.section p,
.section li {
  color: var(--muted);
  line-height: 1.7;
}
.section p {
  margin: 8px 0;
}

/* ── Tables ─────────────────────────────────────────────────────────────── */

table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0;
  font-size: 13px;
}
th,
td {
  text-align: left;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}
th {
  color: var(--text);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
td {
  color: var(--muted);
}
td code {
  font-size: 11px;
}
.col-num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.note {
  font-size: 13px;
  color: var(--muted);
  margin-top: 6px;
  font-style: italic;
}
.qa {
  margin-top: 16px;
}
.qa dt {
  color: var(--text);
  font-weight: 600;
  margin-top: 14px;
}
.qa dd {
  color: var(--muted);
  margin: 4px 0 0 0;
  line-height: 1.6;
}

/* ── Cards ──────────────────────────────────────────────────────────────── */

.card {
  position: relative;
  background: rgba(17, 24, 39, 0.8);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px 20px 18px;
  margin-top: 14px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
  transition: transform 0.25s ease, box-shadow 0.25s ease;
  overflow: hidden;
}

/* Thin gradient accent on left edge */
.card::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: linear-gradient(180deg, var(--accent), var(--accent2));
  border-radius: 14px 0 0 14px;
  pointer-events: none;
}

.card:hover {
  transform: translateY(-2px);
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.45);
}

/* ── Lists ──────────────────────────────────────────────────────────────── */

ol,
ul {
  margin: 0 0 0 18px;
  color: var(--muted);
  line-height: 1.65;
}

/* ── Code ───────────────────────────────────────────────────────────────── */

code {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 2px 7px;
  border-radius: 7px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 12.5px;
  color: var(--accent2);
}

/* ── Rows / button groups ───────────────────────────────────────────────── */

.row {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-top: 12px;
  flex-wrap: wrap;
}

.row button.ghost {
  white-space: nowrap;
}

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

button {
  appearance: none;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 14px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
  transition:
    transform 0.15s ease,
    box-shadow 0.2s ease,
    background 0.2s ease,
    border-color 0.2s ease,
    opacity 0.3s ease;
}

button:hover:not(:disabled) {
  transform: scale(1.03);
}

button:active:not(:disabled) {
  transform: scale(0.97);
}

button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

.primary {
  background: linear-gradient(135deg, rgba(34, 197, 94, 0.95), rgba(56, 189, 248, 0.8));
  border: none;
  box-shadow: 0 4px 18px rgba(34, 197, 94, 0.2), 0 0 0 0 rgba(34, 197, 94, 0);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.primary:hover:not(:disabled) {
  box-shadow: 0 6px 24px rgba(34, 197, 94, 0.3), 0 0 20px rgba(34, 197, 94, 0.15);
  background: linear-gradient(135deg, rgba(34, 197, 94, 1), rgba(56, 189, 248, 0.9));
}

.primary:active:not(:disabled) {
  box-shadow: 0 2px 10px rgba(34, 197, 94, 0.2);
}

.ghost {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.ghost:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.2);
}

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

.status {
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
}

/* ── Callout ────────────────────────────────────────────────────────────── */

.callout {
  margin-top: 12px;
  border: 1px dashed rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.03);
  padding: 10px 12px;
  border-radius: 12px;
  color: var(--muted);
}

/* ── After-load inline banner ───────────────────────────────────────────── */

.afterInline {
  margin-top: 12px;
  border: 1px solid rgba(34, 197, 94, 0.22);
  background: linear-gradient(135deg, rgba(34, 197, 94, 0.10), rgba(56, 189, 248, 0.06));
  padding: 12px 12px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.afterTextWrap {
  flex: 1 1 420px;
  min-width: 240px;
}
.afterText {
  color: rgba(229, 231, 235, 0.92);
  line-height: 1.45;
  font-size: 13px;
}

/* ── Steps ──────────────────────────────────────────────────────────────── */

.steps {
  display: grid;
  gap: 8px;
}

.step {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border: 1px solid var(--border);
  border-left: 3px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.03);
  padding: 10px 12px 10px 14px;
  border-radius: 12px;
  font-size: 13px;
  color: var(--muted);
  transition:
    border-color 0.4s ease,
    border-left-color 0.4s ease,
    background 0.4s ease,
    color 0.4s ease,
    box-shadow 0.4s ease;
}

/* Running step: blue accent with pulse (targets .step containing .tag.run) */
.step:has(.tag.run) {
  border-left-color: var(--accent2);
  background: rgba(56, 189, 248, 0.05);
  color: var(--text);
  animation: stepPulse 2s ease-in-out infinite;
}

@keyframes stepPulse {
  0%, 100% { box-shadow: inset 3px 0 8px -4px rgba(56, 189, 248, 0.3); }
  50%      { box-shadow: inset 3px 0 12px -2px rgba(56, 189, 248, 0.55); }
}

/* Done step: green accent with checkmark */
.step:has(.tag.ok) {
  border-left-color: var(--accent);
  color: var(--text);
}

.step:has(.tag.ok) > div:first-child::before {
  content: "\2713\00a0";
  font-weight: 700;
  color: var(--accent);
  font-size: 14px;
}

/* Error step: red accent */
.step:has(.tag.err) {
  border-left-color: #fb7185;
  background: rgba(251, 113, 133, 0.05);
}

/* ── Tags ───────────────────────────────────────────────────────────────── */

.tag {
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.02);
  transition: color 0.3s ease, border-color 0.3s ease, background 0.3s ease;
}

.tag.ok {
  color: var(--accent);
  border-color: rgba(34, 197, 94, 0.2);
  background: rgba(34, 197, 94, 0.08);
}
.tag.run {
  color: var(--accent2);
  border-color: rgba(56, 189, 248, 0.2);
  background: rgba(56, 189, 248, 0.08);
}
.tag.err {
  color: #fb7185;
  border-color: rgba(251, 113, 133, 0.2);
  background: rgba(251, 113, 133, 0.08);
}

/* ── Spinner ────────────────────────────────────────────────────────────── */

.spinner {
  width: 44px;
  height: 44px;
  border-radius: 999px;
  border: 3px solid rgba(255, 255, 255, 0.12);
  border-top-color: rgba(56, 189, 248, 0.9);
  animation: spin 0.9s linear infinite;
  margin-top: 10px;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ── Hidden class (uses opacity transition where feasible) ──────────────── */

.hidden {
  display: none !important;
}

/* For elements that toggle visibility but keep layout (afterInline, results, nnViz),
   the JS toggles .hidden. Since display:none is needed for layout collapse,
   we keep it as-is. Fade-in is handled by the show-anim class added via CSS. */

/* ── Neural net viz overlay ─────────────────────────────────────────────── */

.nnViz {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background:
    radial-gradient(800px 500px at 20% 20%, rgba(56, 189, 248, 0.18), transparent 60%),
    radial-gradient(900px 520px at 80% 30%, rgba(34, 197, 94, 0.14), transparent 60%),
    rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(8px);
  animation: vizFadeIn 0.4s ease-out both;
}

@keyframes vizFadeIn {
  from { opacity: 0; backdrop-filter: blur(0px); }
  to   { opacity: 1; backdrop-filter: blur(8px); }
}

.nnVizPanel {
  width: min(980px, 96vw);
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.10);
  background: rgba(11, 14, 20, 0.92);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.55);
  padding: 14px 14px 12px;
  position: relative;
  overflow: hidden;
  animation: panelGlow 3s ease-in-out infinite;
}

@keyframes panelGlow {
  0%, 100% { box-shadow: 0 30px 80px rgba(0, 0, 0, 0.55), 0 0 40px rgba(56, 189, 248, 0.06); }
  50%      { box-shadow: 0 30px 80px rgba(0, 0, 0, 0.55), 0 0 60px rgba(34, 197, 94, 0.1), 0 0 80px rgba(56, 189, 248, 0.08); }
}

.nnVizPanel::before {
  content: "";
  position: absolute;
  inset: -2px;
  background: radial-gradient(420px 220px at 20% 20%, rgba(56, 189, 248, 0.20), transparent 65%),
    radial-gradient(420px 220px at 80% 50%, rgba(34, 197, 94, 0.16), transparent 65%);
  pointer-events: none;
  opacity: 0.9;
  filter: blur(8px);
}
.nnVizHeader {
  position: relative;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}
.nnVizTitle {
  font-weight: 800;
  letter-spacing: -0.01em;
}
.nnVizSub {
  color: var(--muted);
  font-size: 13px;
}
.nnVizHint {
  position: relative;
  margin-top: 10px;
  color: rgba(154, 164, 178, 0.95);
  font-size: 12px;
}
#nnVizCanvas {
  position: relative;
  width: 100%;
  height: auto;
  display: block;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(0, 0, 0, 0.20);
}

/* ── Log section ────────────────────────────────────────────────────────── */

.log-wrap {
  position: relative;
  margin-top: 10px;
}

/* Bottom gradient fade when not scrolled to end */
.log-wrap::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 32px;
  background: linear-gradient(to bottom, transparent, rgba(0, 0, 0, 0.6));
  border-radius: 0 0 12px 12px;
  pointer-events: none;
  opacity: 1;
  transition: opacity 0.3s ease;
}

.log {
  margin: 0;
  max-height: 200px;
  overflow: auto;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  color: rgba(229, 231, 235, 0.92);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12.5px;
  line-height: 1.6;
  /* Alternating lines via background gradient stripes */
  background-image: repeating-linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0.015) 0px,
    rgba(255, 255, 255, 0.015) 20px,
    transparent 20px,
    transparent 40px
  );
  background-color: rgba(0, 0, 0, 0.35);
}

/* ── Grid layouts ───────────────────────────────────────────────────────── */

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

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

/* ── Metrics ────────────────────────────────────────────────────────────── */

.metricsGrid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 10px;
}
@media (max-width: 860px) {
  .metricsGrid {
    grid-template-columns: 1fr;
  }
}

.metricCard {
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: linear-gradient(135deg, rgba(17, 24, 39, 0.6), rgba(0, 0, 0, 0.3));
  padding: 14px;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.metricCard:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

.metricHead {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}
.metricTitle {
  font-weight: 700;
  color: var(--text);
}
.metricSub {
  color: var(--muted);
  font-size: 12px;
}
.metricRow {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
}
.metricPill {
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 12px;
  transition: background 0.2s ease;
}
.cmCanvas {
  width: 100%;
  height: auto;
  display: block;
  margin-top: 10px;
  border-radius: 10px;
}

/* ── Shot plots ─────────────────────────────────────────────────────────── */

.shot {
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.25);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.shot:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.shot img {
  width: 100%;
  height: auto;
  display: block;
}

.shot canvas {
  width: 100%;
  height: auto;
  display: block;
}

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

.summary {
  color: var(--muted);
  line-height: 1.65;
}

/* ── Footer ─────────────────────────────────────────────────────────────── */

.site-footer {
  margin-top: 48px;
  padding: 20px 0;
  text-align: center;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.02em;
}

.site-footer a {
  color: var(--accent2);
  text-decoration: none;
  transition: color 0.2s ease;
}

.site-footer a:hover {
  color: var(--accent);
  text-decoration: underline;
}

.lossCanvas { width: 100%; max-width: 600px; height: auto; aspect-ratio: 3/1; margin-bottom: 16px; }

/* Data quality widget */
.dq-wrap { display: flex; gap: 16px; align-items: center; padding: 14px 18px; border-radius: 14px; margin-bottom: 16px; }
.dq-wrap.dq-good { border: 1px solid rgba(34,197,94,0.2); background: rgba(34,197,94,0.05); }
.dq-wrap.dq-fair { border: 1px solid rgba(245,158,11,0.2); background: rgba(245,158,11,0.05); }
.dq-wrap.dq-bad { border: 1px solid rgba(239,68,68,0.2); background: rgba(239,68,68,0.05); }
.dq-score { font-size: 32px; font-weight: 700; min-width: 60px; text-align: center; }
.dq-good .dq-score, .dq-good .dq-label { color: #22c55e; }
.dq-fair .dq-score, .dq-fair .dq-label { color: #f59e0b; }
.dq-bad .dq-score, .dq-bad .dq-label { color: #ef4444; }
.dq-details { flex: 1; font-size: 13px; line-height: 1.6; color: var(--muted); }
.dq-label { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.dq-bar-row { display: flex; align-items: center; gap: 8px; margin-top: 2px; }
.dq-bar-label { min-width: 65px; }
.dq-bar-track { flex: 1; height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; }
.dq-bar-fill { width: var(--bar-pct, 0%); height: 100%; border-radius: 3px; }
.dq-bar-fill.dq-good { background: #22c55e; }
.dq-bar-fill.dq-fair { background: #f59e0b; }
.dq-bar-fill.dq-bad { background: #ef4444; }
.dq-bar-tip { font-size: 11px; opacity: 0.7; }
.dq-warning { margin-top: 10px; padding: 10px 12px; border: 1px solid rgba(251,191,36,0.3); background: rgba(251,191,36,0.08); border-radius: 12px; font-size: 13px; color: #fbbf24; line-height: 1.5; }
