/* cariboucube.com: lo-fi game look. Dark panel, thin green border, green monospace text. */

:root {
  --bg: #07090a;
  --wall: #e3ba70;
  --green: #8af58a;
  --green-bright: #c6ffc0;
  --green-dim: rgba(138, 245, 138, 0.55);
  --green-faint: rgba(138, 245, 138, 0.14);
  --border: #6fe57a;
  --panel: rgba(6, 16, 9, 0.84);
  --mono: "Ubuntu Mono", "PT Mono", ui-monospace, Menlo, Consolas, monospace;
  --glow: 0 0 6px rgba(138, 245, 138, 0.35);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--green);
  font-family: var(--mono);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

body {
  position: fixed;
  inset: 0;
  touch-action: manipulation;
}

a { color: inherit; }

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- scene: the avatar standing against the wall ---------- */

.scene {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: var(--bg);
  z-index: 0;
}

.scene__poster,
.scene__video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 35%;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}

/* stacking: poster at the bottom, loop above it, intro on top. JS fades the intro out once the loop runs. */
.scene__video--loop { z-index: 1; }
.scene__video--intro { z-index: 2; transition: opacity 0.25s linear; }
.scene__video--intro.is-hidden { opacity: 0; }
.scene__video.is-off { display: none; }

/* ---------- splash: logo on black, then cut to the scene ---------- */

.splash {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  background: #050705;
  color: var(--green);
}

/* after the boot log: fade to the scene, like a loading screen giving way to the game */
.splash.is-out {
  opacity: 0;
  transition: opacity 1.2s ease-in-out;
  pointer-events: none;
}

.splash.is-gone { display: none; }

.dialog.is-hidden { opacity: 0; }
.dialog { transition: opacity 0.5s ease-out; }

.splash__logo {
  width: 64px;
  height: 64px;
  filter: drop-shadow(0 0 10px rgba(138, 245, 138, 0.35));
}

.splash__log {
  margin: 0;
  font: inherit;
  font-size: 15px;
  line-height: 1.6;
  letter-spacing: 0.06em;
  color: var(--green-dim);
  text-shadow: var(--glow);
  min-height: 6.4em;
  min-width: 22ch;
  white-space: pre;
}

.splash__log .ok { color: var(--green); }

/* ---------- speaker name: right side, a bit above the box, like Fallout 3 ---------- */

.speaker {
  position: fixed;
  top: 10vh;
  right: 6vw;
  z-index: 4;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--green);
  text-shadow: var(--glow), 0 1px 2px rgba(0, 0, 0, 0.9);
  pointer-events: none;
}

/* ---------- SFX: one small word in the corner ---------- */

.sfx {
  position: fixed;
  right: 18px;
  bottom: 14px;
  z-index: 6;
  font-size: 12px;
  letter-spacing: 0.16em;
  color: rgba(138, 245, 138, 0.5);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.9), 0 0 6px rgba(0, 0, 0, 0.6);
  padding: 6px 4px;
}

.sfx::after { content: " ON"; }
.sfx[aria-pressed="false"]::after { content: " OFF"; }
.sfx[aria-pressed="false"] { text-decoration: line-through; }

.sfx:hover,
.sfx:focus-visible { color: var(--green); outline: none; }

/* ---------- dialogue box ---------- */

.dialog {
  position: fixed;
  left: 0;
  right: 0;
  bottom: max(20px, 6vh);
  margin: 0 auto;
  width: min(800px, calc(100% - 32px));
  z-index: 4;
}

/* the character's line: a subtitle band over the scene, no frame */
.dialog__speech {
  position: relative;
  isolation: isolate;
  padding: 12px 0 10px;
  margin-bottom: 10px;
  cursor: pointer;
}

/* soft dark halo under the line instead of a hard rectangle: a blurred, rounded plate behind the text */
.dialog__speech::before {
  content: "";
  position: absolute;
  inset: 2px -12px;
  z-index: -1;
  background: rgba(0, 0, 0, 0.78);
  border-radius: 18px;
  filter: blur(14px);
}

