/* CELLGUI - layered system-cell visualization. */

:root {
  --bg-0: #080b10;
  --bg-1: #0d1217;
  --bg-2: #12191e;
  --ink-0: #e7eee8;
  --ink-1: #b8c7be;
  --ink-2: #788980;
  --ink-3: #4d5d57;
  --rule: #1f302d;
  --rule-strong: #37514b;
  --jade: #70d79b;
  --cyan: #62d0d4;
  --amber: #f1bf62;
  --rose: #e0717b;
  --violet: #ac91e0;
  --blue: #7fa9ff;
  --font-display: 'Major Mono Display', 'IBM Plex Mono', monospace;
  --font-sans: 'Familjen Grotesk', system-ui, sans-serif;
  --font-mono: 'IBM Plex Mono', 'JetBrains Mono', monospace;
  --pad: 18px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  background:
    radial-gradient(860px 540px at 28% 4%, rgba(98, 208, 212, 0.08), transparent 68%),
    radial-gradient(760px 640px at 92% 102%, rgba(241, 191, 98, 0.08), transparent 70%),
    linear-gradient(180deg, #080b10 0%, #09110f 100%);
  color: var(--ink-0);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.45;
}

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

.top-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px var(--pad);
  border-bottom: 1px solid var(--rule);
  background: rgba(8, 11, 16, 0.94);
  color: var(--ink-2);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0;
  text-transform: uppercase;
}

.strip-left,
.strip-right {
  display: flex;
  align-items: center;
  gap: 11px;
}

.strip-right {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.brand {
  color: var(--amber);
  font-family: var(--font-display);
  font-size: 13px;
}

.sep,
.foot span:nth-child(even) {
  color: var(--ink-3);
}

.strip-right a:hover {
  color: var(--amber);
}

.cell-shell {
  width: min(1600px, 100%);
  margin: 0 auto;
  padding: 22px var(--pad) 28px;
}

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

.kicker {
  margin: 0 0 5px;
  color: var(--cyan);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  color: var(--ink-0);
  font-family: var(--font-display);
  font-size: 38px;
  font-weight: 400;
  line-height: 1;
  letter-spacing: 0;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  align-items: end;
}

.controls label {
  display: grid;
  gap: 4px;
  color: var(--ink-3);
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
}

.controls select,
.controls button {
  height: 38px;
  border: 1px solid var(--rule-strong);
  background: rgba(8, 11, 16, 0.9);
  color: var(--ink-0);
  font: 500 12px var(--font-mono);
  padding: 0 11px;
}

.controls button {
  cursor: pointer;
  text-transform: uppercase;
}

.controls select:focus,
.controls button:focus,
.controls button:hover {
  border-color: var(--amber);
  outline: none;
}

.stage-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 14px;
  align-items: start;
}

.viz-panel,
.meta-panel {
  border: 1px solid var(--rule);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(13, 18, 23, 0.94), rgba(8, 13, 12, 0.94)),
    repeating-linear-gradient(0deg, transparent 0 39px, rgba(112, 215, 155, 0.035) 39px 40px);
}

.viz-panel {
  min-height: 760px;
  overflow: hidden;
}

.cell-svg {
  display: block;
  width: 100%;
  height: min(80vh, 900px);
  min-height: 720px;
}

.meta-panel {
  position: sticky;
  top: 12px;
  max-height: calc(100vh - 24px);
  overflow: auto;
  padding: 15px;
}

.meta-empty {
  margin: 0;
  color: var(--ink-2);
  font-family: var(--font-display);
  font-size: 22px;
}

.meta-panel h2 {
  margin: 0 0 8px;
  color: var(--ink-0);
  font-size: 24px;
  line-height: 1.1;
}

.meta-kicker,
.meta-label {
  color: var(--ink-3);
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
}

.meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 10px 0 12px;
}

.meta-pill {
  border: 1px solid var(--rule-strong);
  color: var(--ink-1);
  font-family: var(--font-mono);
  font-size: 10px;
  padding: 2px 7px;
  text-transform: uppercase;
}

.meta-panel p {
  color: var(--ink-1);
  margin: 8px 0;
}

.meta-list {
  display: grid;
  gap: 5px;
  margin-top: 7px;
}

.meta-item {
  border: 1px solid var(--rule);
  color: var(--ink-1);
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 6px 7px;
}

.layer-band {
  fill: none;
  stroke: rgba(231, 238, 232, 0.1);
  stroke-width: 1.2;
  vector-effect: non-scaling-stroke;
}

.cell-shape {
  cursor: pointer;
  filter: drop-shadow(0 8px 14px rgba(0, 0, 0, 0.26));
}

.cell-fill {
  stroke-width: 1.25;
  vector-effect: non-scaling-stroke;
}

.cell-shape:hover .cell-fill,
.cell-shape:focus .cell-fill,
.cell-shape.selected .cell-fill {
  stroke-width: 2.6;
}

.cell-shape text {
  pointer-events: none;
}

.cell-label {
  fill: var(--ink-0);
  font: 600 12px var(--font-sans);
  text-anchor: middle;
}

.cell-sub {
  fill: var(--ink-2);
  font: 500 9px var(--font-mono);
  text-anchor: middle;
  text-transform: uppercase;
}

.layer-title {
  fill: var(--ink-2);
  font: 600 11px var(--font-mono);
  text-anchor: middle;
  text-transform: uppercase;
}

