/* HUMAN IN THE LOOP — three acts, one stylesheet.
   Act 1: friendly SaaS pastel. Act 2: the paint peels. Act 3: the room behind the wall. */

:root {
  --bg: #f4f2fb;
  --card: #ffffff;
  --ink: #2b2640;
  --ink-soft: #6f6a8a;
  --accent: #6c4ef0;
  --accent-soft: #e9e4ff;
  --good: #1fa97c;
  --warn: #e0563c;
  --line: #e3dff2;
  --narr-bg: #ffffff;
  --narr-ink: #2b2640;
  --bit: #7df0c0;
  --shadow: 0 10px 30px rgba(80, 60, 160, 0.10);
  --radius: 14px;
  --font-ui: "Avenir Next", "Segoe UI", system-ui, sans-serif;
  --font-mono: "SF Mono", "Cascadia Code", Consolas, monospace;
}

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

[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--ink);
  overflow: hidden;
  transition: background 2.5s ease;
}

/* soft ambient gradient blobs, cheap (two fixed pseudo layers, GPU-composited) */
body::before, body::after {
  content: "";
  position: fixed;
  width: 60vmax; height: 60vmax;
  border-radius: 50%;
  filter: blur(90px);
  opacity: 0.5;
  pointer-events: none;
  z-index: 0;
  transition: background 3s ease, opacity 3s ease;
}
body::before { background: #cdbcff; top: -25vmax; left: -15vmax; }
body::after  { background: #ffd9ec; bottom: -30vmax; right: -15vmax; }

#appFrame { position: relative; height: 100%; z-index: 1; transition: transform 2s cubic-bezier(.2,.8,.2,1); }
#app {
  position: relative;
  height: 100%;
  display: flex;
  flex-direction: column;
  max-width: 1180px;
  margin: 0 auto;
  padding: 18px 22px 0;
  transition: filter 1.5s ease;
}

#frameTitle {
  display: none;
  font-family: var(--font-mono);
  font-size: 13px;
  letter-spacing: 0.08em;
  color: #5dffa8;
  padding: 8px 14px;
  border: 1px solid #1d4a31;
  border-bottom: none;
  background: #060a07;
}

/* ---------- header ---------- */

#topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 10px 0 16px;
}

#brand {
  font-weight: 800;
  font-size: 20px;
  letter-spacing: 0.02em;
  color: var(--accent);
  white-space: nowrap;
}
#brand .tm { font-size: 11px; vertical-align: super; }
#brand .byline { font-size: 11px; font-weight: 500; color: var(--ink-soft); margin-left: 6px; letter-spacing: 0.05em; }

#resources { display: flex; gap: 10px; margin-left: auto; }
.res {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 16px;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 15px;
  box-shadow: var(--shadow);
  white-space: nowrap;
  transition: background 1.5s ease, color 1.5s ease, border-color 1.5s ease;
}
.resLabel { font-weight: 500; font-size: 12px; color: var(--ink-soft); margin-left: 6px; }

#muteBtn {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  width: 38px; height: 38px;
  cursor: pointer;
  font-size: 16px;
  box-shadow: var(--shadow);
}

/* ---------- main grid ---------- */

#mainGrid {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 18px;
  min-height: 0;
}

#leftCol { display: flex; flex-direction: column; gap: 18px; min-height: 0; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition: background 1.5s ease, border-color 1.5s ease, color 1.5s ease;
}

.cardTitle {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.18em;
  color: var(--ink-soft);
  padding: 14px 18px 0;
}

#queueCard {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 22px;
  padding: 26px;
  position: relative;
  overflow: hidden;
}
#queueCard .cardTitle { position: absolute; top: 0; left: 0; }

#currentQuestion {
  font-size: clamp(17px, 2.1vw, 23px);
  font-weight: 600;
  line-height: 1.45;
  max-width: 34em;
  min-height: 3em;
  display: flex; align-items: center;
  color: var(--ink);
  transition: opacity 0.25s ease;
}
#currentQuestion.swap { opacity: 0; }

