:root {
  --primary: #6c5ce7;
  --primary-dark: #5847d1;
  --accent: #ff5f7e;
  --bg: #f6f4fd;
  --card: #ffffff;
  --text: #1f1b2e;
  --text-dim: #8b859c;
  --border: #ece9f7;
  --green: #2ecc71;
  --radius: 20px;
  --radius-sm: 12px;
  --nav-h: 68px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  background: var(--bg);
  position: relative;
  padding-bottom: var(--nav-h);
  display: flex;
  flex-direction: column;
}

.hidden { display: none !important; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 10px;
}

.logo {
  font-weight: 800;
  font-size: 22px;
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.pill {
  font-size: 12px;
  font-weight: 700;
  padding: 6px 12px;
  border-radius: 100px;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text-dim);
}

.pill.premium {
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: white;
  border: none;
}

/* ---------- Auth screen ---------- */
#screen-auth {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 32px 28px;
  gap: 18px;
}

.auth-hero {
  text-align: center;
  margin-bottom: 12px;
}

.auth-hero h1 {
  font-size: 34px;
  margin: 10px 0 6px;
  letter-spacing: -1px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.auth-hero p {
  color: var(--text-dim);
  font-size: 15px;
  margin: 0;
}

input {
  width: 100%;
  padding: 15px 16px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  font-size: 15px;
  background: var(--card);
  color: var(--text);
}

input:focus { outline: none; border-color: var(--primary); }

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
}

.btn-primary {
  width: 100%;
  padding: 16px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: white;
  font-weight: 700;
  font-size: 16px;
  box-shadow: 0 8px 20px -6px rgba(108, 92, 231, 0.5);
}

.btn-secondary {
  width: 100%;
  padding: 16px;
  border-radius: var(--radius-sm);
  background: var(--card);
  border: 1.5px solid var(--border);
  color: var(--text);
  font-weight: 700;
  font-size: 15px;
}

.auth-switch {
  text-align: center;
  font-size: 14px;
  color: var(--text-dim);
}

.auth-switch a { color: var(--primary); font-weight: 700; text-decoration: none; }

.divider {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-dim);
  font-size: 12px;
}
.divider::before, .divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ---------- Deck screen ---------- */
#screen-deck { flex: 1; display: flex; flex-direction: column; padding: 6px 20px 20px; }

.deck-stage {
  position: relative;
  flex: 1;
  min-height: 420px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.card-outfit {
  width: 100%;
  max-width: 380px;
  aspect-ratio: 3/4;
  border-radius: var(--radius);
  overflow: hidden;
  position: relative;
  box-shadow: 0 16px 40px -12px rgba(31, 27, 46, 0.25);
  background: var(--card);
}

.card-outfit img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.card-outfit .card-footer {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 18px 16px 16px;
  background: linear-gradient(to top, rgba(0,0,0,0.65), transparent);
  color: white;
}

.card-outfit .card-name { font-weight: 700; font-size: 15px; }
.card-outfit .card-link {
  display: inline-block;
  margin-top: 6px;
  font-size: 12px;
  color: #ffd9e2;
  text-decoration: none;
  font-weight: 600;
}

.empty-state {
  text-align: center;
  color: var(--text-dim);
  padding: 40px 20px;
}
.empty-state .big-emoji { font-size: 48px; display: block; margin-bottom: 12px; }

.deck-actions {
  display: flex;
  justify-content: center;
  gap: 22px;
  padding: 22px 0 6px;
}

.round-btn {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--card);
  border: 1.5px solid var(--border);
  font-size: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 20px -8px rgba(31, 27, 46, 0.2);
}

.round-btn.pass { color: var(--text-dim); }
.round-btn.like {
  width: 76px;
  height: 76px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: white;
  font-size: 30px;
  box-shadow: 0 10px 24px -6px rgba(255, 95, 126, 0.55);
}

/* ---------- Upload screen ---------- */
#screen-upload { flex: 1; padding: 6px 20px 20px; }

.section-title { font-size: 22px; font-weight: 800; margin: 6px 0 4px; }
.section-sub { color: var(--text-dim); font-size: 14px; margin: 0 0 18px; }

.upload-box {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 30px 16px;
  text-align: center;
  color: var(--text-dim);
  cursor: pointer;
  background: var(--card);
  margin-bottom: 14px;
  overflow: hidden;
}
.upload-box img { width: 100%; border-radius: var(--radius-sm); display: block; }
.upload-box .big-emoji { font-size: 34px; display: block; margin-bottom: 8px; }

.crop-wrap { margin-bottom: 14px; }

.crop-viewport {
  position: relative;
  width: 100%;
  aspect-ratio: 3/4;
  border-radius: var(--radius);
  overflow: hidden;
  background: #000;
  touch-action: none;
  cursor: grab;
}
.crop-viewport.dragging { cursor: grabbing; }
.crop-viewport img {
  position: absolute;
  top: 0;
  left: 0;
  max-width: none;
  transform-origin: 0 0;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}

.crop-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
}
.crop-controls input[type="range"] {
  flex: 1;
  accent-color: var(--primary);
}
.crop-controls .crop-zoom-icon { font-size: 13px; color: var(--text-dim); }

.link-btn {
  display: block;
  margin: 10px auto 0;
  background: none;
  border: none;
  color: var(--primary);
  font-weight: 700;
  font-size: 13px;
  padding: 4px 8px;
}

label.field-label { font-size: 13px; font-weight: 700; color: var(--text-dim); margin: 14px 0 6px; display: block; }

.quota-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  margin-bottom: 16px;
  font-size: 13px;
}
.quota-banner strong { color: var(--primary); }

/* ---------- Ranking screen ---------- */
#screen-ranking { flex: 1; padding: 6px 20px 20px; }

.rank-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px;
  margin-bottom: 10px;
}

.rank-num {
  width: 28px;
  text-align: center;
  font-weight: 800;
  color: var(--text-dim);
  font-size: 15px;
}
.rank-row:nth-child(1) .rank-num { color: #ffb300; }
.rank-row:nth-child(2) .rank-num { color: #9aa0a6; }
.rank-row:nth-child(3) .rank-num { color: #c9762f; }

.rank-thumb {
  width: 52px; height: 52px;
  border-radius: 12px;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--border);
}

.rank-meta { flex: 1; min-width: 0; }
.rank-meta .name { font-weight: 700; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rank-meta .likes { font-size: 12px; color: var(--text-dim); }

/* ---------- Bottom nav ---------- */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  height: var(--nav-h);
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-around;
}

.nav-item {
  background: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  font-size: 10px;
  font-weight: 700;
  color: var(--text-dim);
  padding: 6px 14px;
  border-radius: 12px;
}
.nav-item .icon { font-size: 21px; }
.nav-item.active { color: var(--primary); }

/* ---------- Toast ---------- */
#toast {
  position: fixed;
  bottom: calc(var(--nav-h) + 14px);
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--text);
  color: white;
  padding: 12px 20px;
  border-radius: 100px;
  font-size: 13px;
  font-weight: 600;
  opacity: 0;
  transition: opacity .25s, transform .25s;
  pointer-events: none;
  z-index: 50;
  white-space: nowrap;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Loader ---------- */
.spinner {
  width: 22px; height: 22px;
  border: 3px solid rgba(255,255,255,0.4);
  border-top-color: white;
  border-radius: 50%;
  animation: spin .7s linear infinite;
  margin: 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }
