:root {
    --bg: #f4f7fb;
    --bg-soft: #e9f0f9;
    --panel: #ffffff;
    --panel-soft: #f6f9fd;
    --text: #1f2c3d;
    --muted: #64748b;
    --border: #d9e1ec;
    --primary: #1976d2;
    --primary-dark: #115394;
    --primary-grad: linear-gradient(135deg, #2b87e8 0%, #1565c0 100%);
    --danger: #e5484d;
    --danger-grad: linear-gradient(135deg, #f0565b 0%, #d63438 100%);
    --success: #2f9e44;
    --success-grad: linear-gradient(135deg, #40b45a 0%, #2b8a3e 100%);
    --warning: #f08c00;
    --warning-grad: linear-gradient(135deg, #fb9f1d 0%, #e67700 100%);
    --pinyin: #b45309;
    --focus: rgba(25, 118, 210, 0.3);
    --shadow: 0 16px 36px rgba(15, 38, 70, 0.12), 0 3px 8px rgba(15, 38, 70, 0.06);
    --shadow-soft: 0 6px 16px rgba(15, 38, 70, 0.09);
    --radius-card: 22px;
    --radius-control: 14px;
    --tap-size: 48px;
    --hanzi-box-size: clamp(184px, 58vw, 240px);
    --ease-spring: cubic-bezier(0.34, 1.3, 0.5, 1);
    /* Grille de calligraphie 米字格 (cadre + croix + diagonales en pointillés)
       utilisée en fond des zones d'écriture pour bien positionner le tracé. */
    --mizige-bg: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100' preserveAspectRatio='none'%3E%3Cg fill='none' stroke='%23db929a' stroke-width='1.3' stroke-dasharray='5 5' opacity='0.6'%3E%3Cline x1='50' y1='3' x2='50' y2='97'/%3E%3Cline x1='3' y1='50' x2='97' y2='50'/%3E%3Cline x1='4' y1='4' x2='96' y2='96'/%3E%3Cline x1='96' y1='4' x2='4' y2='96'/%3E%3C/g%3E%3Crect x='1.5' y='1.5' width='97' height='97' fill='none' stroke='%23dd9aa1' stroke-width='2' opacity='0.55'/%3E%3C/svg%3E");
    --mizige-paper: #fffdf6;
}

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

html {
    min-height: 100%;
    background: var(--bg);
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    margin: 0;
    min-height: 100vh;
    min-height: 100dvh;
    width: 100%;
    overflow-x: hidden;
    display: flex;
    justify-content: center;
    padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", sans-serif;
    color: var(--text);
    background: linear-gradient(170deg, #fbfdff 0%, var(--bg-soft) 60%, #e3edf9 100%);
    background-attachment: fixed;
}

button,
select,
input {
    font: inherit;
}

button {
    border: 0;
    cursor: pointer;
    touch-action: manipulation;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    transition: transform 0.12s ease, box-shadow 0.18s ease, filter 0.18s ease;
}

button:not(:disabled):active {
    transform: scale(0.96);
    filter: brightness(0.96);
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.55;
}

button:focus-visible,
select:focus-visible,
input:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 2px;
}

[hidden] {
    display: none !important;
}

.app-container {
    width: min(100%, 460px);
    min-width: 0;
    padding-bottom: max(4px, env(safe-area-inset-bottom));
}

.app-header {
    text-align: center;
    margin-bottom: 10px;
}

.app-header h1 {
    margin: 4px 0 2px;
    font-size: clamp(1.45rem, 6vw, 1.9rem);
    line-height: 1.12;
    letter-spacing: -0.01em;
    font-weight: 900;
    background: linear-gradient(135deg, #1565c0 0%, #2b87e8 60%, #1976d2 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    color: var(--primary-dark);
}

.app-version {
    -webkit-text-fill-color: initial;
    color: var(--muted);
    font-size: 0.62rem;
    font-weight: 800;
    letter-spacing: 0.04em;
    vertical-align: middle;
    opacity: 0.75;
}

.user-profile {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    max-width: 100%;
    margin-top: 10px;
    padding: 7px 12px 7px 8px;
    color: var(--text);
    background: rgba(255, 255, 255, 0.82);
    border: 1px solid rgba(216, 222, 232, 0.85);
    border-radius: 999px;
    box-shadow: var(--shadow-soft);
}

.user-avatar,
.user-avatar-fallback {
    width: 38px;
    height: 38px;
    flex: 0 0 38px;
    border-radius: 50%;
}

.user-avatar {
    display: block;
    object-fit: cover;
    background: var(--panel-soft);
    border: 2px solid #fff;
}

.user-avatar-fallback {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    font-weight: 900;
}

.user-greeting {
    min-width: 0;
    font-size: clamp(0.95rem, 4.2vw, 1.08rem);
    line-height: 1.15;
    font-weight: 900;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.subtitle {
    margin: 0;
    color: var(--muted);
    font-size: 0.95rem;
}

.auth-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    margin: 8px 0 14px;
    text-align: center;
}

.auth-row button,
.btn-secondary,
#btn-mastery,
.btn-review,
.btn-back,
.audio-btn {
    min-height: var(--tap-size);
    border-radius: var(--radius-control);
    font-weight: 800;
}

.auth-row button,
.btn-secondary {
    width: 100%;
    padding: 11px 14px;
    color: #fff;
    background: var(--primary-grad);
    box-shadow: var(--shadow-soft);
}

.auth-row #logoutBtn {
    background: #475467;
}

.filter-group {
    display: grid;
    gap: 10px;
    margin-bottom: 12px;
}

select,
.free-hanzi-input {
    width: 100%;
    min-width: 0;
    color: var(--text);
    background: var(--panel);
    border: 1px solid var(--border);
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.75) inset;
}

select {
    min-height: var(--tap-size);
    padding: 10px 38px 10px 12px;
    border-radius: var(--radius-control);
}

.action-row {
    display: grid;
    gap: 10px;
    margin-bottom: 10px;
}

#btn-mastery {
    width: 100%;
    padding: 11px 14px;
    color: #fff;
    background: var(--warning-grad);
    box-shadow: var(--shadow-soft);
}

.card-counter {
    margin-bottom: 10px;
    text-align: center;
    font-size: 0.93rem;
    font-weight: 800;
    color: var(--muted);
}

#card-container {
    min-height: clamp(320px, 56dvh, 460px);
    margin-bottom: 14px;
}

#card-container.mode-free-hanzi,
#card-container.mode-empty,
#card-container.mode-result {
    min-height: 0;
}

