: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 {
  position: fixed;
  z-index: 2;
  top: 150px;
  bottom: 130px;
  left: 8%;
  right: 8%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  pointer-events: none;
}
.lobby h2 { margin: 0; font-size: 2rem; color: var(--orange); text-shadow: 0 0 16px #000; }
.lobby-list {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-content: flex-start;
  gap: 8px;
  overflow: auto;
  pointer-events: auto;
}
.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); }
.settings .check { display: flex; align-items: center; gap: 8px; }
.settings input[type="checkbox"] { width: 20px; height: 20px; }
.settings input[type="number"] { padding: 8px; }

.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; }
}
