/* ─────────────────────────────────────────────────────────────────────────
   GACHA — style.css
   ───────────────────────────────────────────────────────────────────────── */

/* ── Reset & Base ─────────────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --accent:     #cc77ff;
  --gold:       #ffd700;
  --text-light: #e8d8ff;
  --text-dim:   #9980aa;
  --border:     #5a2d82;
}

html, body {
  width: 100%;
  height: 100%;
}

body {
  background-color: #FFF;
  font-family: 'Segoe UI', 'Apple SD Gothic Neo', sans-serif;
  color: var(--text-light);
  overflow: hidden;
}

/* ── Screens ──────────────────────────────────────────────────────────── */
.screen {
  display: none;
  width: 100%;
  height: 100dvh;
  align-items: center;
  justify-content: center;
}
.screen.active {
  display: flex;
}

/* ── Loading screen ───────────────────────────────────────────────────── */
.loading-spinner {
  width: 52px;
  height: 52px;
  border: 4px solid rgba(107, 32, 32, 0.733);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
  margin-bottom: 16px;
}
.loading-text {
  font-size: 0.95rem;
  color: #f0e9f8;
  letter-spacing: 0.08em;
}
#screen-loading {
  flex-direction: column;
  position: relative;
  background-image: linear-gradient(rgba(24, 24, 24, 0.5), rgba(15, 15, 15, 0.5)), url('src/background.png');
  background-size: cover;
  background-position: center top;
  background-repeat: no-repeat;
}

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

/* ── Error screen ─────────────────────────────────────────────────────── */
#screen-error {
  position: relative;
  background-image: linear-gradient(rgba(24, 24, 24, 0.5), rgba(15, 15, 15, 0.5)), url('src/background.png');
  background-size: cover;
  background-position: center top;
  background-repeat: no-repeat;
}

.error-box,
.loading-box {
  text-align: center;
  padding: 40px 32px;
  background: rgba(37, 37, 37, 0.45);
  border: 1px solid rgba(255, 255, 255, 0.25);
  backdrop-filter: blur(2px);
  border-radius: 16px;
  max-width: 400px;
}

.loading-box {
  display: flex;
  flex-direction: column;
  align-items: center;
}
.error-title { font-size: 1.6rem; font-weight: 700; color: #ffffff; margin-bottom: 10px; }
.error-message { font-size: 0.95rem; color: #f0e9f8; line-height: 1.6; }

/* ── Machine screen ───────────────────────────────────────────────────── */
#screen-machine {
  position: relative;
  flex-direction: column;
  padding: 0;
}

/* ── Machine wrapper
     Fills the full viewport. Background image lives here so that
     percentage-positioned children always align with the rendered image. ── */
#machine-wrap {
  position: relative;
  width: 100vw;
  height: 100dvh;
  /* background.png intrinsic size: 1600x900 */
  --bg-rendered-width: max(100vw, calc(100dvh * 16 / 9));
  --bg-rendered-height: calc(var(--bg-rendered-width) * 9 / 16);
  background-image: url('src/background.png');
  background-size: cover;
  background-position: center top;
  background-repeat: no-repeat;
  flex-shrink: 0;
  overflow: hidden;
}

/* ── Poster area ──────────────────────────────────────────────────────── */
#poster-area {
  position: absolute;
  /* size/position locked to rendered background image */
  width: calc(var(--bg-rendered-width) * 320 / 1600);
  aspect-ratio: 1 / 1;
  left: 50%;
  top: calc(var(--bg-rendered-height) * 490 / 1600);
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  mix-blend-mode: multiply;
}

#poster-link {
  display: flex;
  width: 100%;
  height: 100%;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

#poster-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
  transition: opacity 0.25s;
  user-select: none;
  -webkit-user-select: none;
  pointer-events: none; /* let the <a> handle clicks */
}

#poster-link:hover #poster-img {
  opacity: 0.88;
}

/* ── Capsule animation zone ───────────────────────────────────────────── */
#machine-window {
  position: absolute;
  bottom: 6%;
  left:   29%;
  width:  42%;
  height: 22%;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Loading dots */
#loading-dots {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: center;
}
#loading-dots.hidden { display: none; }

#loading-dots span {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: #fff;
  opacity: 0.6;
  animation: dot-bounce 1s ease-in-out infinite;
}
#loading-dots span:nth-child(2) { animation-delay: 0.15s; }
#loading-dots span:nth-child(3) { animation-delay: 0.30s; }

@keyframes dot-bounce {
  0%, 80%, 100% { transform: translateY(0);    opacity: 0.4; }
  40%            { transform: translateY(-8px); opacity: 1;   }
}

/* Capsule */
#capsule {
  position: absolute;
  width: 42px; height: 42px;
  border-radius: 50% 50% 42% 42% / 55% 55% 45% 45%;
  top: -52px;
  left: calc(50% + (var(--bg-rendered-width) * 140 / 1600));
  transform: translateX(-50%);
  box-shadow: inset 0 -4px 8px rgba(0,0,0,0.25), 0 2px 12px rgba(0,0,0,0.4);
}
#capsule.hidden  { display: none; }
#capsule.falling { animation: capsule-fall 1s ease-in forwards; }

