@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Playfair+Display:wght@700;900&display=swap');

:root {
  --bg: #f7f5f0;
  --card: #ffffff;
  --ink: #23212e;
  --muted: #7b7589;
  --faint: #a9a3b5;
  --line: rgba(35, 33, 46, 0.09);
  --accent: #4f46a8;
  --accent-soft: rgba(79, 70, 168, 0.1);
  --good: #2f8f5b;
  --bad: #c2484f;
  --radius: 16px;
  --shadow: 0 4px 6px -1px rgba(35, 33, 46, 0.06), 0 2px 4px -2px rgba(35, 33, 46, 0.04);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  -webkit-font-smoothing: antialiased;
}

.container {
  max-width: 680px;
  width: 100%;
  padding: 2rem 1.25rem 4rem;
}

/* ---------- Header ---------- */

.header {
  text-align: center;
  margin-bottom: 1.75rem;
}

.header h1 {
  font-family: 'Playfair Display', serif;
  font-weight: 900;
  font-size: 2.8rem;
  margin: 0;
  line-height: 1.05;
  letter-spacing: -0.015em;
}

.header .subtitle {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: 0.09em;
  text-transform: uppercase;
  margin-top: 0.5rem;
}

/* ---------- Nav ---------- */

.nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  justify-content: center;
  margin-bottom: 2rem;
}

.nav a {
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-decoration: none;
  color: var(--muted);
  padding: 0.45rem 0.8rem;
  border-radius: 999px;
  border: 1px solid transparent;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.nav a:hover {
  color: var(--ink);
  background: rgba(35, 33, 46, 0.04);
}

.nav a.active {
  color: #fff;
  background: var(--nav-accent, var(--accent));
  border-color: var(--nav-accent, var(--accent));
}

/* ---------- Section labels ---------- */

h2 {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.11em;
  color: var(--muted);
  margin: 2.25rem 0 0.85rem;
  padding-left: 0.2rem;
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
}

h2:first-of-type {
  margin-top: 0;
}

h2 .hint {
  font-size: 0.68rem;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  color: var(--faint);
}

/* ---------- Cards ---------- */

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

.card.flush {
  padding: 0.5rem 0.35rem;
}

/* ---------- Game selector ---------- */

.game-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.75rem;
}

.game-tile {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.1rem 1.1rem 1rem;
  text-decoration: none;
  color: var(--ink);
  display: block;
  position: relative;
  overflow: hidden;
  transition: transform 0.15s, box-shadow 0.15s;
}

.game-tile::before {
  content: '';
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  background: var(--tile-accent);
}

.game-tile:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 18px -8px rgba(35, 33, 46, 0.18), var(--shadow);
}

.game-tile .tile-name {
  font-family: 'Playfair Display', serif;
  font-weight: 700;
  font-size: 1.22rem;
  line-height: 1.15;
}

.game-tile .tile-tag {
  font-size: 0.72rem;
  color: var(--muted);
  margin-top: 0.3rem;
  line-height: 1.35;
}

.game-tile .tile-meta {
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--tile-accent);
  margin-top: 0.7rem;
}

/* ---------- Tables ---------- */

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
}

thead th {
  font-size: 0.66rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--faint);
  text-align: right;
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

thead th:first-child,
thead th.left {
  text-align: left;
}

tbody td {
  padding: 0.6rem;
  text-align: right;
  border-bottom: 1px solid rgba(35, 33, 46, 0.05);
  font-variant-numeric: tabular-nums;
}

tbody td:first-child,
tbody td.left {
  text-align: left;
}

tbody tr:last-child td {
  border-bottom: none;
}

tbody tr:hover {
  background: rgba(35, 33, 46, 0.02);
}

td.player {
  font-weight: 600;
}

td.rank {
  color: var(--faint);
  font-weight: 700;
  width: 2.5rem;
}

