/* ============================================================
   LEX: WIZARD OF WORDS — CGA Stylesheet
   Palette: CGA mode 4, palette 0, high intensity.
   Four colours only; depth comes from dither, glow and motion.
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&family=VT323&display=swap');

:root {
  --k:  #000000;   /* black   */
  --r:  #ff5555;   /* salmon  */
  --g:  #55ff55;   /* green   */
  --y:  #ffff55;   /* yellow  */

  --r-dim: rgba(255, 85, 85, 0.35);
  --g-dim: rgba(85, 255, 85, 0.30);
  --y-dim: rgba(255, 255, 85, 0.30);

  --font-pixel: 'Press Start 2P', monospace;
  --font-term:  'VT323', monospace;
}

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

html, body {
  width: 100%; height: 100%;
  background: var(--k);
  color: var(--r);
  font-family: var(--font-term);
  font-size: 20px;
  overflow: hidden;
}

/* CRT scanlines */
body::after {
  content: '';
  position: fixed; inset: 0;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0px, transparent 2px,
    rgba(0,0,0,0.28) 2px, rgba(0,0,0,0.28) 4px
  );
  pointer-events: none;
  z-index: 9999;
}

#app {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  padding: 12px;
}

.screen {
  width: 100%;
  max-width: 860px;
  height: 100%;
  max-height: 660px;
  display: flex;
  flex-direction: column;
  border: 2px solid var(--r);
  box-shadow: 0 0 24px var(--r-dim), inset 0 0 60px rgba(255,85,85,0.05);
  background: var(--k);
  animation: fadeIn 0.25s ease;
  overflow: hidden;
}

@keyframes fadeIn {
  from { opacity: 0; } to { opacity: 1; }
}

/* ── Typography ──────────────────────────────────────────── */
.px { font-family: var(--font-pixel); }

.term {
  font-family: var(--font-term);
  font-size: 26px;
  line-height: 1.35;
  color: var(--y);
}

.t-r { color: var(--r); }
.t-g { color: var(--g); }
.t-y { color: var(--y); }

.glow-r { text-shadow: 0 0 10px var(--r-dim); }
.glow-g { text-shadow: 0 0 10px var(--g-dim); }
.glow-y { text-shadow: 0 0 10px var(--y-dim); }

.blink { animation: blink 1s step-end infinite; }
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }

/* ── SVG text classes (used inside sprites) ─────────────── */
.svg-sign-val {
  font-family: var(--font-pixel);
  font-size: 15px;
  fill: var(--y);
}
.svg-chest {
  font-family: var(--font-pixel);
  font-size: 13px;
  fill: var(--k);
}
/* outlined so it stays legible over the patterned robes */
.svg-cloak {
  font-family: var(--font-pixel);
  font-size: 26px;
  fill: var(--y);
  stroke: var(--k);
  stroke-width: 5px;
  paint-order: stroke fill;
}
.svg-trailsign {
  font-family: var(--font-term);
  font-size: 15px;
  fill: var(--y);
}

/* ── Landscape band (top ~25%) ──────────────────────────── */
.land-band {
  flex: 0 0 25%;
  min-height: 108px;
  position: relative;
  border-bottom: 2px solid var(--r);
  overflow: hidden;
}

.forest-svg { width: 100%; height: 100%; display: block; }

/* Lives and score must stay readable over a busy landscape, so this sits
   on solid black rather than tinted over the trees. */
.band-status {
  position: absolute;
  top: 8px; right: 10px;
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--k);
  border: 2px solid var(--y);
  box-shadow: 0 0 12px var(--y-dim);
  padding: 5px 12px;
}

.bs-item { display: flex; align-items: center; gap: 7px; }

.bs-label {
  font-family: var(--font-pixel);
  font-size: 7px;
  color: var(--g);
  letter-spacing: 1px;
}

.bs-rule {
  width: 2px;
  align-self: stretch;
  background: var(--y);
  opacity: 0.4;
}

.band-status .lives {
  font-size: 22px;
  line-height: 1;
  letter-spacing: 2px;
}

.band-status .score {
  font-family: var(--font-term);
  font-size: 24px;
  line-height: 1;
  color: var(--y);
}

/* a life just lost flashes before settling to its spent state */
.life-spent { color: rgba(255,85,85,0.22); }
.life-held  { color: var(--r); text-shadow: 0 0 8px var(--r-dim); }

/* ── Character stage (middle ~62%) ──────────────────────── */
.stage {
  flex: 1 1 auto;
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  padding: 10px 14px 0;
  min-height: 0;
}

