/* Styled after TI-99/4A text adventures (Scott Adams' Adventure series, 1981):
   black text on the TI's light green, a 40-column 6x8 pixel font, the location
   at the top, a divider, then a running log ending in WHAT SHALL I DO?

   Accessibility choices that differ from the original:
   - 1.5 line height (the original packs lines with no gap).
   - Sizes in rem/%, so the visitor's browser font-size setting still applies.
   - Every text/background pair below meets WCAG AA contrast (4.5:1); see README.
   - Story text is mixed case; only commands are in capitals. */

@font-face {
  font-family: "Exhibit 99";
  src: url("fonts/exhibit99.woff") format("woff");
  font-display: block;
}

/* Fallback only: used for characters Exhibit 99 lacks (accented letters typed
   into the form, for example). SIL Open Font License, see fonts/VT323-OFL.txt. */
@font-face {
  font-family: "VT323";
  src: url("fonts/vt323.woff2") format("woff2");
  font-display: swap;
}

:root {
  /* TMS9918A palette */
  --black: #000000;
  --medium-green: #21c842;
  --light-green: #5edc78;
  --dark-blue: #5455ed;
  --light-blue: #7d76fc;
  --dark-red: #d4524d;
  --cyan: #42ebf5;
  --medium-red: #fc5554;
  --light-red: #ff7978;
  --dark-yellow: #d4c154;
  --light-yellow: #e6ce80;
  --dark-green: #21b03b;
  --magenta: #c95bba;
  --gray: #cccccc;
  --white: #ffffff;

  --font: "Exhibit 99", "VT323", "Courier New", monospace;
  --px: 0.125em;                 /* one font pixel: 8 rows per em */
}

/* Screen colors change with the situation, as in TI Adventure.
   Contrast: cyan/black 14.4:1, green/black 12:1, yellow/black 11.5:1, blue/white 5.4:1. */
body.mood-title  { --bg: var(--cyan);        --fg: var(--black); }
body.mood-normal { --bg: var(--light-green); --fg: var(--black); }
body.mood-dark   { --bg: var(--dark-blue);   --fg: var(--white); }
body.mood-win    { --bg: var(--dark-yellow); --fg: var(--black); }

* { box-sizing: border-box; }
[hidden] { display: none !important; }

/* 100% = the visitor's default (usually 16px, so 1 font pixel = 2px).
   Larger screens scale up in whole pixels where possible: 3px, then 4px. */
html { font-size: 100%; }
@media (min-width: 820px) { html { font-size: 150%; } }
@media (min-width: 1200px) and (min-height: 760px) { html { font-size: 200%; } }

html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  line-height: 1.5;
  -webkit-font-smoothing: none;
  transition: background-color 0.4s steps(2, end);
}

p { margin: 0 0 0.75em; }

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  margin: 0;
  cursor: pointer;
  text-align: left;
}

/* Inverse video for hover and keyboard focus. */
button:hover,
button:focus-visible,
.skip:hover,
.skip:focus-visible {
  background: var(--fg);
  color: var(--bg);
  outline: none;
}

.skip {
  display: block;
  width: fit-content;
  margin: 0.5em 0.5em 0 auto;
  color: var(--fg);
  font-size: 1rem;
}
@media (min-width: 820px) { .skip { font-size: 0.6667rem; } }
@media (min-width: 1200px) and (min-height: 760px) { .skip { font-size: 0.5rem; } }

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

.screen {
  max-width: calc(40ch + 2em);   /* 40 columns of text, like TI text mode, plus padding */
  margin: 0 auto;
  padding: 2em 1em;
  min-height: 80vh;
  display: flex;
  flex-direction: column;
}

#title { justify-content: space-between; text-align: center; }
#title p { margin: 0.5em 0; }
.title-body { margin: 2em 0; }
.title-name { font-size: 1.5em; }
.title-ready { align-self: center; text-align: center; margin: 2em 0; }

