:root {
  --bg: #eef7ef;   /* very light pastel green */
  --fg: #1a1a1a;
  --muted: #888;
  --line: #e4e4e0;
  --green: #16a34a;
  --green-bg: #ecfdf3;
  --red: #b91c1c;
  --accent: #2563eb;
  --danger: #b91c1c;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--fg);
  line-height: 1.5;
}

main {
  max-width: 720px;
  margin: 0 auto;
  padding: 1rem 1rem 4rem;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { margin: 0 0 0.75rem; }
h2.sub { margin-top: 1.25rem; font-size: 1.1rem; }
/* Tight intro/footnote lines under a heading or stat row. */
.note { margin: 0.4rem 0 0.9rem; }
.note.flush { margin-bottom: 0; }
.muted { color: var(--muted); }
.small { font-size: 0.85em; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--line);
  background: white;
}
.brand { font-weight: 700; color: var(--fg); font-size: 1.15rem; }
nav { display: flex; gap: 1rem; align-items: center; }

.cta {
  background: var(--accent);
  color: white !important;
  padding: 0.4rem 0.8rem;
  border-radius: 6px;
  font-size: 0.9rem;
}
.cta:hover { text-decoration: none; opacity: 0.9; }

.page-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.page-head h1 { margin: 0; }   /* so the CTA lines up with the heading text, not its margin box */

.inline { display: inline; }
.link {
  background: none; border: none; color: var(--accent);
  cursor: pointer; padding: 0; font: inherit;
}
.link:hover { text-decoration: underline; }
.link.danger { color: var(--danger); }

.flash {
  list-style: none;
  padding: 0.6rem 1rem;
  margin: 0 0 1rem;
  background: var(--green-bg);
  border: 1px solid #b7e4c7;
  border-radius: 6px;
}
.flash li { padding: 0; }

/* Leaderboard */
.board {
  width: 100%;
  border-collapse: collapse;
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}
.board th, .board td {
  text-align: left;
  padding: 0.6rem 0.8rem;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
.board th { font-size: 0.8rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; }
.board th.nowrap, .board td.nowrap { white-space: nowrap; }
.board tr:last-child td { border-bottom: none; }
.board .rank { color: var(--muted); width: 2rem; text-align: center; }
/* Match the emoji's line box to the digits so the goat row isn't taller. */
.board .rank.goat { font-size: 1rem; line-height: 1; }
.board .rating { font-weight: 600; }
.board tr:nth-child(1) .rank { color: #d4a017; font-weight: 700; }
/* inline-flex keeps the td a real table-cell (so row heights/borders stay even)
   while still centering the name and rename pencil together. */
.player-cell { display: inline-flex; align-items: center; gap: 0.35rem; vertical-align: middle; }

.edit-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
  font-size: 0.85rem;
  padding: 0 0.2rem;
  opacity: 0;
  transition: opacity 0.1s;
}
.board tr:hover .edit-btn, h1 .edit-btn { opacity: 1; }
.edit-btn:hover { color: var(--accent); }
h1 .edit-btn { font-size: 1rem; vertical-align: middle; }

/* Match form */
.match-form { max-width: 100%; }
/* Some mobile browsers (notably iOS Safari) render datalist <option>s in-flow
   as visible vertical space until an input is focused. Force it hidden — it
   still works as the autocomplete picker. */
datalist { display: none !important; }
/* stretch keeps the two boxes equal height (and full-width when stacked on
   mobile); smaller gap tightens the space around the vs. */
.teams { display: flex; gap: 0.6rem; align-items: stretch; }
.team {
  flex: 1;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  padding: 0.7rem 0.75rem 0.4rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin: 0;
}
.team-head { display: flex; justify-content: space-between; align-items: center; }
.team-title { font-weight: 600; }
.team input[type="text"], .team input:not([type]) {
  font-size: 1rem;
  padding: 0.5rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
}
.winner { margin-top: 0; font-size: 0.95rem; display: flex; align-items: center; gap: 0.4rem; }
.vs { align-self: center; color: var(--muted); font-weight: 600; }

.scores { margin: 1rem 0; }
.scores summary { cursor: pointer; color: var(--muted); font-size: 0.9rem; }
.score-row { display: flex; align-items: center; gap: 0.5rem; margin-top: 0.5rem; }
.score-row input {
  width: 4rem; font-size: 1rem; padding: 0.4rem;
  border: 1px solid var(--line); border-radius: 6px; text-align: center;
}

.match-form > button[type="submit"] {
  padding: 0.6rem 1.2rem;
  font-size: 1rem;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
}

/* Match cards */
.match {
  position: relative;
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.6rem 0.8rem;
  margin: 0.5rem 0;
}
.match.deletable { padding-right: 1.8rem; }   /* room for the corner ✕ */
.match-teams {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 0.5rem;
}
/* Names centered in their cell; the trophy is absolutely positioned so it
   sits to the right of the name WITHOUT shifting it off-center. */
.team-side { position: relative; text-align: center; }
.team-side.won { font-weight: 600; }
.team-side.won::after { content: "🏆"; position: absolute; margin-left: 0.25em; }
.team-side.lost { color: var(--muted); }
.score { color: var(--muted); font-size: 0.9rem; padding: 0 0.4rem; }

/* Delete sits in the card's top-right corner so it adds no extra row. */
.match-delete { position: absolute; top: 0.3rem; right: 0.4rem; margin: 0; }
.match-delete button {
  background: none; border: none; cursor: pointer;
  color: var(--muted); font-size: 0.95rem; line-height: 1; padding: 0.15rem 0.25rem;
}
.match-delete button:hover { color: var(--danger); }

/* Player page */
.stat-cards { display: flex; gap: 0.75rem; flex-wrap: wrap; }
.stat {
  flex: 1;
  min-width: 5rem;
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.75rem;
  text-align: center;
}
.stat-num { font-size: 1.4rem; font-weight: 700; }
.stat-num.up { color: var(--green); }
.stat-num.down { color: var(--red); }
.stat-label { font-size: 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; }

/* Leaderboard streak / weekly-mover badges next to a name */
.badges { white-space: nowrap; font-size: 0.95em; }

/* Rating-over-time chart (inline SVG) */
.chart {
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.5rem;
  margin: 0.25rem 0 0.5rem;
}
.rating-chart { width: 100%; height: auto; display: block; }
.chart-line { stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart-dot { fill: var(--accent); }
.chart-ref { stroke: var(--green); stroke-width: 1; stroke-dasharray: 4 3; opacity: 0.7; }
.chart-axis { fill: var(--muted); font-size: 11px; }

@media (max-width: 600px) {
  .topbar { padding: 0.5rem 0.75rem; flex-wrap: wrap; gap: 0.5rem; }
  nav { gap: 0.6rem; font-size: 0.9rem; }
  .teams { flex-direction: column; gap: 0.3rem; }
  .vs { padding: 0; }
  /* Keep the heading and button on one tidy row, button hugging the right. */
  .page-head { gap: 0.75rem; }
  /* All page headings the same size as the leaderboard's on mobile. */
  h1 { font-size: 1.4rem; }
  /* No hover on touch, so always show the rename pencil. */
  .edit-btn { opacity: 0.55; }
  /* Tighten the table so all columns fit without wrapping. */
  .board th, .board td { padding: 0.55rem 0.5rem; }
  /* Stack each match's teams so 2v2/3v3 names get full width (no mid-name
     wrapping). Names stay centered; the trophy is out of flow so it doesn't
     shift them. */
  .match-teams { grid-template-columns: 1fr; gap: 0.15rem; text-align: center; }
  .score { padding: 0; text-align: center; }
}
