:root {
  --pink: #ffd9ec;
  --pink-deep: #f2a7cd;
  --ice: #bfe0ff;
  --ice-deep: #8fbef2;
  --lav: #cbb7ec;
  --plum: #241b3a;
  --ink: #2a2140;
  --white: #fff;
  --glass: rgba(255, 255, 255, 0.14);
  --glass-line: rgba(255, 255, 255, 0.38);
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { min-height: 100%; }
body {
  font-family: 'Quicksand', sans-serif;
  color: #fff;
  background: linear-gradient(168deg, #1d1533 0%, #3d2a5c 30%, #6b4a86 55%, #9d8fd0 78%, #ffd9ec 115%);
  background-attachment: fixed;
  min-height: 100vh;
  overflow-x: hidden;
  padding-bottom: 96px;
}

/* fairy sky: glows + twinkling stars */
.sky { position: fixed; inset: 0; z-index: -1; pointer-events: none; }
.glow { position: absolute; border-radius: 50%; filter: blur(70px); opacity: 0.55; }
.g1 { width: 55vw; height: 55vw; background: #ffd9ec; top: -12vw; right: -14vw; }
.g2 { width: 60vw; height: 60vw; background: #8fbef2; bottom: -18vw; left: -16vw; opacity: 0.4; }
.g3 { width: 34vw; height: 34vw; background: #cbb7ec; top: 38%; left: 30%; opacity: 0.35; }
.stars {
  position: absolute; inset: 0;
  background-image:
    radial-gradient(1.6px 1.6px at 12% 18%, #fff 60%, transparent),
    radial-gradient(1.2px 1.2px at 78% 8%, #ffe6f4 60%, transparent),
    radial-gradient(2px 2px at 90% 42%, #fff 60%, transparent),
    radial-gradient(1.3px 1.3px at 28% 48%, #dff0ff 60%, transparent),
    radial-gradient(1.7px 1.7px at 58% 26%, #fff 60%, transparent),
    radial-gradient(1.1px 1.1px at 8% 68%, #fff 60%, transparent),
    radial-gradient(1.5px 1.5px at 44% 78%, #ffe6f4 60%, transparent),
    radial-gradient(1.2px 1.2px at 84% 84%, #fff 60%, transparent);
  animation: twinkle 4.5s ease-in-out infinite alternate;
}
.stars.s2 {
  background-image:
    radial-gradient(1px 1px at 22% 30%, #fff 60%, transparent),
    radial-gradient(1.4px 1.4px at 66% 14%, #dff0ff 60%, transparent),
    radial-gradient(1px 1px at 38% 62%, #fff 60%, transparent),
    radial-gradient(1.6px 1.6px at 92% 62%, #ffe6f4 60%, transparent),
    radial-gradient(1.1px 1.1px at 16% 88%, #fff 60%, transparent);
  animation-delay: 2.2s;
}
@keyframes twinkle { from { opacity: 0.5; } to { opacity: 1; } }

.glass {
  background: var(--glass);
  border: 1px solid var(--glass-line);
  border-radius: 24px;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 10px 34px rgba(29, 21, 51, 0.35);
}

.appbar {
  display: flex; justify-content: center; padding: 18px 16px 6px;
}
.brand {
  font-family: 'Cormorant Garamond', serif;
  font-size: 26px; letter-spacing: 0.12em; font-weight: 600;
  text-shadow: 0 0 18px rgba(255, 217, 236, 0.55);
}
.moon { color: var(--pink); }
.beta {
  font-family: 'Quicksand', sans-serif; font-size: 9px; letter-spacing: 0.18em;
  vertical-align: super; color: var(--ice); text-transform: uppercase;
}

main { max-width: 440px; margin: 0 auto; padding: 10px 16px 0; }
.tab { display: none; }
.tab.active { display: block; animation: fadein 0.35s ease; }
@keyframes fadein { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.stage { position: relative; overflow: hidden; aspect-ratio: 2 / 2.6; }
.stage img { width: 100%; height: 100%; object-fit: cover; object-position: top; display: block; transition: opacity 0.35s ease; }
.avatar-stage { aspect-ratio: 2 / 2.4; }
.chip {
  position: absolute; left: 12px; bottom: 12px;
  background: rgba(29, 21, 51, 0.72); color: var(--pink);
  border-radius: 999px; padding: 5px 12px; font-size: 11px; letter-spacing: 0.06em;
}
.burst {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-size: 90px; color: #fff; text-shadow: 0 0 24px var(--pink), 0 0 60px var(--ice);
  animation: burst 0.7s ease forwards; pointer-events: none;
}
@keyframes burst { 0% { transform: scale(0.2) rotate(0deg); opacity: 0; } 40% { opacity: 1; } 100% { transform: scale(1.6) rotate(40deg); opacity: 0; } }

.rail-wrap { margin-top: 14px; }
.rail-label { font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; color: rgba(255,255,255,0.75); margin-bottom: 8px; }
.rail { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 6px; scrollbar-width: none; }
.rail::-webkit-scrollbar { display: none; }
.piece {
  flex: 0 0 auto; width: 84px; height: 84px; border-radius: 18px; overflow: hidden;
  background: #fff; border: 2px solid transparent; cursor: pointer; padding: 0;
  transition: transform 0.15s ease, border-color 0.15s ease;
}
.piece img { width: 100%; height: 100%; object-fit: cover; display: block; }
.piece:active { transform: scale(0.93); }
.piece.selected { border-color: var(--pink); box-shadow: 0 0 16px rgba(255, 217, 236, 0.7); }
.add-tile {
  flex: 0 0 auto; width: 84px; height: 84px; border-radius: 18px;
  border: 2px dashed rgba(255,255,255,0.55); background: transparent; color: rgba(255,255,255,0.85);
  font-family: inherit; font-size: 10.5px; line-height: 1.35; cursor: pointer;
}

.two-slots { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.slot {
  aspect-ratio: 3 / 3.4; color: #fff; font-family: inherit; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  border-style: dashed; overflow: hidden; position: relative; padding: 8px;
}
.slot.filled { border-style: solid; }
.slot img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.slot .veil { position: absolute; inset: auto 0 0 0; padding: 8px; background: rgba(29,21,51,0.55); font-size: 11px; }
.slot-plus { font-size: 26px; color: var(--pink); }
.slot-label { font-weight: 600; font-size: 14px; }
.slot-hint { font-size: 10px; color: rgba(255,255,255,0.7); }

.linkrow { display: flex; gap: 8px; margin-top: 12px; padding: 8px 8px 8px 16px; border-radius: 999px; align-items: center; }
.linkrow input {
  flex: 1; background: none; border: none; outline: none; color: #fff;
  font-family: inherit; font-size: 13px; min-width: 0;
}
.linkrow input::placeholder { color: rgba(255,255,255,0.6); }
.linkrow button {
  background: var(--ice); color: var(--ink); border: none; border-radius: 999px;
  padding: 8px 14px; font-family: inherit; font-weight: 600; font-size: 12px; cursor: pointer;
}

.cta {
  width: 100%; margin-top: 14px; border: none; cursor: pointer;
  background: linear-gradient(100deg, var(--pink) 0%, var(--ice) 100%);
  color: var(--ink); font-family: inherit; font-weight: 700; font-size: 15px;
  letter-spacing: 0.04em; border-radius: 999px; padding: 15px;
  box-shadow: 0 6px 24px rgba(255, 217, 236, 0.45);
  transition: transform 0.15s ease, opacity 0.2s;
}
.cta:active { transform: scale(0.97); }
.cta:disabled { opacity: 0.45; box-shadow: none; cursor: not-allowed; }
.quota { text-align: center; font-size: 11px; color: rgba(255,255,255,0.72); margin-top: 8px; }

.result { margin-top: 14px; overflow: hidden; position: relative; }
.result img { width: 100%; display: block; }
.loading { padding: 44px 16px; text-align: center; }
.spinner { font-size: 34px; color: var(--pink); animation: spin 1.4s linear infinite; text-shadow: 0 0 18px var(--pink); }
@keyframes spin { to { transform: rotate(360deg); } }
.loading p { margin-top: 10px; font-size: 13px; color: rgba(255,255,255,0.85); }
.err { padding: 22px 16px; font-size: 13px; color: #ffe0e6; text-align: center; }
.result-actions { display: flex; gap: 8px; padding: 12px; }
.mini {
  flex: 1; border: none; border-radius: 999px; padding: 10px; cursor: pointer;
  background: var(--pink); color: var(--ink); font-family: inherit; font-weight: 600; font-size: 12px;
}
.mini.ghost { background: transparent; color: #fff; border: 1px solid rgba(255,255,255,0.5); }

.note { margin-top: 14px; padding: 18px; }
.note h2 { font-family: 'Cormorant Garamond', serif; font-size: 21px; font-weight: 600; margin-bottom: 8px; }
.note p { font-size: 13px; line-height: 1.6; color: rgba(255,255,255,0.88); }

.sheet {
  position: fixed; inset: 0; z-index: 30; background: rgba(29, 21, 51, 0.6);
  backdrop-filter: blur(4px); display: flex; align-items: flex-end;
}
.sheet-card {
  width: 100%; max-width: 440px; margin: 0 auto; background: linear-gradient(170deg, #3d2a5c, #6b4a86);
  border-radius: 26px 26px 0 0; padding: 16px 16px 28px; border: 1px solid var(--glass-line); border-bottom: none;
}
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; font-weight: 600; letter-spacing: 0.05em; }
.sheet-head button { background: none; border: none; color: #fff; font-size: 16px; cursor: pointer; padding: 6px; }
.sheet-rail { margin-bottom: 12px; }
.upload-tile {
  display: block; text-align: center; padding: 13px; border-radius: 16px; cursor: pointer;
  border: 2px dashed rgba(255,255,255,0.55); font-size: 12.5px; color: rgba(255,255,255,0.9);
}

.tabs {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 14px; z-index: 20;
  display: flex; gap: 4px; padding: 6px;
  background: rgba(36, 27, 58, 0.72); border: 1px solid var(--glass-line);
  border-radius: 999px; backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
}
.tabbtn {
  border: none; background: none; color: rgba(255,255,255,0.7); cursor: pointer;
  font-family: inherit; font-size: 13px; font-weight: 600; letter-spacing: 0.04em;
  padding: 9px 22px; border-radius: 999px;
}
.tabbtn.active { background: linear-gradient(100deg, var(--pink), var(--ice)); color: var(--ink); }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 86px; z-index: 40;
  background: rgba(29, 21, 51, 0.88); border: 1px solid var(--glass-line);
  color: #fff; padding: 10px 18px; border-radius: 999px; font-size: 12.5px;
  box-shadow: 0 8px 26px rgba(0,0,0,0.35); white-space: nowrap;
}

.sheet[hidden] { display: none; }
.burst[hidden] { display: none; }
