/* =========================================================
   Sama Cours — responsive design
   Desktop  > 1200px
   Tablet   768px – 1199px
   Mobile   < 768px
   ========================================================= */

/* -------------------- Tablette -------------------- */

@media (max-width: 1199px) {
  :root {
    --sidebar-width: 240px;
  }

  .header-search {
    max-width: 280px;
  }

  .resource-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* -------------------- Mobile (< 768px) -------------------- */

@media (max-width: 767px) {
  :root {
    --tabbar-height: 60px;
  }

  .hamburger-btn {
    display: flex;
  }

  /* Nom du site plus discret sur téléphone */
  .logo-wordmark {
    font-size: 0.7rem;
    letter-spacing: 0.02em;
  }

  .logo-icon-img {
    height: 26px;
  }

  .site-logo {
    gap: 0.4rem;
  }

  /* Logo + recherche élargie : les onglets sont passés dans la bande fixe du bas, la recherche prend la place libérée */
  .site-header {
    gap: 0.5rem;
    padding: 0 0.6rem;
  }

  .hamburger-btn {
    width: 34px;
  }

  /* La recherche reste dans l'en-tête, comme sur desktop : plus de bouton loupe séparé ni de tiroir sous l'en-tête */
  .search-toggle-btn {
    display: none;
  }

  .header-search {
    display: flex;
    flex: 1;
    max-width: none;
    margin: 0;
  }

  /* -------------------- Onglets (Accueil, Boutique, Vidéos…) : bande fixe en bas d'écran, icône + nom dessous -------------------- */

  .header-nav {
    position: fixed;
    inset: auto 0 0 0;
    z-index: 44;
    margin: 0;
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 1fr;
    gap: 0;
    background: linear-gradient(180deg, #16233a, var(--color-navy));
    border-top: 1px solid var(--color-navy-border);
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.18);
    padding-bottom: env(safe-area-inset-bottom);
  }

  .header-home-link {
    flex-direction: column;
    justify-content: center;
    gap: 0.2rem;
    padding: 0.45rem 0.1rem;
    border-radius: 0;
    font-size: 1.3rem;
  }

  .header-home-link span {
    font-size: 0.62rem;
    font-weight: 600;
    letter-spacing: 0.01em;
    white-space: nowrap;
  }

  .header-home-link.active {
    background: none; /* dans la bande du bas, la couleur propre à l'onglet (voir style.css) suffit à montrer l'onglet actif */
  }

  /* Plein écran réel (bouton « plein écran » du lecteur) seulement : la bande reste visible pendant
     la lecture normale d'un manuel ou d'une vidéo, body.is-fullscreen posée par reader.js (fullscreenchange). */
  body.is-fullscreen .header-nav {
    display: none;
  }

  /* Lecteur de manuel (zone verrouillée en hauteur, défilement interne — voir style.css « page-manuel ») :
     réserver aussi la hauteur de la bande du bas, sinon le fond des pages (la dernière surtout, rien à
     défiler après) reste caché dessous. Pas besoin en plein écran : le navigateur fait alors remplir tout
     l'écran à .manual-viewer, hors de cette contrainte de hauteur. */
  body.page-manuel:not(.is-fullscreen) .main-content {
    height: calc(100vh - var(--header-height) - var(--tabbar-height) - env(safe-area-inset-bottom));
    height: calc(100dvh - var(--header-height) - var(--tabbar-height) - env(safe-area-inset-bottom));
  }

  .app-layout {
    position: relative;
  }

  .sidebar {
    position: fixed;
    top: var(--header-height);
    left: 0;
    height: calc(100vh - var(--header-height));
    width: min(85vw, 320px);
    z-index: 50;
    transform: translateX(-100%);
    transition: transform var(--transition-base);
    box-shadow: var(--shadow-lg);
  }

  body.sidebar-open .sidebar {
    transform: translateX(0);
  }

  body.sidebar-open .sidebar-overlay {
    display: block;
  }

  .sidebar-overlay[hidden] {
    display: none;
  }

  .main-content {
    margin-left: 0;
    padding: 1rem 1rem calc(1.25rem + var(--tabbar-height) + env(safe-area-inset-bottom));
    width: 100%;
  }

  .classes-grid,
  .subjects-grid,
  .manuals-grid {
    grid-template-columns: 1fr 1fr;
  }

  .resource-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.85rem;
  }
}

@media (max-width: 420px) {
  .classes-grid,
  .subjects-grid,
  .manuals-grid {
    grid-template-columns: 1fr;
  }
}

