/*
 * Recto — système de design.
 *
 * Repères : fond papier, encre presque noire, traits de 2px partout, aplats de couleur
 * franche, typo grasse très resserrée sur les grands titres. Une couleur par cours.
 */

:root {
    --paper: #fbf9f4;
    --ink: #17140f;
    --muted: #8a8478;
    --faint: #b5aea2;
    --hairline: #eae5da;
    --accent: #2f6bff;
    --accent-ink: #1b4bc4;
    --answer: #ffd84d;
    --done: #12b981;
    --danger: #e5484d;

    --r1: #e5484d;
    --r2: #f76b15;
    --r3: #ffd84d;
    --r4: #8ecf4d;
    --r5: #12b981;

    --line: 2px solid var(--ink);
    --sans: 'Schibsted Grotesk', system-ui, -apple-system, 'Segoe UI', sans-serif;
    --mono: 'JetBrains Mono', ui-monospace, 'SF Mono', monospace;
}

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

html {
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    background: var(--paper);
    color: var(--ink);
    font-family: var(--sans);
    font-size: 16px;
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
}

img {
    max-width: 100%;
    height: auto;
}

a {
    color: inherit;
    text-decoration: none;
}

:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 2px;
}

/* ---------------------------------------------------------------- Coquille */

.app {
    display: flex;
    min-height: 100vh;
    min-height: 100dvh;
}

.main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

/* Colonne de cours, masquée sur mobile : la page d'accueil joue ce rôle. */
.nav {
    display: none;
}

@media (min-width: 900px) {
    .nav {
        display: flex;
        flex-direction: column;
        width: 300px;
        flex: none;
        border-right: var(--line);
        position: sticky;
        top: 0;
        height: 100vh;
        height: 100dvh;
        overflow-y: auto;
    }
}

.nav__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 24px;
    border-bottom: var(--line);
}

.nav__brand {
    font-size: 22px;
    font-weight: 800;
    letter-spacing: -0.03em;
}

.nav__item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 24px;
    border-bottom: 2px solid var(--hairline);
}

.nav__item:hover {
    background: var(--hairline);
}

.nav__item[aria-current='page'] {
    background: var(--ink);
    color: var(--paper);
}

.nav__item[aria-current='page'] .nav__meta {
    color: var(--faint);
}

