/* The Maze - styles. Pixel/monospace system fonts only. CRT effects over the low-res PS1-style canvas are pure CSS. */
:root {
  --bg: #000; --fg: #cfc9bd; --dim: #7d776c; --blood: #b3121a; --blood-hi: #ff2a35; --relic: #f0c870;
  --mono: "Courier New", Consolas, "Lucida Console", "DejaVu Sans Mono", monospace;
  --danger: 0; --pulse: 1s;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg); font-family: var(--mono); overflow: hidden; }
body { -webkit-user-select: none; user-select: none; }

#game { position: relative; width: 100vw; height: 100vh; height: 100dvh; display: flex; align-items: center; justify-content: center; background: #000; }

/* 16:9 stage that always fits the window; font-size scales with its width so everything is proportional */
#stage {
  --w: min(100vw, calc(100vh * 16 / 9));
  position: relative; width: var(--w); height: calc(var(--w) * 9 / 16); overflow: hidden; background: #000;
  font-size: max(9px, calc(var(--w) / 80));
}
#screen { position: absolute; inset: 0; width: 100%; height: 100%; display: block; image-rendering: pixelated; image-rendering: crisp-edges; background: #000; }

/* ---------- FX layers ---------- */
#fx, #fx > div { position: absolute; inset: 0; pointer-events: none; }
#fx { z-index: 3; }
#fx-vignette { background: radial-gradient(ellipse at center, rgba(0,0,0,0) 38%, rgba(0,0,0,.55) 72%, rgba(0,0,0,.92) 100%); }
#fx-scan { background: repeating-linear-gradient(to bottom, rgba(0,0,0,0) 0, rgba(0,0,0,0) 2px, rgba(0,0,0,.14) 3px, rgba(0,0,0,0) 4px); mix-blend-mode: multiply; }
#fx-chroma { background: linear-gradient(to right, rgba(255,0,40,.07), rgba(255,0,40,0) 9%, rgba(0,200,255,0) 91%, rgba(0,200,255,.07)); mix-blend-mode: screen; }
#fx-grain {
  opacity: .10; mix-blend-mode: overlay; background-size: 160px 160px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 .5  0 0 0 0 .5  0 0 0 0 .5  0 0 0 1.4 -.2'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  animation: grain .6s steps(6) infinite;
}
@keyframes grain { 0% { background-position: 0 0; } 20% { background-position: -40px 25px; } 40% { background-position: 30px -60px; } 60% { background-position: -80px -20px; } 80% { background-position: 55px 70px; } 100% { background-position: 0 0; } }

/* red danger vignette that pulses with the heartbeat */
#fx-danger { opacity: var(--danger); transition: opacity .25s linear; }
#fx-danger i { position: absolute; inset: 0; background: radial-gradient(ellipse at center, rgba(120,0,0,0) 30%, rgba(150,0,8,.55) 75%, rgba(200,0,10,.9) 100%); animation: hb var(--pulse) ease-in-out infinite; }
@keyframes hb { 0%, 100% { opacity: .55; } 12% { opacity: 1; } 26% { opacity: .7; } 38% { opacity: .95; } 55% { opacity: .55; } }

/* slow lamp-flicker over the whole picture */
#fx-flicker { background: #000; opacity: 0; animation: lamp 7s steps(1) infinite; }
@keyframes lamp { 0%, 100% { opacity: 0; } 31% { opacity: .0; } 31.4% { opacity: .22; } 31.8% { opacity: 0; } 32.2% { opacity: .35; } 32.6% { opacity: 0; } 71% { opacity: .15; } 71.4% { opacity: 0; } }

#fx-flash { opacity: 0; background: #fff; }
#stage.flash-pickup #fx-flash { background: rgba(240,200,110,.5); animation: flash .6s ease-out 1; }
#stage.caught #fx-flash { background: #a00; animation: flashRed 1.2s ease-out 1; }
@keyframes flash { 0% { opacity: 1; } 100% { opacity: 0; } }
@keyframes flashRed { 0% { opacity: 1; } 40% { opacity: .7; } 100% { opacity: .0; } }

/* screen shake: strong when caught, mild when the thing is very close */
#stage.caught #screen, #stage.caught #hud { animation: shake .09s linear 14; }
#stage.shaky #screen { animation: shake .12s linear infinite; }
@keyframes shake { 0% { transform: translate(0,0); } 25% { transform: translate(-.5%, .4%); } 50% { transform: translate(.45%, -.35%); } 75% { transform: translate(-.3%, -.5%); } 100% { transform: translate(0,0); } }

