/* =========================================================
   PoengMestern — mobile-first stylesheet.
   Base rules target phones. @media (min-width: …) blocks
   progressively enhance for tablets and desktops.
   ========================================================= */

:root {
  --bg: #0b1120;
  --card: #18233b;
  --card2: #1e293b;
  --line: #2c3a55;
  --text: #eef2f9;
  --muted: #93a4c0;
  --accent: #38bdf8;
  --accent2: #818cf8;
  --good: #34d399;
  --bad: #f87171;
  --gold: #fbbf24;
  --radius: 16px;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  --nav-h: 64px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: radial-gradient(1000px 500px at 50% -10%, #16233f 0%, var(--bg) 55%) fixed;
  color: var(--text);
  line-height: 1.55;
  min-height: 100vh;
  /* Leave room for the fixed bottom tab bar on mobile. */
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
}

/* ---------- Navigation: bottom tab bar (mobile-first) ---------- */
nav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 30;
  display: flex;
  align-items: stretch;
  gap: 2px;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: rgba(11, 17, 32, 0.92);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
/* The wordmark is hidden in the mobile tab bar; page titles give context. */
nav .brand {
  display: none;
  font-weight: 800;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
nav a {
  flex: 1 1 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--muted);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.82rem;
  border-top: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}
nav a:active { color: var(--text); }
nav a.active {
  color: var(--accent);
  border-top-color: var(--accent);
}
/* Admin is desktop-only: groups input on phones, admin takes over elsewhere. */
nav a.admin-only { display: none; }

/* ---------- Layout ---------- */
main { width: 100%; max-width: 760px; margin: 0 auto; padding: 18px 14px 28px; }

h1 { font-size: 1.45rem; margin: 0 0 4px; letter-spacing: -0.02em; }
h2 { font-size: 1.1rem; margin: 26px 0 10px; letter-spacing: -0.01em; }
.sub { color: var(--muted); margin: 0 0 18px; }
.danger-text { color: var(--bad); }

.card {
  background: linear-gradient(180deg, var(--card), var(--card2));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}

/* ---------- Forms (touch-first) ---------- */
label { display: block; font-size: 0.82rem; color: var(--muted); margin: 12px 0 5px; font-weight: 600; }
label:first-child { margin-top: 0; }

input[type=text], input[type=password], select {
  width: 100%;
  padding: 14px;
  background: #0b1424;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--text);
  font-size: 16px; /* >=16px stops iOS zoom-on-focus */
  min-height: 50px;
  appearance: none;
  -webkit-appearance: none;
}
input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.18);
}
select {
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 1.35em, calc(100% - 13px) 1.35em;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 38px;
}

/* Buttons: full width by default (mobile), shrink on larger screens. */
button {
  width: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  color: #04121f;
  border: none;
  padding: 14px 20px;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  margin-top: 14px;
  min-height: 50px;
  transition: filter 0.15s, transform 0.05s;
}
button:hover { filter: brightness(1.08); }
button:active { transform: scale(0.985); }
button.ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); }
button.danger { background: linear-gradient(90deg, #ef4444, #f87171); color: #fff; }
button.mini { width: auto; padding: 9px 14px; font-size: 0.9rem; margin: 0; min-height: 0; }

/* ---------- Tables ---------- */
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 7px; border-bottom: 1px solid var(--line); }
tr:last-child td { border-bottom: none; }
th { color: var(--muted); font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.05em; }
td.num, th.num { text-align: right; }

/* ---------- Bits ---------- */
.msg { margin-top: 12px; font-size: 0.92rem; min-height: 1.2em; }
.msg.ok { color: var(--good); }
.msg.err { color: var(--bad); }

.pill { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 0.8rem; font-weight: 700; }
.pill.good { background: rgba(52, 211, 153, .15); color: var(--good); }
.pill.bad  { background: rgba(248, 113, 113, .15); color: var(--bad); }

.rank { font-weight: 800; font-size: 1.15rem; width: 40px; }

/* ---------- Leaderboard: responsive flex rows (no horizontal scroll) ---------- */
.board { display: flex; flex-direction: column; }
.lb-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 2px;
  border-bottom: 1px solid var(--line);
}
.lb-row:last-child { border-bottom: none; }
.lb-rank { flex: 0 0 auto; width: 34px; text-align: center; font-size: 1.35rem; font-weight: 800; }
.lb-main { flex: 1 1 auto; min-width: 0; }
.lb-name {
  font-weight: 700;
  font-size: 1.05rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.lb-break { color: var(--muted); font-size: 0.8rem; margin-top: 2px; }
.lb-total {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  font-size: 1.6rem;
  font-weight: 800;
  line-height: 1;
  color: var(--accent);
}
.lb-unit { font-size: 0.62rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; margin-top: 3px; }
.muted { color: var(--muted); font-size: 0.88rem; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
hr { border: none; border-top: 1px solid var(--line); margin: 24px 0; }
.member { margin-bottom: 8px; }

/* =========================================================
   ≥ 640px — tablets/desktop: top nav bar, roomier layout
   ========================================================= */
@media (min-width: 640px) {
  body { padding-bottom: 0; }

  nav {
    position: sticky;
    top: 0; bottom: auto;
    height: auto;
    gap: 6px;
    align-items: center;
    padding: 10px 16px;
    border-top: none;
    border-bottom: 1px solid var(--line);
    overflow-x: auto;
    scrollbar-width: none;
  }
  nav::-webkit-scrollbar { display: none; }
  nav .brand { display: inline; font-size: 1.05rem; margin-right: 10px; white-space: nowrap; }
  nav a {
    flex: 0 0 auto;
    border-top: none;
    border-radius: 999px;
    padding: 8px 15px;
    font-size: 0.95rem;
    white-space: nowrap;
  }
  nav a:hover { background: var(--card2); color: var(--text); }
  nav a.active {
    color: #04121f;
    background: linear-gradient(90deg, var(--accent), var(--accent2));
  }
  nav a.admin-only { display: inline-flex; align-items: center; }

  main { padding: 26px 20px 60px; }
  h1 { font-size: 1.75rem; }
  h2 { font-size: 1.2rem; }
  .card { padding: 22px; }

  /* On larger screens, buttons size to their content. */
  button { width: auto; }
  button.danger, button#login { width: auto; }
}

@media (min-width: 1024px) {
  main { max-width: 820px; }
}

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