/* ── Houdini @property — register as <color> for smooth transitions ── */
@property --mood-buffer-bg { syntax: '<color>'; inherits: true; initial-value: #0e0e12; }
@property --mood-buffer-fg { syntax: '<color>'; inherits: true; initial-value: #c0beb8; }
@property --mood-grid-bg   { syntax: '<color>'; inherits: true; initial-value: #161420; }
@property --mood-grid-fg   { syntax: '<color>'; inherits: true; initial-value: #808090; }
@property --mood-accent    { syntax: '<color>'; inherits: true; initial-value: #9098b0; }
@property --mood-ui-bg     { syntax: '<color>'; inherits: true; initial-value: #0e0e12; }
@property --mood-border    { syntax: '<color>'; inherits: true; initial-value: #1e1e28; }

:root {
  /* ── Mood palette (updated dynamically by JS on room change) ── */
  --mood-buffer-bg: #0e0e12;
  --mood-buffer-fg: #c0beb8;
  --mood-grid-bg: #161420;
  --mood-grid-fg: #808090;
  --mood-accent: #9098b0;
  --mood-ui-bg: #0e0e12;
  --mood-border: #1e1e28;

  transition:
    --mood-buffer-bg 1.2s ease-in-out,
    --mood-buffer-fg 1.2s ease-in-out,
    --mood-grid-bg 1.2s ease-in-out,
    --mood-grid-fg 1.2s ease-in-out,
    --mood-accent 1.2s ease-in-out,
    --mood-ui-bg 1.2s ease-in-out,
    --mood-border 1.2s ease-in-out;

  /* ── AsyncGlk / GlkOte base theme ── */
  --glkote-buffer-bg: #0e0e12;
  --glkote-buffer-fg: #c0beb8;
  --glkote-buffer-reverse-bg: #c0beb8;
  --glkote-buffer-reverse-fg: #0e0e12;
  --glkote-buffer-size: 16px;
  --glkote-buffer-line-height: 1.6;
  --glkote-grid-bg: #161420;
  --glkote-grid-fg: #808090;
  --glkote-grid-reverse-bg: #808090;
  --glkote-grid-reverse-fg: #161420;
  --glkote-grid-size: 14px;
  --glkote-input-fg: #9098b0;
  --glkote-error-border: #882020;
  --glkote-warning-border: #3333aa;
  --glkote-prop-family: "Iowan Old Style", Palatino, Georgia, "Times New Roman", serif;
  --glkote-mono-family: "SF Mono", "Fira Code", "Cascadia Code", Consolas, "Courier New", monospace;
  --glkote-grid-mono-family: var(--glkote-mono-family);

  --asyncglk-ui-bg: #0e0e12;
  --asyncglk-ui-border: #1e1e28;
  --asyncglk-ui-fg: #c0beb8;
  --asyncglk-ui-selected: #181824;
  --asyncglk-ui-textbox: #0a0a10;
}

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  background: #080808;
  overflow: hidden;
}

div#gameport {
  position: absolute;
  inset: 0;
  background: var(--mood-ui-bg);
  transition: background-color 1.2s ease-in-out;
}

/* Overlay layers for effects */
#gameport::before,
#gameport::after {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 10000;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.WindowFrame {
  background: var(--mood-ui-bg) !important;
}

.WindowFrame:has(.GridWindow) {
  background: var(--mood-buffer-fg) !important;
  transition: background-color 1.2s ease-in-out;
}

.GridWindow,
.GridWindow * {
  background-color: var(--mood-buffer-fg) !important;
  color: #0a0a0a !important;
  font-weight: bold;
  transition: background-color 1.2s ease-in-out, color 1.2s ease-in-out;
}

.GridWindow {
  padding: 6px 12px;
}

.BufferWindow {
  background-color: var(--mood-buffer-bg) !important;
  color: var(--mood-buffer-fg) !important;
  transition: background-color 1.2s ease-in-out, color 1.2s ease-in-out;
}

.BufferWindowInner {
  padding: 20px 40px;
  text-rendering: optimizeLegibility;
}

.Input {
  font-weight: bold;
  color: var(--mood-accent);
  caret-color: var(--mood-accent);
  caret-shape: underscore;
  transition: color 1.2s ease-in-out, caret-color 1.2s ease-in-out;
}

/* ── Text fade-in ── */
@keyframes bufferFadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}
.BufferLine { animation: bufferFadeIn 0.3s ease-out; }

.Style_header {
  color: #c0c8d0;
  text-shadow: 0 0 8px rgba(160,176,192,0.15);
}

.Style_alert {
  color: #b08870;
  text-shadow: 0 0 6px rgba(176,136,112,0.12);
}

.Style_note {
  color: #808898;
}

.BufferWindow {
  scrollbar-width: thin;
  scrollbar-color: #282830 transparent;
}
.BufferWindow::-webkit-scrollbar { width: 6px; }
.BufferWindow::-webkit-scrollbar-track { background: transparent; }
.BufferWindow::-webkit-scrollbar-thumb { background: #282830; border-radius: 3px; }
.BufferWindow::-webkit-scrollbar-thumb:hover { background: #404050; }

#loadingpane {
  position: absolute;
  width: 100%;
  text-align: center;
  top: 35%;
  color: #607080;
  font-size: 1.2em;
  font-family: var(--glkote-mono-family);
}

@keyframes pulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 1; }
}

#loadingpane em {
  animation: pulse 1.5s ease-in-out infinite;
}

/* ══════════════════════════════════════════════════════════════
   MEDICAL MONITOR INTRO — cold blue-green clinical display
   ══════════════════════════════════════════════════════════════ */

@keyframes monitorFlicker {
  0%, 100% { opacity: 1; }
  5%       { opacity: 0.92; }
  8%       { opacity: 1; }
  50%      { opacity: 0.96; }
  52%      { opacity: 1; }
  80%      { opacity: 0.94; }
  83%      { opacity: 1; }
}

@keyframes monitorPulse {
  0%, 100% { text-shadow: 0 0 4px rgba(112,176,160,0.4), 0 0 10px rgba(112,176,160,0.15); }
  50%      { text-shadow: 0 0 6px rgba(112,176,160,0.6), 0 0 16px rgba(112,176,160,0.25); }
}

@keyframes scanlineDrift {
  0%   { transform: translateY(-100%); }
  100% { transform: translateY(100vh); }
}

body.monitor-intro .BufferWindow {
  background-color: #060a0a !important;
  color: #70b0a0 !important;
  font-family: var(--glkote-mono-family);
  animation: monitorFlicker 5s steps(1) infinite, monitorPulse 3s ease-in-out infinite;
  transition: none;
}

body.monitor-intro .BufferWindow .Input {
  color: #70b0a0 !important;
  caret-color: #70b0a0 !important;
  text-shadow: 0 0 4px rgba(112,176,160,0.4);
}

body.monitor-intro .GridWindow,
body.monitor-intro .GridWindow * {
  background-color: #70b0a0 !important;
  color: #060a0a !important;
  font-family: var(--glkote-mono-family);
  text-shadow: none;
}

body.monitor-intro .GridWindow {
  box-shadow: 0 0 12px rgba(112,176,160,0.2), 0 0 24px rgba(112,176,160,0.08);
}

/* Thin scanlines over game area */
body.monitor-intro #gameport::before {
  background: repeating-linear-gradient(
    to bottom,
    transparent 0px,
    transparent 3px,
    rgba(0,0,0,0.15) 3px,
    rgba(0,0,0,0.15) 4px
  );
  opacity: 1;
}

