/* Fonts per the design file (client-licensed; files in assets/fonts) */
@font-face { font-family: 'Rubik Glitch'; src: url(../assets/fonts/rubik-glitch.woff2) format('woff2'); font-weight: 400; font-display: swap; } /* SIL OFL, see assets/fonts/RubikGlitch-OFL.txt */
@font-face { font-family: 'AT Web'; src: url(../assets/fonts/american-typewriter-bold.woff2) format('woff2'); font-weight: 700; font-display: swap; }
@font-face { font-family: 'AT Web'; src: url(../assets/fonts/american-typewriter-light.woff2) format('woff2'); font-weight: 300; font-display: swap; }

:root {
  --red: #e5202a;
  --red-deep: #b5121b;
  --ink: #120a0a;
  --white: #fff;
  --font-display: 'Rubik Glitch', system-ui, sans-serif;          /* headlines, buttons */
  --font-sans: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-body: 'AT Web', 'American Typewriter', 'Courier New', serif; /* body copy, readings */
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; background: var(--ink); color: var(--white); overflow: hidden; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { font-family: var(--font-body); font-synthesis: none; /* no smeared fake-bold when the typewriter fallback lacks a bold */ -webkit-tap-highlight-color: transparent; user-select: none; }

/* Height is also set from window.innerHeight in app.js: iOS 100vh includes the area behind Safari's toolbars */
#app { position: relative; height: 100vh; height: 100dvh; max-width: 600px; margin: 0 auto; overflow: hidden; }

/* ---------- Screens ---------- */
.screen {
  position: absolute; top: 0; right: 0; bottom: 0; left: 0;
  display: flex; flex-direction: column;
  opacity: 0; visibility: hidden;
  transition: opacity .5s ease, visibility .5s;
  background: var(--ink) center / cover no-repeat;
}
.screen.is-active { opacity: 1; visibility: visible; }

.content {
  position: relative; z-index: 2;
  flex: 1; display: flex; flex-direction: column; align-items: center; text-align: center;
  padding: calc(env(safe-area-inset-top) + 6vh) 12px calc(env(safe-area-inset-bottom) + 4vh);
}
/* Tips screen starts a little higher so the grid + button fit */
[data-screen="tips"] .content { padding-top: calc(env(safe-area-inset-top) + 5vh); }
/* If a screen's content is taller than the phone (small iPhones), the content scrolls instead of hiding buttons */
.content { overflow-y: auto; overflow-x: hidden; /* no sideways scroll (headline canvas is a bit wider) */ -webkit-overflow-scrolling: touch; min-height: 0; overscroll-behavior: contain; }
.content > * { flex-shrink: 0; }
.content > .spacer { flex-shrink: 1; min-height: 16px; }
.content.center { justify-content: center; }
.content.center > * + * { margin-top: 20px; }
.spacer { flex: 1; }

/* Landing art lives on ::before so it can drift, sway and flicker like the reference intro */
.screen--landing { background-image: none; }
.screen--landing::before {
  content: ''; position: absolute; top: -6%; right: -6%; bottom: -6%; left: -6%; background: url(../assets/bg-landing.jpg) center / cover no-repeat;
}
.screen--landing.is-active::before { animation: cam-drift 2.2s cubic-bezier(.2,.6,.3,1) both, cam-sway 6s 2.2s ease-in-out infinite alternate, bulb 5s 1s infinite; }
@keyframes cam-drift { from { transform: scale(1.15) translate(2%, 2%) rotate(-1.5deg); opacity: 0; } 40% { opacity: .5; } to { transform: none; opacity: 1; } }
/* Jump-scare frame: a split-second negative flash + jolt (toggled from JS) */
.screen--landing.scare { filter: invert(1) contrast(1.7) saturate(0); transform: translate(5px, -4px) scale(1.03); }
@keyframes cam-sway { to { transform: translate(-1.2%, .8%) rotate(.6deg) scale(1.02); } }
@keyframes bulb { 0%, 100% { opacity: 1; } 31% { opacity: 1; } 32% { opacity: .35; } 33% { opacity: 1; } 35% { opacity: .5; } 36% { opacity: 1; } 77% { opacity: 1; } 78% { opacity: .2; } 80% { opacity: 1; } }
.screen--landing::after {
  content: ''; position: absolute; top: 0; right: 0; bottom: 0; left: 0;
  background: linear-gradient(180deg, rgba(0,0,0,.35) 0%, transparent 30%, transparent 60%, rgba(0,0,0,.55) 100%);
}
.screen--red { background-image: url(../assets/bg-red.jpg); }
.screen--red::after { content: ''; position: absolute; top: 0; right: 0; bottom: 0; left: 0; background: rgba(200, 10, 20, .35); mix-blend-mode: multiply; }
/* Film grain + uneasy flicker on the red screens */
.screen--red::before { content: ''; position: absolute; top: -20%; right: -20%; bottom: -20%; left: -20%; z-index: 1; pointer-events: none; background: url(../assets/grain.jpg) center / 60% repeat; mix-blend-mode: screen; opacity: .18; }
.screen--red.is-active::before { animation: grain .5s steps(4) infinite; }
.screen--red.is-active::after { animation: red-flicker 7s infinite; }
@keyframes grain { 25% { transform: translate(-4%, 3%); } 50% { transform: translate(3%, -2%); } 75% { transform: translate(-2%, -4%); } }
@keyframes red-flicker { 0%, 100% { opacity: 1; } 48% { opacity: 1; } 49% { opacity: .4; } 50% { opacity: 1; } 52% { opacity: .6; } 53% { opacity: 1; } }

/* ---------- Type ---------- */

/* ---------- Landing: horror glitch headline ---------- */

/* Blood-ink reveal is drawn on a canvas (src/headline.js) so it looks the same in every browser.
   The h1 keeps the layout and is the fallback; it turns invisible only once the canvas is ready. */
.headline { position: relative; }
.ink-reveal.canvas-ready { color: transparent; text-shadow: none; }
.headline-canvas { position: absolute; pointer-events: none; }
/* Every few seconds the headline twitches like something tugged it (transform only) */
.screen--landing.is-active .headline-canvas { -webkit-animation: jerk 5s 4s infinite; animation: jerk 5s 4s infinite; }
@-webkit-keyframes jerk { 0%, 90%, 100% { -webkit-transform: none; } 91% { -webkit-transform: translate(-4px, 1px) skewX(-10deg); } 92% { -webkit-transform: translate(5px, -2px) skewX(8deg); } 93% { -webkit-transform: none; } 95% { -webkit-transform: translateY(2px) scaleY(1.06); } 96% { -webkit-transform: none; } }
@keyframes jerk { 0%, 90%, 100% { transform: none; } 91% { transform: translate(-4px, 1px) skewX(-10deg); } 92% { transform: translate(5px, -2px) skewX(8deg); } 93% { transform: none; } 95% { transform: translateY(2px) scaleY(1.06); } 96% { transform: none; } }
@media (prefers-reduced-motion: reduce) { .screen--landing.is-active .headline-canvas { animation: none; } }
.glitch {
  font-family: var(--font-display); font-weight: 400; text-transform: uppercase;
  font-size: 26px; font-size: clamp(26px, 8vw, 44px); line-height: 1.05; letter-spacing: .02em;
  letter-spacing: .04em;
  text-shadow: 0 2px 0 rgba(0,0,0,.65), 0 0 14px rgba(0,0,0,.7); /* crisp edge + dark halo for contrast on busy art */
}
.glitch--red { color: var(--red); font-size: 28px; font-size: clamp(26px, 8.2vw, 46px); text-shadow: 0 3px 0 #000, 0 0 20px rgba(0,0,0,.85); }
.body-copy { font-weight: 700; font-size: 14px; font-size: clamp(14px, 3.9vw, 18px); line-height: 1.45; max-width: 40ch; text-shadow: 0 1px 3px rgba(0,0,0,.95), 0 0 10px rgba(0,0,0,.7); }
.screen--landing .body-copy { margin-bottom: 18px; }

/* ---------- Button ---------- */
.btn {
  display: inline-block; cursor: pointer; text-decoration: none;
  font-family: var(--font-display); text-transform: uppercase; font-size: 16px; font-size: clamp(16px, 4.6vw, 22px);
  color: var(--white); background: transparent;
  border: 2px solid var(--white); padding: 6px 14px;
  margin-top: 30px;
  transition: background .2s, color .2s;
}
.btn:active { background: var(--white); color: var(--red-deep); }

/* ---------- Tips ---------- */
.tips {
  list-style: none; display: grid; grid-template-columns: 1fr 1fr; gap: 22px 18px; gap: min(22px, 2.5vh) 18px;
  width: 260px; width: min(100%, 310px, 42vh); margin: 0; padding-bottom: 14px;
  font-weight: 700; font-size: 12px; font-size: clamp(11.5px, 3.2vw, 14px); line-height: 1.3; text-shadow: 0 1px 3px rgba(0,0,0,.9);
}
.tips li { display: flex; flex-direction: column; align-items: center; }
/* One line per span, broken exactly as in the design (no extra browser wrapping) */
.tips li > span:not(.tip-icon) { display: block; white-space: nowrap; }
.tip-icon { position: relative; width: 100%; height: 0; padding-bottom: 100%; margin-bottom: 8px; background: #000; border-radius: 6px; }
/* Icons are exported from the design file (assets/tip-*.svg) */
.tip-icon img { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); max-width: 62%; max-height: 64%; }

/* ---------- Camera screen ---------- */
#camera { position: absolute; top: 0; right: 0; bottom: 0; left: 0; width: 100%; height: 100%; object-fit: cover; }
/* Red tint like the design without blend modes (they don't apply over <video> everywhere):
   the camera is desaturated a little, then a see-through red layer sits on top; vignette darkens edges */
#camera { filter: grayscale(.55) contrast(1.1) brightness(.9); }
.camera-shade { position: absolute; top: 0; right: 0; bottom: 0; left: 0; background: rgba(170, 0, 18, .38); }
.camera-shade::before { content: ''; position: absolute; top: 0; right: 0; bottom: 0; left: 0; background: radial-gradient(ellipse at 50% 45%, transparent 45%, rgba(20, 0, 0, .6) 100%); }
.camera-shade::after { content: ''; position: absolute; top: 0; right: 0; bottom: 0; left: 0; background: url(../assets/grain.jpg) center / cover; mix-blend-mode: screen; opacity: .35; }
.radar { position: absolute; left: 50%; top: 46%; width: 125%; height: 0; padding-bottom: 125%; transform: translate(-50%, -50%); pointer-events: none; mix-blend-mode: screen; }
.radar img { position: absolute; top: 0; left: 0; width: 100%; height: 100%; object-fit: contain; animation: pulse 2.4s ease-in-out infinite; }
.radar-line {
  position: absolute; left: calc(50% - 3px); top: 50%; width: 6px; height: 24%; transform-origin: 50% 0;
  background: repeating-linear-gradient(var(--red) 0 16px, transparent 16px 26px);
}
/* Sweep the dashed line around the radar centre while scanning */
/* Fading red wake behind the line */
.radar-trail {
  position: absolute; left: 26%; top: 26%; width: 48%; height: 48%; border-radius: 50%; opacity: 0;
  background: conic-gradient(from 120deg, transparent 0deg, rgba(229,32,42,.55) 59deg, transparent 60deg);
}
/* Smooth continuous sweep; flicker keeps the horror feel */
.screen--camera:not([data-current="found"]):not([data-current="reward"]) .radar-line,
.screen--camera:not([data-current="found"]):not([data-current="reward"]) .radar-trail { animation: sweep 4s linear infinite, flicker 2.3s steps(1) infinite; }
.screen--camera:not([data-current="found"]):not([data-current="reward"]) .radar-trail { opacity: 1; }
@keyframes sweep { to { transform: rotate(360deg); } }
@keyframes flicker {
  0%, 100% { filter: none; }
  8% { filter: brightness(.2); }
  10% { filter: none; }
  47% { filter: brightness(2.5) drop-shadow(0 0 6px var(--red)); }
  49% { filter: none; }
  63% { filter: brightness(.1); }
  64% { filter: none; }
}
@keyframes pulse { 50% { opacity: .75; transform: scale(1.03); } }

.arc-title { position: absolute; z-index: 3; top: calc(env(safe-area-inset-top) + 13vh); left: 50%; transform: translateX(-50%); width: min(80%, 360px); }
.arc-title text { font-family: var(--font-display); font-size: 20px; fill: var(--red); text-transform: uppercase; }

.state { position: absolute; top: 0; right: 0; bottom: 0; left: 0; z-index: 2; display: none; flex-direction: column; align-items: center; }
.state.is-active { display: flex; animation: fade .5s ease; }
@keyframes fade { from { opacity: 0; } }

.center-msg { position: absolute; top: 46%; transform: translateY(-50%); text-align: center; width: 100%; padding: 0 12px; }
.msg-title { color: var(--red); font-size: 22px; font-size: clamp(22px, 6.8vw, 36px); }
.center-msg .body-copy { margin: 2px auto 0; }

.hud {
  position: absolute; left: 0; right: 0; bottom: calc(env(safe-area-inset-bottom) + 5vh);
  display: flex; justify-content: space-between; align-items: flex-end; padding: 0 12px;
}
.hud-label { font-weight: 700; font-size: 15px; line-height: 1.15; margin-bottom: 6px; }
.energy { display: grid; gap: 3px; }
.energy i { display: block; width: 52px; height: 4px; background: var(--red); transform-origin: left; transition: transform .12s linear; }
.hud-right { text-align: right; }
.hud-value { font-weight: 700; font-size: 18px; font-variant-numeric: tabular-nums; }
/* Glitch spike on the readings */
.hud.spike .hud-value, .hud.spike .hud-coords { color: var(--red); text-shadow: 2px 0 rgba(0,255,255,.6), -2px 0 var(--red); animation: shake .15s steps(2) infinite; }
.hud.spike .energy i { background: #fff; }
@keyframes shake { 50% { transform: translate(-2px, 1px) skewX(-8deg); } }
.hud-coords span { font-variant-numeric: tabular-nums; }
.hud-coords { font-weight: 300; display: flex; align-items: center; justify-content: flex-end; color: rgba(229,32,42,.6); font-size: 13px; line-height: 1.2; margin-top: 6px; }
.hazard { color: var(--red); font-size: 22px; margin-right: 10px; }

/* Ghost floats in from a random edge (--from-x/--from-y set in JS), then hovers */
.ghost-btn { position: absolute; top: 20%; height: 60%; left: 50%; transform: translateX(-50%); background: none; border: 0; padding: 0; cursor: pointer; }
.ghost { height: 100%; width: auto; filter: drop-shadow(0 0 30px rgba(0,0,0,.8)); }
.state.is-active .ghost-btn { animation: ghost-in 1.6s cubic-bezier(.2,.7,.2,1) both; }
.state.is-active .ghost { animation: float 3s 1.6s ease-in-out infinite; }
@keyframes ghost-in {
  from { transform: translate(calc(-50% + var(--from-x, 0px)), var(--from-y, 0px)) scale(.5); opacity: 0; filter: blur(8px); }
  60% { opacity: .9; filter: blur(2px); }
}
@keyframes float { 50% { transform: translateY(-12px) rotate(-1.5deg); } }
.ghost-btn.vanish { animation: ghost-out .7s ease-in forwards !important; }
@keyframes ghost-out { to { transform: translateX(-50%) scale(1.4); opacity: 0; filter: blur(14px) brightness(3) sepia(1) hue-rotate(-30deg); } }
@keyframes blink { 50% { opacity: .3; } }
.flash { position: absolute; top: 0; right: 0; bottom: 0; left: 0; z-index: 5; pointer-events: none; background: radial-gradient(circle at 50% 45%, #fff 0, rgba(229,32,42,.8) 30%, transparent 70%); animation: flash .8s ease-out forwards; }
@keyframes flash { from { opacity: 0; } 30% { opacity: 1; } to { opacity: 0; } }
.state[data-state="reward"].is-active .chocolate { animation: choc-in .9s cubic-bezier(.3,1.5,.5,1) both; }
@keyframes choc-in { from { transform: scale(.2) rotate(-12deg); opacity: 0; filter: blur(8px); } }
.state[data-state="reward"].is-active .bottom { animation: fade .6s .6s both; }
.chocolate { position: absolute; top: 28%; width: min(72%, 380px); }
.bottom {
  position: absolute; left: 0; right: 0; bottom: calc(env(safe-area-inset-bottom) + 6vh);
  display: flex; flex-direction: column; align-items: center; text-align: center; padding: 0 12px;
}
.bottom > * + * { margin-top: 14px;
}
.reward-copy { font-size: 12.5px; font-size: clamp(12px, 3.3vw, 15px); max-width: 36ch; }
.code-row { position: relative; display: flex; align-items: center; justify-content: center; }
.code { margin-left: 45px; font-family: var(--font-body); font-weight: 700; color: var(--red); font-size: 26px; font-size: clamp(24px, 7.4vw, 34px); letter-spacing: .04em; user-select: all; text-shadow: 0 2px 6px rgba(0,0,0,.8); }
.copy-btn { margin-left: 8px; width: 34px; height: 34px; padding: 6px; background: none; border: 0; cursor: pointer; }
.copy-btn img { display: block; width: 100%; height: 100%; }
.copy-btn:active { opacity: .6; }
.copied { position: absolute; left: 0; right: 0; top: 100%; font-size: 12px; font-weight: 700; color: #fff; }

/* ---------- Transition FX (landing → tips) ---------- */
.fx { position: absolute; top: 0; right: 0; bottom: 0; left: 0; z-index: 50; pointer-events: none; }
.fx-static { position: absolute; top: 0; right: 0; bottom: 0; left: 0; width: 100%; height: 100%; image-rendering: pixelated; opacity: 0; }
.fx.on-static .fx-static { opacity: 1; }
#app.shake .screen.is-active { animation: screen-shake .4s steps(4); }
@keyframes screen-shake { 25% { transform: translate(-6px, 4px); } 50% { transform: translate(5px, -3px); } 75% { transform: translate(-3px, -5px); } }
.fx-smear {
  position: absolute; left: -5%; width: 110%; top: 0; height: 160%;
  background: url(../assets/blood-smear.png) center top / 100% 100% no-repeat; transform: translateY(-100%);
}
.fx.on-smear .fx-smear { animation: smear .9s cubic-bezier(.7,0,.3,1) forwards; }
@keyframes smear { 0% { transform: translateY(-100%); } 45%, 55% { transform: translateY(-15%); } 100% { transform: translateY(70%); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .screen--landing.is-active::before, .screen--red.is-active::before, .screen--red.is-active::after { animation: none; } }

/* Small diagnostic line on the gate screen */
.gate-reason { font-family: var(--font-sans); font-size: 12px; opacity: .6; max-width: 34ch; }

/* ---------- Orientation guard (phones in landscape) ---------- */
.rotate { position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: 99; display: none; place-items: center; text-align: center; padding: 24px; background: var(--ink); }
@media (orientation: landscape) and (max-height: 500px) { .rotate { display: grid; } }

/* Short screens (small iPhones with Safari bars): tighter tips so the button stays on screen */
@media (max-height: 600px) {
  .tips { font-size: 11px; line-height: 1.2; padding-bottom: 8px; }
  .tip-icon { margin-bottom: 4px; }
  [data-screen="tips"] .content { padding-top: calc(env(safe-area-inset-top) + 4vh); }
}

/* ---------- Button placement: sit under the text, not stuck to the bottom ---------- */
/* Same fixed gap under the button on landing and tips, so both buttons sit at the same height (design: ~14% from bottom) */
.content > .spacer--end { flex: 0 0 10vh; min-height: 0; }
.btn--gap { margin-top: 30px; }
.tips { margin-bottom: 0 !important; }
.bottom { bottom: calc(env(safe-area-inset-bottom) + 12vh); }

/* ---------- Mute toggle ---------- */
.mute-btn {
  position: absolute; z-index: 60; top: calc(env(safe-area-inset-top) + 12px); right: 12px;
  width: 40px; height: 40px; padding: 8px; border-radius: 50%; cursor: pointer;
  background: rgba(0, 0, 0, .45); border: 1px solid rgba(255, 255, 255, .5);
}
.mute-btn svg { display: block; width: 100%; height: 100%; fill: none; stroke: #fff; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.mute-btn svg path:first-child { fill: #fff; }
.mute-btn .icon-off, .mute-btn[aria-pressed="true"] .icon-on { display: none; }
.mute-btn[aria-pressed="true"] .icon-off { display: block; }
#app[data-view="gate"] .mute-btn { display: none; }
@media (max-height: 600px) { .btn--gap { margin-top: 14px; } .content > .spacer--end { flex-basis: 5vh; } }

/* ---------- Revised design (V3) ---------- */
/* Landing: Flipkart Minutes logo above the headline */
.brand-logo { display: block; width: 33%; max-width: 160px; margin-bottom: 2.5vh; filter: drop-shadow(0 2px 6px rgba(0,0,0,.6)); }
/* Ghost found: red + white copy, pulsing red target dot on the ghost (tap cue) */
.found-copy { margin-bottom: 6vh; font-size: 13.5px; font-size: clamp(13px, 3.6vw, 17px); max-width: none; }
.red { color: var(--red); }
.target-dot {
  position: absolute; left: 50%; top: 38%; width: 30px; height: 30px; margin: -15px 0 0 -15px; border-radius: 50%;
  background: radial-gradient(circle, var(--red) 0 52%, transparent 54% 66%, rgba(229,32,42,.9) 68% 100%);
  box-shadow: 0 0 14px rgba(229,32,42,.8); animation: dot-pulse 1.2s ease-in-out infinite;
}
@keyframes dot-pulse { 50% { transform: scale(1.25); box-shadow: 0 0 24px rgba(229,32,42,1); } }
/* Short screens: smaller chocolate so it clears the reward copy */
@media (max-height: 640px) { .chocolate { width: min(60%, 38vh); top: 24%; } }
