/* effects.css — CRT overlay, scanlines, vignette, glitch, reduced-motion */

/* ── CRT overlay (fixed above everything) ─────────────────── */
.crt-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
}

/* Scanlines */
.crt-overlay::before {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0px,
    transparent 2px,
    rgba(0, 0, 0, 0.10) 2px,
    rgba(0, 0, 0, 0.10) 4px
  );
}

/* Vignette */
.crt-overlay::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(
    ellipse 80% 70% at 50% 50%,
    transparent 50%,
    rgba(0, 0, 0, 0.55) 100%
  );
}

/* ── Subtle page flicker (CRT power instability) ──────────── */
@keyframes crt-flicker {
  0%, 95%, 100%  { opacity: 1; }
  96%            { opacity: 0.96; }
  97%            { opacity: 1; }
  98%            { opacity: 0.97; }
}

.desktop {
  animation: crt-flicker 12s steps(1) infinite;
}

/* ── Glitch effect triggered via JS (.glitching class) ───── */
@keyframes glitch-jitter {
  0%   { transform: translate(0,      0);   clip-path: none; }
  20%  { transform: translate(-3px,  1px);  clip-path: inset(10% 0 70% 0); }
  40%  { transform: translate( 2px, -1px);  clip-path: inset(60% 0 15% 0); }
  60%  { transform: translate(-1px,  2px);  clip-path: none; color: #cc4444; }
  80%  { transform: translate( 2px,  0);   }
  100% { transform: translate(0,      0);   clip-path: none; color: inherit; }
}

.glitching {
  animation: glitch-jitter 0.12s steps(2, end) forwards;
}

/* ── Noise grain texture on the window frame ──────────────── */
.window::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.75' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='200' height='200' filter='url(%23n)' opacity='0.04'/%3E%3C/svg%3E");
  background-size: 200px 200px;
  opacity: 0.6;
  z-index: 1;
  border-radius: 0;
}

/* Ensure interactive children sit above the grain overlay */
.window > * {
  position: relative;
  z-index: 2;
}

/* ── Brief screen jolt on spin start ─────────────────────── */
@keyframes spin-start-shake {
  0%   { transform: translate(0, 0); }
  20%  { transform: translate(-1px, 1px); }
  40%  { transform: translate(1px, -1px); }
  60%  { transform: translate(-1px, 0); }
  80%  { transform: translate(0, 1px); }
  100% { transform: translate(0, 0); }
}

.window.spinning {
  animation: spin-start-shake 0.18s ease-out;
}

/* ── Click-to-enter overlay (shown on every page load) ───── */
#enter-overlay {
  position: fixed;
  inset: 0;
  z-index: 99999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.88);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease-out;
}

/* Scanlines over the dimmed backdrop */
#enter-overlay::before {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0px,
    transparent 2px,
    rgba(0, 0, 0, 0.14) 2px,
    rgba(0, 0, 0, 0.14) 4px
  );
  pointer-events: none;
  z-index: 0;
}

#enter-overlay.enter-overlay--visible {
  opacity: 1;
  pointer-events: all;
}

#enter-overlay.enter-overlay--leaving {
  opacity: 0;
  pointer-events: none;
}

/* Win98-style dialog box */
.enter-dialog {
  position: relative;
  z-index: 1;
  background: var(--w-gray);
  border: 2px solid;
  border-color: var(--w-white) var(--w-black) var(--w-black) var(--w-white);
  box-shadow:
    inset 1px 1px 0 var(--w-gray-light),
    inset -1px -1px 0 var(--w-gray-dark),
    6px 6px 0 rgba(0, 0, 0, 0.7);
  width: min(360px, calc(100vw - 32px));
  font-family: var(--font-ui);
}

.enter-dialog-titlebar {
  background: linear-gradient(90deg, var(--w-title-start), var(--w-title-end));
  padding: 4px 6px;
  display: flex;
  align-items: center;
  gap: 5px;
  user-select: none;
}

.enter-dialog-titlebar-icon {
  font-size: 11px;
  color: var(--w-title-text);
  line-height: 1;
}

.enter-dialog-titlebar-text {
  color: var(--w-title-text);
  font-size: 12px;
  font-weight: bold;
  letter-spacing: 0.4px;
  flex: 1;
}

.enter-dialog-body {
  padding: 18px 18px 10px;
  display: flex;
  align-items: flex-start;
  gap: 14px;
}

.enter-dialog-warn-icon {
  font-size: 30px;
  line-height: 1;
  flex-shrink: 0;
  margin-top: 1px;
}

.enter-dialog-msg {
  font-size: 13px;
  line-height: 1.5;
  color: var(--w-black);
  margin: 0;
  padding-top: 3px;
}

.enter-progress {
  font-size: 12px;
  line-height: 1.35;
  color: var(--w-gray-dark);
  margin: 0;
  padding-top: 4px;
  white-space: nowrap;
}

.enter-dialog-footer {
  padding: 8px 18px 14px;
  display: flex;
  justify-content: flex-end;
}

.enter-confirm-btn {
  min-width: 72px;
}

/* ── Title-bar FX (title-bar-fx.js) ───────────────────────── */

