/* Layout and controls follow Hub's styles.css; colours are Battle Ground Lords'. */
:root {
  --accent: #E8420A;
  --accent-dark: #b8330a;
  --accent-tint: #fdeee7;
  --ink: #1e1b2e;
  --night: #1e1b2e;
  --muted: #6c6a7a;
  --line: #e4e2ec;
  --bg: #f6f5fa;
  --card: #ffffff;
  --danger: #b4453a;
  --ok: #2c8a4b;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 8px 24px rgba(0,0,0,.04);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: "DM Sans", system-ui, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

code, .mono, .num { font-family: "DM Mono", ui-monospace, monospace; }

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  border-radius: 8px;
  padding: .6rem 1rem;
  font-size: .92rem;
  font-weight: 500;
  transition: background .15s, opacity .15s;
}
button:disabled { opacity: .6; cursor: default; }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-dark); }
.btn-ghost { background: transparent; color: var(--muted); padding: .4rem .6rem; }
.btn-ghost:hover { color: var(--danger); }
.btn-outline { background: transparent; border: 1px solid var(--line); color: var(--ink); }
.btn-outline:hover { border-color: var(--accent); color: var(--accent); }

input, select {
  font-family: inherit;
  font-size: .92rem;
  padding: .55rem .65rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  width: 100%;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
label { display: block; font-size: .78rem; color: var(--muted); margin-bottom: .25rem; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; align-items: start; padding: 10vh 1rem 1rem; background: var(--night); }
.login-card {
  width: 100%; max-width: 360px; background: var(--card);
  padding: 2rem; border-radius: var(--radius); box-shadow: var(--shadow);
}
.brand { font-family: "DM Mono", monospace; font-size: 1.4rem; font-weight: 500; letter-spacing: -.02em; }
.brand .dot { color: var(--accent); }
.login-card h1 { font-size: 1.05rem; margin: 1.2rem 0 .25rem; }
.login-card p.sub { color: var(--muted); font-size: .85rem; margin: 0 0 1.4rem; }
.field { margin-bottom: .9rem; }
.msg { font-size: .82rem; margin-top: .8rem; min-height: 1rem; }
.msg.error { color: var(--danger); }
.msg.ok { color: var(--ok); }
.forgot-link {
  display: block; width: 100%; margin-top: .9rem;
  background: none; border: none; padding: 0;
  font-size: .82rem; color: var(--muted); text-align: center; cursor: pointer;
}
.forgot-link:hover { color: var(--accent); }
.login-wrap .login-card + .login-card { margin-top: 1rem; }

/* ---------- Change password ---------- */
#change-pw-form { padding: .4rem .5rem .2rem; }
.chpw-field { margin-bottom: .45rem; }
.chpw-field input { font-size: .8rem; padding: .45rem .6rem; }
.chpw-save { flex: 1; font-size: .82rem; padding: .45rem; margin-top: .1rem; }
.chpw-cancel {
  margin-top: .1rem; padding: .45rem .6rem; font-size: .82rem;
  background: transparent; border: 1px solid var(--line); color: var(--muted);
}
.chpw-cancel:hover { border-color: var(--danger); color: var(--danger); }

/* ---------- App shell ---------- */
.app { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--card); border-right: 1px solid var(--line);
  padding: 1.4rem 1rem; display: flex; flex-direction: column; gap: .2rem;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar .brand { padding: 0 .6rem 1.2rem; }
.nav-item {
  display: block; width: 100%; text-align: left; background: transparent;
  color: var(--ink); padding: .55rem .6rem; border-radius: 8px; font-weight: 500;
}
.nav-item:hover { background: var(--bg); }
.nav-item.active { background: var(--accent-tint); color: var(--accent-dark); }
.nav-sub { padding-left: 1.4rem; font-size: .85rem; color: var(--muted); }
.nav-sub.active { color: var(--accent-dark); }
.nav-label { font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); padding: .6rem .6rem .2rem; }
.sidebar .spacer { flex: 1; }
.user-row { font-size: .78rem; color: var(--muted); padding: 0 .6rem .5rem; word-break: break-all; display: flex; align-items: center; gap: .45rem; }
.user-row .swatch { flex-shrink: 0; }

