:root {
  --bg: #f4f5f2;
  --surface: #ffffff;
  --surface-2: #eef0ec;
  --text: #1c211d;
  --muted: #5f685f;
  --border: #d9ddd6;
  --accent: #2f6f3e;
  --accent-text: #ffffff;
  --danger: #b3261e;
  --warn: #9a6700;
  --ok: #1f7a3a;
  --radius: 12px;
  --shadow: 0 1px 2px rgb(0 0 0 / 6%), 0 2px 8px rgb(0 0 0 / 5%);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121512;
    --surface: #1b1f1b;
    --surface-2: #232823;
    --text: #e8ece6;
    --muted: #9ba59a;
    --border: #2f362f;
    --accent: #5fb173;
    --accent-text: #0d140f;
    --danger: #f2766c;
    --warn: #e0b04a;
    --ok: #6ccf87;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.1rem; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.hidden { display: none !important; }
.num { font-variant-numeric: tabular-nums; }

header.bar {
  display: flex; align-items: center; gap: .75rem; flex-wrap: wrap;
  padding: .75rem 1rem; background: var(--surface); border-bottom: 1px solid var(--border);
}
header.bar h1 { margin: 0; flex: 1; min-width: 0; }

main { padding: 1rem; max-width: 1400px; margin: 0 auto; }
main.narrow { max-width: 560px; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem; box-shadow: var(--shadow); margin-bottom: 1rem;
}

.badge {
  display: inline-flex; align-items: center; gap: .35rem; padding: .2rem .6rem; border-radius: 999px;
  font-size: .8rem; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.badge.running { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.badge.paused { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.badge.ended { background: color-mix(in srgb, var(--danger) 15%, transparent); color: var(--danger); }

.dot { width: .85rem; height: .85rem; border-radius: 50%; display: inline-block; flex: none; border: 2px solid rgb(255 255 255 / 70%); box-shadow: 0 0 0 1px rgb(0 0 0 / 15%); }

button, .button {
  font: inherit; font-weight: 600; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); padding: .6rem 1rem; cursor: pointer;
  text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
}
button:hover:not(:disabled) { filter: brightness(.97); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
button.ghost { background: transparent; }
button.small { padding: .3rem .6rem; font-size: .85rem; }
button.big { width: 100%; padding: 1rem; font-size: 1.1rem; }

input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: .5rem .6rem; width: 100%;
}
input[type="color"] { padding: 2px; height: 2.4rem; width: 3rem; }
input[type="checkbox"] { width: auto; }
label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: .2rem; }
.field { margin-bottom: .75rem; }
.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.row > .grow { flex: 1; min-width: 8rem; }
.grid-form { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: .25rem 1rem; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .45rem .5rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: .8rem; color: var(--muted); font-weight: 600; }
.table-wrap { overflow-x: auto; }

.map { height: 420px; border-radius: var(--radius); border: 1px solid var(--border); z-index: 0; }

/* toast */
#toast {
  position: fixed; left: 50%; bottom: 1.25rem; transform: translateX(-50%); z-index: 1000;
  display: flex; flex-direction: column; gap: .5rem; width: min(92vw, 440px);
}
#toast div {
  background: var(--text); color: var(--bg); padding: .75rem 1rem; border-radius: 10px; box-shadow: var(--shadow);
  font-weight: 500; animation: pop .2s ease-out;
}
#toast div.error { background: var(--danger); color: #fff; }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }

/* map markers */
.flag-marker { background: none; border: none; }
.flag-marker svg { filter: drop-shadow(0 1px 1px rgb(0 0 0 / 40%)); }
.team-marker {
  border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 0 1px rgb(0 0 0 / 35%), 0 1px 4px rgb(0 0 0 / 40%);
}

