:root {
  --bg: #1a1a1d;
  --panel: #232327;
  --panel-2: #2c2c31;
  --line: #3a3a40;
  --text: #ececf0;
  --muted: #9a9aa5;
  --accent: #ffffff;
  --card: 76px;
  --label: 72px;
  /* Classic tier-list colours. The tier letter is always printed on the
     label, so the colour is never the only signal. */
  --tier-S: #ff7f7f;
  --tier-A: #ffbf7f;
  --tier-B: #ffdf7f;
  --tier-C: #ffff7f;
  --tier-D: #bfff7f;
  --tier-F: #7fffff;
  --tier-X: #55555c;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: inherit; }
button, input, textarea { font: inherit; color: inherit; }

.topbar { padding: 10px 16px; border-bottom: 1px solid var(--line); }
.brand { font-weight: 800; text-decoration: none; letter-spacing: .02em; }
.brand-s { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 5px; background: var(--tier-S); color: #111; margin-right: 4px; }

main { max-width: 1100px; margin: 0 auto; padding: 16px; }
h1 { font-size: 1.6rem; margin: 0 0 4px; }
h2 { font-size: 1.15rem; margin: 24px 0 8px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px; }
label.field { display: block; margin: 0 0 12px; }
label.field > span { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 4px; }
input[type=text], input[type=url], textarea {
  width: 100%; padding: 9px 10px; background: var(--bg); border: 1px solid var(--line); border-radius: 6px;
}
textarea { min-height: 140px; resize: vertical; }
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 6px; border: 1px solid var(--line); background: var(--panel-2); cursor: pointer; text-decoration: none; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: #f0f0f3; color: #111; border-color: #f0f0f3; font-weight: 600; }
.btn.danger { border-color: #b84a4a; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.small { padding: 4px 9px; font-size: .85rem; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.spacer { flex: 1; }

.head { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-start; margin-bottom: 12px; }
.head .titles { flex: 1; min-width: 220px; }
.closed-badge { display: inline-block; font-size: .75rem; font-weight: 700; padding: 2px 8px; border: 1px solid var(--muted); border-radius: 99px; margin-left: 8px; vertical-align: middle; }

.people { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 0; padding: 0; list-style: none; }
.person { font-size: .8rem; padding: 3px 9px; border-radius: 99px; border: 1px solid var(--line); }
/* Submitted: solid and bright with a check. Still ranking: dashed and dim. */
.person.done { background: #f0f0f3; color: #111; border-color: #f0f0f3; font-weight: 600; }
.person.pending { border-style: dashed; color: var(--muted); }
.person.me { outline: 2px solid var(--accent); outline-offset: 1px; }
button.person { cursor: pointer; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: 16px 0 12px; overflow-x: auto; }
.tab { padding: 9px 14px; border: none; background: none; cursor: pointer; color: var(--muted); border-bottom: 3px solid transparent; white-space: nowrap; }
.tab[aria-selected=true] { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

/* --- tier board --- */
.board { border: 1px solid #000; background: #000; display: grid; gap: 2px; }
.tier { display: grid; grid-template-columns: var(--label) 1fr; min-height: calc(var(--card) + 4px); background: var(--panel); }
.tier-label {
  display: grid; place-items: center; text-align: center; color: #111; font-weight: 800; font-size: 1.9rem;
  cursor: default; user-select: none; padding: 4px; border: none;
}
.tier-label.small-text { font-size: .8rem; line-height: 1.1; }
.tier[data-tier=S] .tier-label { background: var(--tier-S); }
.tier[data-tier=A] .tier-label { background: var(--tier-A); }
.tier[data-tier=B] .tier-label { background: var(--tier-B); }
.tier[data-tier=C] .tier-label { background: var(--tier-C); }
.tier[data-tier=D] .tier-label { background: var(--tier-D); }
.tier[data-tier=F] .tier-label { background: var(--tier-F); }
.tier[data-tier=X] { background: var(--bg); }
.tier[data-tier=X] .tier-label { background: var(--tier-X); color: #ddd; font-size: .8rem; font-weight: 700; }
.tier[data-tier=X] .tier-items { border: 2px dashed var(--line); }
.tier-items { display: flex; flex-wrap: wrap; align-content: flex-start; gap: 2px; padding: 2px; min-height: calc(var(--card) + 4px); }
.selecting .tier-label, .selecting .tier-items { cursor: pointer; }
.selecting .tier:hover .tier-items { box-shadow: inset 0 0 0 2px var(--accent); }

.pool-wrap { margin-top: 14px; }
/* While ranking, the unranked pool stays in reach at the bottom of the screen. */
.pool-wrap.sticky { position: sticky; bottom: 0; z-index: 2; background: var(--bg); padding: 6px 0; border-top: 1px solid var(--line); }
.pool-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin-bottom: 6px; }
.pool-head h2 { margin: 0; }
.pool-wrap.sticky .pool-head h2 { font-size: .95rem; }
.pool-wrap.sticky .pool-head .btn { padding: 5px 10px; font-size: .85rem; }
/* About 1.5 rows of cards: small enough to leave the board visible, and the
   cut-off second row shows the tray scrolls. */
.pool-wrap.sticky .pool { max-height: calc(var(--card) * 1.5 + 12px); overflow-y: auto; overscroll-behavior: contain; }
.pool { border: 1px solid var(--line); border-radius: 8px; background: var(--panel); min-height: calc(var(--card) + 12px); padding: 4px; }

.card {
  position: relative; width: var(--card); height: var(--card); flex: 0 0 auto; background: var(--panel-2);
  overflow: hidden; cursor: grab; user-select: none; -webkit-user-select: none; touch-action: manipulation; -webkit-tap-highlight-color: transparent;
  border: none; padding: 0;
}
.card img { width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; }
.card .cap {
  position: absolute; left: 0; right: 0; bottom: 0; font-size: .68rem; line-height: 1.15; padding: 2px 3px;
  background: rgba(0,0,0,.72); color: #fff; overflow: hidden; text-align: center;
  /* Wrap rather than truncate: "Acura MDX (2nd gen)" and "(3rd gen)" must stay distinguishable. */
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow-wrap: anywhere;
}
.card.text-only { display: grid; place-items: center; padding: 4px; background: #3d3d45; }
.card.text-only .cap { position: static; background: none; white-space: normal; font-size: .78rem; font-weight: 600; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; }
.card.selected { outline: 3px solid var(--accent); outline-offset: -3px; }
.card.selected::after { content: "✓"; position: absolute; top: 2px; right: 3px; background: #fff; color: #111; font-weight: 800; border-radius: 99px; width: 18px; height: 18px; display: grid; place-items: center; font-size: .75rem; }
.sortable-ghost { opacity: .35; }
.board.readonly .card { cursor: pointer; }

.score { position: absolute; top: 0; left: 0; background: rgba(0,0,0,.8); color: #fff; font-size: .72rem; font-weight: 700; padding: 1px 4px; border-bottom-right-radius: 4px; }

.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 14px 0; }
.status { font-size: .85rem; color: var(--muted); }
.notice { padding: 10px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); margin: 10px 0; }
.notice.locked::before { content: "🔒 "; }

/* --- distribution bars in item detail --- */
.dist { display: grid; grid-template-columns: 28px 1fr 28px; gap: 4px 8px; align-items: center; margin: 12px 0; }
.dist .lbl { font-weight: 800; text-align: center; color: #111; border-radius: 3px; }
.dist .bar { height: 14px; background: var(--panel-2); border-radius: 3px; overflow: hidden; }
.dist .bar > i { display: block; height: 100%; background: #e8e8ee; }
.dist .n { text-align: right; font-variant-numeric: tabular-nums; }

dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 12px; padding: 18px; width: min(440px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0,0,0,.6); }
dialog h3 { margin: 0 0 10px; }
.detail-img { width: 100%; max-height: 220px; object-fit: contain; background: #000; border-radius: 6px; }

.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.list li .thumb { width: 40px; height: 40px; object-fit: cover; background: var(--panel-2); border-radius: 4px; flex: 0 0 auto; }
.list li .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }

#toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: #f0f0f3; color: #111; padding: 8px 14px; border-radius: 8px; font-weight: 600; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 10; }
#toast.show { opacity: 1; }

@media (max-width: 600px) {
  :root { --card: 64px; --label: 52px; }
  .card .cap { font-size: .6rem; line-height: 1.1; padding: 1px 2px; }
  .tier-label { font-size: 1.5rem; }
  .tier[data-tier=X] .tier-label, .tier-label.small-text { font-size: .68rem; }
  h1 { font-size: 1.3rem; }
}
