/* =====================================================
   JEUX TOURAK - Gaming Dark Theme + Mobile
   ===================================================== */
:root {
  --bg-0: #06081a;
  --bg-1: #0a0e27;
  --bg-2: #131836;
  --bg-3: #1d2347;
  --line: rgba(255,255,255,0.08);
  --line-strong: rgba(255,255,255,0.16);
  --text: #e8eaf2;
  --text-dim: #9aa0bf;
  --muted: #6b7194;
  --primary: #6366f1;
  --primary-2: #8b5cf6;
  --accent: #22d3ee;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --gold: #fbbf24;
  --silver: #cbd5e1;
  --bronze: #b45309;
  --shadow: 0 8px 24px rgba(0,0,0,0.4);
  --shadow-glow: 0 0 32px rgba(99,102,241,0.35);
  --radius: 14px;
  --radius-lg: 22px;
  --header-h: 64px;
  --container: 1280px;
  --grad-1: linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #ec4899 100%);
  --grad-2: linear-gradient(135deg, #22d3ee 0%, #6366f1 100%);
  --grad-card: linear-gradient(165deg, rgba(99,102,241,0.10), rgba(139,92,246,0.04));
}

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

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

body {
  margin: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg-0);
  background-image:
    radial-gradient(ellipse 80% 60% at 20% -10%, rgba(99,102,241,0.25), transparent 60%),
    radial-gradient(ellipse 70% 50% at 100% 20%, rgba(139,92,246,0.20), transparent 60%),
    radial-gradient(ellipse 60% 40% at 30% 110%, rgba(34,211,238,0.15), transparent 60%);
  min-height: 100vh;
  overflow-x: hidden;
}

a { color: var(--accent); text-decoration: none; transition: color .15s; }
a:hover { color: var(--primary-2); }

h1, h2, h3, h4 { margin: 0 0 .6em; line-height: 1.2; letter-spacing: -0.02em; }
h1 { font-size: clamp(1.8rem, 3.6vw, 2.6rem); }
h2 { font-size: clamp(1.4rem, 2.8vw, 1.9rem); }
h3 { font-size: 1.2rem; }

img { max-width: 100%; height: auto; }
button { font-family: inherit; }

