:root {
  --bg: #0b0a0f;
  --panel: #16131d;
  --border: #2c2534;
  --text: #d8d3e0;
  --text-dim: #a39cb0;
  --accent: #9b6dff;
  --win: #7fe0a0;
  --lose: #ff6b6b;

  --moth: #b47cff;
  --bone: #e7e2d6;
  --serpent: #5fbf7a;
  --ashling: #ff8a4c;
  --drowspawn: #4b3f6b;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(ellipse at top, #1a1424 0%, var(--bg) 60%);
  color: var(--text);
  font-family: Georgia, "Times New Roman", serif;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 2rem 1rem 3rem;
  position: relative;
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background: radial-gradient(circle at 50% -10%, rgba(155, 109, 255, 0.16), transparent 55%);
  animation: torch-pulse 6s ease-in-out infinite;
  pointer-events: none;
  z-index: 0;
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  background-image: radial-gradient(rgba(216, 211, 224, 0.03) 1px, transparent 1px);
  background-size: 28px 28px;
  pointer-events: none;
  z-index: 0;
}

@keyframes torch-pulse {
  0%, 100% { opacity: 0.55; }
  50% { opacity: 1; }
}

.ember {
  position: fixed;
  bottom: -10px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 180, 120, 0.9), transparent 70%);
  pointer-events: none;
  z-index: 0;
  animation: ember-rise linear infinite;
}

@keyframes ember-rise {
  0% { transform: translateY(0) translateX(0); opacity: 0; }
  10% { opacity: 1; }
  90% { opacity: 0.8; }
  100% { transform: translateY(-100vh) translateX(18px); opacity: 0; }
}

.ember:nth-child(1) { left: 10%; animation-duration: 9s; animation-delay: 0s; }
.ember:nth-child(2) { left: 30%; animation-duration: 12s; animation-delay: 2s; }
.ember:nth-child(3) { left: 55%; animation-duration: 10s; animation-delay: 4s; }
.ember:nth-child(4) { left: 75%; animation-duration: 14s; animation-delay: 1s; }
.ember:nth-child(5) { left: 90%; animation-duration: 11s; animation-delay: 3s; }

header, main, footer {
  position: relative;
  z-index: 1;
}

header {
  max-width: 560px;
  text-align: center;
  margin-bottom: 1.5rem;
}

h1 {
  font-family: "Cinzel", Georgia, serif;
  font-size: 2.4rem;
  letter-spacing: 0.06em;
  margin: 0 0 0.6rem;
  color: #eae4f5;
  text-shadow: 0 0 18px rgba(155, 109, 255, 0.35);
}

.tagline {
  color: var(--text-dim);
  font-size: 0.92rem;
  line-height: 1.6;
  font-style: italic;
}

