/* ============================================================
   MathL1 Playground — Thème commun
   ============================================================ */

:root {
  --c-bg:        #f4f6fb;
  --c-surface:   #ffffff;
  --c-surface-2: #eef1f8;
  --c-border:    #e2e6f0;
  --c-text:      #1f2437;
  --c-text-soft: #5c6378;
  --c-primary:   #4f46e5;
  --c-primary-2: #4338ca;
  --c-accent:    #0d9488;
  --c-warn:      #b45309;
  --c-ok:        #15803d;
  --c-err:       #b91c1c;
  --c-info:      #1d4ed8;
  --radius:      14px;
  --shadow:      0 4px 18px rgba(31, 36, 55, 0.08);
  --shadow-lg:   0 10px 32px rgba(31, 36, 55, 0.14);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "Cascadia Code", Consolas, "Courier New", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font);
  background: var(--c-bg);
  color: var(--c-text);
  line-height: 1.55;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--c-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- En-tête & navigation ---------- */
.topbar {
  background: linear-gradient(135deg, var(--c-primary), #7c3aed);
  color: #fff;
  padding: 14px 22px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  box-shadow: var(--shadow);
}

.topbar .brand {
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: 0.3px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar .brand .logo {
  background: rgba(255, 255, 255, 0.18);
  border-radius: 10px;
  padding: 4px 8px;
  font-size: 1.3rem;
}

.topbar nav {
  margin-left: auto;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.topbar nav a {
  color: #fff;
  opacity: 0.85;
  font-weight: 600;
  font-size: 0.95rem;
  padding: 6px 12px;
  border-radius: 8px;
}

.topbar nav a:hover,
.topbar nav a.active {
  background: rgba(255, 255, 255, 0.16);
  opacity: 1;
  text-decoration: none;
}

/* ---------- Structure ---------- */
.container {
  width: 100%;
  max-width: 1080px;
  margin: 0 auto;
  padding: 24px 20px 48px;
  flex: 1;
}

.page-title {
  margin: 8px 0 4px;
  font-size: 1.7rem;
  font-weight: 800;
}

.page-sub {
  color: var(--c-text-soft);
  margin: 0 0 24px;
  max-width: 780px;
}

/* ---------- Cartes ---------- */
.card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.card h2, .card h3 { margin-top: 0; }

/* ---------- Grille d'outils (hub) ---------- */
.grid-tools {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 18px;
  margin-top: 18px;
}

.tool-card {
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.tool-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
}

.tool-card .t-icon {
  font-size: 2rem;
  margin-bottom: 10px;
}

.tool-card .t-title {
  font-size: 1.15rem;
  font-weight: 800;
  margin: 0 0 6px;
}

.tool-card .t-desc {
  color: var(--c-text-soft);
  font-size: 0.92rem;
  margin: 0 0 14px;
  flex: 1;
}

.tool-card .t-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 14px;
}

/* ---------- Badges & étiquettes ---------- */
.badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid transparent;
}

.badge-theme-analyse    { background:#eef2ff; color:#4338ca; border-color:#c7d2fe; }
.badge-theme-algebre    { background:#ecfdf5; color:#047857; border-color:#a7f3d0; }
.badge-theme-complexes  { background:#fdf2f8; color:#be185d; border-color:#fbcfe8; }
.badge-theme-logique    { background:#fffbeb; color:#b45309; border-color:#fde68a; }
.badge-format-jeu       { background:#fef2f2; color:#b91c1c; border-color:#fecaca; }
.badge-format-viz       { background:#eff6ff; color:#1d4ed8; border-color:#bfdbfe; }
.badge-format-exo       { background:#f5f3ff; color:#6d28d9; border-color:#ddd6fe; }
.badge-format-calc      { background:#f0fdf4; color:#15803d; border-color:#bbf7d0; }
.badge-l1               { background:#1f2437; color:#fff; }

/* ---------- Boutons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font: inherit;
  font-weight: 700;
  font-size: 0.95rem;
  border: none;
  border-radius: 10px;
  padding: 10px 18px;
  cursor: pointer;
  background: var(--c-primary);
  color: #fff;
  transition: background 0.15s ease, transform 0.1s ease;
}

.btn:hover { background: var(--c-primary-2); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn.secondary { background: #64748b; }
.btn.secondary:hover { background: #475569; }
.btn.outline { background: transparent; color: var(--c-primary); border: 2px solid var(--c-primary); }
.btn.outline:hover { background: #eef2ff; }
.btn.success { background: var(--c-ok); }
.btn.success:hover { background: #166534; }
.btn.ghost { background: transparent; color: var(--c-text-soft); }
.btn.ghost:hover { background: var(--c-surface-2); color: var(--c-text); }

.btn-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

/* ---------- Formulaires ---------- */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.field label {
  font-weight: 700;
  font-size: 0.9rem;
}

input[type="text"], input[type="number"], input[type="email"], select, textarea {
  font: inherit;
  padding: 9px 12px;
  border: 1.5px solid var(--c-border);
  border-radius: 10px;
  background: var(--c-surface);
  color: var(--c-text);
  width: 100%;
  max-width: 380px;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--c-primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}

/* ---------- Sliders ---------- */
input[type="range"] {
  width: 100%;
  max-width: 380px;
  accent-color: var(--c-primary);
}

/* ---------- Tableaux ---------- */
table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.95rem;
}

th, td {
  text-align: left;
  padding: 9px 12px;
  border-bottom: 1px solid var(--c-border);
}

th {
  font-weight: 700;
  color: var(--c-text-soft);
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

/* ---------- Formules mathématiques ---------- */
.mq {
  font-family: var(--font-mono);
  background: var(--c-surface-2);
  border-radius: 8px;
  padding: 2px 8px;
  font-size: 1.02em;
  white-space: nowrap;
}

.formula {
  font-family: var(--font-mono);
  background: var(--c-surface-2);
  border: 1px solid var(--c-border);
  border-radius: 10px;
  padding: 14px 18px;
  font-size: 1.15rem;
  overflow-x: auto;
}

/* ---------- Messages / feedback ---------- */
.msg {
  padding: 12px 16px;
  border-radius: 10px;
  font-weight: 600;
  border: 1px solid transparent;
  margin: 10px 0;
}

.msg.ok  { background:#f0fdf4; color:#166534; border-color:#bbf7d0; }
.msg.err { background:#fef2f2; color:#b91c1c; border-color:#fecaca; }
.msg.info{ background:#eff6ff; color:#1e40af; border-color:#bfdbfe; }
.msg.warn{ background:#fffbeb; color:#92400e; border-color:#fde68a; }

/* ---------- Quiz / choix ---------- */
.option {
  display: block;
  width: 100%;
  text-align: left;
  font: inherit;
  font-weight: 600;
  background: var(--c-surface);
  border: 2px solid var(--c-border);
  border-radius: 12px;
  padding: 12px 16px;
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s;
  margin-bottom: 8px;
}

.option:hover:not(:disabled) { border-color: var(--c-primary); background: #f5f6ff; }
.option:disabled { cursor: default; }
.option.correct  { border-color: var(--c-ok);  background: #f0fdf4; }
.option.wrong    { border-color: var(--c-err); background: #fef2f2; }

/* ---------- Pied de page ---------- */
.footer {
  text-align: center;
  color: var(--c-text-soft);
  font-size: 0.85rem;
  padding: 18px 20px;
  border-top: 1px solid var(--c-border);
  background: var(--c-surface);
}

/* ---------- Panneau de score ---------- */
.score-box {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.score-item {
  background: var(--c-surface-2);
  border-radius: 12px;
  padding: 8px 16px;
  min-width: 110px;
}

.score-item .label { font-size: 0.75rem; color: var(--c-text-soft); text-transform: uppercase; font-weight: 700; }
.score-item .value { font-size: 1.3rem; font-weight: 800; }

/* ---------- Panneau « Le point cours » ---------- */
.theorie .theorie-title { margin-bottom: 10px; }

.theorie-intro {
  color: var(--c-text-soft);
  max-width: 780px;
}

.theorie h3 {
  margin: 20px 0 10px;
  font-size: 1.05rem;
}

.theorie-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
}

.theorie-item {
  background: var(--c-surface-2);
  border: 1px solid var(--c-border);
  border-radius: 12px;
  padding: 12px 14px;
}

.theorie-item .ti-title {
  font-weight: 800;
  font-size: 0.95rem;
  color: var(--c-primary);
  margin-bottom: 4px;
}

.theorie-item .ti-text { font-size: 0.92rem; }

.theorie-astuces {
  margin: 8px 0 0;
  padding-left: 20px;
  color: var(--c-text-soft);
  font-size: 0.95rem;
}

.theorie-astuces li { margin-bottom: 4px; }

/* ---------- Classes utilitaires ---------- */
.hidden { display: none !important; }
.muted { color: var(--c-text-soft); }
.small { font-size: 0.85rem; }
.mt-8  { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-8  { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.row   { display: flex; gap: 16px; flex-wrap: wrap; align-items: center; }
.center { text-align: center; }
.text-ok   { color: var(--c-ok); }
.text-err  { color: var(--c-err); }
.text-warn { color: var(--c-warn); }
.mono { font-family: var(--font-mono); }

/* Canvas */
canvas {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: 12px;
  max-width: 100%;
}

/* ============================================================
   Mise en page générale (contenu + barre latérale publicitaire)
   ============================================================ */
.layout-main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 24px;
  align-items: start;
}

.layout-main .content {
  min-width: 0;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 18px;
  position: sticky;
  top: 16px;
}

@media (max-width: 1023px) {
  .layout-main {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: static;
    flex-direction: row;
    flex-wrap: wrap;
  }
  .sidebar .ad-slot {
    flex: 1 1 320px;
    max-width: 336px;
  }
}

@media (max-width: 639px) {
  .sidebar {
    flex-direction: column;
  }
  .sidebar .ad-slot {
    flex: 1 1 auto;
    max-width: none;
  }
}

/* ============================================================
   Emplacements publicitaires (AdSense / placeholders)
   ============================================================ */
.ad-slot {
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  margin: 0 auto;
}

.ad-zone {
  display: flex;
  flex-direction: column;
  gap: 18px;
  margin-top: 24px;
}

/* Boîte grise de secours (compte AdSense non configuré) */
.ad-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 90px;
  background: var(--c-surface-2);
  border: 1.5px dashed var(--c-border);
  border-radius: 12px;
  color: var(--c-text-soft);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 1.2px;
  text-transform: uppercase;
}

/* Emplacement haut — bannière horizontale */
.ad-top {
  width: 100%;
  max-width: 728px;
  margin: 16px auto 0;
}

.ad-top .ad-placeholder { min-height: 90px; }

/* Emplacements latéraux — blocs responsives */
.ad-sb {
  width: 100%;
  max-width: 300px;
}

.ad-sb .ad-placeholder { min-height: 250px; }

/* Sous l'outil et fin de contenu — blocs responsives pleine largeur */
.ad-below,
.ad-end {
  width: 100%;
  max-width: 728px;
  margin: 0 auto;
}

.ad-below .ad-placeholder,
.ad-end .ad-placeholder { min-height: 250px; }

@media (max-width: 639px) {
  .ad-top, .ad-below, .ad-end { max-width: 100%; }
  .ad-top .ad-placeholder { min-height: 100px; }
}
