/* ppotiny-web styles */
:root {
  --bg: #0e1014;
  --bg-elev: #15181f;
  --bg-elev2: #1c2029;
  --border: #2a2f3a;
  --border-strong: #3b414f;
  --text: #e6e8ee;
  --text-dim: #9aa0ad;
  --text-faint: #6b7180;
  --accent: #5eead4;
  --accent-soft: rgba(94, 234, 212, 0.14);
  --accent-strong: #2dd4bf;
  --good: #5eead4;
  --warn: #fbbf24;
  --bad: #f87171;
  --snake: #5eead4;
  --snake-head: #f5f7fa;
  --food: #f87171;
  --grid: #1d2129;
  --shadow: 0 12px 40px rgba(0,0,0,0.5);
}
:root.light {
  --bg: #f7f8fa;
  --bg-elev: #ffffff;
  --bg-elev2: #f0f2f5;
  --border: #e2e5eb;
  --border-strong: #c8ccd4;
  --text: #181c24;
  --text-dim: #4a5260;
  --text-faint: #8b909c;
  --accent: #0d9488;
  --accent-soft: rgba(13, 148, 136, 0.10);
  --accent-strong: #0f766e;
  --good: #0d9488;
  --warn: #d97706;
  --bad: #dc2626;
  --snake: #0d9488;
  --snake-head: #1f2937;
  --food: #dc2626;
  --grid: #e6e9ef;
  --shadow: 0 6px 24px rgba(0,0,0,0.06);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
code, pre, .mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }

/* Header */
header.app-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elev);
  position: sticky; top: 0; z-index: 10;
}
header .brand { display: flex; align-items: center; gap: 12px; }
header .brand-mark {
  width: 28px; height: 28px;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  border-radius: 7px;
  display: grid; place-items: center;
  color: #0a0c10; font-weight: 700; font-size: 14px;
}
header .title { font-size: 15px; font-weight: 600; letter-spacing: -0.01em; }
header .subtitle { font-size: 12px; color: var(--text-dim); margin-left: 4px; }
header nav { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }

/* Buttons */
.btn {
  background: var(--bg-elev2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 7px 13px;
  border-radius: 7px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
  display: inline-flex; align-items: center; gap: 6px;
}
.btn:hover { background: var(--border); border-color: var(--border-strong); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary {
  background: var(--accent); color: #0a0c10; border-color: var(--accent);
  font-weight: 600;
}
.btn.primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: var(--bg-elev2); }
.btn .ic { width: 14px; height: 14px; opacity: 0.8; }

/* Theme toggle: show the icon for the mode you'd switch INTO.
   Dark mode (default) → show sun (click = go light).
   Light mode (:root.light) → show moon (click = go dark). */
#themeToggle { padding: 7px 10px; }
#themeToggle .icon-moon { display: none; }
:root.light #themeToggle .icon-sun { display: none; }
:root.light #themeToggle .icon-moon { display: inline; }

/* Layout */
main {
  max-width: 1280px; margin: 0 auto;
  padding: 24px;
  display: grid; gap: 20px;
  grid-template-columns: minmax(360px, 460px) minmax(420px, 1fr);
  align-items: start;
}
@media (max-width: 900px) {
  main { grid-template-columns: 1fr; }
}

/* Card */
.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  box-shadow: var(--shadow);
}
.card h2 {
  margin: 0 0 14px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-dim);
}
.card .h2-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.card .h2-row h2 { margin: 0; }

/* Snake */
#canvas-wrap {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
}
canvas#canvas {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  display: block;
  width: 360px; height: 360px;
  image-rendering: optimizeQuality;
}
.snake-meta {
  display: flex; gap: 10px; font-size: 11px; color: var(--text-faint);
  margin-top: 6px;
}
.snake-meta span b { color: var(--text); font-weight: 600; }

