/* ── Global interaction lockdown ────────────────────────────────────── */
* {
  user-select: none;
  /* stylelint-disable-next-line property-no-vendor-prefix */
  -webkit-user-select: none;
}

/* ── Canvas layers ─────────────────────────────────────────────────── */
#starfield {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  z-index: 0; pointer-events: none;
}

/* Custom image background (BG_MODE=image) */
#bg-image {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  z-index: 0; background-size: cover; background-position: center;
  pointer-events: none;
}

/* Game canvas - always on top, always active in standalone mode */
#pihole-canvas {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  z-index: 15; image-rendering: pixelated;
  opacity: 0; transition: opacity 0.6s linear;
  touch-action: manipulation;
}

/* body always has .pihole-mode in standalone; this activates the canvas */
body.pihole-mode #pihole-canvas {
  pointer-events: auto; cursor: default;
}

/* ── CRT filter ────────────────────────────────────────────────────────
   Opt-in retro look, modelled on how real-CRT shaders (VileR/FFmpeg, crt-lottes)
   are built rather than a grid drawn on top:

     1. The CONTENT gets a soft blur + brightness/contrast/saturation bump, so
        pixels read as glowing phosphor and to pre-compensate for step 2's
        darkening. This is half of what sells "CRT".
     2. The overlay's scanlines + shadow mask are applied with mix-blend-mode:
        multiply, so they darken lit pixels but leave black black - exactly like
        a real tube, where dark areas emit no beam and show no scanline.

   Unlike the earlier static version this does per-frame GPU compositing (a blend
   layer + a canvas filter), so it is heavier - fine on a desktop, and it stays
   opt-in so low-power boards (RPi) can leave it off. Sits above the game canvas
   + HUD (z 15/16), below the 2P modal (z 30); pointer-events:none. */

/* 1. Phosphor glow on the content itself. */
body.crt-on #pihole-canvas,
body.crt-on #starfield,
body.crt-on #bg-image {
  filter: saturate(1.18) contrast(1.05) brightness(1.22) blur(0.5px);
}

