/*
 * LudiMesa — Main Stylesheet
 * Mobile-first. All colors use var() from themes.css.
 * Breakpoints: 640px (sm), 1024px (lg)
 */

/* ─── Reset & Base ───────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

html {
  font-size: 16px;
  scroll-behavior: smooth;
  /* theme applied here via data-theme attribute */
}

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background-color: var(--bg-page);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

img { max-width: 100%; display: block; }

/* ─── Typography ─────────────────────────────────────────────────────────── */
h1, h2, h3, h4 {
  line-height: 1.2;
  letter-spacing: -0.01em;
  color: var(--text-primary);
}

h1 { font-size: clamp(1.8rem, 5vw, 3rem); font-weight: 800; }
h2 { font-size: clamp(1.3rem, 4vw, 2rem); font-weight: 700; }
h3 { font-size: clamp(1rem, 3vw, 1.4rem); font-weight: 600; }
h4 { font-size: 1rem; font-weight: 600; }

p { color: var(--text-secondary); }

/* ─── Navigation ─────────────────────────────────────────────────────────── */
.nav {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  padding: 0 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
}

.nav__brand {
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--accent);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.nav__actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.nav__username {
  font-size: 0.875rem;
  color: var(--text-secondary);
  padding: 0.375rem 0.75rem;
  border-radius: 6px;
  cursor: pointer;
  border: 1px solid var(--border);
  background: transparent;
  transition: border-color 0.2s, color 0.2s;
}
.nav__username:hover {
  border-color: var(--border-focus);
  color: var(--text-primary);
}

/* ─── Admin panel page ───────────────────────────────────────────────────── */
.admin-panel {
  max-width: 640px;
  margin: 4rem auto;
  padding: 0 1rem;
}

.admin-panel__title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 0.375rem;
}

.admin-panel__sub {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-bottom: 2rem;
}

.admin-panel__grid {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.admin-panel__card {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 1rem;
  padding: 1.25rem 1.5rem;
  background: var(--bg-card);
  border: 2px solid var(--border-card);
  border-radius: 10px;
  box-shadow: var(--shadow-card);
  text-decoration: none;
  color: var(--text-secondary);
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.1s, box-shadow 0.15s;
}
.admin-panel__card:hover {
  background: var(--bg-card-hover);
  border-color: var(--accent);
  color: var(--accent);
  transform: translateX(4px);
  box-shadow: var(--shadow-card), -4px 0 0 0 var(--accent);
}
.admin-panel__card:active {
  transform: translateX(2px);
}

.admin-panel__card-icon {
  font-size: 1.5rem;
  color: var(--accent);
  flex-shrink: 0;
}

.admin-panel__card-label {
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}

/* ─── Buttons ────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.6rem 1.2rem;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: background 0.15s, transform 0.1s, box-shadow 0.15s;
  white-space: nowrap;
  line-height: 1;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn--primary {
  background: var(--accent);
  color: var(--text-inverse);
}
.btn--primary:hover { background: var(--accent-hover); box-shadow: var(--accent-glow); }

.btn--outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-primary);
}
.btn--outline:hover { border-color: var(--border-focus); background: var(--accent-dim); }

.btn--danger {
  background: transparent;
  border: 1px solid var(--danger);
  color: var(--danger);
}
.btn--danger:hover { background: var(--danger); color: #fff; }

.btn--ghost {
  background: transparent;
  color: var(--text-secondary);
  padding: 0.4rem 0.75rem;
}
.btn--ghost:hover { color: var(--text-primary); background: var(--accent-dim); }

.btn--sm { padding: 0.35rem 0.75rem; font-size: 0.75rem; border-radius: 6px; }
.btn--full { width: 100%; }

/* Loading state */
.btn.htmx-request { opacity: 0.7; pointer-events: none; }
.btn.htmx-request::after {
  content: '';
  width: 12px; height: 12px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin-left: 0.5rem;
}

/* ─── Forms ──────────────────────────────────────────────────────────────── */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.form-label {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-secondary);
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.form-input {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-radius: 8px;
  padding: 0.7rem 0.875rem;
  font-size: 0.9375rem;
  width: 100%;
  transition: border-color 0.2s, box-shadow 0.2s;
  -webkit-appearance: none;
}
.form-input:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
.form-input::placeholder { color: var(--text-muted); }

.form-stack { display: flex; flex-direction: column; gap: 1rem; }

/* ─── Auth error inline ──────────────────────────────────────────────────── */
.auth-error {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #fca5a5;
  border-radius: 8px;
  padding: 0.75rem 1rem;
  font-size: 0.875rem;
}

.auth-success {
  background: rgba(34, 197, 94, 0.1);
  border: 1px solid rgba(34, 197, 94, 0.3);
  color: #86efac;
  border-radius: 8px;
  padding: 0.75rem 1rem;
  font-size: 0.875rem;
}

/* ─── Cards ──────────────────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: 12px;
  padding: 1.25rem;
  box-shadow: var(--shadow-card);
  transition: background 0.2s, border-color 0.2s;
}
.card:hover { background: var(--bg-card-hover); border-color: var(--border); }

/* ─── Badges ─────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.55rem;
  border-radius: 20px;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.badge--pending { background: var(--badge-pending); color: var(--badge-pending-text); }
.badge--active  { background: var(--badge-active);  color: var(--badge-active-text); }

/* ─── Section headers ────────────────────────────────────────────────────── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.875rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}
.section-title {
  font-size: 0.875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

/* ─── Tabs (auth form toggle) ────────────────────────────────────────────── */
.tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.5rem;
}
.tab {
  flex: 1;
  padding: 0.75rem;
  text-align: center;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 0.2s, border-color 0.2s;
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
}
.tab.active, .tab:hover {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ─── Modal ──────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-overlay);
  display: flex;
  align-items: flex-end;      /* Mobile: slide up from bottom */
  justify-content: center;
  z-index: 200;
  padding: 0;
  animation: fadeIn 0.15s ease;
}

