/* Riddles of Fear — prototype
   Bone ink on near-black. One accent, used sparingly and only when it means
   something (damage, the far light). Everything else is white ink and dark. */

/* Fonts are served from ./fonts (Fontsource builds): no request leaves the
   page for them, which keeps it working offline and keeps automated testing
   from tripping Google's traffic flag, which once served a challenge page in
   place of the font CSS. Fraunces carries the opsz and wght axes. */
/* block, not swap: the game holds its text until the art is ready anyway,
   and a title that appears in Georgia and turns into Fraunces reads as a
   glitch. The files are preloaded from index.html. */
@font-face {
  font-family: 'Fraunces'; font-style: normal; font-weight: 100 900; font-display: block;
  src: url(./fonts/fraunces-latin-opsz-normal.woff2) format('woff2-variations');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Fraunces'; font-style: normal; font-weight: 100 900; font-display: swap;
  src: url(./fonts/fraunces-latin-ext-opsz-normal.woff2) format('woff2-variations');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'Commit Mono'; font-style: normal; font-weight: 400; font-display: swap;
  src: url(./fonts/commit-mono-latin-400-normal.woff2) format('woff2');
}
@font-face {
  font-family: 'Commit Mono'; font-style: normal; font-weight: 700; font-display: swap;
  src: url(./fonts/commit-mono-latin-700-normal.woff2) format('woff2');
}

:root {
  --bg: #0a0b0d;
  --ink: #e6e1d7;
  --ink-dim: #8b877f;
  --accent: #e14a39;
  /* UI scale. The scene is drawn to the window, but text is not: at 900px
     tall the sizes below are the design; on a 1440px monitor at 100% they
     were a 530px strip under a 2560px picture. Text follows the window's
     HEIGHT (viewing distance), not its width, so an ultrawide stays at its
     height's size. Steps rather than a continuous curve: a resize never
     nudges the type by a fraction of a pixel. */
  --ui: 1;
}
@media (min-height: 1100px) { :root { --ui: 1.2; } }
@media (min-height: 1300px) { :root { --ui: 1.4; } }
@media (min-height: 1600px) { :root { --ui: 1.65; } }

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg);
  color: var(--ink);
  overflow: hidden;
  font-family: 'Fraunces', Georgia, serif;
  -webkit-font-smoothing: antialiased;
}

#stage { position: relative; width: 100vw; height: 100vh; overflow: hidden; }
#scene { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.mono { font-family: 'Commit Mono', ui-monospace, Menlo, monospace; }
.dim { color: var(--ink-dim); }
.hidden { display: none !important; }

.key {
  border: 1px solid color-mix(in srgb, var(--ink) 35%, transparent);
  padding: 1px 5px; font-size: 0.85em; border-radius: 2px;
  font-family: 'Commit Mono', ui-monospace, monospace;
}

/* ---- Screens (loading / title) ---- */
.screen {
  position: absolute; inset: 0; z-index: 30;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 18px; background: var(--bg);
}
.screen h1 {
  font-size: clamp(34px, 6vw, calc(62px * var(--ui))); font-weight: 600;
  font-variation-settings: 'opsz' 96; letter-spacing: -0.02em;
  margin: 0; text-align: center;
}
.screen p { margin: 0; font-size: calc(13px * var(--ui)); letter-spacing: 0.04em; }
/* what the road is, in as few words as it can be said */
.screen .tagline {
  font-size: clamp(15px, 1.7vw, calc(18px * var(--ui))); line-height: 1.6; letter-spacing: 0;
  font-variation-settings: 'opsz' 36; color: var(--ink); opacity: 0.85;
  text-align: center; max-width: 34em; margin: 4px 0 10px;
}
#begin {
  margin-top: 10px; background: none; color: var(--ink);
  border: 1px solid color-mix(in srgb, var(--ink) 40%, transparent);
  padding: 9px 26px; font-size: calc(12px * var(--ui)); letter-spacing: 0.16em;
  text-transform: uppercase; cursor: pointer; border-radius: 2px;
  transition: background 0.2s ease, border-color 0.2s ease;
}
#begin:hover { background: color-mix(in srgb, var(--ink) 10%, transparent); border-color: var(--ink); }

/* Title screen fades out rather than cutting */
.screen.fading { transition: opacity 0.9s ease; opacity: 0; pointer-events: none; }

/* ---- Scrim under the talking ---- */
#scrim {
  position: absolute; left: 0; right: 0; bottom: 0; height: 46%;
  z-index: 15; pointer-events: none; opacity: 0;
  transition: opacity 1s ease;
  background: linear-gradient(to top,
    rgba(10,11,13,0.97) 0%, rgba(10,11,13,0.92) 34%, rgba(10,11,13,0.55) 68%, rgba(10,11,13,0) 100%);
}
#scrim.show { opacity: 1; }
/* the road is bright and busy underfoot; passing captions need their own
   ground to sit on, but a lighter one than an encounter warrants */
/* A passing caption is a whisper, not an encounter: its own shallow band,
   with only opacity ever changing so it can never jump on the way out. */
