:root {
  --bg: #0f0f1a;
  --surface: #1a1a2e;
  --surface2: #22223b;
  --border: #2e2e4a;
  --text: #e8e8f0;
  --text-muted: #7070a0;
  --radius: 10px;

  --tier-S: #ff6b6b;
  --tier-A: #ffa94d;
  --tier-B: #ffe066;
  --tier-C: #69db7c;
  --tier-D: #74c0fc;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, sans-serif;
  min-height: 100vh;
  padding: 0 0 60px;
}

/* ── Explainer ── */
#explainer {
  text-align: center;
  padding: 14px 24px;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.88rem;
}

#tier-legend {
  display: flex;
  gap: 20px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 10px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.legend-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  font-weight: 800;
  font-size: 0.75rem;
  flex-shrink: 0;
}

.legend-badge[data-tier="S"] { background: var(--tier-S); color: #000; }
.legend-badge[data-tier="A"] { background: var(--tier-A); color: #000; }
.legend-badge[data-tier="B"] { background: var(--tier-B); color: #000; }
.legend-badge[data-tier="C"] { background: var(--tier-C); color: #000; }
.legend-badge[data-tier="D"] { background: var(--tier-D); color: #000; }

/* ── Header ── */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 24px 32px;
  text-align: center;
}

header h1 {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -0.5px;
}

header p {
  color: var(--text-muted);
  margin-top: 6px;
  font-size: 0.9rem;
}

#view-toggle {
  display: inline-flex;
  margin-top: 16px;
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg);
}

.view-btn {
  padding: 8px 20px;
  background: transparent;
  border: none;
  color: rgba(255,255,255,0.45);
  font-size: 0.88rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.view-btn:not(:last-child) {
  border-right: 1px solid rgba(255,255,255,0.15);
}

.view-btn.active {
  background: rgba(255,255,255,0.12);
  color: var(--text);
}

/* ── Main ── */
main {
  max-width: 900px;
  margin: 32px auto;
  padding: 0 16px;
}

/* ── Tier list ── */
#tier-list {
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}

.tier-row {
  display: flex;
  align-items: stretch;
  min-height: 80px;
  border-bottom: 1px solid var(--border);
}

.tier-row:last-child {
  border-bottom: none;
}

.tier-label {
  width: 64px;
  min-width: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
  font-weight: 900;
  color: #0f0f1a;
  flex-shrink: 0;
}

.tier-label[data-tier="S"] { background: var(--tier-S); }
.tier-label[data-tier="A"] { background: var(--tier-A); }
.tier-label[data-tier="B"] { background: var(--tier-B); }
.tier-label[data-tier="C"] { background: var(--tier-C); }
.tier-label[data-tier="D"] { background: var(--tier-D); }

.tier-items {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 12px;
  flex: 1;
  background: var(--surface2);
}

/* ── Snack card ── */
.snack-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
  min-width: 80px;
  position: relative;
}

.snack-card:hover {
  transform: translateY(-3px);
  border-color: #5050a0;
  box-shadow: 0 6px 20px rgba(0,0,0,0.4);
}

.snack-visual {
  width: 64px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.snack-img {
  width: 64px;
  height: 64px;
  object-fit: contain;
  border-radius: 6px;
}

.snack-emoji {
  font-size: 1.8rem;
  line-height: 1;
}

.snack-name {
  font-size: 0.72rem;
  text-align: center;
  color: var(--text);
  max-width: 80px;
  line-height: 1.3;
}

.snack-votes {
  font-size: 0.65rem;
  color: var(--text-muted);
}

.snack-my-badge {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  font-size: 0.6rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #0f0f1a;
}

.badge-S { background: var(--tier-S); }
.badge-A { background: var(--tier-A); }
.badge-B { background: var(--tier-B); }
.badge-C { background: var(--tier-C); }
.badge-D { background: var(--tier-D); }

/* ── Unranked section ── */
#unranked-section {
  margin-top: 32px;
}

#unranked-section h2 {
  font-size: 1rem;
  color: var(--text-muted);
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

#unranked-count {
  font-size: 0.8rem;
  background: var(--surface2);
  padding: 2px 8px;
  border-radius: 99px;
  color: var(--text-muted);
}

#unranked-items {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

#unranked-items .snack-card {
  background: var(--surface2);
  border-color: var(--border);
  opacity: 0.8;
}

#unranked-items .snack-card:hover {
  opacity: 1;
}

/* ── Modal ── */
#modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(4px);
}

#modal-overlay.hidden {
  display: none;
}

#modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 36px 32px 28px;
  text-align: center;
  max-width: 380px;
  width: 90%;
  position: relative;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
}

#modal-close {
  position: absolute;
  top: 14px;
  right: 16px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  transition: color 0.15s;
}

#modal-close:hover {
  color: var(--text);
}

#modal-emoji {
  font-size: 3.5rem;
  margin-bottom: 8px;
}

#modal h2 {
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 6px;
}

#modal-stats {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-bottom: 4px;
}

#modal-my-vote {
  font-size: 0.85rem;
  margin-bottom: 18px;
  min-height: 20px;
}

.vote-label {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 14px;
}

#tier-buttons {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.tier-btn {
  width: 52px;
  height: 52px;
  border: none;
  border-radius: 8px;
  font-size: 1.3rem;
  font-weight: 900;
  color: #0f0f1a;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
}

.tier-btn:hover {
  transform: scale(1.12);
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}

.tier-btn[data-tier="S"] { background: var(--tier-S); }
.tier-btn[data-tier="A"] { background: var(--tier-A); }
.tier-btn[data-tier="B"] { background: var(--tier-B); }
.tier-btn[data-tier="C"] { background: var(--tier-C); }
.tier-btn[data-tier="D"] { background: var(--tier-D); }

.tier-btn.selected {
  box-shadow: 0 0 0 3px white, 0 0 0 5px rgba(255,255,255,0.3);
  transform: scale(1.15);
}

#vote-feedback {
  margin-top: 18px;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 0.9rem;
  background: var(--surface2);
  border: 1px solid var(--border);
}

#vote-feedback.hidden {
  display: none;
}

/* ── Drag & Drop ── */
.snack-card[draggable="true"] {
  cursor: grab;
}

.snack-card.dragging {
  opacity: 0.3;
}

.tier-items.drag-over {
  background: rgba(255, 255, 255, 0.06);
  outline: 2px dashed rgba(255, 255, 255, 0.25);
  outline-offset: -4px;
}

/* ── Responsive ── */
@media (max-width: 600px) {
  header h1 { font-size: 1.4rem; }
  .tier-label { width: 48px; min-width: 48px; font-size: 1.4rem; }
  .snack-card { min-width: 68px; padding: 8px 10px; }
}
