/* ===========================================================
   JLPT N2 — Thème graphique brun / crème / café
   Inspiré de l'architecture du site Concours MEAE
   =========================================================== */

/* ---------- Reset & base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
    margin: 0; padding: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: 16px; line-height: 1.6;
    background: var(--bg-color);
    color: var(--text-main);
    transition: background 0.3s ease, color 0.3s ease;
    min-height: 100vh;
}

/* ---------- Variables : thème JOUR (crème lumineux) ---------- */
:root {
    /* Palette principale brun / crème / café */
    --jlpt-brown:        #5B3A1F;   /* brun profond — primaire */
    --jlpt-brown-soft:   #8B6943;   /* brun moyen — accents */
    --jlpt-cream:        #F5EBDC;   /* crème — fond */
    --jlpt-cream-light:  #FAF4E8;   /* crème clair — cartes */
    --jlpt-cream-dark:   #E8D9C0;   /* crème foncé — séparateurs */
    --jlpt-coffee:       #3A2417;   /* café noir — texte */
    --jlpt-terra:        #B8632E;   /* terre cuite — boutons/CTA */
    --jlpt-gold:         #C9A35A;   /* doré chaud — distinctions (utilisé avec parcimonie) */
    --jlpt-success:      #6B8E3E;   /* vert olive — bonnes réponses */
    --jlpt-error:        #A6403A;   /* rouge brique — erreurs */
    --jlpt-warn:         #D88C2C;   /* ambre — attention */

    /* Sémantique */
    --bg-color: var(--jlpt-cream);
    --bg-gradient: linear-gradient(180deg, #F8F0DF 0%, #F1E5CC 100%);
    --surface-color: var(--jlpt-cream-light);
    --bg-card: #FFFCF6;
    --text-main: var(--jlpt-coffee);
    --text-body: #4A2F1E;
    --text-muted: #6B4A30;
    --border-color: rgba(91, 58, 31, 0.15);
    --glass-border: rgba(91, 58, 31, 0.18);
    --glass-bg: rgba(250, 244, 232, 0.78);
    --shadow-sm: 0 2px 8px rgba(91, 58, 31, 0.08);
    --shadow-md: 0 4px 16px rgba(91, 58, 31, 0.12);
    --shadow-lg: 0 10px 32px rgba(91, 58, 31, 0.18);

    --primary: var(--jlpt-brown);
    --primary-hover: var(--jlpt-coffee);
    --accent: var(--jlpt-terra);

    --radius-sm: 6px;
    --radius:    12px;
    --radius-lg: 18px;
    --radius-xl: 24px;

    --header-height: 72px;
}

/* ---------- Variables : thème NUIT (café profond) ---------- */
[data-theme="dark"] {
    --jlpt-cream:        #1F1812;
    --jlpt-cream-light:  #2A1F17;
    --jlpt-cream-dark:   #382A20;

    --bg-color: #1A130D;
    --bg-gradient: linear-gradient(180deg, #1A130D 0%, #221710 100%);
    --surface-color: #261B12;
    --bg-card: #2F2218;
    --text-main: #F2E4CC;
    --text-body: #E5D2B0;
    --text-muted: #C9AE85;
    --border-color: rgba(245, 235, 220, 0.10);
    --glass-border: rgba(245, 235, 220, 0.14);
    --glass-bg: rgba(38, 27, 18, 0.78);
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.35);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.45);
    --shadow-lg: 0 10px 32px rgba(0, 0, 0, 0.55);

    --primary: #D9A875;
    --primary-hover: #E8BD8E;
    --accent: #D88C2C;
}

body { background: var(--bg-gradient); }

/* ---------- Typographie ---------- */
h1, h2, h3, h4 {
    font-family: 'Instrument Serif', 'Georgia', serif;
    font-weight: normal;
    color: var(--text-main);
    line-height: 1.15;
    margin: 0 0 0.5em 0;
}
h1 { font-size: clamp(2rem, 4vw, 3rem); }
h2 { font-size: clamp(1.5rem, 3vw, 2.25rem); }
h3 { font-size: 1.35rem; }
h4 { font-size: 1.15rem; font-family: 'Inter', sans-serif; font-weight: 600; }
p { margin: 0 0 1em 0; }
a { color: var(--primary); text-decoration: none; transition: color 0.2s; }
a:hover { color: var(--accent); }

