:root {
  --bg: #f4f3ef;
  --ink: #12161b;
  --accent: #f47230;
  --accent-soft: #fdebe1;
  --muted: #5b6168;
  --line: #dcd8ce;
  --ok: #23804d;
  --danger: #c2372b;
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }

[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, "PingFang SC", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

button:disabled { cursor: default; }

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

img { max-width: 100%; }

.top, main {
  max-width: 1400px;
  margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
}

.top { padding-top: 20px; }

h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.25;
  letter-spacing: 0.01em;
}

.sub {
  margin: 4px 0 0;
  color: var(--muted);
}

.progress {
  margin: 10px 0 0;
  font-size: 14px;
  font-weight: 600;
}

.vote-page main { padding-bottom: calc(150px + env(safe-area-inset-bottom)); }

.vote-page.is-closed main { padding-bottom: 40px; }

.label {
  margin: 20px 0 8px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
}

.loading { color: var(--muted); }

.names {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.name {
  min-height: 40px;
  padding: 6px 14px;
  border: 1.5px solid var(--line);
  border-radius: 999px;
  background: #fff;
}

.name[aria-pressed="true"] {
  border-color: var(--ink);
  background: var(--ink);
  color: #fff;
}

.voted {
  margin-left: 4px;
  color: var(--ok);
  font-size: 13px;
  font-weight: 700;
}

.name[aria-pressed="true"] .voted { color: #8fe0ad; }

.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 20px;
}

@media (min-width: 561px) {
  .grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (min-width: 901px) {
  .grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px;
  }
}

@media (min-width: 1201px) {
  .grid {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }
}

.card { position: relative; }

.pick {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  padding: 0;
  border: 0;
  border-radius: 14px;
  overflow: hidden;
  background: #e6e3db;
  box-shadow: 0 1px 2px rgba(18, 22, 27, 0.08);
}

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

.pick::after {
  content: "";
  position: absolute;
  inset: 0;
  border: 5px solid transparent;
  border-radius: inherit;
  pointer-events: none;
  transition: border-color 0.12s;
}

.pick[aria-pressed="true"]::after { border-color: var(--accent); }

.num {
  position: absolute;
  top: 9px;
  left: 9px;
  padding: 0 7px;
  border-radius: 6px;
  background: rgba(18, 22, 27, 0.78);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  line-height: 22px;
  font-variant-numeric: tabular-nums;
}

.tick {
  position: absolute;
  top: 9px;
  right: 9px;
  display: none;
  width: 28px;
  height: 28px;
  place-items: center;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}

.pick[aria-pressed="true"] .tick { display: grid; }

.zoom-btn {
  position: absolute;
  right: 9px;
  bottom: 9px;
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.94);
  color: var(--ink);
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.28);
}

.zoom-btn svg {
  width: 20px;
  height: 20px;
}

.shake { animation: shake 0.36s ease-in-out; }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

@media (prefers-reduced-motion: reduce) {
  .shake {
    animation: none;
  }

  .pick::after {
    transition: none;
  }
}

.bar {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 10;
  padding: 10px max(16px, env(safe-area-inset-right)) calc(10px + env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.97);
  box-shadow: 0 -4px 16px rgba(18, 22, 27, 0.06);
}

.done, .bar-row {
  max-width: 1400px;
  margin: 0 auto;
}

.done {
  margin-bottom: 6px;
  color: var(--ok);
  font-size: 14px;
  font-weight: 700;
}

.bar-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.slots {
  display: flex;
  flex: 1;
  gap: 8px;
}

.slot {
  display: grid;
  width: 56px;
  height: 46px;
  place-items: center;
  border: 1.5px dashed #b8b3a7;
  border-radius: 10px;
  background: transparent;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

button.slot {
  position: relative;
  border: 2px solid var(--accent);
  background: var(--accent-soft);
}

button.slot::after {
  content: "×";
  position: absolute;
  top: -8px;
  right: -8px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--ink);
  color: #fff;
  font-size: 13px;
  line-height: 18px;
  text-align: center;
}

