:root {
  --bg: #07111f;
  --surface: rgba(14, 24, 44, 0.82);
  --surface-strong: #132340;
  --ink: #edf4ff;
  --muted: #93a7c6;
  --line: rgba(146, 182, 236, 0.14);
  --accent: #3d8bfd;
  --accent-soft: rgba(61, 139, 253, 0.16);
  --accent-strong: #90bfff;
  --gold: #f1b75a;
  --sky: #75a8ff;
  --rose: #ef8a7c;
  --shadow: 0 24px 70px rgba(2, 8, 22, 0.42);
  --radius-xl: 28px;
  --radius-lg: 20px;
  --radius-md: 14px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Manrope", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(61, 139, 253, 0.22), transparent 28%),
    radial-gradient(circle at top right, rgba(21, 74, 153, 0.28), transparent 30%),
    linear-gradient(180deg, #08111e 0%, #0d1830 52%, #091423 100%);
}

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

a {
  color: inherit;
  text-decoration: none;
}

h1,
h2,
h3 {
  font-family: "Fraunces", serif;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

.site-shell {
  max-width: 1380px;
  margin: 0 auto;
  padding: 24px;
}

.panel-flat {
  border: 1px solid var(--line);
  border-radius: 20px;
  background: rgba(13, 24, 45, 0.78);
  box-shadow: var(--shadow);
}

.top-banner {
  margin-bottom: 24px;
  padding: 8px 4px 20px;
  border-bottom: 1px solid var(--line);
}

body[data-page="home"] .top-banner,
body[data-page="home"] .home-single,
body[data-page="home"] .pager-nav {
  margin-left: auto;
  margin-right: auto;
  text-align: center;
}

.eyebrow {
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.75rem;
  font-weight: 800;
  color: var(--accent-strong);
}

h1 {
  font-size: clamp(2.2rem, 4vw, 4.3rem);
  line-height: 0.98;
  margin-bottom: 14px;
}

h2 {
  font-size: 1.35rem;
  line-height: 1.1;
  margin-bottom: 0;
}

.lead,
.helper-text,
.meaning-box p {
  color: var(--muted);
  line-height: 1.6;
}

.compact-lead {
  margin-bottom: 16px;
}

.chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 14px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-weight: 700;
}

.chip.subtle {
  background: rgba(146, 182, 236, 0.08);
  color: var(--muted);
}

.home-grid,
.home-single,
.phase-layout {
  display: grid;
  gap: 24px;
}

.home-single {
  max-width: 760px;
}

body[data-page="home"] .button-row {
  justify-content: center;
}

.phase-layout {
  grid-template-columns: minmax(300px, 380px) minmax(0, 1fr);
  align-items: start;
}

.tokenization-flow {
  display: grid;
  gap: 18px;
}

.phase-player {
  display: grid;
  gap: 18px;
}

.token-text-panel {
  padding: 20px 24px;
}

.shared-text-display {
  min-height: 88px;
  padding: 18px 20px;
  border-radius: 18px;
  border: 1px solid rgba(146, 182, 236, 0.12);
  background: rgba(7, 15, 29, 0.72);
  color: var(--ink);
  font-size: 1.08rem;
  line-height: 1.7;
}

.token-note {
  margin-top: 12px;
  margin-bottom: 0;
}

.control-card,
.sidebar-card,
.explanation-card,
.stage-card {
  padding: 24px;
}

.sidebar-card {
  position: sticky;
  top: 20px;
}

.panel-block + .panel-block {
  margin-top: 24px;
  padding-top: 24px;
  border-top: 1px solid var(--line);
}

.section-head {
  margin-bottom: 16px;
}

.field {
  display: grid;
  gap: 10px;
  margin-bottom: 16px;
}

.field.compact {
  margin-bottom: 14px;
}

.field span,
.field-head span {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 800;
}

.field-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

textarea,
select,
input[type="range"] {
  width: 100%;
}

textarea,
select {
  padding: 14px 16px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(146, 182, 236, 0.18);
  background: rgba(7, 15, 29, 0.92);
  color: var(--ink);
}

textarea {
  resize: vertical;
  min-height: 150px;
  line-height: 1.55;
}

input[type="range"] {
  accent-color: var(--accent);
}

.button-row,
.button-grid,
.speed-buttons,
.status-group,
.token-grid,
.generation-row,
.candidate-list,
.legend-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

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

.button,
.speed-button,
.pager-link {
  border-radius: 999px;
  transition:
    transform 150ms ease,
    background-color 150ms ease,
    border-color 150ms ease;
}

.button,
.speed-button {
  appearance: none;
  border: 1px solid transparent;
  cursor: pointer;
  padding: 11px 16px;
  font-weight: 700;
}

.button:hover,
.speed-button:hover,
.pager-link:hover {
  transform: translateY(-1px);
}

.primary {
  background: var(--accent);
  color: white;
}

.secondary,
.speed-button,
.pager-link {
  background: rgba(17, 28, 51, 0.94);
  border: 1px solid rgba(146, 182, 236, 0.14);
  color: var(--ink);
}

.speed-button.active {
  background: var(--accent-soft);
  border-color: rgba(15, 135, 120, 0.28);
  color: var(--accent-strong);
}

.tip-box,
.meaning-box,
.empty-state,
.stats-grid .stat,
.metric,
.weight-item {
  border-radius: 18px;
  background: rgba(17, 29, 52, 0.95);
  border: 1px solid rgba(146, 182, 236, 0.12);
}

.tip-box,
.meaning-box {
  padding: 16px 18px;
}

.main-stack {
  display: grid;
  gap: 18px;
}

.bottom-controls {
  margin-top: 18px;
  padding: 18px 20px;
}

.bottom-info {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 14px;
}

.bottom-copy {
  max-width: 720px;
}

.bottom-explanation {
  margin-bottom: 0;
}

.controls-row,
.speed-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}

