:root {
  --pink: #c8c8d4;
  --pink-soft: #e0e0e8;
  --purple: #a8a8b8;
  --ink: #ececf0;
  --ink-muted: #9898a8;
  --bg: #0a0a0e;
  --bg-elevated: #141418;
  --card: rgba(255, 255, 255, 0.05);
  --border: rgba(200, 200, 210, 0.22);
  --glow: rgba(200, 200, 220, 0.35);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Nunito', system-ui, sans-serif;
  width: 420px;
  min-height: 620px;
  max-height: 620px;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
}

.app {
  padding: 14px;
  display: flex;
  flex-direction: column;
  height: 620px;
}

.header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  padding: 12px;
  background: var(--bg-elevated);
  border-radius: 16px;
  border: 1px solid var(--border);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
  flex-shrink: 0;
}

.logo {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  object-fit: cover;
  box-shadow: 0 4px 16px var(--glow);
}

.header h1 {
  font-size: 15px;
  font-weight: 900;
  line-height: 1.1;
}

.header p {
  font-size: 11px;
  color: var(--ink-muted);
  max-width: 140px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 6px;
  margin-bottom: 10px;
  flex-shrink: 0;
}

.tab {
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: 12px;
  padding: 9px 4px;
  font-family: inherit;
  font-size: 11px;
  font-weight: 800;
  color: var(--ink-muted);
  cursor: pointer;
  transition: 0.15s;
}

.tab.active {
  background: linear-gradient(135deg, var(--pink), #888894);
  color: white;
  border-color: transparent;
  box-shadow: 0 8px 20px var(--glow);
}

.panel {
  display: none;
  flex: 1;
  min-height: 0;
  flex-direction: column;
}

.panel.active { display: flex; }

.toolbar {
  flex-shrink: 0;
  margin-bottom: 8px;
}

.search {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--ink);
  border-radius: 12px;
  padding: 9px 12px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 8px;
}

.search::placeholder { color: var(--ink-muted); }
.search:focus {
  outline: none;
  border-color: var(--pink-soft);
  box-shadow: 0 0 0 3px rgba(200, 200, 212, 0.15);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--ink-muted);
  border-radius: 999px;
  padding: 4px 10px;
  font-family: inherit;
  font-size: 10px;
  font-weight: 800;
  cursor: pointer;
  transition: 0.15s;
}

.chip.active {
  background: linear-gradient(135deg, var(--pink), #888894);
  color: white;
  border-color: transparent;
}

.panel-desc {
  font-size: 11px;
  color: var(--ink-muted);
  margin-bottom: 8px;
  flex-shrink: 0;
}

.toggle {
  margin-left: auto;
  position: relative;
  width: 46px;
  height: 26px;
  flex-shrink: 0;
}

.toggle input { opacity: 0; width: 0; height: 0; }

.slider {
  position: absolute;
  inset: 0;
  background: #2a2a32;
  border-radius: 999px;
  cursor: pointer;
  transition: 0.2s;
}

.slider:before {
  content: '';
  position: absolute;
  width: 20px;
  height: 20px;
  left: 3px;
  top: 3px;
  background: white;
  border-radius: 50%;
  transition: 0.2s;
  box-shadow: 0 2px 6px rgba(0,0,0,0.25);
}

.toggle input:checked + .slider { background: var(--pink); }
.toggle input:checked + .slider:before { transform: translateX(20px); }

.scroll-grid {
  overflow-y: auto;
  flex: 1;
  min-height: 0;
  padding-right: 4px;
  margin-bottom: 10px;
}

.scroll-grid::-webkit-scrollbar { width: 6px; }
.scroll-grid::-webkit-scrollbar-thumb {
  background: rgba(200, 200, 212, 0.35);
  border-radius: 999px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  align-content: start;
}

.card {
  border: 2px solid transparent;
  background: var(--card);
  border-radius: 14px;
  padding: 8px 4px 6px;
  text-align: center;
  cursor: pointer;
  transition: 0.15s transform, 0.15s border-color, 0.15s box-shadow;
}

.card:hover {
  transform: translateY(-2px);
  border-color: var(--border);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.2);
}

.card.active {
  border-color: var(--pink);
  box-shadow: 0 0 0 3px rgba(200, 200, 212, 0.2);
}

