/* ═══════════════════════════════════════════════════════════════════════════
   QuizBattle — main.css
   Design tokens, typography, layout, mobile-first base
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Google Fonts ─────────────────────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700;800;900&display=swap');

/* ── Custom Properties (Design Tokens) ─────────────────────────────────────── */
:root {
  /* Brand colours */
  --c-red:    #e21b3c;
  --c-blue:   #1368ce;
  --c-green:  #26890c;
  --c-yellow: #d89e00;
  --c-purple: #46178f;
  --c-purple-dark: #2e0f6a;

  /* Neutral */
  --c-bg:         #f0f2ff;
  --c-surface:    #ffffff;
  --c-border:     #e0e4ef;
  --c-text:       #1a1a2e;
  --c-text-muted: #5c6080;
  --c-overlay:    rgba(70,23,143,.85);

  /* Functional */
  --c-success: #26890c;
  --c-error:   #e21b3c;
  --c-warning: #d89e00;

  /* Answer button shades (hover/active) */
  --c-red-dark:    #b5142e;
  --c-blue-dark:   #0d4fa0;
  --c-green-dark:  #1a6208;
  --c-yellow-dark: #a87900;

  /* Spacing scale */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 24px;
  --sp-6: 32px;
  --sp-7: 48px;
  --sp-8: 64px;

  /* Typography scale */
  --fs-xs:  12px;
  --fs-sm:  14px;
  --fs-md:  16px;
  --fs-lg:  20px;
  --fs-xl:  24px;
  --fs-2xl: 32px;
  --fs-3xl: 48px;
  --fs-4xl: 64px;

  /* Radius */
  --r-sm:   8px;
  --r-md:   12px;
  --r-lg:   20px;
  --r-full: 9999px;

  /* Shadows */
  --shadow-sm:  0 2px 8px rgba(0,0,0,.10);
  --shadow-md:  0 4px 16px rgba(0,0,0,.15);
  --shadow-lg:  0 8px 32px rgba(0,0,0,.20);
  --shadow-xl:  0 16px 48px rgba(0,0,0,.25);

  /* Transitions */
  --t-fast:   0.12s ease;
  --t-normal: 0.22s ease;
  --t-slow:   0.4s ease;
}

/* ── Reset ──────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }

body {
  font-family: 'Nunito', system-ui, -apple-system, sans-serif;
  background: var(--c-bg);
  color: var(--c-text);
  line-height: 1.5;
  min-height: 100vh;
}

img, svg { max-width: 100%; display: block; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font-family: inherit; }
ul, ol { list-style: none; }

/* ── Typography ─────────────────────────────────────────────────────────────── */
h1 { font-size: var(--fs-2xl); font-weight: 900; line-height: 1.2; }
h2 { font-size: var(--fs-xl);  font-weight: 800; line-height: 1.25; }
h3 { font-size: var(--fs-lg);  font-weight: 700; line-height: 1.3; }
h4 { font-size: var(--fs-md);  font-weight: 700; }

@media (min-width: 768px) {
  h1 { font-size: var(--fs-3xl); }
  h2 { font-size: var(--fs-2xl); }
}

/* ── Layout utilities ────────────────────────────────────────────────────────── */
.container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 var(--sp-4);
}
@media (min-width: 768px) { .container { padding: 0 var(--sp-6); } }

.flex      { display: flex; }
.flex-col  { display: flex; flex-direction: column; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: var(--sp-2); }
.gap-3 { gap: var(--sp-3); }
.gap-4 { gap: var(--sp-4); }
.gap-5 { gap: var(--sp-5); }
.text-center { text-align: center; }
.mt-2 { margin-top: var(--sp-2); }
.mt-3 { margin-top: var(--sp-3); }
.mt-4 { margin-top: var(--sp-4); }
.mt-5 { margin-top: var(--sp-5); }
.mb-3 { margin-bottom: var(--sp-3); }
.mb-4 { margin-bottom: var(--sp-4); }
.mb-5 { margin-bottom: var(--sp-5); }
.w-full { width: 100%; }
.hidden { display: none !important; }

