:root {
  --bg: #0b0618;
  --panel: #1a0f2e;
  --line: #3a2a5c;
  --orange: #ff7a18;
  --green: #7cfc6a;
  --text: #f5efe6;
  --muted: #a89cc0;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
}

h1 { font-size: 1.6rem; margin: 0 0 12px; color: var(--orange); }

button {
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  border: 0;
  border-radius: 10px;
  padding: 12px 18px;
  background: var(--orange);
  color: var(--panel);
}

button:disabled { opacity: 0.4; cursor: not-allowed; }

input {
  font: inherit;
  width: 100%;
  padding: 12px;
  border-radius: 10px;
  border: 2px solid var(--line);
  background: #120a22;
  color: var(--text);
}

.hidden { display: none !important; }
.error { color: #ff6b6b; min-height: 1.4em; }

/* Player screen */
.wrap { max-width: 480px; margin: 0 auto; padding: 16px; }
.join label { display: block; margin: 12px 0 4px; }
.join #code { text-transform: uppercase; letter-spacing: 0.2em; }

.last {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 64px;
  margin-bottom: 12px;
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--panel);
}
.last .emoji { font-size: 2.2rem; }

.card { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }

.cell {
  aspect-ratio: 1;
  padding: 2px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-weight: 400;
  background: var(--panel);
  color: var(--text);
  border: 2px solid var(--line);
  transition: transform 0.15s, background 0.15s;
}
.cell .emoji { font-size: 1.6rem; line-height: 1.1; }
.cell .label { max-width: 100%; font-size: 0.55rem; line-height: 1.1; color: var(--muted); text-align: center; overflow-wrap: anywhere; }
.cell.marked { background: var(--orange); border-color: #ffd9b0; transform: scale(0.94); }
.cell.marked .label { color: var(--panel); }
.cell.shake { animation: shake 0.3s; }

@keyframes shake {
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

.bingo { width: 100%; margin-top: 14px; padding: 16px; font-size: 1.4rem; }

.banner {
  min-height: 1.4em;
  margin-top: 12px;
  padding: 12px;
  border-radius: 12px;
  background: var(--panel);
  text-align: center;
}
.banner.win { background: var(--green); color: var(--bg); font-weight: 700; animation: pop 0.5s; }

@keyframes pop {
  0% { transform: scale(0.6); }
  70% { transform: scale(1.08); }
  100% { transform: scale(1); }
}

/* Host screen */
#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }

.hud {
  position: fixed;
  z-index: 2;
  padding: 14px 18px;
  border-radius: 14px;
  background: rgba(26, 15, 46, 0.82);
  font-size: 1.3rem;
}
.hud.tl { top: 16px; left: 16px; }
.hud.tr { top: 16px; right: 16px; text-align: right; }
.hud.bottom { left: 16px; right: 16px; bottom: 16px; display: flex; align-items: center; gap: 14px; }

.code { font-size: 3rem; font-weight: 800; letter-spacing: 0.2em; color: var(--orange); }
.drawn { flex: 1; display: flex; flex-wrap: wrap; gap: 4px; max-height: 84px; overflow: auto; font-size: 1.5rem; }

.flat {
  position: fixed;
  inset: 0;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.flat .emoji { font-size: 12rem; }
.flat .label { font-size: 2.5rem; }

.winner {
  position: fixed;
  z-index: 3;
  left: 0;
  right: 0;
  top: 38%;
  text-align: center;
  font-size: 4rem;
  font-weight: 800;
  color: var(--green);
  text-shadow: 0 0 24px #000;
  pointer-events: none;
}

.start {
  position: fixed;
  inset: 0;
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: rgba(11, 6, 24, 0.6);
}

/* Small buttons, selects, and shared effects */
.small { padding: 6px 12px; font-size: 1rem; }
select {
  font: inherit;
  width: 100%;
  padding: 8px;
  border-radius: 10px;
  border: 2px solid var(--line);
  background: #120a22;
  color: var(--text);
}

.confetti { position: fixed; inset: 0; z-index: 5; overflow: hidden; pointer-events: none; }
.confetti span { position: absolute; top: -3rem; animation: fall linear forwards; }
.confetti img { display: block; width: 1.6em; height: auto; }
@keyframes fall {
  to { transform: translateY(115vh) rotate(540deg); }
}

.pop { animation: pop 0.45s; }

/* Player screen: avatar picker, sound button, card motion */
.avatars { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; }
.avatar {
  aspect-ratio: 1;
  padding: 0;
  font-size: 1.5rem;
  font-weight: 400;
  background: var(--panel);
  border: 2px solid var(--line);
}
.avatar[aria-checked="true"] { background: var(--orange); border-color: #ffd9b0; transform: scale(1.1); }

.topline { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.topline #who { min-width: 0; margin: 8px 0; }
/* The message box takes no attention when it has no message. */
.banner:empty { visibility: hidden; }
.topline .small { flex: none; background: var(--panel); color: var(--text); border: 2px solid var(--line); }

.last .emoji { display: inline-block; }
.cell .emoji { display: inline-block; }
.cell.marked { box-shadow: 0 0 14px rgba(255, 122, 24, 0.7); }
.cell.marked .emoji { animation: haunt 2.4s ease-in-out infinite; }
@media (hover: hover) {
  .cell:not(.marked):hover .emoji { animation: wiggle 0.5s ease-in-out infinite; }
  .cell:not(.marked):hover { border-color: var(--orange); }
}
@keyframes wiggle {
  0%, 100% { transform: rotate(0) scale(1.15); }
  25% { transform: rotate(-14deg) scale(1.15); }
  75% { transform: rotate(14deg) scale(1.15); }
}
@keyframes haunt {
  0%, 100% { transform: translateY(0) rotate(-4deg); }
  50% { transform: translateY(-3px) rotate(4deg); }
}

/* Host screen: lobby, settings, flash, winner, themes */
.hud .small { margin-top: 8px; }
.hud.tr .small { background: var(--panel); color: var(--text); border: 2px solid var(--line); }

/* Lobby: the join code on top, the players on the left, the settings on the right, "Start" below. */
.lobby {
  position: fixed;
  inset: 0;
  z-index: 2;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 14px;
  padding: 16px;
  overflow: auto;
}
.lobby-head { display: flex; justify-content: center; }
.lobby-hint { margin: 0; font-size: 1.2rem; font-weight: 700; }
.lobby-main { display: grid; grid-template-columns: minmax(0, 3fr) minmax(300px, 2fr); gap: 14px; min-height: 0; }
.lobby-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
  min-height: 0;
  padding: 14px 18px;
  border-radius: 14px;
  background: rgba(26, 15, 46, 0.82);
}
.lobby-panel h3 { margin: 0; font-size: 1.3rem; color: var(--orange); }
.lobby-list {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 8px;
  overflow: auto;
}
.lobby-foot { display: flex; justify-content: center; }
.big { padding: 14px 72px; font-size: 2rem; }
/* In the lobby, the join box and the settings panel are parts of the layout. */
.lobby .hud { position: static; }
.lobby .settings {
  flex: 1;
  width: auto;
  min-height: 0;
  max-height: none;
  padding: 0;
  overflow-y: auto;
  border: 0;
  background: none;
  box-shadow: none;
}
.lobby #closeSettings { display: none; }
@media (max-width: 800px) {
  .lobby { grid-template-rows: auto auto auto; }
  .lobby-main { grid-template-columns: minmax(0, 1fr); }
  .lobby-list { max-height: 40vh; }
  .lobby .settings { overflow: visible; }
}

/* The join box: the game code, and a small QR code that gets large with a click. */
#hudJoin { display: flex; align-items: center; gap: 16px; }
.qr-small { flex: none; width: 104px; height: 104px; padding: 4px; border-radius: 10px; background: #fff; }
.qr-small img, .qr-big img { display: block; width: 100%; height: 100%; }
.qr-big {
  position: fixed;
  inset: 0;
  z-index: 7;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 16px;
  background: rgba(11, 6, 24, 0.93);
  cursor: pointer;
}
.qr-big img { width: min(68vh, 86vw); height: auto; padding: 8px; border-radius: 16px; background: #fff; }
.qr-big p { margin: 0; font-size: 2rem; font-weight: 700; text-align: center; }

/* "How to play" on the big screen, before the round */
.intro {
  position: fixed;
  inset: 0;
  z-index: 6;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 24px;
  background: rgba(11, 6, 24, 0.88);
  text-align: center;
}
.intro h2 { margin: 0; font-size: 3.4rem; }
.intro-stage { display: flex; align-items: center; justify-content: center; gap: 18px; width: min(100%, 1200px); height: min(50vh, 480px); }
.intro-clip { flex: 1 1 0; min-width: 0; max-height: 100%; border-radius: 16px; border: 4px solid #1c1230; box-shadow: 0 8px 0 rgba(0, 0, 0, 0.4); }
.intro-clip:only-child { flex: none; width: auto; height: 100%; max-width: 100%; }
.intro-monster.pic { height: 82%; width: auto; max-width: 30%; border: 4px solid #1c1230; box-shadow: 0 0 30px rgba(255, 122, 24, 0.6); }
.intro-logo { max-width: 100%; max-height: 100%; }
.intro-text { max-width: 28em; min-height: 2.6em; margin: 0; font-size: 2rem; font-weight: 700; text-shadow: 0 2px 0 #1c1230; }
.intro-dots { display: flex; gap: 8px; }
.intro-dots i { width: 12px; height: 12px; border-radius: 50%; background: #3f3168; box-shadow: 0 0 0 2px #1c1230; }
.intro-dots i.on { background: var(--orange); }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px 6px 8px;
  border-radius: 999px;
  background: rgba(26, 15, 46, 0.88);
  border: 2px solid var(--line);
  font-size: 1.5rem;
  animation: pop 0.45s;
}
.chip-avatar { font-size: 2rem; }

.settings {
  top: 150px;
  right: 16px;
  z-index: 4;
  width: 300px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 1rem;
  background: rgba(26, 15, 46, 0.96);
}
.settings h2 { margin: 0; font-size: 1.3rem; color: var(--orange); }
/* On and off settings are switches. The real checkbox is on top of the switch, and it is not visible. */
.switch { position: relative; display: flex; align-items: center; justify-content: space-between; gap: 12px; cursor: pointer; }
.switch input { position: absolute; right: 0; width: 52px; height: 28px; margin: 0; opacity: 0; cursor: pointer; }
.switch i {
  flex: none;
  position: relative;
  width: 52px;
  height: 28px;
  border-radius: 999px;
  border: 2px solid #1c1230;
  background: #2a1f4a;
  box-shadow: inset 0 0 0 1px #6b57a6;
  transition: background 0.15s;
}
.switch i::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #a89cc0;
  box-shadow: 0 2px 0 #1c1230;
  transition: transform 0.15s, background 0.15s;
}
.switch input:checked + i { background: linear-gradient(#ffb347, #ef7a12); box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.45); }
.switch input:checked + i::after { transform: translateX(24px); background: #fff; }
.switch input:focus-visible + i { outline: 3px solid #8dff5c; outline-offset: 2px; }

.flash { position: fixed; inset: 0; z-index: 3; background: #fff; opacity: 0; pointer-events: none; }
.flash.soft { animation: flash-soft 0.5s ease-out; }
.flash.strong { animation: flash-strong 0.9s ease-out; }
@keyframes flash-soft {
  0% { opacity: 0.22; }
  100% { opacity: 0; }
}
@keyframes flash-strong {
  0% { opacity: 0.6; }
  100% { opacity: 0; }
}

.winner { top: 20%; animation: winner-in 0.8s cubic-bezier(0.2, 1.6, 0.4, 1); }
.winner-avatar { font-size: 9rem; line-height: 1.1; animation: winner-dance 1.2s ease-in-out infinite; }
@keyframes winner-in {
  0% { transform: scale(0.2) rotate(-12deg); opacity: 0; }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}
@keyframes winner-dance {
  0%, 100% { transform: translateY(0) rotate(-8deg) scale(1); }
  50% { transform: translateY(-18px) rotate(8deg) scale(1.12); }
}

.flat .emoji.land { animation: land 0.7s; }
@keyframes land {
  0% { transform: scale(0.2) rotate(-30deg); }
  55% { transform: scale(1.25) rotate(6deg); }
  70% { transform: scale(0.95) translateX(-8px); }
  85% { transform: scale(1.03) translateX(8px); }
  100% { transform: scale(1); }
}

/* Background colors for the flat view. The 3D view sets its own colors. */
body.host[data-theme="night"] { background: #0b0618; }
body.host[data-theme="blood"] { background: #1a0406; }
body.host[data-theme="fog"] { background: #06140c; }
body.host[data-theme="storm"] { background: #0d0a24; }

/* Pictures of items and avatars. Each picture is a round medallion. */
.pic { display: inline-block; aspect-ratio: 1; object-fit: cover; border-radius: 50%; }
.cell { min-width: 0; overflow: hidden; }
.cell .pic { width: 78%; height: auto; }
.last .pic { display: block; width: 52px; height: 52px; }
.avatars { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.avatar { padding: 4px; border-radius: 50%; }
.avatar .pic { display: block; width: 100%; height: auto; }
.who-face.pic { width: 32px; height: 32px; vertical-align: middle; }
.chip-avatar.pic { width: 44px; height: 44px; }
.drawn-face.pic { width: 40px; height: 40px; }
.winner-face.pic { width: 11rem; height: 11rem; box-shadow: 0 0 40px rgba(255, 122, 24, 0.8); }
.flat-face { font-size: 12rem; }
.flat-face.pic { width: min(48vh, 420px); height: auto; }

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

/* Player join screen: one big monster with a "pick another" button, and "How to play" at the side. */
.join-view { display: grid; gap: 16px; }
.avatar-pick { position: relative; width: 150px; margin: 0 auto; }
.avatar-big { display: block; width: 150px; height: 150px; padding: 6px; border-radius: 50%; font-size: 5rem; line-height: 1; }
.avatar-big .pic { display: block; width: 100%; height: auto; }
.avatar-random { position: absolute; right: -8px; bottom: -4px; width: 54px; height: 54px; padding: 0; border-radius: 50%; font-size: 1.7rem; line-height: 1; }
.join button[type="submit"] { width: 100%; }
.howto { padding: 14px 18px; border-radius: 14px; background: var(--panel); }
.howto h2 { margin: 0 0 10px; font-size: 1.7rem; color: var(--orange); }
.howto ol { display: grid; gap: 10px; margin: 0; padding-left: 1.4em; line-height: 1.35; }
@media (min-width: 820px) {
  .wrap:has(.join-view:not(.hidden)) { max-width: 880px; }
  .join-view { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; gap: 28px; }
}
/* The box above the card, while the player waits for the round to start. */
.last.waiting .emoji { animation: haunt 1.6s ease-in-out infinite; }

/* Join screen: the form and "How to play" are two boxes with the same top line.
   In the form, the monster is at the side of the fields. */
.join { padding: 14px 18px; border-radius: 14px; background: var(--panel); }
.join h2 { margin: 0 0 12px; font-size: 1.7rem; text-align: center; color: var(--orange); }
.join-top { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 18px; }
.join-fields label:first-child { margin-top: 0; }
.avatar-pick { width: 132px; margin: 0; }
.avatar-big { width: 132px; height: 132px; }
.join .error { margin: 8px 0; }
@media (max-width: 380px) {
  .join-top { gap: 12px; }
  .avatar-pick, .avatar-big { width: 104px; }
  .avatar-big { height: 104px; }
  .avatar-random { width: 44px; height: 44px; font-size: 1.3rem; }
}

/* "How to play" in steps */
.howto { text-align: center; }
.howto-art { display: flex; align-items: center; justify-content: center; gap: 14px; height: 120px; }
.howto-pic.pic { width: 96px; height: 96px; animation: haunt 2.4s ease-in-out infinite; }
.howto-pic.pic:nth-child(2) { animation-delay: -0.8s; }
.howto-pic.pic:nth-child(3) { animation-delay: -1.6s; }
.howto-grid { display: grid; grid-template-columns: repeat(5, 18px); gap: 4px; }
.howto-grid i { width: 18px; height: 18px; border-radius: 4px; background: #3f3168; box-shadow: 0 0 0 1px #1c1230; }
.howto-grid i.on { background: var(--orange); animation: pop 1.2s ease-in-out infinite alternate; }
.howto h3 { margin: 10px 0 4px; font-size: 1.2rem; text-transform: uppercase; }
.howto p { min-height: 2.8em; margin: 0 0 10px; line-height: 1.35; }
.howto-nav { display: flex; align-items: center; justify-content: center; gap: 14px; }
.howto-arrow { padding: 4px 12px; font-size: 1.1rem; }

/* Easy level: a square that the player needs for a win shines. It shakes when its monster is called. */
.cell.near { border-color: #8dff5c; box-shadow: inset 0 0 0 1px #6b57a6, 0 0 0 2px #8dff5c, 0 0 14px rgba(141, 255, 92, 0.85); animation: near-shine 1.2s ease-in-out infinite; }
.cell.near-now { animation: near-shine 1.2s ease-in-out infinite, near-shake 0.6s ease-in-out infinite; }
@keyframes near-shine {
  50% { box-shadow: inset 0 0 0 1px #6b57a6, 0 0 0 2px #8dff5c, 0 0 26px rgba(141, 255, 92, 1); background: #3f5a4a; }
}
@keyframes near-shake {
  0%, 100% { transform: rotate(0); }
  25% { transform: rotate(-5deg) scale(1.05); }
  75% { transform: rotate(5deg) scale(1.05); }
}

/* The intro of a theme with no mode clips: the pattern of the mode as a big grid. */
.intro-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; height: 90%; aspect-ratio: 1; padding: 14px; border-radius: 16px; background: #2a1f4a; border: 4px solid #1c1230; }
.intro-grid i { border-radius: 8px; background: #3f3168; box-shadow: 0 0 0 2px #1c1230; }
.intro-grid i.on { background: var(--orange); box-shadow: 0 0 0 2px #1c1230, 0 0 18px rgba(255, 122, 24, 0.8); }