/* -------------------- Desktop large -------------------- */

@media (min-width: 1200px) {
  .main-content {
    padding: 2rem 2.5rem 3rem;
  }
}

@media (min-width: 1600px) {
  .page-content {
    max-width: 1400px;
  }

  .resource-grid {
    grid-template-columns: repeat(5, 1fr);
  }
}

.hero-actions-more { display: none; }
/* Sous l'image de l'accueil (02/11) : bouton « Voir les corrections » sur tous les écrans, à côté de « Partager » (partage natif : téléphone seulement). */
.hero-share { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 0.6rem; margin-top: 0.8rem; }
.hero-share .share-btn--auto { display: none; }
.hero-corr { display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem; height: 42px; padding: 0 1.2rem 0 0.4rem; border-radius: 999px; border: 2px solid var(--color-primary, #b8872b); background: #fff; color: var(--color-primary-dark, #8f6212); font-weight: 700; font-size: 0.92rem; text-decoration: none; white-space: nowrap; box-shadow: 0 4px 12px rgba(143, 98, 18, 0.18); transition: transform 0.12s, box-shadow 0.15s, background 0.15s; }
.hero-corr-ico { display: grid; place-items: center; flex: none; width: 28px; height: 28px; border-radius: 50%; background: var(--color-primary, #b8872b); color: #fff; font-size: 0.95rem; line-height: 1; }
.hero-corr:hover, .hero-corr:focus-visible { background: #fff8e6; box-shadow: 0 8px 18px rgba(143, 98, 18, 0.28); transform: translateY(-1px); }
.hero-corr:focus-visible { outline: 3px solid rgba(184, 135, 43, 0.4); outline-offset: 2px; }
.hero-corr:active { transform: scale(0.97); }

/* -------------------- Accueil (mobile / fenêtre très basse : flux normal, défilement vertical) -------------------- */

@media (max-width: 700px), (max-height: 420px) {
  body.page-accueil .main-content {
    padding: 1rem 1rem calc(1.25rem + var(--tabbar-height, 60px) + env(safe-area-inset-bottom));
  }

  /* Mobile : le logo animé (gauche) et la photo (droite) côte à côte, de même taille, avec « Partager » dessous ;
     puis le titre et le reste en pleine largeur. */
  .hero {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    column-gap: 0.7rem;
    row-gap: 0.7rem;
    align-items: start;
    padding: 0.25rem 0 1rem;
  }

  .hero-text { display: contents; }
  .hero-visual { display: contents; }

  .hero-logo,
  .hero-visual > img {
    display: block;
    grid-row: 1;
    width: 100%;
    max-width: 100%;
    height: auto;
    aspect-ratio: 675 / 504;
    border-radius: 14px;
  }
  .hero-logo { grid-column: 1; box-shadow: var(--shadow-sm, 0 2px 8px rgba(0, 0, 0, 0.12)); }
  .hero-visual > img { grid-column: 2; }

  .hero-share { grid-column: 1 / -1; grid-row: 2; }

  .hero-eyebrow { grid-column: 1 / -1; grid-row: 3; align-self: end; margin: 0.2rem 0 0; font-size: 0.72rem; }

  .hero h1 {
    grid-column: 1 / -1;
    grid-row: 4;
    align-self: start;
    margin: 0;
    font-size: clamp(1.35rem, 6.2vw, 1.75rem);
    line-height: 1.15;
  }

  .hero-subtitle,
  .hero-actions,
  .hero-stats { grid-column: 1 / -1; }

  .hero-subtitle {
    font-size: 0.92rem;
    margin: 0.3rem 0 0;
  }

  /* Boutons de la page d'accueil : plus petits, deux par ligne, côte à côte */
  .hero-actions {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    gap: 0.5rem;
    margin: 0;
  }

  .hero-actions .btn {
    flex: 1 1 0;
    min-width: 0;
    justify-content: center;
    padding: 0.55rem 0.4rem;
    font-size: 0.8rem;
    line-height: 1.2;
    text-align: center;
  }

  /* Mini-badges « 4 classes · 8 matières · Accès hors ligne » : une seule ligne, plus petits */
  .hero-stats { display: flex; flex-wrap: nowrap; gap: 0.35rem; margin: 0; }
  .hero-stats li { flex: 0 1 auto; min-width: 0; padding: 0.3rem 0.5rem; gap: 0.25rem; font-size: 0.68rem; white-space: nowrap; }
  .hero-stats li svg { width: 0.85em; height: 0.85em; flex: none; }

  /* Raccourcis « Cours · Exercices corrigés · Annales · Fiches mémo » : deux colonnes, plus petits */
  body.page-accueil .shortcuts { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.5rem; padding: 0.6rem; margin: 1rem 0 0.5rem; }
  body.page-accueil .shortcut { padding: 0.35rem; gap: 0.5rem; font-size: 0.78rem; line-height: 1.2; }
  body.page-accueil .shortcut-icon { width: 2rem; height: 2rem; font-size: 0.85rem; flex: none; }
  /* Bouton « Partager » : pilule dorée à la largeur du texte, centrée, avec une pastille blanche pour l'icône (l'état « lien copié » garde le vert de share.css) */
  .hero-share { display: flex; justify-content: center; gap: 0.5rem; margin-top: 0; }
  .hero-share .share-btn--auto { display: inline-flex; }
  .hero-corr { height: 38px; padding: 0 0.9rem 0 0.35rem; font-size: 0.82rem; gap: 0.4rem; }
  .hero-corr-ico { width: 26px; height: 26px; font-size: 0.85rem; }
  .hero-share .share-btn { width: auto; flex: none; height: 38px; gap: 0.5rem; padding: 0 1.1rem 0 0.35rem; justify-content: center; font-size: 0.88rem; font-weight: 700; letter-spacing: 0.01em; white-space: nowrap; transition: transform 0.12s, box-shadow 0.15s, background 0.15s; }
  .hero-share .share-btn span { display: inline; }
  .hero-share .share-btn:not(.is-done) { background: linear-gradient(135deg, #cf9d36, var(--color-primary) 55%, var(--color-primary-dark)); border-color: transparent; color: #fff; box-shadow: 0 6px 14px rgba(150, 112, 31, 0.32), inset 0 1px 0 rgba(255, 255, 255, 0.28); }
  .hero-share .share-btn svg { flex: none; width: 26px; height: 26px; padding: 5px; box-sizing: border-box; border-radius: 50%; background: #fff; color: var(--color-primary-dark); font-size: 1rem; }
  .hero-share .share-btn:not(.is-done):hover, .hero-share .share-btn:not(.is-done):focus-visible { border-color: transparent; box-shadow: 0 8px 18px rgba(150, 112, 31, 0.42), inset 0 1px 0 rgba(255, 255, 255, 0.28); }
  .hero-share .share-btn:focus-visible { outline: 3px solid rgba(184, 135, 43, 0.4); outline-offset: 2px; }
  .hero-share .share-btn:active { transform: scale(0.96); }
  .hero-share .share-btn.is-done svg { background: #128c4a; color: #fff; }
  .hero-actions-more { display: flex; }

  .classes-grid-section h2 {
    font-size: 1.6rem;
  }

  /* Badges de classe : deux colonnes, plus petits */
  body.page-accueil .classes-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.6rem;
  }

  .class-card { padding: 0.8rem 0.65rem 0.6rem; gap: 0.4rem; }
  .class-card::before { height: 5px; }
  .class-card-head { gap: 0.4rem; }
  .class-card-name { font-size: 0.98rem; }
  .class-card-desc { font-size: 0.74rem; line-height: 1.25; }
  .class-card-icon { width: 1.9rem; height: 1.9rem; font-size: 0.9rem; }
  .class-card-chips { gap: 0.25rem; }
  .chip { padding: 0.08rem 0.38rem; font-size: 0.6rem; }
  .class-card-cta { font-size: 0.78rem; }

  .shortcuts {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 420px) {
  body:not(.page-accueil) .shortcuts {
    grid-template-columns: 1fr;
  }
}

/* Accueil : les classes restent sur une seule ligne dès que l'écran n'est plus mobile */
@media (min-width: 701px) {
  body.page-accueil .classes-grid {
    grid-template-columns: none;
    grid-auto-flow: column;
    grid-auto-columns: minmax(0, 1fr);
  }

  /* Cartes compactes : 7 classes sur une ligne */
  .class-card {
    padding: 1.2em 0.9em 1em;
    gap: 0.7em;
  }

  .class-card-head {
    flex-direction: column-reverse;
    align-items: flex-start;
    gap: 0.6em;
  }

  .class-card-name {
    font-size: 1.35em;
  }

  .class-card-desc {
    font-size: 0.9em;
  }

  .class-card-icon {
    width: 2.2em;
    height: 2.2em;
    font-size: 1.2em;
  }

  .chip {
    font-size: 0.75em;
    padding: 0.15em 0.55em;
  }
}

/* Page classe : 2 tuiles de matières par ligne sur téléphone */
@media (max-width: 520px) {
  .subject-tiles {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.8rem;
  }

  .subject-tile-name {
    font-size: 1rem;
  }
}

/* -------------------- Pages classe et matière sur téléphone : tout tient dans l'écran, sans défilement -------------------- */
@media (max-width: 700px) {
  body.page-classe .main-content,
  body.page-matiere .main-content { padding: 0.6rem 0.9rem 0.5rem; }
  body.page-classe .breadcrumb,
  body.page-matiere .breadcrumb { margin-bottom: 0.4rem; font-size: 0.78rem; }
  body.page-classe .page-header,
  body.page-matiere .page-header { margin-bottom: 0.6rem; }
  body.page-classe .page-header h1,
  body.page-matiere .page-header h1 { font-size: 1.15rem; margin: 0; }
  body.page-classe .page-eyebrow,
  body.page-matiere .page-eyebrow { font-size: 0.7rem; margin-bottom: 0.1rem; }

  /* Pages Quiz (accueil/classe/matière/quiz) et Banque d'exercices (accueil/classe/matière) : même réduction que classe/matière, texte de présentation inclus */
  body.page-quiz .page-header,
  body.page-banque .page-header { margin-bottom: 0.6rem; }
  body.page-quiz .page-header h1,
  body.page-banque .page-header h1 { font-size: 1.15rem; margin: 0; }
  body.page-quiz .page-eyebrow,
  body.page-banque .page-eyebrow { font-size: 0.7rem; margin-bottom: 0.1rem; }
  body.page-quiz .page-intro,
  body.page-banque .page-intro { font-size: 0.85rem; line-height: 1.45; }

  /* Boutons de partage : le mot « Partager » sur sa ligne, les boutons dessous, tous alignés sur une rangée */
  .page-header .share-bar { gap: 0.3rem; margin-top: 0.4rem; flex-wrap: nowrap; }
  .page-header .share-label { flex: 0 0 100%; margin: 0 0 0.05rem; font-size: 0.78rem; }
  .page-header .share-bar { flex-wrap: wrap; }
  .page-header .share-btn { height: 32px; flex: none; }
  .page-header .share-btn--copy { flex: 1 1 0; min-width: 0; width: auto; padding: 0 0.55rem; justify-content: flex-start; gap: 0.3rem; }
  .page-header .share-btn--copy span { display: block; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .page-header .share-btn--native { padding: 0 0.5rem; gap: 0.25rem; font-size: 0.78rem; }
  .page-header .share-btn:not(.share-btn--copy):not(.share-btn--native) { width: 32px; padding: 0; }

  /* Tuiles plus petites : 2 colonnes, hauteur adaptée à l'écran (4 rangées visibles d'un coup) */
  .subject-tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.45rem; }
  .subject-tile {
    aspect-ratio: auto;
    height: clamp(76px, calc((100dvh - 330px) / 4), 128px);
    padding: 0.35rem 0.4rem 0.45rem;
    gap: 0.1rem;
    border-radius: 14px;
  }
  /* l'illustration remplit la place restante au-dessus du nom, sans jamais le recouvrir */
  .subject-tile-art { position: relative; flex: 1 1 0; min-height: 0; overflow: hidden; font-size: 2rem; }
  .subject-tile-art img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
  .subject-tile-icon { font-size: 2.1rem; }
  .subject-tile-name { font-size: 0.85rem; line-height: 1.15; }
  .subject-tile-meta { font-size: 0.68rem; }
  body.page-classe .site-footer,
  body.page-matiere .site-footer { margin-top: 0.6rem; padding: 0.5rem 0 0.3rem; }
}

/* Très petits téléphones : icône et nom de la bande du bas un peu réduits pour que les 5-6 onglets
   (avec « Installer » quand il apparaît) tiennent sans retour à la ligne. */
@media (max-width: 430px) {
  .header-home-link {
    font-size: 1.15rem;
  }
  .header-home-link span {
    font-size: 0.58rem;
  }
}
@media (max-width: 380px) {
  .header-home-link span {
    font-size: 0.54rem;
  }
  .site-header {
    gap: 0.2rem;
    padding: 0 0.4rem;
  }
}

/* Onglet « Programmes » (18/10) : libellé un peu plus court dans la bande du bas des petits téléphones. */
@media (max-width: 430px) {
  .header-home-link .nav-label-long { display: none; }
  .header-home-link .nav-label-short { display: inline; }
}
