:root {
  --bg: #ffe9c8;
  --ink: #4a3f63;
  --ink-soft: rgba(74, 63, 99, 0.62);
  --paper: rgba(255, 248, 234, 0.9);
  --paper-solid: #fff8ea;
  --paper-strong: #fffdf6;
  --line: rgba(96, 76, 132, 0.28);
  --shadow: rgba(122, 92, 160, 0.22);
  --accent: #ff9d5c;
  --accent-2: #59bfe8;
  --gold: #f0b93c;
  --radius: 22px;
  --font: "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

#app { position: fixed; inset: 0; }

#scene { position: absolute; inset: 0; display: block; width: 100%; height: 100%; }

#flash {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 50% 48%, #fffdf2 0%, #fff3d8 45%, rgba(255, 236, 200, 0.5) 100%);
  opacity: 0;
  pointer-events: none;
  z-index: 6;
}

#vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse at 50% 46%, rgba(255, 255, 255, 0) 52%, rgba(112, 86, 150, 0.16) 100%),
    linear-gradient(to bottom, rgba(255, 252, 240, 0.34), rgba(255, 252, 240, 0) 20%, rgba(255, 252, 240, 0) 76%, rgba(255, 246, 226, 0.4));
  z-index: 4;
}

.hud { position: absolute; left: 0; right: 0; z-index: 8; pointer-events: none; }
.hud-top { top: 0; display: flex; align-items: flex-start; justify-content: space-between; padding: 20px 24px; gap: 16px; }
.hud-bottom { bottom: 0; display: flex; justify-content: center; padding: 0 22px 24px; }
.hud button, .hud .panel { pointer-events: auto; }

