* { box-sizing: border-box; }

:root {
  --purple: #4d1979;
  --purple-light: #8152ad;
  --purple-dark: #24103e;
  --gold: #f5c542;
  --gold-dark: #b88716;
  --red: #df2844;
  --white: #ffffff;
  --ink: #20182e;
  --muted: #746a83;
  --shadow: 0 18px 42px rgba(34,12,58,.25);
}

html, body {
  margin: 0;
  min-height: 100%;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
  font-family: Arial, Helvetica, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 8% 4%, rgba(245,197,66,.24), transparent 28rem),
    linear-gradient(150deg, #eee4f8, #faf8ff 45%, #efe8f6);
}

button { font: inherit; }

.app {
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 12px;
  padding: 12px;
}

.topbar {
  min-height: 102px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 14px 20px;
  border: 2px solid rgba(77,25,121,.12);
  border-top: 7px solid var(--gold);
  border-radius: 22px;
  background: rgba(255,255,255,.97);
  box-shadow: var(--shadow);
}

.version {
  display: block;
  margin-bottom: 3px;
  color: var(--purple);
  font-size: .68rem;
  font-weight: 900;
  letter-spacing: .15em;
}

h1, h2, p { margin-top: 0; }

h1 {
  margin-bottom: 3px;
  color: var(--purple-dark);
  font-size: clamp(2rem, 4vw, 3.7rem);
  line-height: .95;
  letter-spacing: -.05em;
}

.brand p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: clamp(.82rem, 1.2vw, 1rem);
}

.hud {
  display: flex;
  align-items: stretch;
  gap: 9px;
  flex-shrink: 0;
}

.hud-card {
  min-width: 104px;
  padding: 10px 14px;
  border: 3px solid var(--gold);
  border-radius: 15px;
  text-align: center;
  color: white;
  background: var(--purple-dark);
}

.hud-card span {
  display: block;
  color: var(--gold);
  font-size: .66rem;
  font-weight: 900;
  letter-spacing: .13em;
}

.hud-card strong { font-size: 1.65rem; }

.start-btn {
  min-width: 132px;
  border: 0;
  border-radius: 15px;
  padding: 0 18px;
  color: var(--purple-dark);
  background: linear-gradient(135deg, var(--gold), #ffdc72);
  box-shadow: 0 9px 20px rgba(184,135,22,.28);
  font-weight: 900;
  cursor: pointer;
}

.start-btn:hover:not(:disabled) { filter: brightness(1.04); }
.start-btn:disabled { opacity: .55; cursor: not-allowed; }

.game-layout {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(170px,.58fr) minmax(0,3fr) minmax(190px,.68fr);
  gap: 12px;
}

.side-card {
  min-height: 0;
  padding: 16px;
  border: 2px solid rgba(77,25,121,.12);
  border-radius: 22px;
  background: rgba(255,255,255,.97);
  box-shadow: var(--shadow);
  overflow: auto;
}

.side-card h2 {
  margin-bottom: 10px;
  color: var(--purple-dark);
  font-size: 1.1rem;
}

.side-card p {
  color: var(--muted);
  line-height: 1.48;
  font-size: .9rem;
}

.board-wrap {
  position: relative;
  min-height: 0;
}

.board {
  position: relative;
  height: 100%;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0,1fr));
  grid-template-rows: repeat(3, minmax(0,1fr));
  gap: clamp(6px,.9vw,12px);
  padding: clamp(10px,1.35vw,18px);
  overflow: hidden;
  border: clamp(6px,.6vw,9px) solid var(--gold-dark);
  border-radius: 24px;
  background:
    radial-gradient(circle at 20% 12%, rgba(255,255,255,.15), transparent 22rem),
    linear-gradient(145deg, var(--purple-light), var(--purple));
  box-shadow: inset 0 0 0 4px rgba(255,255,255,.08), var(--shadow);
  touch-action: manipulation;
}

.slot {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border: 0;
  border-radius: 13px;
  padding: 0;
  background: rgba(31,10,53,.22);
  cursor: default;
  touch-action: manipulation;
}