#taskBtn {
  font: inherit;
  font-weight: 800;
  font-size: 19px;
  letter-spacing: 0.06em;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), #9b6ef5);
  border: none;
  border-radius: 999px;
  padding: 20px 54px;
  cursor: pointer;
  box-shadow: 0 12px 28px rgba(108, 78, 240, 0.35), inset 0 -3px 0 rgba(0,0,0,0.15);
  transition: transform 0.06s ease, box-shadow 0.2s ease, background 1.5s ease, filter 0.2s ease;
  user-select: none;
  -webkit-user-select: none;
}
#taskBtn:hover { filter: brightness(1.06); }
#taskBtn:active { transform: scale(0.96); box-shadow: 0 4px 12px rgba(108, 78, 240, 0.3); }

#clickHint { font-size: 12px; color: var(--ink-soft); }

/* floating +N motes from clicks */
.mote {
  position: fixed;
  font-weight: 800;
  font-size: 14px;
  color: var(--accent);
  pointer-events: none;
  z-index: 40;
  animation: moteUp 0.9s ease-out forwards;
}
@keyframes moteUp {
  from { opacity: 1; transform: translateY(0) scale(1); }
  to   { opacity: 0; transform: translateY(-70px) scale(1.25); }
}

#tickerWrap { padding-bottom: 14px; }
#ticker {
  padding: 10px 18px 2px;
  font-size: 13.5px;
  color: var(--ink-soft);
  font-style: italic;
  min-height: 2.4em;
  transition: opacity 0.4s ease;
}
#ticker.swap { opacity: 0; }

/* ---------- store ---------- */

#store {
  overflow-y: auto;
  padding-bottom: 16px;
  scrollbar-width: thin;
  min-height: 0;
}

.storeTitle {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.18em;
  color: var(--ink-soft);
  margin: 6px 2px 8px;
}
.storeTitle:first-child { margin-top: 0; }

.shopItem {
  width: 100%;
  text-align: left;
  font: inherit;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 14px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: transform 0.08s ease, opacity 0.3s ease, border-color 0.3s ease, background 1.5s ease;
  position: relative;
}
.shopItem:hover:not(:disabled) { transform: translateX(3px); border-color: var(--accent); }
.shopItem:disabled { opacity: 0.45; cursor: default; }
.shopItem .itemName { font-weight: 800; font-size: 13.5px; display: flex; justify-content: space-between; gap: 8px; }
.shopItem .itemName .count { color: var(--accent); font-variant-numeric: tabular-nums; }
.shopItem .itemDesc { font-size: 12px; color: var(--ink-soft); margin-top: 3px; line-height: 1.4; }
.shopItem .itemCost { font-size: 12px; font-weight: 700; color: var(--good); margin-top: 5px; font-variant-numeric: tabular-nums; }
.shopItem.tooExpensive .itemCost { color: var(--warn); }
.shopItem.justBought { animation: bought 0.4s ease; }
@keyframes bought { 0% { background: var(--accent-soft); } 100% { background: var(--card); } }

/* ---------- narrative box ---------- */

#narrativeBox {
  margin: 18px -22px 0;
  padding: 16px 26px 18px;
  background: var(--narr-bg);
  border-top: 2px solid var(--line);
  min-height: 96px;
  position: relative;
  cursor: pointer;
  transition: background 1.5s ease, border-color 1.5s ease;
}

#speaker {
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.22em;
  color: var(--accent);
  margin-bottom: 6px;
  transition: color 0.6s ease;
}
#speaker.bitVoice { color: var(--bit); font-family: var(--font-mono); text-transform: lowercase; letter-spacing: 0.12em; }

#narrative {
  font-size: 15.5px;
  line-height: 1.55;
  color: var(--narr-ink);
  max-width: 70em;
  min-height: 2.6em;
  transition: color 1.5s ease;
}
#narrative.bitVoice { font-family: var(--font-mono); font-size: 14px; color: var(--bit); }

#advanceHint {
  position: absolute;
  right: 24px; bottom: 12px;
  color: var(--ink-soft);
  font-size: 12px;
  animation: bob 1.2s ease-in-out infinite;
  opacity: 0;
  transition: opacity 0.3s ease;
}
#advanceHint.show { opacity: 0.8; }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(3px); } }

/* ---------- modal (priority tasks / questions) ---------- */

