/* ============================================================
   WIREFRAME//RENDER — stylesheet
   Aesthetic: CRT terminal, symmetric panel layout, VT323
   ============================================================ */

:root {
  --bg: #000000;
  --bg-soft: #050a05;

  --primary: #00fd00;
  --warning: #FFFF33;
  --error:   #ed0400;
  --success: #008000;

  --primary-glow: rgba(0, 253, 0, 0.45);
  --primary-dim:  rgba(0, 253, 0, 0.55);
  --primary-faint:rgba(0, 253, 0, 0.18);

  --ink: var(--primary);
  --ink-dim: rgba(0, 253, 0, 0.65);

  --font: 'VT323', 'Courier New', monospace;

  --radius: 10px;
  --border-w: 4px;
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-weight: 400;
  font-size: 18px;
  line-height: 1.4;
  overflow-x: hidden;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---------- CRT effects ---------- */

.scanlines {
  position: fixed; inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    0deg,
    rgba(0, 253, 0, 0.04) 0px,
    rgba(0, 253, 0, 0.04) 1px,
    transparent 1px,
    transparent 3px
  );
  z-index: 100;
  mix-blend-mode: screen;
}

.grain {
  position: fixed; inset: -50%;
  pointer-events: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0.16 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  opacity: 0.30;
  z-index: 99;
  animation: grain-shift 0.8s steps(6) infinite;
  mix-blend-mode: overlay;
}
@keyframes grain-shift {
  0%   { transform: translate(0, 0); }
  20%  { transform: translate(-2%, 3%); }
  40%  { transform: translate(2%, -2%); }
  60%  { transform: translate(-1%, 1%); }
  80%  { transform: translate(3%, 2%); }
  100% { transform: translate(0, 0); }
}

/* ---------- Hero (chip + START) ---------- */

.hero {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 24px;
  min-height: 100vh;
}
.hero.hidden { display: none; }

.hero-stack {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
}

.gpu-chip {
  width: clamp(160px, 22vw, 240px);
  height: auto;
  color: var(--primary);
  filter: drop-shadow(0 0 12px var(--primary-glow));
  animation: chip-pulse 2.4s ease-in-out infinite;
}
.gpu-chip rect { fill: currentColor; }
.gpu-chip rect[fill="none"] { fill: none; }

@keyframes chip-pulse {
  0%, 100% { filter: drop-shadow(0 0 12px var(--primary-glow)); }
  50%      { filter: drop-shadow(0 0 22px var(--primary-glow)) drop-shadow(0 0 40px var(--primary-faint)); }
}

.btn-start {
  background: transparent;
  border: var(--border-w) solid var(--primary);
  color: var(--primary);
  font-family: var(--font);
  font-size: clamp(40px, 6vw, 72px);
  letter-spacing: 0.08em;
  padding: 14px 56px;
  cursor: pointer;
  border-radius: var(--radius);
  text-shadow: 0 0 14px var(--primary-glow);
  box-shadow:
    inset 0 0 30px rgba(0, 253, 0, 0.06),
    0 0 30px var(--primary-faint);
  transition: all 0.2s cubic-bezier(.2,.7,.2,1);
}
.btn-start:hover {
  background: var(--primary);
  color: var(--bg);
  text-shadow: none;
  box-shadow: 0 0 50px var(--primary-glow), 0 0 100px var(--primary-faint);
}
.btn-start:active { transform: scale(0.97); }
.btn-bracket { color: var(--warning); margin: 0 0.1em; }
.btn-start:hover .btn-bracket { color: var(--bg); }

/* ---------- Level top bar ---------- */

.level-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 24px 32px 32px;
  width: 100%;
  max-width: 1600px;
  margin: 0 auto;
  min-height: 100vh;
}
.level-view.hidden { display: none; }

.level-topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  margin-bottom: 22px;
  gap: 16px;
}

