:root {
  --bg:     #070709;
  --fg:     #e8e8e8;
  --dim:    rgba(232,232,232,0.32);
  --green:  #39ff14;
  --red:    #ff4d6d;
  --gold:   #ffd700;
  --nav-h:  52px;
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: 'Courier New', Courier, monospace;
  overflow: hidden;
}

/* ─── CRT EFFECTS ─────────────────────────── */

/* scanlines */
body::before {
  content: '';
  position: fixed; inset: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0,0,0,0.15) 2px,
    rgba(0,0,0,0.15) 4px
  );
  pointer-events: none;
  z-index: 9999;
}

/* vignette */
body::after {
  content: '';
  position: fixed; inset: 0;
  background: radial-gradient(ellipse at center, transparent 55%, rgba(0,0,0,0.65) 100%);
  pointer-events: none;
  z-index: 9998;
}

/* screen flicker */
@keyframes flicker {
  0%, 97%, 100% { opacity: 1; }
  97.5%         { opacity: 0.85; }
  98%           { opacity: 1; }
  98.5%         { opacity: 0.92; }
}
body { animation: flicker 8s infinite; }

/* ─── BOOT SCREEN ─────────────────────────── */
#boot {
  position: fixed; inset: 0; z-index: 10000;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  flex-direction: column; gap: 12px;
  transition: opacity .4s ease;
}
#boot.done { opacity: 0; pointer-events: none; }

#boot-text {
  font-size: clamp(0.7rem, 2vw, 0.85rem);
  letter-spacing: 0.1em;
  color: var(--green);
  text-shadow: 0 0 10px var(--green);
  text-align: left;
  white-space: pre;
  line-height: 1.8;
}

#boot-cursor {
  display: inline-block;
  width: 8px; height: 1.1em;
  background: var(--green);
  box-shadow: 0 0 8px var(--green);
  animation: blink-cursor .6s step-end infinite;
  vertical-align: text-bottom;
  margin-left: 2px;
}

@keyframes blink-cursor {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0; }
}

/* ─── NAV ─────────────────────────────────── */
nav {
  position: fixed; top: 0; left: 0; right: 0;
  height: var(--nav-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px;
  border-bottom: 1px solid rgba(57,255,20,0.08);
  background: var(--bg);
  z-index: 100;
}

/* glitch logo */
.logo {
  font-size: 0.88rem;
  letter-spacing: 0.24em;
  color: var(--green);
  text-shadow: 0 0 16px var(--green);
  position: relative;
  cursor: default;
}

.logo:hover {
  animation: glitch .3s linear;
}

@keyframes glitch {
  0%   { text-shadow: 0 0 16px var(--green); }
  10%  { text-shadow: -2px 0 #ff00ff, 2px 0 #00ffff, 0 0 16px var(--green); transform: translate(1px, -1px); }
  20%  { text-shadow: 2px 0 #ff00ff, -2px 0 #00ffff, 0 0 16px var(--green); transform: translate(-1px, 1px); }
  30%  { text-shadow: 0 0 16px var(--green); transform: translate(0); }
  50%  { text-shadow: -1px 1px #ff00ff, 1px -1px #00ffff, 0 0 16px var(--green); transform: translate(2px, 0); clip-path: inset(40% 0 20% 0); }
  60%  { clip-path: inset(0); transform: translate(0); }
  70%  { text-shadow: 2px 0 #ff00ff, -1px 0 #00ffff; transform: translate(-1px, 1px); clip-path: inset(10% 0 60% 0); }
  80%  { clip-path: inset(0); transform: translate(0); text-shadow: 0 0 16px var(--green); }
  100% { text-shadow: 0 0 16px var(--green); transform: translate(0); }
}

.nav-links { display: flex; gap: 4px; }

.nb {
  background: none; border: none;
  font: inherit; font-size: 0.66rem;
  letter-spacing: 0.15em; text-transform: uppercase;
  color: var(--dim); cursor: pointer;
  padding: 6px 12px; border-radius: 4px;
  transition: color .15s, background .15s, text-shadow .15s;
  position: relative;
}
.nb:hover  { color: var(--fg); }
.nb.on {
  color: var(--green);
  background: rgba(57,255,20,.07);
  text-shadow: 0 0 8px rgba(57,255,20,.5);
}
.nb.on::after {
  content: '';
  position: absolute; bottom: 2px; left: 20%; right: 20%;
  height: 1px;
  background: var(--green);
  box-shadow: 0 0 6px var(--green);
  animation: pulse-bar 2s ease-in-out infinite;
}
@keyframes pulse-bar {
  0%, 100% { opacity: .4; }
  50%      { opacity: 1; }
}

/* ─── PAGES ───────────────────────────────── */
.pg {
  position: fixed; top: var(--nav-h); left: 0; right: 0; bottom: 0;
  opacity: 0; pointer-events: none;
  transition: opacity .25s ease;
  overflow-y: auto;
}
.pg.on { opacity: 1; pointer-events: all; }

/* glitch-in on page switch */
.pg.glitch-in {
  animation: page-glitch .35s ease-out;
}
@keyframes page-glitch {
  0%   { opacity: 0; transform: translateX(4px); filter: hue-rotate(90deg) brightness(2); }
  20%  { opacity: 1; transform: translateX(-2px); filter: hue-rotate(0) brightness(1.4); }
  40%  { transform: translateX(1px); filter: brightness(1); }
  60%  { transform: translateX(-1px) skewX(-0.5deg); }
  100% { transform: translateX(0) skewX(0); filter: none; }
}

/* ─── SNAKE PAGE ──────────────────────────── */
#pg-snake {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 10px 16px 16px;
}

#hud {
  display: flex; gap: 28px;
  margin-bottom: 10px;
  font-size: 0.68rem; letter-spacing: 0.12em;
}
#hud span { opacity: 0.3; }
#hud b {
  font-weight: normal; font-size: 1rem;
  display: inline-block;
  transition: transform .08s, color .08s;
}
#hud b.pop { transform: scale(1.6); color: var(--green); text-shadow: 0 0 12px var(--green); }

#cv {
  display: block;
  border: 1px solid rgba(57,255,20,.15);
  box-shadow:
    0 0 50px rgba(57,255,20,.06),
    0 0 120px rgba(57,255,20,.03),
    inset 0 0 40px rgba(57,255,20,.02);
  cursor: pointer;
  width:  min(calc(100vw - 32px), 400px);
  height: min(calc(100vw - 32px), 400px);
  border-radius: 2px;
}

#msg {
  margin-top: 10px; font-size: 0.66rem;
  letter-spacing: .1em; opacity: .26;
  transition: opacity .3s;
}
#lv {
  margin-top: 4px; font-size: 0.6rem;
  letter-spacing: .12em; opacity: .18;
  min-height: 13px;
  text-shadow: 0 0 6px rgba(57,255,20,.3);
}

