/* PingRank design system — mobile-first, light + dark, no external deps.
   Targets: WCAG AA contrast, >=48px touch targets, calm cards, one accent. */

:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --line: #d8dee6;
  --text: #17222e;
  --muted: #55616e;
  --accent: #c2410c;        /* AA on white for text/buttons */
  --accent-soft: #ffedcc;
  --accent-2: #0b63b8;
  --good: #14713c;
  --bad: #b02a2a;
  --shadow: 0 1px 2px rgba(23, 34, 46, 0.06), 0 8px 24px rgba(23, 34, 46, 0.07);
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141a;
    --card: #171f29;
    --line: #2c3642;
    --text: #e9edf2;
    --muted: #9aa6b2;
    --accent: #ff8a45;
    --accent-soft: #3a2415;
    --accent-2: #6cb2ff;
    --good: #58c98b;
    --bad: #ff8f8f;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, sans-serif;
}

b { font-weight: 700; }

/* ---------- top bar ---------- */
.top {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  text-decoration: none;
  font-size: 19px;
  font-weight: 800;
  letter-spacing: -0.02em;
}
.brand b { color: var(--accent); }
.top-nav { display: flex; gap: 4px; margin-left: auto; }
.top-nav a {
  color: var(--muted);
  text-decoration: none;
  padding: 8px 10px;
  border-radius: 10px;
  font-size: 14px;
}
.top-nav a.on { color: var(--text); background: var(--bg); font-weight: 600; }
.lang {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  border-radius: 10px;
  padding: 7px 10px;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
}

/* ---------- layout ---------- */
.view {
  max-width: 920px;
  margin: 0 auto;
  padding: 18px 16px calc(96px + env(safe-area-inset-bottom));
}
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 16px;
}
.card h2 { margin: 0 0 4px; font-size: 20px; letter-spacing: -0.01em; }
.card .sub { color: var(--muted); font-size: 14px; margin: 0 0 14px; }
.grid2 { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 720px) { .grid2 { grid-template-columns: 1fr 1fr; } }

.hero-actions { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 720px) { .hero-actions { grid-template-columns: 1fr 1fr 1fr; } }
.action {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 18px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  text-decoration: none;
  min-height: 104px;
}
.action .big { font-size: 18px; font-weight: 700; }
.action .desc { color: var(--muted); font-size: 14px; }
.action:hover { border-color: var(--accent); }
.action .emoji { font-size: 26px; }

/* ---------- forms ---------- */
label.f { display: block; margin-bottom: 12px; }
label.f span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }
input[type=text], input[type=number], select {
  width: 100%;
  padding: 12px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  min-height: 48px;
}
input:focus, select:focus, button:focus-visible {
  outline: 2px solid var(--accent-2);
  outline-offset: 1px;
}

button.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 12px 18px;
  border: none;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 16px;
  cursor: pointer;
}
button.btn.secondary {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--line);
}
button.btn:disabled { opacity: 0.45; cursor: not-allowed; }
button.btn.small { min-height: 40px; padding: 8px 12px; font-size: 14px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; }
.row > * { flex: 1 1 160px; }