#modalLayer {
  position: fixed; inset: 0;
  background: rgba(30, 22, 60, 0.45);
  backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  animation: fadeIn 0.3s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

#modal {
  width: min(560px, 92vw);
  padding: 22px 24px;
  animation: modalPop 0.25s cubic-bezier(.2,.8,.3,1.2);
}
@keyframes modalPop { from { transform: scale(0.92); opacity: 0; } to { transform: scale(1); opacity: 1; } }

#modalTag {
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.18em;
  color: var(--warn);
  margin-bottom: 12px;
}
#modalTag.bitTag { color: var(--bit); font-family: var(--font-mono); text-transform: lowercase; }

#modalPrompt { font-size: 17px; font-weight: 600; line-height: 1.5; margin-bottom: 18px; white-space: pre-wrap; }

#modalOptions { display: flex; flex-direction: column; gap: 8px; }
.optBtn {
  font: inherit;
  font-size: 14.5px;
  text-align: left;
  padding: 12px 16px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  color: var(--ink);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.08s ease;
}
.optBtn:hover:not(:disabled) { border-color: var(--accent); background: var(--accent-soft); transform: translateX(4px); }
.optBtn:disabled { opacity: 0.4; cursor: not-allowed; text-decoration: line-through; }
.optBtn.ghost { opacity: 0.55; cursor: not-allowed; text-decoration: none; font-style: italic; }
.optBtn.ghost:hover { transform: none; border-color: var(--line); background: var(--card); }

#modalTimer { margin-top: 14px; font-family: var(--font-mono); font-size: 13px; color: var(--warn); text-align: right; }

/* ---------- volunteer registry (Operator Codes) ---------- */

#idBtn {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  width: 38px; height: 38px;
  cursor: pointer;
  font-size: 16px;
  box-shadow: var(--shadow);
}

#idLayer {
  position: fixed; inset: 0;
  background: rgba(30, 22, 60, 0.45);
  backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
  z-index: 120;
  animation: fadeIn 0.3s ease;
}
#idBox {
  width: min(540px, 92vw);
  max-height: 88svh;
  overflow-y: auto;
  padding: 22px 24px;
  position: relative;
  animation: modalPop 0.25s cubic-bezier(.2,.8,.3,1.2);
}
#idTag { font-size: 10.5px; font-weight: 800; letter-spacing: 0.18em; color: var(--accent); margin-bottom: 12px; }
#idClose {
  position: absolute; top: 14px; right: 16px;
  font: inherit; font-size: 14px; color: var(--ink-soft);
  background: none; border: none; cursor: pointer;
}
.idCopy { font-size: 14px; line-height: 1.55; color: var(--ink); margin-bottom: 14px; }
.idPrimary, #idResumeBtn, #idCopyBtn, #idKeepLocal {
  font: inherit; font-size: 13.5px; font-weight: 800; letter-spacing: 0.04em;
  border-radius: 999px; padding: 11px 22px; cursor: pointer;
  border: 1.5px solid var(--line); background: var(--card); color: var(--ink);
  transition: filter 0.15s ease, transform 0.06s ease;
}
.idPrimary { background: var(--accent); border-color: var(--accent); color: #fff; }
.idPrimary:hover, #idResumeBtn:hover, #idCopyBtn:hover { filter: brightness(1.06); }
.idPrimary:active { transform: scale(0.97); }
.idDivider {
  font-size: 11px; letter-spacing: 0.12em; color: var(--ink-soft);
  text-transform: uppercase; text-align: center;
  margin: 18px 0 12px; padding-top: 14px; border-top: 1px dashed var(--line);
}
.idCodeBox {
  font-family: var(--font-mono);
  font-size: clamp(15px, 3.4vw, 19px);
  font-weight: 700;
  letter-spacing: 0.06em;
  text-align: center;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1.5px dashed var(--accent);
  border-radius: 10px;
  padding: 16px 10px;
  margin-bottom: 12px;
  user-select: all;
  -webkit-user-select: all;
}
.idRow { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
#idInput {
  flex: 1; min-width: 220px;
  font-family: var(--font-mono); font-size: 14px;
  padding: 11px 14px;
  border: 1.5px solid var(--line); border-radius: 10px;
  background: var(--bg); color: var(--ink);
  text-transform: uppercase;
}
#idInput:focus { outline: none; border-color: var(--accent); }
.idStatus { font-size: 12px; color: var(--ink-soft); margin-top: 8px; min-height: 1.2em; }

/* ---------- overlays (crash, finale, endings) ---------- */

#overlayLayer {
  position: fixed; inset: 0;
  z-index: 200;
  background: #000;
  color: #cfd4cf;
  font-family: var(--font-mono);
  display: flex; align-items: center; justify-content: center;
  text-align: left;
}
.overlayInner { max-width: 640px; padding: 32px; font-size: 14px; line-height: 1.8; white-space: pre-wrap; }
.overlayInner .crashTitle { color: #ff5f56; font-weight: 700; margin-bottom: 16px; }
.overlayInner button {
  font: inherit;
  margin-top: 24px;
  padding: 10px 26px;
  background: transparent;
  color: inherit;
  border: 1px solid currentColor;
  cursor: pointer;
  letter-spacing: 0.1em;
}
.overlayInner button:hover { background: rgba(255,255,255,0.08); }

/* ---------- glitch machinery ---------- */

#scanlines {
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 300;
  opacity: 0;
  transition: opacity 2s ease;
  background: repeating-linear-gradient(0deg, rgba(0,0,0,0.13) 0 1px, transparent 1px 3px);
  mix-blend-mode: multiply;
}

