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

:root {
  --bg: #000;
  --panel: #0e1213;
  --line: #1f2a2b;
  --text: #d8d8d0;
  --dim: #7a7a72;
  --accent: #6dffb0;
  --red: #ff3030;
  --font: 'Consolas', 'Leelawadee UI', 'Tahoma', monospace;
  --thai: 'Leelawadee UI', 'Sarabun', 'Tahoma', 'Noto Sans Thai', sans-serif;
}

html, body { height: 100%; background: var(--bg); color: var(--text); font-family: var(--font); overflow: hidden; }
.hidden { display: none !important; }

/* shared with editor.html */
.panel-title { font-size: 12px; color: var(--dim); letter-spacing: 3px; }
.section-label { font-size: 11px; color: var(--dim); letter-spacing: 3px; margin-top: 6px; border-bottom: 1px solid var(--line); padding-bottom: 4px; }

/* ---------- Full-screen camera ---------- */
#game { position: fixed; inset: 0; background: #000; display: flex; align-items: center; justify-content: center; overflow: hidden; }
#screen {
  position: relative;
  /* largest 16:9 box that fits the window (fills a 16:9 monitor completely) */
  width: min(100vw, calc(100vh * 16 / 9));
  aspect-ratio: 16 / 9;
  background: #000;
  overflow: hidden;
  will-change: transform;
}
#screen canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
#view { filter: grayscale(1) contrast(1.08) brightness(0.95); } /* grayscale hides tint differences between normal and anomaly images */
#draw { cursor: crosshair; z-index: 5; touch-action: none; }

.scanlines {
  position: absolute; inset: 0; pointer-events: none; z-index: 3;
  background: repeating-linear-gradient(to bottom, rgba(0,0,0,0) 0, rgba(0,0,0,0) 2px, rgba(0,0,0,0.18) 3px);
}
.vignette {
  position: absolute; inset: 0; pointer-events: none; z-index: 3;
  background: radial-gradient(ellipse at center, rgba(0,0,0,0) 55%, rgba(0,0,0,0.7) 100%);
}
#dangerTint {
  position: absolute; inset: 0; pointer-events: none; z-index: 3; opacity: 0;
  background: radial-gradient(ellipse at center, rgba(120,0,0,0) 40%, rgba(150,0,0,0.55) 100%);
  transition: opacity 0.4s;
}

