/* ---------- Tokens ---------- */
:root {
  --bg: #fff8f0;
  --bg-alt: #fef1e2;
  --surface: #ffffff;
  --surface-2: #fff3e6;
  --border: #f0dcc4;
  --text: #3a2a1e;
  --text-muted: #8a7362;
  --accent: #ff8a3d;
  --accent-2: #ffb15e;
  --accent-strong: #e8641a;
  --gold: #f5b301;
  --success: #4caf82;
  --danger: #e05d5d;
  --shadow: 0 6px 20px rgba(120, 72, 24, 0.10);
  --shadow-lg: 0 14px 40px rgba(120, 72, 24, 0.16);
  --radius: 18px;
  --radius-sm: 12px;
  --font-display: 'Fredoka', 'Comic Sans MS', system-ui, sans-serif;
  --font-body: 'Nunito', system-ui, -apple-system, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c140e;
    --bg-alt: #241a12;
    --surface: #2a1f16;
    --surface-2: #33251a;
    --border: #4a3625;
    --text: #f5e9db;
    --text-muted: #c2ab93;
    --accent: #ff9c52;
    --accent-2: #ffb15e;
    --accent-strong: #ffab6b;
    --gold: #ffd166;
    --shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 14px 40px rgba(0, 0, 0, 0.45);
  }
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  line-height: 1.5;
  min-height: 100vh;
  position: relative;
  overflow-x: hidden;
}

.wrap {
  max-width: 980px;
  margin: 0 auto;
  padding: 0 20px;
}

.bg-paws {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background-image: radial-gradient(circle at 8% 12%, var(--bg-alt) 0%, transparent 40%),
    radial-gradient(circle at 92% 85%, var(--bg-alt) 0%, transparent 40%);
  opacity: 0.9;
}

/* ---------- Header ---------- */
.site-header {
  padding: 36px 0 22px;
  text-align: center;
}

.header-inner { display: flex; flex-direction: column; align-items: center; gap: 6px; }

.brand {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  text-decoration: none;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(2rem, 5vw, 2.8rem);
  color: var(--text);
}
.brand-mark { font-size: 0.85em; }
.brand-text { letter-spacing: -0.01em; }
.brand-dot { color: var(--accent-strong); }

.tagline {
  margin: 0;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.98rem;
}

/* ---------- Upload card ---------- */
.upload-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 26px 28px 28px;
  box-shadow: var(--shadow);
  margin-bottom: 40px;
}

.upload-card h2 {
  margin: 0 0 4px;
  font-family: var(--font-display);
  font-size: 1.35rem;
}

.hint {
  margin: 0 0 18px;
  color: var(--text-muted);
  font-size: 0.92rem;
}

.dropzone {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 160px;
  border: 2px dashed var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.1s ease;
  margin-bottom: 18px;
  padding: 16px;
  text-align: center;
  position: relative;
  overflow: hidden;
}
.dropzone:hover, .dropzone:focus-visible { border-color: var(--accent); background: var(--surface); }
.dropzone.drag-over { border-color: var(--accent-strong); background: var(--surface); transform: scale(1.01); }

.dropzone-content { display: flex; flex-direction: column; align-items: center; gap: 6px; color: var(--text-muted); }
.dropzone-icon { font-size: 2.2rem; }
.dropzone-text { color: var(--text); font-weight: 700; }
.dropzone-sub { font-size: 0.82rem; }

.preview-img {
  max-width: 100%;
  max-height: 280px;
  border-radius: 10px;
  object-fit: contain;
  display: block;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 14px;
}

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-weight: 700; font-size: 0.86rem; color: var(--text-muted); }
.optional { font-weight: 400; text-transform: none; }

input[type="text"] {
  font-family: var(--font-body);
  font-size: 0.98rem;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s ease;
}
input[type="text"]:focus { border-color: var(--accent); }

.confirm-row {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 600;
  font-size: 0.92rem;
  margin: 6px 0 16px;
  cursor: pointer;
  user-select: none;
}
.confirm-row input { width: 17px; height: 17px; accent-color: var(--accent-strong); cursor: pointer; }

.form-error {
  background: color-mix(in srgb, var(--danger) 14%, transparent);
  color: var(--danger);
  border: 1px solid color-mix(in srgb, var(--danger) 40%, transparent);
  padding: 9px 12px;
  border-radius: 10px;
  font-size: 0.88rem;
  font-weight: 700;
  margin: 0 0 14px;
}

.btn {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1rem;
  border: none;
  border-radius: 999px;
  padding: 12px 26px;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease, opacity 0.12s ease;
}
.btn:active { transform: translateY(1px) scale(0.98); }
.btn-primary {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-strong) 100%);
  color: #fff;
  box-shadow: 0 8px 20px rgba(232, 100, 26, 0.35);
}
.btn-primary:hover { box-shadow: 0 10px 24px rgba(232, 100, 26, 0.45); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; box-shadow: none; }