.dialog__box {
  position: relative;
  display: flex;
  flex-direction: column;
  transition: opacity 0.45s ease-out, transform 0.45s cubic-bezier(0.2, 0.7, 0.2, 1), visibility 0s linear 0s;
  background:
    repeating-linear-gradient(
      to bottom,
      rgba(0, 0, 0, 0.22) 0px,
      rgba(0, 0, 0, 0.22) 1px,
      transparent 1px,
      transparent 3px
    ),
    var(--panel);
  border: 1px solid var(--border);
  box-shadow:
    inset 0 0 0 1px rgba(111, 229, 122, 0.28),
    inset 0 0 24px rgba(0, 0, 0, 0.6),
    0 0 14px rgba(111, 229, 122, 0.18),
    0 10px 30px rgba(0, 0, 0, 0.5);
}

/* the frame appears only once the line is done, already at its full size */
.dialog__box.is-hidden {
  opacity: 0;
  visibility: hidden;
  transform: translateY(14px);
  /* when hiding, keep it in the layout until the fade is over; when showing, be visible from frame one */
  transition: opacity 0.3s ease-in, transform 0.3s ease-in, visibility 0s linear 0.3s;
}

.dialog__body {
  padding: 16px 24px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--green-dim) transparent;
  min-height: 0;
  max-height: min(56vh, 520px);
}

.dialog__line {
  margin: 0;
  text-align: center;
  font-size: 21px;
  line-height: 1.38;
  min-height: 1.4em;
  text-shadow: var(--glow), 0 0 10px rgba(0, 0, 0, 0.9), 0 0 18px rgba(0, 0, 0, 0.8);
  cursor: pointer;
}

.dialog__line.is-done { cursor: default; }

/* zero width in the text flow, so the cursor can never push a word onto a new line */
/* the word being typed: fully laid out, revealed left to right by a mask (monospace, so 1ch per character).
   The cursor is drawn by the same span, right after the last revealed character, outside the flow. */
