:root {
  color-scheme: dark;
  --bg: #03050a;
  --panel: rgba(9, 13, 24, 0.8);
  --panel-2: rgba(255,255,255,0.06);
  --border: rgba(255,255,255,0.12);
  --text: #f8fafc;
  --muted: #94a3b8;
  --accent: #ff4d4d;
  --danger: #fb7185;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow: hidden;
}

button, input, select, textarea {
  font: inherit;
}

.app-shell {
  position: relative;
  min-height: 100vh;
  background: radial-gradient(circle at center, #111827 0%, #03050a 70%);
  padding: 24px;
}

.overlay {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at center, rgba(255,255,255,0.05) 0%, transparent 60%);
  pointer-events: none;
}

.hud {
  position: absolute;
  top: 24px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 12px;
  z-index: 3;
}

.hud-pill {
  padding: 10px 14px;
  border-radius: 999px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.12);
  color: var(--text);
  display: flex;
  gap: 8px;
  align-items: center;
}

.hud-pill strong { font-size: 1rem; }

.stage {
  position: relative;
  height: calc(100vh - 160px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 24px;
}

.machine-frame {
  position: relative;
  width: min(86vw, 420px);
  aspect-ratio: 1 / 1.15;
  border-radius: 28px;
  background: linear-gradient(180deg, rgba(255,255,255,0.08), rgba(255,255,255,0.03));
  border: 1px solid rgba(255,255,255,0.14);
  box-shadow: 0 30px 70px rgba(0,0,0,0.45);
  overflow: hidden;
}

.machine-art {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
  pointer-events: none;
  z-index: 0;
}

.capsule-stage {
  position: absolute;
  left: 50%;
  top: 54%;
  width: 170px;
  height: 170px;
  transform: translate(-50%, -50%);
  z-index: 2;
}

.capsule-ball {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  cursor: pointer;
}

.explosion-art {
  position: absolute;
  inset: -10%;
  width: 120%;
  height: 120%;
  object-fit: cover;
  object-position: center;
  opacity: 0;
  transform: scale(0.15);
  pointer-events: none;
  z-index: 3;
}

.machine-frame.is-rolling .capsule-stage {
  animation: shakeMachine 0.7s ease-in-out infinite;
}

.machine-frame.is-rolling .machine-art {
  animation: machineGlow 0.5s ease-in-out infinite alternate;
}

.machine-frame.is-exploding .explosion-art {
  animation: explosionPulse 0.18s ease-out forwards;
}

.machine-frame.is-exploding .machine-art {
  opacity: 0;
  transition: opacity 0.02s linear;
}

@keyframes shakeMachine {
  0%, 100% { transform: translate(-50%, -50%) translateX(0) translateY(0) rotate(0deg); }
  25% { transform: translate(-50%, -50%) translateX(-7px) translateY(-5px) rotate(-3deg); }
  50% { transform: translate(-50%, -50%) translateX(8px) translateY(6px) rotate(3deg); }
  75% { transform: translate(-50%, -50%) translateX(-4px) translateY(-4px) rotate(-2deg); }
}

@keyframes machineGlow {
  0% { filter: brightness(1); }
  100% { filter: brightness(1.08); }
}

@keyframes explosionPulse {
  0% { opacity: 0; transform: scale(0.08); }
  20% { opacity: 1; transform: scale(1.02); }
  60% { opacity: 1; transform: scale(1.12); }
  100% { opacity: 0; transform: scale(1.22); }
}

.result-card {
  position: relative;
  z-index: 2;
  width: min(86vw, 560px);
  border-radius: 24px;
  padding: 18px 20px;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.12);
  box-shadow: 0 24px 50px rgba(0,0,0,0.25);
  backdrop-filter: blur(8px);
}

.result-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 8px;
}

