/* web/hud/stage.css
   The Stage (web/hud/stage.js, web/hud/stage_lines.js): a split screen beside the game
   window, sliding in from the side Settings picks while a scene plays or the story is
   read back, above the input line, which runs under it. --stage-ms and --stage-ease
   are the one timing for everything that moves with it: the Stage, the game window
   narrowing, the columns tucking away and coming back (web/play-panels.css). Reduced
   motion, the system's or Settings' Text movement Off, makes it all instant and stills
   the go-on mark. Settings' Stages sets --stage-w (Stage width), --scene-size and
   --combat-size (Scene and Combat Stage text size, until picked a little larger than the
   game window's) and --stage-bg (Colour, web/swatches.js, Deep slate to start); its
   animation is drawn on a canvas inside it (web/backgrounds.js). A tool on it --
   Settings (web/hud/settings.css), the Armory (web/hud/armory_stage.css), the Training
   console (web/hud/training_console.css) -- and a fight,
   the Combat Stage, sit between the
   columns: web/hud/stage.js sets its --sg-left, --sg-right and --stage-w from the room
   they leave. A fight's lines (#stage-fight) take Settings' Combat looks from play.html's
   styles, as the game window's do. */

:root {
  --stage-ms: 600ms;
  --stage-ease: cubic-bezier(.22, .61, .36, 1);
  --stage-w: 62%;
  --stage-bg: #12141a;
  --stage-ink: #e6dcc8;
  --stage-cutscene: #b9a4ff;
  --stage-conversation: #ffa3d1;
  --stage-story: #e0c98f;
  --stage-settings: #8fd3c7;
  --stage-armory: #d9b26a;
  --stage-training: #9fcf7a;
  --stage-combat: #ff8f6b;
}
@media (prefers-reduced-motion: reduce) { :root { --stage-ms: 0ms; } }
:root[data-motion="off"] { --stage-ms: 0ms; }

/* Sliding past the screen's edge never makes the page scroll sideways. */
#centre { overflow-x: clip; }

/* Its foot, --stage-foot, is the room the input line and the bar take under it
   (web/hud/stage.js). Sliding, it is clipped at the side it comes in from, so a tool
   between the columns never passes over one; moving between a scene's place and a
   tool's, it slides over and narrows in the same time. */
#stage {
  position: absolute; top: 0; bottom: var(--stage-foot, 0px); left: var(--sg-left, 0px); z-index: 8;
  width: var(--stage-w); min-width: 0; box-sizing: border-box;
  display: flex; flex-direction: column;
  background: var(--stage-bg);
  border-right: 2px solid #333;
  clip-path: inset(0);
  transition: transform var(--stage-ms) var(--stage-ease), clip-path var(--stage-ms) var(--stage-ease),
    left var(--stage-ms) var(--stage-ease), right var(--stage-ms) var(--stage-ease),
    width var(--stage-ms) var(--stage-ease);
}
/* A tool or a fight sits under the columns' grips, so a column can still be widened
   beside it. */
#stage.sg-between { z-index: 5; }
/* Behind the Stage's animation, over its colour and under everything on it. */
#stage > .sg-backdrop {
  position: absolute; left: 0; top: 0; width: 100%; height: 100%;
  z-index: -1; pointer-events: none;
}
#stage[hidden] { display: none; }
#stage.sg-out { transform: translateX(-100%); clip-path: inset(0 0 0 100%); }
:root[data-stage-side="right"] #stage {
  left: auto; right: var(--sg-right, 0px); border-right: 0; border-left: 2px solid #333;
}
:root[data-stage-side="right"] #stage.sg-out { transform: translateX(100%); clip-path: inset(0 100% 0 0); }

/* The game window beside it, dimmed unless Settings says As normal -- never beside
   a tool (data-stage-tool), whose changes it shows. */
#screen { transition: opacity var(--stage-ms) ease; }
:root:not([data-stage-dim="normal"]) #centre.staged:not([data-stage-tool]) #screen {
  opacity: .5;
}

/* A scene's lines and the room it shows are on the Stage while it plays, and come
   back to the game window as it closes. */
#screen .line[data-staged="story"], #screen .line[data-staged="room"],
#screen .line[data-staged="fight"] { display: none; }