/* ── Card ───────────────────────────────────────────────────────────────────── */
.card {
  background: var(--c-surface);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-md);
  padding: var(--sp-5);
}
@media (min-width: 768px) { .card { padding: var(--sp-6); } }

/* ── Buttons ────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-5);
  border: none;
  border-radius: var(--r-md);
  font-weight: 700;
  font-size: var(--fs-md);
  cursor: pointer;
  transition: transform var(--t-fast), box-shadow var(--t-fast), filter var(--t-fast);
  min-height: 48px;
  white-space: nowrap;
  text-align: center;
  user-select: none;
}
.btn:hover:not(:disabled)  { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.btn:active:not(:disabled) { transform: translateY(0); }
.btn:disabled              { opacity: .5; cursor: not-allowed; }

.btn-primary {
  background: var(--c-purple);
  color: #fff;
}
.btn-primary:hover:not(:disabled) { background: var(--c-purple-dark); }

.btn-success {
  background: var(--c-green);
  color: #fff;
}
.btn-danger {
  background: var(--c-red);
  color: #fff;
}
.btn-outline {
  background: transparent;
  border: 2px solid var(--c-border);
  color: var(--c-text);
}
.btn-outline:hover:not(:disabled) { border-color: var(--c-purple); color: var(--c-purple); }

.btn-lg {
  padding: var(--sp-4) var(--sp-7);
  font-size: var(--fs-lg);
  border-radius: var(--r-lg);
  min-height: 64px;
}
.btn-sm {
  padding: var(--sp-2) var(--sp-3);
  font-size: var(--fs-sm);
  min-height: 36px;
}
.btn-icon {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: var(--r-sm);
  min-height: unset;
}

/* ── Forms ──────────────────────────────────────────────────────────────────── */
.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  margin-bottom: var(--sp-4);
}
.form-group label {
  font-weight: 700;
  font-size: var(--fs-sm);
  color: var(--c-text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.form-control {
  width: 100%;
  padding: var(--sp-3) var(--sp-4);
  border: 2px solid var(--c-border);
  border-radius: var(--r-md);
  font-size: var(--fs-md);
  font-family: inherit;
  color: var(--c-text);
  background: var(--c-surface);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
  min-height: 48px;
}
.form-control:focus {
  outline: none;
  border-color: var(--c-purple);
  box-shadow: 0 0 0 3px rgba(70,23,143,.15);
}
.form-control.error { border-color: var(--c-red); }
.form-error {
  font-size: var(--fs-sm);
  color: var(--c-red);
  font-weight: 600;
}
select.form-control { cursor: pointer; }
textarea.form-control { min-height: 100px; resize: vertical; }

/* ── Navigation ─────────────────────────────────────────────────────────────── */
.navbar {
  background: var(--c-purple);
  color: #fff;
  padding: var(--sp-3) 0;
  box-shadow: var(--shadow-md);
  position: sticky;
  top: 0;
  z-index: 100;
}
.navbar .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
}
.navbar-brand {
  font-size: var(--fs-xl);
  font-weight: 900;
  color: #fff;
  letter-spacing: -.02em;
}
.navbar-brand span { color: #ffd700; }
.navbar-nav {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}
.navbar-nav a {
  color: rgba(255,255,255,.85);
  font-weight: 700;
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r-sm);
  transition: background var(--t-fast), color var(--t-fast);
  font-size: var(--fs-sm);
}
.navbar-nav a:hover, .navbar-nav a.active {
  background: rgba(255,255,255,.15);
  color: #fff;
}
.navbar-nav .btn-sm { background: #ffd700; color: var(--c-purple); }

/* ── Alert / Flash ──────────────────────────────────────────────────────────── */
.alert {
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-md);
  font-weight: 600;
  margin-bottom: var(--sp-4);
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
}
.alert-success { background: #e8f5e9; color: #1b5e20; border-left: 4px solid var(--c-green); }
.alert-error   { background: #fce4ec; color: #880e24; border-left: 4px solid var(--c-red); }
.alert-info    { background: #e3f2fd; color: #0d47a1; border-left: 4px solid var(--c-blue); }
.alert-warning { background: #fff8e1; color: #663c00; border-left: 4px solid var(--c-yellow); }

/* ── Badge ──────────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px var(--sp-2);
  border-radius: var(--r-full);
  font-size: var(--fs-xs);
  font-weight: 700;
}
.badge-purple { background: var(--c-purple); color: #fff; }
.badge-green  { background: var(--c-green); color: #fff; }
.badge-red    { background: var(--c-red); color: #fff; }

/* ── Table ──────────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-sm);
}
th, td {
  padding: var(--sp-3) var(--sp-4);
  text-align: left;
  border-bottom: 1px solid var(--c-border);
}
th { font-weight: 700; color: var(--c-text-muted); text-transform: uppercase; font-size: var(--fs-xs); letter-spacing: .05em; }
tr:hover td { background: rgba(70,23,143,.04); }

/* ── Page header ─────────────────────────────────────────────────────────────── */
.page-header {
  padding: var(--sp-5) 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--sp-4);
}

/* ── Grid ───────────────────────────────────────────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: 1fr; gap: var(--sp-4); }
.grid-3 { display: grid; grid-template-columns: 1fr; gap: var(--sp-4); }
@media (min-width: 640px)  { .grid-2 { grid-template-columns: repeat(2,1fr); } }
@media (min-width: 768px)  { .grid-3 { grid-template-columns: repeat(2,1fr); } }
@media (min-width: 1024px) { .grid-3 { grid-template-columns: repeat(3,1fr); } }

/* ── Spinner ────────────────────────────────────────────────────────────────── */
.spinner {
  width: 40px; height: 40px;
  border: 4px solid rgba(70,23,143,.2);
  border-top-color: var(--c-purple);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  margin: var(--sp-5) auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Toggle (checkbox as switch) ────────────────────────────────────────────── */
.toggle {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  cursor: pointer;
  user-select: none;
}
.toggle input[type=checkbox] { display: none; }
.toggle-track {
  width: 44px; height: 24px;
  background: var(--c-border);
  border-radius: var(--r-full);
  position: relative;
  transition: background var(--t-fast);
}
.toggle-track::after {
  content: '';
  position: absolute;
  top: 2px; left: 2px;
  width: 20px; height: 20px;
  background: #fff;
  border-radius: 50%;
  transition: transform var(--t-fast);
  box-shadow: var(--shadow-sm);
}
.toggle input:checked + .toggle-track { background: var(--c-purple); }
.toggle input:checked + .toggle-track::after { transform: translateX(20px); }

/* ── Lobby hero background ───────────────────────────────────────────────────── */
.hero-bg {
  background: linear-gradient(135deg, var(--c-purple) 0%, #7b2ff7 50%, #1368ce 100%);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--sp-5);
  color: #fff;
}

/* ── Auth pages ──────────────────────────────────────────────────────────────── */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-5);
  background: linear-gradient(135deg, var(--c-purple-dark) 0%, var(--c-purple) 100%);
}
.auth-card {
  background: var(--c-surface);
  border-radius: var(--r-lg);
  padding: var(--sp-7);
  width: 100%;
  max-width: 440px;
  box-shadow: var(--shadow-xl);
}
.auth-logo {
  text-align: center;
  margin-bottom: var(--sp-5);
  font-size: var(--fs-2xl);
  font-weight: 900;
  color: var(--c-purple);
}
.auth-logo span { color: var(--c-red); }

/* ── Drag handle ────────────────────────────────────────────────────────────── */
.drag-handle {
  cursor: grab;
  color: var(--c-border);
  padding: var(--sp-2);
  font-size: var(--fs-xl);
}
.drag-handle:active { cursor: grabbing; }
.sortable-ghost { opacity: .4; background: var(--c-bg); }

/* ── Quiz card ──────────────────────────────────────────────────────────────── */
.quiz-card {
  background: var(--c-surface);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: transform var(--t-normal), box-shadow var(--t-normal);
  border: 2px solid transparent;
}
.quiz-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
  border-color: var(--c-purple);
}
.quiz-card-body { padding: var(--sp-4); }
.quiz-card-footer {
  padding: var(--sp-3) var(--sp-4);
  background: var(--c-bg);
  border-top: 1px solid var(--c-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2);
  flex-wrap: wrap;
}