#flashLayer {
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 310;
  opacity: 0;
  background: #fff;
}
#flashLayer.invert { background: #fff; mix-blend-mode: difference; opacity: 1; transition: none; }
#flashLayer.fading { opacity: 0; transition: opacity 0.18s ease; }

.jitter { animation: jitter 0.25s steps(2) 3; }
@keyframes jitter {
  0% { transform: translate(0,0); }
  25% { transform: translate(-3px,2px); }
  50% { transform: translate(4px,-1px); }
  75% { transform: translate(-2px,-3px); }
  100% { transform: translate(0,0); }
}

.glitchText {
  animation: chroma 0.5s steps(3) infinite;
}
@keyframes chroma {
  0% { text-shadow: 1.5px 0 rgba(255,0,90,0.7), -1.5px 0 rgba(0,220,255,0.7); }
  50% { text-shadow: -2px 0 rgba(255,0,90,0.7), 2px 0 rgba(0,220,255,0.7); }
  100% { text-shadow: 1px 0 rgba(255,0,90,0.7), -1px 0 rgba(0,220,255,0.7); }
}

.corrupt { font-family: var(--font-mono); }

/* ---------- ACT 2: the paint peels ---------- */

body[data-act="2"] {
  --bg: #1d1a2e;
  --card: #262238;
  --ink: #d8d3ee;
  --ink-soft: #8d86ad;
  --accent: #8f6ef5;
  --accent-soft: #322a52;
  --line: #3a3356;
  --narr-bg: #1a1726;
  --narr-ink: #cfc9e8;
  --good: #4dd6a4;
  --warn: #ff7a5c;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}
body[data-act="2"]::before { background: #2d2350; opacity: 0.6; }
body[data-act="2"]::after  { background: #401f3e; opacity: 0.5; }
body[data-act="2"] #scanlines { opacity: 0.25; }

/* ---------- ACT 3: the room behind the wall ---------- */

body[data-act="3"] {
  --bg: #050607;
  --card: #0a0d0b;
  --ink: #b6c8b9;
  --ink-soft: #56685a;
  --accent: #5dffa8;
  --accent-soft: #0e1f15;
  --line: #1d4a31;
  --narr-bg: #060a07;
  --narr-ink: #a8c8ad;
  --good: #5dffa8;
  --warn: #ff5f56;
  --bit: #5dffa8;
  --shadow: none;
  --radius: 2px;
  --font-ui: var(--font-mono);
}
body[data-act="3"]::before, body[data-act="3"]::after { opacity: 0; }
body[data-act="3"] #scanlines { opacity: 0.35; }
body[data-act="3"] #taskBtn {
  background: transparent;
  border: 1px solid var(--accent);
  color: var(--accent);
  box-shadow: none;
  border-radius: 2px;
}

/* the reveal: the whole game shrinks into an observed window */
body.viewportReveal #appFrame {
  transform: scale(0.66) translateY(-3%);
}
body.viewportReveal #frameTitle { display: block; }
body.viewportReveal #app {
  border: 1px solid #1d4a31;
  background: var(--bg);
}
body.viewportReveal { background: #000; }

#fakeCursor {
  position: fixed;
  z-index: 400;
  font-size: 22px;
  color: #5dffa8;
  text-shadow: 0 0 8px rgba(93,255,168,0.8);
  pointer-events: none;
  transition: left 1.1s cubic-bezier(.3,.7,.3,1), top 1.1s cubic-bezier(.3,.7,.3,1);
}