/* 2. Scanline + shadow-mask multiply layer. */
#crt-overlay {
  position: fixed; inset: 0;
  z-index: 20;
  pointer-events: none;
  display: none;
  /* Grayscale scanlines (dark gaps, phosphor-line centres pass at white) times a
     near-white RGB shadow mask. background-blend-mode multiplies the two into one
     opaque pattern; mix-blend-mode multiplies THAT onto the game behind it, so it
     structures lit pixels and vanishes on black. */
  background:
    repeating-linear-gradient(
      to bottom,
      rgb(135, 135, 135) 0,
      rgb(255, 255, 255) 2.6px,
      rgb(255, 255, 255) 3.4px,
      rgb(135, 135, 135) 6px
    ),
    repeating-linear-gradient(
      to right,
      rgb(255, 232, 232) 0,   rgb(255, 232, 232) 1px,
      rgb(232, 255, 232) 1px, rgb(232, 255, 232) 2px,
      rgb(232, 232, 255) 2px, rgb(232, 232, 255) 3px
    );
  background-blend-mode: multiply;
  mix-blend-mode: multiply;
  /* Tube edge darkening (multiplied -> a soft vignette / convex-glass read) */
  box-shadow: inset 0 0 200px 60px rgba(0, 0, 0, 0.45);
  /* Ease the effect down over the HUD strip so the readout stays legible; full
     strength above it. The render loop drives both vars: --hud-h is the strip's
     on-screen height (shrinks as auto-hide slides it away) and --crt-floor is the
     reduction over that band (0.58 shown -> 1 hidden), so the filter fills back in
     as the HUD leaves. Defaults (0px / 1) = full effect when JS hasn't run yet. */
  -webkit-mask-image: linear-gradient(to top,
    rgba(0, 0, 0, var(--crt-floor, 1)) 0,
    rgba(0, 0, 0, var(--crt-floor, 1)) var(--hud-h, 0px),
    #000 calc(var(--hud-h, 0px) + 64px));
  mask-image: linear-gradient(to top,
    rgba(0, 0, 0, var(--crt-floor, 1)) 0,
    rgba(0, 0, 0, var(--crt-floor, 1)) var(--hud-h, 0px),
    #000 calc(var(--hud-h, 0px) + 64px));
}
body.crt-on #crt-overlay { display: block; }

/* 3. Additive phosphor glow so the effect still reads on near-black areas - a
   real tube is never truly off-black; the phosphor rows glow and the glass
   diffuses a little light. Screen blend lifts darks (a faint line of light on
   each 6px row, aligned to the multiply scanlines) and barely touches pixels
   that are already bright. This is what gives the dark space background CRT
   presence without a fake grid painted over the black. */
#crt-glow {
  position: fixed; inset: 0;
  z-index: 19;
  pointer-events: none;
  display: none;
  mix-blend-mode: screen;
  background:
    repeating-linear-gradient(
      to bottom,
      rgba(0, 0, 0, 0)          0,
      rgba(170, 190, 225, 0.07) 3px,
      rgba(0, 0, 0, 0)          6px
    ),
    linear-gradient(rgba(120, 140, 180, 0.02), rgba(120, 140, 180, 0.02));
  -webkit-mask-image: linear-gradient(to top,
    rgba(0, 0, 0, var(--crt-floor, 1)) 0,
    rgba(0, 0, 0, var(--crt-floor, 1)) var(--hud-h, 0px),
    #000 calc(var(--hud-h, 0px) + 64px));
  mask-image: linear-gradient(to top,
    rgba(0, 0, 0, var(--crt-floor, 1)) 0,
    rgba(0, 0, 0, var(--crt-floor, 1)) var(--hud-h, 0px),
    #000 calc(var(--hud-h, 0px) + 64px));
}
body.crt-on #crt-glow { display: block; }

/* Gentle brightness flicker (opacity modulates the multiply strength). */
@media (prefers-reduced-motion: no-preference) {
  body.crt-on #crt-overlay { animation: crt-flicker 6s ease-in-out infinite; }
}
@keyframes crt-flicker {
  0%, 100% { opacity: 1; }
  48%      { opacity: 0.96; }
  50%      { opacity: 0.99; }
  52%      { opacity: 0.95; }
}

/* One-shot CRT power flash. Sits above the scanline layer, screen-blends so it
   only adds light (never blacks out the game), stays transparent at rest, and is
   driven by a class JS adds for a single animation. Ignores reduced-motion by
   design (opt-in, one-shot on a deliberate toggle). */
#crt-power {
  position: fixed; inset: 0;
  pointer-events: none;
  opacity: 0;
  mix-blend-mode: screen;
  transform-origin: center center;
  will-change: opacity, transform;
}

/* Soft center-weighted band rather than a full white sheet: even at full opacity
   the top/bottom stay clear, so the flash reads as a gentle beam rather than a
   blinding wash. scaleY opens/collapses the band for the power on/off. */
#crt-power {
  z-index: 21;
  background: linear-gradient(to bottom,
    rgba(0, 0, 0, 0)          0,
    rgba(0, 0, 0, 0)          8%,
    rgba(218, 236, 255, 0.42) 50%,
    rgba(0, 0, 0, 0)          92%,
    rgba(0, 0, 0, 0)          100%);
}
/* Opt-in CRT toggle flash; ignores prefers-reduced-motion by design. */
#crt-power.on  { animation: crt-power-on  460ms cubic-bezier(0.2, 0.8, 0.3, 1); }
#crt-power.off { animation: crt-power-off 420ms cubic-bezier(0.6, 0, 0.9, 0.4); }
@keyframes crt-power-on {
  0%   { opacity: 0;    transform: scaleY(0.04); }
  10%  { opacity: 0.75; transform: scaleY(0.04); }  /* soft beam-line */
  42%  { opacity: 0.3;  transform: scaleY(1);    }  /* line eases open, dim */
  100% { opacity: 0;    transform: scaleY(1);    }
}
@keyframes crt-power-off {
  0%   { opacity: 0;    transform: scaleY(1)    scaleX(1);    }
  26%  { opacity: 0.3;  transform: scaleY(1)    scaleX(1);    }  /* soft flare */
  62%  { opacity: 0.7;  transform: scaleY(0.04) scaleX(1);    }  /* collapse to a beam-line */
  85%  { opacity: 0.55; transform: scaleY(0.04) scaleX(0.14); }  /* pinch toward a dot */
  100% { opacity: 0;    transform: scaleY(0.02) scaleX(0);    }
}

