:root {
  --bg: #0b0a0f;
  --panel: #15121c;
  --panel-2: #1d1826;
  --ink: #e9e1d3;
  --muted: #9a8fa8;
  --blood: #b3122e;
  --blood-hot: #e0213f;
  --candle: #f2b45c;
  --violet: #7a5cff;
  --line: #2c2537;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(ellipse at top, #1c1426 0%, var(--bg) 60%) fixed;
  color: var(--ink);
  font-family: "Cormorant Garamond", Georgia, serif;
  font-size: 19px;
  overflow-x: hidden;
}

#rain { position: fixed; inset: 0; pointer-events: none; z-index: 0; opacity: .35; }
#lightning { position: fixed; inset: 0; background: #dfe6ff; opacity: 0; pointer-events: none; z-index: 50; }
#lightning.flash { animation: flash .9s ease-out; }
@keyframes flash { 0% {opacity:0} 8% {opacity:.55} 14% {opacity:.05} 22% {opacity:.35} 100% {opacity:0} }

.screen { display: none; position: relative; z-index: 1; }
.screen.active { display: block; }
.hidden { display: none !important; }
.muted { color: var(--muted); }

/* Intro */
#intro { min-height: 100vh; display: none; place-items: center; text-align: center; padding: 2rem; }
#intro.active { display: grid; }
.intro-inner { max-width: 720px; }
.eyebrow { letter-spacing: .3em; text-transform: uppercase; color: var(--candle); font-size: .85rem; }
h1 {
  font-family: "Creepster", cursive; font-weight: 400;
  font-size: clamp(3.5rem, 10vw, 7rem); line-height: .95; margin: .2em 0 .4em;
  color: var(--blood-hot); text-shadow: 0 0 30px rgba(224,33,63,.45), 0 4px 0 #400;
}
.setting { font-size: 1.25rem; line-height: 1.55; font-style: italic; }
.setting.small { font-size: 1rem; }
.powered { margin-top: 2rem; color: var(--muted); font-size: .95rem; }
.powered strong { color: var(--violet); }
.how-to { text-align: left; display: table; margin: 1.2rem auto 1.6rem; padding-left: 1.4rem; line-height: 1.7; }
.how-to b { color: var(--candle); }
.fine-print { margin-top: 1rem; color: var(--muted); font-size: .8rem; }
.fine-print a { color: var(--violet); }

/* Buttons */
.btn {
  font: 600 1rem "IBM Plex Mono", monospace; border-radius: 6px; cursor: pointer;
  padding: .7em 1.2em; border: 1px solid transparent; transition: .15s;
}
.btn-blood { background: var(--blood); color: #fff; box-shadow: 0 0 18px rgba(179,18,46,.4); }
.btn-blood:hover:not(:disabled) { background: var(--blood-hot); transform: translateY(-1px); }
.btn-blood:disabled { opacity: .45; cursor: not-allowed; }
.btn-ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn-ghost:hover { border-color: var(--violet); }
#enter { font-size: 1.2rem; padding: .9em 2em; margin-top: 1rem; }

/* Game layout */
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: .8rem 1.5rem; border-bottom: 1px solid var(--line); background: rgba(11,10,15,.85);
  position: sticky; top: 0; z-index: 10; backdrop-filter: blur(6px);
}
.topbar h2 { font-family: "Creepster", cursive; font-weight: 400; color: var(--blood-hot); margin: 0; font-size: 2rem; }
.topbar-actions { display: flex; gap: .6rem; }
#log-count { background: var(--violet); color: #fff; border-radius: 99px; padding: 0 .5em; margin-left: .3em; }

.layout { display: grid; grid-template-columns: 340px 1fr; gap: 1.5rem; padding: 1.5rem; max-width: 1400px; margin: 0 auto; }
@media (max-width: 900px) { .layout { grid-template-columns: 1fr; } }