/* d-pad */
#dpad {
  display: none; margin-top: 18px;
  grid-template-areas: ". u ." "l . r" ". d .";
  gap: 5px;
}
@media (pointer: coarse) { #dpad { display: grid; } }
.dp {
  width: 52px; height: 52px;
  background: rgba(255,255,255,.05);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 10px; color: var(--fg);
  font-size: 1.1rem;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  transition: background .1s, box-shadow .1s;
}
.dp:active {
  background: rgba(57,255,20,.18);
  box-shadow: 0 0 14px rgba(57,255,20,.3);
}
#du { grid-area: u; } #dl { grid-area: l; }
#dr { grid-area: r; } #dd { grid-area: d; }

/* ─── WRITING PAGE ────────────────────────── */
#pg-writing {
  display: flex; flex-direction: column;
  align-items: center;
  padding: 60px 24px 80px;
}

.w-title {
  font-size: clamp(1.2rem, 4vw, 1.8rem);
  letter-spacing: .22em; text-transform: uppercase;
  font-weight: normal; margin-bottom: 8px;
}
.w-sub { font-size: .73rem; letter-spacing: .1em; opacity: .28; margin-bottom: 52px; }

.post-list {
  width: 100%; max-width: 540px;
  border-top: 1px solid rgba(255,255,255,.07);
}
.post {
  display: flex; align-items: baseline;
  justify-content: space-between;
  padding: 22px 0;
  border-bottom: 1px solid rgba(255,255,255,.04);
  gap: 20px;
}
.pt { font-size: .86rem; letter-spacing: .04em; opacity: .12; font-style: italic; }
.pd { font-size: .6rem;  letter-spacing: .12em; opacity: .08; white-space: nowrap; }
.w-soon {
  margin-top: 42px; font-size: .62rem;
  letter-spacing: .18em; text-transform: uppercase; opacity: .14;
}

/* ─── MYSTERY PAGE ────────────────────────── */
#pg-mystery {
  position: fixed; top: var(--nav-h);
  background: #000; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
}

#mcursor {
  position: absolute; width: 7px; height: 7px;
  border-radius: 50%; background: rgba(255,255,255,.45);
  pointer-events: none; display: none;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 10px rgba(255,255,255,.25);
}
