/* ── Variables & base ───────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --navy:        #1a1a2e;
  --red:         #c4162a;
  --blue:        #0f3460;
  --gold:        #f5a623;
  --green:       #27ae60;
  --bg:          #f7f6f3;
  --white:       #ffffff;
  --border:      #ddd;
  --text:        #222;
  --muted:       #666;
  --radius:      8px;
  --shadow:      0 2px 12px rgba(0,0,0,0.10);
  --panel-w:     300px;
  --rail-w:      180px;
  --controls-h:  56px;
  --header-h:    48px;
}

html { font-size: 16px; }
body {
  font-family: Georgia, 'Times New Roman', serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

a { color: var(--blue); }
button { cursor: pointer; font-family: inherit; }

/* ── Header ─────────────────────────────────────────────────────────────────── */
header {
  background: var(--navy);
  color: #fff;
  height: var(--header-h);
  padding: 0 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  z-index: 20;
}
.header-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
header h1 {
  font-size: 1.2rem;
  font-weight: normal;
  letter-spacing: 0.02em;
  white-space: nowrap;
  line-height: 1;
}
header h1 span { color: var(--gold); }

.byline {
  font-size: 0.78rem;
  font-family: sans-serif;
  color: #aaa;
  line-height: 1;
  margin: 0;
}
.byline a { color: #ddd; text-decoration: none; }
.byline a:hover { text-decoration: underline; }

.icon-btn {
  background: none;
  border: none;
  color: #fff;
  font-size: 1.2rem;
  padding: 4px 6px;
  border-radius: 4px;
  line-height: 1;
  transition: background 0.15s;
}
.icon-btn:hover { background: rgba(255,255,255,0.15); }

.ctrl-settings-btn { color: var(--navy); font-size: 1rem; }
.ctrl-settings-btn:hover { background: rgba(0,0,0,0.06); }

.ctrl-divider {
  width: 1px;
  height: 1.5rem;
  background: var(--border);
  flex-shrink: 0;
}

.ctrl-tour-link {
  margin-left: auto;
  font-family: sans-serif;
  font-size: 0.82rem;
  color: var(--blue);
  text-decoration: none;
  white-space: nowrap;
  padding-right: 0.25rem;
}
.ctrl-tour-link:hover { text-decoration: underline; }

/* ── Explainer ───────────────────────────────────────────────────────────────── */
#explainer {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1.5rem;
  overflow-y: auto;
}

.slide-card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 2rem 2.5rem 1.75rem;
  max-width: 680px;
  width: 100%;
  position: relative;
}

.skip-btn {
  position: absolute;
  top: 1rem;
  right: 1.25rem;
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.78rem;
  font-family: sans-serif;
  color: var(--muted);
  padding: 3px 8px;
}
.skip-btn:hover { background: var(--bg); color: var(--text); }

.slide-card h2 {
  font-size: 1.45rem;
  color: var(--navy);
  margin-bottom: 0.6rem;
}
.slide-card p {
  font-size: 0.97rem;
  line-height: 1.7;
  color: var(--text);
  margin-bottom: 1rem;
}

#slide-viz {
  margin: 1rem 0;
  min-height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
}
#slide-viz svg { max-width: 100%; overflow: visible; }

.slide-nav {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 1.25rem;
}
.slide-nav button {
  background: var(--navy);
  color: #fff;
  border: none;
  border-radius: 5px;
  padding: 0.45rem 1.1rem;
  font-size: 0.9rem;
  font-family: sans-serif;
}
.slide-nav button:hover { background: var(--blue); }
.slide-nav #btn-prev { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.slide-nav #btn-prev:hover { background: #eee; }

.dots {
  display: flex;
  gap: 6px;
  margin-left: auto;
}
.dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--border);
  transition: background 0.2s;
}
.dot.active { background: var(--navy); }

/* ── App shell ───────────────────────────────────────────────────────────────── */
#app {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#app.hidden { display: none; }

/* ── Settings panel ──────────────────────────────────────────────────────────── */
#settings-panel {
  position: fixed;
  top: var(--header-h);
  left: 0;
  width: var(--panel-w);
  bottom: 0;
  background: var(--white);
  border-right: 1px solid var(--border);
  box-shadow: 2px 0 12px rgba(0,0,0,0.08);
  z-index: 15;
  transform: translateX(-100%);
  transition: transform 0.25s ease;
  overflow-y: auto;
}
#settings-panel.open { transform: translateX(0); }