.main { padding: 2rem 2.4rem; max-width: 900px; width: 100%; }
.view-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; margin-bottom: 1.4rem; }
.view-head h2 { margin: 0; font-size: 1.4rem; letter-spacing: -.01em; }
.view-head .eyebrow { font-family: "DM Mono", monospace; font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; color: var(--accent); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.4rem; box-shadow: var(--shadow); }
.card + .card { margin-top: 1.2rem; }
.card h3 { margin: 0 0 1rem; font-size: 1rem; }
.card p { line-height: 1.5; }

.empty { text-align: center; color: var(--muted); padding: 2.4rem 1rem; font-size: .9rem; line-height: 1.5; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: .7rem; }
.stat-box { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: .7rem .9rem; }
.stat-k { font-size: .68rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin-bottom: .25rem; }
.stat-v { font-family: "DM Mono", monospace; font-size: 1.4rem; font-weight: 500; }

/* ---------- Colour swatches ---------- */
.swatch {
  display: inline-block; width: 14px; height: 16px;
  clip-path: polygon(25% 0, 75% 0, 100% 50%, 75% 100%, 25% 100%, 0 50%);
}
.swatches { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: .8rem; }
.swatch-btn {
  position: relative; width: 44px; height: 44px; padding: 0; border-radius: 10px;
  border: 2px solid transparent; background: var(--bg);
  display: grid; place-items: center;
}
.swatch-btn .swatch { width: 28px; height: 32px; }
.swatch-btn.selected { border-color: var(--ink); }
.swatch-btn.taken::after {
  content: ""; position: absolute; inset: 6px; border-radius: 6px;
  background: repeating-linear-gradient(45deg, transparent 0 5px, rgba(255,255,255,.75) 5px 7px);
  pointer-events: none;
}
.custom-colour { display: flex; align-items: center; gap: .6rem; font-size: .85rem; color: var(--muted); }
.custom-colour input[type=color] { width: 44px; height: 36px; padding: 2px; cursor: pointer; }
.hint { font-size: .8rem; color: var(--muted); margin: .3rem 0 0; min-height: 1rem; }

.row-actions { display: flex; gap: .6rem; align-items: center; margin-top: 1.2rem; }
.row-actions .msg { margin-top: 0; }