@media (min-width: 640px) {
  .modal-overlay { align-items: center; padding: 1rem; }
}

.modal {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 16px 16px 0 0;
  box-shadow: var(--shadow-modal);
  width: 100%;
  max-height: 90dvh;
  overflow-y: auto;
  padding: 1.5rem;
  animation: slideUp 0.2s ease;
}

@media (min-width: 640px) {
  .modal {
    border-radius: 16px;
    max-width: 480px;
    max-height: 80dvh;
    animation: fadeIn 0.15s ease;
  }
}

.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
}
.modal__close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.25rem;
  cursor: pointer;
  padding: 0.25rem;
  border-radius: 4px;
  transition: color 0.2s;
}
.modal__close:hover { color: var(--text-primary); }

/* ─── Frontpage layout ───────────────────────────────────────────────────── */
.frontpage {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Auth card — top of viewport on mobile */
.auth-section {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  padding: 1.5rem 1rem;
}

.auth-card {
  max-width: 420px;
  margin: 0 auto;
}

/* Hero below auth on mobile */
.hero-section {
  flex: 1;
  padding: 2rem 1rem;
  background: var(--game-hero-gradient);
}

.hero__eyebrow {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 0.5rem;
}

.hero__title { margin-bottom: 0.75rem; }

.hero__desc {
  font-size: 1rem;
  color: var(--text-secondary);
  margin-bottom: 1.5rem;
  max-width: 520px;
}

.hero__tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}

.hero__tag {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.3rem 0.75rem;
  border-radius: 20px;
  background: var(--accent-dim);
  color: var(--accent);
  border: 1px solid var(--border-focus);
}

/* Teaser card */
.teaser-section {
  padding: 2rem 1rem;
  background: var(--teaser-gradient);
  border-top: 1px solid var(--border);
}

.teaser-card {
  max-width: 640px;
  margin: 0 auto;
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: 12px;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.teaser-card__label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
}

.teaser-card__coming-soon {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--warning);
  background: rgba(245, 158, 11, 0.12);
  border: 1px solid rgba(245, 158, 11, 0.25);
  padding: 0.25rem 0.6rem;
  border-radius: 20px;
}

/* ─── Lobby layout ───────────────────────────────────────────────────────── */
.lobby {
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
}

@media (min-width: 1024px) {
  .lobby {
    flex-direction: row;
    align-items: flex-start;
    padding: 1.5rem;
    gap: 1.5rem;
  }
  .lobby__games   { flex: 1.4; }
  .lobby__friends { flex: 1; }
}

.lobby__panel {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
}

/* ─── Games list ─────────────────────────────────────────────────────────── */
.game-row {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 1rem 0;
  border-bottom: 1px solid var(--border);
}
.game-row:last-child { border-bottom: none; padding-bottom: 0; }