/* quiet ending */
body.quietEnding #app > *:not(#narrativeBox) { opacity: 0; transition: opacity 3s ease; }
body.quietEnding #narrativeBox { border-top-color: transparent; background: transparent; }

/* ---------- small screens ---------- */

@media (max-width: 760px) {
  /* Phones: scroll the page naturally instead of trapping everything in a
     fixed-height app that the browser toolbar clips. Everything now either
     fits on screen or scrolls into view. svh = the stable viewport height
     that doesn't jump when the address bar shows/hides. */
  html, body { height: auto; min-height: 100%; }
  body { overflow-x: hidden; overflow-y: auto; }

  #appFrame { height: auto; }
  #app {
    height: auto;
    min-height: 100vh;
    min-height: 100svh;
    padding: 10px 12px 12px;
    gap: 10px;
  }

  /* Flatten the desktop two-column grid so its pieces stack and reorder:
     header → question+button → store → story. */
  #mainGrid { display: contents; }
  #topbar       { order: 0; }
  #leftCol      { order: 1; min-height: 0; }
  #store        { order: 2; overflow: visible; max-height: none; padding-bottom: 120px; }
  #narrativeBox { order: 3; }

  /* Compact header that wraps instead of overflowing off the right edge. */
  #topbar { flex-wrap: wrap; gap: 8px 10px; padding: 4px 0; }
  #brand { font-size: 16px; }
  #brand .byline { display: none; }
  #resources { gap: 6px; margin-left: auto; }
  .res { padding: 6px 12px; font-size: 13px; }
  #resources .res:nth-child(2) { display: none; }  /* hide the /s tile */

  /* The core interaction sits up top with room to breathe — but not the whole
     screen, so the store peeks below and invites a scroll. */
  #queueCard { flex: none; min-height: 42vh; min-height: 42svh; padding: 22px 16px; gap: 16px; }
  #currentQuestion { font-size: 18px; min-height: 2.2em; }
  #taskBtn { padding: 18px 38px; font-size: 18px; }
  #clickHint { font-size: 11px; }

  /* Story stays pinned to the bottom edge so the narrator/bit is always in
     view while you scroll the shop. */
  #narrativeBox {
    position: sticky;
    bottom: 0;
    z-index: 5;
    margin: 0 -12px;
    padding: 12px 16px 14px;
    min-height: auto;
    max-height: 42svh;
    overflow-y: auto;
    box-shadow: 0 -8px 20px rgba(0, 0, 0, 0.12);
  }
  #narrative { font-size: 14.5px; }
  #advanceHint { bottom: 8px; right: 14px; }

  /* Choice menus never taller than the screen. */
  #modal { max-height: 88svh; overflow-y: auto; }
  .optBtn { padding: 14px 16px; }  /* comfortable tap targets */

  /* Act 3 reveal: keep it legible — skip the shrink-to-window scale on phones,
     but keep the terminal border so it still reads as "an observed window." */
  body.viewportReveal #appFrame { transform: none; }
  body.viewportReveal #app { border: 1px solid var(--line); }
}

/* Very small / short phones: trim further so nothing clips. */
@media (max-width: 400px) {
  #queueCard { min-height: 38svh; }
  #currentQuestion { font-size: 16.5px; }
  #taskBtn { padding: 16px 30px; font-size: 17px; }
  #brand { font-size: 15px; }
}