.slot::after {
  content: "";
  position: absolute;
  z-index: 1;
  left: 10%;
  right: 10%;
  bottom: 5%;
  height: 15%;
  border-radius: 50%;
  background: radial-gradient(ellipse at center,#0d0712 0 54%,#775127 55% 70%,#4d3218 71% 100%);
  box-shadow: inset 0 5px 11px rgba(0,0,0,.52), 0 3px 7px rgba(0,0,0,.2);
}

.target-wrap {
  position: absolute;
  z-index: 2;
  left: 50%;
  bottom: -140%;
  width: min(82%, 165px);
  aspect-ratio: 1 / 1;
  transform: translateX(-50%);
  border: 5px solid var(--gold);
  border-radius: 50%;
  overflow: hidden;
  background: white;
  box-shadow: 0 10px 22px rgba(0,0,0,.28);
  transition: bottom .16s ease, transform .10s ease, filter .10s ease;
  pointer-events: none;
}

.target {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  object-position: center 20%;
  border-radius: 50%;
  user-select: none;
}

.slot:nth-child(2) .target,
.slot:nth-child(6) .target { object-position: center 15%; }

.slot:nth-child(4) .target,
.slot:nth-child(7) .target { object-position: center 18%; }

.slot.active { cursor: pointer; }
.slot.active .target-wrap { bottom: 8%; }

.slot.hit .target-wrap {
  transform: translateX(-50%) scale(.88) rotate(-4deg);
  filter: brightness(.78) saturate(1.12);
}

.slot.active:focus-visible {
  outline: 4px solid var(--gold);
  outline-offset: -4px;
}

.hammer {
  --hammer-x: 50%;
  --hammer-y: 50%;
  position: absolute;
  z-index: 10;
  left: var(--hammer-x);
  top: var(--hammer-y);
  width: clamp(130px,15vw,250px);
  height: auto;
  opacity: 0;
  pointer-events: none;
  transform-origin: 68% 76%;
  filter: drop-shadow(0 15px 11px rgba(0,0,0,.36));
}

.hammer.swing {
  animation: hammer-smack 370ms cubic-bezier(.14,.9,.2,1);
}

@keyframes hammer-smack {
  0%   { opacity:0; transform:translate(9%,-122%) rotate(-83deg) perspective(700px) rotateX(20deg) scale(.88); }
  15%  { opacity:1; }
  58%  { opacity:1; transform:translate(-47%,-55%) rotate(-11deg) perspective(700px) rotateX(4deg) scale(1.09); }
  72%  { opacity:1; transform:translate(-50%,-52%) rotate(5deg) perspective(700px) rotateX(0deg) scale(1.05); }
  100% { opacity:0; transform:translate(-18%,-90%) rotate(-50deg) perspective(700px) rotateX(12deg) scale(.96); }
}

.miss-layer {
  position: absolute;
  inset: 0;
  z-index: 7;
  pointer-events: none;
}

.miss-x {
  position: absolute;
  width: 54px;
  height: 54px;
  opacity: 0;
  transform: translate(-50%,-50%) scale(.5);
  filter: drop-shadow(0 4px 5px rgba(0,0,0,.35));
  animation: miss-pop 660ms ease-out forwards;
}

.miss-x::before,
.miss-x::after {
  content: "";
  position: absolute;
  left: 23px;
  top: 2px;
  width: 8px;
  height: 50px;
  border-radius: 5px;
  background: var(--red);
  box-shadow: 0 0 0 3px white;
}

.miss-x::before { transform: rotate(45deg); }
.miss-x::after { transform: rotate(-45deg); }

@keyframes miss-pop {
  0% { opacity:0; transform:translate(-50%,-50%) scale(.45); }
  20% { opacity:1; transform:translate(-50%,-50%) scale(1.12); }
  72% { opacity:1; transform:translate(-50%,-50%) scale(1); }
  100% { opacity:0; transform:translate(-50%,-50%) scale(.88); }
}

.round-message {
  position: absolute;
  z-index: 8;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  border-radius: 24px;
  background: rgba(25,8,45,.75);
  backdrop-filter: blur(5px);
  transition: opacity .2s ease, visibility .2s ease;
}

.round-message.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.message-card {
  min-width: min(390px,88%);
  padding: 24px;
  text-align: center;
  color: white;
  border: 3px solid var(--gold);
  border-radius: 20px;
  background: var(--purple-dark);
}

.message-card h2 {
  margin-bottom: 7px;
  color: var(--gold);
  font-size: clamp(2rem,4vw,3rem);
}

.message-card p { margin-bottom: 0; }
.fallback { margin-bottom: 0; font-size: .86rem; }

@media (max-width: 850px) {
  body { overflow: auto; }
  .app { height: auto; min-height: 100dvh; }
  .topbar { align-items: stretch; flex-direction: column; }
  .hud { width: 100%; }
  .hud-card, .start-btn { flex: 1; min-width: 0; }
  .game-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(620px,72vh) auto;
  }
  .instructions { order: 2; }
  .board-wrap { order: 1; }
  .leaderboard-panel { order: 3; }
}

@media (max-width: 480px) {
  .app { padding: 8px; gap: 8px; }
  .topbar { padding: 13px; }
  .hud { gap: 6px; }
  .hud-card { padding: 9px 7px; }
  .start-btn { padding: 0 8px; font-size: .82rem; }
  .game-layout { grid-template-rows: auto minmax(500px,68vh) auto; }
  .board { padding: 7px; gap: 5px; border-width: 6px; }
  .target-wrap { width: min(88%,125px); border-width: 4px; }
}