#osd { position: absolute; inset: 0; pointer-events: none; z-index: 4; font-size: clamp(13px, 1.5vw, 26px); color: #fff; text-shadow: 0 0 4px #000, 1px 1px 0 #000; }
#osd > div { position: absolute; }
.osd-tl { top: 3%; left: 2.5%; font-family: var(--thai), var(--font); opacity: 0.85; }
.osd-tr { top: 3%; right: 2.5%; display: flex; align-items: center; gap: 8px; }
.osd-bl { bottom: 3%; left: 2.5%; opacity: 0.8; }
.osd-br { bottom: 3.6%; left: 50%; transform: translateX(-50%); display: flex; gap: 6px; }
.rec-dot { width: 0.7em; height: 0.7em; border-radius: 50%; background: var(--red); animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.cam-dot { width: 0.55em; height: 0.55em; border-radius: 50%; border: 1px solid rgba(255,255,255,0.7); }
.cam-dot.on { background: #fff; box-shadow: 0 0 6px #fff; }

/* left / right arrows */
.arrow {
  position: absolute; top: 50%; transform: translateY(-50%); z-index: 20;
  width: clamp(40px, 4vw, 80px); height: clamp(90px, 14vh, 160px);
  background: transparent; border: none; cursor: pointer; opacity: 0.75; transition: opacity 0.15s, transform 0.15s;
}
.arrow svg { width: 100%; height: 100%; fill: none; stroke: #fff; stroke-width: 3.5; stroke-linecap: round; stroke-linejoin: round; filter: drop-shadow(0 0 4px #000); }
.arrow:hover { opacity: 1; }
#arrowL { left: 1.5vw; }
#arrowR { right: 1.5vw; }
#arrowL:active { transform: translateY(-50%) translateX(-4px); }
#arrowR:active { transform: translateY(-50%) translateX(4px); }

.icon-btn {
  position: absolute; bottom: 2vh; z-index: 20; width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center;
  background: rgba(0,0,0,0.45); border: 1px solid rgba(255,255,255,0.3); color: #fff; cursor: pointer; opacity: 0.6;
  transition: opacity 0.15s, scale 0.15s;
}
.icon-btn:hover { opacity: 1; }
.icon-btn:active { scale: 0.92; }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; overflow: visible; }
#btnMute { right: 1.5vw; }
#btnMute .ico-fill { fill: currentColor; }
/* speaker waves morph into an X when muted */
#btnMute .ico-waves, #btnMute .ico-x { transform-origin: 16px 12px; transition: opacity 0.22s, scale 0.22s cubic-bezier(.2,.8,.2,1); }
#btnMute .ico-x, #btnMute.muted .ico-waves { opacity: 0; scale: 0.4; }
#btnMute.muted .ico-x { opacity: 1; scale: 1; }
.hint-ico { width: 1.2em; height: 1.2em; vertical-align: -0.25em; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }

/* morph: blur + scale in/out when shown or hidden (display transition needs Chrome 117 / Safari 17.4 / Firefox 129, else instant) */
.morph { transition: opacity 0.25s, filter 0.25s, scale 0.25s cubic-bezier(.2,.8,.2,1), display 0.25s allow-discrete; }
.morph.hidden { opacity: 0; filter: blur(8px); scale: 0.97; }
@starting-style { .morph { opacity: 0; filter: blur(8px); scale: 0.97; } }
@media (prefers-reduced-motion: reduce) { .morph, #btnMute * { transition-duration: 0.01s; } }

#processing {
  position: absolute; inset: 0; z-index: 6; display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.35); pointer-events: none;
}
.proc-text { font-family: var(--thai); font-size: clamp(18px, 2.4vw, 40px); color: var(--accent); letter-spacing: 3px; text-shadow: 0 0 10px var(--accent); }
.dots::after { content: ''; animation: dots 1s steps(4) infinite; }
@keyframes dots { 0% { content: ''; } 25% { content: '.'; } 50% { content: '..'; } 75% { content: '...'; } }

/* announcement: no box, pale text bleeding red, flickers like a failing monitor */
#toast {
  position: absolute; left: 50%; top: 13%; transform: translateX(-50%); z-index: 7;
  padding: 0.55em 2.4em; font-family: var(--thai); font-size: clamp(16px, 2vw, 32px); letter-spacing: 2px;
  pointer-events: none; white-space: nowrap; color: #e8e4da;
  background: radial-gradient(ellipse at center, rgba(0,0,0,0.85) 0%, rgba(0,0,0,0.6) 55%, rgba(0,0,0,0) 75%);
  text-shadow: -2px 0 rgba(255,0,0,0.65), 2px 0 rgba(0,180,255,0.25), 0 0 12px rgba(0,0,0,0.9), 0 0 2px #000;
  animation: toast-flicker 2.4s steps(1) infinite, toast-jitter 0.18s steps(2) 3;
}
#toast.bad { color: #ff3a2e; text-shadow: -2px 0 rgba(120,0,0,0.9), 2px 0 rgba(255,255,255,0.15), 0 0 18px rgba(255,0,0,0.55), 0 0 2px #000; }
#toast.good { color: #b9c9bd; }
#toast.info { color: #e8e4da; }
@keyframes toast-flicker {
  0%, 100% { opacity: 1; } 7% { opacity: 0.35; } 8% { opacity: 1; } 41% { opacity: 0.8; } 42% { opacity: 1; } 77% { opacity: 0.2; } 78% { opacity: 1; }
}
@keyframes toast-jitter {
  0% { translate: -3px 1px; } 50% { translate: 3px -1px; } 100% { translate: 0 0; }
}
@media (prefers-reduced-motion: reduce) { #toast { animation: none; } }

/* ---------- Jumpscare ---------- */
#jumpscare { position: absolute; inset: 0; z-index: 15; background: #000; overflow: hidden; }
#jumpImg {
  position: absolute; inset: 0; width: 100%; height: 100%;
  filter: grayscale(1) brightness(2.4) contrast(1.5);
  transform-origin: var(--ox) var(--oy);
  animation: js-zoom 0.22s cubic-bezier(.2,.9,.3,1) forwards, js-shake 0.06s linear 0.22s infinite;
}
@keyframes js-zoom {
  from { transform: translate(0, 0) scale(1); }
  to { transform: translate(var(--tx), var(--ty)) scale(var(--z)); }
}
@keyframes js-shake {
  0% { transform: translate(calc(var(--tx) + 14px), calc(var(--ty) - 10px)) scale(var(--z)) rotate(1.5deg); }
  50% { transform: translate(calc(var(--tx) - 16px), calc(var(--ty) + 12px)) scale(calc(var(--z) * 1.04)) rotate(-1.5deg); }
  100% { transform: translate(calc(var(--tx) + 8px), calc(var(--ty) + 6px)) scale(var(--z)) rotate(0.5deg); }
}
#flash { position: absolute; inset: 0; z-index: 30; pointer-events: none; background: #b00000; opacity: 0; mix-blend-mode: screen; }
#flash.go { animation: js-flash 1.6s steps(1) forwards; }
@keyframes js-flash {
  0% { opacity: 0.9; } 8% { opacity: 0; } 16% { opacity: 0.7; } 24% { opacity: 0; } 40% { opacity: 0.5; } 48% { opacity: 0; } 100% { opacity: 0; }
}