@keyframes card-enter {
    from {
        opacity: 0;
        transform: translateY(14px) scale(0.985);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.flashcard {
    width: 100%;
    min-height: 300px;
    height: clamp(320px, 56dvh, 460px);
    display: flex;
    justify-content: center;
    align-items: stretch;
    perspective: 1200px;
    cursor: pointer;
    animation: card-enter 0.32s var(--ease-spring) both;
}

.card-inner {
    position: relative;
    width: 100%;
    height: 100%;
    min-width: 0;
    transition: transform 0.55s cubic-bezier(0.4, 0.2, 0.2, 1);
    transform-style: preserve-3d;
}

.card-inner.is-flipped {
    transform: rotateY(180deg);
}

.card-front,
.card-back,
.result-screen,
.empty-state {
    background: linear-gradient(180deg, #ffffff 0%, #fbfdff 100%);
    border: 1px solid rgba(217, 225, 236, 0.8);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow);
}

.card-front,
.card-back {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 10px;
    min-width: 0;
    min-height: 240px;
    padding: clamp(16px, 4.5vw, 22px);
    text-align: center;
    overflow: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    backface-visibility: hidden;
    scroll-padding-block: 12px;
}

.card-front > *,
.card-back > * {
    max-width: 100%;
}

.card-back {
    transform: rotateY(180deg);
    background: linear-gradient(180deg, #fcfdff 0%, #f4f8fd 100%);
}

.card-front.is-overflowing,
.card-back.is-overflowing,
.flashcard.density-compact .card-back,
.flashcard.is-hanzi-radical .card-back {
    justify-content: flex-start;
}

.icon {
    margin-bottom: 2px;
    font-size: clamp(2.35rem, 10vw, 3.5rem);
    line-height: 1;
}

.fr {
    max-width: 100%;
    font-size: clamp(1.25rem, 5.8vw, 1.95rem);
    line-height: 1.25;
    font-weight: 800;
    overflow-wrap: anywhere;
    text-wrap: balance;
}

.hz {
    max-width: 100%;
    color: var(--text);
    font-size: clamp(2rem, 11vw, 4rem);
    line-height: 1.12;
    font-weight: 900;
    text-align: center;
    word-break: keep-all;
    overflow-wrap: anywhere;
    white-space: normal;
    text-wrap: balance;
}

.hz.hanzi-large {
    font-size: clamp(2.5rem, 13vw, 4.35rem);
    line-height: 1.06;
}

.hz.hanzi-medium {
    font-size: clamp(2.05rem, 10vw, 3.45rem);
    line-height: 1.1;
}

.hz.hanzi-small {
    font-size: clamp(1.55rem, 7.8vw, 2.55rem);
    line-height: 1.16;
}

.hz.hanzi-xsmall {
    font-size: clamp(1.18rem, 5.6vw, 1.9rem);
    line-height: 1.23;
}

.fit-tight .hz.hanzi-large,
.flashcard.density-compact .hz.hanzi-large {
    font-size: clamp(2.1rem, 10.4vw, 3.2rem);
    line-height: 1.16;
}

.fit-tight .hz.hanzi-medium,
.flashcard.density-compact .hz.hanzi-medium {
    font-size: clamp(1.8rem, 8.8vw, 2.75rem);
}

.fit-tight .hz.hanzi-small,
.flashcard.density-compact .hz.hanzi-small {
    font-size: clamp(1.38rem, 6.9vw, 2.2rem);
}

.fit-tight .hz.hanzi-xsmall,
.flashcard.density-compact .hz.hanzi-xsmall {
    font-size: clamp(1.05rem, 5.1vw, 1.7rem);
}

.fit-tighter .hz.hanzi-large {
    font-size: clamp(1.85rem, 9.4vw, 2.85rem);
    line-height: 1.18;
}

.fit-tighter .hz.hanzi-medium {
    font-size: clamp(1.6rem, 7.8vw, 2.45rem);
}

.fit-tighter .hz.hanzi-small {
    font-size: clamp(1.25rem, 6.2vw, 1.95rem);
}

.fit-tighter .hz.hanzi-xsmall {
    font-size: clamp(0.98rem, 4.7vw, 1.52rem);
}

.fit-tiny .hz {
    font-size: clamp(0.95rem, 4.9vw, 1.65rem);
    line-height: 1.22;
}

.pinyin {
    max-width: 100%;
    margin-top: 2px;
    color: var(--pinyin);
    font-size: clamp(1rem, 4.8vw, 1.55rem);
    line-height: 1.3;
    font-weight: 800;
    overflow-wrap: anywhere;
    text-wrap: balance;
}

.fit-tight .pinyin,
.flashcard.density-compact .pinyin {
    font-size: clamp(0.94rem, 4.2vw, 1.22rem);
    line-height: 1.22;
}

.fit-tighter .pinyin {
    font-size: clamp(0.86rem, 3.8vw, 1.08rem);
}

.fit-tiny .pinyin {
    font-size: clamp(0.8rem, 3.5vw, 0.98rem);
}

.fit-tight .fr,
.flashcard.density-compact .fr {
    font-size: clamp(1.08rem, 5vw, 1.45rem);
    line-height: 1.18;
}

.fit-tighter .fr {
    font-size: clamp(0.98rem, 4.4vw, 1.25rem);
}

.fit-tiny .fr {
    font-size: clamp(0.9rem, 4vw, 1.1rem);
}

.card-hint {
    margin: 6px 0 0;
    color: #8b95a5;
    font-size: 0.82rem;
    line-height: 1.35;
}

.audio-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    max-width: 100%;
    margin-top: 4px;
    padding: 11px 16px;
    color: var(--primary-dark);
    background: #ecf3fc;
    border: 1px solid #c8dcf3;
    border-radius: 999px;
    line-height: 1.2;
    font-weight: 800;
}

.audio-track-list {
    display: grid;
    gap: 8px;
    width: 100%;
    max-height: min(240px, 42dvh);
    margin-top: 8px;
    overflow-y: auto;
    padding-right: 2px;
}

.audio-track-btn {
    width: 100%;
    min-height: 44px;
}

.hanzi-examples {
    display: grid;
    gap: 6px;
    width: 100%;
    margin-top: 4px;
    color: var(--muted);
    font-size: 0.9rem;
}

.hanzi-example {
    padding: 8px 10px;
    border-radius: 12px;
    background: var(--panel-soft);
    overflow-wrap: anywhere;
}

.flashcard.density-compact .card-back,
.flashcard.is-hanzi-radical .card-back,
.card-back.fit-tight,
.card-back.fit-tighter,
.card-back.fit-tiny {
    gap: 6px;
    padding-block: 12px;
}

.flashcard.density-compact .hanzi-examples,
.fit-tight .hanzi-examples {
    gap: 5px;
    margin-top: 2px;
    font-size: 0.82rem;
    line-height: 1.18;
}

.flashcard.density-compact .hanzi-example,
.fit-tight .hanzi-example {
    padding: 6px 8px;
    border-radius: 10px;
}

.fit-tighter .hanzi-examples,
.fit-tiny .hanzi-examples {
    gap: 4px;
    margin-top: 0;
    font-size: 0.76rem;
    line-height: 1.14;
}

.fit-tighter .hanzi-example,
.fit-tiny .hanzi-example {
    padding: 5px 7px;
    border-radius: 9px;
}

.hanzi-category {
    margin-top: 2px;
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.flashcard.density-compact .hanzi-category,
.fit-tight .hanzi-category,
.fit-tighter .hanzi-category,
.fit-tiny .hanzi-category {
    margin-top: 0;
    font-size: 0.7rem;
    line-height: 1.1;
}

.flashcard.density-compact .audio-btn,
.fit-tight .audio-btn,
.fit-tighter .audio-btn,
.fit-tiny .audio-btn {
    min-height: 38px;
    margin-top: 0;
    padding: 8px 12px;
    font-size: 0.85rem;
}

.controls {
    position: sticky;
    bottom: max(8px, env(safe-area-inset-bottom));
    z-index: 5;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    padding-top: 2px;
}

.btn-red,
.btn-green {
    min-width: 0;
    min-height: 54px;
    padding: 13px 10px;
    border-radius: 16px;
    color: #fff;
    font-size: 0.98rem;
    font-weight: 900;
    line-height: 1.1;
    letter-spacing: 0.02em;
    box-shadow: var(--shadow-soft);
}

.btn-red {
    background: var(--danger-grad);
}

.btn-green {
    background: var(--success-grad);
}

.result-screen,
.empty-state {
    padding: clamp(20px, 6vw, 28px);
    text-align: center;
}

.result-screen h2,
.empty-state h2 {
    margin: 0 0 10px;
    font-size: clamp(1.25rem, 6vw, 1.65rem);
}

.result-screen p,
.empty-state p {
    margin: 8px 0;
    line-height: 1.35;
}

.result-actions {
    display: grid;
    gap: 10px;
    margin-top: 16px;
}

.btn-review {
    padding: 12px 14px;
    color: #fff;
    background: var(--primary-grad);
}

.btn-back {
    padding: 12px 14px;
    color: var(--text);
    background: #eef4fb;
    border: 1px solid var(--border);
}

.flashcard.is-hanzi-writing,
.flashcard:has(.hanzi-writer-panel) {
    height: auto;
    min-height: 0;
    align-items: stretch;
    cursor: default;
}

.flashcard.is-hanzi-writing .card-inner,
.flashcard:has(.hanzi-writer-panel) .card-inner {
    height: auto;
    min-height: clamp(520px, calc(100dvh - 190px), 680px);
}

.flashcard.is-hanzi-writing .card-front,
.card-front:has(.hanzi-writer-panel) {
    position: relative;
    height: auto;
    min-height: inherit;
    justify-content: flex-start;
    align-items: stretch;
    gap: 10px;
    overflow: visible;
}

.flashcard.is-hanzi-writing .card-back,
.flashcard:has(.hanzi-writer-panel) .card-back {
    min-height: 100%;
}

.hanzi-writer-panel {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    min-width: 0;
    margin: 0;
}

.hanzi-writer-target {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    width: 100%;
    min-width: 0;
    min-height: var(--hanzi-box-size);
    margin: 0;
    padding: 0;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
}

.hanzi-writer-target.is-multi-hanzi {
    justify-content: center;
    padding-bottom: 4px;
    scroll-snap-type: x proximity;
    /* Largeur disponible répartie entre les caractères (en tenant compte des gaps). */
    --hanzi-multi-fit: calc((100% - (var(--hanzi-count, 1) - 1) * 10px) / var(--hanzi-count, 1));
}

/* Plusieurs caractères : les boîtes rétrécissent pour tenir dans la fenêtre
   au lieu de déborder/être tronquées. Plancher de 104px : au-delà, le défilement
   horizontal reprend le relais (mots très longs). */
.hanzi-writer-target.is-multi-hanzi .hanzi-writer-box {
    width: max(104px, min(var(--hanzi-box-size), var(--hanzi-multi-fit))) !important;
    height: auto !important;
    aspect-ratio: 1 / 1;
    flex: 0 0 auto;
}

.hanzi-writer-target .card-hint {
    margin: 12px 0;
    font-size: 0.88rem;
}

.hanzi-writer-box,
.hanzi-draw-stage {
    width: var(--hanzi-box-size) !important;
    height: var(--hanzi-box-size) !important;
    flex: 0 0 var(--hanzi-box-size);
}

.hanzi-writer-box {
    scroll-snap-align: center;
    /* Même fond 米字格 (cahier chinois) que la zone « À toi », pour montrer
       le tracé de référence sur la même grille que celle où l'on écrit. */
    background-color: var(--mizige-paper);
    background-image: var(--mizige-bg);
    background-size: 100% 100%;
    background-repeat: no-repeat;
    border-radius: 10px;
}

.hanzi-writer-box svg {
    display: block;
    width: 100% !important;
    height: 100% !important;
}

.hanzi-draw-stage {
    position: relative;
    max-width: 100%;
    margin: 0 auto;
    overflow: hidden;
    background-color: var(--mizige-paper);
    background-image: var(--mizige-bg);
    background-size: 100% 100%;
    background-repeat: no-repeat;
    border: 2px solid #e3aeb3;
    border-radius: 18px;
    /* Conteneur de requête : permet de dimensionner le filigrane en cqh
       (hauteur de la case) pour qu'il soit toujours centré dans sa grille. */
    container-type: size;
}

/* Une cellule centrée par caractère, calée exactement sur les cases de la
   grille → chaque hanzi filigrane est parfaitement centré dans sa case. */
.hanzi-draw-guide {
    position: absolute;
    inset: 0;
    z-index: 1;
    display: grid;
    grid-template-columns: repeat(var(--hanzi-count, 1), 1fr);
    color: rgba(35, 49, 66, 0.12);
    line-height: 1;
    pointer-events: none;
    user-select: none;
}

.hanzi-draw-guide span {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 80cqh;
    line-height: 1;
}

/* Couche de tracé guidé (quiz HanziWriter) superposée à la zone « À toi ». */
.hanzi-quiz-host {
    position: absolute;
    inset: 0;
    z-index: 5;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: none;
}

.hanzi-quiz-host svg {
    display: block;
    touch-action: none;   /* le doigt trace, il ne fait pas défiler la page */
}

/* En mode quiz, on masque le dessin libre (guide + canvas) sous le quiz. */
.hanzi-draw-stage.is-quizzing .hanzi-draw-guide,
.hanzi-draw-stage.is-quizzing .hanzi-layer {
    visibility: hidden;
}

/* Petit bandeau « Écris de mémoire », aux tons chauds du cahier chinois. */
.hanzi-quiz-label {
    position: absolute;
    top: 6px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 6;
    padding: 3px 12px;
    background: rgba(180, 83, 9, 0.92);
    color: #fff;
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.02em;
    border-radius: 999px;
    white-space: nowrap;
    pointer-events: none;
}

/* Note finale : plus grande et dorée. */
.hanzi-quiz-label.is-grade {
    top: 50%;
    transform: translate(-50%, -50%);
    padding: 8px 20px;
    font-size: 1.15rem;
    background: linear-gradient(135deg, #f59e0b, #d97706);
    box-shadow: 0 6px 18px rgba(217, 119, 6, 0.35);
}

.hanzi-layer {
    position: absolute;
    inset: 0;
    display: block;
    width: 100%;
    height: 100%;
}

.hanzi-saved-layer {
    z-index: 2;
    opacity: 0.92;
}

.hanzi-draw-layer {
    z-index: 3;
    cursor: crosshair;
    touch-action: none;
}

.hanzi-saved-layer.is-hidden,
.is-hidden {
    display: none;
}

.hanzi-all-tools,
.hanzi-draw-tools,
.hanzi-draw-tools-compact {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 8px;
    width: 100%;
    margin: 2px 0 0;
    align-items: center;
}

.hanzi-tool-btn {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    gap: 4px;
    width: 100%;
    min-width: 0;
    min-height: 44px;
    height: 44px;
    padding: 0;
    border-radius: 13px;
    font-size: 1.05rem;
    font-weight: 900;
    line-height: 1;
    white-space: nowrap;
    overflow: hidden;
}

.hanzi-tool-primary {
    color: #fff;
    background: var(--primary);
}

.hanzi-tool-secondary {
    color: var(--text);
    background: #eef4fb;
    border: 1px solid var(--border);
}

.hanzi-all-tools .btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.hanzi-all-tools .btn-text {
    display: none;
}

.flashcard.is-free-hanzi {
    display: block;
    height: auto;
    min-height: 0;
    perspective: none;
    cursor: default;
}

.flashcard.is-free-hanzi .card-inner {
    height: auto;
    transform: none !important;
    transition: none;
}

.flashcard.is-free-hanzi .card-front {
    position: relative;
    inset: auto;
    height: auto;
    min-height: 0;
    justify-content: flex-start;
    align-items: stretch;
    gap: 10px;
    padding: clamp(12px, 4vw, 16px);
    overflow: visible;
    backface-visibility: visible;
}

.flashcard.is-free-hanzi .card-back {
    display: none;
}

.free-hanzi-card {
    display: grid;
    gap: 10px;
    width: 100%;
    min-width: 0;
}

.free-hanzi-controls {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    gap: 8px;
    align-items: center;
    width: 100%;
}

.free-hanzi-label {
    display: none;
}

.free-hanzi-input {
    min-height: 52px;
    padding: 8px 12px;
    border-radius: 16px;
    font-size: clamp(1.6rem, 8vw, 2.35rem);
    line-height: 1;
    font-weight: 800;
    text-align: center;
}

.free-hanzi-load-btn,
.free-hanzi-random-btn {
    min-height: 52px;
    padding: 8px 12px;
    border-radius: 16px;
    font-size: 0.93rem;
    font-weight: 900;
    white-space: nowrap;
}

.free-hanzi-load-btn {
    color: #fff;
    background: var(--primary);
}

.free-hanzi-random-btn {
    color: var(--text);
    background: #eef4fb;
    border: 1px solid var(--border);
}

.free-hanzi-recent-row {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 8px;
    align-items: center;
    width: 100%;
    color: var(--muted);
    font-size: 0.85rem;
}

.free-hanzi-recent {
    display: flex;
    gap: 6px;
    min-width: 0;
    overflow-x: auto;
    padding: 2px 0 4px;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
}

.free-hanzi-chip {
    flex: 0 0 auto;
    min-width: 34px;
    min-height: 34px;
    padding: 2px 8px;
    color: var(--text);
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 999px;
    font-size: 1.08rem;
}

.free-hanzi-info {
    display: grid;
    justify-items: center;
    gap: 2px;
    padding: 2px 0;
}

.free-hanzi-main {
    font-size: clamp(2.7rem, 14vw, 4.6rem);
    line-height: 0.95;
    font-weight: 900;
}

.free-hanzi-info .pinyin {
    margin-top: 0;
    font-size: clamp(1.05rem, 5vw, 1.55rem);
}

.free-hanzi-fr {
    margin-top: 0;
    font-size: clamp(0.98rem, 4.2vw, 1.25rem);
    line-height: 1.2;
}

.hanzi-practice-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    width: 100%;
    min-width: 0;
}

.hanzi-practice-cell {
    display: grid;
    justify-items: center;
    gap: 6px;
    width: 100%;
    min-width: 0;
}

.hanzi-practice-title {
    color: var(--muted);
    font-size: 0.76rem;
    font-weight: 900;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.free-hanzi-card .hanzi-writer-target {
    min-height: 0;
    overflow-x: auto;
}

/* Le « Modèle » du haut est une simple référence : on laisse le doigt faire
   défiler la page dessus (pas de capture tactile → plus de confusion). */
.free-hanzi-card .hanzi-writer-target,
.free-hanzi-card .hanzi-writer-box,
.free-hanzi-card .hanzi-writer-box svg {
    touch-action: pan-y;
    pointer-events: none;
}

.free-hanzi-card .hanzi-writer-box,
.free-hanzi-card .hanzi-draw-stage {
    width: clamp(180px, 70vw, 260px) !important;
    height: clamp(180px, 70vw, 260px) !important;
    max-width: 260px;
    max-height: 260px;
    flex: 0 0 auto;
    margin: 0 auto;
}

/* Écriture libre avec plusieurs caractères : on rétrécit aussi pour éviter
   la troncature en mode smartphone. */
.free-hanzi-card .hanzi-writer-target.is-multi-hanzi .hanzi-writer-box {
    width: max(100px, min(clamp(180px, 70vw, 260px), var(--hanzi-multi-fit))) !important;
    height: auto !important;
    aspect-ratio: 1 / 1;
    margin: 0;
}

/* ===== Écriture libre : mot de plusieurs caractères ===== */
/* On empile Modèle / À toi pour donner toute la largeur de la carte au mot,
   et on adapte les deux cadres pour qu'il soit visible en entier. */
.free-hanzi-card.is-multi .hanzi-practice-grid {
    grid-template-columns: 1fr;
}

/* Modèle : les boîtes rétrécissent toujours pour tenir (aucun plancher qui déborde). */
.free-hanzi-card.is-multi .hanzi-writer-target.is-multi-hanzi .hanzi-writer-box {
    width: min(clamp(180px, 70vw, 260px), var(--hanzi-multi-fit)) !important;
}

/* À toi : cadre rectangulaire (N caractères de large), le guide occupe toute
   la hauteur via les unités de conteneur → le mot entier est visible. */
.free-hanzi-card.is-multi .hanzi-draw-stage {
    width: 100% !important;
    height: auto !important;
    max-width: none !important;
    max-height: none !important;
    aspect-ratio: var(--hanzi-count, 1) / 1;
    container-type: size;
    /* Une grille 米字格 carrée par caractère. */
    background-size: calc(100% / var(--hanzi-count, 1)) 100%;
    background-repeat: repeat-x;
}

.free-hanzi-card .hanzi-all-tools {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 8px;
    margin-top: 2px;
}

.free-hanzi-card .hanzi-tool-btn {
    height: 46px;
    min-height: 46px;
    border-radius: 13px;
    font-size: 1.12rem;
}

.free-hanzi-card .hanzi-tool-btn .btn-text {
    display: none;
}

@media (min-width: 560px) {
    :root {
        --hanzi-box-size: 260px;
    }

    .app-container {
        width: min(100%, 520px);
    }

    .flashcard.is-hanzi-writing .card-inner,
    .flashcard:has(.hanzi-writer-panel) .card-inner {
        min-height: 660px;
    }
}

@media (min-width: 720px) {
    .app-container {
        width: min(100%, 760px);
    }

    .filter-group {
        grid-template-columns: 1fr 1fr;
    }

    .hanzi-practice-grid {
        grid-template-columns: 1fr 1fr;
        align-items: start;
    }

    .free-hanzi-card .hanzi-all-tools .btn-text {
        display: inline;
        font-size: 0.84rem;
    }
}

@media (max-width: 430px) {
    :root {
        --radius-card: 18px;
        --tap-size: 42px;
        --hanzi-box-size: min(190px, 76vw);
    }

    body {
        padding: max(6px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
    }

    .app-header {
        margin-bottom: 5px;
    }

    .app-header h1 {
        margin: 2px 0 0;
        font-size: clamp(1.28rem, 5.4vw, 1.55rem);
    }

    .user-profile {
        width: fit-content;
        max-width: 100%;
        margin-top: 6px;
        gap: 8px;
        padding: 5px 10px 5px 6px;
    }

    .user-avatar,
    .user-avatar-fallback {
        width: 32px;
        height: 32px;
        flex-basis: 32px;
    }

    .user-greeting {
        font-size: clamp(0.88rem, 3.8vw, 0.98rem);
    }

    .auth-row {
        margin: 6px 0 8px;
    }

    .auth-row button,
    .btn-secondary,
    #btn-mastery {
        padding: 8px 12px;
        font-size: 0.92rem;
    }

    .filter-group {
        gap: 7px;
        margin-bottom: 7px;
    }

    select {
        min-height: 42px;
        padding: 7px 34px 7px 10px;
        font-size: 0.96rem;
        border-radius: 14px;
    }

    .card-counter {
        margin-bottom: 6px;
        font-size: 0.82rem;
    }

    #card-container {
        min-height: clamp(330px, 56dvh, 430px);
        margin-bottom: 10px;
    }

    .flashcard {
        min-height: 330px;
        height: clamp(330px, 56dvh, 430px);
    }

    .card-front,
    .card-back {
        padding: 12px;
        gap: 7px;
    }

    .flashcard.is-hanzi-radical .card-back,
    .flashcard.density-compact .card-back {
        padding: 10px 12px;
        gap: 5px;
    }

    .icon {
        font-size: clamp(1.85rem, 8vw, 2.7rem);
    }

    .card-hint {
        margin-top: 2px;
        font-size: 0.75rem;
    }

    .btn-red,
    .btn-green {
        min-height: 48px;
        padding: 10px 8px;
        font-size: 0.86rem;
        border-radius: 14px;
    }

    .flashcard.is-hanzi-writing .card-inner,
    .flashcard:has(.hanzi-writer-panel) .card-inner {
        min-height: auto;
    }

    .flashcard.is-hanzi-writing .card-front,
    .card-front:has(.hanzi-writer-panel) {
        padding: 12px;
    }

    .hanzi-all-tools,
    .hanzi-draw-tools,
    .hanzi-draw-tools-compact {
        gap: 6px;
    }

    .hanzi-tool-btn {
        height: 42px;
        min-height: 42px;
        border-radius: 12px;
        font-size: 0.98rem;
    }

    .free-hanzi-controls {
        grid-template-columns: 1fr 46px 56px;
        gap: 6px;
    }

    .free-hanzi-load-btn,
    .free-hanzi-random-btn {
        padding: 0;
    }

    .free-hanzi-load-btn {
        font-size: 0;
    }

    .free-hanzi-load-btn::before {
        content: "OK";
        font-size: 0.88rem;
    }

    .free-hanzi-random-btn {
        font-size: 0;
    }

    .free-hanzi-random-btn::before {
        content: "🎲";
        font-size: 1.05rem;
    }

    .free-hanzi-card .hanzi-writer-box,
    .free-hanzi-card .hanzi-draw-stage {
        width: min(72vw, 235px) !important;
        height: min(72vw, 235px) !important;
    }

    .free-hanzi-card .hanzi-all-tools {
        gap: 6px;
    }
}

@media (max-width: 360px) {
    .app-header h1 {
        font-size: 1.35rem;
    }

    select,
    .auth-row button,
    .btn-secondary,
    #btn-mastery {
        font-size: 0.92rem;
    }

    .fr {
        font-size: clamp(1.12rem, 5.4vw, 1.55rem);
    }

    .card-hint {
        font-size: 0.78rem;
    }

    .controls {
        gap: 8px;
    }
}

@media (max-height: 760px) and (max-width: 430px) {
    .auth-row,
    .filter-group,
    .action-row {
        margin-bottom: 6px;
    }

    .card-counter {
        margin-bottom: 4px;
    }

    .flashcard {
        min-height: 310px;
        height: clamp(310px, calc(100dvh - 320px), 410px);
    }

    .card-front,
    .card-back {
        padding: 10px 12px;
    }

    .icon {
        font-size: clamp(1.8rem, 8vw, 2.55rem);
    }

    .card-hint {
        margin-top: 2px;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
    }

    .card-inner {
        transition: none;
    }

    .flashcard {
        animation: none;
    }

    button {
        transition: none;
    }
}

/* ================= MENU PRINCIPAL & SOUS-MENUS ================= */
.menu-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    width: 100%;
}

.menu-btn {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 4px;
    min-height: 104px;
    padding: 14px 10px;
    background: linear-gradient(180deg, #ffffff 0%, #fbfdff 100%);
    border: 1px solid rgba(217, 225, 236, 0.8);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-soft);
    text-align: center;
}

.menu-btn:not(:disabled):hover {
    box-shadow: var(--shadow);
}

.menu-emoji {
    font-size: 2rem;
    line-height: 1;
}

.menu-label {
    font-weight: 900;
    font-size: 1rem;
    color: var(--text);
}

.menu-sub {
    font-size: 0.74rem;
    line-height: 1.2;
    color: var(--muted);
}

.submenu-list {
    display: grid;
    gap: 8px;
    width: 100%;
}

.submenu-btn {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    min-height: 56px;
    padding: 10px 14px;
    background: linear-gradient(180deg, #ffffff 0%, #fbfdff 100%);
    border: 1px solid rgba(217, 225, 236, 0.8);
    border-radius: var(--radius-control);
    box-shadow: var(--shadow-soft);
    text-align: left;
}

.submenu-label {
    font-weight: 800;
    font-size: 0.98rem;
    color: var(--text);
}

.submenu-sub {
    font-size: 0.78rem;
    color: var(--muted);
}

.hz-inline {
    font-size: 1.25rem;
    font-weight: 900;
    margin-right: 4px;
}

.btn-home {
    width: 100%;
    min-height: var(--tap-size);
    padding: 11px 14px;
    border-radius: var(--radius-control);
    font-weight: 800;
    color: var(--text);
    background: #eef4fb;
    border: 1px solid var(--border);
}

/* ================= QUIZ / QCM ================= */
.quiz-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: clamp(16px, 4.5vw, 22px);
    background: linear-gradient(180deg, #ffffff 0%, #fbfdff 100%);
    border: 1px solid rgba(217, 225, 236, 0.8);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow);
    text-align: center;
}

.quiz-prompt {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    width: 100%;
}

.quiz-hz {
    font-size: clamp(2.4rem, 12vw, 4rem);
}

.quiz-hz.quiz-sentence,
.quiz-sentence {
    font-size: clamp(1.3rem, 6vw, 2rem);
    line-height: 1.35;
}

.quiz-py {
    font-size: clamp(1.5rem, 7vw, 2.2rem);
    font-weight: 900;
    color: var(--pinyin);
}

.quiz-fr,
.quiz-fr-hint {
    font-size: clamp(1.1rem, 5vw, 1.5rem);
    font-weight: 800;
}

.quiz-fr-hint {
    font-size: 0.95rem;
    color: var(--muted);
    font-weight: 700;
}

.quiz-options {
    display: grid;
    gap: 8px;
    width: 100%;
}

.quiz-option {
    min-height: 50px;
    padding: 10px 14px;
    background: #fff;
    border: 2px solid var(--border);
    border-radius: 14px;
    font-weight: 700;
    font-size: 0.98rem;
    line-height: 1.25;
    color: var(--text);
    overflow-wrap: anywhere;
}

.quiz-option.is-hanzi {
    font-size: 1.45rem;
    font-weight: 900;
}

.quiz-option.is-correct {
    background: #d3f9d8;
    border-color: #2b8a3e;
}

.quiz-option.is-wrong {
    background: #ffe3e3;
    border-color: #d63438;
}

.quiz-option:disabled {
    opacity: 1;
    cursor: default;
}

.quiz-listen {
    font-size: 1.05rem;
    min-height: 54px;
    padding: 12px 22px;
}

.quiz-score {
    font-size: clamp(1.6rem, 8vw, 2.2rem);
    font-weight: 900;
    margin: 6px 0;
}

.quiz-score.is-pass { color: var(--success); }
.quiz-score.is-fail { color: var(--danger); }

.btn-errors { background: var(--warning-grad); }

/* ================= PHRASE MÉLANGÉE ================= */
.scramble-answer {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 6px;
    width: 100%;
    min-height: 60px;
    padding: 10px;
    border: 2px dashed var(--border);
    border-radius: 14px;
    background: var(--panel-soft);
}

.scramble-placeholder {
    color: var(--muted);
    font-size: 0.85rem;
}

.scramble-pool {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    width: 100%;
}

.scramble-chip {
    min-height: 44px;
    padding: 8px 14px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 999px;
    font-size: 1.25rem;
    font-weight: 800;
    color: var(--text);
    box-shadow: var(--shadow-soft);
}

.scramble-chip.is-placed {
    background: #ecf3fc;
    border-color: #c8dcf3;
    color: var(--primary-dark);
}

.scramble-feedback {
    display: grid;
    justify-items: center;
    gap: 6px;
    width: 100%;
    padding: 12px;
    border-radius: 14px;
}

.scramble-feedback.is-ok { background: #d3f9d8; }
.scramble-feedback.is-ko { background: #ffe3e3; }

/* ================= DICTÉE ================= */
.dictation-input {
    width: 100%;
    min-height: 54px;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--panel);
    color: var(--text);
    font-size: 1.3rem;
    text-align: center;
}

.dictation-answer {
    display: grid;
    justify-items: center;
    gap: 4px;
    width: 100%;
    padding: 12px;
    border-radius: 14px;
    background: var(--panel-soft);
}

.dictation-verdict {
    margin: 4px 0 0;
    font-weight: 800;
}

.dictation-grade {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    width: 100%;
}

/* ================= LECTEUR AUDIO ================= */
.player-controls {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
    width: 100%;
    margin-top: 4px;
}

.player-controls .hanzi-tool-btn {
    height: 50px;
    min-height: 50px;
    font-size: 1rem;
}

.quiz-box .result-actions {
    width: 100%;
    margin-top: 4px;
}

/* ================= ONTOLOGIE DES RADICAUX ================= */
.onto-box {
    align-items: stretch;
    text-align: left;
}

.onto-radical {
    align-self: center;
    display: flex;
    align-items: baseline;
    gap: 12px;
    font-size: clamp(3.4rem, 17vw, 5rem);
    font-weight: 900;
    line-height: 1;
    color: var(--text);
}

.onto-variant {
    font-size: 0.45em;
    color: var(--primary-dark);
    font-weight: 900;
}

.onto-box .pinyin {
    align-self: center;
    text-align: center;
}

.onto-heuristic {
    padding: 10px 14px;
    border-radius: 14px;
    background: #ecf3fc;
    border: 1px solid #c8dcf3;
    color: var(--primary-dark);
    font-weight: 700;
    font-size: 0.92rem;
    line-height: 1.35;
}

.onto-list {
    display: grid;
    gap: 8px;
    width: 100%;
}

.onto-row {
    display: grid;
    grid-template-columns: 56px minmax(0, 1fr);
    gap: 10px;
    align-items: center;
    padding: 8px 10px;
    border-radius: 14px;
    background: var(--panel-soft);
    border: 1px solid rgba(217, 225, 236, 0.7);
}

.onto-row.is-hors {
    opacity: 0.78;
    border-style: dashed;
}

.onto-char {
    width: 56px;
    height: 56px;
    border-radius: 14px;
    background: #fff;
    border: 1px solid var(--border);
    font-size: 1.9rem;
    font-weight: 900;
    color: var(--text);
    box-shadow: var(--shadow-soft);
}

.onto-info {
    min-width: 0;
}

.onto-py {
    font-weight: 800;
    font-size: 0.92rem;
    line-height: 1.3;
    overflow-wrap: anywhere;
}

.onto-note {
    margin-top: 1px;
    font-size: 0.8rem;
    color: var(--muted);
    line-height: 1.3;
}

.onto-badge {
    display: inline-block;
    padding: 1px 7px;
    border-radius: 999px;
    background: #fff3e0;
    border: 1px solid #f3c98b;
    color: #b45309;
    font-size: 0.66rem;
    font-weight: 800;
    vertical-align: middle;
}

.onto-trap {
    padding: 10px 14px;
    border-radius: 14px;
    background: #fff3f3;
    border: 1px solid #f3b4b4;
    color: #a13335;
    font-weight: 700;
    font-size: 0.88rem;
    line-height: 1.35;
}

/* ================= HANZI CLIQUABLES (tap = son) ================= */
.speakable {
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    transition: transform 0.12s ease;
}

.speakable:active {
    transform: scale(0.95);
}

.speakable::after {
    content: " 🔊";
    font-size: 0.32em;
    vertical-align: super;
    opacity: 0.5;
}

/* ================= EXERCICE D'ÉCRITURE NOTÉ (田字格) ================= */
.write-head {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 10px;
    width: 100%;
}

.write-fr {
    font-weight: 800;
    font-size: 1rem;
}

.write-listen {
    min-height: 40px;
    padding: 6px 14px;
    margin-top: 0;
}

.write-stage {
    position: relative;
    width: clamp(230px, 74vw, 310px);
    height: clamp(230px, 74vw, 310px);
    margin: 0 auto;
    border-radius: 12px;
    overflow: hidden;
    background-color: #fffdf8;
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><rect x="1.5" y="1.5" width="97" height="97" fill="none" stroke="%23d98b8b" stroke-width="2.4"/><path d="M50 2 V98" stroke="%23e8b4b4" stroke-width="1" stroke-dasharray="3.5 2.8"/><path d="M2 50 H98" stroke="%23e8b4b4" stroke-width="1" stroke-dasharray="3.5 2.8"/><path d="M2 2 L98 98" stroke="%23f2d3d3" stroke-width="1" stroke-dasharray="3.5 2.8"/><path d="M98 2 L2 98" stroke="%23f2d3d3" stroke-width="1" stroke-dasharray="3.5 2.8"/></svg>');
    background-size: 100% 100%;
    box-shadow: var(--shadow-soft);
}

.write-model {
    position: absolute;
    inset: 0;
    z-index: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: clamp(170px, 56vw, 235px);
    line-height: 1;
    color: rgba(31, 44, 61, 0.18);
    pointer-events: none;
    user-select: none;
    transition: opacity 0.25s ease;
}

.write-model.is-hidden-model {
    opacity: 0;
}

.write-model.is-rated {
    color: rgba(25, 118, 210, 0.3);
}

.write-canvas {
    position: absolute;
    inset: 0;
    z-index: 2;
    width: 100%;
    height: 100%;
    cursor: crosshair;
    touch-action: none;
}

.write-tools {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 8px;
    width: 100%;
}

.write-tools .hanzi-tool-btn {
    height: 48px;
    min-height: 48px;
    font-size: 0.92rem;
}

.write-verdict {
    display: grid;
    justify-items: center;
    gap: 6px;
    width: 100%;
    padding: 12px;
    border-radius: 14px;
    font-weight: 700;
}

.write-verdict.is-ok { background: #d3f9d8; }
.write-verdict.is-ko { background: #ffe3e3; }

.write-verdict p {
    margin: 0;
    text-align: center;
}

.write-verdict .result-actions {
    grid-template-columns: 1fr 1fr;
    display: grid;
    width: 100%;
    gap: 10px;
    margin-top: 6px;
}

.write-detail {
    font-size: 0.82rem;
    color: var(--muted);
    font-weight: 700;
    line-height: 1.4;
}

/* ================= INVITATION À L'INSTALLATION (PWA) ================= */
.install-banner {
    position: fixed;
    left: max(8px, env(safe-area-inset-left));
    right: max(8px, env(safe-area-inset-right));
    bottom: max(10px, env(safe-area-inset-bottom));
    z-index: 1000;
    display: flex;
    align-items: center;
    gap: 10px;
    max-width: 520px;
    margin: 0 auto;
    padding: 12px 14px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: var(--shadow);
    animation: install-banner-in 0.32s var(--ease-spring);
}

@keyframes install-banner-in {
    from { transform: translateY(120%); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.install-banner-icon {
    font-size: 1.6rem;
    line-height: 1;
    flex: 0 0 auto;
}

.install-banner-text {
    flex: 1 1 auto;
    font-size: 0.86rem;
    font-weight: 600;
    line-height: 1.3;
    color: var(--text);
}

.install-banner-cta {
    flex: 0 0 auto;
    padding: 9px 16px;
    border: none;
    border-radius: 12px;
    background: var(--primary-grad);
    color: #fff;
    font-size: 0.9rem;
    font-weight: 800;
    cursor: pointer;
}

.install-banner-dismiss {
    flex: 0 0 auto;
    width: 30px;
    height: 30px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: var(--bg-soft);
    color: var(--muted);
    font-size: 0.9rem;
    line-height: 1;
    cursor: pointer;
}

/* Notice pas-à-pas (iOS Safari et navigateurs sans prompt natif) */
.install-help-overlay {
    position: fixed;
    inset: 0;
    z-index: 1100;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding: 16px;
    background: rgba(15, 38, 70, 0.55);
    animation: install-banner-in 0.2s ease;
}

.install-help-card {
    position: relative;
    width: 100%;
    max-width: 420px;
    margin-bottom: max(8px, env(safe-area-inset-bottom));
    padding: 22px 20px 20px;
    background: var(--panel);
    border-radius: 20px;
    box-shadow: var(--shadow);
}

.install-help-card h2 {
    margin: 0 0 6px;
    font-size: 1.16rem;
    color: var(--text);
}

.install-help-sub {
    margin: 0 0 14px;
    font-size: 0.9rem;
    line-height: 1.4;
    color: var(--muted);
}

.install-help-steps {
    margin: 0;
    padding-left: 20px;
    display: grid;
    gap: 10px;
    font-size: 0.94rem;
    line-height: 1.45;
    color: var(--text);
}

.install-help-steps .ih-key {
    display: inline-block;
    padding: 0 4px;
}

/* Bloc « copier le lien » (aide à ouvrir dans Chrome). */
.install-help-copy {
    display: flex;
    gap: 8px;
    margin-top: 14px;
}

.install-help-url {
    flex: 1 1 auto;
    min-width: 0;
    padding: 9px 10px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--panel-soft);
    color: var(--muted);
    font-size: 0.82rem;
}

.install-help-copybtn {
    flex: 0 0 auto;
    padding: 9px 14px;
    border: none;
    border-radius: 10px;
    background: var(--primary-grad);
    color: #fff;
    font-size: 0.86rem;
    font-weight: 800;
    white-space: nowrap;
    cursor: pointer;
}

.install-help-close {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 32px;
    height: 32px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: var(--bg-soft);
    color: var(--muted);
    font-size: 1rem;
    line-height: 1;
    cursor: pointer;
}

@media (min-width: 560px) {
    .install-help-overlay {
        align-items: center;
    }
}

/* ================= LANDING / GARDE D'ACCÈS ================= */
body.is-gated {
    overflow: hidden;
}

.access-gate {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: max(20px, env(safe-area-inset-top)) 18px max(20px, env(safe-area-inset-bottom));
    background: linear-gradient(160deg, #eaf2fc 0%, #dce8f7 55%, #f3e9ec 100%);
    overflow-y: auto;
}

.access-gate[hidden] {
    display: none;
}

.gate-card {
    width: 100%;
    max-width: 380px;
    padding: 28px 24px 24px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 24px;
    box-shadow: var(--shadow);
    text-align: center;
    animation: install-banner-in 0.3s var(--ease-spring);
}

.gate-logo {
    width: 72px;
    height: 72px;
    margin: 0 auto 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.4rem;
    font-weight: 900;
    color: #fff;
    background: var(--primary-grad);
    border-radius: 22px;
    box-shadow: var(--shadow-soft);
}

/* Logo image de la landing (marque Liù Liù Liù). */
.gate-logo-img {
    display: block;
    width: 120px;
    height: 120px;
    margin: 0 auto 16px;
    border-radius: 24px;
    box-shadow: var(--shadow);
    object-fit: cover;
}

.gate-title {
    margin: 0 0 4px;
    font-size: 1.55rem;
    color: var(--text);
}

.gate-tagline {
    margin: 0 0 22px;
    font-size: 0.9rem;
    line-height: 1.4;
    color: var(--muted);
}

.gate-hint {
    margin: 0 0 14px;
    font-size: 0.96rem;
    line-height: 1.4;
    color: var(--text);
    font-weight: 600;
}

.gate-btn {
    width: 100%;
    min-height: 48px;
    padding: 12px 16px;
    border: none;
    border-radius: var(--radius-control);
    background: var(--primary-grad);
    color: #fff;
    font-size: 1rem;
    font-weight: 800;
    cursor: pointer;
}

.gate-code-row {
    display: flex;
    gap: 8px;
}

.gate-code-row input {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 48px;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-control);
    background: var(--panel-soft);
    color: var(--text);
    font-size: 1.05rem;
    text-align: center;
    letter-spacing: 0.12em;
}

.gate-code-row input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--focus);
}

.gate-code-row .gate-btn {
    width: auto;
    flex: 0 0 auto;
    padding: 12px 20px;
}

.gate-error {
    margin: 14px 0 0;
    padding: 10px 12px;
    font-size: 0.9rem;
    font-weight: 700;
    line-height: 1.4;
    color: #b42318;
    background: #fdecea;
    border: 1px solid #f6c9c2;
    border-radius: 12px;
}

.gate-link {
    margin-top: 16px;
    padding: 6px 10px;
    border: none;
    background: transparent;
    color: var(--muted);
    font-size: 0.86rem;
    font-weight: 700;
    text-decoration: underline;
    cursor: pointer;
}

.gate-status {
    margin: 0 0 12px;
    padding: 12px 14px;
    font-size: 0.92rem;
    line-height: 1.45;
    font-weight: 600;
    border-radius: 14px;
}

.gate-status-wait {
    color: #92560a;
    background: #fff4e2;
    border: 1px solid #f4d49a;
}

.gate-status-no {
    color: #b42318;
    background: #fdecea;
    border: 1px solid #f6c9c2;
}

.gate-email-line {
    margin: 0 0 4px;
    font-size: 0.84rem;
    color: var(--muted);
    word-break: break-all;
}

/* ===== Panneau admin : demandes d'accès ===== */
.admin-overlay {
    position: fixed;
    inset: 0;
    z-index: 2100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(15, 38, 70, 0.55);
    animation: install-banner-in 0.2s ease;
}

.admin-card {
    position: relative;
    width: 100%;
    max-width: 460px;
    max-height: 80vh;
    overflow-y: auto;
    padding: 22px 20px;
    background: var(--panel);
    border-radius: 20px;
    box-shadow: var(--shadow);
}

.admin-card h2 {
    margin: 0 0 16px;
    font-size: 1.16rem;
    color: var(--text);
}

.admin-close {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 32px;
    height: 32px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: var(--bg-soft);
    color: var(--muted);
    font-size: 1rem;
    cursor: pointer;
}

.admin-empty {
    margin: 8px 0;
    color: var(--muted);
    font-size: 0.92rem;
    text-align: center;
}

.admin-list {
    display: grid;
    gap: 10px;
}

.admin-row {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas: "info badge" "actions actions";
    gap: 8px 10px;
    align-items: center;
    padding: 12px;
    background: var(--panel-soft);
    border: 1px solid var(--border);
    border-radius: 14px;
}

.admin-info {
    grid-area: info;
    display: grid;
    min-width: 0;
}

.admin-email {
    font-size: 0.92rem;
    font-weight: 800;
    color: var(--text);
    word-break: break-all;
}

.admin-name {
    font-size: 0.82rem;
    color: var(--muted);
}

.admin-badge {
    grid-area: badge;
    align-self: start;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 0.76rem;
    font-weight: 800;
    white-space: nowrap;
}

.admin-badge-pending { color: #92560a; background: #fff4e2; }
.admin-badge-approved { color: #1b7a37; background: #e6f6ec; }
.admin-badge-rejected { color: #b42318; background: #fdecea; }

.admin-actions {
    grid-area: actions;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.admin-actions button {
    min-height: 40px;
    border: none;
    border-radius: 11px;
    font-size: 0.9rem;
    font-weight: 800;
    cursor: pointer;
}

.admin-approve { color: #fff; background: var(--success); }
.admin-reject { color: #fff; background: var(--danger); }

.admin-actions button:disabled {
    opacity: 0.4;
    cursor: default;
}
