/* base.css — shell, typography, auth, lobby, errors, mobile
   ---------------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }

html { min-height: 100%; }

body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.55;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  position: relative;
  isolation: isolate;
}

/* ── Cinematic background ─────────────────────────── */
.quantum-bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
  background:
    radial-gradient(ellipse 80% 60% at 80% 10%, rgba(176,108,255,0.18), transparent 60%),
    radial-gradient(ellipse 70% 50% at 10% 90%, rgba(122,215,255,0.15), transparent 60%),
    radial-gradient(ellipse 50% 50% at 50% 50%, rgba(138,77,224,0.06), transparent 70%),
    linear-gradient(180deg, #07080c 0%, #0b0d14 100%);
}
.quantum-bg::before,
.quantum-bg::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  filter: blur(90px);
  opacity: 0.55;
  animation: drift 22s ease-in-out infinite alternate;
}
.quantum-bg::before {
  width: 520px; height: 520px;
  top: -160px; right: -140px;
  background: radial-gradient(circle, rgba(176,108,255,0.35), transparent 70%);
}
.quantum-bg::after {
  width: 640px; height: 640px;
  bottom: -240px; left: -200px;
  background: radial-gradient(circle, rgba(122,215,255,0.30), transparent 70%);
  animation-delay: -11s;
}
@keyframes drift {
  0%   { transform: translate(0, 0) scale(1); }
  50%  { transform: translate(40px, -30px) scale(1.08); }
  100% { transform: translate(-20px, 30px) scale(0.96); }
}

/* subtle grain overlay */
.quantum-bg-grain {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  opacity: 0.05;
  background-image:
    repeating-radial-gradient(circle at 25% 25%, rgba(255,255,255,0.6) 0 1px, transparent 1px 40px),
    repeating-radial-gradient(circle at 75% 75%, rgba(255,255,255,0.4) 0 1px, transparent 1px 40px);
  mix-blend-mode: overlay;
}

/* ── Typography ───────────────────────────────────── */
h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 500;
  letter-spacing: -0.015em;
  margin: 0 0 var(--s-4) 0;
  line-height: 1.15;
}
h1 { font-size: clamp(28px, 3.6vw, 44px); }
h2 { font-size: 22px; }
h3 { font-size: 17px; }

p { margin: 0 0 var(--s-3) 0; }

a {
  color: var(--cyan);
  text-decoration: none;
  transition: color var(--t-fast) var(--ease);
}
a:hover { color: #b6ecff; text-decoration: underline; text-underline-offset: 3px; }

code, pre, .mono { font-family: var(--font-mono); font-size: 13px; }

::selection { background: rgba(122,215,255,0.35); color: var(--fg); }

/* ── Header ───────────────────────────────────────── */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--s-4) var(--s-6);
  border-bottom: 1px solid var(--border);
  background: rgba(11, 13, 20, 0.55);
  backdrop-filter: blur(16px) saturate(140%);
  -webkit-backdrop-filter: blur(16px) saturate(140%);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 500;
  color: var(--fg);
  letter-spacing: 0.01em;
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  transition: opacity var(--t-fast) var(--ease);
}
.brand:hover { text-decoration: none; opacity: 0.85; }
.brand-mark {
  display: inline-flex;
  width: 26px; height: 26px;
  align-items: center;
  justify-content: center;
  border-radius: var(--r-1);
  background: var(--grad-hero);
  box-shadow: var(--glow-cyan);
  color: #08090e;
  font-weight: 700;
  font-family: var(--font-mono);
  font-size: 14px;
}
.brand-text {
  background: var(--grad-hero);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
}

.site-nav {
  display: flex;
  align-items: center;
  gap: var(--s-4);
}
.site-nav a {
  color: var(--fg-dim);
  font-size: 14px;
  padding: var(--s-1) var(--s-2);
  border-radius: var(--r-1);
  transition: color var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
}
.site-nav a:hover { color: var(--fg); text-decoration: none; background: rgba(255,255,255,0.04); }
.site-nav .user {
  color: var(--fg-dim);
  font-family: var(--font-mono);
  font-size: 12px;
  padding: var(--s-1) var(--s-3);
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
  background: rgba(255,255,255,0.02);
}

.site-main {
  flex: 1;
  padding: var(--s-8) var(--s-6);
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
  animation: page-in var(--t-slow) var(--ease-out);
}

@keyframes page-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Buttons ──────────────────────────────────────── */
button, .btn {
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0.01em;
  padding: var(--s-3) var(--s-5);
  background: rgba(255,255,255,0.04);
  color: var(--fg);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-2);
  cursor: pointer;
  transition:
    background var(--t-fast) var(--ease),
    border-color var(--t-fast) var(--ease),
    transform var(--t-fast) var(--ease),
    box-shadow var(--t-fast) var(--ease),
    color var(--t-fast) var(--ease);
  position: relative;
}
button:hover, .btn:hover {
  background: rgba(255,255,255,0.08);
  border-color: var(--border-hot);
}
button:active, .btn:active { transform: translateY(1px); }
button:disabled, .btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}
button:focus-visible, .btn:focus-visible {
  outline: none;
  box-shadow: var(--ring-cyan);
  border-color: var(--cyan);
}

