/* ==========================================================================
 * THE LAB CONSOLE + FIELD FINDINGS PANEL
 * ==========================================================================
 * The console is the one place the two-instrument idea pays off hardest:
 *
 *   PAPER    — a teletype printout. Cream stock, tractor-feed perforations
 *              down both edges, ink type. A terminal that was PRINTED.
 *   PHOSPHOR — a CRT terminal. Dark tube, green trace, bloom, scanlines.
 *
 * Same markup, same shell, two machines. Console colours are their own token
 * set (`--con-*`) because the console is not made of the same material as the
 * page around it — on paper it is a different, whiter stock.
 * ====================================================================== */

:root {
  --con-stock:   #fdfaf2;   /* the printout itself */
  --con-edge:    #efe8d6;   /* tractor-feed margin */
  --con-ink:     #2a2520;
  --con-ink-dim: #8d8375;
  --con-key:     #1b46c2;   /* prompt, links */
  --con-warn:    #cf2f22;
  --con-ok:      #17795e;
  --con-rule:    rgba(42, 37, 32, .16);
  --con-glow:    none;
  --con-shell:   #d8cdb6;   /* the machine's body around the paper */
  --con-lamp:    #cf2f22;
}

[data-world="phosphor"] {
  --con-stock:   #04090a;
  --con-edge:    #071113;
  --con-ink:     #b8f5d2;
  --con-ink-dim: #4e8a6c;
  --con-key:     #52f2a0;
  --con-warn:    #ffab3d;
  --con-ok:      #52f2a0;
  --con-rule:    rgba(82, 242, 160, .22);
  --con-glow:    0 0 9px rgba(82, 242, 160, .42);
  --con-shell:   #0a1214;
  --con-lamp:    #52f2a0;
}

/* ================================================================= overlay */

.console {
  position: fixed;
  inset: 0;
  /* Above the toast rail (1200). Findings logged while the console is open are
     printed into its scrollback rather than floated over it — see
     LabConsole.report — but if anything else ever floats, the console wins. */
  z-index: 1250;
  display: grid;
  place-items: center;
  padding: clamp(10px, 3vw, 30px);
  padding-top: calc(clamp(10px, 3vw, 30px) + var(--sat));
  padding-bottom: calc(clamp(10px, 3vw, 30px) + var(--sab));
  background: rgba(30, 26, 20, .58);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  opacity: 0;
  transition: opacity .2s var(--ease-out);
}
[data-world="phosphor"] .console { background: rgba(0, 0, 0, .78); }
.console.on { opacity: 1; }
.console[hidden] { display: none; }

/* ------------------------------------------------------------------ frame */

.console-frame {
  position: relative;
  display: flex;
  flex-direction: column;
  width: min(880px, 100%);
  height: min(640px, 100%);
  background: var(--con-stock);
  border: 1px solid var(--con-rule);
  border-radius: 3px;
  box-shadow: 0 30px 70px -24px rgba(20, 17, 13, .6);
  overflow: hidden;
  transform: translateY(10px) scale(.99);
  transition: transform .26s var(--ease-back);
}
.console.on .console-frame { transform: none; }

/* Tractor-feed perforations: PAPER only. Two vertical strips of holes, drawn
   as a repeating radial-gradient so there is no image to load. */
.console-frame::before,
.console-frame::after {
  content: '';
  position: absolute;
  top: 0; bottom: 0;
  width: 17px;
  background:
    linear-gradient(var(--con-edge), var(--con-edge)),
    repeating-radial-gradient(circle at 50% 9px,
      var(--con-rule) 0 2.4px, transparent 2.4px 100%);
  background-size: 100% 100%, 100% 22px;
  border-right: 1px dashed var(--con-rule);
  pointer-events: none;
  z-index: 2;
}
.console-frame::before { left: 0; }
.console-frame::after {
  right: 0;
  border-right: 0;
  border-left: 1px dashed var(--con-rule);
}
/* A CRT has no paper feed. */
[data-world="phosphor"] .console-frame::before,
[data-world="phosphor"] .console-frame::after { display: none; }

/* On phosphor the frame becomes a tube: inset shadow for curvature, and a
   scanline wash over the whole screen. */
[data-world="phosphor"] .console-frame {
  border-color: var(--con-rule);
  box-shadow:
    0 0 0 1px rgba(82, 242, 160, .16),
    0 30px 80px -20px rgba(0, 0, 0, .9),
    inset 0 0 90px rgba(82, 242, 160, .06);
}