/* Tube warm-up / cool-down, run in step with the power flash so the filter itself
   fades in/out instead of snapping. crt-warming/crt-cooling are added alongside the
   flash and cleared on its animationend (matched durations). These take over the
   scanline layer's `animation` slot during the transition (the steady flicker
   resumes once the class is gone) and, like the flash, ignore reduced-motion. */
body.crt-warming #crt-overlay,
body.crt-warming #crt-glow { animation: crt-layer-in  460ms ease-out; }
body.crt-cooling #crt-overlay,
body.crt-cooling #crt-glow { animation: crt-layer-out 420ms ease-in forwards; }
@keyframes crt-layer-in {
  0%   { opacity: 0;   }
  35%  { opacity: 0.3; }
  75%  { opacity: 1;   }
  100% { opacity: 1;   }
}
@keyframes crt-layer-out {
  0%   { opacity: 1;    }
  40%  { opacity: 0.8;  }   /* hold through the flare */
  72%  { opacity: 0.22; }   /* drop as the beam collapses */
  100% { opacity: 0;    }
}

/* Content phosphor bump eases in/out too, from the identity filter to the steady
   value set by `body.crt-on` above (kept in sync with that rule). */
body.crt-warming #pihole-canvas,
body.crt-warming #starfield,
body.crt-warming #bg-image { animation: crt-content-in  460ms ease-out; }
body.crt-cooling #pihole-canvas,
body.crt-cooling #starfield,
body.crt-cooling #bg-image { animation: crt-content-out 420ms ease-in forwards; }
@keyframes crt-content-in {
  from { filter: saturate(1) contrast(1) brightness(1) blur(0); }
  to   { filter: saturate(1.18) contrast(1.05) brightness(1.22) blur(0.5px); }
}
@keyframes crt-content-out {
  from { filter: saturate(1.18) contrast(1.05) brightness(1.22) blur(0.5px); }
  to   { filter: saturate(1) contrast(1) brightness(1) blur(0); }
}

/* Settings burger button; bottom synced by JS on resize */
#settings-btn {
  position: fixed;
  left: 14px;
  bottom: 44px; /* JS overrides this on load via resize(); vertically centered in HUD strip */
  width: 24px;
  height: 20px;
  display: none;
  z-index: 16;
  cursor: pointer;
  opacity: 0.48;
  transition: opacity 150ms ease;
}
#settings-btn:hover  { opacity: 0.88; }
#settings-btn.menu-open { opacity: 0.95; }
#settings-btn.menu-open::before {
  content: '';
  position: absolute;
  top: -30px;
  left: -14px;
  right: -26px;
  bottom: -6px;
}

#settings-btn span {
  position: absolute;
  left: 0;
  width: 22px;
  height: 2px;
  background: rgba(140, 160, 175, 0.95);
  border-radius: 1px;
  transform-origin: center center;
  /* Closing: crisp snap back, top-first */
  transition: transform 200ms cubic-bezier(0.4, 0, 0.2, 1), opacity 160ms ease;
}
#settings-btn span:nth-child(1) { top: 0;    transition-delay: 0ms;  }
#settings-btn span:nth-child(2) { top: 9px;  transition-delay: 10ms; }
#settings-btn span:nth-child(3) { top: 18px; transition-delay: 20ms; }

