* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg: #0a0a0a;
  --bg-panel: #111;
  --border: #1a1a1a;
  --text: #ccc;
  --text-dim: #666;
  --text-muted: #444;

  --teal: #7dd3c0;
  --lavender: #c4b5fd;
  --coral: #fca5a5;
  --amber: #fde68a;
  --sky: #93c5fd;
  --mint: #86efac;
  --rose: #fda4af;
  --percolating: #4ade80;

  --font: ui-monospace, "SF Mono", Monaco, "Cascadia Code", monospace;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font);
  font-size: 12px;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

/* layout: grid fills space, panel on right */
.app {
  display: flex;
  height: 100vh;
  width: 100vw;
}

/* main grid view */
.grid-view {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  min-width: 0;
}

.grid-view canvas {
  width: min(calc(100vw - 320px - 2rem), calc(100vh - 2rem));
  height: min(calc(100vw - 320px - 2rem), calc(100vh - 2rem));
  max-width: 800px;
  max-height: 800px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

/* side panel */
.panel {
  width: 300px;
  flex-shrink: 0;
  background: var(--bg-panel);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 1.5rem;
  gap: 1.5rem;
  overflow-y: auto;
}

/* header */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

h1 {
  font-size: 16px;
  font-weight: normal;
  letter-spacing: 0.05em;
}

.status {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 11px;
  color: var(--text-dim);
}

.indicator {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
}

.indicator.connected {
  background: var(--percolating);
  box-shadow: 0 0 6px var(--percolating);
}

.indicator.error {
  background: var(--coral);
  box-shadow: 0 0 6px var(--coral);
}

/* info section */
.info {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.description {
  font-size: 11px;
  color: var(--text-dim);
  line-height: 1.6;
}

.description strong {
  color: var(--percolating);
}

/* density meter */
.density-meter {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.density-bar {
  height: 8px;
  background: var(--bg);
  border-radius: 4px;
  position: relative;
  overflow: hidden;
}

.density-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--teal), var(--percolating));
  border-radius: 4px;
  transition: width 0.3s ease;
}

.density-critical {
  position: absolute;
  left: 59%;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--percolating);
  opacity: 0.7;
}

.density-labels {
  display: flex;
  justify-content: space-between;
  font-size: 9px;
  color: var(--text-muted);
}

.critical-label {
  color: var(--percolating);
  position: relative;
  left: 9%;
}

/* scaling curve */
.scaling-curve {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.scaling-curve canvas {
  width: 100%;
  height: 80px;
  background: var(--bg);
  border-radius: 4px;
}

.scaling-label {
  font-size: 9px;
  color: var(--text-dim);
  text-align: center;
}

.scaling-label span span {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

/* big stats row */
.status-row {
  display: flex;
  gap: 1rem;
}

.big-stat {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.75rem;
  background: var(--bg);
  border-radius: 4px;
}

.big-value {
  font-size: 20px;
  font-weight: 500;
  color: var(--text);
}

.big-value.yes {
  color: var(--percolating);
  text-shadow: 0 0 10px var(--percolating);
}

.big-value.no {
  color: var(--text-dim);
}

.big-label {
  font-size: 9px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* mini stats */
.mini-stats {
  display: flex;
  justify-content: space-between;
}

.mini-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.1rem;
}

.mini-value {
  font-size: 14px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.mini-label {
  font-size: 9px;
  color: var(--text-muted);
}

/* mini grids */
.mini-grids {
  display: flex;
  gap: 1rem;
  margin-top: auto;
}

.mini-grid {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
}

.mini-grid canvas {
  width: 100%;
  aspect-ratio: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 2px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.mini-grid span {
  font-size: 9px;
  color: var(--text-muted);
}

/* footer */
footer {
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  text-align: center;
}

footer a {
  font-size: 10px;
  color: var(--text-dim);
  text-decoration: none;
}

footer a:hover {
  color: var(--text);
}

/* mobile: stack vertically */
@media (max-width: 768px) {
  .app {
    flex-direction: column;
  }

  .grid-view {
    flex: none;
    height: 50vh;
    padding: 0.5rem;
  }

  .grid-view canvas {
    width: min(calc(100vw - 1rem), calc(50vh - 1rem));
    height: min(calc(100vw - 1rem), calc(50vh - 1rem));
  }

  .panel {
    width: 100%;
    border-left: none;
    border-top: 1px solid var(--border);
    padding: 1rem;
    gap: 1rem;
    flex: 1;
    overflow-y: auto;
  }

  .description {
    font-size: 10px;
  }

  .mini-grids {
    margin-top: 0;
  }

  .mini-grid canvas {
    max-width: 100px;
  }
}

/* very small screens */
@media (max-width: 400px) {
  .status-row {
    flex-direction: column;
    gap: 0.5rem;
  }

  .mini-stats {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .mini-stat {
    flex: 1 0 30%;
  }
}