.btn-back {
  justify-self: start;
  background: transparent;
  border: 2px solid var(--primary);
  color: var(--primary);
  font-family: var(--font);
  font-size: 16px;
  padding: 6px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.15s;
}
.btn-back:hover { background: var(--primary); color: var(--bg); }

.topbar-spacer { /* keeps nav centered via grid */ }

.level-nav {
  display: flex;
  gap: 10px;
  align-items: center;
  font-size: 22px;
  color: var(--primary);
}
.level-nav .nav-label { margin-right: 6px; letter-spacing: 0.06em; }
.level-nav button {
  background: transparent;
  border: none;
  color: var(--primary);
  font-family: var(--font);
  font-size: 22px;
  cursor: pointer;
  padding: 2px 4px;
  transition: all 0.15s;
  text-shadow: 0 0 8px var(--primary-faint);
}
.level-nav button:hover { text-shadow: 0 0 14px var(--primary-glow); }
.level-nav button.active {
  color: var(--warning);
  text-shadow: 0 0 14px rgba(255, 255, 51, 0.5);
}
.level-nav button.locked { color: var(--ink-dim); opacity: 0.7; }

/* ---------- Level grid ---------- */

.level-grid {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) 2fr;
  gap: 22px;
  flex: 1;
  align-items: stretch;
}
.level-grid.tutorial-collapsed {
  grid-template-columns: 56px 1fr;
}

.pane {
  border: var(--border-w) solid var(--primary);
  border-radius: var(--radius);
  background: var(--bg);
  box-shadow: 0 0 18px var(--primary-faint), inset 0 0 22px rgba(0,253,0,0.03);
  position: relative;
  padding: 22px;
}
.pane-title {
  font-size: 22px;
  color: var(--primary);
  margin-bottom: 14px;
  letter-spacing: 0.04em;
}

/* ---------- Tutorial pane ---------- */

.tutorial-pane {
  position: relative;
  overflow: hidden;
  transition: padding 0.25s;
}
.tutorial-content {
  font-size: 17px;
  padding-right: 24px;  /* space for the X button */
  max-height: 100%;
  overflow-y: auto;
}
.tutorial-content h3 {
  font-size: 26px;
  margin-bottom: 8px;
  margin-top: 18px;
  color: var(--primary);
  text-shadow: 0 0 10px var(--primary-faint);
}
.tutorial-content h3:first-child { margin-top: 0; }
.tutorial-content p { margin-bottom: 12px; }
.tutorial-content ul { list-style: none; margin-bottom: 14px; }
.tutorial-content li {
  padding-left: 18px;
  position: relative;
  margin-bottom: 6px;
}
.tutorial-content li::before {
  content: '>';
  position: absolute;
  left: 0;
  color: var(--warning);
}
.tutorial-content code,
.tutorial-content .inline {
  color: var(--warning);
  padding: 0 4px;
}
.tutorial-content .matrix-block {
  display: inline-block;
  padding: 6px 14px;
  margin: 6px 6px 6px 0;
  border-left: 2px solid var(--primary);
  border-right: 2px solid var(--primary);
  color: var(--warning);
}

.pane-close {
  position: absolute;
  top: 10px;
  right: 14px;
  width: 30px; height: 30px;
  background: transparent;
  border: 2px solid var(--primary);
  border-radius: 6px;
  color: var(--primary);
  font-family: var(--font);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  z-index: 3;
  transition: all 0.15s;
}
.pane-close:hover { background: var(--primary); color: var(--bg); }

.tutorial-reopen {
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: var(--border-w) solid var(--primary);
  border-radius: var(--radius);
  color: var(--primary);
  font-family: var(--font);
  font-size: 18px;
  cursor: pointer;
  box-shadow: 0 0 18px var(--primary-faint);
  transition: all 0.15s;
  padding: 0;
}
.tutorial-reopen span {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  letter-spacing: 0.18em;
}
.tutorial-reopen:hover { background: var(--primary); color: var(--bg); }

.hidden { display: none !important; }

/* ---------- Right column (canvas + bottom row) ---------- */