/* -- warden side (question sign + figure) -- */
.warden-side {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  min-width: 0;
  min-height: 0;
}

.sign-board {
  /* sized to its text, and free to reach out across the VLUP wardens
     when the prompt is long — the Tower's definitions and heteronyms
     are far too wide for the warden's own column */
  width: max-content;
  max-width: 100%;
  /* at least as wide as the warden's hand span, so the hands always
     meet the board rather than reaching into empty space */
  min-width: 190px;
  position: relative;
  z-index: 3;
  border: 3px solid var(--y);
  background: var(--k);
  padding: 10px 16px;
  box-shadow: 0 0 16px var(--y-dim), 0 0 0 6px var(--k);
  animation: signIn 0.28s ease;
}

/* long prompts overhang the wardens rather than wrapping into a column */
.sign-board.is-long,
.sign-board.is-teach {
  max-width: min(660px, 86vw);
}

@keyframes signIn {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Questions must never be clipped — the board wraps and grows instead.
   Long riddles simply start at a smaller size. */
.sign-text {
  font-family: var(--font-term);
  font-size: clamp(20px, 3.2vw, 32px);
  color: var(--y);
  line-height: 1.25;
  letter-spacing: 1px;
  white-space: normal;
  overflow-wrap: break-word;
}

.sign-text.is-long { font-size: clamp(17px, 2.3vw, 24px); }

.sign-kicker {
  font-family: var(--font-pixel);
  font-size: 7px;
  color: var(--g);
  letter-spacing: 1px;
  margin-bottom: 6px;
}

/* the board while the serpent's lesson is being shown */
.sign-board.is-teach {
  border-color: var(--g);
  box-shadow: 0 0 22px var(--g-dim);
}

/* A pixel font at 3px tracking runs out of room fast — SIMULTANEOUSLY is
   14 characters — so this stays modest and is allowed to wrap. */
.teach-answer {
  font-family: var(--font-pixel);
  font-size: clamp(10px, 1.7vw, 15px);
  color: var(--g);
  letter-spacing: 2px;
  line-height: 1.5;
  margin-top: 10px;
  max-width: 100%;
  overflow-wrap: anywhere;
  text-shadow: 0 0 14px var(--g-dim);
  animation: teachPop 0.4s ease;
}

@keyframes teachPop {
  0%   { opacity: 0; transform: scale(0.85); }
  60%  { transform: scale(1.06); }
  100% { opacity: 1; transform: scale(1); }
}

/* the same question, asked a second time */
.sign-board.is-retry { border-color: var(--g); }
.sign-board.is-retry .sign-kicker { color: var(--y); }

/* the warden stands directly under its sign, hands to the board */
/* the figure's hands are drawn at the very top of its viewBox, so
   pulling it up under the board makes them grip its bottom edge */
.warden-svg {
  height: 100%;
  max-height: 260px;
  /* keeps the figure readable when a long riddle grows the board */
  min-height: 118px;
  width: auto;
  margin-top: -13px;
  margin-left: 26px;
  flex: 1 1 auto;
}

/* the serpent looms larger than the wardens — it is the last gate */
.serpent-svg {
  max-height: 300px;
  min-height: 150px;
  margin-left: 8px;
  animation: serpentIn 0.45s ease;
  filter: drop-shadow(0 0 14px var(--g-dim));
}
@keyframes serpentIn {
  0%   { opacity: 0; transform: translateY(14px) scale(0.92); }
  60%  { transform: translateY(0) scale(1.03); }
  100% { opacity: 1; transform: scale(1); }
}

/* -- VLUP rank -- */
.vlup-rank {
  display: flex;
  align-items: flex-end;
  gap: clamp(2px, 1vw, 10px);
  min-height: 0;
}

.vlup-svg {
  height: 100%;
  max-height: 300px;
  width: auto;
  transition: filter 0.35s ease;
  filter: grayscale(0.55) brightness(0.55);
}

.vlup-svg.is-revealed {
  filter: none;
  animation: vlupReveal 0.45s ease;
}

@keyframes vlupReveal {
  0%   { filter: grayscale(0.55) brightness(0.55); }
  45%  { filter: brightness(1.7) drop-shadow(0 0 10px var(--y)); }
  100% { filter: none; }
}

/* -- props -- */
.prop {
  position: absolute;
  bottom: 4px;
  opacity: 0.9;
}
.prop-scroll { right: 10px; }
.prop-trophy { left: 10px; }
.prop-svg { height: 44px; width: auto; display: block; }
.prop-trophy .prop-svg { height: 50px; }

/* ── Answer bar (bottom ~13%) ───────────────────────────── */
.answer-bar {
  flex: 0 0 auto;
  border-top: 2px solid var(--r);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px 10px;
  background: var(--k);
}

.answer-label {
  font-family: var(--font-term);
  font-size: clamp(22px, 3vw, 30px);
  color: var(--y);
  white-space: nowrap;
}

/* the teach line names a whole word, so it wraps instead of clipping */
.answer-label.answer-teach {
  white-space: normal;
  font-size: clamp(19px, 2.5vw, 26px);
  line-height: 1.3;
}

.answer-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  font-family: var(--font-term);
  font-size: clamp(22px, 3vw, 30px);
  color: var(--y);
  caret-color: var(--y);
  letter-spacing: 2px;
  text-transform: lowercase;
  min-width: 0;
}