.result-card img {
  display: block;
  width: auto;
  height: auto;
  max-width: min(100%, 420px);
  max-height: min(60vh, 420px);
  object-fit: contain;
  object-position: center;
  border-radius: 18px;
  margin-bottom: 12px;
  padding: 10px;
  background: rgba(255,255,255,0.04);
}

.result-card h2 { margin: 0 0 8px; font-size: 1.2rem; font-weight: 700; }
.result-card p { margin: 0; color: var(--muted); }

.result-card .rarity-uncommon {
  color: #4ade80;
}

.result-card .rarity-epic {
  color: #facc15;
}

.result-card .rarity-rare {
  color: #60a5fa;
}

.result-card .rarity-mythic {
  color: #c084fc;
}

.result-card .rarity-legendary {
  background: linear-gradient(90deg, #ff4d4d 0%, #f59e0b 20%, #facc15 40%, #4ade80 60%, #60a5fa 80%, #c084fc 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: legendaryShimmer 2.4s linear infinite;
}

@keyframes legendaryShimmer {
  0% { filter: hue-rotate(0deg); }
  100% { filter: hue-rotate(360deg); }
}

.controls {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 12px;
  z-index: 4;
}

.secret-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.8s ease;
}

.secret-overlay.is-active {
  opacity: 1;
  pointer-events: auto;
}

.secret-tree {
  width: min(72vw, 420px);
  max-width: 420px;
  height: auto;
  filter: drop-shadow(0 0 35px rgba(255,255,255,0.12));
}

.egg-item {
  position: absolute;
  right: 24px;
  bottom: 24px;
  width: min(24px, 4.5vw);
  height: auto;
  z-index: 5;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.6s ease, transform 0.6s ease;
  transform: translateY(10px);
}

.egg-item.is-visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

@keyframes treeFloat {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-12px) scale(1.02); }
}

.rarity-legend {
  position: absolute;
  left: 24px;
  bottom: 24px;
  z-index: 4;
  padding: 12px 14px;
  border-radius: 16px;
  background: rgba(3, 5, 10, 0.8);
  border: 1px solid rgba(255,255,255,0.12);
  box-shadow: 0 12px 30px rgba(0,0,0,0.24);
  backdrop-filter: blur(8px);
  min-width: 160px;
}

.legend-title {
  font-size: 0.85rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 8px;
}

.legend-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  font-size: 0.95rem;
  padding: 4px 0;
  color: var(--text);
}

.legend-color {
  font-weight: 700;
}