.panel-inner {
  padding: 1.25rem 1.25rem 2rem;
}
.panel-inner h2 {
  font-size: 0.85rem;
  font-family: sans-serif;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 1.1rem 0 0.6rem;
  padding-bottom: 0.35rem;
  border-bottom: 1px solid var(--border);
}
.panel-inner h2:first-child { margin-top: 0; }

.field-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.55rem;
}
.field-row label {
  font-size: 0.88rem;
  font-family: sans-serif;
  color: var(--text);
}
.field-row input {
  width: 80px;
  padding: 4px 6px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.88rem;
  font-family: sans-serif;
  text-align: right;
}
.field-row input:focus { outline: 2px solid var(--blue); }

#nodes-per-layer {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 0.75rem;
}
#nodes-per-layer select {
  font-size: 0.85rem;
  font-family: sans-serif;
  padding: 3px 5px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
}

/* Data table */
#data-table-wrap {
  overflow-x: auto;
  margin-bottom: 0.5rem;
}
#data-table-wrap table {
  border-collapse: collapse;
  font-size: 0.82rem;
  font-family: sans-serif;
  width: 100%;
}
#data-table-wrap th {
  background: var(--navy);
  color: #fff;
  padding: 4px 8px;
  text-align: center;
  font-weight: 600;
  white-space: nowrap;
  font-size: 0.78rem;
}
#data-table-wrap th.input-col  { background: var(--blue); }
#data-table-wrap th.output-col { background: #5a2d82; }
#data-table-wrap td {
  border: 1px solid var(--border);
  padding: 2px;
}
#data-table-wrap td input {
  width: 100%;
  border: none;
  padding: 3px 6px;
  font-size: 0.82rem;
  font-family: sans-serif;
  text-align: center;
  background: transparent;
}
#data-table-wrap td input:focus { background: #fffde7; outline: none; }
#data-table-wrap tr:nth-child(even) td { background: #f9f9f9; }

.table-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 1rem;
}
.table-controls button {
  font-size: 0.75rem;
  font-family: sans-serif;
  padding: 3px 7px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
  color: var(--text);
}
.table-controls button:hover { background: #e8e8e8; }

.btn-pair {
  display: flex;
  gap: 8px;
  margin-bottom: 0.5rem;
}
.half-btn {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  padding: 0.4rem;
  background: var(--bg);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.82rem;
  font-family: sans-serif;
  line-height: 1.4;
  text-align: center;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.half-btn:hover { background: #e8e8e8; color: var(--text); }

.build-btn {
  width: 100%;
  padding: 0.6rem;
  background: var(--red);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-family: sans-serif;
  font-weight: 600;
  letter-spacing: 0.02em;
  margin-top: 0.25rem;
  transition: background 0.15s;
}
.build-btn:hover { background: #aa1a00; }

/* ── Main content ────────────────────────────────────────────────────────────── */
#main-content {
  flex: 1;
  display: flex;
  overflow: hidden;
  /* bottom padding for controls bar */
  padding-bottom: var(--controls-h);
}

/* Canvas wrap */
#canvas-wrap {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: var(--bg);
}

#canvas-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2rem;
  color: var(--muted);
  font-size: 1rem;
  pointer-events: none;
}
#canvas-placeholder p { max-width: 320px; line-height: 1.6; }
#canvas-placeholder strong { color: var(--red); }
#canvas-placeholder.hidden { display: none; }

#nn-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* Node tooltip */
#node-tooltip {
  display: none;
  position: fixed;
  background: var(--navy);
  color: #fff;
  font-family: sans-serif;
  font-size: 0.8rem;
  padding: 8px 12px;
  border-radius: 6px;
  pointer-events: none;
  z-index: 50;
  line-height: 1.7;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

/* ── Progress rail ───────────────────────────────────────────────────────────── */
#progress-rail {
  width: var(--rail-w);
  flex-shrink: 0;
  background: var(--white);
  border-left: 1px solid var(--border);
  padding: 1rem 0.75rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0;
}
#progress-rail.hidden { display: none; }
#progress-rail h3 {
  font-size: 0.8rem;
  font-family: sans-serif;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--navy);
  margin-bottom: 0.1rem;
}
.progress-sub {
  font-family: sans-serif;
  font-size: 0.72rem;
  color: var(--muted);
  margin-bottom: 0.75rem;
}