/* ------------------------------------------------------------------- bar */

.console-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: none;
  padding: 9px 12px 9px 26px;
  background: var(--con-shell);
  border-bottom: 1px solid var(--con-rule);
  z-index: 3;
}
[data-world="phosphor"] .console-bar { padding-left: 12px; }

.console-lamp {
  width: 7px; height: 7px;
  flex: none;
  border-radius: 50%;
  background: var(--con-lamp);
  box-shadow: 0 0 7px var(--con-lamp);
  animation: lampPulse 2.4s ease-in-out infinite;
}
@keyframes lampPulse { 0%, 100% { opacity: 1 } 50% { opacity: .35 } }

.console-title {
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--con-ink-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.console-bar-actions { display: flex; gap: 4px; margin-left: auto; }
.console-bar-btn {
  width: 25px; height: 25px;
  display: grid;
  place-items: center;
  border: 1px solid transparent;
  border-radius: 2px;
  background: transparent;
  color: var(--con-ink-dim);
  font-size: .82rem;
  line-height: 1;
  transition: color .14s, border-color .14s, background .14s;
}
.console-bar-btn:hover {
  color: var(--con-ink);
  border-color: var(--con-rule);
  background: var(--con-stock);
}

/* ---------------------------------------------------------------- screen */

.console-screen {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: auto;
  padding: 16px 26px;
  font-family: var(--f-mono);
  font-size: .8rem;
  line-height: 1.55;
  color: var(--con-ink);
  /* Terminal output is pre-formatted; ASCII art depends on it. */
  white-space: pre;
  -webkit-overflow-scrolling: touch;
}
.console-screen:focus { outline: none; }

/* Phosphor: glow the text and lay scanlines over the screen area only. */
[data-world="phosphor"] .console-screen {
  text-shadow: var(--con-glow);
  background-image: repeating-linear-gradient(
    180deg,
    rgba(0, 0, 0, .26) 0 1px,
    transparent 1px 3px);
}

.con-line { min-height: 1.55em; }

.con-echo { color: var(--con-ink-dim); }
.con-echo-prompt { color: var(--con-key); font-weight: 700; }
.con-err  { color: var(--con-warn); }
.con-ok   { color: var(--con-ok); }
.con-dim  { color: var(--con-ink-dim); }
.con-art  { color: var(--con-key); }
.con-matrix {
  color: var(--con-ok);
  /* Tighter leading so the rain reads as a field, not a list. */
  line-height: 1.15;
  min-height: 0;
  letter-spacing: .08em;
}

/* Fresh output slides up a hair. Cheap, and makes the shell feel alive. */
.console-screen .con-line { animation: conLine .16s var(--ease-out); }
@keyframes conLine { from { opacity: 0; transform: translateY(2px) } to { opacity: 1 } }
@media (prefers-reduced-motion: reduce) {
  .console-screen .con-line { animation: none; }
}

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

.console-input-row {
  display: flex;
  align-items: center;
  gap: 9px;
  flex: none;
  padding: 11px 26px;
  border-top: 1px solid var(--con-rule);
  background: var(--con-stock);
  z-index: 3;
}
.console-prompt {
  flex: none;
  font-size: .8rem;
  font-weight: 700;
  color: var(--con-key);
  white-space: nowrap;
}
[data-world="phosphor"] .console-prompt { text-shadow: var(--con-glow); }

#console-input {
  flex: 1 1 auto;
  min-width: 0;
  border: 0;
  background: transparent;
  font-size: .8rem;
  color: var(--con-ink);
  caret-color: var(--con-key);
  outline: none;
}
[data-world="phosphor"] #console-input { text-shadow: var(--con-glow); }

.console-keys {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  flex: none;
  padding: 7px 26px 9px;
  border-top: 1px dashed var(--con-rule);
  background: var(--con-shell);
  font-size: .6rem;
  letter-spacing: .06em;
  color: var(--con-ink-dim);
  z-index: 3;
}
.console-keys kbd {
  display: inline-block;
  padding: 1px 4px;
  margin-right: 3px;
  border: 1px solid var(--con-rule);
  border-bottom-width: 2px;
  border-radius: 3px;
  font-family: inherit;
  font-size: .95em;
  color: var(--con-ink);
}

/* ========================================================= findings panel */