button.primary, .btn.primary {
  background: var(--grad-button);
  color: #08090e;
  border-color: transparent;
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(90,183,236,0.28), inset 0 1px 0 rgba(255,255,255,0.35);
}
button.primary:hover, .btn.primary:hover {
  background: var(--grad-button-hover);
  box-shadow: 0 10px 28px rgba(122,215,255,0.35), inset 0 1px 0 rgba(255,255,255,0.4);
  transform: translateY(-1px);
}
button.primary:active, .btn.primary:active { transform: translateY(0); }

button.danger {
  border-color: rgba(255,106,106,0.4);
  color: var(--red);
}
button.danger:hover {
  background: rgba(255,106,106,0.12);
  border-color: rgba(255,106,106,0.6);
}

button.link-btn, .link-btn {
  background: transparent;
  border: none;
  padding: 0;
  color: var(--cyan);
  font-size: inherit;
  box-shadow: none;
}
button.link-btn:hover { text-decoration: underline; background: transparent; color: #b6ecff; }
button.link-btn:focus-visible { box-shadow: none; outline: 2px solid var(--cyan); outline-offset: 3px; border-radius: 2px; }

.btn-sm { padding: var(--s-1) var(--s-3); font-size: 13px; }

/* ── Inputs ───────────────────────────────────────── */
input[type="text"],
input[type="password"],
input[type="email"],
select {
  font-family: var(--font-body);
  font-size: 15px;
  padding: var(--s-3) var(--s-4);
  background: rgba(7, 8, 12, 0.6);
  color: var(--fg);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-2);
  outline: none;
  transition: border-color var(--t-fast) var(--ease),
              background var(--t-fast) var(--ease),
              box-shadow var(--t-fast) var(--ease);
  width: 100%;
}
input::placeholder { color: var(--fg-muted); }
input:hover, select:hover { border-color: rgba(255,255,255,0.22); }
input:focus, select:focus {
  border-color: var(--cyan);
  background: rgba(7, 8, 12, 0.85);
  box-shadow: var(--ring-cyan);
}
input:-webkit-autofill {
  -webkit-box-shadow: 0 0 0 30px #0b0d14 inset !important;
  -webkit-text-fill-color: var(--fg) !important;
  caret-color: var(--fg);
}

label {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  font-size: 12px;
  color: var(--fg-dim);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
label input, label select { margin-top: 0; text-transform: none; letter-spacing: 0; }

.inline-form {
  display: flex;
  gap: var(--s-2);
  align-items: stretch;
  flex-wrap: wrap;
}
.inline-form input, .inline-form select { flex: 1 1 160px; }

/* ── Feedback ─────────────────────────────────────── */
.feedback {
  font-size: 13px;
  min-height: 1.4em;
  margin: 0;
  color: var(--fg-dim);
}
.feedback.error { color: var(--red); }
.feedback.success { color: var(--green); }

/* ── Auth ─────────────────────────────────────────── */
.auth-wrap {
  min-height: calc(100vh - 72px - var(--s-16));
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--s-8) var(--s-4);
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--r-4);
  padding: var(--s-10) var(--s-8);
  box-shadow: var(--sh-3);
  backdrop-filter: blur(20px) saturate(140%);
  -webkit-backdrop-filter: blur(20px) saturate(140%);
  position: relative;
  overflow: hidden;
}
.auth-card::before {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--grad-panel);
  pointer-events: none;
  border-radius: inherit;
}
.auth-card::after {
  content: "";
  position: absolute;
  top: -1px; left: -1px; right: -1px;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(122,215,255,0.5), rgba(176,108,255,0.5), transparent);
  pointer-events: none;
}
.auth-eyebrow {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--cyan);
  margin-bottom: var(--s-3);
  text-align: center;
}
.auth-card h1 {
  text-align: center;
  margin-bottom: var(--s-2);
  font-size: 34px;
  background: var(--grad-hero);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
}
.auth-sub {
  text-align: center;
  color: var(--fg-dim);
  margin-bottom: var(--s-8);
  font-size: 14px;
}
.auth-form {
  display: flex;
  flex-direction: column;
  gap: var(--s-5);
  position: relative;
}
.auth-form button[type="submit"] {
  margin-top: var(--s-2);
  padding: var(--s-4);
  font-size: 15px;
}
.auth-card .auth-alt {
  text-align: center;
  color: var(--fg-dim);
  margin: var(--s-6) 0 0 0;
  font-size: 14px;
}

/* ── Lobby ────────────────────────────────────────── */
.lobby { max-width: 1100px; margin: 0 auto; }
.lobby-hero {
  margin-bottom: var(--s-10);
  text-align: left;
}
.lobby-hero .eyebrow {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--cyan);
  margin-bottom: var(--s-3);
}
.lobby-hero h1 {
  margin-bottom: var(--s-3);
  font-size: clamp(32px, 5vw, 52px);
}
.lobby-hero h1 .accent {
  background: var(--grad-hero);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
}
.lobby-hero p {
  color: var(--fg-dim);
  font-size: 16px;
  max-width: 620px;
}

