:root, [data-theme="zinc"] {
  --bg: #09090b; --surface: #18181b; --border: #29292f;
  --text: #f4f4f5; --accent: #818cf8; --btn-text: #0b0b12; --muted: #a1a1aa;
}
[data-theme="midnight"] {
  --bg: #020617; --surface: #0f172a; --border: #1e293b;
  --text: #e2e8f0; --accent: #38bdf8; --btn-text: #041322; --muted: #7c93b0;
}
[data-theme="forest"] {
  --bg: #022c22; --surface: #064e3b; --border: #0d6e54;
  --text: #ecfdf5; --accent: #34d399; --btn-text: #022018; --muted: #6ee7b7;
}
[data-theme="pastel"] {
  --bg: #fdf2f8; --surface: #ffffff; --border: #f3d6e8;
  --text: #3b0764; --accent: #ec4899; --btn-text: #ffffff; --muted: #9d6bc4;
}

* { box-sizing: border-box; }
html, body {
  background-color: var(--bg); color: var(--text);
  transition: background-color 0.5s ease, color 0.5s ease;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  margin: 0; min-height: 100vh;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
button { font-family: inherit; cursor: pointer; }
input { font-family: inherit; }

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

.field-label, .label-sm {
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; font-weight: 700;
  color: var(--muted); margin: 0.75rem 0 0.25rem;
  display: block;
}

input[type="text"], input[type="password"], input:not([type]), select {
  width: 100%; padding: 0.6rem 0.75rem; border-radius: 0.6rem;
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
  font-size: 1rem; margin-bottom: 0.25rem;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.btn-primary {
  background: var(--accent); color: var(--btn-text); border: none;
  border-radius: 0.6rem; padding: 0.7rem 1.2rem; font-weight: 700;
  margin-top: 1rem; width: 100%; transition: transform 0.1s, filter 0.15s;
}
.btn-primary:hover { filter: brightness(1.08); }
.btn-primary:active { transform: scale(0.98); }
.btn-secondary {
  background: transparent; color: var(--text); border: 1px solid var(--border);
  border-radius: 0.6rem; padding: 0.6rem 1rem; font-weight: 600; transition: border-color 0.15s;
}
.btn-secondary:hover { border-color: var(--accent); }
.icon-btn {
  background: transparent; border: 1px solid var(--border); color: var(--text);
  border-radius: 0.5rem; height: 2.2rem; padding: 0 0.7rem;
  display: inline-flex; align-items: center; gap: 0.4rem; font-weight: 600; font-size: 0.85rem;
  transition: border-color 0.15s;
}
.icon-btn:hover { border-color: var(--accent); }

.alert { border-radius: 0.6rem; padding: 0.6rem 0.8rem; margin: 0.5rem 0; font-size: 0.9rem; }
.alert-error { color: #f87171; background: rgba(239,68,68,0.1); border: 1px solid rgba(239,68,68,0.2); }
.alert-success { color: #4ade80; background: rgba(34,197,94,0.1); border: 1px solid rgba(34,197,94,0.2); }

.auth-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1rem;
}
.auth-card { width: 100%; max-width: 26rem; }
.brand { margin: 0 0 0.25rem; font-size: 1.5rem; }
.brand-small { font-weight: 800; }

.boot-spinner { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.spinner {
  width: 2rem; height: 2rem; border-radius: 0.4rem; background: var(--accent);
  animation: spin-pulse 1s ease-in-out infinite;
}
@keyframes spin-pulse {
  0%, 100% { transform: rotate(0deg) scale(1); }
  50% { transform: rotate(180deg) scale(0.7); }
}

.navbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 10;
  background: color-mix(in srgb, var(--bg) 55%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.navbar-inner {
  max-width: 72rem; margin: 0 auto; padding: 0.9rem 1.25rem;
  display: flex; align-items: center; gap: 1.5rem;
}
.nav-links { display: flex; gap: 0.25rem; flex: 1; flex-wrap: wrap; }
.nav-link {
  background: transparent; border: none; color: var(--muted); font-weight: 600;
  padding: 0.4rem 0.7rem; border-radius: 0.5rem; font-size: 0.9rem; transition: background 0.15s, color 0.15s;
}
.nav-link:hover { color: var(--text); }
.nav-link.active { color: var(--btn-text); background: var(--accent); }
.nav-right { display: flex; align-items: center; gap: 0.5rem; position: relative; }
.theme-menu {
  position: absolute; top: 2.8rem; right: 0; background: var(--surface);
  border: 1px solid var(--border); border-radius: 0.6rem; padding: 0.4rem; z-index: 20;
  min-width: 10rem; box-shadow: 0 8px 24px rgba(0,0,0,0.25);
}
.theme-menu button {
  display: flex; align-items: center; gap: 0.5rem; width: 100%; background: transparent;
  border: none; color: var(--text); padding: 0.5rem 0.6rem; border-radius: 0.4rem; text-align: left;
  font-size: 0.9rem;
}
.theme-menu button:hover { background: var(--bg); }
.theme-menu button.current { font-weight: 700; }
.swatch { width: 0.85rem; height: 0.85rem; border-radius: 50%; display: inline-block; border: 1px solid rgba(255,255,255,0.2); }
#theme-btn .swatch { margin-right: 0.1rem; }

main { max-width: 72rem; margin: 0 auto; padding: 6rem 1.25rem 3rem; }
.footer {
  max-width: 72rem; margin: 0 auto; padding: 1rem 1.25rem 2rem;
  display: flex; justify-content: space-between; color: var(--muted); font-size: 0.8rem;
}

.view { animation: fade-in 0.3s ease; }
@keyframes fade-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

.hub-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); gap: 1.25rem; margin-top: 1.5rem; }
.game-card {
  cursor: pointer; text-align: center; transition: transform 0.15s, border-color 0.15s;
}
.game-card:hover { transform: translateY(-3px); border-color: var(--accent); }
.game-card .game-icon {
  width: 3rem; height: 3rem; border-radius: 0.8rem; background: var(--accent); color: var(--btn-text);
  display: flex; align-items: center; justify-content: center; font-size: 1.4rem; font-weight: 800;
  margin: 0 auto 0.6rem;
}
.game-card h2 { margin: 0.5rem 0; }

/* Wordle */
.wordle-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.wordle-grid { display: grid; grid-template-rows: repeat(6, 1fr); gap: 0.35rem; max-width: 22rem; margin: 0 auto 1.5rem; }
.wordle-row { display: grid; grid-template-columns: repeat(5, 1fr); gap: 0.35rem; }
.wordle-tile {
  aspect-ratio: 1; border: 2px solid var(--border); border-radius: 0.3rem;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.5rem; font-weight: 800; text-transform: uppercase;
  transition: transform 0.5s; color: var(--text);
}
.wordle-tile.flipping { animation: tile-flip 0.5s ease forwards; }
@keyframes tile-flip { 0% { transform: rotateY(0); } 50% { transform: rotateY(90deg); } 100% { transform: rotateY(0); } }
.wordle-tile.filled { transform: scale(1.05); border-color: var(--muted); }
.wordle-tile.correct { background: #16a34a; border-color: #16a34a; color: #fff; }
.wordle-tile.present { background: #ca8a04; border-color: #ca8a04; color: #fff; }
.wordle-tile.absent { background: #27272a; border-color: #27272a; color: #a1a1aa; }

.keyboard { max-width: 30rem; margin: 0 auto; padding: 0 0.5rem; }
.kb-row { display: flex; justify-content: center; gap: 0.3rem; margin-bottom: 0.4rem; }
.kb-key {
  min-width: 0; height: 3rem; border-radius: 0.4rem; border: none;
  background: var(--border); color: var(--text); font-weight: 700; font-size: 0.8rem;
  padding: 0 0.3rem; flex: 1 1 0; max-width: 3rem;
}
.kb-key.wide { max-width: 4.5rem; flex-grow: 1.5; font-size: 0.65rem; }
.kb-key.correct { background: #16a34a; color: #fff; }
.kb-key.present { background: #ca8a04; color: #fff; }
.kb-key.absent { background: #3f3f46; color: #71717a; }

.toast {
  position: fixed; top: 6rem; left: 50%; transform: translateX(-50%);
  background: var(--accent); color: var(--btn-text); padding: 0.6rem 1.2rem;
  border-radius: 0.6rem; font-weight: 700; z-index: 50;
}

.end-card { text-align: center; max-width: 24rem; margin: 1.5rem auto 0; }
.end-card .target-word { font-size: 1.4rem; font-weight: 800; letter-spacing: 0.2em; margin: 0.5rem 0; color: var(--accent); }
.countdown { font-variant-numeric: tabular-nums; font-weight: 700; margin: 0.5rem 0; }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; z-index: 30; padding: 1rem;
}
.modal { max-width: 26rem; width: 100%; }

/* Leaderboard */
.lb-row { display: flex; align-items: center; gap: 0.9rem; padding: 0.75rem 1rem; border-bottom: 1px solid var(--border); }
.lb-row:last-child { border-bottom: none; }
.lb-rank { width: 1.6rem; text-align: center; font-weight: 800; color: var(--muted); }
.lb-row.rank-1 { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.lb-avatar {
  width: 2.2rem; height: 2.2rem; border-radius: 50%; background: var(--border);
  display: flex; align-items: center; justify-content: center; font-weight: 700; flex-shrink: 0;
}
.lb-name { flex: 1; }
.lb-badge { font-size: 0.7rem; background: var(--accent); color: var(--btn-text); border-radius: 0.3rem; padding: 0.1rem 0.4rem; margin-left: 0.4rem; }
.lb-score { font-weight: 800; font-size: 1.1rem; color: var(--accent); }

/* Stats */
.stat-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(8rem, 1fr)); gap: 0.8rem; margin: 1rem 0 1.5rem; }
.stat-tile { text-align: center; }
.stat-tile .value { font-size: 1.6rem; font-weight: 800; color: var(--accent); }
.hist-row { display: flex; align-items: center; gap: 0.6rem; margin-bottom: 0.4rem; }
.hist-bar-track { flex: 1; background: var(--border); border-radius: 0.3rem; height: 1rem; overflow: hidden; }
.hist-bar { height: 100%; background: var(--accent); }

/* Admin */
.admin-row { display: flex; align-items: center; gap: 0.6rem; padding: 0.75rem 1rem; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.admin-row:last-child { border-bottom: none; }
.admin-actions { display: flex; gap: 0.4rem; margin-left: auto; }
.admin-actions button { font-size: 0.75rem; padding: 0.35rem 0.6rem; }
table.admin-table { width: 100%; border-collapse: collapse; }

section > h1 { margin-top: 0; }

/* Mobile */
@media (max-width: 640px) {
  .navbar-inner { padding: 0.6rem 0.75rem; gap: 0.75rem; }
  .nav-links {
    flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch;
    scrollbar-width: none; gap: 0.15rem;
  }
  .nav-links::-webkit-scrollbar { display: none; }
  .nav-link { padding: 0.35rem 0.55rem; font-size: 0.82rem; white-space: nowrap; flex-shrink: 0; }
  .brand-small { display: none; } /* reclaim width for the nav scroller + actions */
  #theme-btn .btn-label { display: none; } /* swatch-only on mobile, still tappable */

  main { padding: 4.5rem 0.75rem 2rem; }
  .card { padding: 1rem; }

  .footer { flex-direction: column; gap: 0.3rem; text-align: center; padding: 1rem 0.75rem 1.5rem; }

  .wordle-grid { gap: 0.25rem; margin-bottom: 1rem; }
  .wordle-row { gap: 0.25rem; }
  .wordle-tile { font-size: 1.1rem; border-radius: 0.25rem; }

  .keyboard { padding: 0 0.15rem; }
  .kb-row { gap: 0.2rem; }
  .kb-key { height: 2.6rem; font-size: 0.72rem; padding: 0 0.15rem; }
  .kb-key.wide { font-size: 0.58rem; }

  .admin-row { padding: 0.6rem 0.75rem; }
  .admin-actions { width: 100%; margin-left: 0; justify-content: flex-start; }

  .toast { top: 4.5rem; left: 1rem; right: 1rem; transform: none; text-align: center; }
}

@media (max-width: 360px) {
  .wordle-tile { font-size: 0.95rem; }
  .kb-key { height: 2.35rem; font-size: 0.65rem; }
}