.mute-button {
  margin-top: 0.8rem;
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.3rem 0.9rem;
  font-family: Georgia, serif;
  font-size: 0.72rem;
  letter-spacing: 0.03em;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.mute-button:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.mute-button.muted {
  color: var(--lose);
  border-color: rgba(255, 107, 107, 0.4);
}

main {
  width: 100%;
  max-width: 520px;
}

.hud {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  gap: 1rem;
  flex-wrap: wrap;
}

.stat {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 1rem;
  text-align: center;
  min-width: 80px;
}

.stat-count {
  display: block;
  font-family: "Cinzel", Georgia, serif;
  font-size: 1.6rem;
  font-weight: bold;
  color: var(--accent);
}

.stat-label {
  font-size: 0.7rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.wards {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.ward {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.45rem 0.6rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 128px;
}

.ward.sealed {
  opacity: 0.35;
}

.ward.seal-flash {
  animation: seal-flash 0.7s ease-out;
}

@keyframes seal-flash {
  0% { box-shadow: 0 0 0 0 rgba(234, 228, 245, 0.9); }
  100% { box-shadow: 0 0 26px 8px rgba(234, 228, 245, 0); }
}

.ward svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.ward:not(.sealed) svg {
  animation: idle-breathe 3s ease-in-out infinite;
}

@keyframes idle-breathe {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}

.ward-info {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.ward-name {
  font-family: "Cinzel", Georgia, serif;
  font-size: 0.66rem;
  letter-spacing: 0.02em;
  color: var(--text);
}

.ward-bar-track {
  flex-grow: 1;
  height: 6px;
  background: #201a2b;
  border-radius: 3px;
  overflow: hidden;
}

.ward-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.25s ease;
}

.ward-near .ward-bar-fill {
  animation: bar-glow 1s ease-in-out infinite;
}

@keyframes bar-glow {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.6); }
}

.board-wrap {
  display: flex;
  justify-content: center;
  position: relative;
}

.toast {
  position: absolute;
  top: -2.2rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.35rem 0.9rem;
  font-size: 0.72rem;
  color: var(--text-dim);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.toast.visible {
  opacity: 1;
}

.combo-popup {
  position: absolute;
  top: 40%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-family: "Cinzel", Georgia, serif;
  font-size: 1.1rem;
  color: #fff2d8;
  text-shadow: 0 0 12px rgba(255, 200, 120, 0.7);
  pointer-events: none;
  animation: combo-rise 0.85s ease-out forwards;
  z-index: 4;
}

@keyframes combo-rise {
  0% { opacity: 0; transform: translate(-50%, -40%) scale(0.8); }
  20% { opacity: 1; transform: translate(-50%, -55%) scale(1.05); }
  100% { opacity: 0; transform: translate(-50%, -90%) scale(1); }
}

.board {
  display: grid;
  gap: 4px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px;
  transition: opacity 0.15s ease;
}

.board.busy {
  pointer-events: none;
  opacity: 0.9;
}

.tile {
  width: 44px;
  height: 44px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border: 1px solid rgba(255, 255, 255, 0.06);
  transition: transform 0.12s ease;
}

.tile:hover {
  transform: scale(1.06);
}

.tile.selected {
  outline: 2px solid var(--accent);
  transform: scale(1.08);
}

.tile.clearing {
  animation: fade-out 0.2s ease forwards;
}

.tile.tile-pop {
  animation: tile-pop-in 0.22s ease-out;
}

.tile.shake {
  animation: tile-shake 0.22s ease-in-out;
}

@keyframes fade-out {
  to { opacity: 0; transform: scale(0.5); }
}

@keyframes tile-pop-in {
  from { opacity: 0; transform: scale(0.3); }
  to { opacity: 1; transform: scale(1); }
}

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

.tile svg {
  width: 24px;
  height: 24px;
  color: rgba(0, 0, 0, 0.55);
}

footer {
  margin-top: 2rem;
  max-width: 480px;
  text-align: center;
  color: var(--text-dim);
  font-size: 0.78rem;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(6, 5, 9, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 5;
}

.overlay[hidden] {
  display: none;
}

.overlay-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 2rem 2.4rem;
  text-align: center;
  max-width: 340px;
  box-shadow: 0 0 30px rgba(155, 109, 255, 0.18);
  animation: card-in 0.25s ease-out;
}

.overlay-card--intro {
  max-width: 460px;
}

.overlay-card--win {
  border-color: var(--win);
  box-shadow: 0 0 34px rgba(127, 224, 160, 0.25);
}

.overlay-card--win h2 {
  color: var(--win);
}

.overlay-card--lose {
  border-color: var(--lose);
  box-shadow: 0 0 34px rgba(255, 107, 107, 0.2);
}

.overlay-card--lose h2 {
  color: var(--lose);
}

@keyframes card-in {
  from { opacity: 0; transform: scale(0.92); }
  to { opacity: 1; transform: scale(1); }
}

.overlay-card h2 {
  font-family: "Cinzel", Georgia, serif;
  margin-top: 0;
  color: var(--accent);
}

.intro-lore {
  color: var(--text-dim);
  font-size: 0.88rem;
  line-height: 1.6;
  font-style: italic;
  text-align: left;
}

.codex {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
  margin: 1.2rem 0;
  text-align: left;
}

.codex-entry {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.6rem;
}

.codex-entry svg {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  animation: idle-breathe 3s ease-in-out infinite;
}

.codex-name {
  display: block;
  font-family: "Cinzel", Georgia, serif;
  font-size: 0.76rem;
  color: var(--text);
}

.codex-flavor {
  display: block;
  font-size: 0.68rem;
  color: var(--text-dim);
  line-height: 1.3;
  margin-top: 2px;
}

.overlay-card button {
  margin-top: 1rem;
  background: var(--accent);
  border: none;
  color: #0b0a0f;
  font-family: "Cinzel", Georgia, serif;
  font-size: 0.9rem;
  padding: 0.6rem 1.3rem;
  border-radius: 6px;
  cursor: pointer;
  transition: transform 0.12s ease;
}

.overlay-card button:hover {
  transform: scale(1.05);
}