/* Monitor vignette — darkened edges */
body.monitor-intro #gameport::after {
  box-shadow:
    inset 0 0 80px 20px rgba(0,0,0,0.5),
    inset 0 0 200px 50px rgba(0,0,0,0.25);
  opacity: 1;
}

/* Drifting scan bar */
body.monitor-intro .monitor-scanbar {
  display: block;
}

.monitor-scanbar {
  display: none;
  position: fixed;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(to bottom,
    transparent,
    rgba(112,176,160,0.04) 30%,
    rgba(112,176,160,0.08) 50%,
    rgba(112,176,160,0.04) 70%,
    transparent
  );
  pointer-events: none;
  z-index: 10002;
  animation: scanlineDrift 4s linear infinite;
}

/* Smooth transition OUT of monitor mode */
body.monitor-fade .BufferWindow {
  transition: background-color 2.5s ease, color 2.5s ease, text-shadow 2.5s ease;
}
body.monitor-fade .GridWindow {
  transition: background-color 2.5s ease, color 2.5s ease, text-shadow 2.5s ease;
}
body.monitor-fade #gameport::before,
body.monitor-fade #gameport::after {
  transition: opacity 2.5s ease;
  opacity: 0;
}

/* ══════════════════════════════════════════════════════════════
   EVENT: Glass break — screen shake + shard particles
   ══════════════════════════════════════════════════════════════ */