/* ---------- overlays ---------- */
.overlay {
  position: absolute; inset: 0; z-index: 5; display: none; flex-direction: column; align-items: center; justify-content: center; text-align: center;
  padding: 3% 8%; background: radial-gradient(ellipse at center, rgba(0,0,0,.55) 0%, rgba(0,0,0,.9) 100%);
}
.overlay h1, .overlay h2 { margin: 0 0 .4em; letter-spacing: .22em; font-weight: 700; text-transform: uppercase; color: var(--fg); text-shadow: 2px 0 rgba(255,0,40,.6), -2px 0 rgba(0,220,255,.45); }
.overlay h1 { font-size: 6em; letter-spacing: .3em; margin-right: -.3em; color: #d8d2c4; }
.overlay h2 { font-size: 3.2em; }
#gameover h2 { color: var(--blood-hi); }
.tag { margin: 0 0 1.2em; font-size: 1.5em; color: var(--blood); letter-spacing: .08em; }
.blurb { max-width: 46em; margin: 0 0 1.4em; line-height: 1.55; font-size: 1.25em; color: #a9a396; }
.blurb em { color: var(--blood-hi); font-style: normal; }
.stats { font-size: 1.6em; margin: 0 0 1.4em; color: var(--dim); }
.stats b { color: var(--fg); }
.small { font-size: 1.05em; color: var(--dim); margin: 1.2em 0 0; }
.controls { list-style: none; padding: 0; margin: 0 0 1.6em; display: grid; grid-template-columns: repeat(4, auto); gap: .4em 2.2em; font-size: 1.1em; color: var(--dim); text-align: left; }
.controls b { color: var(--fg); }
.controls span { color: var(--dim); }

button { font: inherit; font-size: 1.3em; padding: .55em 1.8em; margin: .3em; background: #120808; color: var(--fg); border: 2px solid #5a1a1a; cursor: pointer; letter-spacing: .12em; text-transform: uppercase; border-radius: 0; box-shadow: 3px 3px 0 #000; }
button:hover, button:focus-visible { background: #2a0c0c; border-color: var(--blood-hi); color: #fff; outline: none; }
button.primary { border-color: var(--blood); background: #2a0808; }
button.primary:hover, button.primary:focus-visible { background: #4a0c10; }
button.link { font-size: 1em; padding: 0; margin: 0; background: none; border: 0; box-shadow: none; text-transform: none; letter-spacing: 0; color: var(--dim); text-decoration: underline; }
button.link:hover { color: var(--fg); background: none; }

/* glitchy title: two offset copies clipped in animated slices */
.glitch { position: relative; animation: titleJitter 5s steps(1) infinite; }
.glitch::before, .glitch::after { content: attr(data-text); position: absolute; left: 0; top: 0; width: 100%; overflow: hidden; letter-spacing: inherit; text-shadow: none; }
.glitch::before { color: #ff2a35; transform: translate(-.04em, 0); clip-path: inset(0 0 60% 0); animation: glitchA 3.1s steps(1) infinite; mix-blend-mode: screen; }
.glitch::after { color: #19e0ff; transform: translate(.04em, 0); clip-path: inset(60% 0 0 0); animation: glitchB 2.3s steps(1) infinite; mix-blend-mode: screen; }
@keyframes glitchA { 0%, 100% { clip-path: inset(0 0 100% 0); } 4% { clip-path: inset(10% 0 55% 0); transform: translate(-.06em,0); } 6% { clip-path: inset(0 0 100% 0); } 51% { clip-path: inset(45% 0 30% 0); transform: translate(.05em,0); } 53% { clip-path: inset(0 0 100% 0); } 90% { clip-path: inset(70% 0 5% 0); } 92% { clip-path: inset(0 0 100% 0); } }
@keyframes glitchB { 0%, 100% { clip-path: inset(100% 0 0 0); } 12% { clip-path: inset(50% 0 20% 0); transform: translate(.07em,0); } 14% { clip-path: inset(100% 0 0 0); } 62% { clip-path: inset(15% 0 60% 0); } 64% { clip-path: inset(100% 0 0 0); } }
@keyframes titleJitter { 0%, 100% { transform: none; opacity: 1; } 47% { transform: none; opacity: 1; } 47.5% { transform: translate(.02em,0) skewX(-4deg); opacity: .7; } 48% { transform: none; opacity: 1; } 83% { opacity: 1; } 83.4% { opacity: .35; } 83.8% { opacity: 1; } }

/* ---------- HUD ---------- */
#hud { position: absolute; inset: 0; z-index: 4; pointer-events: none; display: none; }
#hud-count { display: none; } /* superseded by #relics (kept because game.js writes to it) */
.lbl { text-transform: uppercase; letter-spacing: .15em; font-size: .85em; color: var(--dim); }
#hud, #hud * { text-shadow: 1px 0 rgba(255,0,40,.55), -1px 0 rgba(0,220,255,.4), 0 0 .3em #000; }
#relics { position: absolute; top: 2.2%; left: 2%; font-size: 1.9em; color: var(--relic); letter-spacing: .08em; }
#relics .lbl { color: #b8a070; font-size: .6em; }
#pips { display: flex; gap: .25em; margin-top: .3em; }
#pips i { display: block; width: .55em; height: .55em; border: 1px solid #5a4a28; background: #120d05; }
#pips i.on { background: var(--relic); border-color: #ffe9b0; box-shadow: 0 0 .4em var(--relic); }
#stamina-wrap { position: absolute; left: 2%; bottom: 3.5%; }
#stamina { width: 14em; height: .6em; margin-top: .3em; background: #1a1a1a; border: 1px solid #444; }
#stamina-fill { height: 100%; width: 100%; background: #b9b3a6; }
#stamina.low #stamina-fill { background: var(--blood-hi); }
#stamina.low { animation: blink .5s steps(1) infinite; }
@keyframes blink { 50% { border-color: var(--blood-hi); } }
#sense { position: absolute; left: 2%; bottom: 10%; display: flex; align-items: center; gap: .4em; opacity: .85; }
#sense i { width: .5em; height: .9em; background: #222; border: 1px solid #333; }
#sense.l1 i:nth-of-type(1), #sense.l2 i:nth-of-type(-n+2), #sense.l3 i { background: var(--relic); border-color: #ffe9b0; box-shadow: 0 0 .4em var(--relic); }
#sense.l3 { animation: sensepulse .6s ease-in-out infinite; }
@keyframes sensepulse { 50% { opacity: .45; } }
#minimap { position: absolute; top: 2.2%; right: 1.5%; display: none; image-rendering: pixelated; width: 17em; height: 17em; border: 1px solid #3a3a3a; opacity: .9; }
#region { position: absolute; top: 2.6%; left: 50%; transform: translateX(-50%); font-size: 1.1em; letter-spacing: .28em; text-transform: uppercase; color: var(--rc, #9a9488); white-space: nowrap; }
#region-pips { margin-left: .8em; letter-spacing: .2em; color: var(--relic); }
#banner { position: absolute; left: 0; right: 0; top: 24%; text-align: center; opacity: 0; transition: opacity 1.6s ease; }
#banner b { display: block; font-size: 3.4em; letter-spacing: .4em; margin-right: -.4em; font-weight: 400; text-transform: uppercase; color: var(--rc, #cfc9bd); }
#banner small { display: block; margin-top: .5em; font-size: 1.15em; letter-spacing: .22em; color: #a9a396; }
#banner.show { opacity: 1; transition: opacity .5s ease; }
.reveal { margin: -.4em 0 1.3em; font-size: 1.25em; color: #a9a396; min-height: 2.6em; }
.reveal b { display: block; color: var(--fg); letter-spacing: .3em; font-size: 1.25em; margin-bottom: .25em; }
body.no-webgl #nogl { display: flex; z-index: 9; }
body.minimap-on #minimap { display: block; }
#hud-keys { position: absolute; right: 2%; bottom: 3%; font-size: .95em; color: #4f4a42; }
#toast { position: absolute; left: 50%; bottom: 17%; transform: translateX(-50%); font-size: 1.7em; letter-spacing: .1em; color: #e6dcc0; text-align: center; opacity: 0; transition: opacity .6s ease; max-width: 80%; font-style: italic; }
#toast.show { opacity: 1; transition: opacity .12s ease; }
#toast.bad { color: var(--blood-hi); }
#lockhint { position: absolute; left: 50%; top: 14%; transform: translateX(-50%); display: none; text-align: center; font-size: 1.2em; color: #e6dcc0; background: rgba(0,0,0,.6); padding: .5em 1em; border: 1px solid #5a1a1a; }
#lockhint small { color: var(--dim); }
#lockhint.show { display: block; animation: blink2 1.4s ease-in-out infinite; }
@keyframes blink2 { 50% { opacity: .55; } }

/* mode visibility */
body[data-mode="menu"] #menu,
body[data-mode="paused"] #pause,
body[data-mode="gameover"] #gameover,
body[data-mode="won"] #win { display: flex; }
body[data-mode="playing"] #hud, body[data-mode="paused"] #hud { display: block; }
body[data-mode="gameover"] #hud, body[data-mode="won"] #hud { display: none; }
body[data-mode="paused"] #fx-danger, body[data-mode="menu"] #fx-danger { opacity: 0; }
body[data-mode="paused"] #pause, body[data-mode="menu"] #menu { cursor: pointer; }
body.locked #game { cursor: none; }
body.dying #hud { display: none !important; }

/* small windows / phones */
@media (max-width: 700px) { .controls { grid-template-columns: repeat(2, auto); } .blurb { font-size: 1.05em; } }

@media (prefers-reduced-motion: reduce) {
  #fx-grain, #fx-flicker, .glitch, .glitch::before, .glitch::after, #fx-danger i, #stage.shaky #screen, #stage.caught #screen, #stage.caught #hud,
  #lockhint.show, #sense.l3, #stamina.low { animation: none !important; }
  #banner { transition: none; }
  #fx-flicker { display: none; }
  .glitch::before, .glitch::after { display: none; }
  #stage.flash-pickup #fx-flash, #stage.caught #fx-flash { animation-duration: .01s !important; }
  #fx-danger i { opacity: .8; }
  #fx-danger { transition: none; }
}
