/* BIKEE! - mobile first. Everything here is designed for a phone held in one
   hand, outdoors, in the sun: big targets, high contrast, no hover-only
   affordances, nothing that can only be dismissed by a precise tap. */

:root {
  --bg: #0e1116;
  --panel: #161b23;
  --panel-2: #1e242e;
  --line: #2a323d;
  --text: #eef2f7;
  --muted: #9aa7b6;
  --accent: #ff2d78;
  --accent-ink: #16000a;
  --ok: #21c06a;
  --warn: #f0a500;
  --bad: #ff4d4d;
  --radius: 14px;
  --pad: 16px;
  --tap: 56px;

  /* Height of the sticky header. The map view is `position: fixed`, so it does
     not lay out below the header on its own - it has to be told where to start,
     or it sits underneath and the scoreboard disappears behind the topbar.
     match.js measures the real height (which depends on the safe-area inset and
     the font) and updates this; the value here is just a sane default for the
     first paint. */
  --topbar-h: 52px;
}

* { box-sizing: border-box; }

/* The hidden attribute must always win.
   The client shows and hides panels with `el.hidden = true/false`, but the UA
   stylesheet's `[hidden] { display: none }` loses to any author rule that sets
   `display` - so `.sheet { display: flex }` quietly made the dock sheet
   permanently visible and its close button do nothing. `!important` here means
   no future rule can reintroduce that, whichever element it is. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--accent); }
h1 { font-size: 1.6rem; margin: 0 0 .5rem; }
h2 { font-size: 1.15rem; margin: 0 0 .6rem; }
h3 { font-size: 1rem; margin: 1rem 0 .4rem; }
code { background: var(--panel-2); padding: .1em .4em; border-radius: 6px; font-size: .85em; }

.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.pad { padding: var(--pad); }
.accent { color: var(--accent); }

/* ------------------------------------------------------------------ chrome */
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px var(--pad);
  padding-top: calc(10px + env(safe-area-inset-top, 0px));
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 900;
}
.brand { font-weight: 800; letter-spacing: -.5px; text-decoration: none; color: var(--text); font-size: 1.15rem; }
.brand .bang { color: var(--accent); }
.whoami { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.whoami .nick { color: var(--muted); font-size: .9rem; }
.linkbtn { background: none; border: 0; color: var(--accent); font: inherit; font-size: .9rem; cursor: pointer; padding: 6px; }
.code-pill {
  font-family: ui-monospace, Menlo, monospace; letter-spacing: 2px;
  background: var(--panel-2); border: 1px solid var(--line);
  padding: 4px 10px; border-radius: 999px; font-size: .9rem;
}
main { padding-bottom: env(safe-area-inset-bottom, 0px); }
main.flush { padding: 0; }

/* ------------------------------------------------------------------ cards */
.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: var(--pad); margin: 0 var(--pad) var(--pad);
}
.card.narrow { max-width: 420px; margin: 24px auto; }
.grid2 { display: grid; gap: var(--pad); grid-template-columns: 1fr; }
@media (min-width: 760px) { .grid2 { grid-template-columns: 1fr 1fr; } }

.hero { padding: 24px var(--pad) 8px; max-width: 760px; }
.hero .lede { color: var(--muted); }

/* ------------------------------------------------------------------ forms */
label { display: block; margin: 0 0 12px; font-size: .9rem; color: var(--muted); }
label.check { display: flex; gap: 10px; align-items: flex-start; color: var(--text); }
label.check small { display: block; color: var(--muted); font-weight: 400; }
input, select, button { font: inherit; }
input[type=text], input[type=password], input[type=email], input:not([type]), select {
  width: 100%; margin-top: 4px; padding: 12px;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 10px;
}
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.code-input { font-family: ui-monospace, Menlo, monospace; letter-spacing: 4px; text-transform: uppercase; font-size: 1.4rem; text-align: center; }