@keyframes screenShake {
  0%   { transform: translate(0, 0); }
  10%  { transform: translate(-4px, 2px); }
  20%  { transform: translate(5px, -3px); }
  30%  { transform: translate(-3px, 4px); }
  40%  { transform: translate(4px, -2px); }
  50%  { transform: translate(-2px, 3px); }
  60%  { transform: translate(3px, -1px); }
  70%  { transform: translate(-1px, 2px); }
  80%  { transform: translate(2px, -1px); }
  90%  { transform: translate(-1px, 1px); }
  100% { transform: translate(0, 0); }
}

body.glass-shake #gameport {
  animation: screenShake 0.6s ease-out;
}

@keyframes shardFall {
  0%   { opacity: 1; transform: translate(0, 0) rotate(0deg); }
  100% { opacity: 0; transform: translate(var(--sx), var(--sy)) rotate(var(--sr)); }
}

.glass-shard {
  position: fixed;
  width: var(--shard-w, 4px);
  height: var(--shard-h, 8px);
  background: linear-gradient(135deg, rgba(200,220,240,0.8), rgba(140,170,200,0.4));
  clip-path: polygon(20% 0%, 100% 10%, 80% 100%, 0% 90%);
  pointer-events: none;
  z-index: 10003;
  animation: shardFall var(--shard-dur, 1s) ease-out forwards;
}

/* ══════════════════════════════════════════════════════════════
   EVENT: Fungus consumed — hue ripple + amber flash
   ══════════════════════════════════════════════════════════════ */

@keyframes fungusRipple {
  0%   { filter: hue-rotate(0deg) saturate(1); }
  20%  { filter: hue-rotate(30deg) saturate(1.4); }
  40%  { filter: hue-rotate(-20deg) saturate(1.2); }
  60%  { filter: hue-rotate(15deg) saturate(1.1); }
  80%  { filter: hue-rotate(-5deg) saturate(1.05); }
  100% { filter: hue-rotate(0deg) saturate(1); }
}

body.fungus-ripple #gameport {
  animation: fungusRipple 2.5s ease-in-out;
}

@keyframes fungusFlash {
  0%   { opacity: 0; }
  15%  { opacity: 0.3; }
  40%  { opacity: 0.15; }
  100% { opacity: 0; }
}

.fungus-overlay {
  position: fixed;
  inset: 0;
  background: radial-gradient(ellipse at center, rgba(200,160,60,0.4) 0%, rgba(160,120,40,0.2) 40%, transparent 70%);
  pointer-events: none;
  z-index: 10003;
  animation: fungusFlash 2.5s ease-out forwards;
}

/* ══════════════════════════════════════════════════════════════
   EVENT: Spray exposure — glitch + static
   ══════════════════════════════════════════════════════════════ */

@keyframes sprayGlitch {
  0%   { filter: none; }
  10%  { filter: hue-rotate(90deg) invert(0.1); }
  12%  { filter: none; }
  30%  { filter: hue-rotate(-60deg) invert(0.15); }
  33%  { filter: none; }
  50%  { filter: hue-rotate(120deg) saturate(2); }
  53%  { filter: none; }
  70%  { filter: invert(0.2) hue-rotate(-90deg); }
  73%  { filter: none; }
  85%  { filter: hue-rotate(45deg) invert(0.08); }
  88%  { filter: none; }
  100% { filter: none; }
}

body.spray-glitch #gameport {
  animation: sprayGlitch 1.5s steps(1) forwards;
}

@keyframes staticFlash {
  0%   { opacity: 0; }
  5%   { opacity: 0.3; }
  10%  { opacity: 0; }
  15%  { opacity: 0.2; }
  20%  { opacity: 0; }
  40%  { opacity: 0.15; }
  42%  { opacity: 0; }
  100% { opacity: 0; }
}