/* ====== Topbar ====== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  height: var(--header-h);
  padding: 0 1.4rem;
  background: rgba(10,14,39,0.85);
  backdrop-filter: blur(14px) saturate(160%);
  -webkit-backdrop-filter: blur(14px) saturate(160%);
  border-bottom: 1px solid var(--line);
}
.logo {
  display: flex;
  align-items: center;
  gap: .55rem;
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text);
  letter-spacing: .02em;
}
.logo-icon { font-size: 1.6rem; filter: drop-shadow(0 0 8px rgba(99,102,241,.5)); }
.logo strong { background: var(--grad-1); -webkit-background-clip: text; background-clip: text; color: transparent; }

.nav-main {
  display: flex;
  gap: 1.4rem;
  margin-left: auto;
}
.nav-main a {
  color: var(--text-dim);
  font-weight: 500;
  font-size: .95rem;
  padding: .35rem 0;
  border-bottom: 2px solid transparent;
}
.nav-main a:hover { color: var(--text); border-bottom-color: var(--primary); }

.nav-user { display: flex; gap: .6rem; align-items: center; margin-left: auto; }
.user-chip {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .35rem .35rem .35rem .8rem;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 99px;
}
.user-points { font-weight: 600; color: var(--gold); font-size: .9rem; }
.user-name { color: var(--text); font-weight: 600; font-size: .9rem; }
.btn-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px;
  background: var(--bg-3); border-radius: 50%; color: var(--text-dim);
}
.btn-icon:hover { background: var(--danger); color: white; }

.nav-toggle { display: none; background: transparent; border: 0; color: var(--text); font-size: 1.5rem; cursor: pointer; }

/* ====== Buttons ====== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  padding: .65rem 1.2rem;
  font-size: .95rem;
  font-weight: 600;
  border-radius: 99px;
  border: 0;
  cursor: pointer;
  transition: transform .12s, box-shadow .15s, background .15s;
  text-decoration: none;
  line-height: 1;
}
.btn:active { transform: translateY(1px); }
.btn-primary {
  background: var(--grad-1);
  color: white;
  box-shadow: 0 6px 18px rgba(99,102,241,0.35);
}
.btn-primary:hover { color: white; box-shadow: 0 10px 26px rgba(99,102,241,.55); transform: translateY(-2px); }
.btn-ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--line-strong);
}
.btn-ghost:hover { background: var(--bg-2); color: var(--text); }
.btn-full { width: 100%; }
.btn-lg { padding: .9rem 1.6rem; font-size: 1.05rem; }

/* ====== Flash / Alert ====== */
.flash {
  max-width: var(--container);
  margin: 1rem auto;
  padding: .8rem 1.2rem;
  background: rgba(34,211,238,0.12);
  border: 1px solid rgba(34,211,238,0.4);
  border-radius: var(--radius);
  color: var(--accent);
}
.alert { padding: .8rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; }
.alert-error { background: rgba(239,68,68,.1); border: 1px solid rgba(239,68,68,.4); color: #fca5a5; }
.alert-success { background: rgba(34,197,94,.1); border: 1px solid rgba(34,197,94,.4); color: #86efac; }

/* ====== Main ====== */
.main {
  max-width: var(--container);
  margin: 0 auto;
  padding: 1.5rem 1.4rem 4rem;
}

/* ====== Hero ====== */
.hero {
  position: relative;
  padding: 3rem 1.5rem 4rem;
  text-align: center;
  border-radius: var(--radius-lg);
  background: var(--grad-card);
  border: 1px solid var(--line);
  margin-bottom: 2.5rem;
  overflow: hidden;
}
.hero::before {
  content: '';
  position: absolute; inset: -1px;
  background: var(--grad-1);
  opacity: .08;
  filter: blur(40px);
  z-index: 0;
}
.hero > * { position: relative; z-index: 1; }
.hero h1 {
  font-size: clamp(2rem, 5vw, 3.4rem);
  font-weight: 800;
  margin-bottom: .5rem;
}
.hero h1 span { background: var(--grad-1); -webkit-background-clip: text; background-clip: text; color: transparent; }
.hero p { max-width: 640px; margin: 0 auto 1.6rem; color: var(--text-dim); font-size: 1.1rem; }
.hero-cta { display: flex; gap: .8rem; justify-content: center; flex-wrap: wrap; }
.hero-stats { display: flex; gap: 2rem; justify-content: center; flex-wrap: wrap; margin-top: 2.4rem; }
.hero-stat strong { display: block; font-size: 1.8rem; font-weight: 800; background: var(--grad-1); -webkit-background-clip: text; background-clip: text; color: transparent; }
.hero-stat span { color: var(--text-dim); font-size: .85rem; }

/* ====== Game grid ====== */
.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 1.2rem;
  flex-wrap: wrap;
  gap: .6rem;
}
.section-head h2 { margin: 0; }
.section-head .filters { display: flex; gap: .4rem; flex-wrap: wrap; }
.chip {
  padding: .35rem .8rem;
  border-radius: 99px;
  border: 1px solid var(--line);
  font-size: .85rem;
  color: var(--text-dim);
  background: var(--bg-2);
  cursor: pointer;
  text-decoration: none;
  transition: all .15s;
}
.chip:hover, .chip.active { color: var(--text); border-color: var(--primary); background: rgba(99,102,241,.15); }

.games-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1.1rem;
}
.game-card {
  position: relative;
  display: block;
  padding: 1.4rem 1.2rem 1.2rem;
  background: var(--grad-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  transition: transform .2s, border-color .2s, box-shadow .2s;
  text-decoration: none;
  color: var(--text);
}
.game-card::before {
  content: '';
  position: absolute; top: -40px; right: -40px;
  width: 120px; height: 120px;
  background: var(--card-color, var(--primary));
  opacity: .15;
  border-radius: 50%;
  filter: blur(30px);
  transition: opacity .25s;
}
.game-card:hover {
  transform: translateY(-4px);
  border-color: var(--card-color, var(--primary));
  box-shadow: 0 14px 30px rgba(0,0,0,.4), 0 0 0 1px var(--card-color, var(--primary));
  color: var(--text);
}
.game-card:hover::before { opacity: .3; }
.game-icon {
  font-size: 2.6rem;
  display: block;
  margin-bottom: .5rem;
  filter: drop-shadow(0 4px 10px rgba(0,0,0,.3));
}
.game-name { font-size: 1.15rem; font-weight: 700; margin: .2rem 0; }
.game-desc { font-size: .85rem; color: var(--text-dim); margin-bottom: .8rem; min-height: 2.5em; }
.game-meta { display: flex; justify-content: space-between; align-items: center; font-size: .8rem; color: var(--muted); }
.game-meta .badge { background: rgba(99,102,241,.15); color: var(--primary-2); padding: .15rem .55rem; border-radius: 99px; font-weight: 600; }

/* ====== Auth ====== */
.auth-wrap {
  max-width: 460px;
  margin: 2rem auto;
  padding: 0 1rem;
}
.auth-card {
  padding: 2rem 1.8rem;
  background: var(--grad-card);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}
.auth-card h1 { font-size: 1.6rem; margin-bottom: .3rem; }
.muted { color: var(--text-dim); font-size: .92rem; margin-bottom: 1.4rem; }
.auth-link { text-align: center; margin-top: 1.2rem; color: var(--text-dim); }

.form { display: flex; flex-direction: column; gap: 1rem; }
.form label { display: flex; flex-direction: column; gap: .35rem; font-size: .9rem; color: var(--text-dim); font-weight: 500; }
.form .req { color: var(--danger); }
.form input, .form textarea, .form select {
  padding: .75rem 1rem;
  background: var(--bg-1);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
  transition: border-color .15s, box-shadow .15s;
}
.form input:focus, .form textarea:focus, .form select:focus {
  outline: 0;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99,102,241,.25);
}
.form small { color: var(--muted); font-size: .8rem; }

