/* ── Houdini @property — register as <color> for smooth transitions ── */
@property --mood-buffer-bg { syntax: '<color>'; inherits: true; initial-value: #111111; }
@property --mood-buffer-fg { syntax: '<color>'; inherits: true; initial-value: #d4c5a9; }
@property --mood-grid-bg   { syntax: '<color>'; inherits: true; initial-value: #1c1810; }
@property --mood-grid-fg   { syntax: '<color>'; inherits: true; initial-value: #aa9966; }
@property --mood-accent    { syntax: '<color>'; inherits: true; initial-value: #e8d090; }
@property --mood-ui-bg     { syntax: '<color>'; inherits: true; initial-value: #111111; }
@property --mood-border    { syntax: '<color>'; inherits: true; initial-value: #2a2418; }

:root {
  /* ── Mood palette (updated dynamically by JS on room change) ── */
  --mood-buffer-bg: #111;
  --mood-buffer-fg: #d4c5a9;
  --mood-grid-bg: #1c1810;
  --mood-grid-fg: #aa9966;
  --mood-accent: #e8d090;
  --mood-ui-bg: #111;
  --mood-border: #2a2418;

  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: #111;
  --glkote-buffer-fg: #d4c5a9;
  --glkote-buffer-reverse-bg: #d4c5a9;
  --glkote-buffer-reverse-fg: #111;
  --glkote-buffer-size: 19px;
  --glkote-buffer-line-height: 1.6;
  --glkote-grid-bg: #1c1810;
  --glkote-grid-fg: #aa9966;
  --glkote-grid-reverse-bg: #aa9966;
  --glkote-grid-reverse-fg: #1c1810;
  --glkote-grid-size: 17px;
  --glkote-input-fg: #e8d090;
  --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: #1a1810;
  --asyncglk-ui-border: #3a2a10;
  --asyncglk-ui-fg: #d4c5a9;
  --asyncglk-ui-selected: #2a2010;
  --asyncglk-ui-textbox: #111;
}

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

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

.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: #e8d8b0;
  text-shadow: 0 0 8px rgba(232,216,176,0.15);
}

.Style_alert {
  color: #cc8844;
  text-shadow: 0 0 6px rgba(204,136,68,0.12);
}

.Style_note {
  color: #aa9966;
}

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

#loadingpane {
  position: absolute;
  width: 100%;
  text-align: center;
  top: 35%;
  color: #887755;
  font-size: 1.2em;
  font-family: Georgia, "Times New Roman", serif;
}

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

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

/* ── CRT intro mode — green phosphor terminal until first input ── */

@keyframes crtFlicker {
  0%, 100% { opacity: 1; }
  3%       { opacity: 0.85; }
  6%       { opacity: 1; }
  42%      { opacity: 0.95; }
  44%      { opacity: 1; }
  87%      { opacity: 0.92; }
  89%      { opacity: 1; }
}

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

body.crt-intro .BufferWindow {
  background-color: #0a0a0a !important;
  color: #33ff33 !important;
  font-family: "SF Mono", "Fira Code", "Cascadia Code", Consolas, "Courier New", monospace;
  text-shadow: 0 0 5px rgba(51,255,51,0.5), 0 0 12px rgba(51,255,51,0.2);
  animation: crtFlicker 4s steps(1) infinite;
  transition: none;
}

body.crt-intro .BufferWindow .Input {
  color: #33ff33 !important;
  caret-color: #33ff33 !important;
  text-shadow: 0 0 5px rgba(51,255,51,0.5);
}

body.crt-intro .GridWindow,
body.crt-intro .GridWindow * {
  --glkote-grid-bg: #33ff33;
  --glkote-grid-fg: #0a0a0a;
  background-color: #33ff33 !important;
  color: #0a0a0a !important;
  font-family: "SF Mono", "Fira Code", "Cascadia Code", Consolas, "Courier New", monospace;
  text-shadow: none;
}

body.crt-intro .GridWindow {
  box-shadow: 0 0 15px rgba(51,255,51,0.3), 0 0 30px rgba(51,255,51,0.1);
}

/* Scanlines over the game area */
body.crt-intro #gameport::before {
  background: repeating-linear-gradient(
    to bottom,
    transparent 0px,
    transparent 2px,
    rgba(0,0,0,0.25) 2px,
    rgba(0,0,0,0.25) 4px
  );
  opacity: 1;
}

/* CRT vignette — darkened corners */
body.crt-intro #gameport::after {
  box-shadow:
    inset 0 0 100px 30px rgba(0,0,0,0.6),
    inset 0 0 250px 60px rgba(0,0,0,0.3);
  opacity: 1;
}

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

.crt-scanbar {
  display: none;
  position: fixed;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(to bottom,
    transparent,
    rgba(51,255,51,0.06) 30%,
    rgba(51,255,51,0.10) 50%,
    rgba(51,255,51,0.06) 70%,
    transparent
  );
  pointer-events: none;
  z-index: 10002;
  animation: crtScanDrift 3s linear infinite;
}

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

/* ═══════════════════════════════════════════════════════════════
   Tree area — leaves, dappled light, canopy glow, sway, text shimmer
   ═══════════════════════════════════════════════════════════════ */

@keyframes treeSway {
  0%, 100% { transform: rotate(-0.5deg) translateX(-3px); }
  30%      { transform: rotate(0.3deg) translateX(2px); }
  60%      { transform: rotate(0.5deg) translateX(4px); }
  80%      { transform: rotate(-0.2deg) translateX(-1px); }
}

@keyframes canopyGlow {
  0%, 100% {
    box-shadow:
      inset 0 0 120px 20px rgba(30,120,20,0.04),
      inset 0 80px 80px -30px rgba(60,160,30,0.06);
  }
  50% {
    box-shadow:
      inset 0 0 120px 20px rgba(50,150,30,0.10),
      inset 0 80px 80px -30px rgba(80,200,40,0.14);
  }
}

@keyframes dappledShimmer {
  0%, 100% { transform: translate(0, 0); opacity: 0.5; }
  25%      { transform: translate(40px, -25px); opacity: 0.9; }
  50%      { transform: translate(-30px, 20px); opacity: 0.6; }
  75%      { transform: translate(20px, -15px); opacity: 0.85; }
}

@keyframes windGust {
  0%, 65%, 100% { transform: skewX(0deg) translateX(0); }
  70%           { transform: skewX(0.3deg) translateX(3px); }
  80%           { transform: skewX(-0.2deg) translateX(-2px); }
  92%           { transform: skewX(0.1deg) translateX(1px); }
}

@keyframes dapple {
  0%, 100% { opacity: 0.5; transform: scale(1); }
  50%      { opacity: 1; transform: scale(1.12); }
}

@keyframes vignetteBreath {
  0%, 100% { opacity: 0.4; }
  50%      { opacity: 0.65; }
}

@keyframes leafFall1 {
  0%   { transform: translateY(-20px) translateX(0)    rotate(0deg);   opacity: 0; }
  8%   { opacity: 0.7; }
  25%  { transform: translateY(25vh)  translateX(40px)  rotate(190deg); }
  50%  { transform: translateY(50vh)  translateX(-25px) rotate(380deg); }
  75%  { transform: translateY(75vh)  translateX(55px)  rotate(560deg); }
  92%  { opacity: 0.3; }
  100% { transform: translateY(105vh) translateX(15px)  rotate(720deg); opacity: 0; }
}

@keyframes leafFall2 {
  0%   { transform: translateY(-20px) translateX(0)     rotate(0deg);   opacity: 0; }
  8%   { opacity: 0.6; }
  30%  { transform: translateY(28vh)  translateX(-35px)  rotate(170deg); }
  55%  { transform: translateY(52vh)  translateX(30px)   rotate(350deg); }
  80%  { transform: translateY(80vh)  translateX(-40px)  rotate(530deg); }
  92%  { opacity: 0.25; }
  100% { transform: translateY(105vh) translateX(-10px)  rotate(680deg); opacity: 0; }
}

@keyframes leafFall3 {
  0%   { transform: translateY(-20px) translateX(0)     rotate(0deg);   opacity: 0; }
  10%  { opacity: 0.5; }
  20%  { transform: translateY(18vh)  translateX(25px)   rotate(120deg); }
  50%  { transform: translateY(48vh)  translateX(-35px)  rotate(310deg); }
  75%  { transform: translateY(74vh)  translateX(45px)   rotate(500deg); }
  90%  { opacity: 0.2; }
  100% { transform: translateY(105vh) translateX(20px)   rotate(660deg); opacity: 0; }
}

/* mood-tree: base effect (Forest Path + Up a Tree) — leaves, dappled light */
/* mood-tree-canopy: Up a Tree only — adds canopy glow */
/* mood-tree-sway: after egg taken in Up a Tree — adds sway + text shimmer */

/* Canopy glow on buffer (Up a Tree only) */
body.mood-tree-canopy .BufferWindow {
  animation: canopyGlow 7s ease-in-out infinite;
}

/* Sway + dappled light shimmer — after egg taken */
body.mood-tree-sway .BufferWindowInner {
  position: relative;
  animation: treeSway 12s ease-in-out infinite;
  transform-origin: top center;
}

body.mood-tree-sway .BufferWindowInner::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse 100px 80px at 15% 25%, rgba(140,220,80,0.18), transparent 70%),
    radial-gradient(ellipse 80px 100px at 55% 45%, rgba(160,230,90,0.14), transparent 70%),
    radial-gradient(ellipse 90px 70px at 80% 15%, rgba(120,200,60,0.12), transparent 70%),
    radial-gradient(ellipse 70px 90px at 35% 70%, rgba(150,215,75,0.15), transparent 70%),
    radial-gradient(ellipse 60px 50px at 70% 80%, rgba(130,210,65,0.10), transparent 70%);
  mix-blend-mode: overlay;
  animation: dappledShimmer 8s ease-in-out infinite;
  z-index: 1;
}

body.mood-tree-sway .GridWindow {
  animation: windGust 15s ease-in-out infinite;
}

/* Dappled sunlight + forest vignette (always exist, fade in when mood-tree) */
#gameport::before,
#gameport::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity 1.5s ease-in-out;
}