.spray-static {
  position: fixed;
  inset: 0;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0px,
    transparent 2px,
    rgba(255,255,255,0.08) 2px,
    rgba(255,255,255,0.08) 3px
  );
  pointer-events: none;
  z-index: 10003;
  animation: staticFlash 1.5s steps(1) forwards;
}

/* ══════════════════════════════════════════════════════════════
   EVENT: Valve drain — brief shake + blue drain overlay
   ══════════════════════════════════════════════════════════════ */

@keyframes drainShake {
  0%   { transform: translate(0, 0); }
  15%  { transform: translate(-2px, 1px); }
  30%  { transform: translate(3px, -2px); }
  50%  { transform: translate(-2px, 1px); }
  70%  { transform: translate(1px, -1px); }
  100% { transform: translate(0, 0); }
}

body.drain-shake #gameport {
  animation: drainShake 0.5s ease-out;
}

@keyframes drainFade {
  0%   { opacity: 0.25; transform: translateY(0); }
  100% { opacity: 0; transform: translateY(100%); }
}

.drain-overlay {
  position: fixed;
  inset: 0;
  background: linear-gradient(to bottom, transparent 30%, rgba(60,100,140,0.15) 60%, rgba(40,80,120,0.25) 100%);
  pointer-events: none;
  z-index: 10003;
  animation: drainFade 2s ease-in forwards;
}

/* ══════════════════════════════════════════════════════════════
   EVENT: Valve flood — rising water overlay
   ══════════════════════════════════════════════════════════════ */

@keyframes floodRise {
  0%   { transform: translateY(100%); opacity: 0.3; }
  60%  { transform: translateY(20%); opacity: 0.4; }
  100% { transform: translateY(0%); opacity: 0.5; }
}

.flood-overlay {
  position: fixed;
  inset: 0;
  background: linear-gradient(to top, rgba(20,40,60,0.5) 0%, rgba(30,50,70,0.3) 40%, rgba(20,40,60,0.15) 70%, transparent 100%);
  pointer-events: none;
  z-index: 10003;
  animation: floodRise 3s ease-in forwards;
}

/* ══════════════════════════════════════════════════════════════
   EVENT: Basin touch — radial amber/white flash
   ══════════════════════════════════════════════════════════════ */

@keyframes basinFlash {
  0%   { opacity: 0; transform: scale(0.3); }
  20%  { opacity: 0.6; transform: scale(0.8); }
  50%  { opacity: 0.8; transform: scale(1.2); }
  100% { opacity: 0; transform: scale(2); }
}

.basin-overlay {
  position: fixed;
  inset: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(ellipse at center, rgba(255,255,240,0.6) 0%, rgba(224,176,64,0.3) 30%, rgba(192,152,64,0.1) 50%, transparent 70%);
  pointer-events: none;
  z-index: 10003;
  animation: basinFlash 3s ease-out forwards;
}

/* ══════════════════════════════════════════════════════════════
   EVENT: Wound opening — red-amber vignette pulse
   ══════════════════════════════════════════════════════════════ */

@keyframes woundPulse {
  0%   { opacity: 0; }
  30%  { opacity: 0.5; }
  60%  { opacity: 0.3; }
  100% { opacity: 0; }
}

.wound-overlay {
  position: fixed;
  inset: 0;
  box-shadow:
    inset 0 0 80px 20px rgba(160,60,30,0.4),
    inset 0 0 160px 40px rgba(140,50,20,0.2);
  pointer-events: none;
  z-index: 10003;
  animation: woundPulse 1.5s ease-out forwards;
}

/* ══════════════════════════════════════════════════════════════
   PERSISTENT: Post-fungus — shock, peak, recovery
   Ramps up over ~10s, peaks at ~15s, fades out by ~40s.
   Settles to a mild permanent altered state.
   ══════════════════════════════════════════════════════════════ */