.speed-row {
  margin-top: 14px;
}

.controls-label {
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 800;
}

.generation-controls {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-top: 16px;
  align-items: end;
}

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

.summary-stat,
.summary-note {
  padding: 14px;
  border-radius: 16px;
  border: 1px solid rgba(146, 182, 236, 0.12);
  background: rgba(11, 21, 40, 0.95);
}

.summary-notes {
  display: grid;
  gap: 12px;
}

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

.generation-field {
  margin-bottom: 0;
}

.generation-toggle {
  align-self: center;
  justify-content: center;
  min-height: 52px;
  padding: 0 8px;
}

.status-row,
.stage-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 20px;
}

.progress-bar {
  width: 100%;
  height: 10px;
  border-radius: 999px;
  background: rgba(146, 182, 236, 0.12);
  overflow: hidden;
}

.progress-fill {
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--gold));
  transition: width 160ms ease;
}

.phase-canvas {
  margin-top: 18px;
  min-height: 620px;
  padding: 20px;
  border-radius: 24px;
  background: linear-gradient(180deg, rgba(10, 19, 36, 0.96), rgba(12, 23, 43, 0.96));
  border: 1px solid rgba(146, 182, 236, 0.12);
}

.canvas-stack {
  display: grid;
  gap: 18px;
}

.metric-grid,
.stats-grid,
.weight-grid {
  display: grid;
  gap: 12px;
}

.metric-grid,
.stats-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.weight-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.metric,
.stats-grid .stat,
.weight-item {
  padding: 14px;
}

.label {
  display: block;
  margin-bottom: 8px;
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 800;
}

.value {
  font-size: 1rem;
  font-weight: 800;
}

.visual-card {
  padding: 18px;
  border-radius: 22px;
  background: rgba(17, 29, 52, 0.78);
  border: 1px solid rgba(146, 182, 236, 0.12);
}

.is-muted {
  opacity: 0.45;
  filter: saturate(0.6);
}

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

.training-step {
  padding: 14px;
  border-radius: 16px;
  border: 1px solid rgba(146, 182, 236, 0.12);
  background: rgba(11, 21, 40, 0.92);
}

.training-step strong {
  display: block;
  margin-bottom: 8px;
}

