:root {
  --page-background: #000000;
  --page-glow: rgba(52, 70, 86, 0.28);
  --panel-background: rgba(7, 10, 12, 0.94);
  --panel-border: rgba(238, 242, 246, 0.7);
  --panel-shadow: rgba(0, 0, 0, 0.66);
  --text-color: #f2efe6;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  background:
    radial-gradient(circle at 50% 35%, var(--page-glow), transparent 45%),
    linear-gradient(180deg, #050505 0%, var(--page-background) 100%);
  color: var(--text-color);
  font-family: "Courier New", Courier, monospace;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: clamp(20px, 4vw, 40px);
  overflow: hidden;
}

.start-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  border: 0;
  background:
    radial-gradient(circle at 50% 38%, rgba(56, 76, 90, 0.18), transparent 34%),
    rgba(0, 0, 0, 0.94);
  color: var(--text-color);
  display: grid;
  place-items: center;
  gap: 0.75rem;
  padding: 24px;
  cursor: pointer;
  font: inherit;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  transition: opacity 220ms ease, transform 220ms ease;
}

.start-overlay:hover .start-overlay__title {
  text-shadow: 0 0 12px rgba(255, 255, 255, 0.12);
}

.start-overlay__title {
  font-size: clamp(1rem, 2.5vw, 1.45rem);
  line-height: 1.1;
}

.start-overlay__hint {
  color: rgba(242, 239, 230, 0.7);
  font-size: 0.82rem;
  letter-spacing: 0.12em;
  text-align: center;
}

body.demo-started .start-overlay {
  opacity: 0;
  pointer-events: none;
  transform: scale(1.01);
}

.scene {
  width: 100%;
  display: flex;
  justify-content: center;
}

.dialogue-box {
  position: relative;
  width: min(92vw, 920px);
  min-height: clamp(360px, 64vh, 700px);
  padding: clamp(18px, 2vw, 28px);
  background: var(--panel-background);
  border: 2px solid var(--panel-border);
  border-radius: 4px;
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.05),
    0 16px 48px var(--panel-shadow),
    inset 0 0 26px rgba(255, 255, 255, 0.03);
  display: flex;
  align-items: stretch;
  overflow: hidden;
  isolation: isolate;
  --box-jitter-x: 0px;
  --box-jitter-y: 0px;
  --major-box-shift-x: 0px;
  --major-box-shift-y: 0px;
  --major-box-opacity: 1;
  --major-box-brightness: 1;
  --major-box-contrast: 1;
  --major-strip-shift: 0px;
  transform: translate(
    calc(var(--box-jitter-x) + var(--major-box-shift-x)),
    calc(var(--box-jitter-y) + var(--major-box-shift-y))
  );
  opacity: var(--major-box-opacity);
  filter: brightness(var(--major-box-brightness)) contrast(var(--major-box-contrast));
  transition: transform 90ms ease-out, opacity 60ms ease-out, filter 60ms ease-out;
  will-change: transform, opacity, filter;
}

.dialogue-content {
  position: relative;
  flex: 1;
  overflow: hidden;
  border-radius: 2px;
  --content-jitter-x: 0px;
  --content-jitter-y: 0px;
  --major-content-shift-x: 0px;
  --major-content-shift-y: 0px;
  --major-content-opacity: 1;
  --major-content-brightness: 1;
  --major-content-contrast: 1;
  transform: translate(
    calc(var(--content-jitter-x) + var(--major-content-shift-x)),
    calc(var(--content-jitter-y) + var(--major-content-shift-y))
  );
  opacity: var(--major-content-opacity);
  filter: brightness(var(--major-content-brightness)) contrast(var(--major-content-contrast));
  transition: transform 90ms ease-out, opacity 60ms ease-out, filter 60ms ease-out;
  will-change: transform, opacity, filter;
}

.dialogue-content::before,
.dialogue-content::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  opacity: 0;
}

.noise-text {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: 0;
  white-space: pre;
  overflow: hidden;
  font-size: clamp(0.65rem, 0.95vw, 0.95rem);
  line-height: 1.18;
  letter-spacing: 0.04em;
  color: rgba(191, 205, 219, 0.45);
  text-shadow: 0 0 8px rgba(63, 89, 118, 0.08);
  user-select: none;
  z-index: 0;
}

.scramble-word {
  display: inline;
  white-space: pre;
  font-size: inherit;
  line-height: inherit;
  letter-spacing: inherit;
  font-weight: 400;
  color: #f6f3ec;
  text-shadow: 0 0 8px rgba(255, 255, 255, 0.12);
  pointer-events: none;
  user-select: none;
  transition: color 60ms ease-out, opacity 60ms ease-out, filter 60ms ease-out;
  will-change: opacity, filter;
}

.scramble-word[data-tone="soft"] {
  color: #f0ede6;
}

.scramble-word[data-tone="dim"] {
  color: rgba(244, 240, 230, 0.88);
}

.scramble-word[data-tone="bright"] {
  color: #ffffff;
}

body.major-glitch--shift .dialogue-box {
  filter: brightness(1.12) contrast(1.08);
}

body.major-glitch--duplicate .noise-text,
body.major-glitch--duplicate .scramble-word {
  text-shadow:
    -1px 0 rgba(255, 92, 92, 0.82),
    1px 0 rgba(95, 155, 255, 0.82),
    0 0 8px rgba(255, 255, 255, 0.08);
}

body.major-glitch--rgb .noise-text,
body.major-glitch--rgb .scramble-word {
  text-shadow:
    -2px 0 rgba(255, 84, 84, 0.82),
    2px 0 rgba(83, 153, 255, 0.82),
    0 0 10px rgba(255, 255, 255, 0.18);
  filter: saturate(1.25) contrast(1.1);
}

body.major-glitch--scanline .dialogue-content::after {
  opacity: 0.9;
  background:
    repeating-linear-gradient(
      180deg,
      rgba(255, 255, 255, 0.1) 0 2px,
      transparent 2px 5px
    );
  mix-blend-mode: screen;
  animation: scanline-flash 90ms steps(2, end) 1;
}

body.major-glitch--strip .dialogue-content::before {
  inset: 38% 0 auto 0;
  height: 22%;
  opacity: 0.9;
  transform: translateX(var(--major-strip-shift));
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.08),
    rgba(255, 255, 255, 0.02)
  );
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    inset 0 -1px 0 rgba(0, 0, 0, 0.56);
  mix-blend-mode: screen;
}

body.major-glitch--flicker .dialogue-content {
  opacity: 0.62;
  filter: brightness(1.28) contrast(1.16);
}

body.major-glitch--malform .noise-text,
body.major-glitch--malform .scramble-word {
  filter: blur(0.18px) saturate(0.9) contrast(1.18);
}

body.major-glitch--malform .scramble-word {
  letter-spacing: 0.05em;
}

.measurement-sample {
  position: fixed;
  left: -9999px;
  top: -9999px;
  visibility: hidden;
  white-space: pre;
  font-size: clamp(0.65rem, 0.95vw, 0.95rem);
  line-height: 1.18;
  letter-spacing: 0.04em;
  font-family: inherit;
}

@keyframes scanline-flash {
  0% {
    opacity: 0.15;
    transform: translateY(-3px);
  }

  50% {
    opacity: 0.95;
  }

  100% {
    opacity: 0.45;
    transform: translateY(3px);
  }
}