/* Stats grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px 16px;
  margin-top: 12px;
}
.stat {
  display: flex; flex-direction: column;
  padding: 10px 12px;
  background: var(--bg-elev2);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.stat .label {
  font-size: 11px;
  color: var(--text-faint);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.stat .value {
  font-size: 18px; font-weight: 600;
  font-family: ui-monospace, Menlo, monospace;
  margin-top: 2px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.stat .value.dim { color: var(--text-dim); font-weight: 500; font-size: 16px; }
.stat .sub { font-size: 11px; color: var(--text-faint); margin-top: 2px; }

/* Status indicator */
.status-pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 4px 10px; border-radius: 999px;
  background: var(--bg-elev2);
  border: 1px solid var(--border);
  font-size: 12px; color: var(--text-dim);
}
.status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--text-faint);
}
.status-dot.idle { background: var(--text-faint); }
.status-dot.busy { background: var(--good); animation: pulse 1.4s ease-in-out infinite; }
.status-dot.err { background: var(--bad); }
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(94,234,212,0.6); transform: scale(1); }
  50% { box-shadow: 0 0 0 6px rgba(94,234,212,0); transform: scale(1.15); }
}

/* Chart */
#chartCanvas {
  background: var(--bg-elev2);
  border: 1px solid var(--border);
  border-radius: 8px;
  display: block;
  width: 100%; height: 160px;
}

/* Log */
.log {
  font-size: 11px; color: var(--text-faint);
  font-family: ui-monospace, Menlo, monospace;
  max-height: 110px; overflow-y: auto;
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 8px 10px; border-radius: 6px;
  white-space: pre-wrap; word-break: break-word;
}
.log .err { color: var(--bad); }

/* Stats line */
.stats-line {
  font-size: 11px; color: var(--text-dim);
  font-family: ui-monospace, Menlo, monospace;
  letter-spacing: -0.01em;
  margin-top: 8px;
  padding: 8px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  white-space: pre;
  overflow-x: auto;
}
.stats-line b { color: var(--text); font-weight: 600; }

/* Modal panel */
.overlay {
  position: fixed; inset: 0;
  background: rgba(8, 10, 14, 0.72);
  backdrop-filter: blur(4px);
  display: none;
  z-index: 100;
  padding: 28px;
  align-items: stretch; justify-content: center;
}
.overlay.open { display: flex; }
.modal {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 14px;
  width: 100%; max-width: 1100px;
  max-height: calc(100vh - 56px);
  display: flex; flex-direction: column;
  overflow: hidden;
  box-shadow: 0 30px 80px rgba(0,0,0,0.45);
}
.modal header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  gap: 14px;
}
.modal header h3 { margin: 0; font-size: 14px; font-weight: 600; letter-spacing: -0.01em; }
.modal header .close { cursor: pointer; }
.modal .body {
  display: flex; flex: 1; min-height: 0; overflow: hidden;
}

/* Sidebar list (kernels / source files) */
.sidebar {
  width: 260px; min-width: 240px;
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  background: var(--bg-elev);
}
.sidebar .filter {
  padding: 10px;
  border-bottom: 1px solid var(--border);
}
.sidebar input[type=text] {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 7px 10px;
  border-radius: 6px;
  font: inherit;
  font-size: 13px;
}
.sidebar input[type=text]:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.sidebar .list {
  flex: 1; overflow-y: auto;
  padding: 4px 6px;
}
.sidebar .item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 7px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12.5px;
  color: var(--text-dim);
  font-family: ui-monospace, Menlo, monospace;
  user-select: none;
}
.sidebar .item:hover { background: var(--bg-elev2); color: var(--text); }
.sidebar .item.active { background: var(--accent-soft); color: var(--accent); }
.sidebar .item .pill {
  font-size: 10px;
  background: var(--bg-elev2);
  color: var(--text-faint);
  padding: 1px 6px;
  border-radius: 999px;
  margin-left: 8px;
}
.sidebar .item.active .pill { color: var(--accent); background: rgba(94,234,212,0.12); }