.progress-item {
  margin-bottom: 0.6rem;
}
.progress-item .ex-label {
  font-family: sans-serif;
  font-size: 0.72rem;
  color: var(--muted);
  margin-bottom: 2px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.progress-item.active-example .ex-label {
  font-weight: 700;
  color: var(--text);
}
.ex-swatch {
  width: 10px; height: 10px;
  border-radius: 2px;
  flex-shrink: 0;
}
.progress-track {
  height: 10px;
  background: #eee;
  border-radius: 5px;
  overflow: hidden;
  position: relative;
}
.progress-fill {
  height: 100%;
  width: 0%;
  border-radius: 5px;
  transition: width 0.4s ease;
}

#epoch-counter {
  margin-top: auto;
  padding-top: 0.75rem;
  font-family: sans-serif;
  font-size: 0.75rem;
  color: var(--muted);
  text-align: center;
  border-top: 1px solid var(--border);
}

/* ── Controls bar ────────────────────────────────────────────────────────────── */
#controls-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--controls-h);
  background: var(--white);
  border-top: 1px solid var(--border);
  box-shadow: 0 -2px 10px rgba(0,0,0,0.06);
  z-index: 20;
  display: flex;
  align-items: center;
}
#controls-bar.hidden { display: none; }

.controls-inner {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0 1.25rem;
  flex-wrap: wrap;
}
.ctrl-label {
  font-family: sans-serif;
  font-size: 0.82rem;
  color: var(--muted);
  white-space: nowrap;
}
.radio-group {
  display: flex;
  gap: 0.6rem;
}
.radio-group label {
  font-family: sans-serif;
  font-size: 0.82rem;
  display: flex;
  align-items: center;
  gap: 3px;
  cursor: pointer;
  white-space: nowrap;
}
#step-count {
  width: 58px;
  padding: 4px 6px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.88rem;
  font-family: sans-serif;
  text-align: center;
}
.run-btn {
  padding: 0.4rem 1.4rem;
  background: var(--red);
  color: #fff;
  border: none;
  border-radius: 5px;
  font-size: 0.9rem;
  font-family: sans-serif;
  font-weight: 600;
  transition: background 0.15s;
}
.run-btn:hover:not(:disabled) { background: #aa1a00; }
.run-btn:disabled { opacity: 0.5; cursor: default; }

#training-status {
  font-family: sans-serif;
  font-size: 0.8rem;
  color: var(--muted);
  font-style: italic;
}

/* ── Tour bubble ─────────────────────────────────────────────────────────────── */
#tour-bubble {
  position: fixed;
  background: var(--navy);
  color: #fff;
  border-radius: 8px;
  padding: 1rem 1.25rem 0.85rem;
  max-width: 300px;
  width: 280px;
  z-index: 200;
  box-shadow: 0 4px 20px rgba(0,0,0,0.35);
  font-family: sans-serif;
  font-size: 0.85rem;
  line-height: 1.55;
}
#tour-bubble.hidden { display: none; }

.tour-close {
  position: absolute;
  top: 0.4rem;
  right: 0.6rem;
  background: none;
  border: none;
  color: #aaa;
  font-size: 1.1rem;
  line-height: 1;
  padding: 2px 4px;
}
.tour-close:hover { color: #fff; }

#tour-text {
  margin: 0.1rem 0 0.75rem;
  font-size: 0.85rem;
  line-height: 1.6;
}
#tour-text a { color: var(--gold); }

.tour-nav {
  display: flex;
  gap: 0.5rem;
}
.tour-nav button {
  font-size: 0.78rem;
  font-family: sans-serif;
  padding: 4px 10px;
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 4px;
  background: rgba(255,255,255,0.1);
  color: #fff;
}
.tour-nav button:hover { background: rgba(255,255,255,0.2); }

/* Pulsing highlight ring drawn on canvas — handled in JS */

/* ── Utility ─────────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