/* Combined distortion + sway (40s one-shot) */
@keyframes fungusDecay {
  0% {
    filter: blur(0.5px) hue-rotate(5deg) saturate(1.1);
    letter-spacing: 0.5px;
    word-spacing: 1px;
    text-shadow: -0.5px 0 rgba(200,140,40,0.1), 0.5px 0 rgba(80,160,60,0.08);
    transform: skewX(0deg) translateX(0) rotate(0deg);
  }
  /* Ramp up */
  25% {
    filter: blur(2px) hue-rotate(40deg) saturate(1.6);
    letter-spacing: 3px;
    word-spacing: 5px;
    text-shadow: -1.5px 0 rgba(200,140,40,0.35), 1.5px 0 rgba(80,160,60,0.25), 0 1px rgba(160,100,180,0.2);
    transform: skewX(0.4deg) translateX(3px) rotate(-0.3deg);
  }
  /* Peak */
  40% {
    filter: blur(3px) hue-rotate(65deg) saturate(2);
    letter-spacing: 6px;
    word-spacing: 10px;
    text-shadow: -2.5px 0 rgba(200,140,40,0.5), 2.5px 0 rgba(80,160,60,0.4), 0 1.5px rgba(160,100,180,0.3);
    transform: skewX(-0.5deg) translateX(-4px) rotate(0.4deg);
  }
  /* Fade out */
  70% {
    filter: blur(1px) hue-rotate(18deg) saturate(1.2);
    letter-spacing: 1px;
    word-spacing: 1.5px;
    text-shadow: -0.6px 0 rgba(200,140,40,0.12), 0.6px 0 rgba(80,160,60,0.08);
    transform: skewX(0.1deg) translateX(0.5px) rotate(-0.05deg);
  }
  /* Settled */
  100% {
    filter: blur(0.3px) hue-rotate(8deg) saturate(1.1);
    letter-spacing: 0.3px;
    word-spacing: 0.5px;
    text-shadow: -0.4px 0 rgba(180,120,40,0.08), 0.4px 0 rgba(80,140,60,0.05);
    transform: skewX(0deg) translateX(0) rotate(0deg);
  }
}

/* Vignette — ramp, peak, settle (40s one-shot) */
@keyframes fungusVignette {
  0% {
    box-shadow:
      inset 0 0 60px 15px rgba(160,120,40,0.06),
      inset 0 0 120px 30px rgba(140,100,30,0.03);
  }
  40% {
    box-shadow:
      inset 0 0 100px 35px rgba(160,120,40,0.35),
      inset 0 0 200px 60px rgba(140,100,30,0.2),
      inset 0 0 300px 80px rgba(120,80,20,0.1);
  }
  100% {
    box-shadow:
      inset 0 0 60px 15px rgba(160,120,40,0.08),
      inset 0 0 120px 30px rgba(140,100,30,0.04);
  }
}

body.state-fungus .BufferWindowInner {
  animation: fungusDecay 40s ease-in-out forwards;
  transform-origin: top center;
}

body.state-fungus #gameport::after {
  opacity: 1;
  animation: fungusVignette 40s ease-in-out forwards;
}

body.state-fungus .BufferLine {
  animation-duration: 0.6s;
}

/* ══════════════════════════════════════════════════════════════
   PERSISTENT: Post-spray — chromatic aberration + static flicker
   ══════════════════════════════════════════════════════════════ */

@keyframes chromaticFlicker {
  0%, 89%, 100% { text-shadow: none; }
  90% { text-shadow: -1px 0 rgba(255,60,60,0.3), 1px 0 rgba(60,60,255,0.3); }
  93% { text-shadow: 1px 0 rgba(255,60,60,0.2), -1px 0 rgba(60,60,255,0.2); }
  95% { text-shadow: none; }
}

body.state-spray .BufferWindow {
  animation: chromaticFlicker 6s steps(1) infinite;
}

@keyframes staticOverlay {
  0%, 92%, 100% { opacity: 0; }
  93%  { opacity: 0.04; }
  95%  { opacity: 0; }
  96%  { opacity: 0.03; }
  97%  { opacity: 0; }
}

body.state-spray #gameport::before {
  background: repeating-linear-gradient(
    to bottom,
    transparent 0px,
    transparent 2px,
    rgba(255,255,255,0.06) 2px,
    rgba(255,255,255,0.06) 3px
  );
  animation: staticOverlay 8s steps(1) infinite;
  opacity: 0;
}