.bars {
  height: 3em;
  background: linear-gradient(90deg,
    var(--black) 0 7.14%, var(--medium-green) 0 14.28%, var(--light-green) 0 21.42%,
    var(--dark-blue) 0 28.56%, var(--light-blue) 0 35.7%, var(--dark-red) 0 42.84%,
    var(--medium-red) 0 49.98%, var(--light-red) 0 57.12%, var(--dark-yellow) 0 64.26%,
    var(--light-yellow) 0 71.4%, var(--dark-green) 0 78.54%, var(--magenta) 0 85.68%,
    var(--gray) 0 92.82%, var(--white) 0 100%);
}


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

.terminal {
  max-width: calc(40ch + 2em);
  margin: 0 auto;
  padding: 1.5em 1em 5em;
}

/* Breathing room above the scene, and the same gap kept when a new scene
   scrolls into view (main.js scrolls #scene to its top on every turn). */
#scene { padding-top: 0.5em; scroll-margin-top: 1.5em; }
#scene p { margin: 0 0 0.5em; }
#scene p.story { animation: print 0.2s steps(2, end) both; }
@keyframes print { from { opacity: 0; } to { opacity: 1; } }

/* The <-------> line, built from font characters by main.js. */
.divider { white-space: pre; overflow: hidden; margin: 0.25em 0 1em; }

#log .turn { margin: 0 0 0.75em; }
#log p { margin: 0; }

.prompt-q { white-space: nowrap; }

#cmd-form { display: flex; align-items: baseline; gap: 1ch; flex-wrap: nowrap; }
.cmd-wrap { position: relative; flex: 1; display: block; min-width: 4ch; }
#cmd {
  width: 100%;
  font: inherit;
  color: var(--fg);
  background: transparent;
  border: 0;
  padding: 0;
  text-transform: uppercase;    /* commands are in capitals, as in the original */
  caret-color: transparent;     /* replaced by the flashing underline below */
}
#cmd:focus { outline: none; }
/* Visible focus for the field: a full-width rule under it, plus the flashing cursor. */
.cmd-wrap:focus-within { box-shadow: 0 calc(var(--px) * 2) 0 calc(var(--px) * -1) var(--fg); }

/* Flashing underline cursor that follows the text caret. */
.cursor {
  position: absolute;
  top: 0.875em;
  left: min(calc(var(--col, 0) * 1ch), calc(100% - 1ch));
  width: 1ch;
  height: calc(var(--px) * 1.5);
  background: var(--fg);
  animation: blink 1s steps(1, end) infinite;
  pointer-events: none;
}
@keyframes blink { 50% { opacity: 0; } }
/* When the field isn't focused, show a dimmer, static cursor so it's still findable. */
.cmd-wrap:not(:focus-within) .cursor { animation: none; opacity: 0.5; }

#choices {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.25em;
  margin: 1em 0 0;
}

/* ---------- Contact form ---------- */

#contact { margin-top: 1em; }
#contact label { display: block; margin: 0.75em 0; }
#contact input,
#contact textarea {
  display: block;
  width: 100%;
  margin-top: 0.25em;
  font: inherit;
  line-height: 1.5;
  color: var(--black);
  background: var(--white);
  border: calc(var(--px) * 1) solid var(--black);
  border-radius: 0;
  padding: 0.25em 0.5ch;
  resize: vertical;
}
#contact input:focus,
#contact textarea:focus { outline: calc(var(--px) * 2) solid var(--black); outline-offset: 0; }
#contact-status { min-height: 1.5em; margin-top: 1em; }
#contact-status.error::before { content: "* "; }   /* TI BASIC error style */
.play-again { margin-top: 1.5em; }
.turnstile:not(:empty) { margin: 0.75em 0; }   /* Turnstile only shows if it needs a click */

.hp { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }

@media (prefers-reduced-motion: reduce) {
  body { transition: none; }
  #scene p.story { animation: none; }
  .cursor { animation: none; }
}
