:root {
  --bg: #0e0b1a;
  --panel: rgba(255, 255, 255, 0.035);
  --panel-solid: #171226;
  --border: rgba(255, 255, 255, 0.09);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text: #f2effa;
  --muted: #9d92bd;
  --accent: #8b6cff;
  --accent-2: #ff6ba9;
  --common: #a3abb8;
  --uncommon: #4ade8c;
  --rare: #5aa2f0;
  --epic: #c66ef2;
  --legendary: #ffc93d;
}

* { box-sizing: border-box; }

html { color-scheme: dark; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter', sans-serif;
  background:
    radial-gradient(50rem 30rem at 85% -10%, rgba(139, 108, 255, 0.14), transparent 60%),
    radial-gradient(40rem 26rem at 0% 110%, rgba(255, 107, 169, 0.08), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.1rem 2rem;
  border-bottom: 1px solid var(--border);
  background: rgba(14, 11, 26, 0.75);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 10;
}

header h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  background: linear-gradient(90deg, var(--accent-2), var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

#userBadge {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  color: var(--muted);
  font-size: 0.9rem;
}

#userBadge strong { color: var(--text); font-weight: 600; }

button {
  cursor: pointer;
  border: none;
  border-radius: 10px;
  padding: 0.6rem 1.2rem;
  font-size: 0.95rem;
  font-weight: 600;
  font-family: inherit;
  background: var(--accent);
  color: white;
  transition: transform 0.12s ease, box-shadow 0.12s ease, opacity 0.12s ease;
}

button:hover { opacity: 0.92; transform: translateY(-1px); }
button:active { transform: translateY(0) scale(0.98); }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

#logoutBtn {
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--muted);
  font-weight: 500;
  padding: 0.45rem 0.95rem;
  font-size: 0.85rem;
}

#logoutBtn:hover { color: var(--text); border-color: var(--accent); opacity: 1; }

main { max-width: 760px; margin: 2.75rem auto; padding: 0 1.5rem; }

.hidden { display: none !important; }

/* ---------- Login ---------- */

#loginView { max-width: 420px; margin: 4rem auto 0; }

#loginForm {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 2rem;
  box-shadow: 0 24px 60px -24px rgba(0, 0, 0, 0.6);
}

#loginForm label {
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.45;
}

#loginForm input {
  padding: 0.7rem 0.9rem;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: rgba(0, 0, 0, 0.35);
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

#loginForm input::placeholder { color: #6d6390; }

#loginForm input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(139, 108, 255, 0.25);
}

#loginForm button {
  margin-top: 0.35rem;
  padding: 0.75rem;
  font-size: 1rem;
  background: linear-gradient(135deg, var(--accent-2), var(--accent));
  box-shadow: 0 8px 24px -10px rgba(139, 108, 255, 0.7);
}

.error {
  color: #ff7b8a;
  margin-top: 0.85rem;
  font-size: 0.9rem;
  text-align: center;
}

/* ---------- Game panel ---------- */

.game-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 2.25rem 2rem;
  text-align: center;
  margin-bottom: 2.25rem;
  box-shadow: 0 24px 60px -30px rgba(0, 0, 0, 0.55);
}

.panel-title { font-weight: 650; font-size: 1.02rem; margin-bottom: 0.9rem; }

.attempts-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  margin-bottom: 1rem;
}

.attempts-label {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  margin-right: 0.35rem;
}

.pip {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  transform: rotate(45deg);
}

.pip.full { background: linear-gradient(135deg, var(--accent-2), var(--accent)); }
.pip.spent { background: rgba(255, 255, 255, 0.1); }

/* ---------- Archery scene ---------- */

.scene {
  position: relative;
  height: 165px;
  border-radius: 14px;
  background:
    linear-gradient(to bottom, rgba(90, 162, 240, 0.08), transparent 70%),
    linear-gradient(to top, rgba(74, 222, 140, 0.09) 0%, transparent 22%),
    rgba(0, 0, 0, 0.25);
  border: 1px solid var(--border);
  overflow: hidden;
  margin-bottom: 0.9rem;
}

