@font-face {
  font-family: 'HandFallback';
  src: local('Segoe Print'), local('Bradley Hand'), local('Comic Sans MS');
}

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

html, body {
  width: 100%; height: 100%;
  background: #000;
  color: #ddd;
  font-family: Georgia, 'Times New Roman', serif;
  overflow: hidden;
  -webkit-user-select: none; user-select: none;
  touch-action: none;
}

#game-canvas {
  position: fixed; top: 0; left: 0;
  width: 100%; height: 100%;
  display: block;
  outline: none;
}

.screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  z-index: 50;
  background: rgba(5,5,6,0.98);
}
.hidden { display: none !important; }

/* Title */
#title-screen { background: #050505; flex-direction: column; }
.title-wrap { text-align: center; }
.game-title {
  font-size: 3.2rem;
  letter-spacing: 0.35em;
  font-weight: 300;
  color: #b9b3a5;
  text-shadow: 0 0 25px rgba(255,220,150,0.08);
  margin-bottom: 3rem;
  animation: titleFlicker 6s infinite;
}
@keyframes titleFlicker {
  0%, 94%, 100% { opacity: 1; }
  95% { opacity: 0.75; }
  96% { opacity: 0.95; }
  97% { opacity: 0.6; }
  98% { opacity: 1; }
}
.title-menu { display: flex; flex-direction: column; gap: 0.9rem; align-items: center; }
.menu-btn {
  background: transparent;
  border: 1px solid rgba(180,170,150,0.35);
  color: #cfc8b8;
  font-family: Georgia, serif;
  font-size: 1rem;
  letter-spacing: 0.15em;
  padding: 0.7rem 2.2rem;
  cursor: pointer;
  transition: all 0.25s ease;
  min-width: 220px;
}
.menu-btn:hover { background: rgba(180,170,150,0.08); border-color: rgba(220,210,190,0.7); color: #fff; }
.menu-btn.small { min-width: auto; padding: 0.4rem 1rem; font-size: 0.85rem; }
.menu-btn:disabled { opacity: 0.3; cursor: default; }

.thank-you {
  margin-top: 3rem;
  font-size: 1.3rem;
  letter-spacing: 0.2em;
  color: #a89d86;
  opacity: 0;
  animation: thankFade 4s ease forwards;
}
@keyframes thankFade { to { opacity: 1; } }

/* Panels */
.panel {
  background: rgba(15,14,13,0.9);
  border: 1px solid rgba(150,140,120,0.25);
  padding: 2.2rem 2.6rem;
  min-width: 320px;
  display: flex; flex-direction: column; gap: 1.3rem;
}
.panel h2 {
  font-weight: 300; letter-spacing: 0.2em; color: #cfc8b8;
  text-align: center; margin-bottom: 0.5rem;
}
.panel label { display: flex; flex-direction: column; gap: 0.4rem; font-size: 0.9rem; color: #b7b0a0; letter-spacing: 0.05em; }
.panel label.row { flex-direction: row; align-items: center; justify-content: space-between; }
.panel input[type="range"] { width: 100%; accent-color: #8a7f68; }
.panel select {
  background: #161513; color: #cfc8b8; border: 1px solid rgba(150,140,120,0.3);
  padding: 0.4rem; font-family: Georgia, serif;
}

/* Loading */
#loading-screen { background: #000; }
.loading-text { color: #7a7264; letter-spacing: 0.2em; font-size: 0.95rem; animation: pulse 2s infinite; }
@keyframes pulse { 0%,100%{opacity:0.4;} 50%{opacity:1;} }

/* HUD */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 20; }
#crosshair {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%);
  width: 6px; height: 6px; border-radius: 50%;
  background: rgba(255,255,255,0.5);
}
#interact-prompt {
  position: absolute; top: 58%; left: 50%; transform: translate(-50%,0);
  background: rgba(0,0,0,0.55);
  border: 1px solid rgba(255,255,255,0.2);
  padding: 0.4rem 0.9rem;
  font-size: 0.85rem;
  letter-spacing: 0.08em;
  color: #eee;
}
#hud-topright {
  position: absolute; top: 14px; right: 14px;
  display: flex; gap: 8px; pointer-events: all;
}
.icon-btn {
  background: rgba(0,0,0,0.4);
  border: 1px solid rgba(255,255,255,0.15);
  color: #ddd; width: 38px; height: 38px;
  border-radius: 50%;
  cursor: pointer; font-size: 1rem;
}
.icon-btn:hover { background: rgba(0,0,0,0.65); }

/* Mobile controls */
#mobile-controls { position: fixed; inset: 0; z-index: 25; pointer-events: none; }
#joystick-zone {
  position: absolute; bottom: 30px; left: 30px;
  width: 130px; height: 130px; pointer-events: all;
}
#joystick-base {
  width: 100%; height: 100%; border-radius: 50%;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.2);
  position: relative;
}
#joystick-knob {
  width: 54px; height: 54px; border-radius: 50%;
  background: rgba(255,255,255,0.25);
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%,-50%);
}
#touch-look-zone {
  position: absolute; top: 0; right: 0; width: 60%; height: 100%;
  pointer-events: all;
}
.mobile-btn {
  position: absolute; bottom: 55px; right: 40px;
  width: 76px; height: 76px; border-radius: 50%;
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.3);
  color: #eee; font-size: 0.8rem; letter-spacing: 0.05em;
  pointer-events: all; z-index: 26;
}