#gameport::before {
  z-index: 10000;
  background:
    radial-gradient(ellipse 60px 45px at 15% 20%, rgba(140,200,70,0.06), transparent 70%),
    radial-gradient(ellipse 45px 60px at 55% 12%, rgba(160,210,90,0.05), transparent 70%),
    radial-gradient(ellipse 55px 40px at 78% 40%, rgba(120,190,60,0.05), transparent 70%),
    radial-gradient(ellipse 70px 55px at 35% 60%, rgba(150,210,80,0.06), transparent 70%),
    radial-gradient(ellipse 40px 50px at 8% 75%,  rgba(130,195,65,0.04), transparent 70%),
    radial-gradient(ellipse 50px 45px at 88% 70%, rgba(145,205,75,0.05), transparent 70%);
  animation: dapple 8s ease-in-out infinite;
}

#gameport::after {
  z-index: 10001;
  box-shadow: inset 0 0 120px 50px rgba(0,0,0,0.25);
  animation: vignetteBreath 6s ease-in-out infinite;
}

body.mood-tree #gameport::before,
body.mood-tree #gameport::after {
  opacity: 1;
}

/* Falling leaf particles */
.leaf {
  position: fixed;
  pointer-events: none;
  z-index: 10002;
  border-radius: 50% 0 50% 0;
  opacity: 0;
  filter: blur(0.3px);
}