/* ====== Dashboard ====== */
.profile-head {
  display: flex;
  gap: 1.5rem;
  align-items: center;
  padding: 2rem 1.6rem;
  background: var(--grad-card);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  margin-bottom: 1.6rem;
  flex-wrap: wrap;
}
.avatar-lg {
  width: 96px; height: 96px; border-radius: 50%;
  background: var(--grad-1);
  display: flex; align-items: center; justify-content: center;
  font-size: 2.6rem; font-weight: 800; color: white;
  border: 3px solid var(--bg-3);
  box-shadow: var(--shadow-glow);
}
.profile-info { flex: 1; min-width: 220px; }
.profile-info h1 { margin: 0; font-size: 1.8rem; }
.profile-info .lv { display: inline-block; padding: .2rem .7rem; background: var(--grad-1); border-radius: 99px; font-size: .8rem; font-weight: 700; color: white; margin-top: .4rem; }
.profile-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 1rem; width: 100%; }
.stat-card {
  padding: 1rem;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  text-align: center;
}
.stat-card strong { display: block; font-size: 1.5rem; font-weight: 700; }
.stat-card span { color: var(--text-dim); font-size: .8rem; }

/* ====== Leaderboard ====== */
.lb-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.lb-table th, .lb-table td { padding: .85rem 1rem; text-align: left; }
.lb-table th { background: var(--bg-2); font-size: .85rem; text-transform: uppercase; letter-spacing: .05em; color: var(--text-dim); }
.lb-table tr { border-bottom: 1px solid var(--line); }
.lb-table tr:last-child { border-bottom: 0; }
.lb-table tr:hover { background: var(--bg-2); }
.lb-rank { font-weight: 800; font-size: 1.05rem; width: 60px; }
.lb-rank.gold { color: var(--gold); }
.lb-rank.silver { color: var(--silver); }
.lb-rank.bronze { color: var(--bronze); }
.lb-user { display: flex; align-items: center; gap: .6rem; }
.lb-user .avatar-sm { width: 32px; height: 32px; border-radius: 50%; background: var(--grad-1); display:flex;align-items:center;justify-content:center;color:white;font-weight:700;font-size:.85rem; }