/* ---------- live score stepper ---------- */
.score-wrap {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
}
.player-side { text-align: center; }
.player-side .pname { font-weight: 700; margin-bottom: 6px; word-break: break-word; }
.score-num {
  font-size: 56px;
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.stepper { display: flex; gap: 8px; justify-content: center; margin-top: 8px; }
.stepper button {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  font-size: 30px;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}
.stepper button.minus { color: var(--bad); }
.stepper button.plus { color: var(--good); border-color: var(--good); }
.vs {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  padding: 4px 6px;
}
.sets-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.setchip {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 10px;
  font-variant-numeric: tabular-nums;
  font-size: 15px;
}
.setchip.won { border-color: var(--good); color: var(--good); font-weight: 700; }
.setchip.lost { color: var(--muted); }

/* ---------- lists / tables ---------- */
table.tbl { width: 100%; border-collapse: collapse; font-size: 15px; }
table.tbl th {
  text-align: left;
  color: var(--muted);
  font-size: 12.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 6px 8px;
  border-bottom: 1px solid var(--line);
}
table.tbl td { padding: 10px 8px; border-bottom: 1px solid var(--line); }
table.tbl tr:last-child td { border-bottom: none; }
.pos { font-weight: 800; color: var(--muted); font-variant-numeric: tabular-nums; }
.rating { font-weight: 800; font-variant-numeric: tabular-nums; }
.delta-up { color: var(--good); font-weight: 700; }
.delta-down { color: var(--bad); font-weight: 700; }
.muted { color: var(--muted); }
.tag {
  display: inline-block;
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 12.5px;
  font-weight: 700;
  background: var(--accent-soft);
  color: var(--text);
}
.tag.ok { background: rgba(20, 113, 60, 0.14); color: var(--good); }
.tag.done { background: var(--bg); color: var(--muted); }

/* ---------- tournament bracket ---------- */
.bracket { display: flex; gap: 14px; overflow-x: auto; padding-bottom: 8px; }
.bracket-col { min-width: 200px; flex: 0 0 auto; display: flex; flex-direction: column; justify-content: space-around; gap: 10px; }
.bmatch {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  background: var(--card);
  font-size: 14px;
}
.bmatch .p { display: flex; justify-content: space-between; gap: 8px; padding: 2px 0; }
.bmatch .p .n { word-break: break-word; }
.bmatch .p.win .n { font-weight: 700; }
.bmatch .p .s { font-variant-numeric: tabular-nums; font-weight: 700; }
.bmatch.pending { border-color: var(--accent); }
.bmatch.bye { opacity: 0.55; }

/* ---------- team match ---------- */
.subrow {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.subrow:last-child { border-bottom: none; }
.subrow .who { flex: 1 1 180px; }
.subrow .res { font-variant-numeric: tabular-nums; font-weight: 700; }
.teamscore {
  display: flex;
  align-items: center;
  gap: 14px;
  justify-content: center;
  font-size: 40px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  margin: 4px 0 10px;
}
.teamscore .tn { font-size: 15px; max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(84px + env(safe-area-inset-bottom));
  background: var(--text);
  color: var(--bg);
  padding: 12px 18px;
  border-radius: 12px;
  font-weight: 600;
  z-index: 50;
  max-width: 90vw;
  box-shadow: var(--shadow);
}

/* ---------- bottom tab bar (mobile) ---------- */
.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: var(--card);
  border-top: 1px solid var(--line);
  z-index: 30;
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  flex: 1;
  text-align: center;
  padding: 10px 4px;
  color: var(--muted);
  text-decoration: none;
  font-size: 11.5px;
  font-weight: 600;
}
.tabbar a.on { color: var(--accent); }
.tabbar a .ico { display: block; font-size: 20px; margin-bottom: 2px; }

@media (min-width: 720px) {
  .tabbar { display: none; }
  .view { padding-bottom: 40px; }
}
@media (max-width: 719px) {
  .top-nav { display: none; }
}

/* ---------- auth widget & PIN overlay ---------- */
.authbox { display: flex; align-items: center; gap: 8px; margin-left: auto; }
@media (max-width: 719px) { .authbox { margin-left: 0; } .authbox .btn { padding: 8px 10px; } }
.top-nav { margin-left: 0; }
.authbox + .lang { margin-left: 0; }
.top:has(.authbox:not(:empty)) .top-nav { margin-right: 8px; }

.pin-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 14, 20, 0.66);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 18px;
}
.pin-card {
  background: var(--card);
  border-radius: 18px;
  padding: 20px;
  width: min(340px, 92vw);
  text-align: center;
  box-shadow: var(--shadow);
}
.pin-card .pname { font-size: 18px; font-weight: 800; margin-bottom: 2px; }
.pin-dots {
  font-size: 28px;
  letter-spacing: 0.35em;
  min-height: 40px;
  margin: 8px 0 10px;
  color: var(--accent);
}
.pin-pad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.pin-key {
  height: 64px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  font-size: 24px;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}
.pin-key.pin-ok { background: var(--accent); color: #fff; border-color: var(--accent); }
.pin-key.pin-del { font-size: 20px; }

/* ---------- misc ---------- */
.empty { color: var(--muted); text-align: center; padding: 22px 0; }
.split { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.legend { font-size: 13px; color: var(--muted); }
footer.legend { text-align: center; margin-top: 26px; }
a { color: var(--accent-2); }
.about p { margin: 8px 0; }
.kbd {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 1px 7px;
  font-size: 13.5px;
}