.arrow {
  position: absolute;
  left: 8px;
  top: 0;
  width: 44px;
  height: 10px;
  transform: translateY(var(--start-y, 64px));
  z-index: 2;
}

.arrow.flying { animation: fly 0.6s cubic-bezier(0.3, 0, 0.8, 1) forwards; }

@keyframes fly {
  0% { transform: translate(0, var(--start-y)) rotate(var(--tilt, 0deg)); }
  12% { transform: translate(-10px, var(--start-y)) rotate(var(--tilt, 0deg)); } /* draw back */
  100% { transform: translate(var(--fly-x), var(--end-y)) rotate(var(--tilt, 0deg)); }
}

.scene.shake { animation: sceneShake 0.35s ease; }

@keyframes sceneShake {
  0%, 100% { transform: translate(0, 0); }
  25% { transform: translate(-3px, 2px); }
  50% { transform: translate(3px, -2px); }
  75% { transform: translate(-2px, 1px); }
}

.impact-ring {
  position: absolute;
  right: 44px;
  top: 22px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 3px solid var(--legendary);
  opacity: 0;
  pointer-events: none;
  z-index: 3;
}

.impact-ring.burst { animation: ringBurst 0.5s ease-out; }

@keyframes ringBurst {
  0% { transform: scale(0.3); opacity: 1; }
  100% { transform: scale(2.4); opacity: 0; }
}

.pig-target {
  position: absolute;
  right: 26px;
  bottom: 8px;
  text-align: center;
  animation: idleBob 3s ease-in-out infinite;
}

@keyframes idleBob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-3px); }
}

.pig-target.duck { animation: duck 0.4s ease; }

@keyframes duck {
  0%, 100% { transform: translateY(0); }
  40% { transform: translateY(10px) rotate(-4deg); }
}

.pig-target.hop { animation: happyHop 0.55s cubic-bezier(0.34, 1.56, 0.64, 1); }

@keyframes happyHop {
  0%, 100% { transform: translateY(0) scale(1, 1); }
  30% { transform: translateY(-14px) scale(0.96, 1.06) rotate(3deg); }
  60% { transform: translateY(0) scale(1.06, 0.94); }
  80% { transform: translateY(-5px) scale(1, 1); }
}

.apple {
  display: block;
  width: 22px;
  height: 25px;
  margin: 0 auto -4px;
  position: relative;
  z-index: 1;
}

.apple.popped { animation: applePop 0.6s ease-out forwards; }

@keyframes applePop {
  0% { transform: translate(0, 0) rotate(0deg); opacity: 1; }
  100% { transform: translate(34px, -58px) rotate(230deg); opacity: 0; }
}

.wind-row {
  min-height: 1.4rem;
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 1rem;
}

.wind-row strong { color: var(--text); }

.wind-icon {
  font-size: 1.05rem;
  margin-right: 0.15rem;
  display: inline-block;
  animation: windDrift 2.2s ease-in-out infinite;
}

@keyframes windDrift {
  0%, 100% { transform: translate(0, 0); }
  50% { transform: translate(3px, -2px); }
}

.aim-row { display: flex; justify-content: center; gap: 0.7rem; flex-wrap: wrap; }

.aim-btn {
  font-size: 0.95rem;
  padding: 0.7rem 1.4rem;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent-2), var(--accent));
  box-shadow: 0 8px 22px -10px rgba(255, 107, 169, 0.45);
}

.aim-btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; box-shadow: none; }

.game-msg { min-height: 1.3rem; margin-top: 0.9rem; font-size: 0.95rem; font-weight: 550; }

/* Mystery box shown while the prize pig is "spinning up" */
.roll-result.mystery { border-color: var(--border-strong); }

.mystery-box {
  width: 64px;
  height: 64px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  font-weight: 800;
  color: white;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent-2), var(--accent));
  animation: shake 0.9s ease-in-out infinite;
}

@keyframes shake {
  0%, 100% { transform: rotate(0deg) scale(1); }
  20% { transform: rotate(-8deg) scale(1.04); }
  40% { transform: rotate(7deg) scale(0.98); }
  60% { transform: rotate(-6deg) scale(1.06); }
  80% { transform: rotate(5deg) scale(1); }
}