.answer-input::placeholder { color: rgba(255,255,85,0.3); }

.answer-verdict {
  font-family: var(--font-term);
  font-size: clamp(22px, 3vw, 30px);
  white-space: normal;
  overflow-wrap: anywhere;
  animation: verdictIn 0.2s ease;
}
.answer-verdict.ok  { color: var(--g); text-shadow: 0 0 12px var(--g-dim); }
.answer-verdict.bad { color: var(--r); text-shadow: 0 0 12px var(--r-dim); }

@keyframes verdictIn {
  from { opacity: 0; transform: translateX(8px); }
  to   { opacity: 1; transform: translateX(0); }
}

.timer-chip {
  font-family: var(--font-pixel);
  font-size: 9px;
  color: var(--g);
  border: 1px solid var(--g);
  padding: 4px 7px;
  white-space: nowrap;
}
.timer-chip.urgent {
  color: var(--r);
  border-color: var(--r);
  animation: timerPulse 0.5s ease infinite alternate;
}
@keyframes timerPulse {
  from { box-shadow: none; }
  to   { box-shadow: 0 0 12px var(--r-dim); }
}

/* ── Buttons ─────────────────────────────────────────────── */
button {
  font-family: var(--font-pixel);
  font-size: 9px;
  cursor: pointer;
  border: 2px solid var(--y);
  color: var(--y);
  background: transparent;
  padding: 10px 18px;
  letter-spacing: 1px;
  text-transform: uppercase;
  transition: all 0.12s ease;
}
button:hover { background: rgba(255,255,85,0.12); box-shadow: 0 0 16px var(--y-dim); }
button:active { transform: translateY(2px); }

.btn-g { border-color: var(--g); color: var(--g); }
.btn-g:hover { background: rgba(85,255,85,0.12); box-shadow: 0 0 16px var(--g-dim); }

.btn-r { border-color: var(--r); color: var(--r); font-size: 8px; padding: 8px 14px; }
.btn-r:hover { background: rgba(255,85,85,0.12); box-shadow: 0 0 16px var(--r-dim); }

/* ── Title / splash screen ──────────────────────────────── */
.splash {
  flex: 1;
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  grid-template-rows: 1fr auto;
  gap: 12px;
  padding: 14px;
  min-height: 0;
}

.splash-logo {
  border: 2px solid var(--r);
  display: flex; align-items: center; justify-content: center;
  padding: 10px;
  min-height: 0;
}

.logo-svg { width: 100%; height: 100%; max-height: 300px; }

.cobra { animation: cobraSway 3.4s ease-in-out infinite alternate; transform-origin: 34px 120px; }
@keyframes cobraSway {
  from { transform: rotate(-2deg); }
  to   { transform: rotate(2deg); }
}

.splash-pub {
  border: 2px solid var(--r);
  padding: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-align: center;
}

.pub-badge {
  border: 2px solid var(--r);
  background: rgba(255,85,85,0.12);
  padding: 8px 10px;
  width: 100%;
}
.pub-badge .pub-small {
  font-family: var(--font-pixel);
  font-size: 6px;
  color: var(--r);
  letter-spacing: 1px;
  line-height: 1.9;
}
.pub-badge .pub-name {
  font-family: var(--font-pixel);
  font-size: clamp(11px, 2vw, 17px);
  color: var(--r);
  letter-spacing: 2px;
  margin: 4px 0;
}
.splash-pub .pub-credit {
  font-family: var(--font-term);
  font-size: 20px;
  color: var(--r);
  line-height: 1.25;
}

