/* ============================================================
   THE ROOM — HUD / shell styling

   The film grain and vignette live in the post-processing shader
   (js/post.js), NOT here, so they affect the rendered image rather
   than sitting on top of the glass. Only the HUD is drawn in CSS.
   ============================================================ */

:root {
  --ink: #c9cdd2;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: #000;
  overflow: hidden;

  /* A game is not a document. Without this a drag on the canvas scrolls
     the page or pulls to refresh mid-scare. */
  touch-action: none;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  color: var(--ink);
  user-select: none;
  cursor: default;
}

#c {
  display: block;
  width: 100vw;
  height: 100vh;
}

/* ---------- crosshair ---------- */
#crosshair {
  position: fixed;
  left: 50%; top: 50%;
  width: 14px; height: 14px;
  transform: translate(-50%, -50%);
  opacity: .45;
  pointer-events: none;
}
#crosshair::before,
#crosshair::after {
  content: "";
  position: absolute;
  background: #fff;
}
#crosshair::before { left: 50%; top: 0; width: 1px; height: 100%; transform: translateX(-50%); }
#crosshair::after  { top: 50%; left: 0; height: 1px; width: 100%; transform: translateY(-50%); }

/* ---------- battery ---------- */
#battery {
  position: fixed;
  left: 18px; bottom: 18px;
  width: 170px;
  pointer-events: none;
}
#battery .lbl {
  font-size: 10px;
  letter-spacing: 3px;
  opacity: .5;
  margin-bottom: 6px;
}
/* The seconds left in the torch. A spare cell adds twenty to the total, so
   the bar alone can look nearly full for most of a run — the number is the
   thing that says what a cell actually bought you. */
#battery .lbl span {
  float: right;
  letter-spacing: 1px;
  opacity: .85;
  font-variant-numeric: tabular-nums;
}
#battery .bar {
  height: 8px;
  border: 1px solid rgba(255,255,255,.25);
  background: rgba(255,255,255,.04);
}
#battery .fill {
  height: 100%;
  width: 100%;
  background: #e9edf1;
  transition: width .12s linear;
}
#battery .fill.low { background: #c0553f; }

/* ---------- inventory ---------- */
#inventory {
  position: fixed;
  left: 50%; bottom: 18px;
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
  pointer-events: none;
}
.slot {
  position: relative;
  width: 58px; height: 58px;
  border: 1px solid rgba(255,255,255,.16);
  background: rgba(8,10,12,.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 4px;
  font-size: 9px;
  letter-spacing: .5px;
  line-height: 1.15;
  text-align: center;
  color: #dfe3e8;
}
.slot .num {
  position: absolute;
  top: 2px; left: 4px;
  font-size: 9px;
  opacity: .3;
}
.slot.active {
  border-color: rgba(255,255,255,.85);
  box-shadow: 0 0 14px rgba(255,255,255,.18);
}

/* ---------- interaction hint ---------- */
#hint {
  position: fixed;
  left: 50%; top: 58%;
  transform: translateX(-50%);
  font-size: 12px;
  letter-spacing: 1.5px;
  opacity: 0;
  transition: opacity .2s;
  text-shadow: 0 1px 4px #000;
  pointer-events: none;
}
#hint.show { opacity: .8; }

/* ---------- start overlay ---------- */
#overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: rgba(0,0,0,.92);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}
#overlay.hidden { display: none; }
#overlay h1 {
  font-size: 34px;
  letter-spacing: 12px;
  font-weight: 400;
  margin: 0 0 8px;
  color: #eef1f4;
}
#overlay .sub {
  opacity: .4;
  font-size: 11px;
  letter-spacing: 2px;
  margin-bottom: 40px;
  max-width: 80vw;
}
#overlay .keys {
  font-size: 12px;
  line-height: 2.1;
  opacity: .85;
}
#overlay .keys b {
  display: inline-block;
  width: 120px;
  text-align: right;
  margin-right: 16px;
  color: #fff;
  font-weight: 600;
}
#overlay .enter {
  margin-top: 36px;
  font-size: 11px;
  letter-spacing: 6px;
  opacity: .7;
  animation: pulse 2s infinite;
}
/* NOT absolutely positioned any more. Pinned to the bottom of the
   overlay it sat directly on top of the START button on a short screen
   and swallowed the tap, so the button looked broken. In the flow it
   scrolls with everything else, and pointer-events:none means it can
   never intercept a click wherever it lands. */