/* ---------- Gallery ---------- */
.gallery-section { padding-bottom: 50px; }

.gallery-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 18px;
}
.gallery-header h2 { margin: 0; font-family: var(--font-display); font-size: 1.5rem; }

.controls { display: flex; align-items: center; gap: 14px; }

.sort-toggle {
  display: inline-flex;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
  gap: 2px;
}
.sort-btn {
  border: none;
  background: transparent;
  padding: 7px 14px;
  border-radius: 999px;
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 0.84rem;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.sort-btn.active { background: var(--accent); color: #fff; }

.cat-count { color: var(--text-muted); font-size: 0.86rem; font-weight: 700; }

/* Leaderboard (top 3) */
.leaderboard {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 30px;
}
.leader-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  position: relative;
  display: flex;
  flex-direction: column;
}
.leader-card .rank-badge {
  position: absolute;
  top: 10px;
  left: 10px;
  font-size: 1.4rem;
  filter: drop-shadow(0 2px 3px rgba(0,0,0,0.25));
  z-index: 1;
}
.leader-card .leader-img-wrap { aspect-ratio: 4 / 3; overflow: hidden; background: var(--surface-2); }
.leader-card img { width: 100%; height: 100%; object-fit: cover; display: block; }
.leader-card .leader-info { padding: 12px 14px 14px; }
.leader-card .leader-name { font-family: var(--font-display); font-weight: 600; font-size: 1.05rem; margin: 0 0 2px; }
.leader-card .leader-votes { color: var(--accent-strong); font-weight: 800; font-size: 0.9rem; }
.leader-card:nth-child(1) { border-color: var(--gold); box-shadow: 0 0 0 2px var(--gold), var(--shadow-lg); }

/* Grid */
.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 18px;
}

.cat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  animation: pop-in 0.35s ease both;
}
.cat-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }

@keyframes pop-in {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.card-img-wrap {
  aspect-ratio: 4 / 3;
  background: var(--surface-2);
  overflow: hidden;
  position: relative;
}
.card-img-wrap img { width: 100%; height: 100%; object-fit: cover; display: block; }

.delete-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,0.55);
  color: #fff;
  font-size: 0.9rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s ease, background 0.15s ease;
}
.cat-card:hover .delete-btn, .delete-btn:focus-visible { opacity: 1; }
.delete-btn:hover { background: var(--danger); }

.card-body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.card-name { font-family: var(--font-display); font-weight: 600; font-size: 1.02rem; margin: 0; }
.card-uploader { color: var(--text-muted); font-size: 0.78rem; margin: -6px 0 0; }

.card-footer { margin-top: auto; display: flex; align-items: center; justify-content: space-between; gap: 10px; }

.vote-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1.5px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-family: var(--font-body);
  font-weight: 800;
  font-size: 0.88rem;
  padding: 9px 10px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}
.vote-btn:hover { border-color: var(--accent); background: var(--surface); }
.vote-btn:active { transform: scale(0.96); }
.vote-btn.voted {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-strong) 100%);
  border-color: transparent;
  color: #fff;
  cursor: default;
}
.vote-btn.voted:hover { transform: none; }
.vote-btn .paw { transition: transform 0.2s ease; }
.vote-btn.bump .paw { animation: paw-bump 0.35s ease; }
@keyframes paw-bump {
  0% { transform: scale(1); }
  40% { transform: scale(1.5) rotate(-15deg); }
  100% { transform: scale(1); }
}

.vote-count { font-weight: 800; color: var(--accent-strong); font-size: 0.86rem; min-width: 20px; text-align: right; }

/* ---------- Empty state ---------- */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.empty-icon { font-size: 2.6rem; display: block; margin-bottom: 10px; }

/* ---------- Footer ---------- */
.site-footer {
  text-align: center;
  padding: 28px 20px 44px;
  color: var(--text-muted);
  font-size: 0.84rem;
  max-width: 640px;
  margin: 0 auto;
}
.footer-actions { margin-top: 6px; }

.link-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  text-decoration: underline;
  cursor: pointer;
  font-size: 0.82rem;
  font-family: var(--font-body);
  padding: 2px 4px;
}
.link-btn:hover { color: var(--danger); }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--text);
  color: var(--bg);
  padding: 11px 20px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.9rem;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 50;
  max-width: 90vw;
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  .field-row { grid-template-columns: 1fr; }
  .leaderboard { grid-template-columns: 1fr; }
  .upload-card { padding: 20px; }
}