.brand { display: flex; align-items: center; gap: 13px; }
.brand-mark {
  width: 46px; height: 46px; border-radius: 15px;
  background:
    radial-gradient(circle at 32% 26%, rgba(255, 255, 255, 0.95), rgba(255, 255, 255, 0) 44%),
    linear-gradient(140deg, #ffd07a, #ff9d6e 52%, #ff8fb6);
  border: 2px solid rgba(74, 63, 99, 0.75);
  box-shadow: 3px 4px 0 rgba(122, 92, 160, 0.28);
  animation: floaty 5.5s ease-in-out infinite;
}
.brand-text h1 {
  margin: 0;
  font-size: 22px;
  letter-spacing: 0.16em;
  font-weight: 800;
  color: #fff8ea;
  text-shadow:
    0 2px 0 rgba(74, 63, 99, 0.55),
    0 0 14px rgba(74, 63, 99, 0.35);
}
.brand-text p {
  margin: 4px 0 0;
  font-size: 10.5px;
  letter-spacing: 0.32em;
  color: rgba(255, 250, 236, 0.9);
  text-shadow: 0 1px 0 rgba(74, 63, 99, 0.5);
}

.hud-actions { display: flex; gap: 10px; }

.ghost-btn {
  appearance: none;
  border: 2px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.1em;
  padding: 9px 15px;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 2px 3px 0 var(--shadow);
  transition: transform 0.16s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.16s ease, background 0.2s ease;
}
.ghost-btn:hover { transform: translate(-1px, -2px); box-shadow: 4px 6px 0 var(--shadow); background: var(--paper-strong); }
.ghost-btn:active { transform: translate(1px, 1px); box-shadow: 1px 1px 0 var(--shadow); }
.ghost-btn.is-off { color: rgba(74, 63, 99, 0.45); box-shadow: 2px 3px 0 rgba(122, 92, 160, 0.12); }
.ghost-danger:hover { background: #ffe7e0; }
.ghost-count { color: var(--accent); margin-left: 3px; font-variant-numeric: tabular-nums; }

.stats {
  position: absolute;
  left: 24px;
  top: 92px;
  z-index: 8;
  display: flex;
  flex-direction: column;
  gap: 9px;
  pointer-events: none;
}
.stat {
  min-width: 126px;
  padding: 9px 14px;
  border-radius: 16px;
  background: var(--paper);
  border: 2px solid var(--line);
  box-shadow: 2px 3px 0 var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.stat span { font-size: 18px; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: 0.03em; }
.stat small { font-size: 10.5px; letter-spacing: 0.2em; color: var(--ink-soft); font-weight: 600; }

.banner {
  position: absolute;
  top: 15%;
  left: 0;
  right: 0;
  z-index: 9;
  display: flex;
  justify-content: center;
  pointer-events: none;
  opacity: 0;
}
.banner-text {
  --rarity: #93a7c4;
  --rarity-glow: #7fd4ff;
  font-size: clamp(38px, 8vw, 84px);
  font-weight: 800;
  letter-spacing: 0.1em;
  color: var(--rarity);
  white-space: nowrap;
  text-shadow:
    3px 3px 0 #fffaf0,
    -3px 3px 0 #fffaf0,
    3px -3px 0 #fffaf0,
    -3px -3px 0 #fffaf0,
    0 6px 0 rgba(74, 63, 99, 0.35),
    0 0 30px var(--rarity-glow);
}
.banner.is-show { animation: bannerIn 2.2s cubic-bezier(0.16, 1, 0.3, 1) forwards; }
.banner.is-show .banner-text { animation: bannerText 2.2s cubic-bezier(0.16, 1, 0.3, 1) forwards; }

.toast {
  --toast-accent: #ffb066;
  position: absolute;
  left: 50%;
  top: 12%;
  transform: translate(-50%, -14px);
  z-index: 10;
  padding: 11px 20px;
  border-radius: 999px;
  background: var(--paper-solid);
  border: 2px solid var(--toast-accent);
  box-shadow: 3px 5px 0 rgba(122, 92, 160, 0.22), 0 0 26px color-mix(in srgb, var(--toast-accent) 35%, transparent);
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.06em;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.32s ease, transform 0.32s cubic-bezier(0.16, 1, 0.3, 1);
  max-width: min(80vw, 540px);
  text-align: center;
}
.toast.is-show { opacity: 1; transform: translate(-50%, 0); }

.panel {
  width: min(680px, 94vw);
  border-radius: var(--radius);
  background: var(--paper);
  border: 2px solid var(--line);
  box-shadow: 4px 6px 0 var(--shadow);
  padding: 15px 20px;
  backdrop-filter: blur(6px);
}
.panel-idle { display: flex; flex-direction: column; align-items: center; gap: 9px; }

.open-btn {
  position: relative;
  appearance: none;
  border: 2px solid rgba(74, 63, 99, 0.85);
  cursor: pointer;
  padding: 15px 52px;
  border-radius: 999px;
  font-family: inherit;
  font-size: 17px;
  letter-spacing: 0.4em;
  font-weight: 800;
  color: #46304f;
  background: linear-gradient(135deg, #ffe08a, #ffb066 55%, #ff9ec4);
  box-shadow: 3px 5px 0 rgba(122, 92, 160, 0.35), inset 0 -3px 0 rgba(74, 63, 99, 0.18);
  transition: transform 0.16s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.18s ease;
  overflow: hidden;
}
.open-btn:hover { transform: translate(-1px, -2px); box-shadow: 5px 8px 0 rgba(122, 92, 160, 0.35), inset 0 -3px 0 rgba(74, 63, 99, 0.18); }
.open-btn:active { transform: translate(2px, 2px); box-shadow: 1px 2px 0 rgba(122, 92, 160, 0.35); }
.open-btn-label { position: relative; z-index: 2; padding-left: 0.4em; }
.open-btn-glow {
  position: absolute;
  inset: -40%;
  background: conic-gradient(from 0deg, rgba(255, 255, 255, 0), rgba(255, 255, 255, 0.75), rgba(255, 255, 255, 0));
  animation: spin 4.2s linear infinite;
  opacity: 0.5;
  z-index: 1;
}

.hint { margin: 0; font-size: 11.5px; letter-spacing: 0.1em; color: var(--ink-soft); font-weight: 600; }

.panel-result { display: flex; align-items: center; justify-content: space-between; gap: 18px; animation: slideUp 0.45s cubic-bezier(0.16, 1, 0.3, 1); }
.result-info { display: flex; align-items: center; gap: 14px; min-width: 0; }
.result-rarity {
  --rarity: #93a7c4;
  --rarity-glow: #7fd4ff;
  font-size: 12.5px;
  font-weight: 800;
  letter-spacing: 0.14em;
  padding: 7px 13px;
  border-radius: 999px;
  color: #3d3350;
  background: linear-gradient(135deg, var(--rarity-glow), var(--rarity));
  border: 2px solid rgba(74, 63, 99, 0.55);
  box-shadow: 2px 3px 0 rgba(122, 92, 160, 0.22);
  white-space: nowrap;
}
.result-name { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.result-name strong { font-size: 19px; letter-spacing: 0.08em; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.result-name small { font-size: 11px; color: var(--ink-soft); letter-spacing: 0.08em; font-weight: 600; }
.result-tag {
  --rarity: #93a7c4;
  font-size: 11.5px;
  font-weight: 800;
  letter-spacing: 0.14em;
  padding: 6px 11px;
  border-radius: 12px;
  border: 2px solid var(--rarity);
  color: var(--rarity);
  background: rgba(255, 255, 255, 0.7);
  white-space: nowrap;
  animation: pop 0.55s cubic-bezier(0.16, 1, 0.3, 1);
}
.result-tag.is-dupe { color: var(--ink-soft); border-color: rgba(74, 63, 99, 0.3); animation: none; }

.collect-btn {
  appearance: none;
  border: 2px solid rgba(74, 63, 99, 0.8);
  background: linear-gradient(135deg, #9fe8b8, #8fd8ff);
  color: #33415a;
  font-family: inherit;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.16em;
  padding: 13px 24px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: 3px 4px 0 rgba(122, 92, 160, 0.3), inset 0 -3px 0 rgba(74, 63, 99, 0.15);
  transition: transform 0.16s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.16s ease;
}
.collect-btn:hover { transform: translate(-1px, -2px); box-shadow: 5px 7px 0 rgba(122, 92, 160, 0.3), inset 0 -3px 0 rgba(74, 63, 99, 0.15); }
.collect-btn:active { transform: translate(2px, 2px); box-shadow: 1px 2px 0 rgba(122, 92, 160, 0.3); }

.album {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(520px, 94vw);
  z-index: 12;
  background: linear-gradient(180deg, #fff8ea, #ffeccd);
  border-left: 2px solid var(--line);
  box-shadow: -18px 0 40px rgba(122, 92, 160, 0.25);
  padding: 24px 22px 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  transform: translateX(102%);
  transition: transform 0.36s cubic-bezier(0.16, 1, 0.3, 1);
  overflow: hidden;
}
.album.is-open { transform: translateX(0); }
.album-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.album-head h2 { margin: 0; font-size: 20px; letter-spacing: 0.22em; font-weight: 800; }
.album-sub { margin: 7px 0 0; font-size: 11px; color: var(--ink-soft); letter-spacing: 0.06em; font-weight: 600; }
.album-head-actions { display: flex; gap: 8px; }

.album-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(108px, 1fr));
  gap: 12px;
  overflow-y: auto;
  padding: 4px 6px 20px 4px;
  scrollbar-width: thin;
  scrollbar-color: rgba(122, 92, 160, 0.35) transparent;
}
.album-grid::-webkit-scrollbar { width: 8px; }
.album-grid::-webkit-scrollbar-thumb { background: rgba(122, 92, 160, 0.28); border-radius: 99px; }

.album-cell {
  --rarity: #93a7c4;
  --rarity-glow: #7fd4ff;
  appearance: none;
  border: none;
  background: none;
  padding: 0;
  cursor: default;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  font-family: inherit;
  color: var(--ink);
  transition: transform 0.18s cubic-bezier(0.16, 1, 0.3, 1);
}
.album-cell.is-owned { cursor: pointer; }
.album-cell.is-owned:hover { transform: translateY(-4px); }
.album-thumb { width: 100%; aspect-ratio: 1 / 1; border-radius: 15px; display: block; }
.album-name { font-size: 12px; letter-spacing: 0.06em; font-weight: 700; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.album-meta { font-size: 10px; letter-spacing: 0.12em; color: var(--rarity); opacity: 0.95; font-weight: 700; }
.album-cell.is-locked .album-name { color: rgba(74, 63, 99, 0.35); }

.loading {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  background: linear-gradient(180deg, #bfe4ff, #ffe6bc 62%, #ffd9a8);
  transition: opacity 0.6s ease;
}
.loading.is-hidden { opacity: 0; pointer-events: none; }
.loading p { margin: 0; font-size: 12px; letter-spacing: 0.28em; color: rgba(74, 63, 99, 0.72); font-weight: 700; }
.loading-ring {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  border: 3px solid rgba(74, 63, 99, 0.16);
  border-top-color: #ff9d6e;
  border-right-color: #ffd166;
  animation: spin 1s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes floaty { 0%, 100% { transform: translateY(0) rotate(-2deg); } 50% { transform: translateY(-5px) rotate(2deg); } }
@keyframes pop { 0% { transform: scale(0.5); opacity: 0; } 60% { transform: scale(1.08); opacity: 1; } 100% { transform: scale(1); } }
@keyframes slideUp { from { transform: translateY(14px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
@keyframes bannerIn { 0% { opacity: 0; } 12% { opacity: 1; } 78% { opacity: 1; } 100% { opacity: 0; } }
@keyframes bannerText {
  0% { transform: scale(0.6) translateY(11px); opacity: 0; }
  18% { transform: scale(1.06) translateY(0); opacity: 1; }
  30% { transform: scale(1); opacity: 1; }
  76% { transform: scale(1.02); opacity: 1; }
  100% { transform: scale(1.14); opacity: 0; }
}

@media (max-width: 720px) {
  .stats { left: 13px; top: 86px; gap: 7px; }
  .stat { min-width: 100px; padding: 7px 11px; }
  .stat span { font-size: 16px; }
  .hud-top { padding: 14px 13px; }
  .brand-mark { width: 40px; height: 40px; }
  .brand-text h1 { font-size: 17px; }
  .brand-text p { font-size: 9px; letter-spacing: 0.18em; }
  .hud-bottom { padding: 0 12px 16px; }
  .panel { padding: 13px; }
  .panel-result { flex-direction: column; align-items: stretch; }
  .collect-btn { width: 100%; }
  .open-btn { padding: 14px 38px; font-size: 15px; }
  .album { padding: 20px 16px 22px; }
}