.card .emoji { font-size: 18px; line-height: 1.1; }
.card .thumb {
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.card .thumb img {
  max-height: 28px;
  max-width: 28px;
  object-fit: contain;
  image-rendering: pixelated;
}

.card .live-badge {
  position: absolute;
  top: -4px;
  right: -2px;
  font-size: 7px;
  font-weight: 900;
  background: var(--pink);
  color: white;
  padding: 1px 4px;
  border-radius: 999px;
}

.card .label {
  font-size: 8px;
  font-weight: 800;
  margin-top: 4px;
  color: var(--ink-muted);
  line-height: 1.2;
}

.custom-panel {
  flex-shrink: 0;
  padding: 12px;
  border-radius: 14px;
  background: var(--bg-elevated);
  border: 1px dashed var(--border);
}

.custom-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  font-size: 12px;
  font-weight: 800;
}

.badge {
  font-size: 9px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(200, 200, 212, 0.12);
  color: var(--pink-soft);
}

.custom-preview-row {
  display: flex;
  gap: 10px;
  align-items: stretch;
}

.custom-preview {
  width: 72px;
  min-height: 72px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  display: grid;
  place-items: center;
  overflow: hidden;
  flex-shrink: 0;
}

.custom-preview.wide { width: 110px; }

.custom-preview img { width: 100%; height: 100%; object-fit: cover; }

.custom-preview .placeholder {
  font-size: 9px;
  font-weight: 700;
  color: var(--ink-muted);
  text-align: center;
  padding: 6px;
}

.custom-actions {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.btn-upload, .btn-apply, .btn-remove {
  border: none;
  border-radius: 11px;
  padding: 9px 10px;
  font-family: inherit;
  font-size: 11px;
  font-weight: 800;
  cursor: pointer;
  text-align: center;
}

.btn-upload {
  display: block;
  background: var(--card);
  color: var(--ink);
  border: 1px solid var(--border);
}

.btn-apply {
  background: linear-gradient(135deg, var(--pink), #888894);
  color: white;
}

.btn-apply:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-remove {
  background: transparent;
  color: #b8b8c0;
  border: 1px solid rgba(160, 160, 168, 0.35);
}

.mode-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  font-size: 11px;
  font-weight: 700;
}

.mode-row label {
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  color: var(--ink-muted);
}

.hint {
  margin-top: 8px;
  font-size: 10px;
  color: var(--ink-muted);
  line-height: 1.35;
}

.bg-grid .card { min-height: 58px; }

.bg-preview {
  position: relative;
  height: 28px;
  border-radius: 8px;
  margin-bottom: 4px;
  border: 1px solid rgba(255,255,255,0.08);
  background-size: cover;
  background-position: center;
}

.bg-none { background: #1e1e24; }
.bg-sakura { background: linear-gradient(90deg, #e8e8ec, #d0d0d8); }
.bg-lavender { background: linear-gradient(90deg, #dcdce4, #c8c8d0); }
.bg-mint { background: linear-gradient(90deg, #e4e4ea, #c8c8d4); }
.bg-sunset { background: linear-gradient(90deg, #ececf0, #d8d8e0); }
.bg-stars { background: linear-gradient(90deg, #282830, #404048); }
.bg-cotton { background: linear-gradient(90deg, #f0f0f4, #dcdce4); }
.bg-peach { background: linear-gradient(90deg, #e8e8ec, #d4d4dc); }

.footer {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  flex-shrink: 0;
}

.footer button, .footer a {
  flex: 1;
  border: none;
  border-radius: 12px;
  padding: 10px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 800;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}

.ghost {
  background: var(--card);
  color: var(--ink-muted);
  border: 1px solid var(--border);
}

.primary {
  background: linear-gradient(135deg, var(--pink), #888894);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-elevated);
  color: var(--ink);
  border: 1px solid var(--border);
  font-size: 11px;
  font-weight: 700;
  padding: 8px 14px;
  border-radius: 999px;
  opacity: 0;
  transition: 0.2s;
  pointer-events: none;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.mine-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding-right: 2px;
}

.mine-section {
  margin-bottom: 14px;
}

.mine-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  font-size: 12px;
}

.mine-grid,
.mine-bg-grid {
  margin-bottom: 8px;
}

.empty-hint {
  grid-column: 1 / -1;
  font-size: 11px;
  color: var(--ink-muted);
  padding: 8px 4px;
  text-align: center;
}

.saved-card {
  position: relative;
}

.saved-card.active .card-saved {
  border-color: var(--pink);
  box-shadow: 0 0 0 2px rgba(200, 200, 212, 0.35);
}

.saved-delete {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 18px;
  height: 18px;
  border: none;
  border-radius: 999px;
  background: #787888;
  color: white;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.name-input {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--ink);
  border-radius: 10px;
  padding: 8px 10px;
  font-family: inherit;
  font-size: 11px;
  font-weight: 600;
  margin-bottom: 6px;
}

.name-input::placeholder {
  color: var(--ink-muted);
}

.custom-actions {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}
