.ngram-workspace {
  grid-template-columns: minmax(300px, 360px) minmax(520px, 1fr) minmax(320px, 390px);
  grid-template-areas:
    "controls probability generation"
    "note note generation"
    "graph graph generation";
  align-items: start;
}

.ngram-control-panel {
  grid-area: controls;
  display: grid;
  gap: 2px;
}

#ngram-training-text {
  min-height: 210px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.88rem;
}

#ngram-start-input {
  width: 100%;
  height: 42px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfa;
  color: var(--text);
}

#ngram-start-input:disabled {
  color: #8d9992;
  background: #edf2ef;
  cursor: not-allowed;
}

#ngram-sampling-select {
  padding-right: 28px;
}

.ngram-graph-note-panel {
  grid-area: note;
}

.ngram-workspace .ngram-probability-panel {
  grid-area: probability;
  min-height: 0;
}

.ngram-graph-panel,
.ngram-side-panel {
  min-height: 0;
}

.ngram-graph-panel {
  grid-area: graph;
}

.ngram-side-panel {
  grid-area: generation;
}

.ngram-graph-wrap {
  height: 520px;
  background: #fbfcfa;
}

.ngram-graph-note-content {
  margin: 0;
  padding: 14px;
  border-top: 1px solid var(--line);
  background: #fbfcfa;
}

.ngram-graph-note-content p {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

#ngram-graph {
  display: block;
  width: 100%;
  height: 100%;
}

.ngram-edge {
  fill: none;
  stroke: #7c8b83;
  stroke-linecap: round;
  opacity: 0.55;
}

.ngram-edge.active {
  stroke: var(--warm);
  opacity: 0.95;
}

.ngram-edge.candidate {
  stroke: var(--accent);
  opacity: 0.88;
}

.ngram-edge-label {
  fill: #536861;
  font-size: 0.72rem;
  font-weight: 750;
  paint-order: stroke;
  stroke: #fbfcfa;
  stroke-width: 4px;
  stroke-linejoin: round;
}

.ngram-node rect,
.ngram-node circle,
.ngram-node ellipse {
  fill: #ffffff;
  stroke: #aebdb5;
  stroke-width: 1.5;
}

.ngram-node.current rect,
.ngram-node.current circle,
.ngram-node.current ellipse {
  fill: var(--selected);
  stroke: var(--accent);
  stroke-width: 3;
}

.ngram-node.visited rect,
.ngram-node.visited circle,
.ngram-node.visited ellipse {
  stroke: var(--warm);
  stroke-width: 2.5;
}

.ngram-node.dead-end rect,
.ngram-node.dead-end circle,
.ngram-node.dead-end ellipse {
  stroke-dasharray: 5 4;
}

.ngram-node .ngram-node-end-ring,
.ngram-node.current .ngram-node-end-ring,
.ngram-node.visited .ngram-node-end-ring,
.ngram-node.dead-end .ngram-node-end-ring {
  fill: none;
  stroke: var(--warm);
  stroke-width: 1.6;
  stroke-dasharray: 5 4;
}

.ngram-node-label {
  fill: var(--text);
  font-size: 0.74rem;
  font-weight: 850;
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
}

.ngram-side-content {
  display: grid;
  gap: 14px;
  padding: 14px;
  background: #fbfcfa;
}

.ngram-generation-control-card,
.ngram-generated-card,
.ngram-current-card {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.ngram-generation-control-card .field {
  margin-bottom: 8px;
}

.ngram-generation-control-card .button-row {
  margin-bottom: 8px;
}

.ngram-generation-control-card .ngram-start-row {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

.ngram-generation-actions {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-bottom: 0;
}

.ngram-generation-actions .run-button {
  min-width: 0;
  padding: 0 10px;
  line-height: 1.15;
}

.ngram-card-label {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 850;
  text-transform: uppercase;
}

.ngram-output {
  min-height: 72px;
  margin: 0;
  color: var(--text);
  font-size: 1.04rem;
  line-height: 1.45;
}

#ngram-current-context {
  color: var(--accent-strong);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 1rem;
}

.ngram-candidates {
  display: grid;
  gap: 7px;
}

.ngram-candidate-row {
  display: grid;
  grid-template-columns: minmax(70px, 1fr) 56px;
  gap: 8px;
  align-items: center;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 750;
}

.ngram-candidate-bar {
  grid-column: 1 / -1;
  height: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: #e7eee9;
}

.ngram-candidate-fill {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}

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

.ngram-stats-grid div {
  display: grid;
  gap: 4px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.ngram-stats-grid span {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 850;
  text-transform: uppercase;
}

.ngram-stats-grid strong {
  color: var(--accent-strong);
  font-size: 1.12rem;
}

.ngram-table-wrap {
  max-height: 360px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.ngram-probability-panel .ngram-table-wrap {
  max-height: 260px;
}

.ngram-table {
  width: 100%;
  min-width: 520px;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.ngram-table caption {
  padding: 10px 12px;
  color: var(--accent-strong);
  font-weight: 850;
  text-align: left;
}

.ngram-table th,
.ngram-table td {
  padding: 8px 10px;
  border-top: 1px solid #e4ebe6;
  text-align: left;
  white-space: nowrap;
}

.ngram-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #eef3ef;
  color: var(--muted);
  font-size: 0.74rem;
  text-transform: uppercase;
}

.ngram-table td:first-child,
.ngram-table td:nth-child(2) {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.ngram-probability-row.current-context td {
  background: #fff7e9;
  box-shadow: inset 0 1px 0 #f2d6ad, inset 0 -1px 0 #f2d6ad;
}

.ngram-probability-row.current-context td:first-child {
  border-left: 5px solid var(--warm);
  color: var(--accent-strong);
  font-weight: 850;
}

@media (max-width: 1180px) {
  .ngram-workspace {
    grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
    grid-template-areas:
      "controls probability"
      "note note"
      "graph graph"
      "generation generation";
  }

  .ngram-graph-wrap {
    height: 500px;
  }
}

@media (max-width: 840px) {
  .ngram-workspace {
    grid-template-columns: 1fr;
    grid-template-areas:
      "controls"
      "note"
      "probability"
      "graph"
      "generation";
  }

  .ngram-generation-control-card .ngram-start-row,
  .ngram-generation-actions {
    grid-template-columns: 1fr;
  }

  .ngram-graph-wrap {
    height: 420px;
  }
}