.submit {
  min-width: 104px;
  height: 46px;
  padding: 0 22px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font-size: 16px;
  font-weight: 700;
}

.submit:disabled {
  background: #d9d5cb;
  color: #74787e;
}

.zoom {
  width: min(92vw, 680px, calc(92vh - 140px));
  max-width: none;
  max-height: 96vh;
  padding: 0;
  border: 0;
  border-radius: 16px;
  background: #fff;
  color: var(--ink);
  overflow: auto;
}

.zoom::backdrop { background: rgba(18, 22, 27, 0.75); }

.zoom-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
}

.zoom-img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1 / 1;
  border-radius: 10px;
  background: #eee;
}

.zoom-controls, .zoom-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.zoom-controls { justify-content: space-between; }

.nav {
  width: 52px;
  height: 44px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  background: #fff;
  font-size: 20px;
}

.zoom-num {
  font-size: 20px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.primary {
  flex: 1;
  height: 46px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font-size: 16px;
  font-weight: 700;
}

.primary[aria-pressed="true"] { background: var(--ink); }

.ghost {
  height: 46px;
  padding: 0 18px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: #fff;
}

.toast {
  position: fixed;
  bottom: calc(110px + env(safe-area-inset-bottom));
  left: 50%;
  z-index: 20;
  width: max-content;
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: 12px;
  background: var(--ink);
  color: #fff;
  font-size: 15px;
  text-align: center;
  transform: translateX(-50%);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
}

.results {
  display: grid;
  gap: 8px;
  max-width: 760px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.result {
  display: grid;
  grid-template-columns: 28px 56px 30px minmax(0, 1fr) 3.2em;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border: 2px solid transparent;
  border-radius: 12px;
  background: #fff;
}

.result.lead { border-color: var(--accent); }

.result img {
  display: block;
  width: 56px;
  height: 56px;
  border-radius: 8px;
  object-fit: cover;
}

.rank {
  font-size: 18px;
  font-weight: 800;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.rid {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.track {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #ece9e1;
}

.fill {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}

.votes {
  font-weight: 700;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.zero {
  max-width: 760px;
  margin-top: 16px;
}

.zero summary {
  margin-bottom: 8px;
  color: var(--muted);
  cursor: pointer;
}

.admin-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.admin-page main { padding-bottom: 48px; }

.phase-btn {
  min-height: 44px;
  padding: 0 18px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}

.phase-btn.reopen { background: var(--ink); }

.notice {
  padding: 12px 16px;
  border-radius: 12px;
  background: #fff3cd;
}

.table-wrap {
  overflow-x: auto;
  border-radius: 12px;
  background: #fff;
}

.tally {
  width: 100%;
  min-width: 820px;
  border-collapse: collapse;
  font-size: 14px;
}

.tally th, .tally td {
  padding: 6px 10px;
  border-bottom: 1px solid #eeebe3;
  text-align: left;
  vertical-align: middle;
}

.tally th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.tally img {
  display: block;
  width: 44px;
  height: 44px;
  border-radius: 6px;
  object-fit: cover;
}

.tally .votes, .tally .rank { text-align: center; }

.tally .source { white-space: nowrap; }

.tally tr.none td { color: #9a9ea4; }

.ballots {
  display: grid;
  gap: 8px;
  max-width: 760px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.ballot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 14px;
  padding: 10px 12px;
  border-radius: 12px;
  background: #fff;
}

.who {
  min-width: 5em;
  font-weight: 700;
}

.their-picks {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.ballot time {
  color: var(--muted);
  font-size: 13px;
}

.clear {
  margin-left: auto;
  min-height: 36px;
  padding: 0 14px;
  border: 1.5px solid var(--danger);
  border-radius: 10px;
  background: #fff;
  color: var(--danger);
}

.clear.armed {
  background: var(--danger);
  color: #fff;
}

.empty, .missing { color: var(--muted); }