.lobby-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--s-5);
}

.lobby-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--r-3);
  padding: var(--s-6);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  position: relative;
  overflow: hidden;
  transition: border-color var(--t-med) var(--ease), transform var(--t-med) var(--ease);
}
.lobby-card::before {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--grad-panel);
  pointer-events: none;
  border-radius: inherit;
}
.lobby-card:hover { border-color: var(--border-strong); }
.lobby-card > * { position: relative; }
.lobby-card h2 {
  font-size: 12px;
  margin-bottom: var(--s-4);
  color: var(--fg-dim);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-family: var(--font-body);
  font-weight: 600;
}
.lobby-card:first-child {
  grid-column: 1 / -1;
  background: linear-gradient(135deg, rgba(122,215,255,0.08), rgba(176,108,255,0.08)), var(--panel);
  border-color: rgba(122,215,255,0.22);
}

.invite-list, .game-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
}
.invite-list li, .game-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--s-3) var(--s-4);
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border);
  border-radius: var(--r-2);
  transition: background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease), transform var(--t-fast) var(--ease);
  gap: var(--s-3);
}
.invite-list li:hover, .game-list li:hover {
  background: rgba(255,255,255,0.06);
  border-color: var(--border-strong);
  transform: translateX(2px);
}
.invite-list .actions, .game-list .actions {
  display: flex; gap: var(--s-2);
  flex-shrink: 0;
}
.empty-note {
  color: var(--fg-muted);
  font-style: italic;
  font-size: 13px;
  padding: var(--s-4) 0;
  text-align: center;
}

.pill {
  display: inline-flex;
  align-items: center;
  padding: 3px var(--s-3);
  font-size: 11px;
  font-family: var(--font-mono);
  letter-spacing: 0.06em;
  border-radius: var(--r-pill);
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border-strong);
  color: var(--fg-dim);
  text-transform: uppercase;
}
.pill.cyan   { color: var(--cyan);   border-color: rgba(122,215,255,0.5); background: rgba(122,215,255,0.08); }
.pill.violet { color: var(--violet); border-color: rgba(176,108,255,0.5); background: rgba(176,108,255,0.08); }
.pill.red    { color: var(--red);    border-color: rgba(255,106,106,0.5); background: rgba(255,106,106,0.06); }
.pill.green  { color: var(--green);  border-color: rgba(107,212,154,0.5); background: rgba(107,212,154,0.06); }
.pill.amber  { color: var(--amber);  border-color: rgba(240,198,116,0.5); background: rgba(240,198,116,0.06); }

/* ── Error pages ──────────────────────────────────── */
.error-page, .error-card {
  text-align: center;
  padding: var(--s-20) var(--s-4);
  max-width: 560px;
  margin: 0 auto;
}
.error-page h1, .error-card h1 {
  font-size: clamp(80px, 14vw, 160px);
  line-height: 1;
  margin: 0 0 var(--s-4) 0;
  background: var(--grad-hero);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
  font-weight: 600;
  letter-spacing: -0.04em;
}
.error-page p, .error-card p { color: var(--fg-dim); font-size: 16px; margin: var(--s-3) 0; }

/* ── Full-page spinner (CSS-only, optional) ──────── */
.page-loader {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  z-index: 9999;
  transition: opacity 0.4s var(--ease-out), visibility 0.4s;
}
.page-loader.hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.spinner {
  width: 48px; height: 48px;
  border-radius: 50%;
  border: 2px solid rgba(122,215,255,0.15);
  border-top-color: var(--cyan);
  border-right-color: var(--violet);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* button loading state (non-functional, just in case a class gets toggled) */
button.loading, .btn.loading {
  color: transparent !important;
  pointer-events: none;
}
button.loading::after, .btn.loading::after {
  content: "";
  position: absolute;
  top: 50%; left: 50%;
  width: 16px; height: 16px;
  margin: -8px 0 0 -8px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #08090e;
  animation: spin 0.6s linear infinite;
}

/* ── Mobile nav & responsive ──────────────────────── */
@media (max-width: 720px) {
  .site-header {
    padding: var(--s-3) var(--s-4);
  }
  .site-main { padding: var(--s-6) var(--s-4); }
  .brand { font-size: 16px; }
  .site-nav { gap: var(--s-2); }
  .site-nav a, .site-nav button { font-size: 13px; padding: var(--s-1) var(--s-2); }
  .site-nav .user { display: none; }

  .lobby-grid { grid-template-columns: 1fr; gap: var(--s-4); }
  .lobby-card { padding: var(--s-5); }

  .auth-card {
    padding: var(--s-8) var(--s-6);
    border-radius: var(--r-3);
  }
  .auth-card h1 { font-size: 28px; }

  .invite-list li, .game-list li {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--s-2);
  }
  .invite-list .actions, .game-list .actions { width: 100%; justify-content: stretch; }
  .invite-list .actions button, .game-list .actions button { flex: 1; }
}

@media (max-width: 420px) {
  h1 { font-size: 26px; }
  .lobby-hero h1 { font-size: 30px; }
  .brand-text { display: none; }
}
