:root {
  --bg: #fff;
  --fg: #000;
  --muted: #666;
  --line: #111;
  --soft: #f4f4f4;
  --tap: 48px;
  --nav-h: 64px;
  --top-h: 52px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}
*, *::before, *::after { box-sizing: border-box; border-radius: 0 !important; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg); color: var(--fg);
  min-height: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
[hidden], .hidden { display: none !important; }
button, input, select, textarea, label { touch-action: manipulation; font-family: inherit; }
body {
  padding-top: calc(var(--top-h) + var(--safe-t));
  padding-bottom: calc(var(--nav-h) + var(--safe-b));
}
body.reveal-mode { padding-bottom: var(--safe-b); }

.topbar {
  position: fixed; top: 0; left: 0; right: 0;
  height: calc(var(--top-h) + var(--safe-t));
  padding: var(--safe-t) 12px 0;
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 2px solid var(--fg); background: var(--bg); z-index: 50; gap: 10px;
}
.topbar h1 { margin: 0; font-size: 18px; font-weight: 800; letter-spacing: 0.04em; }
.badge {
  font-size: 12px; border: 1.5px solid var(--fg); padding: 4px 8px; flex-shrink: 0;
  background: var(--fg); color: var(--bg); font-weight: 700;
}

.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0;
  height: calc(var(--nav-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  display: grid; grid-template-columns: repeat(4, 1fr);
  border-top: 2px solid var(--fg); background: var(--bg); z-index: 50;
}
.nav-btn {
  appearance: none; background: transparent; border: 0;
  border-right: 1px solid #ddd;
  font-size: 14px; font-weight: 700; min-height: var(--nav-h);
  cursor: pointer; color: var(--muted);
}
.nav-btn:last-child { border-right: 0; }
.nav-btn.active {
  color: var(--fg); background: var(--soft);
  box-shadow: inset 0 -3px 0 var(--fg);
}

.app { max-width: 960px; margin: 0 auto; padding: 16px 12px 24px; }
.panel { display: none; }
.panel.active { display: block; }

.card {
  border: 2px solid var(--fg); background: var(--bg); padding: 16px; margin-bottom: 12px;
}
.card.soft { background: var(--soft); }
.card h2 {
  margin: 0 0 12px; font-size: 16px; font-weight: 800; letter-spacing: 0.04em;
  padding-bottom: 10px; border-bottom: 2px solid var(--fg);
}
.card h3 { margin: 16px 0 8px; font-size: 14px; font-weight: 800; }

.hint { color: var(--muted); font-size: 12px; line-height: 1.55; margin: 0 0 12px; font-weight: 500; }
.err {
  color: var(--fg); font-size: 13px; font-weight: 600;
  margin: 0 0 10px; padding: 8px 10px; border: 2px solid var(--fg); background: var(--soft);
}
.err:empty { display: none; }
.stat-row {
  display: flex; flex-wrap: wrap; gap: 12px 20px; margin-bottom: 12px;
  font-size: 13px; font-weight: 700;
}
.stat-row span { color: var(--muted); font-weight: 600; }
.stat-row b { font-weight: 800; font-variant-numeric: tabular-nums; }

.field { margin-bottom: 14px; }
.field label {
  display: block; font-size: 12px; font-weight: 700; color: var(--muted);
  margin-bottom: 6px; letter-spacing: 0.04em;
}
input[type="text"], select, textarea {
  width: 100%; background: var(--bg); border: 2px solid var(--fg);
  color: var(--fg); padding: 12px 14px; font-size: 16px; outline: none; min-height: var(--tap);
}
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, #000 50%), linear-gradient(135deg, #000 50%, transparent 50%);
  background-position: calc(100% - 18px) calc(50% - 3px), calc(100% - 12px) calc(50% - 3px);
  background-size: 6px 6px, 6px 6px; background-repeat: no-repeat; padding-right: 36px; }
