:root {
  --paper: #e7eef2;
  --card: #fbfcfd;
  --ink: #1a2a32;
  --muted: #5c727c;
  --line: #d3e0e6;
  --teal: #0f6e6a;
  --teal-dark: #0b4f4c;
  --rust: #c46b2f;
  --agent: #e25b32;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", "Helvetica Neue", sans-serif;
  font-size: 16px;
  line-height: 1.45;
  color: var(--ink);
  background:
    radial-gradient(1000px 420px at 8% -10%, #f8fbfd, transparent 55%),
    var(--paper);
}

button, input, select { font: inherit; color: inherit; }

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
}

.page {
  max-width: 1120px;
  margin: 0 auto;
  padding: 28px 22px 48px;
}

.eyebrow {
  margin: 0 0 6px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 12px;
  color: var(--teal);
}

h1, h2 {
  font-family: Georgia, "Iowan Old Style", Palatino, serif;
  font-weight: 560;
  letter-spacing: -0.03em;
}

h1 { margin: 0; font-size: 46px; }

h2 { margin: 22px 0 12px; font-size: 22px; }

.panel h2:first-child { margin-top: 0; }

.lede {
  max-width: 42rem;
  margin: 10px 0 0;
  color: var(--muted);
}

main {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(300px, 0.85fr);
  gap: 18px;
  margin-top: 22px;
  align-items: start;
}

.card {
  min-width: 0;
  background: var(--card);
  border-radius: 18px;
  padding: 18px;
  box-shadow: 0 10px 30px rgba(28, 52, 64, 0.06);
}

.board-wrap {
  position: relative;
  width: min(100%, 540px);
  margin: 0 auto;
}

.board {
  --gap: 8px;
  --pad: 8px;
  display: grid;
  grid-template-columns: repeat(var(--cols, 4), minmax(0, 1fr));
  gap: var(--gap);
  padding: var(--pad);
  background: #d5e3ea;
  border-radius: 20px;
}