/* ---------- Badges ---------- */
.badge { display: inline-block; font-size: .68rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; padding: .15rem .45rem; border-radius: 5px; white-space: nowrap; }
.badge-muted { background: var(--bg); color: var(--muted); border: 1px solid var(--line); }
.badge-ok    { background: #e6f4ea; color: var(--ok); }
.badge-bad   { background: #fbe9e7; color: var(--danger); }
.badge-drawn { background: #fff4d6; color: #8a5a00; }

/* ---------- Upload ---------- */
.lead { margin: 0 0 1rem; color: var(--ink); line-height: 1.5; }
.file-pick { display: flex; align-items: center; gap: .8rem; flex-wrap: wrap; margin: 0 0 1rem; cursor: pointer; font-size: .92rem; color: var(--ink); }
.file-pick input[type=file] { position: absolute; width: 1px; height: 1px; opacity: 0; }
.file-pick:focus-within .file-btn { outline: 2px solid var(--accent); outline-offset: 2px; }
.file-btn { display: inline-block; padding: .6rem 1rem; border-radius: 8px; font-weight: 500; }
.file-name { color: var(--muted); font-size: .85rem; word-break: break-all; }
.preview-stats { margin-bottom: .9rem; }
.stat-v.small { font-size: .9rem; line-height: 1.35; padding-top: .2rem; }
.verdict { border-radius: 8px; padding: .75rem .9rem; font-size: .9rem; line-height: 1.45; }
.verdict.ok  { background: #e6f4ea; color: var(--ok); }
.verdict.bad { background: #fbe9e7; color: var(--danger); }
.verdict-note { color: var(--muted); font-size: .82rem; margin-top: .3rem; }
.card.result { margin-top: 1.2rem; }
.card.result.ok  { border-color: #b9dfc4; }
.card.result.bad { border-color: #f1c4bd; }
.card.result p { margin: 0 0 .4rem; }

/* ---------- Runs ---------- */
.run-list { display: flex; flex-direction: column; gap: .7rem; }
.run-row { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .9rem 1.1rem; box-shadow: var(--shadow); }
.run-top { display: flex; align-items: center; gap: .45rem; flex-wrap: wrap; margin-bottom: .35rem; }
.run-date { font-weight: 600; font-size: .92rem; margin-right: .25rem; }
.run-stats { display: flex; flex-wrap: wrap; gap: .3rem 1rem; font-family: "DM Mono", monospace; font-size: .82rem; color: var(--muted); }
.run-outcome { margin-top: .45rem; font-size: .88rem; }
.run-outcome.bad { color: var(--danger); }
.empty a { color: var(--accent); }
.run-when { color: var(--muted); font-size: .85rem; margin-right: .2rem; }
.run-meta { margin-top: .35rem; font-size: .76rem; color: var(--muted); word-break: break-all; }
.run-meta code { font-size: .74rem; }
.list-hint { margin: -.6rem 0 .8rem; }

/* ---------- Admin ---------- */
.invite-row { display: flex; gap: .5rem; }
.invite-row input { flex: 1; min-width: 0; }
.invite-row button { white-space: nowrap; }
.invitee { display: flex; align-items: center; gap: .8rem; padding: .65rem 0; border-bottom: 1px solid var(--line); }
.invitee:last-of-type { border-bottom: none; }
.invitee-main { flex: 1; min-width: 0; }
.invitee-email { font-weight: 500; font-size: .9rem; word-break: break-all; }
.invitee-state { font-size: .8rem; color: var(--muted); margin-top: .1rem; }
.invitee-state.joined { color: var(--ok); }
.invitee-state.pending { color: #8a5a00; }
.invitee-state.expired { color: var(--danger); font-weight: 600; }
.invitee-resend { padding: .4rem .8rem; font-size: .82rem; flex-shrink: 0; }

/* ---------- Leaderboard ---------- */
.table-card { padding: .4rem .4rem .8rem; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th { text-align: left; font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: .6rem .7rem; border-bottom: 1px solid var(--line); }
td { padding: .7rem .7rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
td.num, th.num { text-align: right; font-family: "DM Mono", monospace; white-space: nowrap; }
tr:last-child td { border-bottom: none; }
.lb-row { cursor: pointer; }
.lb-row:hover, .lb-row:focus-visible { background: var(--bg); outline: none; }
.lb-row.me { background: var(--accent-tint); }
.lb-row .rank { color: var(--muted); width: 2.5rem; }
.lb-player { display: flex; align-items: center; gap: .45rem; flex-wrap: wrap; }
.lb-name { font-weight: 500; }
.table-hint { padding: 0 .7rem; }

/* ---------- Map ---------- */
.main.map-mode { padding: 0; max-width: none !important; height: 100vh; height: 100dvh; }
.map-wrap { position: relative; width: 100%; height: 100%; }
.gmap { position: absolute; inset: 0; background: #e8e6ef; }
.map-notice {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 5;
  background: var(--card); color: var(--ink); box-shadow: 0 2px 10px rgba(0,0,0,.15);
  padding: .45rem .95rem; border-radius: 999px; font-size: .85rem; text-align: center;
  max-width: calc(100% - 120px);
}
.map-notice.error { color: var(--danger); border-radius: 12px; }
.map-btn {
  position: absolute; top: 12px; right: 12px; z-index: 5; width: 42px; height: 42px; padding: 0;
  background: var(--card); box-shadow: 0 2px 10px rgba(0,0,0,.15); font-size: 1.15rem;
}
.map-btn:hover { background: var(--bg); }
/* Sits above Google's logo and terms, which must stay visible. */
.map-legend {
  position: absolute; left: 10px; bottom: 34px; z-index: 5; min-width: 150px; max-width: 230px;
  background: var(--card); box-shadow: 0 2px 10px rgba(0,0,0,.15); border-radius: 10px;
  padding: .55rem .75rem; font-size: .8rem;
}
.legend-title { font-size: .66rem; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin-bottom: .3rem; }
.legend-row { display: flex; align-items: center; gap: .4rem; padding: .12rem 0; }
.legend-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend-count { margin-left: auto; padding-left: .6rem; font-family: "DM Mono", monospace; color: var(--muted); }
.legend-note, .legend-empty { color: var(--muted); font-size: .75rem; margin-top: .25rem; line-height: 1.4; }
.legend-empty { margin-top: 0; }
/* ---------- Draw run panel ---------- */
.draw-panel {
  position: absolute; top: 12px; left: 12px; z-index: 6; width: 340px; max-height: calc(100% - 60px); overflow-y: auto;
  background: var(--card); border-radius: 12px; box-shadow: 0 4px 18px rgba(0,0,0,.18); padding: .9rem 1rem;
}
.draw-title { font-weight: 700; font-size: .98rem; margin-bottom: .45rem; }
.draw-stats { font-size: .86rem; line-height: 1.45; margin-bottom: .7rem; min-height: 2.5em; }
.ok-text { color: var(--ok); font-weight: 600; }
.draw-tools { display: flex; flex-wrap: wrap; gap: .4rem; }
.draw-tools button { padding: .5rem .75rem; font-size: .85rem; }
.draw-tools .btn-primary { margin-left: auto; }
.draw-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 0 .6rem; }
.draw-fields .field:last-child { grid-column: 1 / -1; }
.hm { display: flex; align-items: center; gap: .35rem; }
.hm input { width: 4.5rem; }
.hm span { color: var(--muted); font-size: .85rem; margin-right: .4rem; }
.draw-verdict { font-size: .85rem; line-height: 1.45; color: var(--muted); margin: .1rem 0 .6rem; }
.draw-verdict.verdict { padding: .6rem .75rem; }
.draw-verdict.verdict.ok { color: var(--ok); }
.draw-verdict.verdict.bad { color: var(--danger); }
.draw-honesty { font-size: .78rem; color: var(--muted); line-height: 1.45; margin: 0 0 .7rem; background: #fff4d6; border-radius: 8px; padding: .5rem .65rem; }
.draw-done { font-size: .9rem; line-height: 1.45; margin: 0 0 .8rem; }

.map-info { font-family: "DM Sans", system-ui, sans-serif; font-size: .85rem; line-height: 1.5; }
.map-info .swatch { vertical-align: -2px; margin-right: .25rem; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ---------- Mobile top bar + hamburger ---------- */
.mobile-bar {
  display: none;
  position: fixed; top: 0; left: 0; right: 0; z-index: 200;
  height: 52px; background: var(--card); border-bottom: 1px solid var(--line);
  align-items: center; padding: 0 1rem; gap: .8rem;
}
.mobile-title { font-weight: 500; color: var(--muted); font-size: .92rem; }
.hamburger {
  background: none; border: none; font-size: 1.3rem; color: var(--ink);
  padding: .3rem .4rem; cursor: pointer; line-height: 1;
}
.sidebar-overlay {
  display: none; position: fixed; inset: 0; z-index: 299;
  background: rgba(0,0,0,.35);
}
.sidebar-overlay.open { display: block; }

@media (max-width: 720px) {
  .mobile-bar { display: flex; }
  .app { grid-template-columns: 1fr; padding-top: 52px; }

  /* Sidebar becomes a slide-in drawer */
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 300; height: auto;
    width: 260px; transform: translateX(-100%);
    transition: transform .25s ease; box-shadow: none;
  }
  .sidebar.open { transform: translateX(0); box-shadow: 4px 0 24px rgba(0,0,0,.15); }
  .sidebar > .brand { display: none; }

  .main { padding: 1.2rem 1rem; max-width: 100% !important; }
  .card { padding: 1.1rem; }
  .table-card { padding: .2rem .2rem .7rem; }
  .hide-narrow { display: none; }
  .main.map-mode { height: calc(100vh - 52px); height: calc(100dvh - 52px); }
  /* Bottom sheet on phones; stops short of Google's logo/terms, which must stay visible. */
  .draw-panel { top: auto; left: 8px; right: 8px; bottom: 30px; width: auto; max-height: 60%; padding: .75rem .85rem; }
  .draw-stats { min-height: 0; }
  td, th { padding-left: .5rem; padding-right: .5rem; }
}