input:focus, select:focus, textarea:focus { background: var(--soft); }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: var(--tap); border: 2px solid var(--fg);
  background: var(--fg); color: var(--bg);
  font-size: 15px; font-weight: 700; cursor: pointer; padding: 0 16px;
}
.btn:active { opacity: 0.85; }
.btn:disabled { opacity: 0.35; cursor: not-allowed; }
.btn.outline { background: var(--bg); color: var(--fg); }
.btn.soft { background: var(--soft); color: var(--fg); }
.btn.block { width: 100%; }
.btn + .btn { margin-left: 8px; }
.row-btns { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.row-btns .btn { margin-left: 0; flex: 1; min-width: 120px; }

.tabs-class {
  display: flex; flex-wrap: wrap; gap: 0; margin-bottom: 10px; border: 2px solid var(--fg);
}
.tabs-class button {
  flex: 1; min-width: 70px; min-height: 40px; border: 0; border-right: 1px solid #ddd;
  background: var(--bg); font-weight: 700; font-size: 13px; cursor: pointer; color: var(--muted);
}
.tabs-class button:last-child { border-right: 0; }
.tabs-class button.active { background: var(--fg); color: var(--bg); }

.person-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 6px;
  max-height: 320px; overflow: auto; border: 2px solid var(--fg); padding: 8px; background: var(--soft);
}
.person-chip {
  display: flex; align-items: center; gap: 6px;
  border: 1.5px solid var(--fg); background: var(--bg); padding: 8px 8px;
  font-size: 13px; font-weight: 600; cursor: pointer; user-select: none;
}
.person-chip.on { background: var(--fg); color: var(--bg); }
.person-chip input { display: none; }

.group-board {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 8px; margin-top: 12px;
}
.group-card {
  border: 2px solid var(--fg); padding: 10px; background: var(--bg);
}
.group-card .gt {
  font-size: 12px; font-weight: 800; letter-spacing: 0.06em; margin-bottom: 6px;
  padding-bottom: 6px; border-bottom: 2px solid var(--fg);
}
.group-card ul { margin: 0; padding: 0; list-style: none; }
.group-card li {
  font-size: 14px; font-weight: 600; padding: 4px 0;
  border-bottom: 1px solid #eee; display: flex; justify-content: space-between; gap: 6px;
}
.group-card li:last-child { border-bottom: 0; }
.group-card .rm {
  appearance: none; border: 0; background: transparent; cursor: pointer;
  font-size: 12px; font-weight: 700; color: var(--muted); padding: 0;
}

.photo-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px;
}
.photo-card {
  border: 2px solid var(--fg); background: var(--bg); overflow: hidden;
}
.photo-card .thumb {
  aspect-ratio: 1; background: var(--soft); border-bottom: 2px solid var(--fg);
  display: flex; align-items: center; justify-content: center; overflow: hidden;
}
.photo-card .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-card .meta { padding: 10px; }
.photo-card .meta .code { font-size: 12px; font-weight: 800; letter-spacing: 0.06em; margin-bottom: 6px; }
.photo-card .meta input {
  width: 100%; min-height: 40px; padding: 8px 10px; font-size: 14px; margin-bottom: 8px;
}
.photo-card .meta .actions { display: flex; gap: 6px; }
.photo-card .meta .actions .btn { flex: 1; min-height: 36px; font-size: 13px; padding: 0 8px; }

.vote-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px;
}
.vote-item {
  border: 2px solid var(--fg); background: var(--bg); cursor: pointer; position: relative;
  overflow: hidden;
}
.vote-item .thumb {
  aspect-ratio: 1; background: var(--soft);
  display: flex; align-items: center; justify-content: center;
}
.vote-item .thumb img { width: 100%; height: 100%; object-fit: cover; }
.vote-item .label {
  padding: 8px; text-align: center; font-weight: 800; font-size: 13px;
  border-top: 2px solid var(--fg); letter-spacing: 0.04em;
}
.vote-item.picked { outline: 3px solid var(--fg); outline-offset: -5px; }
.vote-item .rank-badge {
  position: absolute; top: 8px; left: 8px;
  background: var(--fg); color: var(--bg); font-weight: 800; font-size: 12px;
  padding: 4px 8px; border: 1.5px solid var(--fg); z-index: 2;
}
.pick-bar {
  display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0;
}
.pick-slot {
  flex: 1; min-width: 100px; border: 2px solid var(--fg); padding: 10px;
  text-align: center; background: var(--soft); font-weight: 700; font-size: 13px;
}
.pick-slot.has { background: var(--fg); color: var(--bg); }