/* Notebook */
#notebook-screen { background: rgba(0,0,0,0.92); z-index: 60; }
#notebook-container {
  position: relative;
  width: min(92vw, 980px); height: min(78vh, 620px);
  display: flex; gap: 4px;
}
.notebook-page {
  flex: 1;
  background: #ece4d0 url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100"><filter id="n"><feTurbulence baseFrequency="0.9" numOctaves="2" result="noise"/><feColorMatrix in="noise" type="saturate" values="0"/></filter><rect width="100" height="100" filter="url(%23n)" opacity="0.03"/></svg>');
  color: #2b2620;
  padding: 2.4rem 2.2rem;
  font-family: 'HandFallback', Georgia, cursive;
  font-size: 1.05rem;
  line-height: 1.7;
  overflow-y: auto;
  box-shadow: inset 0 0 40px rgba(0,0,0,0.15);
  position: relative;
  white-space: pre-wrap;
}
.notebook-page::-webkit-scrollbar { width: 6px; }
.notebook-page::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.2); }
.page-date { font-size: 0.8rem; color: #6b6252; margin-bottom: 0.8rem; letter-spacing: 0.05em; }
.page-drawing { font-size: 2.5rem; text-align: center; margin: 0.5rem 0; opacity: 0.65; filter: grayscale(0.4); }
.clue-word {
  cursor: pointer; border-bottom: 1px dotted #8a6a4a;
  color: #5a3d24;
}
.clue-word:hover { background: rgba(150,100,50,0.15); }
.hidden-text {
  opacity: 0.06; transition: opacity 0.4s ease; cursor: pointer;
}
.hidden-text.revealed { opacity: 1; color: #7a1f1f; }
.notebook-close-btn { position: absolute; top: -46px; right: 0; }
.page-nav {
  position: absolute; top: 50%; transform: translateY(-50%);
  background: rgba(0,0,0,0.4); border: 1px solid rgba(255,255,255,0.2);
  color: #eee; width: 42px; height: 42px; border-radius: 50%; font-size: 1.3rem; cursor: pointer;
}
.page-nav.left { left: -20px; }
.page-nav.right { right: -20px; }
.page-nav:disabled { opacity: 0.2; cursor: default; }
#page-indicator {
  position: absolute; bottom: -34px; left: 50%; transform: translateX(-50%);
  font-size: 0.8rem; color: #8a8272; letter-spacing: 0.1em;
}

/* Toast */
#toast {
  position: fixed; bottom: 60px; left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,0.7); border: 1px solid rgba(255,255,255,0.15);
  padding: 0.6rem 1.2rem; font-size: 0.85rem; color: #eee;
  z-index: 40; letter-spacing: 0.05em;
  animation: toastFade 3.2s ease forwards;
}
@keyframes toastFade {
  0% { opacity: 0; transform: translate(-50%, 10px); }
  10% { opacity: 1; transform: translate(-50%, 0); }
  85% { opacity: 1; }
  100% { opacity: 0; }
}

/* Ending */
#ending-screen {
  background: #000; z-index: 90;
}
#ending-text {
  font-size: 1.6rem; letter-spacing: 0.08em; color: #cfc8b8;
  text-align: center; max-width: 700px; line-height: 2.4;
  opacity: 0;
}

/* Fade overlay */
#fade-overlay {
  position: fixed; inset: 0; background: #000;
  opacity: 0; pointer-events: none; z-index: 100;
  transition: opacity 1.5s ease;
}
#fade-overlay.active { opacity: 1; pointer-events: all; }

/* Vignette — permanent soft darkening at screen edges, sells the "small room" feeling */
#vignette {
  position: fixed; inset: 0; z-index: 15;
  pointer-events: none;
  background: radial-gradient(ellipse at center, rgba(0,0,0,0) 45%, rgba(0,0,0,0.55) 100%);
}

/* Film grain — subtle animated noise, very low opacity so it never feels like a web-app filter */
#grain {
  position: fixed; inset: -50%; width: 200%; height: 200%; z-index: 16;
  pointer-events: none;
  opacity: 0.035;
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="180" height="180"><filter id="g"><feTurbulence type="fractalNoise" baseFrequency="0.85" numOctaves="2" stitchTiles="stitch"/></filter><rect width="180" height="180" filter="url(%23g)"/></svg>');
  animation: grainShift 0.6s steps(4) infinite;
  mix-blend-mode: overlay;
}
@keyframes grainShift {
  0%   { transform: translate(0,0); }
  25%  { transform: translate(-2%,-1%); }
  50%  { transform: translate(1%,2%); }
  75%  { transform: translate(-1%,1%); }
  100% { transform: translate(0,0); }
}
@media (max-width: 720px) {
  #grain { opacity: 0.02; } /* cheaper-looking, kinder to mobile GPUs/battery */
}

@media (max-width: 720px) {
  .game-title { font-size: 2rem; letter-spacing: 0.2em; }
  .menu-btn { min-width: 180px; font-size: 0.9rem; }
  #notebook-container { flex-direction: column; height: 82vh; }
  .notebook-page { font-size: 0.9rem; padding: 1.4rem; }
  .page-nav.left { left: 4px; }
  .page-nav.right { right: 4px; }
}
