:root {
  --bg: #f6f8fa;
  --card: #ffffff;
  --ink: #1a1a2e;
  --muted: #6b7280;
  --primary: #2563eb;
  --ok: #16a34a;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky; top: 0; z-index: 1500;
  background: var(--primary); color: #fff;
  padding: 14px 16px;
  padding-top: calc(14px + env(safe-area-inset-top));
  box-shadow: 0 2px 8px rgba(0, 0, 0, .15);
}
.topbar h1 { margin: 0; font-size: 1.25rem; font-weight: 700; }

main { flex: 1; max-width: 640px; width: 100%; margin: 0 auto; padding: 16px; }

.upload { margin-bottom: 12px; }
.merge-help {
  margin: 0 0 8px; padding: 8px 12px;
  background: var(--card); border: 1px solid #d1d5db; border-radius: 8px;
  font-size: 0.85rem; color: var(--muted);
}
.merge-help a { color: var(--primary); font-weight: 600; }
.file-btn {
  display: block; width: 100%; text-align: center;
  background: var(--primary); color: #fff; border-radius: 10px;
  padding: 14px; font-weight: 600; cursor: pointer;
  transition: filter .15s ease, transform .15s ease;
}
.file-btn:hover { filter: brightness(0.93); transform: translateY(-1px); }
.status { min-height: 1.2em; color: var(--muted); font-size: 0.9rem; margin: 8px 0 0; }
.status.error { color: #dc2626; }

.map-wrap { border-radius: 12px; overflow: hidden; box-shadow: 0 1px 3px rgba(0,0,0,.12); }
#map { height: 55vh; min-height: 320px; width: 100%; }

.results, .submit { margin-top: 20px; }
.results h2, .submit h2 { font-size: 1.1rem; margin: 0 0 8px; }
.result-box {
  background: var(--card); color: var(--ink);
  border: 1px solid #d1d5db; border-radius: 12px; padding: 16px 20px;
  font-size: 1.25rem; font-weight: 700; text-align: center;
  margin-bottom: 16px;
}
.list { list-style: none; padding: 0; margin: 0; }

.location {
  background: var(--card); border-radius: 10px; padding: 12px;
  margin-bottom: 10px; box-shadow: 0 1px 2px rgba(0,0,0,.08);
}
.location .name { font-weight: 600; }
.location.empty { color: var(--muted); font-style: italic; }
.location .pts { color: var(--ok); font-weight: 600; }
.location .modes { display: flex; gap: 12px; margin-top: 8px; }
.location .modes label {
  display: flex; align-items: center; gap: 6px;
  border: 1px solid #d1d5db; border-radius: 8px; padding: 8px 12px;
  flex: 1; justify-content: center; font-size: 0.95rem;
}
.location .modes input { width: 20px; height: 20px; accent-color: var(--primary); }

.submit form { display: flex; flex-direction: column; gap: 10px; }
.submit input {
  padding: 14px; border: 1px solid #d1d5db; border-radius: 10px;
  font-size: 1rem;
}
.btn-primary {
  background: var(--primary); color: #fff; border: none; border-radius: 10px;
  padding: 15px; font-size: 1.05rem; font-weight: 700; cursor: pointer;
  transition: filter .15s ease, transform .15s ease;
}
.btn-primary:hover { filter: brightness(0.93); transform: translateY(-1px); }
#form-status { color: var(--muted); margin: 10px 0 0; font-size: 0.9rem; }
.alert.error {
  background: #fef2f2; color: #dc2626; border: 1px solid #fecaca;
  border-radius: 8px; padding: 10px 12px; font-size: 0.9rem;
  white-space: pre-line;
}
.alert:empty { display: none; }
.alert.success {
  background: #f0fdf4; color: #16a34a; border: 1px solid #bbf7d0;
  border-radius: 8px; padding: 10px 12px; font-size: 0.9rem;
}
.bonuses { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.bonus {
  display: flex; align-items: center; gap: 8px;
  background: var(--card); border: 1px solid #d1d5db; border-radius: 10px;
  padding: 12px; font-size: 1rem;
}
.bonus input { width: 20px; height: 20px; accent-color: var(--primary); }
.back-link {
  display: inline-block; color: #fff; text-decoration: none;
  font-size: 0.9rem; margin-bottom: 6px; opacity: 0.9;
}
.back-link:hover { opacity: 1; text-decoration: underline; }
.identity {
  background: var(--card); border: 1px solid #d1d5db; border-radius: 10px;
  padding: 12px 14px; margin-bottom: 12px; font-weight: 600;
}
.filter-bar {
  display: flex; align-items: center; gap: 8px; margin-bottom: 12px;
}
.filter-bar input[type="search"] {
  flex: 1; padding: 12px 14px; border: 1px solid #d1d5db; border-radius: 10px;
  font-size: 1rem;
}
.btn-clear {
  background: #f3f4f6; color: #374151; border: 1px solid #d1d5db;
  border-radius: 10px; padding: 12px 16px; font-size: 0.95rem;
  font-weight: 600; cursor: pointer; white-space: nowrap;
}
.btn-clear:hover { background: #e5e7eb; }
.admin-table {
  width: 100%; border-collapse: collapse; margin-bottom: 16px;
  background: var(--card); border-radius: 10px; overflow: hidden;
}
.admin-table.leaderboard { table-layout: fixed; }
.admin-table.leaderboard th:first-child, .admin-table.leaderboard td:first-child { width: 12%; text-align: center; }
.admin-table.leaderboard .rank { width: 12%; text-align: center; color: var(--muted); font-weight: 600; }
.admin-table.leaderboard .score { width: 30%; text-align: right; font-weight: 700; }
.admin-table.leaderboard .eye { width: 6%; text-align: center; }
.admin-table.leaderboard th.rank { text-align: center; }
.admin-table.leaderboard th.score { text-align: right; }
.admin-table th, .admin-table td {
  padding: 12px; text-align: left; border-bottom: 1px solid #e5e7eb;
}
.admin-table th.score, .admin-table .score { text-align: right; }
.admin-table th { background: #f3f4f6; }
.admin-table tr.clickable { cursor: pointer; }
.admin-table tr.clickable:hover { background: #f9fafb; }
.admin-table .score { text-align: right; font-weight: 700; }
.detail-table td.modes { white-space: nowrap; display: flex; flex-direction: column; gap: 6px; }
.detail-table td.modes label { display: flex; align-items: center; gap: 6px; }
.detail-table .row-visited td { background: #f0fdf4; }
.detail-table .row-missed td { background: #fef2f2; }
.admin-actions { display: flex; gap: 10px; margin-top: 8px; }
.btn-update {
  background: var(--primary); color: #fff; border: none; border-radius: 10px;
  padding: 14px 18px; font-size: 1rem; font-weight: 700; cursor: pointer; flex: 1;
  transition: filter .15s ease, transform .15s ease;
}
.btn-update:hover { filter: brightness(0.93); transform: translateY(-1px); }
.btn-danger {
  background: #dc2626; color: #fff; border: none; border-radius: 10px;
  padding: 14px 18px; font-size: 1rem; font-weight: 700; cursor: pointer;
  transition: filter .15s ease, transform .15s ease;
}
.btn-danger:hover { filter: brightness(0.9); transform: translateY(-1px); }
.btn-secondary {
  background: #e5e7eb; color: var(--ink); border: none; border-radius: 8px;
  padding: 10px 16px; font-size: 0.95rem; font-weight: 600; cursor: pointer;
  transition: background .15s ease;
}
.btn-secondary:hover { background: #d1d5db; }
.modal-backdrop[hidden] { display: none; }
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.4);
  display: flex; align-items: center; justify-content: center; z-index: 2000;
}
.modal {
  background: #fff; border-radius: 12px; padding: 20px; max-width: 360px; width: 90%;
  box-shadow: 0 10px 30px rgba(0,0,0,.25);
}
.modal p { margin: 0 0 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
.recap {
  background: linear-gradient(135deg, #16a34a, #15803d);
  color: #fff; border-radius: 12px; padding: 18px 20px;
  margin: 16px 0; box-shadow: 0 4px 12px rgba(22, 163, 74, .25);
}
.recap-score { font-size: 1.35rem; font-weight: 700; margin-bottom: 6px; }
.recap-rank { font-size: 1.05rem; opacity: .95; }