/* ═══════════════════════════════════════════════════════════════
   EVENT: Egg taken — golden explosion, screen shake, shockwave
   ═══════════════════════════════════════════════════════════════ */

@keyframes eggFlash {
  0%   { opacity: 0; }
  6%   { opacity: 1; }
  12%  { opacity: 0.4; }
  20%  { opacity: 0.85; }
  35%  { opacity: 0.5; }
  60%  { opacity: 0.2; }
  100% { opacity: 0; }
}

@keyframes eggFlash2 {
  0%   { opacity: 0; transform: scale(1); }
  10%  { opacity: 0.6; transform: scale(1.02); }
  25%  { opacity: 0.3; }
  40%  { opacity: 0.7; transform: scale(1); }
  100% { opacity: 0; transform: scale(0.98); }
}

@keyframes screenShake {
  0%, 100% { transform: translate(0,0) rotate(0deg); }
  5%  { transform: translate(-10px, 6px) rotate(-0.5deg); }
  10% { transform: translate(9px, -8px) rotate(0.6deg); }
  15% { transform: translate(-8px, 5px) rotate(-0.4deg); }
  20% { transform: translate(10px, -4px) rotate(0.5deg); }
  25% { transform: translate(-6px, 7px) rotate(-0.3deg); }
  30% { transform: translate(7px, -6px) rotate(0.4deg); }
  35% { transform: translate(-9px, 3px) rotate(-0.5deg); }
  40% { transform: translate(5px, -3px) rotate(0.2deg); }
  50% { transform: translate(-3px, 4px) rotate(-0.1deg); }
  60% { transform: translate(3px, -2px) rotate(0.1deg); }
  75% { transform: translate(-1px, 1px) rotate(0deg); }
}