.roll-result {
  margin: 1.5rem auto 0;
  padding: 1.4rem 1rem 1.1rem;
  max-width: 300px;
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border);
  animation: pop 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.roll-result.revealed { animation: pop 0.45s cubic-bezier(0.34, 1.56, 0.64, 1), revealFlash 0.6s ease-out; }

@keyframes revealFlash {
  0% { filter: brightness(2.2) saturate(1.6); }
  100% { filter: brightness(1) saturate(1); }
}

.pig-icon {
  display: block;
  width: 44px;
  height: 55px;
  margin: 0 auto;
  filter: drop-shadow(0 3px 6px rgba(0, 0, 0, 0.45));
}

.pig-icon svg { width: 100%; height: 100%; display: block; }

.pig-icon-lg { width: 76px; height: 95px; }

.roll-result .name { font-weight: 650; margin-top: 0.6rem; font-size: 1.02rem; }

.roll-result .rarity {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-top: 0.3rem;
}

@keyframes pop {
  from { transform: scale(0.7); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

/* ---------- Inventory ---------- */

.inventory-panel h2 {
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 1rem 0.15rem;
}

.inventory-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(118px, 1fr));
  gap: 0.85rem;
}

.item-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1rem 0.5rem 0.85rem;
  text-align: center;
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.item-card:hover { transform: translateY(-3px); border-color: var(--border-strong); }

.item-card .name { font-size: 0.85rem; font-weight: 600; margin-top: 0.55rem; line-height: 1.3; }

.item-card .qty {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-top: 0.25rem;
}

/* Rarity accents: tinted card borders and glows */
.card-Common { border-color: color-mix(in srgb, var(--common) 25%, transparent); }
.card-Uncommon { border-color: color-mix(in srgb, var(--uncommon) 30%, transparent); }
.card-Rare { border-color: color-mix(in srgb, var(--rare) 35%, transparent); }
.card-Epic {
  border-color: color-mix(in srgb, var(--epic) 45%, transparent);
  box-shadow: 0 0 18px -6px color-mix(in srgb, var(--epic) 45%, transparent);
}
.card-Legendary {
  border-color: color-mix(in srgb, var(--legendary) 55%, transparent);
  box-shadow: 0 0 22px -6px color-mix(in srgb, var(--legendary) 50%, transparent);
}

.card-Epic:hover { box-shadow: 0 0 24px -6px color-mix(in srgb, var(--epic) 60%, transparent); }
.card-Legendary:hover { box-shadow: 0 0 30px -6px color-mix(in srgb, var(--legendary) 65%, transparent); }

.roll-Common { border-color: color-mix(in srgb, var(--common) 35%, transparent); }
.roll-Uncommon { border-color: color-mix(in srgb, var(--uncommon) 40%, transparent); }
.roll-Rare {
  border-color: color-mix(in srgb, var(--rare) 50%, transparent);
  box-shadow: 0 0 26px -8px color-mix(in srgb, var(--rare) 55%, transparent);
}
.roll-Epic {
  border-color: color-mix(in srgb, var(--epic) 55%, transparent);
  box-shadow: 0 0 30px -8px color-mix(in srgb, var(--epic) 60%, transparent);
}
.roll-Legendary {
  border-color: color-mix(in srgb, var(--legendary) 65%, transparent);
  box-shadow: 0 0 36px -8px color-mix(in srgb, var(--legendary) 65%, transparent);
}

.empty-note { color: var(--muted); font-size: 0.9rem; grid-column: 1 / -1; }

.rarity-Common { color: var(--common); }
.rarity-Uncommon { color: var(--uncommon); }
.rarity-Rare { color: var(--rare); }
.rarity-Epic { color: var(--epic); }
.rarity-Legendary { color: var(--legendary); }

@media (max-width: 520px) {
  header { padding: 1rem 1.25rem; }
  main { margin-top: 1.75rem; }
  .game-panel { padding: 1.75rem 1.25rem; }
}