.casefile { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 1rem; align-self: start; }
.casefile h3 { color: var(--candle); margin: 1rem 0 .3rem; font-size: 1.1rem; letter-spacing: .08em; text-transform: uppercase; }
#notebook {
  width: 100%; min-height: 180px; background: #f3ead6; color: #2a1f14; border: none; border-radius: 4px;
  padding: .7rem; font: italic 1.05rem/1.5 "Cormorant Garamond", serif;
  background-image: repeating-linear-gradient(transparent 0 1.5rem, #d8c9a8 1.5rem calc(1.5rem + 1px));
}

.scene-frame, .portrait { position: relative; aspect-ratio: 1; background: var(--panel-2); border-radius: 8px; overflow: hidden; }
.scene-frame img, .portrait img { width: 100%; height: 100%; object-fit: cover; display: block; opacity: 0; transition: opacity 1.2s; }
.scene-frame img.loaded, .portrait img.loaded { opacity: 1; }
.img-loading {
  position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 1rem;
  color: var(--muted); font: .8rem "IBM Plex Mono", monospace; animation: pulse 1.6s infinite;
}
.loaded + .img-loading { display: none; }
@keyframes pulse { 50% { opacity: .35; } }

/* Suspects */
.suspects { display: grid; grid-template-columns: repeat(6, 1fr); gap: 1rem; }
@media (max-width: 1100px) { .suspects { grid-template-columns: repeat(3, 1fr); } }
.suspect {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: .6rem;
  cursor: pointer; transition: .2s; text-align: center;
}
.suspect:hover { border-color: var(--candle); transform: translateY(-3px); box-shadow: 0 8px 24px rgba(242,180,92,.12); }
.suspect.active { border-color: var(--blood-hot); box-shadow: 0 0 22px rgba(224,33,63,.35); }
.suspect h4 { margin: .5rem 0 0; font-size: 1.05rem; }
.suspect .title { color: var(--candle); font-size: .8rem; font-family: "IBM Plex Mono", monospace; text-transform: uppercase; letter-spacing: .1em; }
.suspect .qcount { font: .7rem "IBM Plex Mono", monospace; color: var(--muted); }

.pick-hint { text-align: center; color: var(--muted); font-style: italic; margin-top: 2rem; }

/* Interrogation */
.interrogation { margin-top: 1.5rem; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 1rem; }
.int-head { display: flex; gap: 1rem; align-items: center; border-bottom: 1px solid var(--line); padding-bottom: .8rem; }
.int-head img { width: 72px; height: 72px; border-radius: 50%; object-fit: cover; border: 2px solid var(--blood); background: var(--panel-2); }
.int-head h3 { margin: 0; font-size: 1.5rem; }
.int-head p { margin: .2rem 0 0; font-size: .95rem; }