.legend-color.common { color: #f8fafc; }
.legend-color.uncommon { color: #4ade80; }
.legend-color.rare { color: #60a5fa; }
.legend-color.epic { color: #facc15; }
.legend-color.mythic { color: #c084fc; }
.legend-color.legendary {
  background: linear-gradient(90deg, #ff4d4d 0%, #f59e0b 20%, #facc15 40%, #4ade80 60%, #60a5fa 80%, #c084fc 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

button {
  border: 0;
  border-radius: 999px;
  padding: 12px 18px;
  background: linear-gradient(135deg, var(--accent), #ff7a4d);
  color: white;
  cursor: pointer;
  transition: 180ms ease;
}

button:hover { transform: translateY(-1px); }
button.secondary {
  background: rgba(255,255,255,0.08);
  color: var(--text);
  border: 1px solid var(--border);
}
button.danger {
  background: rgba(251, 113, 133, 0.18);
  color: #fecdd3;
  border: 1px solid rgba(251, 113, 133, 0.28);
}
button:disabled { opacity: 0.65; cursor: wait; transform: none; }

.pool-panel {
  position: absolute;
  inset: auto 24px 96px 24px;
  max-height: 58vh;
  overflow: auto;
  padding: 18px;
  border-radius: 20px;
  background: rgba(3, 5, 10, 0.95);
  border: 1px solid rgba(255,255,255,0.12);
  box-shadow: 0 24px 55px rgba(0,0,0,0.38);
  z-index: 5;
  display: none;
}

.pool-panel.open { display: block; }

.compact-form { display: grid; gap: 10px; margin-bottom: 12px; }
.compact-form .row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
input, select, textarea {
  width: 100%;
  border-radius: 12px;
  border: 1px solid var(--border);
  padding: 10px 12px;
  background: rgba(255,255,255,0.06);
  color: var(--text);
}
textarea { min-height: 100px; resize: vertical; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 0.78rem;
  background: rgba(255,255,255,0.08);
  color: var(--muted);
}
.badge.common { background: rgba(255,255,255,0.12); color: #f8fafc; }
.badge.uncommon { background: rgba(34, 197, 94, 0.15); color: #bbf7d0; }
.badge.rare { background: rgba(59, 130, 246, 0.16); color: #bfdbfe; }
.badge.epic { background: rgba(250, 204, 21, 0.14); color: #fde68a; }
.badge.mythic { background: rgba(168, 85, 247, 0.16); color: #e9d5ff; }
.badge.legendary {
  background: linear-gradient(90deg, #f87171, #f59e0b, #22c55e, #3b82f6, #a855f7);
  color: transparent;
  -webkit-background-clip: text;
  background-clip: text;
  font-weight: 700;
}

.pool-list { display: grid; gap: 10px; }
.item-card {
  padding: 12px;
  border-radius: 15px;
  background: rgba(255,255,255,0.05);
}
.item-card .meta { display: flex; justify-content: space-between; gap: 8px; align-items: center; margin-bottom: 6px; }
.item-card img { width: 100%; height: 120px; object-fit: cover; border-radius: 12px; margin-top: 8px; border: 1px solid rgba(255,255,255,0.1); }
.small { font-size: 0.9rem; color: var(--muted); }

@keyframes pulseGlow {
  0%, 100% { opacity: 0.45; transform: scale(0.98); }
  50% { opacity: 0.9; transform: scale(1.03); }
}
@keyframes rollOut {
  0% { transform: translate(0, 0) rotate(0deg); }
  30% { transform: translate(110px, -90px) rotate(-18deg); }
  70% { transform: translate(210px, 0px) rotate(22deg); }
  100% { transform: translate(260px, 60px) rotate(28deg); }
}
@keyframes splitLeft { 0% { transform: rotateY(0deg) translateX(0px); } 100% { transform: rotateY(-55deg) translateX(-14px); } }
@keyframes splitRight { 0% { transform: rotateY(0deg) translateX(0px); } 100% { transform: rotateY(55deg) translateX(14px); } }

@media (max-width: 700px) {
  .app-shell { padding: 12px; }
  .hud { flex-wrap: wrap; justify-content: center; }
  .controls { bottom: 12px; flex-wrap: wrap; }
  .pool-panel { inset: auto 12px 90px 12px; }
  .compact-form .row { grid-template-columns: 1fr; }
}

.result-card img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.08);
}

.result-card h3 { margin: 0 0 6px; }

.result-card p { margin: 4px 0; color: var(--muted); }

.small { font-size: 0.9rem; color: var(--muted); }

button:disabled {
  opacity: 0.6;
  cursor: wait;
  transform: none;
}

@keyframes pulseGlow {
  0%, 100% { opacity: 0.45; transform: scale(0.98); }
  50% { opacity: 0.9; transform: scale(1.03); }
}

@keyframes splitLeft {
  0% { transform: rotateY(0deg) translateX(0px); }
  100% { transform: rotateY(-55deg) translateX(-14px); }
}

@keyframes splitRight {
  0% { transform: rotateY(0deg) translateX(0px); }
  100% { transform: rotateY(55deg) translateX(14px); }
}

@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; }
}

@media (max-width: 700px) {
  .app-shell { padding: 14px; }
  header { flex-direction: column; }
  .stats { min-width: auto; width: 100%; }
  .compact-form .row { grid-template-columns: 1fr; }
  .result-card { grid-template-columns: 1fr; }
}
