:root {
  --bg: #0f1016;
  --bg-2: #151724;
  --panel: rgba(27, 29, 41, 0.86);
  --panel-2: rgba(32, 35, 50, 0.9);
  --line: rgba(255, 255, 255, 0.1);
  --line-2: rgba(255, 255, 255, 0.14);
  --text: #f4f6ff;
  --text-soft: #b7bed9;
  --accent: #a05cff;
  --accent-2: #8848f1;
  --accent-soft: rgba(160, 92, 255, 0.2);
  --danger: #ff6a86;
  --shadow: 0 16px 38px rgba(0, 0, 0, 0.35);
  --radius: 14px;
  touch-action: pan-x pan-y;
}

* { box-sizing: border-box; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; }
input, textarea { -webkit-user-select: text; user-select: text; }
img { -webkit-user-drag: none; user-drag: none; pointer-events: none; }

html, body {
  margin: 0; min-height: 100%;
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: radial-gradient(900px 380px at 5% -20%, #4b2b7550, transparent 65%),
              radial-gradient(900px 380px at 95% -20%, #3f2b6d50, transparent 65%),
              linear-gradient(180deg, var(--bg-2), var(--bg));
  overscroll-behavior: none;
}

.appRoot { min-height: 100vh; padding: 8px 10px calc(84px + env(safe-area-inset-bottom)); }

/* ===== TOP BAR ===== */
.topStrip { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }

.topChip {
  border: 1px solid var(--line); background: linear-gradient(180deg, #1b1d29, #181a25);
  color: var(--text); border-radius: 12px; padding: 0 10px; height: 38px;
  display: flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap;
}
.topChip .chipIcon { width: 16px; height: 16px; fill: #a898ff; flex-shrink: 0; }
.topChip strong { font-size: 13px; }
.topChip.slots { flex-direction: column; gap: 0; padding: 0 10px; }
.topChip.slots span { font-size: 12px; font-weight: 700; line-height: 1.2; }
.topChip.slots small { font-size: 10px; color: var(--text-soft); line-height: 1; }
.topRight { display: flex; align-items: center; gap: 6px; }

.iconBtn {
  width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--line);
  background: rgba(255,255,255,0.03); color: #d0caff; display: grid; place-items: center; padding: 0; flex-shrink: 0;
  position: relative;
}
.iconBtn svg { width: 18px; height: 18px; fill: currentColor; }

/* Badge */
.badge {
  position: absolute; top: -4px; right: -4px;
  min-width: 16px; height: 16px; border-radius: 8px;
  background: var(--danger); color: #fff; font-size: 10px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; padding: 0 4px;
}
.badge.hidden { display: none; }

/* ===== CONTENT ===== */
.content { display: grid; gap: 10px; }
.tabPane { display: none; gap: 10px; }
.tabPane.active { display: grid; animation: pageIn 260ms cubic-bezier(.23,.72,.25,1); }
@keyframes pageIn { from { opacity: 0; transform: translateY(8px) scale(0.99); } to { opacity: 1; transform: translateY(0) scale(1); } }

.glassCard {
  border: 1px solid var(--line); background: linear-gradient(180deg, var(--panel), var(--panel-2));
  border-radius: 18px; padding: 14px; box-shadow: var(--shadow); backdrop-filter: blur(10px);
}

h2, h3 { margin: 0 0 10px; font-weight: 700; }
h2 { font-size: 18px; }
h3 { font-size: 15px; color: #dde2f4; }
.hint { margin: -2px 0 10px; color: var(--text-soft); font-size: 12px; }
.labelHint { color: var(--text-soft); font-weight: 400; }

.hidden { display: none !important; }

/* ===== SKELETON ===== */
.skeleton {
  position: relative;
  overflow: hidden;
  background: rgba(255,255,255,0.06);
  border-radius: 10px;
}
.skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.16), transparent);
  animation: shimmer 1.1s infinite;
}
@keyframes shimmer { to { transform: translateX(100%); } }
.skelInput { height: 46px; border-radius: 12px; }
.skelPreview { height: 76px; margin-top: 8px; border-radius: 12px; }
.skelRow { height: 14px; margin: 8px 0; }
.skelCard { height: 78px; border-radius: 12px; margin-bottom: 8px; }
.skelAlert { height: 82px; border-radius: 12px; margin-bottom: 8px; }

/* ===== STATS ===== */
.statsGrid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.statCard { background: #1d1f2d; border: 1px solid var(--line); border-radius: 12px; padding: 9px; }
.statCard span { display: block; font-size: 11px; color: var(--text-soft); }
.statCard b { font-size: 20px; }

/* ===== BUTTONS ===== */
.btn { border: 1px solid transparent; border-radius: 12px; padding: 11px 12px; font-weight: 600; color: var(--text); transition: transform 120ms ease, box-shadow 180ms ease; }
.btn:active { transform: scale(0.97); }
.btn.primary { background: linear-gradient(180deg, var(--accent), var(--accent-2)); color: #f8f4ff; box-shadow: 0 8px 22px rgba(160, 92, 255, 0.35); }
.btn.ghost { background: rgba(255,255,255,0.04); border-color: var(--line); }
.btn.danger { background: rgba(255, 106, 134, 0.12); border-color: rgba(255, 106, 134, 0.3); color: #ffc1cf; padding: 8px 10px; min-width: 74px; }
.btn.full { width: 100%; }

/* ===== FORM ===== */
.field { display: grid; gap: 8px; margin-bottom: 10px; }
.field label { font-size: 12px; color: var(--text-soft); }
.fieldLabelRow { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.favBtn {
  width: 26px; height: 26px; border-radius: 8px; border: 1px solid var(--line-2);
  background: #1b1e2a; color: #ffd96e; font-size: 16px; line-height: 1; padding: 0;
  display: inline-grid; place-items: center;
}
.favBtn.active { background: rgba(255,217,110,0.15); border-color: rgba(255,217,110,0.5); }
.refBox label { font-size: 12px; color: var(--text-soft); }

input[type="number"], input[type="text"] {
  width: 100%; appearance: none; background: #1b1e2a; border: 1px solid var(--line-2);
  color: var(--text); border-radius: 12px; padding: 11px 12px; font-size: 14px; outline: none;
  transition: border-color 180ms ease, box-shadow 180ms ease;
}
input:focus { border-color: rgba(160, 92, 255, 0.7); box-shadow: 0 0 0 3px rgba(160, 92, 255, 0.2); }

/* ===== CUSTOM SELECT ===== */
.customSelect { position: relative; z-index: 10; }
/* Stacking: first select on top so its menu covers inputs below */
.field:nth-child(1) .customSelect { z-index: 50; }
.field:nth-child(2) .customSelect { z-index: 40; }
.field:nth-child(3) .customSelect { z-index: 30; }
.field:nth-child(4) .customSelect { z-index: 20; }
#collectionSelect { z-index: 50; }
#modelSelect { z-index: 40; }
#backdropSelect { z-index: 30; }
#symbolSelect { z-index: 20; }

/* make page taller while lower dropdowns are open so user can scroll */
#modelSelect.open,
#backdropSelect.open,
#symbolSelect.open { margin-bottom: 220px; }

.selectTrigger {
  width: 100%; border: 1px solid var(--line-2); background: #1b1e2a; color: var(--text);
  border-radius: 12px; padding: 11px 12px; display: flex; justify-content: space-between; align-items: center; gap: 10px;
}
.selectTrigger .label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.selectTrigger .sublabel { font-size: 11px; color: var(--text-soft); margin-left: auto; white-space: nowrap; }
.selectTrigger svg { width: 14px; height: 14px; fill: #cfc4ff; flex-shrink: 0; transition: transform 180ms; }
.customSelect.open .selectTrigger svg { transform: rotate(180deg); }

.selectMenu {
  position: absolute; left: 0; right: 0; z-index: 50;
  border: 1px solid var(--line-2); background: #202433; border-radius: 12px;
  max-height: 260px; overflow: auto; box-shadow: 0 12px 40px rgba(0,0,0,0.5); display: none;
}

.customSelect .selectMenu { top: calc(100% + 6px); }
.customSelect.upward .selectMenu { top: auto; bottom: calc(100% + 6px); }
.customSelect.open .selectMenu { display: block; animation: menuIn 140ms ease; }
@keyframes menuIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: translateY(0); } }

.selectSearch { padding: 8px 10px; border-bottom: 1px solid var(--line); }
.selectSearch input {
  width: 100%; background: #191c28; border: 1px solid var(--line-2); color: var(--text);
  border-radius: 10px; padding: 8px 10px; font-size: 13px; outline: none;
}
.selectSearch input::placeholder { color: #7a82a0; }

.selectOption {
  width: 100%; border: 0; background: transparent; color: #e8ecfa; text-align: left;
  padding: 8px 12px; font-size: 14px; display: flex; align-items: center; gap: 10px;
}
.selectOption .optThumb {
  width: 32px; height: 32px; border-radius: 8px; object-fit: contain; flex-shrink: 0;
  background: #181b28; pointer-events: none;
}
.selectOption .optThumb.symbol { filter: brightness(0) invert(1); background: transparent; }
.selectOption .optLabel { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.selectOption .optFloor { font-size: 11px; color: var(--text-soft); white-space: nowrap; }
.selectOption:hover, .selectOption.active { background: rgba(160, 92, 255, 0.18); }
.selectOption.hidden { display: none; }

/* ===== COLLECTION/ITEM PREVIEW ===== */
.collectionPreview {
  margin: 0 0 10px; border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; background: #171b27;
}
.collectionPreview:empty { display: none; border: 0; margin: 0; }
.collectionPreview .inner { display: flex; gap: 10px; padding: 10px; align-items: center; }
.collectionPreview img { width: 56px; height: 56px; border-radius: 12px; object-fit: cover; pointer-events: none; }
.collectionPreview .txt { min-width: 0; }
.collectionPreview .txt b { display: block; font-size: 14px; }
.collectionPreview .txt .floorInfo { font-size: 11px; color: var(--text-soft); margin-top: 2px; }

.itemPreview {
  margin: 4px 0 0; border: 1px solid var(--line); border-radius: 12px;
  overflow: hidden; background: #171b27;
}
.itemPreview:empty { display: none; border: 0; margin: 0; }
.itemPreview .inner { display: flex; gap: 10px; padding: 8px 10px; align-items: center; }
.itemPreview img { width: 44px; height: 44px; border-radius: 10px; object-fit: cover; pointer-events: none; }
.itemPreview .txt { min-width: 0; }
.itemPreview .txt b { display: block; font-size: 13px; }
.itemPreview .txt .floorInfo { font-size: 11px; color: var(--text-soft); }
.itemPreview img.symbolImg { filter: brightness(0) invert(1); background: transparent; }

/* ===== SLOT LIST ===== */
.slotList { display: grid; gap: 10px; }

.slotCard {
  border: 1px solid var(--line); background: linear-gradient(180deg, #1c2030, #191d2b);
  border-radius: 16px; padding: 12px; display: grid; gap: 10px;
}
.slotCardTop { display: flex; align-items: center; gap: 12px; }
.slotCardInfo { flex: 1; min-width: 0; }
.slotCardInfo strong { display: block; font-size: 15px; }
.slotCardInfo .meta { margin-top: 3px; color: var(--text-soft); font-size: 12px; }

.slotCardActions { display: flex; gap: 4px; }
.slotCardActions .btn { display: flex; align-items: center; justify-content: center; gap: 5px; font-size: 12px; padding: 8px 6px; }
.slotCardActions .btn svg { flex-shrink: 0; }
.slotCardActions .editBtn { flex: 1; }
.slotCardActions .shareBtn.iconOnly { flex: 0 0 34px; width: 34px; min-width: 34px; padding: 0; }
.slotCardActions .deleteBtn { flex: 0 0 auto; min-width: 70px; }

/* Composite gift preview */
.giftComposite {
  width: 52px; height: 52px; border-radius: 12px; flex-shrink: 0;
  position: relative; overflow: hidden; background: #121520;
}
.giftComposite .gcBackdrop {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover;
  pointer-events: none;
}
.giftComposite .gcSymbol {
  position: absolute; width: 14px; height: 14px; object-fit: contain;
  filter: brightness(0) invert(1); opacity: 0.35; pointer-events: none;
}
.giftComposite .gcModel {
  position: absolute; inset: 4px; width: calc(100% - 8px); height: calc(100% - 8px);
  object-fit: contain; pointer-events: none; z-index: 2;
}

/* ===== EMPTY STATE ===== */
.emptyState {
  border: 1px dashed rgba(255,255,255,0.18); border-radius: var(--radius);
  padding: 20px 12px; text-align: center; display: grid; gap: 8px; justify-items: center; color: var(--text-soft);
}
.emptyState svg { width: 26px; height: 26px; fill: #b99fff; }
.emptyState b { color: #ece4ff; }

/* ===== PROFILE ===== */
.profileHead { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; }
.avatar { width: 54px; height: 54px; border-radius: 999px; object-fit: cover; background: #1d2232; border: 1px solid var(--line); pointer-events: none; }
.profileMeta strong { display: block; font-size: 15px; }
.profileMeta span { color: var(--text-soft); font-size: 13px; }
.refBox { display: grid; gap: 6px; margin-bottom: 10px; }
.refRow { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; }
.profileInfo { font-size: 13px; color: var(--text-soft); margin-bottom: 4px; }

/* ===== SETTINGS TOGGLE ===== */
.settingRow { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; }
.settingRow span { font-size: 14px; }

.toggle { position: relative; display: inline-block; width: 44px; height: 24px; flex-shrink: 0; }
.toggle input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; cursor: pointer; inset: 0; background: #3a3d4f;
  border-radius: 12px; transition: background 200ms;
}
.slider::before {
  content: ""; position: absolute; width: 18px; height: 18px; left: 3px; bottom: 3px;
  background: #fff; border-radius: 50%; transition: transform 200ms;
}
.toggle input:checked + .slider { background: var(--accent); }
.toggle input:checked + .slider::before { transform: translateX(20px); }

/* ===== TOP-UP FLOW ===== */
.topUpFlow { display: grid; gap: 10px; }
.topUpOptions { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.promoRow { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; }
.promoInfo {
  margin-top: 8px; font-size: 12px; color: #d9c7ff;
  border: 1px solid rgba(160,92,255,0.35); background: rgba(160,92,255,0.12);
  border-radius: 10px; padding: 8px 10px;
}
.promoInfo.error {
  color: #ffd0db;
  border-color: rgba(255,106,134,0.4);
  background: rgba(255,106,134,0.12);
}
.topUpOption {
  border: 1px solid var(--line-2); background: #1b1e2a; color: var(--text);
  border-radius: 12px; padding: 10px 4px; text-align: center; font-size: 13px; font-weight: 600; line-height: 1.3;
  transition: border-color 140ms ease, background 140ms ease;
}
.topUpOption small { display: block; font-weight: 400; font-size: 11px; color: var(--text-soft); margin-top: 2px; }
.topUpOption.active { border-color: var(--accent); background: var(--accent-soft); }

.invoiceBox {
  border-radius: 12px; border: 1px solid var(--line); background: #191d2b; color: var(--text-soft);
  padding: 10px; display: grid; gap: 7px;
}
.invoiceBox:empty { display: none; }
.invoiceBox a { color: #d2bdff; }

/* ===== LEADERBOARD ===== */
.leaderboard { display: grid; gap: 6px; }

.lbRow {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px;
  border: 1px solid var(--line); border-radius: 12px; background: #1c2030;
}
.lbRank {
  width: 26px; height: 26px; border-radius: 999px; background: var(--accent-soft);
  color: #ead8ff; display: grid; place-items: center; font-size: 12px; font-weight: 700; flex-shrink: 0;
}
.lbRank.gold { background: rgba(255, 215, 0, 0.25); color: #ffd700; }
.lbRank.silver { background: rgba(192, 192, 192, 0.25); color: #c0c0c0; }
.lbRank.bronze { background: rgba(205, 127, 50, 0.25); color: #cd7f32; }
.lbName { flex: 1; font-size: 14px; }
.lbScore { font-size: 13px; color: var(--text-soft); font-weight: 600; }

.myRankRow {
  margin-top: 6px; padding: 10px 12px; border: 1px solid var(--accent);
  border-radius: 12px; background: var(--accent-soft);
  display: flex; align-items: center; gap: 10px;
}
.myRankRow .lbRank { background: var(--accent); color: #fff; }
.myRankRow .lbName { font-weight: 600; color: var(--text); }
.myRankRow .lbScore { color: #e0d4ff; }

.platformStats { display: grid; gap: 8px; }
.psStat { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid rgba(255,255,255,0.06); font-size: 13px; }
.psStat:last-child { border-bottom: 0; }
.psStat span { color: var(--text-soft); }
.psStat b { color: var(--text); }

/* ===== ALERTS OVERLAY ===== */
.overlay {
  position: fixed; inset: 0; z-index: 100; background: var(--bg);
  padding: 12px 10px; overflow-y: auto;
  animation: overlayIn 220ms ease;
}
.overlay.closing { animation: overlayOut 200ms ease forwards; }
@keyframes overlayIn { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
@keyframes overlayOut { from { opacity: 1; transform: translateY(0); } to { opacity: 0; transform: translateY(20px); } }
.overlayHeader { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.overlayHeader h2 { margin: 0; }
.overlayHeader .iconBtn { border: 0; background: transparent; }

.alertsList { display: grid; gap: 8px; }
.alertItem {
  border: 1px solid var(--line); background: var(--panel); border-radius: 12px; padding: 10px 12px;
  display: grid; gap: 4px;
  position: relative;
  transition: transform 140ms ease, opacity 140ms ease;
  touch-action: pan-y;
}
.alertItem.removing { opacity: 0; transform: translateX(-80px); }
.alertItem .alertHead { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.alertItem .alertHead b { font-size: 14px; }
.alertItem .alertHead small { font-size: 11px; color: var(--text-soft); }
.alertItem .alertMeta { font-size: 12px; color: var(--text-soft); }
.alertItem a { color: #d2bdff; font-size: 12px; text-decoration: none; }
.alertDismissBtn {
  margin-left: auto; width: 24px; height: 24px; border-radius: 8px;
  border: 1px solid var(--line); background: rgba(255,255,255,0.04); color: var(--text-soft);
  display: grid; place-items: center; font-size: 14px; line-height: 1; padding: 0;
}

.alertsEmpty { text-align: center; color: var(--text-soft); padding: 30px 10px; }

/* ===== TABBAR ===== */
.tabbar {
  position: fixed; left: 10px; right: 10px; bottom: calc(10px + env(safe-area-inset-bottom));
  z-index: 40; border: 1px solid var(--line); background: rgba(23, 25, 36, 0.94);
  border-radius: 16px; padding: 6px; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 2px; box-shadow: var(--shadow); backdrop-filter: blur(10px);
}

.tabBtn {
  border: 0; background: transparent; color: #9ca5c8; border-radius: 12px;
  padding: 7px 4px; display: grid; gap: 3px; justify-items: center;
  transition: background 120ms ease, color 120ms ease;
}
.tabBtn svg { width: 20px; height: 20px; fill: currentColor; }
.tabBtn em { font-style: normal; font-size: 11px; }
.tabBtn.active { color: #f0e5ff; background: rgba(160, 92, 255, 0.2); }

/* ===== APP MODAL ===== */
.appModal {
  position: fixed; inset: 0; z-index: 120;
  background: rgba(0,0,0,0.55);
  display: grid; place-items: center;
  padding: 14px;
}
.appModalCard {
  width: min(420px, 100%);
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #202435, #1a1f2f);
  border-radius: 16px;
  padding: 14px;
  box-shadow: var(--shadow);
}
.appModalBody { color: var(--text-soft); font-size: 14px; margin: 8px 0 10px; }
.modalCheck { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; color: var(--text-soft); font-size: 12px; }
.modalCheck input { accent-color: var(--accent); }
.appModalActions { display: flex; justify-content: flex-end; gap: 8px; }

@media (max-width: 420px) { .topUpOptions { grid-template-columns: repeat(2, 1fr); } }