/* ---- the header: what kind of moment this is ----------------------------- */
.sg-head {
  flex: none; display: flex; align-items: baseline; gap: 10px;
  padding: 10px 18px; border-bottom: 1px solid var(--line);
}
.sg-kind { font: 700 14px var(--mono); letter-spacing: .04em; color: var(--stage-cutscene); }
#stage[data-kind="conversation"] .sg-kind { color: var(--stage-conversation); }
#stage[data-kind="story"] .sg-kind { color: var(--stage-story); }
#stage[data-kind="settings"] .sg-kind { color: var(--stage-settings); }
#stage[data-kind="armory"] .sg-kind { color: var(--stage-armory); }
#stage[data-kind="training"] .sg-kind { color: var(--stage-training); }
#stage[data-kind="combat"] .sg-kind { color: var(--stage-combat); }
.sg-what { color: var(--dim); font-size: 12.5px; }
.sg-what:empty { display: none; }
.sg-head .grow { flex: 1; }
.sg-close { align-self: center; padding: 2px 10px; font-size: 12px; }
.sg-close[hidden] { display: none; }
#stage[data-kind="settings"] .sg-close {
  padding: 3px 14px; font-weight: 600; color: var(--stage-settings); border-color: var(--stage-settings);
}
#stage[data-kind="armory"] .sg-close {
  padding: 3px 14px; font-weight: 600; color: var(--stage-armory); border-color: var(--stage-armory);
}
#stage[data-kind="training"] .sg-close {
  padding: 3px 14px; font-weight: 600; color: var(--stage-training); border-color: var(--stage-training);
}

/* A tool (web/hud/stage.js) takes the room under the header in place of the lines. */
#stage.sg-tool-open > .sg-body, #stage.sg-tool-open > .sg-answers { display: none; }
#stage > .sg-tool { flex: 1 1 auto; min-height: 0; }
#stage > .sg-tool[hidden] { display: none; }

/* ---- the lines: larger, in one reading column ---------------------------- */
.sg-body {
  flex: 1 1 auto; min-height: 0; overflow-y: auto;
  scrollbar-width: thin; scrollbar-color: #333 transparent;
}
#stage.sg-waiting .sg-body { cursor: pointer; }
.sg-col {
  padding: 26px 34px; max-width: 46em; box-sizing: border-box;
  font-family: var(--mono); font-size: var(--scene-size, calc(var(--mono-size) * 1.2)); line-height: 1.65;
  color: var(--stage-ink); white-space: pre-wrap; word-break: break-word;
}
.sg-col[hidden] { display: none; }
/* A fight's lines settle at the foot, by the input line, where the eye already is. */
#stage[data-kind="combat"] .sg-body { display: flex; flex-direction: column; }
#stage-fight { flex: none; margin-top: auto; font-size: var(--combat-size, calc(var(--mono-size) * 1.2)); }
.sg-col .line {
  padding-left: var(--hang, 0); text-indent: calc(-1 * var(--hang, 0)); min-height: 1.65em;
}
.sg-col .line:empty { min-height: .7em; }
.sg-col > .line:first-child:empty { display: none; }
.sg-col .line.sg-apart { margin-top: 1em; }
.sg-col .line.sg-asked { display: none; }
.sg-col .line.sg-room {
  color: var(--ink); font-size: var(--mono-size); line-height: 1.5;
  border-left: 2px solid var(--line); padding-left: calc(12px + var(--hang, 0));
}
.sg-col .line.sg-in { animation: sg-in .6s ease-out both; }
@keyframes sg-in { from { opacity: 0; transform: translateY(6px); } }
.sg-empty { margin: 0; color: var(--dim); font-style: italic; }
/* A scene's room fading in on the Stage, as web/fade-in.js fades it in the game window. */
#stage .line.fd-wait { opacity: 0; }
#stage .line.fd-in { animation: fd-in .9s ease-out both; }

/* The go-on mark: at the end of the last line, where the eye already is. */
.sg-go {
  display: inline-block; margin-left: .5em; text-indent: 0;
  color: var(--accent); font-size: .85em; animation: sg-go 1.2s ease-in-out infinite;
}
@keyframes sg-go {
  0%, 100% { opacity: .35; transform: translateY(0); }
  50% { opacity: 1; transform: translateY(2px); }
}
@media (prefers-reduced-motion: reduce) {
  .sg-col .line.sg-in { animation: none; }
  .sg-go { animation: none; opacity: .9; }
}
:root[data-motion="off"] .sg-col .line.sg-in { animation: none; }
:root[data-motion="off"] .sg-go { animation: none; opacity: .9; }

/* ---- answers, under the lines (web/hud/answers.js) ------------------------ */
#answers {
  flex: none; display: grid; gap: 8px; justify-items: start;
  padding: 14px 30px 18px; border-top: 1px solid var(--line);
}
#answers[hidden] { display: none; }
#answers .an-q { color: var(--dim); font-size: 12px; letter-spacing: .05em; text-transform: uppercase; }
#answers button {
  font-family: var(--mono); font-size: var(--mono-size); line-height: 1.4;
  text-align: left; padding: 8px 12px; border-radius: 6px; max-width: 100%;
  border-color: color-mix(in srgb, var(--stage-conversation) 40%, var(--cell-edge));
}
#answers button:hover { border-color: var(--stage-conversation); }
#answers button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
#answers .an-num { color: var(--accent); }

/* ---- a phone: the Stage takes the game text's place while it is open ------- */
:root[data-phone] #stage {
  position: relative; inset: auto; grid-area: main; width: auto; z-index: 3;
  border: 0; transform: none; clip-path: none; transition: none;
}
:root[data-phone] .sg-col { padding: 16px 18px; }
