:root {
  --bg: #ffffff;
  --surface: #f3f4f6;
  --text: #1a1a1b;
  --muted: #6b7280;
  --border: #d3d6da;
  --accent: #2563eb;
  --danger: #b91c1c;
  --correct: #538d4e;
  --present: #b59f3b;
  --absent: #787c7e;
  --key: #d3d6da;
  --key-text: #1a1a1b;
  --tile-text: #ffffff;
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121213;
    --surface: #1e1f21;
    --text: #f3f4f6;
    --muted: #9ca3af;
    --border: #3a3a3c;
    --accent: #60a5fa;
    --danger: #f87171;
    --correct: #538d4e;
    --present: #b59f3b;
    --absent: #3a3a3c;
    --key: #818384;
    --key-text: #ffffff;
  }
}

:root[data-theme="dark"] {
  --bg: #121213;
  --surface: #1e1f21;
  --text: #f3f4f6;
  --muted: #9ca3af;
  --border: #3a3a3c;
  --accent: #60a5fa;
  --danger: #f87171;
  --correct: #538d4e;
  --present: #b59f3b;
  --absent: #3a3a3c;
  --key: #818384;
  --key-text: #ffffff;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.45;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

a { color: var(--accent); }

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--border);
}

.brand { font-weight: 800; font-size: 1.25rem; text-decoration: none; color: var(--text); letter-spacing: -0.02em; }
.brand span { color: var(--correct); }

.nav { display: flex; align-items: center; gap: 0.7rem; font-size: 0.9rem; justify-content: flex-end; }
.nav a { text-decoration: none; color: var(--text); }
.nav a:hover { color: var(--accent); }

.inline { display: inline; margin: 0; }

.icon-btn, .link-btn {
  background: none; border: 0; color: var(--text); cursor: pointer; font: inherit; padding: 0.2rem;
}
.icon-btn { font-size: 1.2rem; line-height: 1; }
.link-btn:hover { color: var(--accent); }

.container { width: 100%; max-width: 640px; margin: 0 auto; padding: 1rem; flex: 1; }
.container.wide { max-width: 900px; }

h1 { font-size: 1.5rem; margin: 0.5rem 0 1rem; }
h2 { font-size: 1.15rem; margin: 1.5rem 0 0.6rem; }

.messages { list-style: none; margin: 0; padding: 0.5rem 1rem 0; max-width: 640px; width: 100%; margin-inline: auto; }
.message { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.6rem 0.9rem; margin-bottom: 0.4rem; }
.message.error { border-color: var(--danger); }
.message.success { border-color: var(--correct); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; }

.btn {
  display: inline-block; background: var(--accent); color: #fff; border: 0; border-radius: var(--radius);
  padding: 0.65rem 1.1rem; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; text-align: center;
}
.btn.secondary { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn.danger { background: var(--danger); }
.btn.small { padding: 0.35rem 0.7rem; font-size: 0.85rem; }
.btn.block { display: block; width: 100%; }

form p, .field { margin: 0 0 0.9rem; }
label { display: block; font-weight: 600; margin-bottom: 0.25rem; }
input[type="text"], input[type="email"], input[type="password"], input[type="number"] {
  width: 100%; padding: 0.65rem 0.8rem; font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: var(--radius);
}
.helptext, .muted { color: var(--muted); font-size: 0.85rem; }
.errorlist { color: var(--danger); list-style: none; padding: 0; margin: 0.25rem 0; font-size: 0.9rem; }

table { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
th, td { text-align: left; padding: 0.45rem 0.4rem; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }

.dist { display: grid; grid-template-columns: 1.5rem 1fr; gap: 0.3rem 0.5rem; align-items: center; }
.dist-bar { background: var(--absent); color: #fff; min-width: 1.6rem; padding: 0 0.4rem; text-align: right; font-size: 0.85rem; border-radius: 3px; }
.dist-bar.fill { background: var(--correct); }

.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.5rem; text-align: center; margin-bottom: 1rem; }
.stat-grid strong { display: block; font-size: 1.6rem; line-height: 1.1; }
.stat-grid span { font-size: 0.72rem; color: var(--muted); }

/* Mini colour grid, used for other players' results. */
.mini-grid { display: inline-grid; gap: 2px; }
.mini-row { display: flex; gap: 2px; }
.mini-cell { width: 14px; height: 14px; border-radius: 2px; background: var(--absent); }
.mini-cell.g { background: var(--correct); }
.mini-cell.y { background: var(--present); }
.mini-cell.b { background: var(--absent); }

.pill { display: inline-block; border-radius: 999px; padding: 0.05rem 0.55rem; font-size: 0.8rem; background: var(--surface); border: 1px solid var(--border); }
.pill.win { border-color: var(--correct); color: var(--correct); font-weight: 700; }

.row { display: flex; gap: 0.6rem; flex-wrap: wrap; align-items: center; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 0.75rem; }
.copy-field { display: flex; gap: 0.4rem; }
