* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, sans-serif;
  background: #10141a;
  color: #e6e9ef;
  display: flex;
  flex-direction: column;
  height: 100vh;
}

header {
  padding: 0.6rem 1.2rem;
  border-bottom: 1px solid #2a3140;
  display: flex;
  align-items: baseline;
  gap: 1rem;
}

header h1 { margin: 0; font-size: 1.3rem; color: #7dd3fc; }
header p { margin: 0; color: #9aa4b5; font-size: 0.9rem; }
code { color: #fbbf24; }

main {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(320px, 28%) 1fr;
  min-height: 0;
}

.input-pane {
  display: flex;
  flex-direction: column;
  border-right: 1px solid #2a3140;
  padding: 0.8rem;
  gap: 0.6rem;
  min-height: 0;
}

.line-list {
  flex: 1;
  overflow: auto;
  background: #171d26;
  border: 1px solid #2a3140;
  border-radius: 6px;
  padding: 0.4rem 0;
  font-family: Consolas, monospace;
  font-size: 0.8rem;
  min-height: 200px;
  outline: none;
}

.line {
  display: flex;
  gap: 0.6rem;
  padding: 0 0.6rem;
  white-space: pre;
  cursor: pointer;
  border-left: 2px solid transparent;
}

.line:hover { background: #1e2633; }

.line.selected {
  background: #1d3557;
  border-left-color: #22d3ee;
}

.ln {
  flex: none;
  width: 3ch;
  text-align: right;
  color: #4a5568;
  user-select: none;
}

.txt { color: #d7dde8; }

.tok {
  border-radius: 3px;
  padding: 0 1px;
  cursor: pointer;
  text-decoration: underline dotted transparent;
}

.tok-cable { color: #fbbf24; }
.tok-reg { color: #7dd3fc; }

.tok:hover {
  background: #0e7490;
  color: #f1faee;
  text-decoration-color: currentColor;
}

.tok-dead {
  color: #8a94a3;
  cursor: default;
}

.tok-dead:hover { background: transparent; color: #8a94a3; }

/* Mermaid renders inline, so ordinary page CSS reaches inside the SVG. */
#graph svg g.node.dg-selected rect,
#graph svg g.node.dg-selected polygon,
#graph svg g.node.dg-selected path {
  stroke: #0e7490;
  stroke-width: 3px;
}

#graph svg g.node { cursor: pointer; }
#graph svg .edgeLabel { cursor: pointer; }

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  font-size: 0.85rem;
}

button {
  background: #232b38;
  color: #e6e9ef;
  border: 1px solid #3b465a;
  border-radius: 6px;
  padding: 0.4rem 0.9rem;
  cursor: pointer;
  font-size: 0.85rem;
}

button:hover:not(:disabled) { background: #2e3949; }
button:disabled { opacity: 0.4; cursor: default; }
button.primary { background: #0e7490; border-color: #22d3ee; }
button.primary:hover { background: #0891b2; }

select {
  background: #171d26;
  color: #e6e9ef;
  border: 1px solid #3b465a;
  border-radius: 6px;
  padding: 0.35rem;
  max-width: 100%;
}

label.check { display: inline-flex; align-items: center; gap: 0.3rem; }

.stats {
  font-size: 0.8rem;
  color: #9aa4b5;
  background: #171d26;
  border-radius: 6px;
  padding: 0.4rem 0.6rem;
}

#state-panel {
  background: #171d26;
  border: 1px solid #2a3140;
  border-radius: 6px;
  padding: 0.5rem 0.6rem;
  font-size: 0.8rem;
  max-height: 40%;
  overflow: auto;
}

.state-head {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  color: #7dd3fc;
  font-weight: 600;
}

.state-head .check { margin-left: auto; font-weight: 400; color: #9aa4b5; }
.state-head button { padding: 0.15rem 0.5rem; font-size: 0.75rem; }

.state-hint {
  margin: 0.4rem 0 0.5rem;
  color: #6b7688;
  font-size: 0.72rem;
  line-height: 1.35;
}

.state-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.15rem 0;
}

.state-token {
  flex: 1;
  font-family: Consolas, monospace;
  color: #d7dde8;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.state-row select { min-width: 6rem; font-size: 0.78rem; }

details { font-size: 0.8rem; color: #fbbf24; }
details ul { max-height: 10rem; overflow: auto; margin: 0.3rem 0; padding-left: 1.2rem; }

.error {
  background: #7f1d1d;
  color: #fecaca;
  border-radius: 6px;
  padding: 0.5rem 0.7rem;
  font-size: 0.85rem;
}

.graph-pane {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

#graph-toolbar {
  position: absolute;
  top: 0.6rem;
  left: 0.6rem;
  z-index: 10;
  display: flex;
  gap: 0.3rem;
  align-items: center;
  background: rgba(23, 29, 38, 0.9);
  padding: 0.3rem;
  border-radius: 8px;
  border: 1px solid #2a3140;
}

#graph-toolbar .hint { color: #9aa4b5; font-size: 0.75rem; padding: 0 0.4rem; }

#viewport {
  flex: 1;
  overflow: hidden;
  background: #f8fafc;
  cursor: grab;
  touch-action: none;
}

#viewport:active { cursor: grabbing; }

#graph {
  transform-origin: 0 0;
  width: max-content;
}

.placeholder { color: #64748b; padding: 2rem; font-style: italic; }

#drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(14, 116, 144, 0.35);
  border: 3px dashed #22d3ee;
  pointer-events: none;
}

#drop-overlay p {
  background: #171d26;
  border: 1px solid #22d3ee;
  border-radius: 10px;
  padding: 1rem 2rem;
  font-size: 1.1rem;
  color: #e6e9ef;
}

#drop-overlay[hidden] { display: none; }