.edge-line {
  fill: none;
  stroke: rgba(241, 191, 98, 0.35);
  stroke-linecap: round;
  stroke-width: 1.4;
  vector-effect: non-scaling-stroke;
}

.focus-halo {
  fill: none;
  stroke: rgba(241, 191, 98, 0.68);
  stroke-dasharray: 7 8;
  stroke-width: 1.4;
  vector-effect: non-scaling-stroke;
}

.subcell .cell-label {
  font-size: 10px;
}

.subcell .cell-sub {
  font-size: 8px;
}

.foot {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 var(--pad) 22px;
  color: var(--ink-3);
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
}

@media (max-width: 1080px) {
  .toolbar,
  .top-strip {
    align-items: flex-start;
    flex-direction: column;
  }

  .stage-grid {
    grid-template-columns: 1fr;
  }

  .meta-panel {
    position: static;
    max-height: none;
  }
}

@media (max-width: 680px) {
  :root {
    --pad: 12px;
  }

  h1 {
    font-size: 30px;
  }

  .viz-panel {
    min-height: 620px;
  }

  .cell-svg {
    min-height: 620px;
  }
}

/* ----- breadcrumb path ----- */
.crumb-trail {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: .35rem;
  padding: .35rem 1.25rem .65rem;
  font: 400 .78rem 'IBM Plex Mono', monospace;
  color: rgba(184, 199, 190, .65);
  letter-spacing: .04em;
}
.crumb-trail .crumb {
  border: 1px solid rgba(184, 199, 190, .22);
  padding: .12rem .5rem;
  cursor: pointer;
  transition: border-color .15s, color .15s, background .15s;
  background: rgba(15, 22, 18, .35);
}
.crumb-trail .crumb:hover {
  border-color: rgba(112, 215, 155, .75);
  color: #e1efe6;
  background: rgba(112, 215, 155, .08);
}
.crumb-trail .crumb.root { border-style: dashed; }
.crumb-trail .crumb.tip {
  border-color: rgba(241, 191, 98, .75);
  color: #f1bf62;
  cursor: default;
}
.crumb-trail .crumb.tip:hover {
  background: transparent;
}
.crumb-trail .crumb-sep {
  color: rgba(184, 199, 190, .3);
  user-select: none;
}

/* ----- live status pulse on cells ----- */
@keyframes cell-pulse-alive {
  0%, 100% { stroke-opacity: 0.45; }
  50%      { stroke-opacity: 0.95; }
}
@keyframes cell-pulse-dead {
  0%, 100% { stroke-opacity: 0.35; }
  50%      { stroke-opacity: 0.75; }
}
.cell-shape.live-alive .cell-fill {
  animation: cell-pulse-alive 3.4s ease-in-out infinite;
}
.cell-shape.live-dead .cell-fill {
  animation: cell-pulse-dead 2.1s ease-in-out infinite;
  stroke: #e0717b !important;
}
.cell-shape.live-dead .cell-fill {
  fill: rgba(224, 113, 123, .18) !important;
}

/* ----- footer live stamp ----- */
.foot #live-stamp {
  color: #70d79b;
  font-variant-numeric: tabular-nums;
  letter-spacing: .04em;
}
.foot #live-stamp.stale { color: #e0717b; }

/* ----- keyboard help overlay ----- */
#help-toggle {
  background: transparent;
  color: rgba(184, 199, 190, .7);
  border: 1px solid rgba(184, 199, 190, .25);
  padding: .25rem .55rem;
  cursor: pointer;
  font: 700 .9rem 'IBM Plex Mono', monospace;
  border-radius: 50%;
  width: 1.85rem;
  height: 1.85rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: border-color .15s, color .15s, background .15s;
}
#help-toggle:hover, #help-toggle.active {
  border-color: #f1bf62;
  color: #f1bf62;
  background: rgba(241, 191, 98, .08);
}

.viz-panel { position: relative; }
.help-overlay {
  position: absolute;
  top: 16px; right: 16px;
  background: rgba(8, 11, 16, .92);
  border: 1px solid rgba(241, 191, 98, .35);
  padding: 1rem 1.2rem 1.1rem;
  max-width: 320px;
  z-index: 5;
  font: 400 .82rem 'IBM Plex Mono', monospace;
  color: #d6e4dc;
  letter-spacing: .03em;
  box-shadow: 0 12px 32px rgba(0, 0, 0, .5);
}
.help-overlay.hidden { display: none; }
.help-overlay h3 {
  margin: 0 0 .55rem;
  font: 400 .9rem 'Major Mono Display', monospace;
  letter-spacing: .15em;
  color: #f1bf62;
}
.help-overlay ul { list-style: none; margin: 0 0 .65rem; padding: 0; }
.help-overlay li { margin: .25rem 0; }
.help-overlay kbd {
  background: rgba(241, 191, 98, .12);
  border: 1px solid rgba(241, 191, 98, .45);
  padding: 0 .35rem;
  font-family: inherit;
  color: #f1bf62;
}
.help-overlay .help-hint {
  margin: .35rem 0 0;
  font-style: italic;
  color: rgba(184, 199, 190, .65);
}

/* ----- smooth viewBox transition on the SVG itself ----- */
.cell-svg.tweening { /* class set during animation; nothing extra needed */ }
.cell-shape, .focus-halo {
  transition: opacity .25s ease;
}