.findings {
  position: fixed;
  inset: 0;
  z-index: 1100;
  display: grid;
  place-items: start center;
  overflow-y: auto;
  padding: clamp(14px, 4vw, 44px) clamp(12px, 4vw, 30px);
  padding-top: calc(clamp(14px, 4vw, 44px) + var(--sat));
  background: rgba(30, 26, 20, .6);
  backdrop-filter: blur(7px);
  -webkit-backdrop-filter: blur(7px);
  opacity: 0;
  transition: opacity .2s var(--ease-out);
}
[data-world="phosphor"] .findings { background: rgba(0, 0, 0, .8); }
.findings.on { opacity: 1; }
.findings[hidden] { display: none; }

.findings-frame {
  position: relative;
  width: min(620px, 100%);
  padding: clamp(24px, 4vw, 34px) clamp(20px, 4vw, 32px) 26px;
  background: var(--paper-raised);
  border: 1px solid var(--rule-strong);
  border-radius: 2px;
  box-shadow: var(--shadow-deep);
  transform: translateY(12px);
  transition: transform .26s var(--ease-back);
}
.findings.on .findings-frame { transform: none; }

.findings-close {
  position: absolute;
  top: 12px; right: 12px;
  width: 30px; height: 30px;
  display: grid;
  place-items: center;
  border: 1px solid var(--rule);
  border-radius: 2px;
  background: transparent;
  color: var(--ink-soft);
  font-size: .9rem;
  line-height: 1;
  transition: color .14s, border-color .14s, background .14s;
}
.findings-close:hover {
  color: var(--ink);
  border-color: var(--ink);
  background: var(--highlight-a);
}

.findings-head { margin-bottom: 18px; }
.findings-head h2 {
  font-size: clamp(1.5rem, 4.6vw, 1.95rem);
  margin: 5px 0 0;
}
.findings-head .entry-sub { margin: 4px 0 0; font-size: 1.22rem; }

/* --- progress ---------------------------------------------------------- */

.findings-progress {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0 16px;
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  margin-bottom: 18px;
}
.findings-bar {
  flex: 1 1 auto;
  height: 8px;
  background: var(--paper-deep);
  border: 1px solid var(--rule);
  overflow: hidden;
}
.findings-bar span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--red);
  transition: width .5s var(--ease-out);
}
.findings-progress .mono {
  flex: none;
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .04em;
  color: var(--ink-soft);
}

/* --- list -------------------------------------------------------------- */

.findings-list { display: grid; gap: 20px; }

.find-group-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 7px;
  margin-bottom: 9px;
  border-bottom: 1px dashed var(--rule-strong);
}
.find-group-score { font-size: .68rem; font-weight: 700; color: var(--red); }

.find-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 6px 0;
}
.find-mark {
  flex: none;
  width: 12px;
  text-align: center;
  font-size: .82rem;
  line-height: 1.5;
  color: var(--ink-faint);
}
.find-body { min-width: 0; }
.find-title {
  font-size: .9rem;
  line-height: 1.45;
  /* Locked rows show their hint here, in the annotation hand — so an
     unfinished list reads as a set of things to try, not a row of blanks. */
  font-family: var(--f-hand);
  font-size: 1.14rem;
  color: var(--ink-soft);
}
.find-note {
  margin-top: 2px;
  font-size: .84rem;
  line-height: 1.45;
  color: var(--ink-soft);
}

/* Found rows switch from handwriting to print: the note has been written up. */
.find-row.found .find-mark { color: var(--red); }
.find-row.found .find-title {
  font-family: var(--f-prose);
  font-size: .96rem;
  font-weight: 600;
  color: var(--ink);
}

.findings-foot {
  margin: 20px 0 0;
  padding-top: 14px;
  border-top: 1px solid var(--rule);
  font-size: 1.12rem;
}

/* ============================================================== responsive */

@media (max-width: 640px) {
  .console-frame { height: 100%; }
  .console-frame::before, .console-frame::after { width: 11px; }
  .console-screen { padding: 13px 18px; font-size: .75rem; }
  .console-input-row { padding: 10px 18px; }
  .console-keys { padding: 6px 18px 8px; gap: 10px; }
  .console-bar { padding-left: 18px; }
  .console-prompt, #console-input { font-size: .75rem; }
}

/* A short landscape phone has no room for the key hints. */
@media (max-height: 460px) {
  .console-keys { display: none; }
}