.board-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px;
}
.board-card {
  border: 2px solid var(--fg); background: var(--bg); overflow: hidden;
}
.board-card .thumb { aspect-ratio: 4/3; background: var(--soft); border-bottom: 2px solid var(--fg); }
.board-card .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.board-card .info { padding: 12px; }
.board-card .code { font-size: 13px; font-weight: 800; margin-bottom: 4px; }
.board-card .score {
  font-size: 28px; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.1;
}
.board-card .sub { font-size: 12px; color: var(--muted); font-weight: 600; margin-top: 4px; }
.board-card.rank1 { background: var(--fg); color: var(--bg); }
.board-card.rank1 .sub { color: #ccc; }
.board-card.rank1 .thumb { border-bottom-color: #fff; }

.reveal-stage {
  min-height: 60vh; display: flex; flex-direction: column; align-items: center; justify-content: center;
  border: 2px solid var(--fg); background: var(--bg); padding: 24px; text-align: center;
}
.reveal-stage .big-thumb {
  width: min(420px, 90vw); aspect-ratio: 1; border: 2px solid var(--fg);
  background: var(--soft); margin: 0 auto 16px; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
}
.reveal-stage .big-thumb img { width: 100%; height: 100%; object-fit: cover; }
.reveal-stage .spinning { animation: spinPulse 0.35s linear infinite; }
@keyframes spinPulse {
  0% { filter: brightness(1); }
  50% { filter: brightness(0.7); }
  100% { filter: brightness(1); }
}
.reveal-stage .title {
  font-size: clamp(22px, 5vw, 36px); font-weight: 800; letter-spacing: 0.08em; margin: 0 0 8px;
}
.reveal-stage .name {
  font-size: clamp(28px, 6vw, 48px); font-weight: 800; margin: 0 0 8px;
}
.reveal-stage .pts { font-size: 16px; font-weight: 700; color: var(--muted); }

.rank-list { margin-top: 16px; }
.rank-row {
  display: grid; grid-template-columns: 64px 96px 1fr auto; gap: 12px; align-items: center;
  border: 2px solid var(--fg); margin-bottom: 8px; padding: 8px; background: var(--bg);
}
.rank-row .rk {
  font-size: 22px; font-weight: 800; text-align: center;
}
.rank-row .rk-img {
  width: 96px; height: 72px; border: 2px solid var(--fg); overflow: hidden; background: var(--soft);
}
.rank-row .rk-img img { width: 100%; height: 100%; object-fit: cover; }
.rank-row .rk-name { font-size: 18px; font-weight: 800; }
.rank-row .rk-pts { font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums; }
.rank-row.first { background: var(--fg); color: var(--bg); }
.rank-row.first .rk-img { border-color: #fff; }

.detail-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.detail-table th, .detail-table td {
  border: 1.5px solid var(--fg); padding: 8px 10px; text-align: left; font-weight: 600;
}
.detail-table th { background: var(--soft); font-weight: 800; }
.detail-table td.mono { font-variant-numeric: tabular-nums; }

.file-btn { position: relative; overflow: hidden; }
.file-btn input[type="file"] {
  position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%;
}

@media (max-width: 640px) {
  .app { padding: 12px 10px 20px; }
  .rank-row { grid-template-columns: 48px 72px 1fr; }
  .rank-row .rk-pts { grid-column: 2 / -1; }
}

.gate {
  max-width: 420px; margin: 40px auto; padding: 0 12px;
}
.gate .card { margin-bottom: 16px; }
.share-box {
  border: 2px solid var(--fg); background: var(--soft); padding: 12px;
  font-size: 13px; font-weight: 600; word-break: break-all; margin: 8px 0 12px;
}
.share-box code { font-size: 22px; font-weight: 800; letter-spacing: 0.12em; display: block; margin-top: 6px; }
.sync-dot {
  display: inline-block; width: 8px; height: 8px; background: var(--fg); margin-right: 6px;
  vertical-align: middle;
}
.sync-dot.off { opacity: 0.25; }
.role-tag { font-size: 11px; font-weight: 700; color: var(--muted); margin-left: 6px; }
body.gate-mode { padding-bottom: var(--safe-b); }
body.gate-mode .bottom-nav { display: none; }
.export-pre {
  border: 2px solid var(--fg); background: var(--soft); padding: 12px;
  font-size: 12px; font-family: ui-monospace, monospace; white-space: pre-wrap;
  max-height: 280px; overflow: auto; margin-top: 10px;
}

/* Public voter list: voted marker */
.tag-voted {
  display: inline-block;
  margin-left: 4px;
  padding: 1px 6px;
  border: 1.5px solid var(--fg);
  background: var(--fg);
  color: var(--bg);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.04em;
  vertical-align: middle;
}


/* History list */
.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.history-item {
  display: block;
  width: 100%;
  text-align: left;
  background: #111;
  color: #fff;
  border: 2px solid #fff;
  border-radius: 0;
  padding: 12px 14px;
  cursor: pointer;
  font: inherit;
}
.history-item:active { background: #222; }
.hi-actions {
  margin-top: 10px;
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}
.hi-actions .hi-del {
  padding: 6px 12px;
  font-size: 13px;
}
.hi-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  letter-spacing: 0.04em;
}
.hi-phase {
  font-size: 12px;
  font-weight: 700;
  border: 1px solid #fff;
  padding: 2px 8px;
}
.hi-meta {
  margin-top: 6px;
  font-size: 12px;
  opacity: 0.75;
  font-weight: 600;
}
.hi-sum {
  margin-top: 6px;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.35;
}
