:root {
  --ink: #16181d;
  --ink-2: #4a505c;
  --ink-3: #7a808c;
  --line: #e3e5ea;
  --bg: #f4f5f7;
  --card: #fff;
  --accent: #f2c200;
  --accent-ink: #16181d;
  --good: #1f8a4c;
  --bad: #c0392b;
  --radius: 12px;
  --tray-h: 0px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; padding-bottom: var(--tray-h); }
button { font: inherit; cursor: pointer; }
.hidden { display: none !important; }

header.top {
  background: var(--ink);
  color: #fff;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
}
header.top h1 { font-size: 18px; margin: 0; letter-spacing: 0.02em; }
header.top h1 span { color: var(--accent); }
header.top .who { margin-left: auto; font-size: 14px; color: #c9ccd3; display: flex; gap: 12px; align-items: center; }
header.top .who button {
  background: transparent; border: 1px solid #4a505c; color: #fff; border-radius: 8px; padding: 6px 10px; font-size: 13px;
}

main { max-width: 1200px; margin: 0 auto; padding: 20px; }

/* Login */
.login {
  max-width: 380px; margin: 8vh auto; background: var(--card); border-radius: var(--radius);
  padding: 28px; box-shadow: 0 8px 30px rgba(0,0,0,.08);
}
.login h2 { margin: 0 0 6px; font-size: 22px; }
.login p { margin: 0 0 20px; color: var(--ink-2); font-size: 15px; line-height: 1.45; }
.login label { display: block; font-size: 13px; font-weight: 600; margin: 14px 0 6px; color: var(--ink-2); }
.login input {
  width: 100%; padding: 11px 12px; font-size: 16px; border: 1px solid var(--line); border-radius: 8px;
}
.login input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.btn {
  background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 8px;
  padding: 11px 18px; font-weight: 700; font-size: 15px;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.secondary { background: #fff; border: 1px solid var(--line); color: var(--ink); font-weight: 600; }
.login .btn { width: 100%; margin-top: 22px; }
.error { color: var(--bad); font-size: 14px; margin-top: 12px; min-height: 1em; }

/* Intro */
.intro { margin-bottom: 18px; }
.intro h2 { margin: 0 0 6px; font-size: 22px; }
.intro p { margin: 0; color: var(--ink-2); line-height: 1.5; }
.notice {
  background: #fff8d6; border: 1px solid #f0dc8a; border-radius: 10px; padding: 10px 14px;
  margin-top: 12px; font-size: 14px;
}
.notice.ok { background: #e6f5ec; border-color: #b6dfc5; }
.notice.closed { background: #fdecea; border-color: #f2c1bb; }

/* Grid */
.grid {
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
}
.card {
  position: relative; background: var(--card); border-radius: var(--radius); overflow: hidden;
  border: 2px solid transparent; box-shadow: 0 1px 3px rgba(0,0,0,.06);
  display: flex; flex-direction: column; transition: border-color .15s, transform .15s;
}
.card.picked { border-color: var(--accent); }
.card img { width: 100%; aspect-ratio: 1; object-fit: contain; background: #fff; display: block; cursor: zoom-in; }
.card .meta { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 8px; border-top: 1px solid var(--line); }
.card .name { font-weight: 600; font-size: 15px; }
.card .num { color: var(--ink-3); font-size: 12px; font-weight: 500; }
.card .pick {
  border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 8px; font-weight: 600; font-size: 14px;
}
.card .pick:hover { border-color: var(--ink-3); }
.card.picked .pick { background: var(--ink); color: #fff; border-color: var(--ink); }
.card .pick:disabled { opacity: .45; cursor: not-allowed; }
.badge {
  position: absolute; top: 10px; left: 10px; width: 38px; height: 38px; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink); font-weight: 800; font-size: 18px;
  display: grid; place-items: center; box-shadow: 0 2px 8px rgba(0,0,0,.2);
}

/* Ballot tray */
.tray {
  position: fixed; left: 0; right: 0; bottom: 0; background: #fff; border-top: 1px solid var(--line);
  box-shadow: 0 -6px 20px rgba(0,0,0,.06); z-index: 10;
}
.tray-inner {
  max-width: 1200px; margin: 0 auto; padding: 10px 20px; display: flex; gap: 14px; align-items: center;
}
.tray .label { font-weight: 700; font-size: 14px; white-space: nowrap; }
.tray .label small { display: block; font-weight: 400; color: var(--ink-3); font-size: 12px; }
.slots { display: flex; gap: 8px; flex: 1; overflow-x: auto; padding: 2px 0; }
.slot {
  flex: 0 0 auto; width: 78px; border: 1.5px dashed var(--line); border-radius: 10px; padding: 4px;
  display: flex; flex-direction: column; align-items: center; gap: 2px; position: relative; background: #fafbfc;
}
.slot.filled { border-style: solid; border-color: var(--accent); background: #fff; }
.slot .rank { position: absolute; top: 2px; left: 5px; font-size: 12px; font-weight: 800; color: var(--ink-2); }
.slot img { width: 54px; height: 54px; object-fit: contain; }
.slot .empty { width: 54px; height: 54px; display: grid; place-items: center; color: var(--ink-3); font-size: 11px; text-align: center; }
.slot .ctrls { display: flex; gap: 2px; }
.slot .ctrls button {
  border: 1px solid var(--line); background: #fff; border-radius: 5px; width: 22px; height: 20px;
  font-size: 11px; line-height: 1; padding: 0; color: var(--ink-2);
}
.slot .ctrls button:disabled { opacity: .3; cursor: default; }
.tray .status { font-size: 13px; color: var(--ink-3); white-space: nowrap; }

/* Lightbox */
.lightbox {
  position: fixed; inset: 0; background: rgba(10,12,16,.85); z-index: 20; display: grid; place-items: center; padding: 20px;
}
.lightbox .box { background: #fff; border-radius: var(--radius); max-width: min(720px, 100%); width: 100%; overflow: hidden; }
.lightbox img { width: 100%; max-height: 75vh; object-fit: contain; display: block; }
.lightbox .bar { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-top: 1px solid var(--line); }
.lightbox .bar .name { font-weight: 700; margin-right: auto; }

@media (max-width: 640px) {
  main { padding: 14px; }
  .grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .card .meta { padding: 8px; }
  .card .name { font-size: 13px; }
  .badge { width: 30px; height: 30px; font-size: 15px; top: 6px; left: 6px; }
  .tray-inner { flex-wrap: wrap; padding: 8px 12px; gap: 8px; }
  .tray .label { display: none; }
  .slots { order: 1; flex-basis: 100%; gap: 5px; overflow: visible; }
  .slot { flex: 1 1 0; width: auto; min-width: 0; padding: 3px 2px; }
  .slot img, .slot .empty { width: 100%; height: 44px; }
  .slot .ctrls { gap: 1px; }
  .slot .ctrls button { width: 18px; height: 20px; font-size: 10px; }
  .tray .status { order: 2; flex: 1; white-space: normal; }
  .tray .btn { order: 3; }
}

/* Admin */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat { background: #fff; border-radius: var(--radius); padding: 14px 16px; }
.stat .k { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); font-weight: 600; }
.stat .v { font-size: 26px; font-weight: 800; margin-top: 4px; }
.stat .v small { font-size: 14px; color: var(--ink-3); font-weight: 500; }
.panel { background: #fff; border-radius: var(--radius); padding: 18px; margin-bottom: 20px; }
.panel h3 { margin: 0 0 4px; font-size: 17px; }
.panel .sub { margin: 0 0 14px; color: var(--ink-3); font-size: 13px; line-height: 1.45; }
.winner { display: flex; gap: 16px; align-items: center; }
.winner img { width: 130px; height: 130px; object-fit: contain; border-radius: 10px; border: 1px solid var(--line); }
.winner .t { font-size: 13px; color: var(--ink-3); text-transform: uppercase; letter-spacing: .05em; font-weight: 700; }
.winner .n { font-size: 22px; font-weight: 800; margin: 4px 0; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-3); font-weight: 600; }
td.n, th.n { text-align: right; font-variant-numeric: tabular-nums; }
td .thumb { width: 40px; height: 40px; object-fit: contain; vertical-align: middle; margin-right: 8px; }
.bar-cell { width: 30%; }
.bar-track { background: #eef0f3; border-radius: 4px; height: 10px; overflow: hidden; }
.bar-fill { background: var(--accent); height: 100%; }
.table-wrap { overflow-x: auto; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { background: #eef0f3; border-radius: 999px; padding: 4px 10px; font-size: 13px; }
.rounds { display: flex; flex-direction: column; gap: 10px; }
.round { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font-size: 13px; }
.round b { font-size: 13px; }
.round .elim { color: var(--bad); }
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar .muted { color: var(--ink-3); font-size: 13px; }