#cap-scrim {
  position: absolute; left: 0; right: 0; bottom: 0; height: 20%;
  z-index: 16; pointer-events: none; opacity: 0;
  transition: opacity 0.5s ease;
  background: linear-gradient(to top,
    rgba(10,11,13,0.8) 0%, rgba(10,11,13,0.5) 40%, rgba(10,11,13,0) 100%);
}
#cap-scrim.show { opacity: 1; }

/* ---- Passing caption ---- */
/* Text over the road sits on its own plate: a tight, dark, blurred backing
   the size of the line, so it reads against the stones without dimming the
   scene around it. box-decoration-break keeps the plate whole on a wrap. */
#caption {
  position: absolute; left: 50%; bottom: 13%; transform: translateX(-50%);
  z-index: 20; max-width: min(calc(560px * var(--ui)), 78vw); text-align: center;
  font-size: calc(17px * var(--ui)); line-height: 1.5; font-variation-settings: 'opsz' 36;
  color: var(--ink); text-shadow: 0 1px 6px var(--bg);
  opacity: 0; transition: opacity 0.5s ease;
}
#caption {
  padding: 7px 16px; border-radius: 3px;
  background: color-mix(in srgb, var(--bg) 72%, transparent);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
}
/* the spoken line sits on one even plate, whatever the wrap does: a block
   the width of the encounter, not a ribbon that follows ragged line ends */
#speech .line {
  display: block;
  background: color-mix(in srgb, var(--bg) 74%, transparent);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  padding: 8px 14px; border-radius: 3px 3px 0 0;   /* its bottom edge is the rule */
}
#caption.show { opacity: 0.92; }
/* a clue re-read by pointing at the object it came from */
#clue {
  position: absolute; left: 0; top: 0; z-index: 25; pointer-events: none;
  max-width: calc(260px * var(--ui)); padding: 8px 12px;
  font-size: calc(14px * var(--ui)); line-height: 1.45; font-variation-settings: 'opsz' 36;
  color: var(--ink); background: rgba(8, 8, 8, 0.78);
  border: 1px solid rgba(230, 225, 215, 0.14);
  text-shadow: 0 1px 8px var(--bg);
}
/* during an encounter the speech owns the bottom of the frame */
body.in-encounter #caption { bottom: auto; top: 12%; }

/* ---- End of the road: the offer, and the form ---- */
#offer {
  position: absolute; left: 50%; bottom: 20%; transform: translateX(-50%);
  z-index: 24; display: flex; flex-direction: column; align-items: center; gap: 12px;
  padding: 16px 22px; border-radius: 3px;
  background: color-mix(in srgb, var(--bg) 74%, transparent);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  opacity: 0; transition: opacity 0.8s ease;
}
#offer.show { opacity: 1; }
#offer p { margin: 0 0 4px; font-size: calc(17px * var(--ui)); font-variation-settings: 'opsz' 36; }
#offer button, #submit button {
  background: none; color: var(--ink); border: 1px solid color-mix(in srgb, var(--ink) 40%, transparent);
  padding: 8px 16px; font-size: calc(12px * var(--ui)); letter-spacing: 0.12em; text-transform: uppercase; cursor: pointer;
}
#offer button:hover, #submit button:hover { border-color: var(--ink); }
#offer button.dim, #submit button.dim { border-color: transparent; }
#submit { z-index: 40; overflow-y: auto; justify-content: flex-start; padding-top: 6vh; }   /* taller than a short window: scroll from the top, never clip the heading */
#submit-form { width: min(calc(560px * var(--ui)), 90vw); display: flex; flex-direction: column; gap: 14px; padding: 24px 0; }
#submit-form h2 { margin: 0; font-size: calc(30px * var(--ui)); font-weight: 600; font-variation-settings: 'opsz' 72; letter-spacing: -0.01em; }
#submit-form p { margin: 0; font-size: calc(14px * var(--ui)); line-height: 1.5; letter-spacing: 0; }
#submit-form label { display: flex; flex-direction: column; gap: 6px; font-size: calc(13px * var(--ui)); color: var(--ink-dim); letter-spacing: 0.02em; }
#submit-form input, #submit-form textarea {
  background: color-mix(in srgb, var(--ink) 6%, transparent); color: var(--ink);
  border: 1px solid color-mix(in srgb, var(--ink) 22%, transparent); border-radius: 2px;
  padding: 9px 11px; font: inherit; font-size: calc(15px * var(--ui)); letter-spacing: 0; resize: vertical;
}
#submit-form input:focus, #submit-form textarea:focus { outline: none; border-color: color-mix(in srgb, var(--ink) 55%, transparent); }
#submit-form input::placeholder, #submit-form textarea::placeholder { color: color-mix(in srgb, var(--ink) 28%, transparent); }
#submit-form .row { display: flex; gap: 12px; align-items: center; margin-top: 6px; }

