@import url('https://fonts.googleapis.com/css2?family=Creepster&family=Cinzel:wght@400;700&family=UnifrakturMaguntia&display=swap');

* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --orange: #ff6a00;
  --orange-glow: rgba(255,106,0,0.6);
  --purple: #7b2d8b;
  --green: #39ff14;
  --green-glow: rgba(57,255,20,0.5);
  --dark: #0a0008;
  --mid: #110010;
  --blood: #8b0000;
}

body {
  min-height: 100vh;
  background: radial-gradient(ellipse at 50% 0%, #1a0020 0%, #0a0008 60%, #000 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Creepster', cursive;
  padding: 20px;
  overflow: hidden;
  position: relative;
}

/* ── Rain Canvas ── */
#rainCanvas {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}

/* ── Fog ── */
.fog {
  position: fixed;
  bottom: 0;
  left: -50%;
  width: 200%;
  height: 180px;
  background: radial-gradient(ellipse at center, rgba(80,0,100,0.18) 0%, transparent 70%);
  pointer-events: none;
  z-index: 1;
  animation: driftFog 18s ease-in-out infinite alternate;
}
.fog2 {
  height: 120px;
  opacity: 0.6;
  animation-duration: 24s;
  animation-direction: alternate-reverse;
}
@keyframes driftFog {
  from { transform: translateX(0) scaleY(1); }
  to   { transform: translateX(8%) scaleY(1.2); }
}

/* ── Bats ── */
.bats {
  position: absolute;
  top: -10px;
  width: 100%;
  display: flex;
  justify-content: space-around;
  pointer-events: none;
}
.bat {
  font-size: 1.2rem;
  animation: batFly 3s ease-in-out infinite;
  display: inline-block;
}
.bat:nth-child(2) { animation-delay: 1s; animation-duration: 3.5s; }
.bat:nth-child(3) { animation-delay: 2s; animation-duration: 2.8s; }
@keyframes batFly {
  0%,100% { transform: translateY(0) rotate(-5deg); }
  50%      { transform: translateY(-12px) rotate(5deg); }
}

/* ── Container ── */
.container {
  position: relative;
  z-index: 10;
  background: linear-gradient(160deg, #12001a 0%, #0d000f 50%, #080010 100%);
  border: 2px solid var(--purple);
  border-radius: 16px;
  padding: 36px 28px 28px;
  max-width: 480px;
  width: 100%;
  text-align: center;
  box-shadow:
    0 0 0 1px #3d0050,
    0 0 40px rgba(123,45,139,0.4),
    0 0 80px rgba(123,45,139,0.15),
    inset 0 0 40px rgba(0,0,0,0.8);
}

.container::before {
  content: '';
  position: absolute;
  inset: 4px;
  border: 1px solid rgba(123,45,139,0.3);
  border-radius: 13px;
  pointer-events: none;
}

/* ── Title ── */
.title {
  font-family: 'Creepster', cursive;
  font-size: 2rem;
  color: var(--orange);
  text-shadow:
    0 0 10px var(--orange-glow),
    0 0 30px var(--orange-glow),
    0 2px 4px #000;
  letter-spacing: 2px;
  margin-bottom: 4px;
  animation: flicker 6s infinite;
}

@keyframes flicker {
  0%,19%,21%,23%,100% { opacity: 1; }
  20%,22% { opacity: 0.6; }
}

.subtitle {
  color: #7b4a8b;
  font-family: 'Cinzel', serif;
  font-size: 0.75rem;
  letter-spacing: 3px;
  margin-bottom: 24px;
  text-transform: uppercase;
}

/* ── Scoreboard ── */
.scoreboard {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 18px;
  background: rgba(0,0,0,0.4);
  border: 1px solid #3d0050;
  border-radius: 10px;
  padding: 12px 16px;
}

.player {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 18px;
  border-radius: 8px;
  transition: all 0.4s;
  min-width: 90px;
}

.player.active {
  background: rgba(123,45,139,0.2);
  box-shadow: 0 0 16px rgba(123,45,139,0.4);
}

.player-symbol {
  font-size: 2rem;
  line-height: 1;
  display: inline-block;
  transition: filter 0.3s;
  cursor: default;
}

/* toe SVG used in board cells */
.toe-svg {
  width: 72px;
  height: 52px;
  display: block;
  margin: auto;
  filter: drop-shadow(0 0 8px rgba(106,191,69,0.9)) drop-shadow(0 0 2px #000);
}

.player-name {
  font-family: 'Cinzel', serif;
  font-size: 0.65rem;
  color: #7b4a8b;
  letter-spacing: 1px;
  text-transform: uppercase;
}

.score {
  font-family: 'Creepster', cursive;
  font-size: 1.8rem;
  color: var(--orange);
  text-shadow: 0 0 8px var(--orange-glow);
}

.divider {
  font-size: 1.4rem;
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0%,100% { transform: scale(1); }
  50%      { transform: scale(1.2); }
}

/* ── Status ── */
.status {
  font-size: 1.1rem;
  color: #c060e0;
  margin-bottom: 20px;
  min-height: 28px;
  text-shadow: 0 0 8px rgba(192,96,224,0.5);
  transition: all 0.3s;
  letter-spacing: 1px;
}
.status.winner {
  color: var(--orange);
  font-size: 1.25rem;
  text-shadow: 0 0 12px var(--orange-glow), 0 0 30px var(--orange-glow);
  animation: statusPop 0.4s ease-out;
}
.status.draw {
  color: #888;
}
@keyframes statusPop {
  from { transform: scale(0.8); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}

/* ── Board ── */
.board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0;
  margin: 0 auto 24px;
  max-width: 340px;
  border: 2px solid #4a0060;
  border-radius: 8px;
  overflow: hidden;
  box-shadow:
    0 0 20px rgba(123,45,139,0.5),
    0 0 60px rgba(123,45,139,0.15);
}

.cell {
  aspect-ratio: 1;
  background: linear-gradient(135deg, #0e000d, #0a0008);
  border: 1px solid #2d0040;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  transition: background 0.2s;
  position: relative;
  user-select: none;
  overflow: hidden;
}

.cell:hover:not(.taken) {
  background: linear-gradient(135deg, #180025, #0e000d);
  box-shadow: inset 0 0 20px rgba(123,45,139,0.3);
}

.cell.taken { cursor: default; }

/* Toe cell */
.cell.toe-cell { animation: popIn 0.3s cubic-bezier(0.175,0.885,0.32,1.275); }
/* Head cell */
.cell.head-cell { animation: popIn 0.3s cubic-bezier(0.175,0.885,0.32,1.275); }

@keyframes popIn {
  from { transform: scale(0) rotate(-20deg); opacity: 0; }
  to   { transform: scale(1) rotate(0deg);   opacity: 1; }
}

/* ── Winner wiggle ── */
.cell.wiggle-winner {
  animation: wiggleWinner 0.5s ease-in-out infinite;
}
@keyframes wiggleWinner {
  0%,100% { transform: rotate(0deg) scale(1.05); }
  25%      { transform: rotate(-12deg) scale(1.1); }
  75%      { transform: rotate(12deg) scale(1.1); }
}

/* ── Loser wiggle (sad trembling) ── */
.cell.wiggle-loser {
  animation: wiggleLoser 0.4s ease-in-out infinite;
}
@keyframes wiggleLoser {
  0%,100% { transform: translateX(0) rotate(0deg); filter: brightness(0.6); }
  20%      { transform: translateX(-4px) rotate(-5deg); }
  40%      { transform: translateX(4px) rotate(5deg); }
  60%      { transform: translateX(-3px) rotate(-3deg); }
  80%      { transform: translateX(3px) rotate(3deg); }
}

/* ── Explosion animations ── */
@keyframes cellShake {
  0%,100% { transform: translate(0,0) rotate(0deg) scale(1); }
  15%     { transform: translate(-6px,-4px) rotate(-8deg) scale(1.1); }
  30%     { transform: translate(6px,-6px) rotate(8deg) scale(1.15); }
  45%     { transform: translate(-5px,5px) rotate(-6deg) scale(1.1); }
  60%     { transform: translate(7px,3px) rotate(10deg) scale(1.2); }
  75%     { transform: translate(-4px,-5px) rotate(-5deg) scale(1.1); }
}

.cell-exploding {
  animation: cellShake 0.3s ease-in-out forwards !important;
  filter: brightness(1.5) saturate(2);
}

.cell-splattered {
  background: linear-gradient(135deg, #0a1a00, #051000) !important;
  cursor: default;
}

@keyframes gorefly {
  0%   { transform: translate(-50%,-50%) scale(1); opacity: 1; }
  100% { transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(0.2) rotate(720deg); opacity: 0; }
}

@keyframes explodeFlash {
  0%   { transform: translate(-50%,-50%) scale(0); opacity: 1; }
  60%  { transform: translate(-50%,-50%) scale(1.8); opacity: 0.8; }
  100% { transform: translate(-50%,-50%) scale(2.5); opacity: 0; }
}

.splat-svg {
  width: 100%;
  height: 100%;
  display: block;
  filter: drop-shadow(0 0 8px #39ff14) drop-shadow(0 0 16px rgba(57,255,20,0.5));
  animation: splatPulse 1.5s ease-in-out infinite;
}

@keyframes splatPulse {
  0%,100% { filter: drop-shadow(0 0 6px #39ff14) drop-shadow(0 0 12px rgba(57,255,20,0.4)); }
  50%     { filter: drop-shadow(0 0 14px #7fff00) drop-shadow(0 0 28px rgba(127,255,0,0.7)); }
}

/* ── Blood screen flash on win ── */
@keyframes bloodFlash {
  0%   { opacity: 1; }
  100% { opacity: 0; }
}

/* ensure game container always sits above blood canvas */
.container { position: relative; z-index: 100; }

/* bleeding toe glow + drip animation */
.toe-bleeding {
  filter: drop-shadow(0 0 8px rgba(200,0,0,0.9)) drop-shadow(0 0 2px #000) !important;
  animation: bleedPulse 0.6s ease-in-out infinite !important;
}
@keyframes bleedPulse {
  0%,100% { filter: drop-shadow(0 0 6px rgba(180,0,0,0.8)) drop-shadow(0 0 2px #000); }
  50%     { filter: drop-shadow(0 0 16px rgba(255,0,0,1))   drop-shadow(0 0 4px #000); }
}

/* winning cell glow */
.cell.winning-cell {
  background: linear-gradient(135deg, #1a0028, #120018) !important;
  box-shadow: inset 0 0 30px rgba(255,106,0,0.25);
}

/* ── Buttons ── */
.buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.btn {
  font-family: 'Creepster', cursive;
  font-size: 1rem;
  padding: 10px 22px;
  border-radius: 8px;
  border: 1px solid var(--purple);
  background: linear-gradient(145deg, #2d0040, #1a0025);
  color: var(--orange);
  cursor: pointer;
  letter-spacing: 1px;
  transition: all 0.2s;
  box-shadow: 0 0 12px rgba(123,45,139,0.3);
  text-shadow: 0 0 6px var(--orange-glow);
}

.btn:hover {
  background: linear-gradient(145deg, #3d0055, #2d0040);
  box-shadow: 0 0 20px rgba(123,45,139,0.6), 0 0 8px var(--orange-glow);
  transform: translateY(-2px);
}

.btn:active { transform: translateY(0); }

.btn-secondary {
  color: #7b4a8b;
  border-color: #3d0050;
  text-shadow: none;
}
.btn-secondary:hover { color: #c060e0; }

/* ── Spiderweb corners ── */
.container::after {
  content: '🕸';
  position: absolute;
  top: 6px;
  right: 10px;
  font-size: 1.4rem;
  opacity: 0.4;
  pointer-events: none;
}

/* ── Rain drops (canvas drawn, but emoji fallback) ── */
.rain-emoji {
  position: fixed;
  top: -60px;
  font-size: 1.4rem;
  pointer-events: none;
  z-index: 60;
  animation: fall linear forwards;
  user-select: none;
}
@keyframes fall {
  from { transform: translateY(0) rotate(0deg); opacity: 1; }
  to   { transform: translateY(110vh) rotate(360deg); opacity: 0; }
}

/* ── Winner scoreboard flash ── */
.player.winner-flash {
  animation: winnerFlash 0.6s ease-in-out 3;
}
@keyframes winnerFlash {
  0%,100% { background: rgba(123,45,139,0.2); }
  50%      { background: rgba(255,106,0,0.25); box-shadow: 0 0 24px var(--orange-glow); }
}

@media (max-width: 400px) {
  .container { padding: 24px 14px 20px; }
  .title { font-size: 1.5rem; }
  .board { max-width: 280px; }
  .cell { font-size: 1.8rem; }
  .toe-svg { width: 40px; height: 40px; }
}
