:root {
  color-scheme: light;
  --ink: #16130f;
  --paper: #fffaf0;
  --gold: #f5b91f;
  --gold-2: #ffd96a;
  --black: #111;
  --red: #e53f3f;
  --mint: #2bc4a4;
  --line: rgba(22, 19, 15, 0.16);
  --shadow: 0 18px 50px rgba(17, 17, 17, 0.22);
  font-family: Inter, "Hiragino Kaku Gothic ProN", "Yu Gothic", Meiryo, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: #f6b51f;
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(255, 248, 224, 0.28), rgba(246, 181, 31, 0.12) 48%, rgba(22, 19, 15, 0.58)),
    url("assets/gacha-bg.png") center center / cover fixed;
}

button {
  min-height: 48px;
  border: 0;
  border-radius: 16px;
  color: inherit;
  font: inherit;
  font-weight: 900;
  letter-spacing: 0;
  touch-action: manipulation;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  filter: grayscale(0.5);
  opacity: 0.6;
}

.app-shell {
  width: min(1180px, 100%);
  min-height: 100svh;
  margin: 0 auto;
  padding: max(14px, env(safe-area-inset-top)) 14px max(22px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(320px, 0.9fr);
  gap: 14px;
  align-items: start;
}

.panel {
  border: 2px solid rgba(255, 255, 255, 0.5);
  background: rgba(255, 250, 240, 0.86);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.stage {
  grid-column: 1 / -1;
  position: relative;
  min-height: calc(100svh - 28px);
  padding: 18px;
  display: grid;
  grid-template-rows: auto auto auto auto;
  align-items: center;
  align-content: start;
  overflow: hidden;
}

.stage::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 50% 54%, rgba(255, 255, 255, 0.52), transparent 31%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.14), transparent 42%, rgba(0, 0, 0, 0.22));
}

.topbar,
.wallet,
.machine,
.actions,
.status {
  position: relative;
}

.topbar,
.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.topbar {
  width: min(720px, 100%);
  margin: 0 auto;
  padding: 8px 12px;
  border: 1px solid rgba(255, 255, 255, 0.58);
  border-radius: 18px;
  background: rgba(255, 250, 240, 0.76);
  box-shadow: 0 12px 34px rgba(17, 17, 17, 0.16);
  backdrop-filter: blur(12px);
}

.kicker {
  margin: 0 0 4px;
  color: #6c4710;
  font-size: 0.75rem;
  font-weight: 900;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: clamp(2rem, 5vw, 3rem);
  line-height: 1;
  word-break: keep-all;
}

h2 {
  font-size: 1.1rem;
}

.icon-button {
  width: 50px;
  min-width: 50px;
  border-radius: 999px;
  background: var(--black);
  color: #fff;
}

.wallet {
  width: fit-content;
  margin: 8px auto 0;
  padding: 9px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-radius: 999px;
  background: #111;
  color: #fff;
}

.wallet strong {
  color: var(--gold-2);
  font-size: 1.15rem;
}

.machine {
  width: min(280px, 82vw, 39svh);
  margin: clamp(10px, 3svh, 28px) auto 0;
  display: grid;
  justify-items: center;
  filter: drop-shadow(0 26px 36px rgba(0, 0, 0, 0.42));
}