@keyframes ph-float-1 {
  0%   { transform: translate(-6px,  -15px) rotate(-38deg) skewY(-22deg) scaleX(0.60); opacity: 0.62; }
  18%  { transform: translate(-10px, -18px) rotate(-42deg) skewY(-26deg) scaleX(0.60); opacity: 0.58; }
  36%  { transform: translate(-3px,  -21px) rotate(-34deg) skewY(-18deg) scaleX(0.60); opacity: 0.68; }
  55%  { transform: translate(2px,   -14px) rotate(-30deg) skewY(-15deg) scaleX(0.60); opacity: 0.65; }
  74%  { transform: translate(-7px,  -11px) rotate(-41deg) skewY(-25deg) scaleX(0.60); opacity: 0.59; }
  88%  { transform: translate(-9px,  -17px) rotate(-44deg) skewY(-27deg) scaleX(0.60); opacity: 0.61; }
  100% { transform: translate(-6px,  -15px) rotate(-38deg) skewY(-22deg) scaleX(0.60); opacity: 0.62; }
}
@keyframes ph-float-2 {
  0%   { transform: translate(7px,  -20px) rotate(6deg)   skewY(16deg)  scaleX(0.76); opacity: 0.68; }
  22%  { transform: translate(12px, -23px) rotate(10deg)  skewY(12deg)  scaleX(0.76); opacity: 0.64; }
  44%  { transform: translate(14px, -15px) rotate(13deg)  skewY(9deg)   scaleX(0.76); opacity: 0.72; }
  62%  { transform: translate(5px,  -13px) rotate(2deg)   skewY(20deg)  scaleX(0.76); opacity: 0.66; }
  80%  { transform: translate(3px,  -22px) rotate(-1deg)  skewY(23deg)  scaleX(0.76); opacity: 0.70; }
  100% { transform: translate(7px,  -20px) rotate(6deg)   skewY(16deg)  scaleX(0.76); opacity: 0.68; }
}
@keyframes ph-float-3 {
  0%   { transform: translate(16px, -3px)  rotate(30deg)  skewY(-26deg) scaleX(0.48); opacity: 0.58; }
  20%  { transform: translate(11px, -8px)  rotate(24deg)  skewY(-20deg) scaleX(0.48); opacity: 0.64; }
  42%  { transform: translate(8px,  -5px)  rotate(21deg)  skewY(-17deg) scaleX(0.48); opacity: 0.61; }
  64%  { transform: translate(13px, -1px)  rotate(27deg)  skewY(-23deg) scaleX(0.48); opacity: 0.55; }
  84%  { transform: translate(19px, -7px)  rotate(36deg)  skewY(-31deg) scaleX(0.48); opacity: 0.62; }
  100% { transform: translate(16px, -3px)  rotate(30deg)  skewY(-26deg) scaleX(0.48); opacity: 0.58; }
}

/* Opening: hard spring blast, bottom-first */
#settings-btn.menu-open span {
  transition: transform 360ms cubic-bezier(0, 0, 0.15, 1), opacity 280ms ease;
}
#settings-btn.menu-open span:nth-child(1) {
  transform: translate(-6px, -15px) rotate(-38deg) skewY(-22deg) scaleX(0.60);
  opacity: 0.62;
  transition-delay: 32ms;
  animation: ph-float-1 22s linear 0.42s infinite;
}
#settings-btn.menu-open span:nth-child(2) {
  transform: translate(7px, -20px) rotate(6deg) skewY(16deg) scaleX(0.76);
  opacity: 0.68;
  transition-delay: 16ms;
  animation: ph-float-2 17s linear 0.40s infinite;
}
#settings-btn.menu-open span:nth-child(3) {
  transform: translate(16px, -3px) rotate(30deg) skewY(-26deg) scaleX(0.48);
  opacity: 0.58;
  transition-delay: 0ms;
  animation: ph-float-3 27s linear 0.38s infinite;
}

/* Pi-hole dashboard link - hidden DOM element used only as a URL carrier */
#pihole-link { display: none; }

/* ── 2-player modal ──────────────────────────────────────────────── */
#m2p-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(0, 0, 0, 0.68);
  align-items: center;
  justify-content: center;
}
#m2p-overlay.m2p-open { display: flex; }

#m2p-box {
  position: relative;
  background: rgba(8, 11, 16, 0.97);
  padding: 26px 30px 24px;
  min-width: 340px;
  max-width: 520px;
  width: calc(100vw - 40px);
  max-height: 90vh;
  overflow-y: auto;
  user-select: none;
  -webkit-user-select: none;
}

/* Bracket corners -- 8 gradient slices: 2 per corner (horizontal + vertical arm) */
#m2p-box::before {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 10;
  background:
    linear-gradient(rgba(140,160,175,0.42),rgba(140,160,175,0.42)) 0     0    /14px 2px  no-repeat,
    linear-gradient(rgba(140,160,175,0.42),rgba(140,160,175,0.42)) 0     0    /2px  14px no-repeat,
    linear-gradient(rgba(140,160,175,0.42),rgba(140,160,175,0.42)) 100%  0    /14px 2px  no-repeat,
    linear-gradient(rgba(140,160,175,0.42),rgba(140,160,175,0.42)) 100%  0    /2px  14px no-repeat,
    linear-gradient(rgba(140,160,175,0.42),rgba(140,160,175,0.42)) 0     100% /14px 2px  no-repeat,
    linear-gradient(rgba(140,160,175,0.42),rgba(140,160,175,0.42)) 0     100% /2px  14px no-repeat,
    linear-gradient(rgba(140,160,175,0.42),rgba(140,160,175,0.42)) 100%  100% /14px 2px  no-repeat,
    linear-gradient(rgba(140,160,175,0.42),rgba(140,160,175,0.42)) 100%  100% /2px  14px no-repeat;
}