@keyframes shockwaveRing {
  0%   { transform: translate(-50%,-50%) scale(0); opacity: 0.8; border-width: 3px; }
  100% { transform: translate(-50%,-50%) scale(5); opacity: 0;   border-width: 0.5px; }
}

@keyframes sparkFly {
  0%   { transform: translate(0,0) scale(1); opacity: 1; }
  100% { transform: translate(var(--sx), var(--sy)) scale(0); opacity: 0; }
}

@keyframes colorInvert {
  0%, 100% { filter: none; }
  6%       { filter: invert(1) hue-rotate(180deg) brightness(1.5); }
  12%      { filter: none; }
  18%      { filter: invert(0.3) hue-rotate(60deg); }
  24%      { filter: none; }
}

@keyframes textGolden {
  0%   { color: inherit; text-shadow: none; }
  15%  { color: #ffd700; text-shadow: 0 0 12px rgba(255,215,0,0.6), 0 0 30px rgba(255,165,0,0.3), 0 0 60px rgba(255,100,0,0.15); }
  50%  { color: #ffe870; text-shadow: 0 0 8px rgba(255,215,0,0.3); }
  100% { color: inherit; text-shadow: none; }
}

.egg-overlay {
  position: fixed; inset: 0;
  pointer-events: none; z-index: 99998;
  background: radial-gradient(circle at 50% 50%,
    rgba(255,250,200,0.95) 0%, rgba(255,225,100,0.7) 15%,
    rgba(255,180,50,0.4) 35%, rgba(255,140,0,0.12) 55%, transparent 72%);
  animation: eggFlash 2s ease-out forwards;
}

.egg-overlay-2 {
  position: fixed; inset: 0;
  pointer-events: none; z-index: 99997;
  background: linear-gradient(135deg,
    rgba(255,215,0,0.25), transparent 30%,
    rgba(255,180,0,0.15) 50%, transparent 70%,
    rgba(255,200,50,0.25));
  animation: eggFlash2 2.5s ease-out forwards;
}

.egg-ring {
  position: fixed; top: 50%; left: 50%;
  width: 80px; height: 80px;
  border-radius: 50%;
  border: 3px solid rgba(255,215,0,0.5);
  box-shadow: 0 0 20px rgba(255,215,0,0.3), inset 0 0 20px rgba(255,215,0,0.1);
  pointer-events: none; z-index: 100000;
  animation: shockwaveRing var(--ring-dur, 1.2s) var(--ring-delay, 0s) ease-out forwards;
}

.egg-spark {
  position: fixed;
  width: var(--spark-size, 5px);
  height: var(--spark-size, 5px);
  border-radius: 50%;
  background: var(--spark-color, #ffd700);
  box-shadow: 0 0 8px var(--spark-color, #ffd700), 0 0 16px rgba(255,200,0,0.3);
  pointer-events: none; z-index: 100001;
  animation: sparkFly var(--spark-dur, 1s) ease-out forwards;
}

body.egg-shake #gameport {
  animation: screenShake 0.9s ease-out;
}

body.egg-invert {
  animation: colorInvert 0.8s ease-out;
}

body.egg-text-glow .BufferLine:last-of-type {
  animation: textGolden 2.5s ease-out;
}

/* ── Sword glow — blue vignette overlay on screen edges ── */
body.sword-glow-faint::after,
body.sword-glow-bright::after {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
  transition: box-shadow 1.5s ease-in-out;
}

body.sword-glow-faint::after {
  box-shadow: inset 0 0 80px 15px rgba(80, 130, 255, 0.2),
              inset 0 0 160px 30px rgba(60, 100, 220, 0.1);
}

body.sword-glow-bright::after {
  box-shadow: inset 0 0 100px 25px rgba(80, 140, 255, 0.4),
              inset 0 0 200px 50px rgba(60, 110, 240, 0.2),
              inset 0 0 300px 80px rgba(40, 80, 200, 0.1);
}