#overlay .build {
  margin-top: 26px;
  font-size: 10px;
  letter-spacing: 1px;
  opacity: .3;
  pointer-events: none;
}
@keyframes pulse { 50% { opacity: .2; } }

/* ============================================================
   TITLE SCREEN — desktop or mobile
   ------------------------------------------------------------
   body.mobile is set by js/player.js when MOBILE is picked. It swaps
   the control list and (later, on START) turns the thumbsticks on.
   ============================================================ */

#keys-mobile { display: none; }
body.mobile #keys-mobile { display: block; }
body.mobile #keys-desktop { display: none; }

/* small screens are short: let the title screen scroll instead of
   clipping the START button off the bottom */
#overlay { overflow-y: auto; touch-action: pan-y; padding: 24px 16px; }

.modes {
  display: flex;
  gap: 10px;
  margin-top: 12px;      /* the two button rows sit as one block */
}
/* ...and the level row is the top of that block, so it takes the gap */
.modes.levels { margin-top: 32px; }
.modebtn, .levelbtn {
  font: inherit;
  font-size: 11px;
  letter-spacing: 4px;
  padding: 10px 22px;
  color: var(--ink);
  background: rgba(255,255,255,.03);
  border: 1px solid rgba(255,255,255,.18);
  cursor: pointer;
  transition: color .15s, border-color .15s, background .15s, box-shadow .15s;
}
.modebtn:hover, .levelbtn:hover { border-color: rgba(255,255,255,.4); }
.modebtn.on, .levelbtn.on {
  color: #fff;
  border-color: rgba(255,255,255,.85);
  background: rgba(255,255,255,.10);
  box-shadow: 0 0 18px rgba(255,255,255,.12);
}

#startBtn {
  margin-top: 30px;
  font: inherit;
  font-size: 13px;
  letter-spacing: 8px;
  text-indent: 8px;          /* letter-spacing pads the right edge only */
  padding: 15px 54px;
  color: #0a0b0d;
  background: #e9edf1;
  border: 1px solid #e9edf1;
  cursor: pointer;
  transition: background .15s, box-shadow .15s;
}
#startBtn:hover { background: #fff; box-shadow: 0 0 26px rgba(255,255,255,.30); }

/* ============================================================
   THUMBSTICKS — mobile mode only, and only once playing
   ------------------------------------------------------------
   There is no fixed stick any more. The two halves of the screen ARE
   the zones: a stick is spawned — and shown — wherever your thumb
   lands, and taken away when you lift it. js/touch.js decides which
   half, and is the only thing that listens; everything here is paint.

   The layer covers the whole screen so it catches every stroke, which
   means the HUD has to stay reachable: the two buttons are z-indexed
   above it, and the inventory is read-only (the cycle button moves it).
   ============================================================ */
.touch-layer {
  position: fixed;
  inset: 0;
  display: none;
  z-index: 30;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}
body.touch-on .touch-layer { display: block; }
/* nothing gets in the way of the face */
body.touch-on.scare .touch-layer,
body.touch-on.scare .touch-btn { display: none; }

/* ---------- a spawned stick ----------
   126 px across, which is RADIUS * 2 in js/touch.js — keep them
   together. left/top are set to the touch point in px; the transform
   pulls the ring back onto its own centre. pointer-events: none so the
   ring never steals the stroke that spawned it. */
.pad {
  position: absolute;
  left: 0;
  top: 0;
  width: 126px;
  height: 126px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,.34);
  background: rgba(255,255,255,.06);
  /* a thin dark edge outside the light one, so the ring reads against a
     lit wall as well as against the dark. This game is mostly dark, but
     not when the torch is on a white wall half a metre away. */
  box-shadow: 0 0 0 1.5px rgba(0,0,0,.30);
  transform: translate(-50%,-50%);
  opacity: 0;
  pointer-events: none;
}
/* No fade, deliberately. A transition on opacity means the stick is only
   there if the browser gets round to running the animation, and a control
   that is invisible when it misbehaves is the worst failure a touch
   control can have. It appears on the frame you put your thumb down. */
.pad.on { opacity: 1; }