.nav__name {
    font-size: 15px;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.nav__meta {
    font-size: 11px;
    font-weight: 500;
    color: var(--muted);
}

.nav__foot {
    margin-top: auto;
    padding: 16px 24px;
    border-top: var(--line);
    font-size: 14px;
    font-weight: 700;
}

/* Compte connecté : en pied de colonne, ou en tête de la page d'accueil qui n'a pas de colonne. */
.account {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
}

.account--nav {
    padding: 0 24px 16px;
}

.account--head {
    margin-bottom: 14px;
}

.account__email {
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Le formulaire de déconnexion ne doit pas peser dans la mise en page. */
.account__logout {
    margin: 0;
    flex: none;
}

.account__logout button {
    font: inherit;
    font-size: 12px;
    font-weight: 700;
    color: var(--muted);
    background: none;
    border: 0;
    padding: 0;
    cursor: pointer;
    text-decoration: underline;
}

.account__logout button:hover {
    color: var(--ink);
}

/* ------------------------------------------------------------------ Écrans */

.screen {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.screen__body {
    flex: 1;
}

/* Bandeau de titre. Sans modificateur : sur papier. Avec : aplat de couleur. */
.head {
    padding: 22px;
}

.head--accent {
    background: var(--accent);
    color: #fff;
}

.head--done {
    background: var(--done);
    color: var(--ink);
}

.head--course {
    background: var(--course, var(--accent));
    color: var(--course-ink, #fff);
}

.head__back {
    display: inline-block;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    opacity: 0.75;
    margin-bottom: 14px;
}

.head__back:hover {
    opacity: 1;
}

.head__title {
    margin: 0;
    font-size: 36px;
    line-height: 1;
    font-weight: 800;
    letter-spacing: -0.035em;
    text-wrap: balance;
}

.head__title--xl {
    font-size: 40px;
    line-height: 0.98;
    letter-spacing: -0.04em;
}

.head__note {
    font-size: 14px;
    font-weight: 600;
    opacity: 0.8;
    margin-top: 10px;
}

@media (min-width: 900px) {
    .head {
        padding: 34px 40px;
    }

    .head__title {
        font-size: 52px;
        letter-spacing: -0.04em;
    }

    .head__title--xl {
        font-size: 60px;
    }
}

/* Chiffres clés sous un titre. */
.stats {
    display: flex;
    gap: 24px;
    margin-top: 20px;
}

.stats__value {
    display: block;
    font-size: 22px;
    font-weight: 800;
    letter-spacing: -0.02em;
}

.stats__label {
    font-size: 13px;
    font-weight: 600;
}

@media (min-width: 900px) {
    .stats {
        gap: 46px;
        margin-top: 26px;
    }

    .stats__value {
        font-size: 26px;
    }
}

/* Intertitre de section. */
.eyebrow {
    padding: 18px 22px 10px;
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--muted);
}

@media (min-width: 900px) {
    .eyebrow {
        padding: 22px 40px 10px;
    }
}

/* -------------------------------------------------------------- Listes */

.list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.row {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 15px 22px;
    border-top: var(--line);
}

/* Variante allégée pour les longues listes de cartes. */
.row--light {
    border-top: 2px solid var(--hairline);
    align-items: flex-start;
}

.row:hover {
    background: var(--hairline);
}

.row__main {
    flex: 1;
    min-width: 0;
}

.row__name {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.row__name--sm {
    font-size: 15px;
    line-height: 1.25;
}

.row__meta {
    font-size: 12px;
    font-weight: 500;
    color: var(--muted);
    margin-top: 2px;
}

.row__meta--clip {
    font-size: 13px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.row__due {
    font-size: 14px;
    font-weight: 700;
    flex: none;
}

@media (min-width: 900px) {
    .row {
        padding: 18px 40px;
    }
}

/* Pastille de couleur d'un cours. */
.dot {
    width: 26px;
    height: 26px;
    border-radius: 7px;
    background: var(--course, var(--accent));
    flex: none;
}

.dot--sm {
    width: 20px;
    height: 20px;
    border-radius: 6px;
}

/* Note d'une carte. */
.badge {
    font-size: 12px;
    font-weight: 800;
    border: var(--line);
    border-radius: 6px;
    padding: 1px 6px;
    flex: none;
}

.badge--muted {
    border-color: var(--faint);
    color: var(--muted);
}

/* Avancement d'un deck. */
.bar {
    width: 54px;
    height: 8px;
    border: var(--line);
    border-radius: 999px;
    overflow: hidden;
    flex: none;
}

.bar__fill {
    height: 100%;
    background: var(--accent);
}

/* ------------------------------------------------------------- Actions */

.actions {
    margin-top: auto;
    border-top: var(--line);
    padding: 16px 22px;
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.actions--between {
    justify-content: space-between;
}

@media (min-width: 900px) {
    .actions {
        padding: 16px 40px;
    }
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 13px 20px;
    border: var(--line);
    border-radius: 12px;
    background: transparent;
    color: var(--ink);
    font-family: inherit;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    text-align: center;
}

.btn:hover {
    background: var(--hairline);
}

.btn--solid {
    background: var(--ink);
    color: var(--paper);
}

.btn--solid:hover {
    background: #000;
}

.btn--grow {
    flex: 1;
}

/* Un bouton seul dans un <form> doit pouvoir s'étirer comme les autres. */
.actions form {
    display: flex;
    flex: 1;
}

.btn--ghost {
    border-color: currentColor;
    background: transparent;
    color: inherit;
}

.btn--ghost:hover {
    background: rgb(255 255 255 / 0.15);
}

.btn--quiet {
    border: 0;
    padding: 6px 0;
    font-size: 14px;
    color: var(--muted);
}

.btn--quiet:hover {
    background: transparent;
    color: var(--ink);
    text-decoration: underline;
}

.btn--danger {
    border-color: var(--danger);
    color: var(--danger);
}

.btn--danger:hover {
    background: var(--danger);
    color: #fff;
}

.btn__hint {
    font-size: 13px;
    font-weight: 600;
    opacity: 0.6;
}

/* Ligne cliquable pleine largeur, façon gros bouton de liste. */
.big-action {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 17px 22px;
    border: 0;
    border-bottom: var(--line);
    background: transparent;
    color: var(--ink);
    font-family: inherit;
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.02em;
    cursor: pointer;
    text-align: left;
}

.big-action--primary {
    background: var(--ink);
    color: var(--paper);
    font-weight: 800;
}

.big-action:hover {
    background: var(--hairline);
}

.big-action--primary:hover {
    background: #000;
}

.big-action__hint {
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
}

.big-action--primary .big-action__hint {
    color: inherit;
    opacity: 0.65;
}

@media (min-width: 900px) {
    .big-action {
        padding: 17px 40px;
    }
}

/* ------------------------------------------------------------ Révision */

.review {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-height: 100dvh;
    background: var(--accent);
    padding: 20px;
    gap: 16px;
}

.review__bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    color: #fff;
    font-size: 13px;
    font-weight: 700;
}

.review__count {
    font-size: 18px;
    font-weight: 800;
}

.review__stage {
    flex: 1;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    perspective: 1600px;
}

/* Le retournement.
   Sans JS : les deux faces sont empilées dans le flux et la réponse est masquée
   par un <details>, exactement comme avant.
   Avec JS : le contrôleur pose .is-enhanced sur .review, les faces se superposent
   et tournent en 3D, et le <details> reste ouvert en permanence. */
.flip {
    width: 100%;
    max-width: 900px;
}

.flip__inner {
    position: relative;
    width: 100%;
}

.flip__summary {
    display: inline-block;
    margin-top: 16px;
    padding: 13px 20px;
    border: var(--line);
    border-radius: 12px;
    background: var(--paper);
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
}

.flip__hint {
    display: none;
}

.flip__face {
    border: var(--line);
    border-radius: 20px;
    padding: 26px;
    background: var(--paper);
    display: flex;
    flex-direction: column;
    gap: 14px;
    overflow: auto;
}

.flip__face--answer {
    background: var(--answer);
    margin-top: 16px;
}

.flip__label {
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0.1em;
    color: var(--muted);
    flex: none;
}

.flip__face--answer .flip__label {
    color: var(--ink);
    opacity: 0.55;
}

.flip__content {
    margin: auto 0;
    font-size: 24px;
    line-height: 1.25;
    font-weight: 800;
    letter-spacing: -0.03em;
    text-wrap: pretty;
}

.flip__face--answer .flip__content {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1.35;
}

.flip__content :first-child {
    margin-top: 0;
}

.flip__content :last-child {
    margin-bottom: 0;
}

/* Avec JS : superposition et rotation. */
.is-enhanced .flip {
    height: 100%;
    cursor: pointer;
}

.is-enhanced .flip__inner {
    height: 100%;
    transform-style: preserve-3d;
    transition: transform 0.55s cubic-bezier(0.3, 0.8, 0.25, 1);
}

.is-enhanced.is-flipped .flip__inner {
    transform: rotateY(180deg);
}

.is-enhanced .flip__face {
    position: absolute;
    inset: 0;
    margin: 0;
    backface-visibility: hidden;
}

.is-enhanced .flip__face--answer {
    transform: rotateY(180deg);
}

.is-enhanced .flip__hint {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--muted);
    text-align: center;
    flex: none;
}

/* Les notes n'apparaissent qu'une fois la réponse vue. */
.is-enhanced .rate {
    display: none;
}

.is-enhanced.is-flipped .rate {
    display: block;
}

.is-enhanced .rate__keys {
    display: block;
}

@media (prefers-reduced-motion: reduce) {
    .is-enhanced .flip__inner {
        transition: none;
    }
}

@media (min-width: 900px) {
    .review {
        padding: 28px 40px 34px;
    }

    .flip__face {
        padding: 44px;
    }

    .flip__content {
        font-size: 44px;
        line-height: 1.05;
        letter-spacing: -0.04em;
    }

    .flip__face--answer .flip__content {
        font-size: 30px;
    }
}

/* Barre de notes 1 à 5. */
.rate {
    flex: none;
    border: 0;
    margin: 0;
    padding: 0;
    min-width: 0;
}

.rate__legend {
    display: flex;
    justify-content: space-between;
    width: 100%;
    font-size: 12px;
    font-weight: 700;
    color: #fff;
    opacity: 0.8;
    padding: 0 2px 8px;
}

.rate__buttons {
    display: flex;
    gap: 8px;
}

.rate__btn {
    flex: 1;
    height: 64px;
    border: var(--line);
    border-radius: 12px;
    background: var(--rate);
    color: var(--rate-ink);
    font-family: inherit;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    cursor: pointer;
}

.rate__btn:hover {
    filter: brightness(1.08);
}

.rate__n {
    font-size: 22px;
    font-weight: 800;
}

.rate__label {
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.03em;
    opacity: 0.8;
    text-transform: uppercase;
}

/* Le rappel des touches n'a de sens que si le clavier est branché, donc avec JS. */
.rate__keys {
    display: none;
    text-align: center;
    font-size: 13px;
    font-weight: 600;
    color: #fff;
    opacity: 0.8;
    padding-top: 10px;
}

@media (min-width: 900px) {
    .rate__btn {
        height: 76px;
        border-radius: 14px;
    }

    .rate__n {
        font-size: 26px;
    }

    .rate__label {
        font-size: 11px;
    }
}

/* --------------------------------------------------------------- Bilan */

.tiles {
    display: flex;
    border-bottom: var(--line);
}

.tile {
    flex: 1;
    padding: 18px 22px;
    border-right: 2px solid var(--hairline);
}

.tile:last-child {
    border-right: 0;
}

.tile__value {
    font-size: 34px;
    font-weight: 800;
    letter-spacing: -0.03em;
}

.tile__label {
    font-size: 12px;
    font-weight: 700;
    color: var(--muted);
    text-transform: uppercase;
}

@media (min-width: 900px) {
    .tile {
        padding: 24px 40px;
    }

    .tile__value {
        font-size: 44px;
    }
}

/* Répartition des notes. */
.dist {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    height: 150px;
    padding: 0 22px 20px;
    margin: 0;
}

.dist__col {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
    height: 100%;
}

.dist__count {
    font-size: 13px;
    font-weight: 800;
}

.dist__bar {
    width: 100%;
    background: var(--rate);
    border: var(--line);
    border-radius: 8px 8px 0 0;
    min-height: 4px;
}

.dist__n {
    font-size: 12px;
    font-weight: 700;
}

@media (min-width: 900px) {
    .dist {
        height: 220px;
        gap: 16px;
        padding: 0 40px 36px;
    }

    .dist__count {
        font-size: 16px;
    }

    .dist__n {
        font-size: 14px;
    }
}

/* Sur grand écran, chiffres à gauche et cartes faibles à droite. */
@media (min-width: 900px) {
    .split {
        display: flex;
        align-items: stretch;
    }

    .split__left {
        width: 60%;
        border-right: var(--line);
        display: flex;
        flex-direction: column;
    }

    .split__right {
        flex: 1;
        min-width: 0;
    }
}

/* -------------------------------------------------------- Contenu carte */

.face > :first-child {
    margin-top: 0;
}

.face > :last-child {
    margin-bottom: 0;
}

.face figure {
    margin: 12px 0 0;
}

.face img {
    border: var(--line);
    border-radius: 12px;
    display: block;
}

.face ul,
.face ol {
    padding-left: 1.2em;
    margin: 8px 0;
}

.face code {
    font-family: var(--mono);
    font-size: 0.9em;
    background: var(--hairline);
    padding: 1px 5px;
    border-radius: 5px;
}

.face pre {
    background: var(--ink);
    color: var(--paper);
    padding: 14px;
    border-radius: 12px;
    overflow-x: auto;
}

.face pre code {
    background: transparent;
    color: inherit;
    padding: 0;
}

/* ----------------------------------------------------------- Formulaires */

.form {
    padding: 20px 22px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

@media (min-width: 900px) {
    .form {
        padding: 28px 40px;
        max-width: 760px;
    }
}

.form fieldset {
    border: 0;
    margin: 0;
    padding: 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.form legend,
.form > div > label,
.form fieldset > div > label {
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    padding: 0;
}

.form input[type='text'],
.form input[type='email'],
.form input[type='password'],
.form input[type='file'],
.form textarea,
.form select {
    width: 100%;
    font-family: inherit;
    font-size: 16px;
    font-weight: 500;
    color: var(--ink);
    background: #fff;
    border: var(--line);
    border-radius: 12px;
    padding: 13px 14px;
}

.form textarea {
    line-height: 1.45;
    resize: vertical;
}

.form .help,
.form small {
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
}

.form ul {
    list-style: none;
    margin: 6px 0 0;
    padding: 0;
    color: var(--danger);
    font-size: 13px;
    font-weight: 600;
}

/* Case à cocher sur une ligne, à l'inverse des autres champs empilés. */
.check {
    display: flex;
    align-items: center;
    gap: 9px;
}

.check input {
    width: 18px;
    height: 18px;
    accent-color: var(--ink);
    flex: none;
}

.form .check label {
    font-size: 14px;
    font-weight: 600;
    letter-spacing: normal;
    text-transform: none;
}

/* Renvoi vers l'autre page de compte, sous le bouton. */
.form__aside {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    color: var(--muted);
}

.form__aside a {
    font-weight: 700;
    color: var(--ink);
    text-decoration: underline;
}

/* Choix de couleur : les radios deviennent des pastilles. */
.swatches {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.swatches input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.swatch {
    display: block;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    border: var(--line);
    background: var(--swatch);
    cursor: pointer;
    text-indent: -9999px;
    overflow: hidden;
}

.swatches input:checked + .swatch {
    box-shadow: 0 0 0 3px var(--paper) inset, 0 0 0 5px var(--ink);
}

.swatches input:focus-visible + .swatch {
    outline: 3px solid var(--accent);
    outline-offset: 2px;
}

/* Vignettes d'images déjà attachées à une carte. */
.thumbs {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    list-style: none;
    margin: 0;
    padding: 0;
}

.thumb {
    display: flex;
    flex-direction: column;
    gap: 6px;
    align-items: center;
}

.thumb img {
    width: 110px;
    height: 110px;
    object-fit: cover;
    border: var(--line);
    border-radius: 10px;
}

/* Prévisualisation d'un import : les cartes reconnues, avant enregistrement.
   Pas de marge latérale, le .form qui l'entoure la donne déjà. */

.preview {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.preview > li {
    border: var(--line);
    border-radius: 12px;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.preview__label {
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 4px;
}

/* ------------------------------------------------------------- Divers */

.flashes {
    margin: 0;
    padding: 0;
    list-style: none;
}

.flash {
    margin: 0;
    padding: 14px 22px;
    border-bottom: var(--line);
    font-size: 15px;
    font-weight: 700;
    background: var(--done);
}

.flash--error {
    background: var(--danger);
    color: #fff;
}

@media (min-width: 900px) {
    .flash {
        padding: 14px 40px;
    }
}

.empty {
    padding: 40px 22px;
    color: var(--muted);
    font-size: 16px;
    font-weight: 600;
}

@media (min-width: 900px) {
    .empty {
        padding: 48px 40px;
    }
}

.crumbs {
    font-size: 13px;
    font-weight: 700;
    color: var(--muted);
    padding: 18px 22px 0;
}

.crumbs a:hover {
    color: var(--ink);
}

@media (min-width: 900px) {
    .crumbs {
        padding: 22px 40px 0;
    }
}

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