:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --text: #1d2330;
  --muted: #6b7280;
  --border: #e3e5ea;
  --accent: #4f46e5;
  --accent-soft: #eef0ff;
  --danger: #dc2626;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111318;
    --panel: #1a1d24;
    --text: #e6e8ec;
    --muted: #9aa1ad;
    --border: #2c313b;
    --accent: #8b85ff;
    --accent-soft: #252744;
    --danger: #f87171;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}

header, main, footer {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 16px;
}

header { padding-top: 32px; }
h1 { margin: 0; font-size: 1.8rem; }
h2 { margin: 0 0 12px; font-size: 1.1rem; }
.sub { margin: 4px 0 24px; color: var(--muted); }

main {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  align-items: start;
}

@media (max-width: 720px) {
  main { grid-template-columns: 1fr; }
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
}

input[type="search"], input[type="text"] {
  width: 100%;
  padding: 10px 12px;
  font: inherit;
  color: inherit;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}

input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

button {
  font: inherit;
  padding: 8px 14px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}

button.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 4px 10px;
  font-size: 0.875rem;
}
button.ghost:hover { color: var(--text); }
button.danger:hover { color: var(--danger); border-color: var(--danger); }

.results, .toplist {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
}

.results {
  max-height: 420px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.results li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}
.results li:last-child { border-bottom: 0; }
.results li.added { color: var(--muted); }
.results li.none { color: var(--muted); font-style: italic; }
.results button { padding: 4px 10px; font-size: 0.875rem; }
.results li.added button { background: var(--accent-soft); color: var(--accent); cursor: default; }

.custom { margin-top: 16px; }
.custom label { display: block; font-size: 0.9rem; color: var(--muted); margin-bottom: 6px; }
.row { display: flex; gap: 8px; }

.list-head { display: flex; justify-content: space-between; align-items: baseline; }
.actions { display: flex; gap: 6px; }
.count { color: var(--muted); font-weight: normal; font-size: 0.9rem; }

.toplist li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  margin-bottom: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: grab;
}
.toplist li.dragging { opacity: 0.4; }
.toplist li.over { border-color: var(--accent); }

.rank {
  flex: none;
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
  font-size: 0.875rem;
}

.name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.tag { font-size: 0.75rem; color: var(--muted); margin-left: 6px; }

.controls { display: flex; gap: 2px; }
.controls button {
  background: transparent;
  color: var(--muted);
  padding: 2px 6px;
}
.controls button:hover { color: var(--text); }
.controls button:disabled { opacity: 0.3; cursor: default; }
.controls .remove:hover { color: var(--danger); }

.empty { color: var(--muted); text-align: center; margin: 24px 0 8px; }

footer { padding: 24px 16px 40px; color: var(--muted); font-size: 0.85rem; }
footer a { color: inherit; }

/* Top 9 grid */
.grid-section {
  max-width: 640px;
  margin: 24px auto 0;
  padding: 0 16px;
}

.grid-card {
  background: #14161c;
  color: #fff;
  border-radius: 16px;
  padding: 20px;
}

.grid-title {
  margin: 0 0 16px;
  text-align: center;
  font-size: 1.4rem;
  letter-spacing: 0.01em;
}

.grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.tile {
  position: relative;
  aspect-ratio: 1;
  border-radius: 8px;
  overflow: hidden;
  background: #262a33;
}

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

.tile .fallback {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 12px;
  text-align: center;
  font-weight: 700;
  font-size: clamp(0.8rem, 3.2vw, 1.1rem);
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.tile .caption {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 20px 8px 6px;
  font-size: clamp(0.65rem, 2.4vw, 0.8rem);
  font-weight: 600;
  line-height: 1.2;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.85));
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tile .badge {
  position: absolute;
  top: 6px;
  left: 6px;
  min-width: 24px;
  height: 24px;
  padding: 0 6px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.7);
  font-size: 0.8rem;
  font-weight: 700;
}

.tile.empty-slot {
  background: transparent;
  border: 2px dashed #3a3f4b;
  display: grid;
  place-items: center;
  color: #5b6170;
  font-size: 1.6rem;
  font-weight: 700;
}

.grid-actions {
  display: flex;
  justify-content: center;
  margin-top: 12px;
}

footer nav { margin-top: 6px; display: flex; gap: 12px; }

/* Legal pages */
.legal {
  max-width: 720px;
  margin: 0 auto;
  padding: 32px 16px 16px;
}
.legal h1 { margin-bottom: 4px; }
.legal h2 { margin: 28px 0 8px; font-size: 1.15rem; }
.legal p, .legal li { line-height: 1.6; }
.legal a { color: var(--accent); }
.legal .back { display: inline-block; margin-bottom: 16px; font-size: 0.9rem; }