/* Minimize — chromatic tear / signal glitch on <html> */
@keyframes tb-chromatic-tear {
  0% {
    transform: translate(0, 0);
    filter: hue-rotate(0deg) saturate(1);
  }
  20% {
    transform: translate(2px, -1px);
    filter: hue-rotate(35deg) saturate(1.8) contrast(1.05);
  }
  40% {
    transform: translate(-3px, 2px);
    filter: hue-rotate(-25deg) saturate(1.4);
  }
  60% {
    transform: translate(1px, 1px);
    filter: hue-rotate(90deg) saturate(2);
  }
  80% {
    transform: translate(-2px, -1px);
    filter: hue-rotate(-15deg) saturate(1.2);
  }
  100% {
    transform: translate(0, 0);
    filter: hue-rotate(0deg) saturate(1);
  }
}

html.tb-chromatic-tear-on {
  overflow-x: clip;
}

html.tb-chromatic-tear-on body {
  animation: tb-chromatic-tear 0.07s steps(4, end) infinite;
}

/* Maximize — fake Win9x BSOD + Amiga guru (fullscreen) */
#tb-fake-bsod {
  position: fixed;
  inset: 0;
  z-index: 100200;
  display: flex;
  flex-direction: column;
  background: #0000aa;
  color: #fff;
  font-family: "Courier New", Courier, monospace;
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s ease-out, visibility 0.12s;
}

#tb-fake-bsod.is-visible {
  visibility: visible;
  opacity: 1;
  pointer-events: auto;
}

.tb-fake-bsod__win {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

/* Chant wall (background texture) */
.tb-fake-bsod__chant {
  position: absolute;
  inset: 0;
  overflow: hidden;
  opacity: 0.14;
  pointer-events: none;
  user-select: none;
  columns: 3;
  column-gap: 12px;
  font-size: 8px;
  line-height: 1.05;
  color: #aaccff;
}

.tb-fake-bsod__chant-line {
  margin: 0;
  break-inside: avoid;
}

.tb-fake-bsod__meta {
  position: relative;
  z-index: 1;
  padding: clamp(28px, 6vh, 56px) clamp(16px, 5vw, 48px) 20px;
  max-width: 48rem;
  font-size: 13px;
  line-height: 1.45;
  text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.35);
}

.tb-fake-bsod__line {
  margin: 0 0 0.55em;
}

.tb-fake-bsod__prompt {
  margin: 1.25em 0 0;
  animation: tb-bsod-blink 1s steps(1, end) infinite;
}

@keyframes tb-bsod-blink {
  0%,
  49% {
    opacity: 1;
  }
  50%,
  100% {
    opacity: 0;
  }
}

.tb-fake-bsod__guru {
  flex-shrink: 0;
  margin: auto clamp(12px, 4vw, 32px) clamp(16px, 4vh, 40px);
  padding: 18px 20px;
  background: #000;
  border: 2px solid #fff;
  box-shadow:
    inset 0 0 0 1px #333,
    4px 4px 0 rgba(0, 0, 0, 0.5);
  text-align: center;
  font-size: 12px;
  line-height: 1.5;
}

.tb-fake-bsod__guru-line {
  margin: 0 0 0.5em;
  color: #e0e0e0;
}

.tb-fake-bsod__guru-code {
  margin: 0;
  font-size: 11px;
  letter-spacing: 0.06em;
  color: #ff6666;
}

/* Close — darkening / blood-vignette overlay (non-blocking) */
#tb-scary-overlay {
  position: fixed;
  inset: 0;
  z-index: 10050;
  pointer-events: none;
  background:
    radial-gradient(ellipse 85% 65% at 50% 45%, rgba(80, 0, 0, 0) 0%, rgba(0, 0, 0, 0.88) 72%),
    linear-gradient(185deg, rgba(35, 0, 0, 0.55) 0%, rgba(0, 0, 0, 0.92) 55%, rgba(12, 0, 0, 0.75) 100%);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.45s ease, visibility 0.45s;
}

.tb-scary-overlay__img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
  opacity: 0.5;
  pointer-events: none;
  z-index: 0;
  user-select: none;
}

#tb-scary-overlay::after {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 1;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0,
    transparent 3px,
    rgba(0, 0, 0, 0.2) 3px,
    rgba(0, 0, 0, 0.2) 5px
  );
  pointer-events: none;
  opacity: 0.5;
  mix-blend-mode: multiply;
}

body.tb-scary-on #tb-scary-overlay {
  opacity: 1;
  visibility: visible;
}

/* ── Reduced motion overrides ─────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .desktop {
    animation: none;
  }

  #wheel-group {
    transition: none !important;
  }

  .glitching {
    animation: none;
    color: #cc4444;
  }

  .cursor {
    opacity: 1 !important;
  }

  .window.spinning {
    animation: none;
  }

  .enter-confirm-btn {
    /* nothing to disable — button is already static */
  }

  html.tb-chromatic-tear-on body {
    animation: none;
    filter: brightness(0.96) contrast(1.03) hue-rotate(12deg);
  }

  .tb-fake-bsod__prompt {
    animation: none;
  }

  #tb-scary-overlay {
    transition: opacity 0.2s ease, visibility 0.2s;
  }
}