.training-step span {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.training-step.active {
  background: rgba(61, 139, 253, 0.12);
  border-color: rgba(61, 139, 253, 0.3);
  opacity: 1;
  filter: none;
}

.training-step.seen {
  border-color: rgba(146, 182, 236, 0.22);
  opacity: 0.78;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.original-text {
  padding: 18px;
  border-radius: 18px;
  background: rgba(61, 139, 253, 0.08);
  line-height: 1.7;
}

.source-part,
.token-card,
.candidate-item,
.legend-chip {
  border-radius: 16px;
  border: 1px solid rgba(146, 182, 236, 0.12);
  background: rgba(11, 21, 40, 0.95);
}

.source-part {
  display: inline-block;
  padding: 8px 10px;
  margin: 0 6px 6px 0;
}

.source-part.active {
  background: rgba(119, 151, 255, 0.18);
  border-color: rgba(119, 151, 255, 0.32);
}

.token-card {
  min-width: 86px;
  padding: 14px 12px;
}

.token-card.active {
  background: rgba(15, 135, 120, 0.1);
  border-color: rgba(15, 135, 120, 0.32);
}

.token-card.context {
  background: rgba(119, 151, 255, 0.1);
}

.token-card.generated {
  background: rgba(221, 160, 62, 0.14);
}

.vocab-table {
  width: 100%;
  border-collapse: collapse;
}

.vocab-table th,
.vocab-table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid rgba(146, 182, 236, 0.1);
}

.vocab-table th {
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.network-board {
  position: relative;
  min-height: 340px;
  border-radius: 22px;
  overflow: hidden;
  background: linear-gradient(180deg, rgba(14, 26, 49, 0.94), rgba(11, 20, 38, 0.98));
}

.network-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.connection {
  stroke: rgba(146, 182, 236, 0.2);
  stroke-width: 2;
}

.connection.forward {
  stroke: rgba(15, 135, 120, 0.8);
  stroke-width: 4;
}

.connection.backward {
  stroke: rgba(207, 117, 95, 0.82);
  stroke-width: 4;
}

.node-layer {
  position: absolute;
  top: 26px;
  bottom: 26px;
  width: 140px;
  display: flex;
  flex-direction: column;
  justify-content: space-evenly;
  align-items: center;
}

.node-layer.input {
  left: 44px;
}

.node-layer.hidden {
  left: calc(50% - 70px);
}

.node-layer.output {
  right: 44px;
}

.node {
  width: 86px;
  height: 86px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 8px;
  border: 2px solid rgba(146, 182, 236, 0.14);
  background: rgba(11, 21, 40, 0.95);
}

.node.active {
  background: rgba(15, 135, 120, 0.12);
  border-color: rgba(15, 135, 120, 0.34);
}

.node.expected {
  background: rgba(221, 160, 62, 0.16);
  border-color: rgba(221, 160, 62, 0.36);
}

.node.predicted {
  background: rgba(119, 151, 255, 0.16);
  border-color: rgba(119, 151, 255, 0.34);
}

.node-label {
  display: block;
  font-size: 0.72rem;
  color: var(--muted);
}

.node-value {
  display: block;
  margin-top: 4px;
  font-weight: 800;
}

.candidate-item {
  flex: 1 1 180px;
  padding: 14px;
}

.candidate-item.active {
  background: rgba(15, 135, 120, 0.1);
  border-color: rgba(15, 135, 120, 0.34);
}

.candidate-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.candidate-subtext {
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.45;
}

.candidate-bar {
  height: 10px;
  border-radius: 999px;
  background: rgba(146, 182, 236, 0.1);
  overflow: hidden;
}

.candidate-bar span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--sky), var(--accent));
}

.markov-flow {
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr);
  gap: 16px;
  align-items: center;
}

.markov-arrow {
  color: var(--accent-strong);
  font-size: 1.4rem;
  font-weight: 800;
}

.markov-targets {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.markov-node,
.markov-empty {
  min-width: 150px;
  padding: 14px 16px;
  border-radius: 16px;
  border: 1px solid rgba(146, 182, 236, 0.12);
  background: rgba(11, 21, 40, 0.95);
}

.markov-node strong {
  display: block;
  margin-bottom: 6px;
}

.markov-node span {
  color: var(--muted);
  font-size: 0.86rem;
}

.markov-node.current {
  min-width: 170px;
  background: rgba(61, 139, 253, 0.12);
  border-color: rgba(61, 139, 253, 0.26);
}

.markov-node.chosen {
  background: rgba(61, 139, 253, 0.12);
  border-color: rgba(61, 139, 253, 0.3);
}

.markov-empty {
  color: var(--muted);
  line-height: 1.5;
}

.legend-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
}

.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
}

.empty-state {
  min-height: 520px;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 32px;
  color: var(--muted);
}

.pager-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 24px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.pager-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 190px;
  padding: 12px 18px;
  font-weight: 700;
}

.pager-link.disabled {
  opacity: 0.45;
}

@media (max-width: 1100px) {
  .home-grid,
  .home-single,
  .phase-layout {
    grid-template-columns: 1fr;
  }

  .sidebar-card {
    position: static;
  }
}

@media (max-width: 820px) {
  .site-shell {
    padding: 18px;
  }

  .controls-row,
  .speed-row {
    justify-content: stretch;
  }

  .pager-nav {
    flex-direction: column;
    align-items: stretch;
  }

  .status-row,
  .stage-head,
  .bottom-info {
    flex-direction: column;
  }

  .metric-grid,
  .stats-grid,
  .weight-grid,
  .generation-controls,
  .summary-grid {
    grid-template-columns: 1fr;
  }

  .training-flow {
    grid-template-columns: 1fr;
  }

  .markov-flow {
    grid-template-columns: 1fr;
  }

  .node-layer {
    width: 100px;
  }

  .node-layer.input {
    left: 12px;
  }

  .node-layer.hidden {
    left: calc(50% - 50px);
  }

  .node-layer.output {
    right: 12px;
  }

  .node {
    width: 64px;
    height: 64px;
    font-size: 0.84rem;
  }
}