.pad-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: rgba(233,237,241,.30);
  border: 1px solid rgba(255,255,255,.5);
  box-shadow: 0 0 0 1.5px rgba(0,0,0,.34);
  transform: translate(-50%,-50%);
  pointer-events: none;
}
.pad-knob.on { background: rgba(233,237,241,.62); }

/* ---------- flashlight / cycle-item buttons ----------
   A phone has no F and no E, and the flashlight is the only real light
   in the game. Kept up in the top corner so they never sit under a thumb. */
.touch-btn {
  position: fixed;
  top: 16px;
  right: 16px;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  display: none;
  z-index: 31;
  font: inherit;
  font-size: 17px;
  line-height: 1;
  color: #dfe3e8;
  background: rgba(8,10,12,.55);
  border: 1px solid rgba(255,255,255,.22);
  cursor: pointer;
  touch-action: none;
}
.touch-item { right: 72px; }
body.touch-on .touch-btn { display: block; }
.touch-btn.on { background: rgba(233,237,241,.30); }

/* the flashlight bar would otherwise sit under the left thumb */
body.touch-on #battery {
  left: 16px;
  bottom: auto;
  top: 20px;
  width: 108px;
}
body.touch-on .slot { width: 44px; height: 44px; font-size: 8px; }
body.touch-on #inventory { bottom: 8px; gap: 5px; }

/* ---------- short screens ----------
   A phone held sideways is about 380 px tall, and the title screen has
   to fit the mode buttons AND the START button without one of them
   being pushed off the bottom. Tighten everything rather than let the
   player hunt for the button. */
@media (max-height: 500px) {
  #overlay h1 { font-size: 21px; letter-spacing: 8px; margin-bottom: 4px; }
  #overlay .sub { margin-bottom: 12px; }
  #overlay .keys { font-size: 10px; line-height: 1.65; }
  .modes { margin-top: 9px; }
  .modes.levels { margin-top: 20px; }
  .modebtn, .levelbtn { padding: 8px 16px; letter-spacing: 3px; }
  #startBtn { margin-top: 13px; padding: 11px 38px; font-size: 12px; }
  #overlay .build { margin-top: 14px; }
}

/* ---------- when it has you ----------
   The HUD is yours; the view is not. Get all of it out of the way so the
   only thing on screen is its face. js/haunt.js puts .scare on <body> for
   the duration of the catch. */
body.scare #crosshair,
body.scare #hint,
body.scare #inventory,
body.scare #battery {
  opacity: 0 !important;
  transition: opacity .18s;
}

/* ---------- end card ---------- */
#scareEnd {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: #000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  opacity: 0;
  transition: opacity 1.6s ease-out;
  cursor: pointer;
}
#scareEnd.on { opacity: 1; }
#scareEnd .msg {
  font-size: 30px;
  letter-spacing: 14px;
  color: #b8342a;
  text-shadow: 0 0 26px rgba(184,52,42,.55);
}

/* the OTHER ending: out through the door. Same card, but it reads as
   relief rather than as a threat. */
#scareEnd.win .msg {
  color: #cfe6c6;
  text-shadow: 0 0 26px rgba(160,220,150,.45);
}
#scareEnd .sub {
  font-size: 11px;
  letter-spacing: 5px;
  opacity: .4;
  animation: pulse 2s infinite;
}

/* ---------- arriving mid-game ----------
   #fade is the end of a level: black, over a beat, and then the page
   changes. #curtain is the other side of that page change — the same
   black, held, with one line on it, until the player clicks.

   Both are pointer-events:none on purpose, so the click that dismisses
   the curtain is the SAME CLICK that starts the game underneath it, and
   the player never has to press the same button twice. */
#fade, #curtain {
  position: fixed;
  inset: 0;
  z-index: 58;
  background: #000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  opacity: 0;
  pointer-events: none;
}
#fade { transition: opacity 1.15s ease-in; }
#fade.on { opacity: 1; }
#curtain { transition: opacity .8s ease-out; }
#curtain.on { opacity: 1; }
#curtain .msg {
  font-size: 26px;
  letter-spacing: 12px;
  color: #cfe6c6;
  text-shadow: 0 0 26px rgba(160,220,150,.35);
}
#curtain .sub {
  font-size: 11px;
  letter-spacing: 5px;
  opacity: .4;
  animation: pulse 2s infinite;
}