/* Source panel */
.viewer {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column;
  background: var(--bg);
}
.viewer .head {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 12px; color: var(--text-dim);
  display: flex; gap: 16px; align-items: center;
}
.viewer .head .name { color: var(--text); font-weight: 600; font-family: ui-monospace, Menlo, monospace; }
.viewer .head .meta { color: var(--text-faint); font-size: 11px; }
.viewer pre {
  margin: 0; padding: 16px 18px;
  flex: 1; overflow: auto;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.55;
  background: var(--bg);
  color: var(--text);
  tab-size: 4;
}

/* Syntax-highlight tokens (works for both themes) */
.tok-kw { color: #c084fc; }
.tok-fn { color: #60a5fa; }
.tok-ty { color: #f472b6; }
.tok-num { color: #fbbf24; }
.tok-str { color: #5eead4; }
.tok-com { color: var(--text-faint); font-style: italic; }
.tok-anno { color: #f472b6; }
.tok-deco { color: #fbbf24; }
:root.light .tok-kw { color: #7c3aed; }
:root.light .tok-fn { color: #2563eb; }
:root.light .tok-ty { color: #be185d; }
:root.light .tok-num { color: #b45309; }
:root.light .tok-str { color: #047857; }
:root.light .tok-com { color: var(--text-faint); }

/* About panel */
.about {
  padding: 20px 24px;
  overflow-y: auto;
  display: grid;
  gap: 24px;
}
.about-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}
@media (max-width: 800px) { .about-grid { grid-template-columns: 1fr; } }
.about h4 {
  margin: 0 0 10px;
  font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--text-dim); font-weight: 600;
}
.about p { margin: 0 0 8px; color: var(--text); }
.about .desc-block {
  background: var(--bg-elev2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
}
.about .desc-block p { margin: 0 0 10px; }
.about .desc-block p:last-child { margin: 0; }
.about .live {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 16px;
}
.about .live .row {
  display: flex; justify-content: space-between;
  padding: 6px 10px;
  background: var(--bg-elev2);
  border-radius: 6px;
  font-size: 12.5px;
  border: 1px solid var(--border);
}
.about .live .row .k { color: var(--text-dim); }
.about .live .row .v { font-family: ui-monospace, Menlo, monospace; font-weight: 600; }
.about svg.diagram {
  width: 100%; height: auto; max-height: 320px;
  background: var(--bg-elev2);
  border: 1px solid var(--border);
  border-radius: 10px;
  display: block;
}
.about table.params {
  border-collapse: collapse;
  width: 100%;
  font-size: 12.5px;
}
.about table.params th, .about table.params td {
  text-align: left;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
}
.about table.params th { font-weight: 600; color: var(--text-dim); font-size: 11px; text-transform: uppercase; letter-spacing: 0.03em; }
.about table.params td.num { font-family: ui-monospace, Menlo, monospace; text-align: right; }

/* Misc */
.right-col { display: flex; flex-direction: column; gap: 12px; }
.controls {
  display: flex; gap: 8px; flex-wrap: wrap; align-items: center;
}
.spacer { flex: 1; }

/* Source-panel body: flip to column so the header sits above the
   sidebar+viewer row (which keeps its own flex-row layout). */
.modal .body.source-modal-body { flex-direction: column; }
.source-row {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* Source-panel header: the tinygrad build command + kernels button. */
.source-header {
  padding: 14px 18px; background: var(--bg-elev2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.source-header-row {
  display: flex; gap: 16px; align-items: center;
  justify-content: space-between; flex-wrap: wrap;
}
.source-header-cmd { flex: 1; min-width: 260px; }
.source-header-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-faint); margin-bottom: 6px;
}
.source-header-code {
  margin: 0; padding: 8px 10px; background: var(--bg);
  border: 1px solid var(--border); border-radius: 6px;
  font-size: 12px; color: var(--text); white-space: pre-wrap; line-height: 1.45;
}
.source-header-hint {
  font-size: 11.5px; color: var(--text-dim); line-height: 1.5;
  margin-top: 8px;
}
.source-header-hint code {
  background: var(--bg); padding: 0 4px; border-radius: 3px;
  font-size: 11px;
}
