:root {
  /* Halloween night: deep purple sky, pumpkin orange, slime green */
  --night: #120b1d;
  --night-raised: rgba(31, 20, 48, 0.94);
  --line: #3d2b58;
  --bulb: #ff7b1c;
  --blood: #d4382c;
  --bone: #f4ead6;
  --fog: #a99bc2;
  --good: #9be15d;
  --spooky: 'Creepster', 'Fraunces', Georgia, cursive;
  --display: 'Fraunces', Georgia, 'Times New Roman', serif;
  --body: 'Atkinson Hyperlegible', 'Segoe UI', system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
html { background: var(--night); }
body {
  background:
    radial-gradient(60% 50% at 82% 8%, rgba(255, 196, 120, 0.12) 0%, transparent 60%),
    radial-gradient(120% 80% at 50% -10%, #2a1747 0%, transparent 65%),
    linear-gradient(#150c24, #0c0714 70%);
  background-attachment: fixed;
  color: var(--bone);
  font-family: var(--body);
  font-size: 18px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { font-family: var(--display); font-weight: 700; line-height: 1.1; margin: 0; }
p { margin: 0; }
[hidden] { display: none !important; }

.wordmark {
  font-family: var(--spooky);
  font-weight: 400;
  color: var(--bulb);
  letter-spacing: 0.03em;
  text-shadow: 0 0 18px rgba(255, 123, 28, 0.45), 0 2px 0 #3a1500;
}

.muted { color: var(--fog); }

button {
  font: inherit;
  font-weight: 700;
  border: 0;
  border-radius: 10px;
  padding: 0.8em 1.4em;
  cursor: pointer;
  background: var(--bulb);
  color: #1f0c00;
  transition: transform 0.08s ease, filter 0.15s ease;
}
button:hover { filter: brightness(1.08); }
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.35; cursor: not-allowed; filter: none; }
button.quiet { background: transparent; color: var(--fog); border: 1px solid var(--line); }
button.quiet:hover { color: var(--bone); border-color: var(--fog); }
button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 3px solid var(--bone);
  outline-offset: 2px;
}

input, select {
  font: inherit;
  color: var(--bone);
  background: var(--night);
  border: 2px solid var(--line);
  border-radius: 10px;
  padding: 0.7em 0.9em;
  width: 100%;
}
input::placeholder { color: #7f6f9c; }
input:focus { border-color: var(--bulb); outline: none; }
label { display: block; font-size: 0.85rem; color: var(--fog); margin-bottom: 0.35rem; }

/* Focus scale: one chip per sharpening phase, labeled with what it's worth */
.focus-scale { display: flex; gap: 6px; }
.focus-scale span {
  flex: 1;
  text-align: center;
  padding: 0.35em 0;
  border-radius: 8px;
  border: 1px solid var(--line);
  color: #7f6f9c;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-size: 0.9rem;
}
.focus-scale span.past { color: #5b4b78; text-decoration: line-through; border-color: transparent; }
.focus-scale span.now { background: var(--bulb); border-color: var(--bulb); color: #1f0c00; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* Monster screen: two stacked layers so each new stage crossfades in */
.screen {
  position: relative;
  aspect-ratio: var(--frame, 4 / 3);
  width: 100%;
  background: #07040c;
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 0 0 1px #3a1d08, 0 0 60px rgba(255, 123, 28, 0.12), 0 30px 80px rgba(0, 0, 0, 0.6);
}
.screen img.layer {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: contain;
  opacity: 0;
  transition: opacity 0.7s ease;
}
.screen img.layer.on { opacity: 1; }
.screen .caption {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 28px 28px 20px;
  background: linear-gradient(transparent, rgba(7, 4, 12, 0.92) 45%);
}
.screen .caption h2 { font-size: clamp(2rem, 4vw, 3.6rem); font-family: var(--spooky); font-weight: 400; letter-spacing: 0.03em; color: var(--bulb); text-shadow: 0 0 20px rgba(255, 123, 28, 0.4); }
.screen .caption p { color: var(--bulb); font-size: 1.1rem; margin-top: 4px; }

/* Player roster with lock-in status */
.roster-list { list-style: none; margin: 0; padding: 0; }
.roster-list li { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; padding: 9px 2px; border-bottom: 1px solid var(--line); }
.roster-list li:last-child { border-bottom: 0; }
.roster-list li.off { opacity: 0.45; }
.roster-list li.me .name { color: var(--bulb); }
.roster-list .name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.roster-list .score { font-variant-numeric: tabular-nums; font-weight: 700; text-align: right; }
.roster-list .state { grid-column: 1 / -1; font-size: 0.85rem; color: var(--fog); overflow-wrap: anywhere; }
.roster-list .state.in { color: var(--bulb); }
.roster-list .state.hit { color: var(--good); }
.roster-list .state.miss { color: #ff9b8a; }

/* Lobby building blocks */
.card { background: var(--night-raised); border: 1px solid var(--line); border-radius: 16px; padding: 26px; display: flex; flex-direction: column; gap: 16px; }
.card h3 { font-size: 1.35rem; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.eyebrow { font-size: 0.8rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--fog); font-weight: 700; }
.badge { font-size: 0.75rem; letter-spacing: 0.08em; text-transform: uppercase; font-weight: 700; color: var(--night); background: var(--fog); border-radius: 6px; padding: 3px 8px; vertical-align: middle; margin-left: 10px; }
.small { font-size: 0.85rem; }

/* Animated how-to-play demo: an original creature stepping through the four stages */
.demo { display: flex; flex-direction: column; gap: 12px; }
.demo-frame { aspect-ratio: 4 / 3; border-radius: 10px; overflow: hidden; background: #1c1230; }
.demo-frame svg { display: block; width: 100%; height: 100%; transition: filter 0.6s ease; }
.demo-label { color: var(--fog); font-size: 0.95rem; min-height: 1.4em; }

.rules { margin: 0; padding: 0; list-style: none; counter-reset: rule; display: grid; gap: 14px; }
.rules li { counter-increment: rule; display: grid; grid-template-columns: 2em 1fr; gap: 12px; align-items: baseline; }
.rules li::before { content: counter(rule); font-family: var(--display); font-weight: 900; font-size: 1.3rem; color: var(--bulb); text-align: center; }
.rules b { color: var(--bone); }

.player-grid { display: flex; flex-wrap: wrap; gap: 10px; }
.player-chip { display: inline-flex; align-items: center; gap: 10px; background: var(--night); border: 1px solid var(--line); border-radius: 999px; padding: 5px 8px 5px 5px; font-weight: 700; }
.player-chip .avatar { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: var(--bulb); color: #1f0c00; font-family: var(--display); font-size: 0.95rem; }
.player-chip.off { opacity: 0.45; }
.player-chip.me { border-color: var(--bulb); }
.player-chip button { padding: 2px 8px; border-radius: 999px; background: transparent; color: var(--fog); font-weight: 400; }
.player-chip button:hover { color: #ff9b8a; }
.player-chip .pad { width: 4px; }

/* Page frame shared by every screen */
.app { max-width: 1440px; margin: 0 auto; padding: 22px 32px 32px; min-height: 100vh; display: flex; flex-direction: column; gap: 22px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.topbar h1 { font-size: inherit; display: flex; align-items: center; }
.topbar .wordmark { font-size: 2rem; }
.topbar .meta { color: var(--fog); font-variant-numeric: tabular-nums; display: flex; gap: 22px; align-items: center; flex-wrap: wrap; }
.topbar .meta b { color: var(--bone); }
.room-code { display: inline-flex; flex-direction: column; align-items: flex-end; line-height: 1.1; }
.room-code span { font-size: 0.72rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--fog); font-weight: 700; }
.room-code b { font-family: var(--display); font-size: 1.7rem; letter-spacing: 0.12em; color: var(--bulb) !important; }
.error { color: #ff9b8a; font-size: 0.95rem; }
.big { font-family: var(--display); font-size: clamp(2rem, 4vw, 3rem); font-variation-settings: 'SOFT' 100; }
.flicker { animation: flicker 2.4s ease-in-out infinite; }
@keyframes flicker { 0%, 100% { opacity: 1; } 50% { opacity: 0.55; } }
a.button { display: inline-block; text-decoration: none; background: var(--bulb); color: #1f0c00; font-weight: 700; border-radius: 10px; padding: 0.8em 1.4em; text-align: center; }
a.button.quiet { background: transparent; color: var(--fog); border: 1px solid var(--line); }
.tag { font-size: 0.7rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--fog); border: 1px solid var(--line); border-radius: 5px; padding: 1px 5px; margin-left: 2px; font-weight: 700; }

/* Game board */
.play { display: grid; grid-template-columns: 1fr 360px; gap: 28px; flex: 1; align-items: start; }
.screen-col { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.screen-col .screen { width: min(100%, calc(68vh * var(--frame, 1.3333))); margin-inline: auto; }
.readout { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.readout .focus-scale { flex: 1; min-width: 260px; max-width: 520px; }
.stage-label { color: var(--fog); font-variant-numeric: tabular-nums; }
.side { display: flex; flex-direction: column; gap: 18px; }
.panel { background: var(--night-raised); border: 1px solid var(--line); border-radius: 16px; padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.panel h3 { font-size: 1.2rem; }
.panel form { display: flex; flex-direction: column; gap: 12px; }
.panel form input { font-size: 1.2rem; }
.panel .quote { font-size: 1.3rem; font-weight: 700; overflow-wrap: anywhere; }
.result-head { font-family: var(--display); font-size: 2.4rem; font-variation-settings: 'SOFT' 100; }
.result-head.hit { color: var(--good); }
.result-head.miss { color: #ff9b8a; }

/* Final standings */
.standings { list-style: none; padding: 0; margin: 0; }
.standings li { display: grid; grid-template-columns: 2.4em 1fr auto; align-items: baseline; padding: 11px 6px; border-bottom: 1px solid var(--line); font-size: 1.1rem; }
.standings li .place { color: var(--fog); font-variant-numeric: tabular-nums; }
.standings li:nth-child(-n+3) { font-size: 1.35rem; }
.standings li:first-child { color: var(--bulb); }
.standings li.me span:nth-child(2) { color: var(--bulb); }
.standings li .pts { font-variant-numeric: tabular-nums; font-weight: 700; }

@media (max-width: 900px) {
  .app { padding: 16px; }
  .play { grid-template-columns: 1fr; }
}

.screen .screen-msg { position: absolute; inset: 0; display: grid; place-items: center; color: var(--fog); font-size: 1.1rem; }
.screen .screen-msg[hidden] { display: none; }
.screen img.layer:not([src]) { visibility: hidden; }


/* ---------- Halloween scenery (behind everything) ---------- */
.app { position: relative; z-index: 1; }
.scenery { position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden; }
.scenery svg { position: absolute; left: 0; right: 0; bottom: 0; width: 100%; height: 100%; }
.scenery .web { position: absolute; top: 0; left: 0; width: 220px; height: 220px; opacity: 0.22; }
.scenery .web.right { left: auto; right: 0; transform: scaleX(-1); width: 160px; height: 160px; opacity: 0.15; }
.bat { transform-box: fill-box; animation: bat-fly linear infinite; }
.bat .wing { transform-box: fill-box; transform-origin: center; animation: flap 0.35s ease-in-out infinite alternate; }
@keyframes bat-fly {
  0% { transform: translate(0, 0); }
  50% { transform: translate(800px, -40px); }
  100% { transform: translate(1700px, 10px); }
}
@keyframes flap { from { transform: scaleY(1); } to { transform: scaleY(0.35); } }
.fog { animation: fog-drift 38s ease-in-out infinite alternate; }
.fog.two { animation-duration: 52s; animation-direction: alternate-reverse; }
@keyframes fog-drift { from { transform: translateX(-6%); } to { transform: translateX(6%); } }
.candle { animation: flicker-glow 2.6s ease-in-out infinite; }
@keyframes flicker-glow { 0%, 100% { opacity: 0.95; } 40% { opacity: 0.7; } 60% { opacity: 1; } }

/* Small pumpkin before the title */
.wordmark::before {
  content: ''; display: inline-block; width: 0.95em; height: 0.95em; margin-right: 0.3em; vertical-align: -0.08em;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64'%3E%3Cpath d='M33 6c0 5-1 8-3 10' stroke='%233f6b1d' stroke-width='5' fill='none' stroke-linecap='round'/%3E%3Cellipse cx='20' cy='38' rx='14' ry='20' fill='%23e8650f'/%3E%3Cellipse cx='44' cy='38' rx='14' ry='20' fill='%23e8650f'/%3E%3Cellipse cx='32' cy='38' rx='14' ry='21' fill='%23ff7b1c'/%3E%3Cpath d='M19 32l6-7 6 7zM33 32l6-7 6 7z' fill='%23ffd166'/%3E%3Cpath d='M18 44q14 10 28 0l-4 2-3-3-4 4-3-4-4 4-3-3-3 2z' fill='%23ffd166'/%3E%3C/svg%3E") center / contain no-repeat;
  filter: drop-shadow(0 0 6px rgba(255, 140, 40, 0.6));
}

/* Notices */
.toasts { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 50; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { background: #2a1840; border: 1px solid var(--bulb); color: var(--bone); padding: 10px 18px; border-radius: 12px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5); font-weight: 700; transition: opacity 0.5s ease, transform 0.5s ease; animation: toast-in 0.3s ease; }
.toast.out { opacity: 0; transform: translateY(8px); }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }

@media (prefers-reduced-motion: reduce) {
  .bat, .bat .wing, .fog, .candle { animation: none !important; }
  .bat { display: none; }
}