.game-row__meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  font-size: 0.8125rem;
  color: var(--text-secondary);
}

.game-row__host { font-weight: 600; color: var(--text-primary); }

.game-row__actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.empty-state {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--text-muted);
  font-size: 0.875rem;
}

/* ─── Friends panel ──────────────────────────────────────────────────────── */
.section-count {
  font-size: 0.75em;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0;
  text-transform: none;
}

.friend-search {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}
.friend-search .form-input { flex: 1; min-width: 0; }

/* Icon-only on mobile; show label on sm+ */
.btn__label { display: none; }
@media (min-width: 640px) {
  .btn__label { display: inline; }
}

/* Nav username: first name on mobile, full name on sm+ */
.nav__name--full { display: none; }
@media (min-width: 640px) {
  .nav__name--short { display: none; }
  .nav__name--full  { display: inline; }
}

.friend-list { display: flex; flex-direction: column; gap: 0; }
.friend-list--scrollable { max-height: calc(3 * 2.75rem); overflow-y: auto; }

.friend-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.625rem 0;
  border-bottom: 1px solid var(--border);
  gap: 0.5rem;
}
.friend-row:last-child { border-bottom: none; }

.friend-row__name {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-primary);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.friend-row__actions {
  display: flex;
  gap: 0.35rem;
  flex-shrink: 0;
}

.friends-sub-section { margin-top: 1.25rem; }

/* ─── Profile modal content ──────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: 10px;
  padding: 0.875rem;
  text-align: center;
}

.stat-card__value {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--accent);
  line-height: 1;
  margin-bottom: 0.25rem;
}

.stat-card__label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

/* Theme picker */
.theme-picker {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
}

.theme-swatch {
  aspect-ratio: 1;
  border-radius: 8px;
  cursor: pointer;
  border: 2px solid transparent;
  transition: border-color 0.2s, transform 0.15s;
  position: relative;
  overflow: hidden;
}
.theme-swatch:hover { transform: scale(1.08); }
.theme-swatch.active { border-color: var(--accent); }

.theme-swatch[data-swatch="dark_gaming"]     { background: linear-gradient(135deg, #0f1117, #d4904a); }
.theme-swatch[data-swatch="midnight_cyber"]  { background: linear-gradient(135deg, #080a12, #00e5ff); }
.theme-swatch[data-swatch="clean_editorial"] { background: linear-gradient(135deg, #eef0f8, #5b4fe0); }

/* ─── Diagnostics page ───────────────────────────────────────────────────── */
.diag-page {
  max-width: 720px;
  margin: 2rem auto;
  padding: 0 1rem;
}

.diag-table { width: 100%; border-collapse: collapse; margin-top: 1rem; }
.diag-table th, .diag-table td {
  text-align: left;
  padding: 0.625rem 0.875rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.875rem;
}
.diag-table th {
  color: var(--text-muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.diag-pass  { color: var(--success); }
.diag-fail  { color: var(--danger); }
.diag-warn  { color: var(--warning); }
.diag-error-detail {
  font-family: monospace;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
  word-break: break-all;
}

/* ─── Utility ────────────────────────────────────────────────────────────── */
.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

.text-muted { color: var(--text-muted); }
.text-sm    { font-size: 0.875rem; }
.mt-1       { margin-top: 0.25rem; }
.mt-2       { margin-top: 0.5rem; }
.mt-3       { margin-top: 0.75rem; }
.mt-4       { margin-top: 1rem; }
.gap-2      { gap: 0.5rem; }
.flex       { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.w-full     { width: 100%; }

/* ─── Animations ─────────────────────────────────────────────────────────── */
@keyframes fadeIn  { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
@keyframes spin    { to { transform: rotate(360deg); } }

/* HTMX indicators */
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator { display: inline; }
.htmx-request.htmx-indicator  { display: inline; }

/* ─── Ionicons ────────────────────────────────────────────────────────────── */
ion-icon {
  display: inline-block;
  vertical-align: middle;
  font-size: 1.1em;
  flex-shrink: 0;
}

.stat-card__icon {
  font-size: 1.5rem;
  margin-bottom: 0.25rem;
  color: var(--accent);
  display: block;
}

/* ─── Scrollbar (webkit) ─────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg-page); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
