*,
*::before,
*::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  color-scheme: dark;
  --bg: #05060a;
  --ink: rgba(226, 231, 255, 0.84);
}

html,
body { height: 100%; overflow: hidden; background: var(--bg); }

body {
  color: var(--ink);
  font-family: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 0;
}

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

.fallback {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 0;
}
.fallback svg { width: min(78vw, 920px); height: auto; overflow: visible; }

.nojs {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: clamp(48px, 14vw, 160px);
  letter-spacing: 0.04em;
  color: var(--ink);
}

/* ---------------------------------------------------------------- hemligheter */

/* π i nedre högra hörnet: syns bara medan man håller Ctrl+Shift */
.pi {
  position: fixed;
  right: calc(max(12px, env(safe-area-inset-right)) + 48px);
  bottom: max(14px, env(safe-area-inset-bottom));
  z-index: 20;
  width: 44px;
  height: 44px;
  border: 0;
  background: transparent;
  color: #e8ecff;
  font: 300 30px/44px "Times New Roman", serif;
  text-shadow: 0 0 6px #fff, 0 0 18px #b36bff;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s ease;
  cursor: pointer;
}
.pi.on { opacity: 0.9; pointer-events: auto; }

/* Ljudknappen: överkryssad högtalare tills ljudet är igång */
.snd {
  position: fixed;
  right: max(12px, env(safe-area-inset-right));
  bottom: max(12px, env(safe-area-inset-bottom));
  z-index: 20;
  width: 46px;
  height: 46px;
  padding: 11px;
  border: 0;
  background: transparent;
  color: #e8ecff;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity 1.2s ease;
  filter: drop-shadow(0 0 2px #fff) drop-shadow(0 0 7px #b36bff);
  -webkit-tap-highlight-color: transparent;
}
.snd svg { display: block; width: 100%; height: 100%; overflow: visible; }
.snd path { fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.snd .wave { display: none; }
.snd.on .wave { display: inline; }
.snd.on .x { display: none; }
.snd.show { opacity: 0.85; pointer-events: auto; }
/* Pulsen syns bara tills ljudet har varit igång en gång */
.snd.show:not(.used) { animation: snd-pulse 2.6s ease-in-out infinite; }
.snd.used:not(.on) { opacity: 0.5; }
.snd.on.calm { opacity: 0.28; }
.snd.show:hover, .snd.show:focus-visible { opacity: 1; outline: none; }
@keyframes snd-pulse { 50% { opacity: 0.35; } }
@media (prefers-reduced-motion: reduce) { .snd.show { animation: none; } }

/* Terminalen */
.term {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.72);
  padding: 16px;
}
.term[hidden], .magic[hidden], .esper[hidden], .eggframe[hidden] { display: none; }
.term-screen {
  width: min(860px, 100%);
  height: min(560px, 82vh);
  display: flex;
  flex-direction: column;
  padding: 18px 20px;
  background: radial-gradient(ellipse at center, #031a0b 0%, #010904 80%);
  border: 1px solid rgba(125, 255, 154, 0.35);
  border-radius: 14px;
  box-shadow: 0 0 40px rgba(60, 255, 120, 0.15), inset 0 0 60px rgba(0, 0, 0, 0.8);
  color: #7dff9a;
  font: 15px/1.45 ui-monospace, "Cascadia Mono", Menlo, Consolas, monospace;
  text-shadow: 0 0 5px rgba(125, 255, 154, 0.6);
  user-select: text;
  -webkit-user-select: text;
  touch-action: auto;
}
.term-out { flex: 1; overflow-y: auto; white-space: pre-wrap; word-break: break-word; }
.term-line { display: flex; gap: 8px; align-items: center; margin-top: 6px; }
.term-prompt { white-space: nowrap; color: #b8ffc8; }
.term-in {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: 0;
  outline: 0;
  color: inherit;
  font: inherit;
  text-shadow: inherit;
  caret-color: #7dff9a;
}
.term-dim { opacity: 0.55; }
.term-hi { color: #d6ffe0; }
.term-err { color: #ff8f8f; text-shadow: 0 0 5px rgba(255, 120, 120, 0.6); }
.term-echo { opacity: 0.8; }
.term-glitch .term-screen { animation: glitch 0.12s steps(2) 7; }
@keyframes glitch {
  0% { transform: translate(0, 0); filter: hue-rotate(0deg); }
  50% { transform: translate(-6px, 3px) skewX(3deg); filter: hue-rotate(90deg); }
  100% { transform: translate(5px, -2px); filter: hue-rotate(200deg); }
}

/* Magic word */
.magic {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 18px;
  background: #000;
  cursor: pointer;
}
.magic-man { width: 256px; height: 320px; image-rendering: pixelated; }
.magic-text {
  color: #fff;
  font: 700 clamp(16px, 3vw, 26px) ui-monospace, Menlo, Consolas, monospace;
  letter-spacing: 0.06em;
  text-align: center;
  padding: 0 16px;
  animation: blink 0.9s steps(2) infinite;
}
@keyframes blink { 50% { opacity: 0.35; } }

/* Esper-maskinen */
.esper { position: fixed; inset: 0; z-index: 15; pointer-events: none; }
.esper-grid {
  position: absolute;
  inset: 6%;
  border: 1px solid rgba(160, 220, 255, 0.35);
  background:
    linear-gradient(rgba(160, 220, 255, 0.18) 1px, transparent 1px) 0 0 / 100% 25%,
    linear-gradient(90deg, rgba(160, 220, 255, 0.18) 1px, transparent 1px) 0 0 / 25% 100%;
}
.esper-text, .esper-coords {
  position: absolute;
  left: 8%;
  color: #bfe6ff;
  font: 600 14px ui-monospace, Menlo, Consolas, monospace;
  letter-spacing: 0.2em;
  text-shadow: 0 0 6px rgba(160, 220, 255, 0.8);
}
.esper-text { top: 8%; }
.esper-coords { bottom: 8%; opacity: 0.8; }

/* Telefonen med Snake i en ram */
.eggframe {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(0, 0, 0, 0.8);
}
.eggframe iframe { width: 100%; height: 100%; border: 0; display: block; }