/* Inner top glow -- matches the HUD strip highlight */
#m2p-box::after {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 36px;
  pointer-events: none;
  background: linear-gradient(rgba(140,160,175,0.07), rgba(140,160,175,0));
}

#m2p-title {
  font-family: "Press Start 2P", monospace;
  font-size: 10px;
  color: rgba(175, 200, 238, 0.75);
  letter-spacing: 0.06em;
  margin-bottom: 18px;
}

.m2p-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 28px;
}

.m2p-label {
  font-family: "Press Start 2P", monospace;
  font-size: 10px;
  color: rgba(175, 200, 238, 0.55);
  letter-spacing: 0.04em;
  white-space: nowrap;
  flex-shrink: 0;
}

.m2p-status-val {
  font-family: "Press Start 2P", monospace;
  font-size: 10px;
  flex: 1;
}
.m2p-status-val.online  { color: rgba(50,  215, 120, 0.90); }
.m2p-status-val.offline { color: rgba(255,  80,  60, 0.90); }

/* Buttons */
.m2p-btn {
  font-family: "Press Start 2P", monospace;
  font-size: 8px;
  background: none;
  border: 1px solid rgba(140, 160, 175, 0.22);
  color: rgba(175, 200, 238, 0.60);
  padding: 6px 10px;
  cursor: pointer;
  letter-spacing: 0.04em;
  transition: color 120ms, border-color 120ms;
  white-space: nowrap;
  flex-shrink: 0;
}
.m2p-btn:hover           { color: rgba(215,225,248,0.95); border-color: rgba(140,160,175,0.55); }
.m2p-btn.active          { color: rgba(50,215,120,0.95);  border-color: rgba(50,215,120,0.50); }
.m2p-btn.danger:hover    { color: rgba(255,100,80,0.95);  border-color: rgba(255,100,80,0.50); }
.m2p-btn.dim             { opacity: 0.35; cursor: not-allowed; }
.m2p-btn.flash           { color: rgba(50,215,120,0.95);  border-color: rgba(50,215,120,0.50); }

/* Segmented mode buttons sit side by side */
.m2p-seg { display: flex; gap: 6px; }

/* Hash value display */
/* Info text (local mode) */
.m2p-info {
  font-family: "Press Start 2P", monospace;
  font-size: 8px;
  color: rgba(175, 200, 238, 0.45);
  letter-spacing: 0.04em;
  margin: 4px 0;
}
.m2p-error {
  font-family: "Press Start 2P", monospace;
  font-size: 7px;
  color: rgba(255, 100, 80, 0.90);
  letter-spacing: 0.03em;
  line-height: 1.8;
  margin: 8px 0 2px;
}


/* Edit-fields pill toggle -- matches canvas settings pill exactly */
.m2p-pill {
  width: 36px;
  height: 14px;
  position: relative;
  cursor: pointer;
  background: rgba(30, 32, 40, 0.55);
  border: 1px solid rgba(85, 88, 100, 0.50);
  transition: background 120ms, border-color 120ms;
  flex-shrink: 0;
}
.m2p-pill.on {
  background: rgba(50, 215, 120, 0.22);
  border-color: rgba(50, 215, 120, 0.60);
}
.m2p-knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 10px;
  height: 10px;
  background: rgba(95, 100, 115, 0.75);
  transition: left 120ms, background 120ms;
}
.m2p-pill.on .m2p-knob {
  left: 24px;
  background: rgba(50, 215, 120, 0.95);
}

/* Divider */
.m2p-divider {
  height: 1px;
  background: rgba(140, 160, 175, 0.13);
  margin: 13px 0;
}

/* Footer */
.m2p-footer {
  display: flex;
  justify-content: flex-end;
}

/* Error message under save */
.m2p-error {
  font-family: "Press Start 2P", monospace;
  font-size: 8px;
  color: rgba(255, 80, 60, 0.85);
  letter-spacing: 0.03em;
  margin-top: 6px;
}
