:root {
  --ink: #0d1030;
  --panel: #171b48;
  --panel-2: #1f246a;
  --line: #2b3180;
  --text: #f4f2ff;
  --muted: #a3a6d8;
  --cool: #5be7ff;
  --lame: #ff8c42;
  --radius: 20px;
  --font: "Bricolage Grotesque", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--ink);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }
img { display: block; }
:focus-visible { outline: 3px solid var(--cool); outline-offset: 3px; }

/* ---------- header ---------- */
.top { padding: 22px 16px 8px; text-align: center; }
.brand {
  margin: 0;
  font-weight: 800;
  font-size: clamp(2.1rem, 8vw, 3.6rem);
  line-height: 1;
  letter-spacing: -0.035em;
}
.tabs {
  display: inline-flex;
  gap: 4px;
  margin-top: 16px;
  padding: 4px;
  background: var(--panel);
  border-radius: 999px;
}
.tab {
  padding: 8px 18px;
  border-radius: 999px;
  color: var(--muted);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.95rem;
  transition: background 0.15s, color 0.15s;
}
.tab:hover { color: var(--text); }
.tab[aria-current="page"] { background: var(--cool); color: var(--ink); }

main { max-width: 1040px; margin: 0 auto; padding: 8px 14px 48px; }
.status { text-align: center; color: var(--muted); margin: 40px 0; }
.status.error { color: var(--lame); }
.status button { margin-top: 12px; }

/* ---------- vote ---------- */
.prompt {
  text-align: center;
  font-size: clamp(1.25rem, 4vw, 1.7rem);
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 18px 0 14px;
}
.arena {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
}
.vs {
  font-weight: 800;
  font-size: 1rem;
  color: var(--muted);
  font-style: italic;
}
.card {
  position: relative;
  padding: 0;
  background: var(--panel);
  border: 3px solid var(--panel);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.15s, border-color 0.15s, opacity 0.25s, filter 0.25s;
}
.card:hover { border-color: var(--line); transform: translateY(-3px); }
.card:active { transform: scale(0.985); }
.frame { display: block; position: relative; height: clamp(180px, 46vh, 480px); }
.name {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  min-height: 2.9em;
  padding: 9px 10px 11px;
  font-weight: 600;
  font-size: clamp(0.88rem, 3.4vw, 1.1rem);
  line-height: 1.3;
  text-align: center;
  overflow-wrap: anywhere;
}
.name:empty { display: none; }
.frame img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
  transition: opacity 0.18s;
}
.arena.swapping .frame img { opacity: 0; }

.result {
  position: absolute;
  inset: auto 0 0 0;
  padding: 36px 8px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  background: linear-gradient(to top, rgba(13, 16, 48, 0.92), rgba(13, 16, 48, 0));
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
}
.delta { font-size: clamp(2rem, 9vw, 3.2rem); font-weight: 800; line-height: 1; letter-spacing: -0.03em; }
.score { font-size: 0.95rem; color: var(--muted); font-weight: 600; }
.arena.revealed .result { opacity: 1; transform: none; transition: opacity 0.2s, transform 0.2s; }
.arena.revealed .card { cursor: default; }
.arena.revealed .card:hover { transform: none; }
.card.won { border-color: var(--cool); }
.card.won .delta { color: var(--cool); }
.card.lost { opacity: 0.55; filter: grayscale(0.6); }
.card.lost .delta { color: var(--lame); }

.hint { text-align: center; color: var(--muted); font-size: 0.9rem; margin: 16px 0 0; }
.count { text-align: center; color: var(--muted); font-size: 0.9rem; margin: 4px 0 0; min-height: 1.3em; }

/* ---------- chips ---------- */
.chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin: 14px 0 6px; }
.chips:empty { display: none; }
.chip {
  padding: 6px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
}
.chip:hover { color: var(--text); }
.chip[aria-pressed="true"] { background: var(--text); border-color: var(--text); color: var(--ink); }

/* ---------- podium ---------- */
.board { margin: 28px 0 40px; }
.board h2 {
  text-align: center;
  margin: 0 0 4px;
  font-size: clamp(1.6rem, 6vw, 2.3rem);
  font-weight: 800;
  letter-spacing: -0.03em;
}
.board.cool h2 { color: var(--cool); }
.board.lame h2 { color: var(--lame); }
.board .sub { text-align: center; color: var(--muted); margin: 0 0 18px; font-size: 0.95rem; }