.machine::after {
  content: "";
  width: 78%;
  height: clamp(44px, 8svh, 72px);
  margin-top: -10px;
  border: 8px solid #111;
  border-radius: 20px 20px 34px 34px;
  background:
    repeating-linear-gradient(114deg, #111 0 22px, var(--gold) 22px 46px),
    linear-gradient(#ffd96a, #c57d09);
  box-shadow: inset 0 12px 0 rgba(255, 255, 255, 0.28), 0 14px 0 #111;
}

.machine-glass {
  position: relative;
  width: 100%;
  aspect-ratio: 0.84;
  display: grid;
  place-items: center;
  border: 10px solid #171717;
  border-radius: 46% 46% 26% 26%;
  background:
    radial-gradient(circle at 34% 24%, rgba(255, 255, 255, 0.9), transparent 13%),
    radial-gradient(circle at 50% 42%, rgba(255, 255, 255, 0.56), rgba(255, 234, 161, 0.34) 54%, rgba(17, 17, 17, 0.9) 55%),
    linear-gradient(90deg, #111 0 10%, var(--gold) 10% 90%, #111 90%);
  box-shadow: inset 0 10px 26px rgba(255, 255, 255, 0.8), inset 0 -16px 28px rgba(0, 0, 0, 0.28), 0 18px 38px rgba(0, 0, 0, 0.28);
  overflow: hidden;
}

.machine.is-spinning .machine-glass {
  animation: rumble 0.48s linear infinite;
}

.capsule-field {
  position: relative;
  z-index: 2;
  width: 78%;
  aspect-ratio: 1;
  border-radius: 999px;
  background:
    radial-gradient(circle at 38% 24%, rgba(255, 255, 255, 0.9), transparent 18%),
    radial-gradient(circle, rgba(255, 255, 255, 0.42), rgba(255, 255, 255, 0.12));
  box-shadow: inset 0 12px 28px rgba(255, 255, 255, 0.55), inset 0 -18px 24px rgba(0, 0, 0, 0.14);
}

.shine {
  position: absolute;
  inset: -20%;
  background: linear-gradient(115deg, transparent 35%, rgba(255, 255, 255, 0.58) 47%, transparent 58%);
  transform: translateX(-68%);
}

.machine.is-spinning .shine {
  animation: sweep 0.82s ease-in-out infinite;
}

.capsule {
  position: absolute;
  width: 84px;
  aspect-ratio: 1.55;
  border: 4px solid rgba(17, 17, 17, 0.75);
  border-radius: 999px;
  background: linear-gradient(90deg, var(--gold) 0 50%, #fff 50%);
  opacity: 0.9;
}

.c1 { top: 13%; left: 9%; transform: rotate(-22deg); }
.c2 { top: 19%; right: 8%; transform: rotate(18deg); }
.c3 { bottom: 12%; left: 16%; transform: rotate(12deg); }

.capsule.big {
  width: clamp(74px, 18vw, 114px);
  border-width: 5px;
  box-shadow: 0 12px 16px rgba(0, 0, 0, 0.2);
}

.capsule.big.a { top: 10%; left: 7%; transform: rotate(-26deg); }
.capsule.big.b { top: 14%; right: 8%; transform: rotate(24deg); background: linear-gradient(90deg, #111 0 50%, #fff 50%); }
.capsule.big.c { top: 42%; left: 21%; transform: rotate(8deg); background: linear-gradient(90deg, var(--gold) 0 50%, #111 50%); }
.capsule.big.d { right: 16%; bottom: 14%; transform: rotate(-16deg); }
.capsule.big.e { left: 10%; bottom: 9%; transform: rotate(22deg); background: linear-gradient(90deg, #fff 0 50%, var(--gold) 50%); }

.knob {
  width: clamp(88px, 34%, 132px);
  margin-top: -28px;
  aspect-ratio: 1;
  min-height: auto;
  border: 8px solid #111;
  border-radius: 999px;
  background: radial-gradient(circle at 34% 30%, #fff7c8, var(--gold) 40%, #c57d09);
  box-shadow: 0 16px 0 #111, 0 24px 34px rgba(0, 0, 0, 0.3);
  z-index: 3;
}

.knob span {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
}

.machine.is-spinning .knob span {
  animation: spin 0.66s linear infinite;
}

.actions {
  width: min(520px, 100%);
  margin: 8px auto 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.primary,
.secondary {
  box-shadow: 0 8px 0 #111;
}

.primary {
  background: #111;
  color: #fff;
}

.secondary {
  background: var(--gold);
}

.wide {
  width: 100%;
}

.status {
  width: min(520px, 100%);
  min-height: 42px;
  margin: 16px auto 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.7);
  text-align: center;
  font-weight: 800;
}

.panel {
  border-radius: 20px;
  padding: 14px;
}

.result-panel {
  align-self: stretch;
}

.ghost {
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.72);
  font-size: 0.85rem;
}

.danger {
  color: #9f1d1d;
}

.result-card {
  margin-top: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.9), rgba(255, 221, 104, 0.32)),
    repeating-linear-gradient(-24deg, transparent 0 16px, rgba(17, 17, 17, 0.07) 16px 22px);
  text-align: center;
  overflow: hidden;
}

.result-card.pop {
  animation: pop 0.42s ease-out;
}

.rarity-badge {
  width: fit-content;
  margin: 0 auto 10px;
  padding: 6px 12px;
  border-radius: 999px;
  background: #111;
  color: #fff;
  font-size: 0.78rem;
  font-weight: 900;
}

.result-art {
  width: min(210px, 70%);
  aspect-ratio: 1;
  margin: 0 auto 10px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: radial-gradient(circle, #fff 0 48%, rgba(245, 185, 31, 0.7) 49% 70%, #111 71%);
  overflow: hidden;
}

.result-art img {
  width: 78%;
  height: 92%;
  object-fit: contain;
  object-position: top center;
  border-radius: 28px;
}

.result-card h3 {
  font-size: 1.3rem;
}

.result-card p {
  margin-top: 6px;
  color: #57462b;
  font-size: 0.9rem;
  font-weight: 700;
}

.collection {
  margin-top: 12px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 9px;
}

.unit {
  min-width: 0;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.72);
  text-align: center;
}

.unit.locked {
  filter: grayscale(1);
  opacity: 0.52;
}

.unit img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: contain;
  object-position: top center;
  border-radius: 12px;
  background: #fff;
}

.unit b,
.unit span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.unit b {
  margin-top: 4px;
  font-size: 0.78rem;
}

.unit span {
  color: #6d562e;
  font-size: 0.7rem;
  font-weight: 900;
}

.rates {
  margin-top: 12px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.rates span {
  padding: 10px 6px;
  border-radius: 12px;
  background: #111;
  color: #fff;
  text-align: center;
  font-size: 0.78rem;
  font-weight: 900;
}

.modal[hidden] {
  display: none;
}

.modal {
  position: fixed;
  z-index: 10;
  inset: 0;
  display: grid;
  place-items: end center;
  padding: 14px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.52);
}

.modal-sheet {
  position: relative;
  width: min(560px, 100%);
  max-height: min(720px, 88svh);
  padding: 14px;
  border-radius: 22px;
  background: var(--paper);
  box-shadow: var(--shadow);
  overflow: auto;
}

.multi-results {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.mini-result {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  text-align: center;
}

.mini-result img {
  width: 72px;
  height: 72px;
  object-fit: contain;
  object-position: top center;
  border-radius: 16px;
  background: #fff;
}

.mini-result b,
.mini-result span {
  display: block;
  overflow-wrap: anywhere;
}

.mini-result b {
  font-size: 0.82rem;
}

.mini-result span {
  font-size: 0.72rem;
  font-weight: 900;
}

[data-rarity="UR"] { --rarity: #dd34ff; }
[data-rarity="SSR"] { --rarity: #ffb000; }
[data-rarity="SR"] { --rarity: #2bc4a4; }
[data-rarity="R"] { --rarity: #565f70; }

[data-rarity] .rarity-badge,
.mini-result[data-rarity] span,
.unit[data-rarity] span {
  color: #fff;
  background: var(--rarity);
}

.unit[data-rarity] span {
  width: fit-content;
  margin: 4px auto 0;
  padding: 2px 7px;
  border-radius: 999px;
}

@keyframes rumble {
  0%, 100% { transform: translate3d(0, 0, 0) rotate(0); }
  25% { transform: translate3d(2px, -1px, 0) rotate(0.5deg); }
  50% { transform: translate3d(-2px, 1px, 0) rotate(-0.5deg); }
  75% { transform: translate3d(1px, 2px, 0) rotate(0.35deg); }
}

@keyframes sweep {
  to { transform: translateX(68%); }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes pop {
  0% { transform: scale(0.84); opacity: 0.4; }
  72% { transform: scale(1.05); opacity: 1; }
  100% { transform: scale(1); }
}

@media (max-width: 760px) {
  body {
    background-attachment: scroll;
  }

  .app-shell {
    grid-template-columns: 1fr;
    gap: 12px;
    padding-inline: 10px;
  }

  .stage {
    position: relative;
    top: 0;
    min-height: calc(100svh - 20px);
    padding: 10px;
  }

  .machine {
    width: min(300px, 86vw);
    margin-top: 12px;
  }

  .actions {
    position: sticky;
    bottom: max(10px, env(safe-area-inset-bottom));
    z-index: 5;
    margin-top: 18px;
  }

  .collection {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 7px;
  }

  .unit {
    padding: 5px;
    border-radius: 11px;
  }

  .unit b {
    font-size: 0.68rem;
  }

  .rates {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 380px) {
  .actions {
    grid-template-columns: 1fr;
  }

  .collection {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
  }
}