@keyframes capsule-fall {
  0%   { top: -52px;             opacity: 1; }
  85%  { top: calc(100% - 42px); opacity: 1; }
  100% { top: calc(100% - 42px); opacity: 0; }
}

/* ── Handle / lever ───────────────────────────────────────────────────── */
#handle-wrap {
  position: absolute;
  top: calc(var(--bg-rendered-height) * 860/ 1600);
  left: 50%;
  width: calc(var(--bg-rendered-height) * 140/ 1600);     /* scales with machine size */
  min-width: 48px;
  transform: translate(-57%, -50%);
  transform-origin: center center;
  cursor: pointer;
  z-index: 2;
}

#handle-img {
  width: 100%;
  display: block;
  pointer-events: none;
  image-rendering: -webkit-optimize-contrast;
  image-rendering: crisp-edges;
}
#handle-wrap.spinning {
  animation: handle-spin 1.5s ease-in-out forwards;
}
@keyframes handle-spin {
  0%   { transform: translate(-57%, -50%) rotate(0deg);   }
  40%  { transform: translate(-57%, -50%) rotate(200deg); }
  70%  { transform: translate(-57%, -50%) rotate(320deg); }
  100% { transform: translate(-57%, -50%) rotate(360deg); }
}

/* ── PULL button + prob bar (inside machine at bottom) ────────────────── */
#pull-area {
  position: absolute;
  bottom: 1%;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  width: 80%;
}

#pull-btn {
  width: min(calc(var(--bg-rendered-width) * 300/ 1600), 72vw);
  aspect-ratio: 350 / 90;
  background: url('src/button.png') center / contain no-repeat;
  color: transparent;
  border: none;
  border-radius: calc(var(--bg-rendered-width) * 30/ 1600);
  cursor: pointer;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
  transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.2s;
  line-height: 0;
  font-size: 0;
}
#pull-btn:not(:disabled):hover  { transform: scale(1.05); box-shadow: 0 8px 16px rgba(0, 0, 0, 0.35); }
#pull-btn:not(:disabled):active { transform: scale(1.01); }
#pull-btn:disabled { opacity: 0.35; cursor: not-allowed; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15); }

/* ── Probability bar ──────────────────────────────────────────────────── */
#prob-bar {
  display: flex;
  gap: 8px 14px;
  flex-wrap: wrap;
  justify-content: center;
}
.prob-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: clamp(0.55rem, 1.3vw, 0.75rem);
  color: var(--text-dim);
}
.prob-dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}
.prob-name { color: var(--text-light); }
.prob-item.lucky .prob-name,
.prob-item.lucky .prob-pct { color: var(--gold); }

/* ── Result modal ─────────────────────────────────────────────────────── */
#modal-result {
  position: fixed;
  inset: 0;
  background: rgba(8, 2, 18, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
  animation: modal-fade-in 0.3s ease;
}
#modal-result.hidden { display: none; }

@keyframes modal-fade-in {
  from { opacity: 0; transform: scale(0.93); }
  to   { opacity: 1; transform: scale(1); }
}

#modal-inner {
  text-align: center;
  max-width: 400px;
  width: 100%;
}

#grade-badge {
  display: inline-block;
  font-size: 0.95rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  padding: 5px 20px;
  border-radius: 20px;
  margin-bottom: 16px;
}
#grade-badge.lucky {
  background: linear-gradient(135deg, #ffd700, #ffaa00);
  color: #2a1000;
  box-shadow: 0 0 20px rgba(255, 200, 0, 0.6);
  animation: badge-pulse 1.5s ease-in-out infinite;
}
#grade-badge.normal {
  background: rgba(80, 60, 100, 0.6);
  color: rgba(220, 200, 255, 0.45);
  border: 1px solid rgba(120, 90, 150, 0.4);
}
@keyframes badge-pulse {
  0%, 100% { box-shadow: 0 0 20px rgba(255, 200, 0, 0.6); }
  50%       { box-shadow: 0 0 36px rgba(255, 220, 0, 0.95); }
}

/* Result image */
#result-image {
  display: block;
  width: min(100%, 400px);
  aspect-ratio: 1 / 1;
  object-fit: contain;
  margin-bottom: 32px;
  animation: icon-pop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: 0 24px 64px rgba(0,0,0,0.6), 0 0 0 1px rgba(150,80,220,0.15);
}

#result-image:hover {
  transform: rotate(4deg);
  transition: transform 0.3s ease;
}
@keyframes icon-pop {
  from { transform: scale(0.4); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}

#item-name {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-light);
  margin-bottom: 22px;
  letter-spacing: 0.04em;
}

#result-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

#download-btn,
#pull-again-btn {
  width: 100%;
  padding: 12px 16px;
  background: #C22012;
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 0.1em;
  text-decoration: none;
  text-align: center;
  transition: opacity 0.15s, transform 0.1s;
}
#pull-again-btn {
  background: #71C9CD;
  color: #fff;
}
#download-btn:hover,
#pull-again-btn:hover { opacity: 0.85; transform: translateY(-1px); }

/* ── Utility ──────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
