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

:root {
    --nom:    #2563eb;
    --akk:    #dc2626;
    --dat:    #16a34a;
    --gen:    #9333ea;
    --bg:     #f1f5f9;
    --surface:#ffffff;
    --border: #e2e8f0;
    --text:   #0f172a;
    --muted:  #64748b;
    --navy:   #1e3a5f;
    --accent: #2563eb;
    --french: #d97706;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ── Header ── */
.app-header {
    background: var(--navy);
    color: #fff;
    padding: 0.75rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    border-bottom: 3px solid var(--accent);
    flex-shrink: 0;
}
.app-header h1 { font-size: 1.2rem; font-weight: 800; letter-spacing: -0.02em; }
.topic-pill {
    margin-left: auto;
    background: rgba(255,255,255,0.12);
    border: 1px solid rgba(255,255,255,0.2);
    color: #e2e8f0;
    padding: 0.25rem 0.75rem;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 600;
}

/* ── Layout ── */
.app-body { display: flex; flex: 1; overflow: hidden; height: calc(100vh - 51px); }

/* ── Sidebar ── */
.sidebar {
    width: 210px;
    background: var(--navy);
    flex-shrink: 0;
    padding: 1.25rem 0;
    overflow-y: auto;
}
.sidebar-label {
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: #475569;
    padding: 0 1.25rem;
    margin-bottom: 0.4rem;
}
.nav-btn {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    width: 100%;
    padding: 0.55rem 1.25rem;
    background: none;
    border: none;
    border-left: 3px solid transparent;
    color: #94a3b8;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    text-align: left;
    transition: all 0.13s;
}
.nav-btn:hover { background: rgba(255,255,255,0.05); color: #e2e8f0; }
.nav-btn.active { background: rgba(59,130,246,0.15); border-left-color: var(--accent); color: #fff; font-weight: 600; }
.nav-btn.coming { opacity: 0.4; cursor: default; }
.nav-btn.coming:hover { background: none; color: #94a3b8; }
.nav-btn.sub-btn { padding-left: 2.5rem; font-size: 0.82rem; }
.nav-icon { font-size: 1rem; width: 1.25rem; text-align: center; }

.sidebar-divider { height: 1px; background: #1e3f6e; margin: 1rem 0; }

.legend { padding: 0 1.25rem; display: flex; flex-direction: column; gap: 0.4rem; }
.legend-item { display: flex; align-items: center; gap: 0.5rem; font-size: 0.78rem; color: #94a3b8; }

/* ── Content ── */
.content { flex: 1; overflow-y: auto; padding: 1.75rem 2rem; }

.section { display: none; }
.section.active { display: block; }

.page-title { font-size: 1.5rem; font-weight: 800; letter-spacing: -0.02em; margin-bottom: 0.2rem; }
.page-subtitle { color: var(--muted); font-size: 0.875rem; margin-bottom: 1.5rem; }

/* ── Cards ── */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.375rem 1.5rem;
    margin-bottom: 1.125rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
.card-title {
    font-size: 1rem;
    font-weight: 700;
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.45rem;
}

/* ── Case badges ── */
.badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 5px;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.04em;
}
.badge-nom { background: #dbeafe; color: #1e40af; }
.badge-akk { background: #fee2e2; color: #991b1b; }
.badge-dat { background: #dcfce7; color: #166534; }
.badge-gen { background: #f3e8ff; color: #6b21a8; }

.nom { color: var(--nom); font-weight: 600; }
.akk { color: var(--akk); font-weight: 600; }
.dat { color: var(--dat); font-weight: 600; }
.gen { color: var(--gen); font-weight: 600; }

/* ── Tables ── */
.table-wrap { overflow-x: auto; margin: 0.75rem 0; }
table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
th {
    background: #f8fafc;
    padding: 0.45rem 0.75rem;
    text-align: left;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
    border-bottom: 1px solid var(--border);
}
td { padding: 0.55rem 0.75rem; border-bottom: 1px solid #f1f5f9; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #fafbfc; }

/* ── French notes ── */
.french-note {
    background: #fffbeb;
    border-left: 3px solid var(--french);
    padding: 0.75rem 1rem;
    border-radius: 0 8px 8px 0;
    margin: 0.75rem 0;
    font-size: 0.85rem;
    line-height: 1.6;
}
.fr-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    font-weight: 700;
    color: #92400e;
    margin-bottom: 0.3rem;
}

/* ── Suffix tags ── */
.tag {
    display: inline-block;
    padding: 0.18rem 0.55rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 700;
    margin: 0.1rem;
}
.tag-a { background: #dbeafe; color: #1e40af; }
.tag-b { background: #dcfce7; color: #166534; }
.tag-c { background: #f3e8ff; color: #6b21a8; }
.tag-sp { background: #fff7ed; color: #9a3412; }

code {
    background: #f1f5f9;
    padding: 0.1em 0.35em;
    border-radius: 4px;
    font-family: 'SF Mono', Monaco, Menlo, monospace;
    font-size: 0.82em;
    color: #0f172a;
}

/* ── Example rows ── */
.example-row {
    display: flex;
    gap: 0.75rem;
    align-items: baseline;
    padding: 0.3rem 0;
    border-bottom: 1px solid #f1f5f9;
    font-size: 0.875rem;
}
.example-row:last-child { border-bottom: none; }
.ex-de { font-weight: 600; min-width: 160px; }
.ex-en { color: var(--muted); font-style: italic; }

/* ── Tips grid ── */
.tips-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; }
.tip-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1.125rem;
}
.tip-num {
    width: 30px; height: 30px;
    background: var(--accent);
    color: white;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-weight: 800; font-size: 0.8rem;
    margin-bottom: 0.65rem;
}
.tip-card h3 { font-size: 0.9rem; font-weight: 700; margin-bottom: 0.35rem; }
.tip-card p { font-size: 0.83rem; color: var(--muted); line-height: 1.6; }
.hl { background: #dbeafe; color: var(--nom); padding: 0 0.2em; border-radius: 3px; font-weight: 600; }

/* ── Exercises ── */
.mode-tabs { display: flex; gap: 0.5rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.mode-tab {
    padding: 0.45rem 1rem;
    border: 2px solid var(--border);
    border-radius: 8px;
    background: white;
    font-size: 0.83rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.13s;
    color: var(--text);
}
.mode-tab:hover { border-color: var(--accent); }
.mode-tab.active { border-color: var(--accent); background: var(--accent); color: white; }

.mode-hint {
    font-size: 0.78rem;
    color: var(--muted);
    margin-top: -0.5rem;
    margin-bottom: 1.25rem;
}

.ex-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1.125rem;
}
.ex-counter { font-size: 0.8rem; color: var(--muted); white-space: nowrap; }
.progress-bar { flex: 1; height: 6px; background: var(--border); border-radius: 999px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--accent); border-radius: 999px; transition: width 0.3s; }
.score-badge { font-size: 0.83rem; font-weight: 700; color: var(--dat); white-space: nowrap; }

.ex-card {
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: 14px;
    padding: 1.75rem;
}
.ex-type {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
    margin-bottom: 0.625rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.ex-question {
    font-size: 1.2rem;
    font-weight: 600;
    margin-bottom: 1.375rem;
    line-height: 1.45;
}
.ex-question em { font-style: normal; color: var(--accent); border-bottom: 2px solid var(--accent); }

.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 0.65rem; }
.choice {
    padding: 0.7rem 1rem;
    border: 2px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    text-align: left;
    transition: border-color 0.13s, background 0.13s;
    color: var(--text);
}
.choice:hover:not(:disabled) { border-color: var(--accent); background: #eff6ff; }
.choice.correct { border-color: var(--dat); background: #dcfce7; color: #166534; font-weight: 700; }
.choice.wrong   { border-color: var(--akk); background: #fee2e2; color: #991b1b; }

.feedback {
    margin-top: 1rem;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    font-size: 0.875rem;
    line-height: 1.5;
    display: none;
}
.feedback.show { display: block; }
.feedback.ok { background: #dcfce7; color: #166534; }
.feedback.ko { background: #fee2e2; color: #991b1b; }

.next-btn {
    margin-top: 1rem;
    padding: 0.55rem 1.375rem;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 700;
    cursor: pointer;
    display: none;
}
.next-btn.show { display: inline-block; }
.next-btn:hover { background: #1d4ed8; }

/* ── Results ── */
.results {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 3rem 2rem;
    text-align: center;
}
.results-emoji { font-size: 4rem; margin-bottom: 0.75rem; }
.results-score { font-size: 3.5rem; font-weight: 900; color: var(--accent); line-height: 1; }
.results-msg { color: var(--muted); margin-top: 0.5rem; font-size: 1rem; }
.restart-btn {
    margin-top: 1.5rem;
    padding: 0.7rem 2rem;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
}
.restart-btn:hover { background: #1d4ed8; }

/* ── Misc ── */
.divider { height: 1px; background: var(--border); margin: 1rem 0; }
.mt-2 { margin-top: 0.5rem; }
.mt-3 { margin-top: 0.75rem; }
.mt-4 { margin-top: 1rem; }
p { line-height: 1.65; font-size: 0.9rem; }
ul { padding-left: 1.5rem; }
li { margin: 0.3rem 0; font-size: 0.875rem; line-height: 1.65; }
strong { font-weight: 700; }

/* ── Mobile bottom nav ── */
.mobile-nav {
    display: none;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    background: var(--navy);
    border-top: 2px solid var(--accent);
    padding: 0.35rem 0 calc(0.35rem + env(safe-area-inset-bottom, 0px));
    z-index: 100;
    justify-content: space-around;
}
.mob-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.1rem;
    background: none;
    border: none;
    color: #475569;
    font-size: 0.6rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0.3rem 0.9rem;
    cursor: pointer;
    transition: color 0.13s;
}
.mob-btn.active { color: #fff; }
.mob-icon { font-size: 1.35rem; line-height: 1; }

/* ── Topic sheet ── */
.topic-sheet { display: none; position: fixed; inset: 0; z-index: 200; }
.topic-sheet.open { display: block; }
.topic-sheet-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.55);
}
.topic-sheet-panel {
    position: absolute;
    bottom: 0; left: 0; right: 0;
    background: var(--navy);
    border-radius: 18px 18px 0 0;
    padding: 0.6rem 0 calc(1.5rem + env(safe-area-inset-bottom, 0px));
    max-height: 75vh;
    overflow-y: auto;
}
.topic-sheet-handle {
    width: 36px; height: 4px;
    background: #334155;
    border-radius: 999px;
    margin: 0 auto 1rem;
}

/* ── Welcome overlay ── */
.welcome-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 400;
    background: rgba(10, 20, 40, 0.82);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    align-items: center;
    justify-content: center;
}
.welcome-overlay.show { display: flex; }
.welcome-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 3rem 2.5rem;
    max-width: 480px;
    width: calc(100% - 2rem);
    text-align: center;
    box-shadow: 0 24px 60px rgba(0,0,0,0.35);
}
.welcome-flag { font-size: 2.75rem; line-height: 1; display: block; margin-bottom: 0.9rem; }
.welcome-title {
    font-size: 1.85rem;
    font-weight: 800;
    letter-spacing: -0.03em;
    color: var(--navy);
    margin-bottom: 1rem;
}
.welcome-tagline {
    font-size: 0.95rem;
    color: var(--muted);
    line-height: 1.7;
    margin-bottom: 2rem;
}
.welcome-btn {
    display: inline-block;
    padding: 0.75rem 2rem;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.13s;
}
.welcome-btn:hover { background: #1d4ed8; }

@media (max-width: 640px) {
    .sidebar { display: none; }
    .mobile-nav { display: flex; }
    .content {
        padding: 1rem;
        padding-bottom: calc(4.5rem + env(safe-area-inset-bottom, 0px));
        overflow-x: hidden;
    }
    .choices { grid-template-columns: 1fr; }
    .tips-grid { grid-template-columns: 1fr; }
    .ex-card { padding: 1.25rem; }
    .ex-question { font-size: 1.05rem; margin-bottom: 1rem; }
    .mode-tabs { gap: 0.4rem; }
    .mode-tab { padding: 0.4rem 0.75rem; font-size: 0.78rem; }
    .results { padding: 2rem 1.25rem; }
    .app-header h1 { font-size: 1rem; }
    .topic-pill { font-size: 0.72rem; padding: 0.2rem 0.55rem; }
    .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .table-wrap table { width: max-content; min-width: 100%; }
}