/* ====== Game page ====== */
.game-wrap {
  display: grid;
  grid-template-columns: minmax(0,1fr) 320px;
  gap: 1.4rem;
}
.game-canvas-box {
  position: relative;
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  padding: 1rem;
}
.game-canvas-box canvas {
  display: block;
  background: var(--bg-0);
  border-radius: 10px;
  width: 100%;
  max-width: 100%;
  touch-action: none;
}
.game-side {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.side-card {
  padding: 1.2rem;
  background: var(--grad-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.side-card h3 { font-size: 1rem; margin-bottom: .8rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: .05em; }
.score-big { font-size: 2.4rem; font-weight: 800; background: var(--grad-1); -webkit-background-clip: text; background-clip: text; color: transparent; }

.game-toolbar { display: flex; gap: .6rem; flex-wrap: wrap; margin-top: .8rem; }

/* ====== Mobile touch controls ====== */
.touch-controls {
  display: none;
  margin-top: 1rem;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.touch-pad {
  display: grid;
  grid-template-columns: 60px 60px 60px;
  grid-template-rows: 60px 60px 60px;
  gap: .4rem;
  justify-content: center;
}
.touch-btn {
  background: rgba(99,102,241,0.20);
  border: 1px solid var(--primary);
  color: var(--text);
  border-radius: 50%;
  font-size: 1.4rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform .08s, background .12s;
  -webkit-tap-highlight-color: transparent;
}
.touch-btn:active { background: var(--primary); transform: scale(0.92); }
.touch-btn.up    { grid-column: 2; grid-row: 1; }
.touch-btn.left  { grid-column: 1; grid-row: 2; }
.touch-btn.right { grid-column: 3; grid-row: 2; }
.touch-btn.down  { grid-column: 2; grid-row: 3; }
.touch-btn.center{ grid-column: 2; grid-row: 2; background: rgba(236,72,153,0.20); border-color: #ec4899; }

.touch-fire {
  display: flex;
  gap: 1rem;
  justify-content: center;
  margin-top: .8rem;
}
.touch-fire .touch-btn {
  width: 80px; height: 80px;
  border-radius: 50%;
  background: rgba(236,72,153,0.20);
  border-color: #ec4899;
}

.joystick-area {
  display: none;
  position: relative;
  width: 140px; height: 140px;
  background: rgba(99,102,241,0.10);
  border: 2px solid var(--primary);
  border-radius: 50%;
  margin: 1rem auto;
  touch-action: none;
}
.joystick-stick {
  position: absolute;
  top: 50%; left: 50%;
  width: 60px; height: 60px;
  background: var(--grad-1);
  border: 2px solid white;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  box-shadow: var(--shadow-glow);
  pointer-events: none;
}

@media (hover: none) and (pointer: coarse), (max-width: 900px) {
  .touch-controls { display: block; }
  .joystick-area.mobile-show { display: block; }
}

/* ====== Footer ====== */
.footer {
  border-top: 1px solid var(--line);
  background: rgba(6,8,26,.7);
  padding: 3rem 1.4rem 1.4rem;
  margin-top: 4rem;
}
.footer-grid {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1fr;
  gap: 2rem;
  max-width: var(--container);
  margin: 0 auto 2rem;
}
.footer h4 { margin-bottom: .8rem; font-size: 1rem; }
.footer ul { list-style: none; padding: 0; margin: 0; }
.footer li { margin-bottom: .35rem; }
.footer a { color: var(--text-dim); font-size: .9rem; }
.footer a:hover { color: var(--text); }
.footer-bottom { text-align: center; color: var(--muted); font-size: .85rem; padding-top: 1.5rem; border-top: 1px solid var(--line); }

/* ====== Modal / Overlay ====== */
.overlay {
  position: absolute; inset: 0;
  background: rgba(10,14,39,.92);
  display: flex; align-items: center; justify-content: center;
  flex-direction: column;
  gap: .8rem; padding: 1.4rem;
  text-align: center;
  z-index: 5;
  border-radius: 10px;
}
.overlay h2 { font-size: 1.8rem; margin: 0; }
.overlay .score-big { margin: .4rem 0; }
.overlay.hidden { display: none; }

/* ====== Quiz UI ====== */
.quiz-question { font-size: 1.3rem; font-weight: 600; margin-bottom: 1.4rem; line-height: 1.4; }
.quiz-options { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
.quiz-option {
  padding: .9rem 1.1rem;
  background: var(--bg-2);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  color: var(--text);
  cursor: pointer;
  text-align: left;
  font-size: 1rem;
  font-family: inherit;
  transition: all .15s;
}
.quiz-option:hover { border-color: var(--primary); background: rgba(99,102,241,.15); }
.quiz-option.correct { background: rgba(34,197,94,.2); border-color: var(--success); }
.quiz-option.wrong { background: rgba(239,68,68,.2); border-color: var(--danger); }
.quiz-progress {
  height: 6px;
  background: var(--bg-2);
  border-radius: 99px;
  overflow: hidden;
  margin-bottom: 1.4rem;
}
.quiz-progress > div { height: 100%; background: var(--grad-1); transition: width .3s; }

/* ====== Memory / Card grids ====== */
.card-grid {
  display: grid;
  gap: .6rem;
}
.mem-card {
  aspect-ratio: 1;
  background: var(--bg-2);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.8rem;
  cursor: pointer;
  transition: all .2s;
  -webkit-tap-highlight-color: transparent;
}
.mem-card.flipped { background: var(--grad-1); }
.mem-card.matched { background: rgba(34,197,94,.3); border-color: var(--success); }
.mem-card .face { display: none; }
.mem-card.flipped .face, .mem-card.matched .face { display: block; }

/* ====== Sudoku / Connect4 ====== */
.board {
  display: grid;
  gap: 2px;
  background: var(--line-strong);
  padding: 2px;
  border-radius: 10px;
  margin: 0 auto;
  user-select: none;
  -webkit-user-select: none;
}
.cell {
  background: var(--bg-2);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
  font-size: 1.2rem;
  cursor: pointer;
  transition: background .15s;
  -webkit-tap-highlight-color: transparent;
}
.cell:hover { background: var(--bg-3); }
.cell.selected { background: var(--primary); color: white; }
.cell.fixed { color: var(--text-dim); cursor: default; }
.cell.wrong { color: var(--danger); }

/* ====== Responsive ====== */
@media (max-width: 900px) {
  .game-wrap { grid-template-columns: 1fr; }
  .footer-grid { grid-template-columns: 1fr 1fr; }
  .nav-main { display: none; position: absolute; top: var(--header-h); left: 0; right: 0; flex-direction: column; gap: 0; padding: 1rem; background: var(--bg-1); border-bottom: 1px solid var(--line); }
  .nav-main a { padding: .8rem 0; border-bottom: 1px solid var(--line); }
  body.nav-open .nav-main { display: flex; }
  .nav-toggle { display: inline-block; }
  .nav-user .btn { padding: .5rem .9rem; font-size: .85rem; }
  .nav-user { margin-left: 0; }
}
@media (max-width: 560px) {
  .topbar { padding: 0 .9rem; gap: .6rem; }
  .logo span:not(.logo-icon) { display: none; }
  .quiz-options { grid-template-columns: 1fr; }
  .footer-grid { grid-template-columns: 1fr; }
  .user-chip .user-points { display: none; }
  .main { padding: 1rem .8rem 3rem; }
  .hero { padding: 2rem 1rem 2.4rem; }
  .game-canvas-box { padding: .6rem; }
  .games-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .8rem; }
  .game-card { padding: 1rem .8rem; }
  .game-icon { font-size: 2.1rem; }
  .game-name { font-size: 1rem; }
  .game-desc { font-size: .78rem; min-height: 2em; }
}