/* ---------- dashboard ---------- */
.dash { display: grid; grid-template-columns: minmax(320px, 1fr) 1.4fr; gap: 1rem; align-items: start; }
.dash .map { height: calc(100vh - 230px); min-height: 380px; }
@media (max-width: 900px) {
  .dash { grid-template-columns: 1fr; }
  .dash .map { height: 55vh; }
}
.scoreboard { list-style: none; margin: 0; padding: 0; }
.scoreboard li {
  display: grid; grid-template-columns: 2.2rem 1fr auto; gap: .25rem .75rem; align-items: center;
  padding: .7rem .25rem; border-bottom: 1px solid var(--border);
}
.scoreboard li:last-child { border-bottom: none; }
.scoreboard .rank { font-size: 1.3rem; font-weight: 800; text-align: center; color: var(--muted); }
.scoreboard li:first-child .rank { color: #c99a06; }
.scoreboard .name { font-weight: 700; font-size: 1.1rem; display: flex; align-items: center; gap: .5rem; min-width: 0; }
.scoreboard .name span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scoreboard .score { font-size: 1.6rem; font-weight: 800; text-align: right; }
.scoreboard .meta { grid-column: 2 / 4; font-size: .82rem; color: var(--muted); display: flex; gap: .9rem; flex-wrap: wrap; }
.scoreboard .bar { grid-column: 2 / 4; height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.scoreboard .bar i { display: block; height: 100%; border-radius: 3px; transition: width .6s ease; }

.feed { list-style: none; margin: 0; padding: 0; max-height: 340px; overflow-y: auto; }
.feed li { display: flex; gap: .6rem; padding: .45rem 0; border-bottom: 1px solid var(--border); font-size: .92rem; align-items: baseline; }
.feed time { color: var(--muted); font-size: .8rem; flex: none; width: 3.2rem; }
.feed .pts { margin-left: auto; font-weight: 700; flex: none; }
.pts.plus { color: var(--ok); }
.pts.minus { color: var(--danger); }

.flags { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .5rem; }
.flags div { border: 1px solid var(--border); border-left: 6px solid var(--border); border-radius: 8px; padding: .4rem .6rem; font-size: .88rem; }

/* ---------- claim / hunter ---------- */
.team-choices { display: grid; gap: .6rem; }
.team-choice {
  display: flex; align-items: center; gap: .75rem; width: 100%; text-align: left; padding: .9rem 1rem;
  border: 2px solid var(--border); border-radius: var(--radius); background: var(--surface); font-size: 1.1rem;
}
.team-choice .dot { width: 1.3rem; height: 1.3rem; }
.team-choice .hint { margin-left: auto; font-size: .8rem; color: var(--ok); font-weight: 600; }
.team-choice.selected { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 30%, transparent); }
.team-choice .sub { display: block; font-size: .8rem; color: var(--muted); font-weight: 500; }

.hero { text-align: center; padding: 1.5rem 1rem; }
.hero .big-icon { font-size: 3.5rem; line-height: 1; margin-bottom: .5rem; }
.hero h1 { font-size: 1.6rem; }
.owner-chip { display: inline-flex; align-items: center; gap: .4rem; font-weight: 700; }

.notice { padding: .75rem 1rem; border-radius: 10px; background: var(--surface-2); margin-bottom: 1rem; }
.notice.warn { background: color-mix(in srgb, var(--warn) 15%, transparent); }
.notice.error { background: color-mix(in srgb, var(--danger) 14%, transparent); }
.notice.ok { background: color-mix(in srgb, var(--ok) 14%, transparent); }

/* ---------- admin ---------- */
.tabs { display: flex; gap: .25rem; overflow-x: auto; padding: 0 1rem; background: var(--surface); border-bottom: 1px solid var(--border); }
.tabs button { border: none; background: none; border-bottom: 3px solid transparent; border-radius: 0; padding: .75rem .9rem; color: var(--muted); }
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); }
.state-buttons { display: flex; gap: .5rem; flex-wrap: wrap; }
.admin-cols { display: grid; grid-template-columns: 1.3fr 1fr; gap: 1rem; }
@media (max-width: 1000px) { .admin-cols { grid-template-columns: 1fr; } }
tr.voided td { text-decoration: line-through; opacity: .5; }
tr.voided td:last-child { text-decoration: none; opacity: 1; }

/* ---------- QR print sheet ---------- */
.qr-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1rem; }
.qr-card {
  border: 2px dashed #999; border-radius: 12px; padding: 1.25rem; text-align: center; background: #fff; color: #111;
  break-inside: avoid; page-break-inside: avoid;
}
.qr-card img { width: 70%; max-width: 280px; aspect-ratio: 1; }
.qr-card h2 { font-size: 1.6rem; margin: .25rem 0; }
.qr-card .url { font-size: .7rem; color: #555; word-break: break-all; }
@media print {
  .no-print { display: none !important; }
  body { background: #fff; }
  main { max-width: none; padding: 0; }
}