button.primary, a.btn {
  display: block; width: 100%; padding: 14px; margin-top: 8px;
  background: var(--accent); color: var(--accent-ink);
  border: 0; border-radius: 12px; font-weight: 700; cursor: pointer; text-align: center;
  text-decoration: none;
}
button.primary:disabled { opacity: .45; cursor: not-allowed; }
button.ghost { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); border-radius: 12px; cursor: pointer; }
button.danger { display: block; width: 100%; margin-top: 8px; padding: 12px; background: none; color: var(--bad); border: 1px solid var(--bad); border-radius: 12px; cursor: pointer; }
button.big { font-size: 1.15rem; padding: 18px; }
.error { color: var(--bad); background: #2a1416; border: 1px solid #5a1f22; padding: 10px 12px; border-radius: 10px; }
.notice { margin: 0 0 var(--pad); padding: 10px 12px; border-radius: 10px; background: #2a2413; border: 1px solid #5a4a1a; color: #ffd98a; font-size: .88rem; }
.bignum { font-size: 3rem; font-weight: 800; color: var(--accent); margin: 0; }

/* ------------------------------------------------------------------ stats */
.stats { list-style: none; padding: 0; margin: 8px 0 0; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stats li { background: var(--panel-2); border-radius: 10px; padding: 10px; font-size: .85rem; color: var(--muted); }
.stats li span { display: block; font-size: 1.2rem; font-weight: 700; color: var(--text); }
.matchlist { list-style: none; padding: 0; margin: 0; }
.matchlist a { display: flex; gap: 10px; align-items: center; padding: 12px; border-radius: 10px; text-decoration: none; color: var(--text); background: var(--panel-2); margin-bottom: 8px; }
.matchlist .code { font-family: ui-monospace, monospace; color: var(--muted); }
.tag { font-size: .75rem; padding: 2px 8px; border-radius: 999px; background: var(--line); color: var(--muted); }
.tag[style*="--c"] { background: var(--c); color: #fff; }
.state-running { background: var(--ok); color: #04180d; }
.state-lobby { background: var(--warn); color: #1a1400; }

/* ------------------------------------------------------------------ lobby */
.lobby-head { padding: 4px 0 12px; }
.lobby-head h1 { margin-bottom: 2px; }
.teamcard { background: var(--panel); border: 1px solid var(--line); border-left: 6px solid var(--c, var(--line)); border-radius: var(--radius); padding: var(--pad); }
.teamcard h3 { margin: 0 0 8px; display: flex; align-items: center; gap: 8px; }
.teamcard .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--c); display: inline-block; }
.teamcard .area { margin-left: auto; font-variant-numeric: tabular-nums; color: var(--muted); font-size: .9rem; }
.roster { list-style: none; padding: 0; margin: 0; }
.roster li { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: .92rem; }
.roster li:last-child { border-bottom: 0; }
.roster .bike { font-family: ui-monospace, monospace; color: var(--muted); margin-left: auto; }
.roster .rdy { color: var(--ok); }
.roster .notrdy { color: var(--muted); }

/* ------------------------------------------------------------------- play */
#view-play { position: fixed; inset: 0; top: var(--topbar-h); }
#map { position: absolute; inset: 0; z-index: 0; background: #0a0d12; }
.leaflet-container { background: #0a0d12; }

.scoreboard {
  /* Positioned inside #view-play, which already starts below the header and
     below the safe-area inset, so no env() here. */
  position: absolute; z-index: 500;
  top: 8px; left: 8px; right: 8px;
  display: flex; gap: 8px; pointer-events: none;
}
.score {
  flex: 1; background: rgba(14,17,22,.86); backdrop-filter: blur(6px);
  border: 1px solid var(--line); border-top: 4px solid var(--c);
  border-radius: 12px; padding: 8px 10px;
}
.score .name { font-size: .78rem; color: var(--muted); }
.score .area { font-size: 1.25rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.score.me { border-color: var(--accent); }

.hullhint {
  position: absolute; z-index: 500; left: 8px; right: 8px;
  top: calc(8px + 68px);            /* clear of the scoreboard above it */
  background: rgba(240,165,0,.92); color: #1a1400; font-size: .85rem; font-weight: 600;
  padding: 8px 12px; border-radius: 10px;
}
.hullhint.bad { background: rgba(255,77,77,.92); color: #fff; }

.countdown {
  position: absolute; z-index: 800; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: rgba(10,13,18,.93); text-align: center; padding: 24px;
}
.countdown .n { font-size: 5rem; font-weight: 800; color: var(--accent); line-height: 1; font-variant-numeric: tabular-nums; }
.countdown .t { font-size: 1.1rem; margin-top: 8px; }
.countdown .s { color: var(--muted); margin-top: 12px; max-width: 340px; }

.bottombar {
  position: fixed; z-index: 600; left: 0; right: 0; bottom: 0;
  display: flex; gap: 10px; align-items: center;
  padding: 12px var(--pad);
  padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(to top, rgba(14,17,22,.97), rgba(14,17,22,.75));
  border-top: 1px solid var(--line);
}
.bottombar .primary { margin: 0; flex: 1; }
.bottombar .ghost { width: var(--tap); height: var(--tap); font-size: 1.4rem; }

.player-marker { display: grid; place-items: center; font-size: 11px; font-weight: 700; }
.pin { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; color: #fff; border: 2px solid rgba(255,255,255,.85); box-shadow: 0 2px 6px rgba(0,0,0,.5); }
.pin.me { border-color: var(--accent); border-width: 3px; }

/* ------------------------------------------------------------------ sheet */
.sheet { position: fixed; inset: 0; z-index: 1000; background: rgba(0,0,0,.6); display: flex; align-items: flex-end; }
.sheet-inner {
  background: var(--panel); width: 100%; max-height: 88vh; overflow-y: auto;
  border-radius: 18px 18px 0 0; padding: var(--pad);
  padding-bottom: calc(var(--pad) + env(safe-area-inset-bottom, 0px));
  -webkit-overflow-scrolling: touch;
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-head h2 { margin: 0; }
#station-search { margin: 8px 0 4px; }
.rows { list-style: none; padding: 0; margin: 8px 0 0; }
.rows li { border-bottom: 1px solid var(--line); }
.rows button {
  width: 100%; text-align: left; background: none; border: 0; color: var(--text);
  padding: 14px 4px; display: flex; gap: 10px; align-items: center; cursor: pointer;
}
.rows button:active { background: var(--panel-2); }
.rows .n { font-family: ui-monospace, monospace; color: var(--muted); }
.rows .d { margin-left: auto; color: var(--muted); font-size: .85rem; }
.rows .btype { font-size: .72rem; padding: 2px 6px; border-radius: 6px; background: var(--line); color: var(--muted); }
.rows .btype.ELECTRICAL { background: #123a2a; color: #7ff0b5; }
.rows button.taken { opacity: .4; }

.toast {
  position: fixed; z-index: 1200; left: 50%; transform: translateX(-50%);
  bottom: calc(96px + env(safe-area-inset-bottom, 0px));
  max-width: 92vw; padding: 12px 16px; border-radius: 12px;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  box-shadow: 0 8px 24px rgba(0,0,0,.5); font-size: .92rem; text-align: center;
}
.toast.ok { border-color: var(--ok); }
.toast.bad { border-color: var(--bad); }
.toast.warn { border-color: var(--warn); }

.spinner {
  display: inline-block; width: 14px; height: 14px; margin-right: 8px;
  border: 2px solid var(--muted); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -2px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.resbar { height: 10px; border-radius: 6px; background: var(--panel-2); overflow: hidden; margin: 8px 0 4px; }
.resbar > div { height: 100%; background: var(--c, var(--accent)); }

/* ------------------------------------------------------------------ admin */
.logoutform { display: flex; align-items: center; gap: 8px; margin: 0; }
.adminlink {
  text-decoration: none; font-size: .8rem; font-weight: 700;
  letter-spacing: .04em; text-transform: uppercase;
  color: var(--accent); border: 1px solid var(--accent);
  padding: 4px 9px; border-radius: 999px;
}
.adminlink:hover { background: var(--accent); color: var(--accent-ink); }

main.admin { padding: var(--pad); max-width: 1500px; margin: 0 auto; }
main.admin .card { margin-left: 0; margin-right: 0; }

.adminbar { display: flex; flex-wrap: wrap; align-items: center; gap: 14px; }
.adminbar label.inline { display: flex; align-items: center; gap: 8px; margin: 0; }
.adminbar select { width: auto; margin: 0; min-width: 260px; }
.statusline { margin-left: auto; font-size: .9rem; }
.statusline b { color: var(--text); }

.admingrid { display: grid; gap: var(--pad); grid-template-columns: 1fr; margin-bottom: var(--pad); }
@media (min-width: 900px) {
  .admingrid { grid-template-columns: 1fr 1fr; }
  .admingrid.wide-left { grid-template-columns: 2fr 1fr; }
}
.stack { display: flex; flex-direction: column; gap: var(--pad); }

/* The map takes whatever height the tall right-hand column leaves, rather than
   sitting at a fixed size with dead space beneath it. min-height keeps it
   usable (and non-zero for Leaflet) if the columns ever invert. */
#admin-map { flex: 1 1 auto; min-height: 380px; border-radius: 10px; overflow: hidden; background: #0a0d12; }
.admingrid.wide-left > .card { display: flex; flex-direction: column; }
.admingrid.wide-left > .card h2 { flex: none; }

.admin .card hr { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }
.admin h3 { margin-top: 18px; }
button.ghost.wide { display: block; width: 100%; margin-top: 8px; padding: 12px; }
button.small { padding: 4px 10px; font-size: .8rem; }
button.primary.small { width: auto; display: inline-block; margin: 4px 0 0; padding: 8px 12px; }

.rulegrid { display: grid; gap: 10px; grid-template-columns: 1fr; }
@media (min-width: 620px) { .rulegrid { grid-template-columns: 1fr 1fr; } }
.rulegrid label { margin: 0; }
.rulegrid input[type=number], .rulegrid select { width: 100%; }

.riderrow, .teamrow {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 0; border-bottom: 1px solid var(--line); font-size: .9rem;
}
.riderrow:last-child, .teamrow:last-child { border-bottom: 0; }
.riderrow .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.riderrow .bike { margin-left: auto; font-family: ui-monospace, monospace; color: var(--muted); }
.riderrow .station { width: 4.5em; text-align: right; font-family: ui-monospace, monospace; }
.teamrow input[type=color] { width: 34px; height: 30px; padding: 0; border: 1px solid var(--line); background: none; border-radius: 6px; }
.teamrow input[type=text] { flex: 1; margin: 0; padding: 6px 8px; }
.leaflet-popup-content button.primary { width: 100%; margin-top: 6px; }