.steps {
  display: grid;
  grid-template-columns: 1fr 1.15fr 1fr;
  align-items: end;
  gap: 8px;
  max-width: 640px;
  margin: 0 auto;
}
.step { display: flex; flex-direction: column; align-items: stretch; min-width: 0; }
.step.p1 { order: 2; }
.step.p2 { order: 1; }
.step.p3 { order: 3; }
.pic {
  padding: 0;
  border: 0;
  border-radius: 14px 14px 0 0;
  background: var(--panel);
  overflow: hidden;
  cursor: zoom-in;
  aspect-ratio: 1;
}
.pic img { width: 100%; height: 100%; object-fit: contain; }
.pname {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  min-height: 2.7em;
  padding: 6px 6px 0;
  background: var(--panel-2);
  font-weight: 600;
  font-size: clamp(0.72rem, 2.9vw, 0.9rem);
  line-height: 1.3;
  text-align: center;
  overflow-wrap: anywhere;
}
.block {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding-top: 8px;
  background: var(--panel-2);
  border-radius: 0 0 6px 6px;
}
.step.p1 .block { height: 92px; }
.step.p2 .block { height: 66px; }
.step.p3 .block { height: 48px; }
.board.cool .p1 .block { background: var(--cool); color: var(--ink); }
.board.lame .p1 .block { background: var(--lame); color: var(--ink); }
.place { font-size: 1.9rem; font-weight: 800; line-height: 1; letter-spacing: -0.04em; }
.step .elo { font-size: 0.85rem; font-weight: 600; opacity: 0.85; }

.runners { max-width: 640px; margin: 12px auto 0; padding: 0; list-style: none; display: grid; gap: 8px; }
.empty-slot { text-align: center; color: var(--muted); padding: 22px 8px; font-size: 0.9rem; }
.slot-empty { background: var(--panel); border-radius: 14px 14px 0 0; aspect-ratio: 1; display: grid; place-items: center; color: var(--muted); font-size: 1.6rem; }

/* ---------- ranking list ---------- */
.sortbar { display: flex; justify-content: space-between; align-items: center; max-width: 720px; margin: 14px auto 8px; color: var(--muted); font-size: 0.9rem; }
.linkbtn { background: none; border: 0; padding: 4px 0; color: var(--cool); font-weight: 600; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.ranklist { list-style: none; margin: 0 auto; padding: 0; max-width: 720px; display: grid; gap: 6px; }
.row {
  display: grid;
  grid-template-columns: 3.2ch 56px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 6px 12px 6px 10px;
  background: var(--panel);
  border-radius: 14px;
  width: 100%;
  text-align: left;
  border: 0;
  cursor: pointer;
}
.row:hover { background: var(--panel-2); }
.row .rk { font-weight: 800; color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }
.row .th { width: 56px; height: 56px; border-radius: 10px; background: var(--ink); overflow: hidden; }
.row .th img { width: 100%; height: 100%; object-fit: cover; }
.row .who { min-width: 0; display: flex; flex-direction: column; }
.row .nm { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .rec { color: var(--muted); font-size: 0.85rem; }
.row .pts { font-weight: 800; font-size: 1.25rem; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.row .pts.up { color: var(--cool); }
.row .pts.down { color: var(--lame); }
.more { display: block; margin: 16px auto 0; padding: 10px 22px; border-radius: 999px; border: 1px solid var(--line); background: transparent; cursor: pointer; font-weight: 600; }
.more:hover { background: var(--panel); }

/* ---------- overlays ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: min(92vw, 420px);
  padding: 12px 18px;
  border-radius: 14px;
  background: var(--lame);
  color: var(--ink);
  font-weight: 600;
  text-align: center;
  z-index: 30;
}
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 20px;
  background: rgba(8, 10, 32, 0.94);
  cursor: zoom-out;
}
.lightbox img { max-width: 100%; max-height: 78vh; object-fit: contain; border-radius: 12px; }
.lb-meta { margin: 0; font-weight: 600; font-size: 1.05rem; text-align: center; }
.lb-meta .lb-name { display: block; font-size: 1.3rem; font-weight: 800; letter-spacing: -0.02em; }
.lb-meta .lb-stats { color: var(--muted); }
.lb-close { position: absolute; top: 12px; right: 14px; width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--panel); font-size: 1.6rem; line-height: 1; cursor: pointer; }

@media (max-width: 420px) {
  .arena { gap: 6px; }
  .card { border-radius: 16px; border-width: 2px; }
  .row { grid-template-columns: 2.6ch 48px 1fr auto; gap: 10px; }
  .row .th { width: 48px; height: 48px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