.board-wrap.won .board { box-shadow: 0 0 0 3px #c5d36a; }
.board-wrap.lost .board { box-shadow: 0 0 0 3px #9bb0ba; }

.cell {
  position: relative;
  aspect-ratio: 1;
  border-radius: 14px;
  display: grid;
  place-items: center;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.45);
  overflow: hidden;
}

.cell.F,
.cell.S {
  background: linear-gradient(165deg, #f7fcff, #c5dfeb);
}

.cell.heat.F,
.cell.heat.S {
  background: linear-gradient(
    165deg,
    color-mix(in srgb, #f7fcff calc((1 - var(--heat)) * 100%), #ffe7a8),
    color-mix(in srgb, #c5dfeb calc((1 - var(--heat)) * 100%), #e7b15a)
  );
}

.cell.H {
  background: radial-gradient(circle at 50% 42%, #1c3344, #071018 72%);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}

.cell.H::before {
  content: "";
  width: 54%;
  height: 26%;
  border-radius: 50%;
  background: rgba(186, 220, 232, 0.16);
  position: absolute;
  top: 30%;
}

.cell.G {
  background: radial-gradient(circle at 50% 42%, #f7f6d4, #d7e48f 42%, #7ea34a);
}

.cell.current { box-shadow: inset 0 0 0 2px rgba(226, 91, 50, 0.9); }

.cell.spawn { box-shadow: inset 0 0 0 3px var(--rust); }

.brush {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 4px 0 10px;
}

.brush button {
  border: 1px solid var(--line);
  background: white;
  border-radius: 999px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 13px;
}

.brush button.selected {
  border-color: var(--teal);
  background: #e7f5f2;
  color: var(--teal-dark);
}

.brush button:disabled { cursor: not-allowed; color: #8aa0a8; }

.board[data-cols="8"] .cell { border-radius: 8px; }

.idx {
  position: absolute;
  top: 5px;
  left: 7px;
  font-size: 10px;
  color: rgba(20, 40, 50, 0.45);
}

.cell.H .idx { color: rgba(255, 255, 255, 0.5); }

.board[data-cols="8"] .idx { font-size: 8px; top: 3px; left: 4px; }

.mark {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: rgba(20, 50, 60, 0.62);
}

.cell.G .mark { color: #2c4a22; }

.arrow {
  position: absolute;
  left: 50%;
  bottom: 6px;
  transform: translateX(-50%);
  font-size: 18px;
  font-weight: 700;
  color: #1a3c46;
}

.cell.current .arrow { color: var(--rust); font-weight: 700; }

.board[data-cols="8"] .arrow { font-size: 13px; bottom: 2px; }

.cell.visited::after {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(178, 54, 28, 0.45);
  position: absolute;
  left: 8px;
  bottom: 8px;
}

.cell.H.visited::after { background: rgba(255, 255, 255, 0.6); }

.agent {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 2;
  display: grid;
  place-items: center;
  pointer-events: none;
  transition: transform 0.28s ease;
}

.agent::before {
  content: "";
  width: 46%;
  height: 46%;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffe7dc, var(--agent) 46%, #a33216 78%);
  box-shadow: 0 8px 14px rgba(90, 24, 8, 0.28);
}

.board-wrap[data-cols="8"] .agent::before { width: 38%; height: 38%; }

@media (prefers-reduced-motion: reduce) {
  .agent { transition: none; }
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  list-style: none;
  padding: 0;
  margin: 14px 0 8px;
  color: var(--muted);
  font-size: 13px;
}

.legend li { display: flex; align-items: center; gap: 6px; }

.swatch {
  width: 14px;
  height: 14px;
  border-radius: 4px;
  display: inline-block;
  box-shadow: inset 0 0 0 1px rgba(20, 50, 60, 0.18);
}

.swatch.start, .swatch.ice { background: linear-gradient(165deg, #f7fcff, #c5dfeb); }
.swatch.hole { background: #102029; }
.swatch.goal { background: #d5e38a; }
.swatch.agent { background: var(--agent); border-radius: 50%; }

.hint, .meta {
  margin: 6px 0;
  color: var(--muted);
  font-size: 13px;
}

.meta { min-height: 1.2em; }

.status { min-height: 3em; margin: 8px 0 12px; }

.play-row {
  display: flex;
  flex-wrap: wrap;
  gap: 16px 22px;
  align-items: center;
}

.dpad {
  display: grid;
  grid-template-columns: repeat(3, 48px);
  grid-template-rows: 48px 48px;
  gap: 6px;
}

.dpad button:nth-child(1) { grid-column: 2; grid-row: 1; }
.dpad button:nth-child(2) { grid-column: 1; grid-row: 2; }
.dpad button:nth-child(3) { grid-column: 2; grid-row: 2; }
.dpad button:nth-child(4) { grid-column: 3; grid-row: 2; }

.dpad button,
.secondary {
  border: 1px solid var(--line);
  background: white;
  border-radius: 10px;
  cursor: pointer;
}

.dpad button { font-size: 18px; }
.dpad button:hover, .secondary:hover { border-color: var(--teal); color: var(--teal-dark); }

.secondary:disabled, .dpad button:disabled {
  cursor: not-allowed;
  color: #8aa0a8;
}

.playback {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  flex: 1;
}

.secondary { padding: 8px 12px; }

.speed {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
}

#scrub { width: 100%; margin-top: 4px; flex-basis: 100%; }

.segmented {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
  padding: 4px;
  background: #e7eef1;
  border-radius: 12px;
}

.segmented label {
  position: relative;
  text-align: center;
  padding: 8px 6px;
  border-radius: 9px;
  cursor: pointer;
  font-size: 13px;
  line-height: 1.25;
  color: var(--muted);
}

.segmented input {
  position: absolute;
  opacity: 0;
  inset: 0;
  margin: 0;
  cursor: pointer;
}

.segmented label.selected {
  background: white;
  color: var(--teal-dark);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

.note { margin: 12px 0 8px; }

.formula {
  margin: 0 0 12px;
  padding: 8px 10px 10px;
  background: #f3f7f8;
  border-radius: 8px;
}

.equation {
  margin: 0 0 8px;
  font-family: Consolas, "Cascadia Mono", monospace;
  font-size: 13px;
  line-height: 1.45;
}

.symbols {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 3px 8px;
  margin: 0;
}

.symbols dt,
.symbols dd {
  margin: 0;
  font-size: 13px;
  line-height: 1.35;
}

.symbols dt {
  font-family: Consolas, "Cascadia Mono", monospace;
  font-weight: 650;
  color: var(--teal-dark);
}

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

.field {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin: 8px 0;
  font-size: 14px;
}

.field input,
.field select {
  width: 132px;
  padding: 7px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

.field input[type="checkbox"] { width: 18px; height: 18px; }

.reward-fields {
  margin: 12px 0 4px;
  padding: 8px 12px 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
}

.reward-fields legend {
  padding: 0 6px;
  font-size: 14px;
}

.reward-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 14px;
}

.reward-grid label.span { grid-column: 1 / -1; }

.reward-fields label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: 14px;
}

.reward-fields input {
  width: 84px;
  padding: 7px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

#dqn-fields { display: block; }
#dqn-fields[hidden] { display: none; }

.train-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.train-actions .primary { flex: 1.4; }
.train-actions .secondary { flex: 1; }

#episode-fields[hidden],
#one-episode[hidden] { display: none; }

button.primary {
  width: 100%;
  margin-top: 0;
  padding: 12px 16px;
  border: 0;
  border-radius: 12px;
  background: var(--teal);
  color: white;
  font-size: 15px;
  font-weight: 650;
  cursor: pointer;
}

button.primary:hover:not(:disabled) { background: var(--teal-dark); }

button.primary:disabled {
  background: #8aa8a6;
  cursor: wait;
}

.progress {
  height: 8px;
  margin-top: 12px;
  background: #e1ebef;
  border-radius: 99px;
  overflow: hidden;
}

.progress > div {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--teal), #1aa39a);
}

.message:empty { display: none; }

.message {
  margin-top: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  background: #fdecea;
  color: #8a2e24;
}

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

.stat {
  background: #f4f8f9;
  border-radius: 12px;
  padding: 10px;
}

.stat-label { margin: 0; color: var(--muted); font-size: 12px; }

.stat-value {
  margin: 2px 0 0;
  font-size: 22px;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}

.inspector {
  min-height: 4.4em;
  margin: 8px 0 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: #f3f7f8;
  font-family: Consolas, "Cascadia Mono", monospace;
  font-size: 12.5px;
}

.net-card { grid-column: 1 / -1; }
.net-card h2 { margin-top: 0; }
#net-card[hidden] { display: none; }

.net-view {
  overflow: auto;
  max-height: 560px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f7fbfb;
}

.net-svg { display: block; }

.net-matrices {
  display: grid;
  gap: 14px;
  margin-top: 14px;
}

.net-matrix-block h3 {
  margin: 0 0 4px;
  font-size: 15px;
}

.net-matrix-block p {
  margin: 0 0 8px;
}

.net-matrix {
  overflow: auto;
  max-height: 260px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: white;
}

.net-matrix table {
  border-collapse: separate;
  border-spacing: 0;
  font-family: Consolas, "Cascadia Mono", monospace;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.net-matrix th,
.net-matrix td {
  padding: 3px 6px;
  text-align: right;
  white-space: nowrap;
  border-bottom: 1px solid #eef3f5;
}

.net-matrix thead th {
  position: sticky;
  top: 0;
  background: #f7fbfb;
  z-index: 1;
  font-family: "Segoe UI", sans-serif;
  font-weight: 650;
}

.net-matrix .stub {
  position: sticky;
  left: 0;
  text-align: left;
  background: #f7fbfb;
  z-index: 1;
  font-family: "Segoe UI", sans-serif;
}

.net-matrix thead .stub { z-index: 2; }

.net-pos { color: var(--teal-dark); }
.net-neg { color: #a33b24; }
.net-zero { color: #9aadb4; }

.net-matrix tr.hot td { background: #e5f4f3; }
.net-matrix tr.hot .stub { background: #d5eeec; }

.qtable-card { grid-column: 1 / -1; }
.qtable-card h2 { margin-top: 0; }

.qtable-scroll {
  max-height: 640px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
}

.qtable {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
  font-size: 14px;
}

.qtable th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f4f8f9;
  text-align: right;
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 650;
  color: var(--muted);
  white-space: nowrap;
}

.qtable td {
  padding: 7px 12px;
  text-align: right;
  border-top: 1px solid #e6eef2;
  white-space: nowrap;
}

.qtable th:nth-child(-n + 2),
.qtable td:nth-child(-n + 2) { text-align: left; }

.qtable td.best {
  color: var(--teal-dark);
  font-weight: 700;
  background: #e7f5f2;
}

.qtable td.changed,
.qtable tr.selected td.changed,
.qtable tr.here td.changed {
  background: #f6d98a;
  color: #6a4a12;
  font-weight: 700;
}

.qtable td.changed.latest {
  outline: 2px solid #a33b24;
  outline-offset: -2px;
}

.qtable tr.selected td { background: #fff4ec; }
.qtable tr.selected td.best { background: #f6e4d6; }

.qtable tr.here td:first-child { box-shadow: inset 3px 0 0 var(--rust); }

.qtable td.empty {
  text-align: left;
  color: var(--muted);
}

.qtable tbody tr { cursor: pointer; }

.cell.picked { outline: 2px solid var(--teal); outline-offset: -5px; }

.chart-title { margin-bottom: 6px; }

.chart-card canvas {
  width: 100%;
  height: 150px;
  display: block;
}

footer {
  margin-top: 22px;
  color: var(--muted);
  font-size: 13px;
}

footer p { margin: 4px 0; }

@media (max-width: 900px) {
  main { grid-template-columns: 1fr; }
  h1 { font-size: 36px; }
  .page { padding: 20px 14px 36px; }
}