.splash-welcome {
  grid-column: 1 / -1;
  border: 2px solid var(--r);
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.welcome-text {
  font-family: var(--font-term);
  font-size: clamp(19px, 2.4vw, 26px);
  color: var(--r);
  line-height: 1.3;
}

.name-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.name-input {
  flex: 1;
  min-width: 140px;
  background: transparent;
  border: none; outline: none;
  border-bottom: 2px solid var(--y);
  font-family: var(--font-term);
  font-size: 26px;
  color: var(--y);
  caret-color: var(--y);
  letter-spacing: 2px;
  padding: 2px 6px;
}

/* ── Panel screens (map, intro, result) ─────────────────── */
.sheet {
  flex: 1;
  margin: 14px;
  border: 2px solid var(--r);
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--r) transparent;
}
.sheet::-webkit-scrollbar { width: 5px; }
.sheet::-webkit-scrollbar-thumb { background: var(--r); }

.sheet--g { border-color: var(--g); box-shadow: inset 0 0 40px rgba(85,255,85,0.05); }
.sheet--y { border-color: var(--y); box-shadow: inset 0 0 40px rgba(255,255,85,0.05); }

.heading {
  font-family: var(--font-pixel);
  font-size: clamp(9px, 1.8vw, 13px);
  color: var(--y);
  letter-spacing: 2px;
  margin-bottom: 4px;
}

.rule { border: none; border-top: 2px solid var(--r); margin: 12px 0; }
.rule--g { border-color: var(--g); }
.rule--y { border-color: var(--y); }

.speech {
  border-left: 3px solid var(--g);
  padding: 8px 14px;
  margin-top: 10px;
  font-family: var(--font-term);
  font-size: 24px;
  color: var(--g);
}

/* ── Trail map ───────────────────────────────────────────── */
.map-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.trail-card {
  border: 2px solid var(--r);
  padding: 10px 12px;
  cursor: pointer;
  transition: all 0.14s ease;
  background: rgba(255,85,85,0.04);
}
.trail-card:hover:not(.locked),
.trail-card:focus-visible {
  box-shadow: 0 0 16px var(--y-dim);
  border-color: var(--y);
  outline: none;
}

.trail-card:focus-visible { box-shadow: 0 0 22px var(--y); }
.trail-card.done   { border-color: var(--g); background: rgba(85,255,85,0.06); }
.trail-card.active { border-color: var(--y); box-shadow: 0 0 14px var(--y-dim); }
.trail-card.locked { opacity: 0.35; cursor: not-allowed; }

.trail-card .tc-num {
  font-family: var(--font-pixel);
  font-size: 7px; color: var(--g); margin-bottom: 4px;
}
.trail-card .tc-name {
  font-family: var(--font-term); font-size: 24px; color: var(--y);
}
.trail-card .tc-warden {
  font-family: var(--font-term); font-size: 19px; color: var(--r);
}
.trail-card .tc-state {
  font-family: var(--font-pixel); font-size: 7px; margin-top: 6px;
}
.trail-card.done   .tc-state { color: var(--g); }
.trail-card.active .tc-state { color: var(--y); }
.trail-card.locked .tc-state { color: var(--r); }

/* ── Big centred messages ───────────────────────────────── */
.big-title {
  font-family: var(--font-pixel);
  font-size: clamp(14px, 3.4vw, 26px);
  letter-spacing: 4px;
  text-align: center;
  line-height: 1.7;
}
.big-title.win  { color: var(--y); animation: winGlow 1.5s ease infinite alternate; }
.big-title.lose { color: var(--r); text-shadow: 0 0 22px var(--r-dim); }

@keyframes winGlow {
  from { text-shadow: 0 0 10px var(--y-dim); }
  to   { text-shadow: 0 0 34px var(--y), 0 0 60px var(--y-dim); }
}

.center-stack {
  flex: 1;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 18px; text-align: center;
}

/* ── Utilities ───────────────────────────────────────────── */
.row { display: flex; }
.col { display: flex; flex-direction: column; }
.between { justify-content: space-between; }
.center { align-items: center; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.push { margin-top: auto; }
.tc { text-align: center; }

/* ── Narrow screens ─────────────────────────────────────── */
@media (max-width: 720px) {
  .splash { grid-template-columns: 1fr; grid-template-rows: auto auto auto; }
  .splash-pub { display: none; }
  .stage { grid-template-columns: 1fr; }
  .vlup-rank { justify-content: center; }
  .vlup-svg { max-height: 150px; }
  .warden-svg { max-height: 150px; }
  .land-band { flex-basis: 20%; min-height: 84px; }
}
