/**
 * Grouvel - Page d'apprentissage allemand (allemand.html)
 * Couvre : onglets, flashcards, tableaux conjugaison, dark mode.
 */

    :root {
      color-scheme: light dark;
      /* Couleurs des cas grammaticaux */
      --nominativ: #007aff;
      --akkusativ: #ff3b30;
      --dativ: #34c759;
      --genitiv: #af52de;
      /* Couleurs des temps */
      --prasens: #007aff;
      --prateritum: #ff9500;
      --perfekt: #ff3b30;
      --futur: #34c759;
      --k2prasens: #af52de;
      --k2prateritum: #ff2d55;
      /* Couleurs de base */
      --bg-page: radial-gradient(circle at 30% 20%, #e8f4f8 0%, #ffffff 100%);
      --text-main: #2d3142;
      --text-muted: #4a4a4a;
      --text-heading: #1c3d5a;
      --bg-card: rgba(255, 255, 255, 0.92);
      --bg-card-solid: #ffffff;
      --border-color: rgba(0, 0, 0, 0.08);
    }
    @media (prefers-color-scheme: dark) {
      :root {
        --nominativ: #64b5f6;
        --akkusativ: #ef7e7c;
        --dativ: #81c784;
        --genitiv: #ce93d8;
        --prasens: #64b5f6;
        --prateritum: #ffb74d;
        --perfekt: #ef7e7c;
        --futur: #81c784;
        --k2prasens: #ce93d8;
        --k2prateritum: #f48fb1;
        --bg-page: radial-gradient(circle at 30% 20%, #142025 0%, #16213e 100%);
        --text-main: #e8e8f0;
        --text-muted: #9ca3af;
        --text-heading: #e8e8f0;
        --bg-card: rgba(30, 30, 50, 0.92);
        --bg-card-solid: #1e1e2e;
        --border-color: rgba(255, 255, 255, 0.1);
      }
    }
    * { box-sizing: border-box; }
    body {
      margin: 0;
      font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, sans-serif;
      background: var(--bg-page);
      color: var(--text-main);
      display: flex;
      flex-direction: column;
      min-height: 100vh;
    }
    header {
      text-align: center;
      padding: 48px 16px 24px;
    }
    h1 {
      font-size: 2.9rem;
      margin: 0;
      color: var(--text-heading);
    }
    h1 .de {
      color: var(--nominativ);
    }
    header p {
      margin: 0.9em auto 2em;
      max-width: 720px;
      color: var(--text-muted);
      font-size: 1.05rem;
    }
    .nav-buttons {
      display: flex;
      justify-content: center;
      gap: 1em;
      flex-wrap: wrap;
      margin-top: 16px;
    }
    a.btn {
      display: inline-flex;
      align-items: center;
      gap: 0.5em;
      padding: 0.8em 1.6em;
      border-radius: 10px;
      background: linear-gradient(135deg, #007aff 0%, #0051d5 100%);
      color: #fff;
      text-decoration: none;
      font-weight: 600;
      box-shadow: 0 8px 20px rgba(0, 122, 255, 0.25);
      transition: all 0.25s ease-in-out;
    }
    a.btn:hover {
      transform: translateY(-2px) scale(1.02);
      box-shadow: 0 12px 28px rgba(0, 122, 255, 0.35);
    }
    a.btn.secondary {
      background: linear-gradient(135deg, #5856d6 0%, #3c3bb0 100%);
      box-shadow: 0 8px 20px rgba(88, 86, 214, 0.25);
    }
    a.btn.secondary:hover {
      box-shadow: 0 12px 28px rgba(88, 86, 214, 0.35);
    }

    main {
      flex: 1;
      width: 100%;
      max-width: 1200px;
      margin: 0 auto;
      padding: 0 18px 56px;
    }

    .section-tabs {
      display: flex;
      justify-content: center;
      gap: 1em;
      margin-bottom: 32px;
      flex-wrap: wrap;
    }
    .tab-btn {
      padding: 0.9em 2em;
      border: 2px solid var(--nominativ);
      border-radius: 12px;
      background: #fff;
      color: var(--nominativ);
      font-weight: 600;
      font-size: 1.05rem;
      cursor: pointer;
      transition: all 0.25s ease;
    }
    .tab-btn:hover {
      background: rgba(0, 122, 255, 0.08);
      transform: translateY(-2px);
    }
    .tab-btn.active {
      background: var(--nominativ);
      color: #fff;
      box-shadow: 0 8px 20px rgba(0, 122, 255, 0.3);
    }

    .tab-content {
      display: none;
    }
    .tab-content.active {
      display: block;
      animation: fadeIn 0.4s ease-in-out;
    }
    @keyframes fadeIn {
      from { opacity: 0; transform: translateY(10px); }
      to { opacity: 1; transform: translateY(0); }
    }

    /* Section Cours */
    .grammar-section {
      background: rgba(255, 255, 255, 0.95);
      border-radius: 20px;
      padding: 2.5em 2.8em;
      box-shadow: 0 14px 38px rgba(28, 61, 90, 0.12);
      margin-bottom: 2em;
      border: 1px solid rgba(0,0,0,0.04);
    }
    .grammar-section h2 {
      margin-top: 0;
      font-size: 1.9rem;
      color: #1c3d5a;
      border-bottom: 3px solid var(--nominativ);
      padding-bottom: 0.5em;
      margin-bottom: 1.2em;
    }
    .grammar-section h3 {
      font-size: 1.4rem;
      color: var(--nominativ);
      margin: 1.5em 0 0.8em;
    }

    .case-grid {
      display: grid;
      grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
      gap: 1.5em;
      margin: 1.5em 0;
    }
    .case-card {
      padding: 1.5em;
      border-radius: 14px;
      border: 2px solid;
      background: rgba(255, 255, 255, 0.8);
      transition: transform 0.2s ease;
    }
    .case-card:hover {
      transform: translateY(-3px);
      box-shadow: 0 8px 20px rgba(0,0,0,0.12);
    }
    .case-card.nominativ { border-color: var(--nominativ); }
    .case-card.akkusativ { border-color: var(--akkusativ); }
    .case-card.dativ { border-color: var(--dativ); }
    .case-card.genitiv { border-color: var(--genitiv); }

    .case-card h4 {
      margin: 0 0 0.8em;
      font-size: 1.3rem;
    }
    .case-card.nominativ h4 { color: var(--nominativ); }
    .case-card.akkusativ h4 { color: var(--akkusativ); }
    .case-card.dativ h4 { color: var(--dativ); }
    .case-card.genitiv h4 { color: var(--genitiv); }

    .case-card p {
      margin: 0.5em 0;
      font-size: 0.95rem;
      line-height: 1.6;
    }
    .case-card .example {
      font-style: italic;
      color: #555;
      margin-top: 1em;
      padding: 0.8em;
      background: rgba(0,0,0,0.03);
      border-radius: 8px;
    }

    table.declension {
      width: 100%;
      border-collapse: collapse;
      margin: 1.5em 0;
      background: #fff;
      border-radius: 12px;
      overflow: hidden;
      box-shadow: 0 4px 12px rgba(0,0,0,0.08);
    }
    table.declension th {
      background: linear-gradient(135deg, #007aff 0%, #0051d5 100%);
      color: #fff;
      padding: 1em;
      text-align: left;
      font-weight: 600;
    }
    table.declension td {
      padding: 0.9em 1em;
      border-bottom: 1px solid #e8e8e8;
    }
    table.declension tr:last-child td {
      border-bottom: none;
    }
    table.declension tr:hover {
      background: rgba(0, 122, 255, 0.04);
    }

    .preposition-list {
      display: flex;
      flex-wrap: wrap;
      gap: 0.7em;
      margin: 1em 0;
    }
    .prep-tag {
      padding: 0.6em 1.2em;
      border-radius: 8px;
      font-weight: 600;
      font-size: 0.95rem;
      color: #fff;
    }
    .prep-tag.akk { background: var(--akkusativ); }
    .prep-tag.dat { background: var(--dativ); }
    .prep-tag.gen { background: var(--genitiv); }
    .prep-tag.wechsel { background: linear-gradient(90deg, var(--akkusativ), var(--dativ)); }

    /* Section Flashcards */
    .flashcard-container {
      background: rgba(255, 255, 255, 0.95);
      border-radius: 20px;
      padding: 2.5em 2.8em;
      box-shadow: 0 14px 38px rgba(28, 61, 90, 0.12);
      border: 1px solid rgba(0,0,0,0.04);
      max-width: 800px;
      margin: 0 auto;
    }
    .flashcard-container h2 {
      text-align: center;
      font-size: 2rem;
      color: #1c3d5a;
      margin-top: 0;
    }

    .filter-controls {
      display: flex;
      justify-content: center;
      gap: 1em;
      margin: 2em 0;
      flex-wrap: wrap;
    }
    .filter-btn {
      padding: 0.7em 1.5em;
      border: 2px solid #ddd;
      border-radius: 10px;
      background: #fff;
      cursor: pointer;
      font-size: 0.95rem;
      font-weight: 600;
      transition: all 0.2s ease;
    }
    .filter-btn:hover {
      border-color: var(--nominativ);
      background: rgba(0, 122, 255, 0.05);
    }
    .filter-btn.active {
      border-color: var(--nominativ);
      background: var(--nominativ);
      color: #fff;
    }
    .filter-btn .count {
      font-weight: 700;
    }

    .search-and-tense {
      display: grid;
      grid-template-columns: minmax(0, 1fr);
      gap: 1.4em;
      margin-bottom: 2em;
    }
    .search-input {
      position: relative;
      display: block;
    }
    .search-input input {
      width: 100%;
      padding: 0.85em 1.05em;
      border-radius: 12px;
      border: 2px solid rgba(0,0,0,0.08);
      font-size: 16px; /* Minimum 16px pour éviter zoom iOS */
      transition: border-color 0.2s ease, box-shadow 0.2s ease;
    }
    .search-input input:focus {
      outline: none;
      border-color: var(--nominativ);
      box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.18);
    }
    .tense-selector {
      display: flex;
      flex-wrap: wrap;
      gap: 0.75em;
      padding: 0.9em 1em;
      border: 1px solid rgba(0,0,0,0.08);
      border-radius: 12px;
      background: rgba(0,0,0,0.02);
    }
    .tense-selector legend {
      font-weight: 600;
      font-size: 0.95rem;
      margin-right: 1em;
      color: #1c3d5a;
    }
    .tense-toggle {
      display: inline-flex;
      align-items: center;
      gap: 0.4em;
      font-size: 0.92rem;
      cursor: pointer;
      padding: 0.35em 0.75em;
      border-radius: 999px;
      background: #fff;
      border: 1px solid rgba(0,0,0,0.1);
      transition: border-color 0.2s ease, background 0.2s ease, color 0.2s ease;
    }
    .tense-toggle input {
      accent-color: var(--nominativ);
    }
    .tense-toggle.active {
      border-color: var(--nominativ);
      background: rgba(0, 122, 255, 0.12);
      color: #004a99;
    }

    .empty-state {
      margin: 0;
      font-size: 1rem;
      color: #334155;
      text-align: center;
    }

    .verb-lists {
      margin-top: 3em;
      display: flex;
      flex-direction: column;
      gap: 1.5em;
    }
    .verb-collection {
      border: 1px solid rgba(0,0,0,0.08);
      border-radius: 16px;
      background: rgba(255,255,255,0.9);
      transition: box-shadow 0.25s ease, border-color 0.25s ease;
    }
    .verb-collection[open] {
      border-color: rgba(0,122,255,0.4);
      box-shadow: 0 12px 30px rgba(15, 70, 140, 0.12);
    }
    .verb-collection summary {
      cursor: pointer;
      list-style: none;
      padding: 1.1em 1.4em;
      font-weight: 600;
      font-size: 1.05rem;
      color: #1c3d5a;
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 0.6em;
    }
    .verb-collection summary::-webkit-details-marker {
      display: none;
    }
    .verb-collection summary::after {
      content: '▼';
      font-size: 0.75rem;
      color: #64748b;
      transition: transform 0.2s ease;
    }
    .verb-collection[open] summary::after {
      transform: rotate(-180deg);
    }
    .collection-content {
      padding: 0 1.6em 1.6em;
      display: grid;
      gap: 1.2em;
    }
    .verb-panel {
      border: 1px solid rgba(148, 163, 184, 0.25);
      border-radius: 14px;
      padding: 1.2em 1.4em;
      background: #fff;
      box-shadow: 0 8px 24px rgba(15, 70, 140, 0.08);
    }
    .verb-panel header {
      margin-bottom: 1em;
    }
    .verb-panel h4 {
      margin: 0;
      font-size: 1.2rem;
      display: flex;
      align-items: baseline;
      gap: 0.6em;
      color: #1c3d5a;
    }
    .verb-panel h4 span {
      font-size: 0.95rem;
      color: #475569;
      font-weight: 500;
    }
    .verb-panel .verb-meta {
      margin: 0.4em 0 0;
      font-size: 0.9rem;
      color: #64748b;
    }

    .sr-only {
      position: absolute;
      width: 1px;
      height: 1px;
      padding: 0;
      margin: -1px;
      overflow: hidden;
      clip: rect(0, 0, 0, 0);
      border: 0;
    }

    .flashcard {
      position: relative;
      min-height: 400px;
      perspective: 1000px;
      margin: 2em 0 3em;
    }
    .flashcard-inner {
      position: relative;
      width: 100%;
      text-align: center;
      transition: transform 0.6s;
      transform-style: preserve-3d;
      cursor: pointer;
    }
    .flashcard.flipped .flashcard-inner {
      transform: rotateY(180deg);
    }
    .flashcard-front, .flashcard-back {
      position: absolute;
      width: 100%;
      backface-visibility: hidden;
      padding: 2.5em;
      border-radius: 16px;
      box-shadow: 0 10px 30px rgba(0,0,0,0.15);
      top: 0;
      left: 0;
    }
    .flashcard-front {
      background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
      color: #fff;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      min-height: 400px;
    }
    .flashcard-back {
      background: #fff;
      transform: rotateY(180deg);
      border: 2px solid #667eea;
      padding-bottom: 3em;
    }
    .verb-infinitive {
      font-size: 3rem;
      font-weight: 700;
      margin-bottom: 0.5em;
    }
    .verb-translation {
      font-size: 1.4rem;
      opacity: 0.9;
    }
    .verb-category {
      margin-top: 1.5em;
      font-size: 0.95rem;
      padding: 0.6em 1.2em;
      background: rgba(255,255,255,0.2);
      border-radius: 20px;
      display: inline-block;
    }

    .conjugation-grid {
      display: grid;
      gap: 1.5em;
      margin-top: 1em;
    }
    .tense-block {
      background: rgba(0,0,0,0.02);
      padding: 1.2em;
      border-radius: 12px;
      border-left: 4px solid;
    }
    .tense-block.prasens { border-left-color: var(--prasens); }
    .tense-block.prateritum { border-left-color: var(--prateritum); }
    .tense-block.perfekt { border-left-color: var(--perfekt); }
    .tense-block.futur { border-left-color: var(--futur); }
    .tense-block.k2prasens { border-left-color: var(--k2prasens); }
    .tense-block.k2prateritum { border-left-color: var(--k2prateritum); }

    .tense-block h4 {
      margin: 0 0 1em;
      font-size: 1.2rem;
      color: #1c3d5a;
    }
    .tense-block.prasens h4 { color: var(--prasens); }
    .tense-block.prateritum h4 { color: var(--prateritum); }
    .tense-block.perfekt h4 { color: var(--perfekt); }
    .tense-block.futur h4 { color: var(--futur); }
    .tense-block.k2prasens h4 { color: var(--k2prasens); }
    .tense-block.k2prateritum h4 { color: var(--k2prateritum); }

    .conjugation-row {
      display: grid;
      grid-template-columns: 80px 1fr;
      gap: 1em;
      margin: 0.5em 0;
      align-items: center;
    }
    .pronoun {
      font-weight: 600;
      color: #555;
    }
    .form {
      font-weight: 700;
      font-size: 1.05rem;
      color: #1c3d5a;
    }

    .nav-controls {
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-top: 2em;
      gap: 1em;
    }
    .nav-btn {
      padding: 0.9em 1.8em;
      border: none;
      border-radius: 10px;
      background: linear-gradient(135deg, #007aff 0%, #0051d5 100%);
      color: #fff;
      font-weight: 600;
      font-size: 1rem;
      cursor: pointer;
      transition: all 0.25s ease;
      box-shadow: 0 4px 12px rgba(0, 122, 255, 0.25);
    }
    .nav-btn:hover {
      transform: translateY(-2px);
      box-shadow: 0 8px 20px rgba(0, 122, 255, 0.35);
    }
    .nav-btn:disabled {
      opacity: 0.4;
      cursor: not-allowed;
      transform: none;
    }
    .card-counter {
      font-weight: 600;
      color: #555;
      font-size: 1.05rem;
    }

    @media (min-width: 768px) {
      .search-and-tense {
        grid-template-columns: 1.2fr 1fr;
        align-items: start;
      }
    }

    /* Responsive */
    @media (max-width: 640px) {
      h1 { font-size: 2rem; }
      header p { font-size: 0.95rem; }
      .grammar-section { padding: 1.8em 1.5em; }
      .flashcard-container { padding: 1.8em 1.5em; }
      .case-grid { grid-template-columns: 1fr; }
      .tab-btn { padding: 0.75em 1.5em; font-size: 0.95rem; }
      .verb-infinitive { font-size: 2.2rem; }
      .verb-translation { font-size: 1.1rem; }
      .flashcard {
        margin: 1.5em 0 2em;
      }
      .flashcard-front, .flashcard-back { padding: 1.5em; }
      .nav-btn { padding: 0.75em 1.4em; font-size: 0.95rem; }
      .conjugation-row { grid-template-columns: 60px 1fr; }
      .tense-block h4 { font-size: 1.1rem; }
      .conjugation-row .form { font-size: 0.95rem; }
      .collection-content {
        padding: 0 1.2em 1.2em;
      }
      .verb-panel h4 {
        flex-direction: column;
        gap: 0.2em;
      }
      /* Tables plus compactes sur mobile */
      table.declension { font-size: 0.9rem; }
      table.declension th { padding: 0.8em 0.7em; }
      table.declension td { padding: 0.7em 0.6em; }
    }

    @media (min-width: 768px) {
      .search-and-tense {
        grid-template-columns: 1.2fr 1fr;
        align-items: start;
      }
      .collection-content {
        grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
      }
    }

    /* Print stylesheet */
    @media print {
      body {
        background: white;
        color: black;
        font-size: 11pt;
      }
      header, .nav-buttons, .tab-nav, .btn, .back, .flashcard-controls, .search-and-tense {
        display: none !important;
      }
      .tab-content {
        display: block !important;
        background: none;
        box-shadow: none;
        border: 1px solid #ddd;
        page-break-inside: avoid;
        margin: 1em 0;
        padding: 1em;
      }
      .tab-content.active {
        display: block !important;
      }
      h2 {
        color: black;
        font-size: 14pt;
        margin: 0.5em 0;
      }
      h3 {
        font-size: 12pt;
        page-break-after: avoid;
      }
      table {
        width: 100%;
        border-collapse: collapse;
        page-break-inside: avoid;
        font-size: 9pt;
      }
      table th, table td {
        border: 1px solid #999;
        padding: 4px 6px;
      }
      .flashcard {
        display: none !important;
      }
      a {
        color: black;
        text-decoration: none;
      }
    }