/* ---- Encounter ---- */
#encounter {
  position: absolute; left: 50%; bottom: 5.5%; transform: translateX(-50%);
  z-index: 20; width: min(calc(680px * var(--ui)), 88vw);
  display: flex; flex-direction: column; gap: 14px;
}
#speech {
  min-height: 3.2em; font-size: clamp(16px, 1.9vw, calc(19px * var(--ui))); line-height: 1.45;
  font-variation-settings: 'opsz' 48; text-wrap: pretty;
  text-shadow: 0 2px 22px var(--bg), 0 0 44px var(--bg);
  /* the plate rests on the rule below it: one line sits on the line, two
     lines grow upward from it, and the prompt row never moves */
  display: flex; flex-direction: column; justify-content: flex-end;
  margin-bottom: -14px;
}
#speech .narr { color: var(--ink-dim); font-style: italic; }
/* words are laid out whole and revealed a character at a time */
#speech .w { display: inline-block; }
#speech .ch { opacity: 0; transition: opacity 0.14s ease; }
#speech .ch.on { opacity: 1; }
/* Waiting on the monster. Not three dots, which say "chatbot" before it has
   said anything: the rule above the prompt, the line between you and it,
   carries a slow light along its length while it considers, and what you
   typed dims. The last line stays where it is. */
/* Waiting on the monster: a soft wash of light drifts left to right over the
   line you typed, and nothing else on screen moves. It stops when it speaks. */
#input.busy { opacity: 0.5; caret-color: transparent; }
/* the wash covers the typing area only (the label has a fixed width so the
   overlay knows where to start), and is masked to an ellipse so it has no
   hard edges: it tapers at both ends and fades above and below the text */
#prompt-row { position: relative; }
#mode-label { width: 3.4em; flex: none; }
#prompt-row.waiting::after {
  content: ''; position: absolute; left: calc(3.4em + 10px); right: 0; top: -8px; bottom: -8px; pointer-events: none;
  background: linear-gradient(90deg, transparent 0%, transparent 28%, color-mix(in srgb, var(--ink) 11%, transparent) 50%, transparent 72%, transparent 100%);
  background-size: 220% 100%;
  -webkit-mask-image: radial-gradient(ellipse 52% 50% at 50% 50%, black 20%, transparent 100%);
  mask-image: radial-gradient(ellipse 52% 50% at 50% 50%, black 20%, transparent 100%);
  animation: wash 3.8s linear infinite;
}
@keyframes wash { 0% { background-position: 110% 0; } 100% { background-position: -10% 0; } }
@keyframes pulse { 0%, 100% { opacity: 0.2; transform: translateY(0); } 40% { opacity: 0.85; transform: translateY(-2px); } }
#speech.struck { color: var(--accent); }

#prompt-row {
  display: flex; align-items: center; gap: 10px;
  border-top: 1px solid color-mix(in srgb, var(--ink) 22%, transparent);
  padding-top: 11px;
}
#mode-label {
  font-size: calc(11px * var(--ui)); letter-spacing: 0.18em; text-transform: uppercase;
  flex-shrink: 0; transition: color 0.2s ease;
}
#mode-label.naming { color: var(--accent); }
#input {
  flex: 1; background: none; border: none; outline: none;
  color: var(--ink); font-family: 'Commit Mono', ui-monospace, monospace;
  font-size: calc(15px * var(--ui)); padding: 2px 0; caret-color: var(--accent);
}
#input::placeholder { color: color-mix(in srgb, var(--ink) 30%, transparent); }

#meta-row {
  display: flex; justify-content: space-between; gap: 16px;
  font-size: calc(11px * var(--ui)); letter-spacing: 0.04em;
}

/* ---- HUD ---- */
#hud {
  position: absolute; top: calc(22px * var(--ui)); left: calc(26px * var(--ui)); z-index: 20;
  font-size: calc(11px * var(--ui)); letter-spacing: 0.22em; text-transform: uppercase;
}
#nerve .mark { color: var(--ink); margin-right: 3px; }
#nerve .mark.spent { color: color-mix(in srgb, var(--ink) 22%, transparent); }

/* ---- Tuner ---- */
#tuner {
  position: absolute; top: 20px; right: 20px; z-index: 40;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  border: 1px solid color-mix(in srgb, var(--ink) 20%, transparent);
  padding: 12px 14px; font-size: 10.5px; width: 232px;
  display: flex; flex-direction: column; gap: 7px; border-radius: 3px;
}
#tuner label { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
#tuner span.name { color: var(--ink-dim); letter-spacing: 0.06em; }
#tuner input[type=range] { width: 108px; accent-color: var(--accent); }
/* the readout: frame rate, pixel ratio, canvas size, quality level, GPU */
#tuner .stats { color: var(--ink-dim); line-height: 1.5; padding-bottom: 6px; border-bottom: 1px solid color-mix(in srgb, var(--ink) 14%, transparent); word-break: break-word; }
#tuner-hint { position: absolute; bottom: 16px; right: 20px; z-index: 20; font-size: 10px; letter-spacing: 0.1em; }
#lab-hint { position: absolute; top: 16px; right: 20px; z-index: 20; font-size: 10px; letter-spacing: 0.1em; }
/* inside the site's frame (atheo.dev/riddles-of-fear) the bottom corners hold
   the frame's own links, and the tuner is not for visitors anyway */
body.embedded #tuner-hint, body.embedded #lab-hint { display: none; }