/* ---------- Overlays (Thai text) ---------- */
.overlay { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,0.94); display: flex; align-items: center; justify-content: center; overflow-y: auto; }
.intro { max-width: 1100px; width: 90%; padding: 4vh 0; text-align: center; font-family: var(--thai); }
.intro h1 { font-size: clamp(40px, 5.5vw, 84px); font-weight: 400; letter-spacing: 10px; color: #a9a9a2; }
.intro .sub { color: #6b6b66; letter-spacing: 4px; margin: 1vh 0 4vh; font-size: clamp(13px, 1.1vw, 18px); }
.intro .story { font-size: clamp(15px, 1.35vw, 22px); line-height: 1.9; color: #c8c8c0; text-align: left; margin-bottom: 3.5vh; }
.rules { text-align: left; margin: 0 auto 4.5vh; max-width: 900px; padding-left: 1.6em; font-size: clamp(14px, 1.2vw, 20px); line-height: 2.05; color: #bdbdb5; }
.rules b { color: #fff; }
.btn {
  font-family: var(--thai); font-size: clamp(20px, 1.8vw, 30px); font-weight: 700; padding: 14px 64px; cursor: pointer;
  background: #ececea; color: #111; border: none; border-radius: 8px; box-shadow: 0 0 24px rgba(255,255,255,0.12);
}
.btn:hover { background: #fff; }
.btn:disabled { opacity: 0.5; cursor: wait; }
.hint { margin-top: 2.5vh; font-size: clamp(12px, 0.95vw, 15px); color: #66665f; }
.hint b { color: #9a9a92; }
#endTitle.lose { color: var(--red); text-shadow: 0 0 22px rgba(255,48,48,0.5); }
#endStats { margin: 0 auto 4vh; line-height: 2; font-size: clamp(15px, 1.3vw, 21px); color: #c8c8c0; }
#endStats b { color: #fff; }
.card.small { padding: 30px 50px; text-align: center; font-family: var(--thai); background: rgba(10,10,10,0.9); border: 1px solid #333; border-radius: 8px; }
.card.small h2 { font-weight: 400; letter-spacing: 6px; margin-bottom: 10px; }
body.scared .arrow, body.scared #btnMute { display: none; }

/* ---------- Camera overview (js/overview.js) ---------- */
#btnOverview { right: calc(1.5vw + 54px); }
#camOverview { position: absolute; inset: 0; z-index: 25; background: rgba(0,0,0,0.7); display: flex; align-items: center; justify-content: center; }
.overview-box { width: min(90vw, 1100px); font-family: var(--thai), var(--font); }
.overview-title { text-align: center; color: var(--dim); letter-spacing: 3px; margin-bottom: 2vh; font-size: clamp(13px, 1.1vw, 18px); }
.overview-title b { color: #fff; }
#camGrid {
  display: grid; grid-template-columns: repeat(12, 1fr); grid-template-rows: repeat(4, 1fr); gap: 0.5vw;
  height: min(72vh, 52vw); padding: 1vw; border-radius: 6px;
  background: radial-gradient(ellipse at center, #16302e 0%, #0b1716 70%, #050909 100%);
  box-shadow: 0 30px 60px rgba(0,0,0,0.8);
}

/* TV casing */
.tv {
  --case: #2a2a2a; --trim: rgba(255,255,255,0.18);
  position: relative; display: flex; gap: 6%; padding: 5%; cursor: pointer; min-width: 0; min-height: 0;
  font-family: inherit; color: #fff; border: none; border-radius: 10px;
  background: linear-gradient(160deg, color-mix(in srgb, var(--case) 80%, #fff) 0%, var(--case) 35%, color-mix(in srgb, var(--case) 70%, #000) 100%);
  box-shadow: inset 0 2px 0 var(--trim), inset 0 -3px 6px rgba(0,0,0,0.45), 0 6px 14px rgba(0,0,0,0.6);
  transition: transform 0.12s, filter 0.12s;
}
.tv:hover { transform: scale(1.03); z-index: 2; filter: brightness(1.15); }
.ctrl-bottom { flex-direction: column; }
.tv-silver { --case: #a7a59c; }
.tv-yellow { --case: #e3b93c; }
.tv-red    { --case: #d8413f; }
.tv-white  { --case: #d9d6cc; }
.tv-black  { --case: #222; }
.tv-cream  { --case: #e6dcc0; }
.tv-orange { --case: #e2832d; }
.tv-wood {
  --case: #6b3f22;
  background: repeating-linear-gradient(95deg, #6b3f22 0 6px, #74472a 6px 9px, #5e361c 9px 14px);
}

/* CRT screen with live static */
.tv-screen {
  position: relative; flex: 1; min-width: 0; min-height: 0; overflow: hidden;
  border-radius: 14% / 18%; border: 3px solid #111;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.3em;
  background: var(--noise) 0 0 / 160px 90px, #333;
  box-shadow: inset 0 0 18px 6px rgba(0,0,0,0.85);
  animation: tv-static 0.35s steps(4) infinite;
  text-shadow: 0 0 4px #000, 1px 1px 0 #000;
}
.tv-screen::before { /* dims the static + glass glare */
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(ellipse at 35% 25%, rgba(255,255,255,0.18), transparent 45%), rgba(10,14,14,0.3);
}
.tv-screen > * { position: relative; }
.tv-screen > .tv-pic { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; filter: grayscale(1) contrast(1.08) brightness(0.8); opacity: 0.85; }
.tv-pic:not([src]) { display: none; }
.tv-screen > .tv-pic ~ * { z-index: 1; }
.tv-screen::before { z-index: 1; }

/* anomaly just appeared on this cam: flash red, then keep a red glow */
.tv.alert .tv-screen { border-color: var(--red); box-shadow: inset 0 0 18px 6px rgba(0,0,0,0.85), 0 0 18px rgba(255,48,48,0.7); }
.tv.alert .tv-screen::after {
  content: ''; position: absolute; inset: 0; z-index: 2; pointer-events: none; background: rgba(255,30,30,0.55);
  animation: tv-alert 0.4s steps(1) 8 forwards;
}
@keyframes tv-alert { 0% { opacity: 1; } 50% { opacity: 0; } 100% { opacity: 0; } }
@keyframes tv-static { 0% { background-position: 0 0; } 25% { background-position: -37px 21px; } 50% { background-position: 53px -44px; } 75% { background-position: -71px -13px; } 100% { background-position: 19px 61px; } }
.tv.on .tv-screen { border-color: var(--accent); box-shadow: inset 0 0 18px 6px rgba(0,0,0,0.85), 0 0 14px rgba(109,255,176,0.5); }
.tv.on .tile-label::after { content: ' ●'; color: var(--red); }
.tile-key { position: absolute; top: 8%; left: 9%; font-size: clamp(10px, 0.8vw, 14px); color: #9a9a92; }
.tile-label { font-family: var(--font); font-size: clamp(12px, 1.3vw, 22px); letter-spacing: 2px; }
.tile-name { font-size: clamp(10px, 0.95vw, 16px); color: #d0d0c8; text-align: center; }

/* controls: knobs, speaker grille, tape deck */
.tv-ctrl { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8%; flex: 0 0 18%; }
.ctrl-bottom .tv-ctrl { flex: 0 0 18%; flex-direction: row; gap: 4%; }
.ctrl-deck .tv-ctrl { flex: 0 0 24%; }
.knob {
  width: clamp(8px, 1.1vw, 18px); aspect-ratio: 1; border-radius: 50%; flex: none;
  background: radial-gradient(circle at 35% 35%, #eee, #777 55%, #333); box-shadow: 0 1px 2px rgba(0,0,0,0.6);
}
.grille {
  flex: 1; width: 100%; min-height: 6px; border-radius: 3px;
  background: repeating-linear-gradient(to bottom, rgba(0,0,0,0.55) 0 2px, transparent 2px 4px);
}
.ctrl-bottom .grille { height: 100%; background: repeating-linear-gradient(to right, rgba(0,0,0,0.5) 0 2px, transparent 2px 4px); }
.deck { width: 100%; height: 30%; border-radius: 3px; background: #111; border: 2px solid #555; box-shadow: inset 0 0 0 4px #222; }
body.scared #btnOverview { display: none; }

/* ---------- Title menu ---------- */
.title-screen { background: #000; overflow: hidden; }
.title-bg {
  position: absolute; inset: -4%; pointer-events: none;
  background: url('../assets/cam02/01.png') center / cover no-repeat;
  filter: grayscale(1) brightness(0.45) contrast(1.2) blur(1px);
  animation: bg-drift 40s ease-in-out infinite alternate, bg-flicker 7s steps(1) infinite;
}
@keyframes bg-drift { from { transform: scale(1) translate(0, 0); } to { transform: scale(1.06) translate(-1.5%, 1%); } }
@keyframes bg-flicker { 0%, 100% { opacity: 1; } 31% { opacity: 0.55; } 32% { opacity: 1; } 33% { opacity: 0.7; } 34% { opacity: 1; } 88% { opacity: 0.4; } 89% { opacity: 1; } }
.title-noise {
  position: absolute; inset: 0; pointer-events: none; opacity: 0.5;
  background: repeating-linear-gradient(to bottom, rgba(0,0,0,0) 0 2px, rgba(0,0,0,0.3) 3px);
}
.title-vignette { position: absolute; inset: 0; pointer-events: none; background: radial-gradient(ellipse at 50% 45%, rgba(0,0,0,0.15) 25%, rgba(0,0,0,0.9) 90%); }

.title-main { position: relative; z-index: 1; display: flex; flex-direction: column; align-items: center; font-family: var(--thai); }
.title-logo {
  font-family: var(--thai);
  position: relative; font-size: clamp(64px, 9vw, 150px); font-weight: 800; letter-spacing: 0.08em; line-height: 1.1;
  color: #d9d6cc; filter: url(#grunge); text-shadow: 0 0 30px rgba(0,0,0,0.9), 0 6px 0 rgba(0,0,0,0.6);
}
.title-logo::before, .title-logo::after { content: attr(data-text); position: absolute; inset: 0; opacity: 0; }
.title-logo::before { color: #c00; animation: glitch-a 5s steps(1) infinite; }
.title-logo::after { color: #8fd; animation: glitch-b 5s steps(1) infinite; mix-blend-mode: screen; }
@keyframes glitch-a { 0%, 100% { opacity: 0; } 62% { opacity: 0.8; transform: translate(-6px, 2px); clip-path: inset(10% 0 55% 0); } 64% { opacity: 0.8; transform: translate(5px, -2px); clip-path: inset(60% 0 8% 0); } 66% { opacity: 0; } }
@keyframes glitch-b { 0%, 100% { opacity: 0; } 62% { opacity: 0.35; transform: translate(5px, 0); clip-path: inset(40% 0 30% 0); } 65% { opacity: 0; } }
.title-tag { margin: 0.6vh 0 6vh; color: #6e6c66; letter-spacing: 0.6em; font-family: var(--font); font-size: clamp(11px, 0.9vw, 15px); }

.menu { display: flex; flex-direction: column; align-items: center; gap: 1.1vh; }
.menu-item {
  position: relative; background: none; border: none; cursor: pointer; padding: 0.15em 1.2em;
  font-family: var(--thai); font-size: clamp(20px, 1.9vw, 32px); font-weight: 700; letter-spacing: 0.12em;
  color: #b9b6ad; text-shadow: 0 2px 8px #000; transition: color 0.15s, letter-spacing 0.25s, text-shadow 0.15s;
}
.menu-item::before, .menu-item::after { position: absolute; top: 50%; translate: 0 -50%; opacity: 0; color: #c22; transition: opacity 0.15s; }
.menu-item::before { content: '›'; left: 0; }
.menu-item::after { content: '‹'; right: 0; }
.menu-item:hover, .menu-item:focus-visible { outline: none; color: #fff; letter-spacing: 0.2em; text-shadow: -2px 0 rgba(200,0,0,0.7), 0 0 14px rgba(255,255,255,0.25); }
.menu-item:hover::before, .menu-item:hover::after, .menu-item:focus-visible::before, .menu-item:focus-visible::after { opacity: 1; }
.menu-item:disabled { color: #55534e; cursor: wait; letter-spacing: 0.12em; text-shadow: none; }
.menu-item:disabled::before, .menu-item:disabled::after { opacity: 0; }
.title-main .hint { margin-top: 7vh; letter-spacing: 0.15em; }

.menu-panel { position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center; overflow-y: auto; background: rgba(0,0,0,0.72); }
.panel-head { font-weight: 800; letter-spacing: 0.3em; font-size: clamp(28px, 3vw, 48px); color: #d9d6cc; margin-bottom: 3vh; filter: url(#grunge); }
.menu-item.back { margin-top: 3vh; font-size: clamp(16px, 1.4vw, 24px); }
.credits { font-size: clamp(15px, 1.35vw, 22px); line-height: 2.1; color: #c8c8c0; }
.credits b { color: #fff; }
.credits .dim { color: #7a2a2a; font-style: italic; }
@media (prefers-reduced-motion: reduce) { .title-bg, .title-logo::before, .title-logo::after { animation: none; } }

/* ---------- Pause menu (same look as the title) ---------- */
.pause-screen { background: rgba(0,0,0,0.55); backdrop-filter: grayscale(1) blur(4px) brightness(0.55); }
.title-logo.small { font-size: clamp(44px, 5.5vw, 96px); letter-spacing: 0.04em; }
#pauseTag { letter-spacing: 0.25em; font-family: var(--thai), var(--font); }