.chat { max-height: 420px; overflow-y: auto; padding: 1rem .2rem; display: flex; flex-direction: column; gap: .8rem; }
.msg { max-width: 80%; padding: .6rem .9rem; border-radius: 10px; line-height: 1.45; }
.msg.user { align-self: flex-end; background: #2a1d33; border: 1px solid #3d2b4a; font-family: "IBM Plex Mono", monospace; font-size: .9rem; }
.msg.assistant { align-self: flex-start; background: var(--panel-2); border-left: 3px solid var(--blood); }
.msg.assistant em { color: var(--candle); }
.msg .meta { display: block; margin-top: .35rem; font: .68rem "IBM Plex Mono", monospace; color: var(--violet); }
.msg.thinking { color: var(--muted); font-style: italic; animation: pulse 1.4s infinite; }
.msg.error { border-left-color: #f80; color: #fbb; font-family: "IBM Plex Mono", monospace; font-size: .85rem; }

.chips { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: .6rem; }
.chip {
  font: .78rem "IBM Plex Mono", monospace; background: transparent; color: var(--muted);
  border: 1px dashed var(--line); border-radius: 99px; padding: .3em .8em; cursor: pointer;
}
.chip:hover { color: var(--ink); border-color: var(--candle); }

.ask { display: flex; gap: .5rem; }
.ask input {
  flex: 1; background: #0e0c13; color: var(--ink); border: 1px solid var(--line); border-radius: 6px;
  padding: .7rem; font: 1rem "IBM Plex Mono", monospace;
}
.ask input:focus { outline: none; border-color: var(--violet); }

/* Inference log */
.log {
  position: fixed; right: 0; top: 0; bottom: 0; width: 380px; z-index: 20; background: #0d0b12;
  border-left: 1px solid var(--violet); padding: 1rem; overflow-y: auto; font-family: "IBM Plex Mono", monospace; font-size: .8rem;
  box-shadow: -10px 0 40px rgba(122,92,255,.15);
}
.log-head { display: flex; justify-content: space-between; align-items: center; }
.log-head h3 { margin: 0; color: var(--violet); font-size: 1rem; }
.log-totals { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; margin: 1rem 0; }
.log-totals div { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: .5rem; }
.log-totals b { display: block; font-size: 1.2rem; color: var(--ink); }
.log-totals span { color: var(--muted); font-size: .7rem; text-transform: uppercase; }
#log-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column-reverse; gap: .5rem; }
#log-list li { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: .5rem; }
#log-list .ep { color: var(--candle); }
#log-list .what { color: var(--ink); }
#log-list .nums { color: var(--muted); margin-top: .2rem; }

/* Modals */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.78); display: grid; place-items: center; z-index: 30; padding: 1rem; }
.modal-card { background: var(--panel); border: 1px solid var(--blood); border-radius: 12px; padding: 1.5rem; max-width: 720px; width: 100%; box-shadow: 0 0 60px rgba(179,18,46,.35); }
.modal-card h2 { font-family: "Creepster", cursive; font-weight: 400; color: var(--blood-hot); font-size: 2.6rem; margin: 0 0 .3rem; }
.accuse-choices { display: grid; grid-template-columns: repeat(5, 1fr); gap: .6rem; margin: 1rem 0; }
.accuse-choices button {
  background: var(--panel-2); border: 2px solid var(--line); border-radius: 8px; padding: .4rem; color: var(--ink);
  cursor: pointer; font: .85rem "Cormorant Garamond", serif;
}
.accuse-choices button img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 4px; display: block; margin-bottom: .3rem; background: #000; }
.accuse-choices button.selected { border-color: var(--blood-hot); box-shadow: 0 0 16px rgba(224,33,63,.5); }
#reasoning { width: 100%; min-height: 110px; background: #0e0c13; color: var(--ink); border: 1px solid var(--line); border-radius: 6px; padding: .7rem; font: 1rem "Cormorant Garamond", serif; }
.modal-actions { display: flex; justify-content: flex-end; gap: .6rem; margin-top: 1rem; }
.reveal-story { font-size: 1.2rem; line-height: 1.65; white-space: pre-wrap; max-height: 60vh; overflow-y: auto; }
.reveal-story .meta { display: block; margin-top: 1rem; font: .75rem "IBM Plex Mono", monospace; color: var(--violet); }
.hold-tight { text-align: center; padding: 1.5rem 0; white-space: normal; }
.hold-tight p { margin: .5rem 0; }
.hold-title { font-size: 1.5rem; color: var(--candle); animation: pulse 1.6s infinite; }
.hold-clock { font: .8rem "IBM Plex Mono", monospace; color: var(--violet); }
.reveal-card.win { border-color: var(--candle); box-shadow: 0 0 60px rgba(242,180,92,.35); }
.reveal-card.win h2 { color: var(--candle); }

/* The Crypt: the Coroner on your own Serverless endpoint */
.suspect.crypt { border-color: var(--violet); background: linear-gradient(180deg, #1a1530, var(--panel)); }
.suspect.crypt .title { color: var(--violet); }
.crypt-status { font: .68rem/1.3 "IBM Plex Mono", monospace; color: var(--ink); margin-top: .3rem; min-height: 2.6em; }
.int-head .bell { margin-left: auto; white-space: nowrap; }
.int-head .bell:disabled { opacity: .5; cursor: wait; }
#log-list .nums b { color: var(--violet); }