.dialog__word {
  --n: 0;
  position: relative;
  -webkit-mask-image: linear-gradient(to right, #000 calc(var(--n) * 1ch), transparent calc(var(--n) * 1ch));
  mask-image: linear-gradient(to right, #000 calc(var(--n) * 1ch), transparent calc(var(--n) * 1ch));
}

.dialog__word::after {
  content: "";
  position: absolute;
  left: calc(var(--n) * 1ch + 2px);
  bottom: -0.12em;
  width: 0.55em;
  height: 1.02em;
  background: var(--green);
  animation: blink 0.9s steps(1) infinite;
}

.dialog__line.is-done .dialog__word { display: none; }
.dialog__cursor { display: none; }

/* the not yet typed part of the line: present for layout, invisible */
.dialog__rest {
  color: transparent;
  text-shadow: none;
  user-select: none;
}

@keyframes blink {
  0%, 50% { opacity: 1; }
  51%, 100% { opacity: 0; }
}

.dialog__options {
  list-style: none;
  margin: 0;
  padding: 0;
}

.dialog__options li {
  opacity: 0;
  visibility: hidden;
  transform: translateX(-6px);
  transition: opacity 0.18s ease-out, transform 0.18s ease-out, visibility 0s linear 0.18s;
}

.dialog__options li.is-in {
  opacity: 1;
  visibility: visible;
  transform: none;
  transition-delay: 0s;
}

.opt {
  display: flex;
  gap: 10px;
  width: 100%;
  text-align: left;
  font-size: 19px;
  line-height: 1.35;
  padding: 7px 10px 7px 8px;
  margin: 0 -8px;
  width: calc(100% + 16px);
  color: var(--green);
  text-decoration: none;
  text-shadow: var(--glow);
  border: 1px solid transparent;
  transition: background-color 0.08s, color 0.08s;
}

.opt:hover,
.opt:focus-visible,
.opt.is-active {
  background: var(--green-faint);
  color: var(--green-bright);
  border-color: rgba(111, 229, 122, 0.35);
  outline: none;
}

.opt__num {
  flex: 0 0 auto;
  min-width: 1.6em;
  color: var(--green-dim);
}

.opt:hover .opt__num,
.opt:focus-visible .opt__num { color: var(--green); }

.opt__tag { color: var(--green-bright); margin-right: 0.25em; }

.opt__ph {
  color: var(--green-dim);
  font-size: 0.8em;
  margin-left: 0.5em;
  letter-spacing: 0.06em;
  border-bottom: 1px dashed var(--green-dim);
}

.opt.is-placeholder .opt__text { opacity: 0.8; }

.dialog__toast {
  margin: 10px 0 0;
  font-size: 14px;
  color: var(--green-dim);
  letter-spacing: 0.04em;
  min-height: 0;
}

.dialog__toast:empty { display: none; }

.dialog__error {
  color: var(--green);
  font-size: 17px;
}

.dialog__error code {
  display: block;
  margin-top: 8px;
  color: var(--green-bright);
}

/* ---------- phone ---------- */

@media (max-width: 640px) {
  .scene__poster,
  .scene__video {
    object-fit: contain;
    object-position: 50% 0;
  }

  /* the frame is shorter than the screen: fade its lower edge into the page where the dialogue sits */
  .scene::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 45%;
    background: linear-gradient(to bottom, rgba(7, 9, 10, 0) 0%, rgba(7, 9, 10, 0.85) 55%, var(--bg) 100%);
    pointer-events: none;
  }

  .dialog {
    left: 24px;
    right: 24px;
    bottom: auto;
    top: 0;
    height: 100vh;
    height: 100svh;
    width: auto;
    margin: 0;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
    pointer-events: none;
  }

  .dialog__box { pointer-events: auto; }
  .dialog__body {
    max-height: 50vh;
    max-height: 50svh;
  }

  .dialog__body { padding: 14px 16px; }
  .dialog__speech { padding: 12px 0 10px; margin-bottom: 12px; }
  /* pinned to the screen, not to the line, so it does not move when the line has more or fewer rows */
  .speaker {
    position: absolute;
    top: 28vh;
    top: 28svh;
    right: 2px;
    font-size: 16px;
    margin: 0;
  }
  .dialog { padding-bottom: calc(40px + env(safe-area-inset-bottom)); }
  .splash__logo { width: 56px; height: 56px; }
  .splash__log { font-size: 13px; }
  .sfx { right: 10px; bottom: 6px; }

  .dialog__line { font-size: 17px; margin-bottom: 10px; }
  .opt { font-size: 16px; padding: 7px 8px 7px 6px; gap: 8px; }
  .opt__num { min-width: 1.4em; }

}

/* ---------- reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  .splash.is-out { transition: none; }
  .dialog { transition: none; }
  .scene__video { display: none; }
  .dialog__word::after { animation: none; }
  .dialog__options li { transition: none; }
  .dialog__box { transition: none; }
}

/* ---------- phone turned sideways: little height, so everything gets compact ---------- */

@media (max-height: 520px) and (orientation: landscape) {
  .speaker { top: 10px; right: 20px; font-size: 14px; }
  .dialog { bottom: 10px; width: min(760px, calc(100% - 56px)); }
  .dialog__speech { padding: 6px 0 5px; margin-bottom: 6px; }
  .dialog__line { font-size: 15px; line-height: 1.3; }
  .dialog__body { padding: 6px 14px; max-height: 52vh; }
  .opt { font-size: 14px; line-height: 1.3; padding: 4px 8px 4px 6px; gap: 8px; }
  .sfx { bottom: 2px; right: 10px; font-size: 11px; }
}
