:root {
  --bg: #f6f3ec;
  --panel: #ffffff;
  --text: #22201b;
  --muted: #6d675b;
  --line: #e4ddcf;
  --accent: #9a6b12;
  --accent-soft: #f3e6c8;
  --gold: #c9971f;
  --silver: #8d96a0;
  --bronze: #a8653a;
  --danger: #b3261e;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15140f;
    --panel: #1f1d17;
    --text: #ece6d8;
    --muted: #a59d8b;
    --line: #34302a;
    --accent: #e0b04a;
    --accent-soft: #3a3020;
    --danger: #ff8a80;
  }
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
header {
  display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: 12px;
  padding: 20px 24px 0; border-bottom: 1px solid var(--line); background: var(--panel);
}
.brand { display: flex; gap: 12px; align-items: center; padding-bottom: 12px; }
.crest { font-size: 28px; color: var(--accent); }
h1 { margin: 0; font-size: 22px; }
h2 { font-size: 16px; margin: 0 0 8px; }
.sub { margin: 0; color: var(--muted); font-size: 13px; }
nav { display: flex; gap: 4px; flex-wrap: wrap; }
nav button {
  border: 0; background: none; color: var(--muted); padding: 10px 14px; cursor: pointer;
  border-bottom: 3px solid transparent; font: inherit; font-weight: 600;
}
nav button.active { color: var(--text); border-bottom-color: var(--accent); }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 14px 24px; }
.spacer { flex: 1; }
main { padding: 0 24px 40px; max-width: 1200px; }
.tab { display: none; }
.tab.active { display: block; }
label { color: var(--muted); font-size: 13px; display: inline-flex; gap: 6px; align-items: center; }
input, select, button, .button {
  font: inherit; color: var(--text); background: var(--panel);
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px;
}
button, .button { cursor: pointer; background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600; text-decoration: none; display: inline-block; }
button.ghost, .button.ghost { background: var(--panel); color: var(--text); border-color: var(--line); }
button.danger { background: none; color: var(--danger); border-color: transparent; padding: 4px 8px; }
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-bottom: 12px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat span { display: block; font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.table-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: var(--panel); position: sticky; top: 0; }
tr:last-child td { border-bottom: 0; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.rank { font-weight: 700; width: 3em; }
.rank-1 { color: var(--gold); } .rank-2 { color: var(--silver); } .rank-3 { color: var(--bronze); }
.points { font-weight: 700; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { background: var(--accent-soft); border-radius: 999px; padding: 1px 8px; font-size: 12px; white-space: nowrap; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.warn { color: var(--danger); font-size: 12px; }
.empty { color: var(--muted); text-align: center; padding: 30px; }
.help { color: var(--muted); max-width: 70ch; }
.tester { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
td input, td select { width: 100%; padding: 4px 6px; }
td input.small { width: 5.5em; }
body:not(.admin) .admin-only { display: none !important; }
#toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px;
}
@media (max-width: 720px) {
  header, .toolbar, main { padding-left: 16px; padding-right: 16px; }
  .two-col { grid-template-columns: 1fr; }
  .stat span { font-size: 20px; }
}

.notice { border: 1px solid var(--gold); background: var(--accent-soft); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 14px; }
.notice .table-wrap { background: var(--panel); }
.paste { margin-top: 16px; }
.paste summary { cursor: pointer; font-weight: 600; }
textarea { width: 100%; font: 13px/1.4 ui-monospace, Consolas, monospace; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px; margin-top: 8px; }
.cat { font-size: 12px; color: var(--muted); }

tr.idle td { color: var(--muted); }
tr.idle td.points { font-weight: 400; }
.small-note { font-size: 12px; }

/* Sign-in and clan screens */
.gate { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.card { width: min(420px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; }
.card h1 { margin-bottom: 4px; }
.stack { display: grid; gap: 12px; margin-top: 14px; }
.stack label { display: grid; gap: 4px; }
.stack input { width: 100%; }
.seg { display: flex; gap: 4px; margin-top: 16px; border-bottom: 1px solid var(--line); }
.seg button { background: none; color: var(--muted); border: 0; border-bottom: 3px solid transparent; border-radius: 0; padding: 8px 12px; }
.seg button.active { color: var(--text); border-bottom-color: var(--accent); }
#clanSelect { max-width: 16em; }

/* Clan admin */
.admin-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 12px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.panel .actions { align-items: center; }
code.big { font-size: 17px; padding: 6px 10px; background: var(--accent-soft); border-radius: 6px; letter-spacing: .05em; word-break: break-all; }
code.secret { font-size: 13px; letter-spacing: 0; }
td select.role { width: auto; }
.you { font-size: 12px; color: var(--muted); }

[hidden] { display: none !important; }

/* Your clans */
.card.wide { width: min(640px, 100%); }
.row-between { display: flex; justify-content: space-between; align-items: start; gap: 12px; }
.clan-list { display: grid; gap: 8px; margin: 14px 0; }
.clan-item { display: flex; align-items: center; justify-content: space-between; gap: 10px; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.clan-item .role-tag { font-size: 12px; color: var(--muted); }
.home-forms { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; border-top: 1px solid var(--line); padding-top: 6px; }
.home-forms h2 { margin: 6px 0 0; }
.link-box { width: 100%; font: 13px ui-monospace, Consolas, monospace; }
@media (max-width: 600px) { .home-forms { grid-template-columns: 1fr; } }
.home-forms form { align-content: start; }

/* live-update indicator */
.live { font-size: 12px; color: var(--muted); display: inline-flex; align-items: center; gap: 5px; }
.live::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--line); }
.live.on::before { background: #2e9d4f; box-shadow: 0 0 0 3px rgba(46,157,79,.18); }
