@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;700&display=swap');

:root {
  --bg: #000000;
  --bg-elevated: #0a0a0a;
  --phosphor: #00FF41;
  --phosphor-dim: #00aa2a;
  --phosphor-glow: rgba(0, 255, 65, 0.4);
  --warning: #ddff00;
  --warning-dim: #888800;
  --scanline: rgba(0, 255, 65, 0.03);

  --font-mono: "JetBrains Mono", "Fira Code", "IBM Plex Mono", ui-monospace, monospace;
  --fs-base: 14px;
  --fs-chrome: 11px;
  --fs-title: 18px;
  --fs-header: 24px;
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--phosphor);
  font-family: var(--font-mono);
  font-size: var(--fs-base);
  text-shadow: 0 0 1px var(--phosphor-glow);
  overflow: hidden;
}

body { animation: crt-flicker 150ms infinite; }

@keyframes crt-flicker {
  0%, 100% { opacity: 1; }
  47% { opacity: 0.99; }
  50% { opacity: 0.97; }
  53% { opacity: 0.99; }
}

/* Scanline overlay */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0,
    transparent 2px,
    var(--scanline) 2px,
    var(--scanline) 3px
  );
  z-index: 9000;
}

/* CRT vignette / curvature illusion */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  border-radius: 2vmin;
  box-shadow: inset 0 0 12vmin rgba(0,0,0,0.65);
  z-index: 9001;
}

/* ---------- Layout ---------- */
.app {
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 16px;
  gap: 14px;
}

.app-header {
  font-size: var(--fs-chrome);
  display: flex;
  justify-content: space-between;
  align-items: center;
  letter-spacing: 0.1em;
}

.app-header .logo {
  font-size: var(--fs-title);
  letter-spacing: 0.2em;
}

.app-header .meta {
  color: var(--phosphor-dim);
}

.viewers {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 14px;
  min-height: 0;
}

@media (max-width: 1100px) {
  .viewers { grid-template-columns: 1fr; grid-auto-rows: 1fr; }
}

/* ---------- Viewer (ASCII frame fallback: CSS border + glyph corners) ---------- */
.viewer {
  position: relative;
  border: 1px solid var(--phosphor);
  display: flex;
  flex-direction: column;
  background: var(--bg);
  min-height: 0;
}

.viewer::before, .viewer::after {
  position: absolute;
  font-family: var(--font-mono);
  font-size: var(--fs-chrome);
  color: var(--phosphor);
  background: var(--bg);
  padding: 0 2px;
  pointer-events: none;
}
.viewer::before { content: '┘'; bottom: -7px; left: -3px; }
.viewer::after  { content: '└'; top: -7px; right: -3px;
  /* visual flip: not strictly accurate ASCII, but reads as a corner glyph */
}

.viewer-title {
  position: absolute;
  top: -10px;
  left: 12px;
  background: var(--bg);
  padding: 0 8px;
  font-size: var(--fs-chrome);
  letter-spacing: 0.15em;
  color: var(--phosphor);
  z-index: 2;
}
.viewer-title::before { content: '┌─[ '; color: var(--phosphor-dim); }
.viewer-title::after  { content: ' ]─'; color: var(--phosphor-dim); }

.viewer-body {
  flex: 1;
  position: relative;
  padding: 16px 12px 8px 12px;
  min-height: 0;
  overflow: hidden;
}

/* Scope to direct-child textareas only. The code editor's textarea lives
   nested inside .editor, so this rule MUST NOT match it — otherwise it
   overrides the transparent text/caret on the shadow textarea and the
   user sees plain phosphor green covering the Prism-highlighted pre. */
.viewer-body > textarea, .viewer-body > iframe {
  width: 100%;
  height: 100%;
  background: var(--bg);
  color: var(--phosphor);
  font-family: var(--font-mono);
  font-size: var(--fs-base);
  border: none;
  outline: none;
  resize: none;
  caret-color: var(--phosphor);
}

.viewer-body > textarea::placeholder { color: var(--phosphor-dim); }

.viewer-body > iframe { background: white; }

/* ---------- Code viewer: VS Code Dark+ surface, shadow-textarea editor ----
   The code panel is intentionally NOT phosphor-themed. The pedagogical goal
   is for students to recognize what VS Code looks like, since that is what
   they will graduate to. The viewer's outer frame stays on-brand (phosphor
   border, ASCII title) but the editing surface itself is genuine Dark+. */

.editor {
  position: relative;
  width: 100%;
  height: 100%;
  background: #1e1e1e;        /* VS Code Dark+ editor background */
}

.editor-display,
.editor-input {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: 8px 12px;
  font-family: var(--font-mono);
  font-size: var(--fs-base);
  line-height: 1.5;
  tab-size: 2;
  /* Wrap long lines so students don't have to scroll horizontally to
     read or edit. pre-wrap preserves indentation; overflow-wrap: anywhere
     also breaks unbreakable runs (long URLs, base64, etc.). Both layers
     must use identical wrap settings or the cursor drifts off the tokens. */
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  overflow: auto;
  border: 0;
  background: transparent;
}

.editor-display {
  z-index: 1;
  pointer-events: none;
  color: #d4d4d4;             /* VS Code default foreground */
  text-shadow: none;
}
.editor-display code { font: inherit; background: none; padding: 0; color: inherit; }