/* Police japonaise — appliquée aux contenus en japonais */
.jp, .japanese, [lang="ja"] {
    font-family: 'Noto Serif JP', 'Yu Mincho', 'Hiragino Mincho ProN', 'MS Mincho', serif;
    line-height: 1.8;
}
.jp-sans, [lang="ja"].sans {
    font-family: 'Noto Sans JP', 'Hiragino Sans', sans-serif;
}

/* ---------- Container ---------- */
.container {
    max-width: 1280px;
    margin: 0 auto;
    padding: 0 1.5rem;
}
main.container { padding-top: 2rem; padding-bottom: 4rem; }

/* ---------- Header glassmorphism ---------- */
.site-header {
    position: sticky; top: 0; z-index: 100;
    backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
    background: var(--glass-bg);
    border-bottom: 1px solid var(--glass-border);
    height: var(--header-height);
    display: flex; align-items: center;
}
.site-header .container {
    display: flex; align-items: center; justify-content: space-between;
    width: 100%;
}
.brand {
    display: flex; align-items: center; gap: 0.75rem;
    color: var(--text-main);
}
.brand img { height: 38px; width: auto; display: block; }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-text strong {
    font-family: 'Instrument Serif', serif;
    font-size: 1.2rem; font-weight: normal;
}
.brand-text small {
    font-size: 0.7rem;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    color: var(--text-muted);
}

/* Nav */
.site-nav { display: flex; align-items: center; gap: 0.5rem; }
.site-nav a, .site-nav button {
    display: inline-flex; align-items: center; gap: 0.4rem;
    padding: 0.5rem 0.9rem;
    border-radius: var(--radius-sm);
    color: var(--text-main);
    font-size: 0.92rem; font-weight: 500;
    background: transparent; border: none; cursor: pointer;
    transition: background 0.2s, color 0.2s;
    text-decoration: none;
}
.site-nav a:hover, .site-nav button:hover,
.site-nav .dropdown:hover > a {
    background: rgba(91, 58, 31, 0.08);
    color: var(--primary);
}
[data-theme="dark"] .site-nav a:hover,
[data-theme="dark"] .site-nav button:hover {
    background: rgba(245, 235, 220, 0.08);
}
.site-nav a.active {
    background: var(--primary);
    color: #FAF4E8;
}
[data-theme="dark"] .site-nav a.active {
    background: var(--primary);
    color: #1A130D;
}

/* Dropdown préparation */
.dropdown { position: relative; }
.dropdown-menu {
    position: absolute; top: 100%; right: 0;
    min-width: 240px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    padding: 0.5rem;
    margin-top: 0.5rem;
    opacity: 0; visibility: hidden;
    transform: translateY(-6px);
    transition: opacity 0.18s, transform 0.18s, visibility 0.18s;
}
.dropdown:hover .dropdown-menu,
.dropdown:focus-within .dropdown-menu {
    opacity: 1; visibility: visible; transform: translateY(0);
}
.dropdown-menu a {
    display: flex; align-items: center; gap: 0.6rem;
    padding: 0.6rem 0.8rem;
    border-radius: var(--radius-sm);
    color: var(--text-main);
    font-size: 0.92rem;
}
.dropdown-menu a i { width: 18px; color: var(--primary); }
.dropdown-menu a:hover { background: rgba(91, 58, 31, 0.08); }

/* Toggle thème */
.theme-toggle {
    width: 38px; height: 38px;
    border-radius: 50%;
    display: inline-flex; align-items: center; justify-content: center;
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-main);
    cursor: pointer; transition: all 0.2s;
}
.theme-toggle:hover { background: rgba(91, 58, 31, 0.08); transform: rotate(20deg); }

/* ---------- Hero ---------- */
.hero {
    background: linear-gradient(135deg, var(--jlpt-brown) 0%, var(--jlpt-coffee) 100%);
    color: #F5EBDC;
    border-radius: var(--radius-xl);
    padding: 3rem 2.5rem;
    margin: 2rem 0;
    position: relative; overflow: hidden;
    box-shadow: var(--shadow-md);
}
.hero::before {
    content: '';
    position: absolute; top: -50%; right: -10%;
    width: 60%; height: 200%;
    background: radial-gradient(circle, rgba(201, 163, 90, 0.18) 0%, transparent 65%);
    pointer-events: none;
}
.hero h1 { color: #FAF4E8; margin-bottom: 0.6rem; }
.hero p, .hero li {
    color: rgba(250, 244, 232, 0.92);
    font-size: 1.08rem; max-width: 760px;
}
.hero-meta {
    display: inline-block;
    font-size: 0.78rem; font-weight: 600;
    letter-spacing: 2px; text-transform: uppercase;
    color: var(--jlpt-gold);
    margin-bottom: 1rem;
}

/* ---------- Cards ---------- */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
    transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
}
.card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); border-color: var(--primary); }
.card h3 { margin-top: 0; }
.card .card-icon {
    width: 48px; height: 48px;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: var(--radius-sm);
    background: rgba(91, 58, 31, 0.10);
    color: var(--primary);
    font-size: 1.3rem;
    margin-bottom: 0.8rem;
}
[data-theme="dark"] .card .card-icon { background: rgba(217, 168, 117, 0.12); }
.card-link {
    display: inline-flex; align-items: center; gap: 0.4rem;
    margin-top: 1rem; font-weight: 600;
    color: var(--primary);
}
.card-link:hover { color: var(--accent); }