.right-column {
  display: flex;
  flex-direction: column;
  gap: 22px;
  min-width: 0;
}

.canvas-pane {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  background: #010301;
  overflow: hidden;
}
#p5-host {
  aspect-ratio: 640 / 420;
  max-height: 52vh;
  max-width: 100%;
  line-height: 0;
  display: block;
}
#p5-host canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}

.bottom-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 22px;
  height: 260px;          /* fixed row height — prevents console growth from stretching the page */
  flex-shrink: 0;
}
.bottom-row .pane {
  overflow: hidden;       /* contain children so console scrolls instead of growing */
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.bottom-row .pane-title { flex-shrink: 0; }
.bottom-row .controls,
.bottom-row .console {
  flex: 1;
  min-height: 0;
}

@media (max-width: 980px) {
  .level-grid { grid-template-columns: 1fr; }
  .bottom-row { grid-template-columns: 1fr; }
}

/* ---------- Matrix input ---------- */

.controls {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.matrix-input-group {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  align-items: flex-start;
}

.matrix-input {
  display: inline-flex;
  flex-direction: column;
  gap: 6px;
}
.matrix-input-label {
  font-size: 15px;
  color: var(--warning);
  letter-spacing: 0.08em;
}

.matrix-input-grid {
  display: grid;
  gap: 6px;
  padding: 8px 12px;
  border-left: 2px solid var(--primary);
  border-right: 2px solid var(--primary);
}
.matrix-input-grid input {
  width: 56px;
  padding: 6px 4px;
  background: var(--bg);
  border: 2px solid var(--primary);
  border-radius: 4px;
  color: var(--primary);
  font-family: var(--font);
  font-size: 18px;
  text-align: center;
  transition: all 0.15s;
}
.matrix-input-grid input:focus {
  outline: none;
  box-shadow: 0 0 0 1px var(--primary), 0 0 14px var(--primary-glow);
}

.action-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.btn-action {
  background: transparent;
  border: 2px solid var(--primary);
  color: var(--primary);
  font-family: var(--font);
  font-size: 15px;
  letter-spacing: 0.08em;
  padding: 8px 16px;
  cursor: pointer;
  border-radius: 6px;
  transition: all 0.15s;
}
.btn-action:hover { background: var(--primary); color: var(--bg); }
.btn-action.secondary {
  border-color: var(--ink-dim);
  color: var(--ink-dim);
}
.btn-action.secondary:hover { background: var(--ink-dim); color: var(--bg); }

/* ---------- Output console ---------- */

.console {
  font-size: 15px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-right: 4px;
}
.console-line {
  border-left: 3px solid transparent;
  padding: 4px 10px;
  white-space: pre-wrap;
}
.console-line.info    { color: var(--primary); border-left-color: var(--primary); }
.console-line.warning { color: var(--warning); border-left-color: var(--warning); }
.console-line.error   { color: var(--error);   border-left-color: var(--error); }
.console-line.success { color: var(--success); border-left-color: var(--success); text-shadow: 0 0 8px rgba(0, 128, 0, 0.6); }

/* scrollbar styling */
.console::-webkit-scrollbar,
.tutorial-content::-webkit-scrollbar { width: 8px; }
.console::-webkit-scrollbar-thumb,
.tutorial-content::-webkit-scrollbar-thumb {
  background: var(--primary-faint);
  border-radius: 4px;
}
.console::-webkit-scrollbar-thumb:hover,
.tutorial-content::-webkit-scrollbar-thumb:hover {
  background: var(--primary-dim);
}

/* ---------- Stub ---------- */

.stub {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px 24px;
  color: var(--ink-dim);
}
.stub h3 {
  font-size: 24px;
  color: var(--warning);
  margin-bottom: 10px;
}
.stub .blink::after {
  content: '_';
  color: var(--primary);
  animation: blink 1.05s steps(2) infinite;
}
@keyframes blink {
  0%, 50% { opacity: 1; }
  51%, 100% { opacity: 0; }
}