.editor-input {
  z-index: 2;
  color: transparent;
  caret-color: #aeafad;        /* VS Code cursor */
  resize: none;
  outline: none;
}
.editor-input::placeholder { color: #6a6a6a; }
.editor-input::selection   { background: #264f78; }   /* VS Code selection */

/* ---------- Prism token theme — VS Code Dark+ ----------
   These colors are taken straight from VS Code's built-in Dark+ theme
   so the editing surface is visually identical to what students will
   see in a real VS Code window. */

.token.comment,
.token.prolog,
.token.cdata             { color: #6a9955; font-style: italic; }     /* green */
.token.doctype,
.token.doctype .name     { color: #569cd6; }                          /* blue */

/* HTML tag names + their punctuation: VS Code blue */
.token.tag,
.token.tag > .punctuation,
.token.tag .punctuation,
.token.tag .token.tag,
.token.tag .token.namespace { color: #569cd6; }

/* Attribute names: light cyan */
.token.attr-name         { color: #9cdcfe; }

/* Strings + attribute values + URLs: orange */
.token.attr-value,
.token.attr-value .punctuation,
.token.string,
.token.url               { color: #ce9178; }

/* Numbers + booleans + constants: light green */
.token.number,
.token.boolean,
.token.constant          { color: #b5cea8; }

/* Punctuation, operators: default foreground */
.token.punctuation       { color: #d4d4d4; }
.token.operator          { color: #d4d4d4; }
.token.entity            { color: #d7ba7d; }

/* CSS: selectors gold-tan, properties cyan, units like numbers */
.token.selector,
.token.class-name        { color: #d7ba7d; }
.token.property          { color: #9cdcfe; }
.token.unit              { color: #b5cea8; }

/* JS: keywords purple, function names pale yellow */
.token.keyword           { color: #c586c0; }
.token.symbol            { color: #569cd6; }
.token.function          { color: #dcdcaa; }
.token.builtin           { color: #4ec9b0; }
.token.regex             { color: #d16969; }

.viewer-footer {
  display: flex;
  justify-content: flex-end;
  gap: 16px;
  padding: 6px 12px 8px;
  font-size: var(--fs-chrome);
  border-top: 1px dashed var(--phosphor-dim);
}

/* ---------- Buttons (bracket text only) ---------- */
.btn {
  background: none;
  border: none;
  color: var(--phosphor);
  font-family: var(--font-mono);
  font-size: var(--fs-chrome);
  letter-spacing: 0.12em;
  cursor: pointer;
  padding: 2px 4px;
  text-shadow: 0 0 1px var(--phosphor-glow);
  transition: text-shadow 100ms;
}
.btn::before { content: '[ '; color: var(--phosphor-dim); }
.btn::after  { content: ' ]'; color: var(--phosphor-dim); }
.btn:hover { text-shadow: 0 0 6px var(--phosphor); }
.btn:hover::before, .btn:hover::after { color: var(--phosphor); }
.btn:active { background: var(--phosphor); color: var(--bg); text-shadow: none; }
.btn:active::before, .btn:active::after { color: var(--bg); }
.btn:disabled {
  color: var(--phosphor-dim);
  cursor: not-allowed;
  text-shadow: none;
}
.btn--secondary { color: var(--phosphor-dim); font-size: 10px; }

/* ---------- Generating overlay ---------- */
.generating {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--fs-title);
  letter-spacing: 0.25em;
  color: var(--phosphor);
  background: rgba(0,0,0,0.85);
  z-index: 5;
  pointer-events: none;
  text-shadow: 0 0 8px var(--phosphor);
}
.generating.is-hidden { display: none; }

/* ---------- Diagnostics ---------- */
.diagnostics {
  border-top: 1px solid var(--warning-dim);
  background: var(--bg);
  font-size: var(--fs-chrome);
  color: var(--warning);
}
.diagnostics-toggle {
  width: 100%;
  background: none;
  border: none;
  color: var(--warning);
  font-family: var(--font-mono);
  font-size: var(--fs-chrome);
  letter-spacing: 0.1em;
  text-align: left;
  padding: 6px 12px;
  cursor: pointer;
  text-shadow: 0 0 2px var(--warning);
}
.diagnostics-body {
  padding: 8px 12px 12px;
  max-height: 30vh;
  overflow: auto;
  display: none;
  white-space: pre-wrap;
  font-size: var(--fs-chrome);
  line-height: 1.5;
}
.diagnostics.is-open .diagnostics-body { display: block; }
.diagnostics-empty { border-top-color: var(--phosphor-dim); }
.diagnostics-empty .diagnostics-toggle {
  color: var(--phosphor-dim);
  text-shadow: none;
}

/* ---------- Boot sequence ---------- */
.boot {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 10000;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
  padding: 8vh 12vw;
  font-size: var(--fs-base);
  cursor: pointer;
}
.boot.is-done { opacity: 0; pointer-events: none; transition: opacity 400ms; }
.boot-line { white-space: pre; min-height: 1.4em; }
.boot-cursor::after { content: '█'; animation: blink 600ms steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* ---------- Ambient anomaly flickers ---------- */
.anomaly {
  position: fixed;
  color: var(--warning);
  font-size: var(--fs-chrome);
  letter-spacing: 0.12em;
  cursor: pointer;
  z-index: 8000;
  opacity: 0;
  text-shadow: 0 0 3px var(--warning);
}
.anomaly.is-on { animation: anomaly-flicker 1400ms ease-in-out forwards; }
@keyframes anomaly-flicker {
  0%   { opacity: 0; }
  15%  { opacity: 1; }
  70%  { opacity: 1; }
  100% { opacity: 0; }
}

[data-scramble] { display: inline-block; }