/* Grid */
.grid { display: grid; gap: 1.25rem; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }

/* ---------- Boutons ---------- */
.btn {
    display: inline-flex; align-items: center; gap: 0.5rem;
    padding: 0.7rem 1.4rem;
    border-radius: var(--radius-sm);
    font-size: 0.95rem; font-weight: 600;
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
}
.btn-primary {
    background: var(--primary); color: #FAF4E8;
}
.btn-primary:hover { background: var(--primary-hover); color: #FAF4E8; transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.btn-outline {
    background: transparent;
    border-color: var(--primary);
    color: var(--primary);
}
.btn-outline:hover { background: var(--primary); color: #FAF4E8; }
.btn-accent { background: var(--accent); color: #FFFFFF; }
.btn-accent:hover { background: var(--jlpt-brown-soft); color: #FFFFFF; }
.btn-ghost { color: var(--text-main); }
.btn-ghost:hover { background: rgba(91, 58, 31, 0.08); }

/* ---------- Tags & badges ---------- */
.tag {
    display: inline-block;
    padding: 0.25rem 0.7rem;
    border-radius: 999px;
    font-size: 0.78rem; font-weight: 600;
    background: rgba(91, 58, 31, 0.10);
    color: var(--primary);
}
[data-theme="dark"] .tag { background: rgba(217, 168, 117, 0.14); color: var(--primary); }
.tag.tag-high { background: rgba(166, 64, 58, 0.15); color: var(--jlpt-error); }
.tag.tag-med  { background: rgba(216, 140, 44, 0.18); color: var(--jlpt-warn); }
.tag.tag-low  { background: rgba(107, 142, 62, 0.18); color: var(--jlpt-success); }

/* ---------- Indicateur de risque (bandeau de fréquence) ---------- */
.risk-bar {
    display: flex; align-items: center; gap: 0.5rem;
    margin-top: 0.5rem;
}
.risk-bar .risk-track {
    flex: 1; height: 6px;
    background: rgba(91, 58, 31, 0.10);
    border-radius: 999px; overflow: hidden;
}
.risk-bar .risk-fill {
    height: 100%; border-radius: 999px;
    background: linear-gradient(90deg, var(--jlpt-success), var(--jlpt-warn), var(--jlpt-error));
}
.risk-bar .risk-label {
    font-size: 0.78rem; font-weight: 600;
    color: var(--text-muted); min-width: 70px; text-align: right;
}

/* ---------- Exercices : Q/A ---------- */
.exercise {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 1.5rem;
    margin-bottom: 1.25rem;
    box-shadow: var(--shadow-sm);
}
.exercise .q-number {
    display: inline-block;
    font-size: 0.75rem; font-weight: 700;
    letter-spacing: 1.5px; text-transform: uppercase;
    color: var(--primary); margin-bottom: 0.5rem;
}
.exercise .q-text {
    font-size: 1.15rem; line-height: 1.7;
    margin-bottom: 1.25rem;
    font-family: 'Noto Serif JP', 'Yu Mincho', serif;
}
.exercise .q-text .blank {
    display: inline-block; min-width: 4em;
    border-bottom: 2px solid var(--primary);
    padding: 0 0.3em; text-align: center;
    color: var(--accent); font-weight: 600;
}
.exercise .choices { display: grid; gap: 0.6rem; }
.exercise .choice {
    display: flex; align-items: center; gap: 0.8rem;
    padding: 0.85rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--surface-color);
    cursor: pointer;
    transition: all 0.15s;
    font-family: 'Noto Serif JP', 'Yu Mincho', serif;
    font-size: 1.05rem;
}
.exercise .choice:hover { border-color: var(--primary); background: rgba(91, 58, 31, 0.04); }
.exercise .choice .num {
    width: 26px; height: 26px;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: 50%; background: var(--primary); color: #FAF4E8;
    font-size: 0.78rem; font-weight: 700; font-family: 'Inter', sans-serif;
    flex-shrink: 0;
}
.exercise .choice.correct {
    border-color: var(--jlpt-success); background: rgba(107, 142, 62, 0.10);
}
.exercise .choice.correct .num { background: var(--jlpt-success); }
.exercise .choice.incorrect {
    border-color: var(--jlpt-error); background: rgba(166, 64, 58, 0.08);
}
.exercise .choice.incorrect .num { background: var(--jlpt-error); }

/* Explication */
.explanation {
    margin-top: 1.25rem;
    padding: 1rem 1.25rem;
    border-left: 4px solid var(--accent);
    background: rgba(184, 99, 46, 0.07);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    display: none;
}
.explanation.visible { display: block; animation: slideIn 0.3s ease; }
.explanation h4 { color: var(--accent); margin-bottom: 0.5rem; }
.explanation .jp-term {
    display: inline-block;
    padding: 0.1rem 0.45rem;
    margin: 0 0.15rem;
    background: var(--surface-color);
    border-radius: 4px;
    font-family: 'Noto Serif JP', serif;
    border: 1px solid var(--border-color);
}
.explanation .jisho-link {
    font-size: 0.85rem;
    margin-left: 0.4rem;
    color: var(--primary);
}

@keyframes slideIn {
    from { opacity: 0; transform: translateY(-8px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ---------- Formulaires ---------- */
input[type="text"], input[type="password"], input[type="search"], textarea, select {
    width: 100%;
    padding: 0.7rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    color: var(--text-main);
    font-family: inherit; font-size: 1rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}
input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(91, 58, 31, 0.15);
}
label { display: block; margin-bottom: 0.4rem; font-weight: 600; color: var(--text-body); }

/* ---------- Audio player ---------- */
.audio-player {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
    display: flex; align-items: center; gap: 0.8rem;
    margin: 1rem 0;
}
.audio-player audio { flex: 1; }

/* ---------- Stats / progress ---------- */
.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 1.25rem;
    text-align: center;
}
.stat-card .stat-value {
    font-family: 'Instrument Serif', serif;
    font-size: 2.5rem;
    color: var(--primary);
    line-height: 1;
}
.stat-card .stat-label {
    font-size: 0.85rem; font-weight: 600;
    color: var(--text-muted);
    margin-top: 0.4rem;
    text-transform: uppercase; letter-spacing: 1.5px;
}

/* ---------- Footer ---------- */
.site-footer {
    margin-top: 4rem;
    padding: 2rem 0;
    border-top: 1px solid var(--border-color);
    background: var(--surface-color);
    text-align: center;
    color: var(--text-muted);
    font-size: 0.88rem;
}

/* ---------- Login page ---------- */
.login-wrap {
    min-height: 100vh;
    display: flex; align-items: center; justify-content: center;
    padding: 1rem;
    background:
        radial-gradient(circle at 20% 20%, rgba(184, 99, 46, 0.18) 0%, transparent 50%),
        radial-gradient(circle at 80% 80%, rgba(201, 163, 90, 0.18) 0%, transparent 50%),
        var(--bg-gradient);
}
.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xl);
    padding: 2.5rem;
    width: 100%; max-width: 420px;
    box-shadow: var(--shadow-lg);
    text-align: center;
}
.login-card img { height: 56px; margin-bottom: 0.5rem; }
.login-card h1 {
    font-size: 1.8rem; margin-bottom: 0.2rem;
}
.login-card .subtitle {
    color: var(--text-muted); margin-bottom: 1.8rem;
    font-size: 0.9rem;
}
.login-card form { text-align: left; }
.login-card .btn { width: 100%; justify-content: center; margin-top: 1rem; }
.login-error {
    color: var(--jlpt-error);
    background: rgba(166, 64, 58, 0.10);
    border: 1px solid rgba(166, 64, 58, 0.25);
    padding: 0.7rem 1rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

/* ---------- Responsive ---------- */
@media (max-width: 760px) {
    .site-nav span.nav-label { display: none; }
    .hero { padding: 2rem 1.25rem; }
    main.container { padding: 1rem; }
    .dropdown-menu { right: auto; left: 0; }
}

/* ---------- Utilitaires ---------- */
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mt-4 { margin-top: 2rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.mb-4 { margin-bottom: 2rem; }
.hidden { display: none !important; }