tr.top-1 td.rank { color: #b8912f; }
tr.top-2 td.rank { color: #8d8d96; }
tr.top-3 td.rank { color: #a9713f; }

td.score {
  font-weight: 600;
}

td.dim {
  color: var(--muted);
  font-weight: 400;
}

.pill {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 600;
  padding: 0.15rem 0.4rem;
  border-radius: 5px;
  background: var(--accent-soft);
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.pill.absent {
  background: rgba(35, 33, 46, 0.05);
  color: var(--faint);
}

.empty {
  text-align: center;
  color: var(--faint);
  font-size: 0.85rem;
  padding: 1.75rem 1rem;
  line-height: 1.5;
}

/* ---------- Buttons ---------- */

.btn {
  display: block;
  width: 100%;
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 0.9rem;
  border-radius: 12px;
  border: none;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  margin-bottom: 1rem;
  transition: filter 0.15s;
}

.btn:hover {
  filter: brightness(1.08);
}

.btn:disabled {
  opacity: 0.55;
  cursor: default;
}

.btn-sub {
  background: var(--ink);
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
}

.btn-ghost:hover {
  color: var(--ink);
  filter: none;
  background: rgba(35, 33, 46, 0.03);
}

/* ---------- Forms ---------- */

.form {
  display: none;
}

.form.open {
  display: block;
}

.field {
  margin-bottom: 0.9rem;
}

.field label {
  display: block;
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

.field .label-hint {
  text-transform: none;
  letter-spacing: 0;
  font-weight: 400;
  color: var(--faint);
}

input[type="text"],
input[type="number"],
input[type="date"],
input[type="password"],
select,
textarea {
  width: 100%;
  font-family: inherit;
  font-size: 0.9rem;
  color: var(--ink);
  padding: 0.6rem 0.7rem;
  border: 1px solid rgba(35, 33, 46, 0.16);
  border-radius: 10px;
  background: #fdfcfa;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

textarea {
  resize: vertical;
  line-height: 1.5;
}

.field-row {
  display: flex;
  gap: 0.7rem;
}

.field-row > .field {
  flex: 1;
}

/* Wordle-style attempt picker */
.attempts {
  display: flex;
  gap: 0.4rem;
}

.attempts button {
  flex: 1;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  padding: 0.65rem 0;
  border-radius: 10px;
  border: 1px solid rgba(35, 33, 46, 0.16);
  background: #fdfcfa;
  color: var(--ink);
  cursor: pointer;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}

.attempts button:hover {
  border-color: var(--accent);
}

.attempts button.sel {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.attempts button.fail.sel {
  background: var(--bad);
  border-color: var(--bad);
}

.readout {
  font-size: 0.74rem;
  color: var(--muted);
  margin-top: 0.4rem;
  min-height: 1.1em;
}

.status {
  font-size: 0.8rem;
  margin-top: 0.75rem;
  min-height: 1.2em;
}

.status.ok { color: var(--good); }
.status.err { color: var(--bad); }

/* ---------- Game page header ---------- */

.game-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
  padding-bottom: 1.1rem;
  border-bottom: 1px solid var(--line);
}

.game-head h1 {
  font-family: 'Playfair Display', serif;
  font-weight: 900;
  font-size: 2rem;
  margin: 0;
  line-height: 1.1;
  color: var(--accent);
}

.game-head .tag {
  font-size: 0.76rem;
  color: var(--muted);
  margin-top: 0.3rem;
}

.game-head .play {
  flex-shrink: 0;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  text-decoration: none;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 999px;
  padding: 0.4rem 0.75rem;
  margin-top: 0.3rem;
}

.game-head .play:hover {
  background: var(--accent);
  color: #fff;
}

/* ---------- History sparkline ---------- */

.spark {
  width: 100%;
  height: 90px;
  display: block;
  margin-bottom: 0.25rem;
}

.spark-axis {
  display: flex;
  justify-content: space-between;
  font-size: 0.65rem;
  color: var(--faint);
  margin-bottom: 0.75rem;
}

.stat-row {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.stat {
  flex: 1;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.75rem;
  text-align: center;
}

.stat .v {
  font-family: 'Playfair Display', serif;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.stat .k {
  font-size: 0.62rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--faint);
  margin-top: 0.35rem;
}

/* ---------- Suggestions ---------- */

.suggestion {
  border-bottom: 1px solid rgba(35, 33, 46, 0.06);
  padding: 0.9rem 0.6rem;
}

.suggestion:last-child {
  border-bottom: none;
}

.suggestion .s-head {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
}

.suggestion .s-name {
  font-size: 0.8rem;
  font-weight: 700;
}

.suggestion .s-time {
  font-size: 0.68rem;
  color: var(--faint);
}

.suggestion .s-text {
  font-size: 0.87rem;
  line-height: 1.5;
  white-space: pre-wrap;
  color: #3b3849;
}

.btn-x {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--faint);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 0.2rem;
}

.btn-x:hover { color: var(--bad); }

td .btn-x {
  margin-left: 0.4rem;
  font-size: 0.9rem;
  opacity: 0;
}

tbody tr:hover td .btn-x {
  opacity: 1;
}

/* ---------- Modal ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(35, 33, 46, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  z-index: 50;
}

.modal {
  background: var(--card);
  border-radius: var(--radius);
  padding: 1.5rem;
  max-width: 340px;
  width: 100%;
  box-shadow: 0 20px 40px -12px rgba(35, 33, 46, 0.35);
}

.modal h3 {
  font-family: 'Playfair Display', serif;
  font-size: 1.2rem;
  margin: 0 0 0.3rem;
}

.modal p {
  font-size: 0.8rem;
  color: var(--muted);
  margin: 0 0 1rem;
  line-height: 1.45;
}

.modal-actions {
  display: flex;
  gap: 0.6rem;
  margin-top: 1rem;
}

.modal-actions .btn {
  margin-bottom: 0;
}

.footer {
  text-align: center;
  font-size: 0.68rem;
  color: var(--faint);
  margin-top: 3rem;
  line-height: 1.6;
}

.footer a {
  color: var(--muted);
}

@media (max-width: 480px) {
  .header h1 { font-size: 2.1rem; }
  .game-head h1 { font-size: 1.6rem; }
  .container { padding: 1.5rem 1rem 3rem; }
  table { font-size: 0.8rem; }
  tbody td, thead th { padding: 0.5rem 0.4rem; }
}
