/* ---------- Polices ---------- */
/* Comme sur lomitko.com : LOMITKO7 (police maison) pour les titres et l'interface,
   Literata (licence OFL, voir fonts/Literata-OFL.txt) pour les textes. Deux polices variables. */
@font-face {
    font-family: "LOMITKO7";
    src: url(../fonts/LOMITKO7-VF.woff2) format("woff2");
    font-weight: 300 700;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: "Literata";
    src: url(../fonts/literata-latin-opsz-normal.woff2) format("woff2");
    font-weight: 200 900;
    font-style: normal;
    font-display: swap;
}

/* ---------- Tokens ---------- */
/* Noir, blanc et gris ; mêmes valeurs que lomitko.com (encre, fond, discret, filet).
   Seule couleur : le jaune lomitko, réservé au jour courant. */
:root {
    color-scheme: light;
    --color-bg: #ffffff;
    --color-ink: #141414;
    --color-muted: #5f5f5f;
    --color-rule: #d0d0d0;
    /* Cercles : plein, vide, futur. Jamais de noir ni de blanc purs : gris foncé en clair, gris clair en sombre. */
    --color-dot: #3d3d3d;
    --color-dot-empty: #8c8c8c;
    --color-dot-future: #dedede;
    --color-today: #fdb42b;

    /* Titres et interface (onglets, boutons, libellés, repères de la grille). */
    --font-title: "LOMITKO7", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    /* Textes (paragraphes, messages, saisie). */
    --font-text: "Literata", Georgia, serif;
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 1rem;
    --space-4: 1.5rem;

    --page-max: 30rem;
    --tab-bar-height: 3.75rem;
    --dot-gap: 4px;
    /* Le cercle tient à la fois en largeur (12 colonnes + marge) et en hauteur (31 lignes + en-têtes). */
    --dot: clamp(
        13px,
        min((min(100vw, var(--page-max)) - 4.5rem) / 12 - var(--dot-gap), (100dvh - 12.5rem) / 32 - var(--dot-gap)),
        24px
    );
}

/* Sombre : suit le système, sauf si data-theme force un mode (réglage utilisateur à venir). */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;
        --color-bg: #141414;
        --color-ink: #ffffff;
        --color-muted: #a6a6a6;
        --color-rule: #515151;
        --color-dot: #d2d2d2;
        --color-dot-empty: #6a6a6a;
        --color-dot-future: #363636;
    }
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --color-bg: #141414;
    --color-ink: #ffffff;
    --color-muted: #a6a6a6;
    --color-rule: #515151;
    --color-dot: #d2d2d2;
    --color-dot-empty: #6a6a6a;
    --color-dot-future: #363636;
}

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

body {
    margin: 0;
    background: var(--color-bg);
    color: var(--color-ink);
    font-family: var(--font-text);
    font-optical-sizing: auto;
    line-height: 1.4;
    font-kerning: normal;
    -webkit-font-smoothing: antialiased;
    -webkit-text-size-adjust: 100%;
}

a {
    color: inherit;
}

.page {
    max-width: var(--page-max);
    margin: 0 auto;
    padding: max(var(--space-3), env(safe-area-inset-top)) max(var(--space-3), env(safe-area-inset-right))
        calc(var(--tab-bar-height) + var(--space-4) + env(safe-area-inset-bottom))
        max(var(--space-3), env(safe-area-inset-left));
}

/* Titres et éléments d'interface : LOMITKO7. Tout le reste hérite de Literata. */
h1,
h2,
.app-name,
.year-nav,
.grid-head,
.grid-day-number,
.tab,
.button,
.label {
    font-family: var(--font-title);
}

/* ---------- Barre de navigation fixe en bas ---------- */
.tab-bar {
    position: fixed;
    inset: auto 0 0;
    z-index: 10;
    border-top: 1px solid var(--color-rule);
    background: var(--color-bg);
    padding-bottom: env(safe-area-inset-bottom);
}

.tab-bar-inner {
    display: flex;
    max-width: var(--page-max);
    height: var(--tab-bar-height);
    margin: 0 auto;
}

.tab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
    padding: 0;
    border: 0;
    background: none;
    color: var(--color-muted);
    font: inherit;
    font-family: var(--font-title);
    font-size: 0.6875rem;
    font-weight: 500;
    letter-spacing: 0.02em;
    text-decoration: none;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

/* Sans cette règle, display: flex l'emporterait sur l'attribut hidden. */
.tab[hidden] {
    display: none;
}

.tab[aria-current="page"],
.tab:hover {
    color: var(--color-ink);
}

.tab:focus-visible {
    outline: 2px solid var(--color-ink);
    outline-offset: -4px;
}

.tab-icon {
    width: 1.5rem;
    height: 1.5rem;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.5;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.tab-icon-fill {
    fill: currentColor;
    stroke: none;
}

/* ---------- Barre d'app ---------- */
.app-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    min-height: 2.25rem;
    margin-bottom: var(--space-3);
}

.app-name {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    text-decoration: none;
}

/* ---------- Habitude (titre + grille) ---------- */
/* Une habitude par écran, défilement horizontal aimanté. Le conteneur déborde jusqu'aux
   bords de la page pour que les grilles glissent sur toute la largeur. */
.habits {
    display: flex;
    margin-inline: calc(-1 * var(--space-3));
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
}

.habits::-webkit-scrollbar {
    display: none;
}

.habit {
    flex: 0 0 100%;
    min-width: 0;
    padding: 0 var(--space-3) var(--space-3);
    scroll-snap-align: start;
    scroll-snap-stop: always;
    /* Atteinte par son ancre (#habitude-N), la grille ne doit défiler qu'à l'horizontale. */
    scroll-margin-top: 100vh;
}

.habit-title {
    margin: 0 0 var(--space-3);
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    overflow-wrap: anywhere;
}

.year-nav {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    font-variant-numeric: tabular-nums;
}

.year-nav-current {
    font-weight: 600;
}

.year-nav-link {
    display: grid;
    place-items: center;
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 50%;
    font-size: 1.5rem;
    line-height: 1;
    text-decoration: none;
}

.year-nav-link.is-disabled {
    color: var(--color-rule);
}

/* ---------- Grille annuelle ---------- */
.grid {
    display: grid;
    grid-template-columns: 1.5rem repeat(12, 1fr);
}

.grid-column {
    display: grid;
    grid-auto-rows: var(--dot);
    row-gap: var(--dot-gap);
    justify-items: center;
    align-content: start;
}

.grid-head {
    align-self: center;
    color: var(--color-muted);
    font-size: 0.75rem;
    font-weight: 600;
    text-decoration: none;
}

.grid-day-number {
    justify-self: start;
    align-self: center;
    color: var(--color-muted);
    font-size: 0.625rem;
    font-variant-numeric: tabular-nums;
    line-height: 1;
}

.dot {
    width: var(--dot);
    height: var(--dot);
    padding: 0;
    border: 1.5px solid var(--color-dot-empty);
    border-radius: 50%;
    background: transparent;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    appearance: none;
}

.dot.is-done {
    border-color: var(--color-dot);
    background: var(--color-dot);
}

.dot.is-future {
    border-color: var(--color-dot-future);
    cursor: default;
}

/* Aujourd'hui : le cercle lui-même est jaune (contour seul, ou plein s'il est coché). */
.dot.is-today {
    border-color: var(--color-today);
}

.dot.is-today.is-done {
    background: var(--color-today);
}

.dot:focus-visible {
    outline: 2px dashed var(--color-ink);
    outline-offset: 2px;
}

/* ---------- Erreurs ---------- */
.error-message {
    color: var(--color-muted);
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

/* ---------- Formulaires et boutons ---------- */
.page-title {
    margin: 0 0 var(--space-3);
    font-size: 1.5rem;
    font-weight: 700;
}

.section-title {
    margin: calc(2 * var(--space-4)) 0 var(--space-2);
    color: var(--color-muted);
    font-size: 0.875rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.muted {
    color: var(--color-muted);
}

.field-row {
    display: flex;
    gap: var(--space-2);
}

.field {
    flex: 1;
    min-width: 0;
    height: 2.75rem;
    padding: 0 var(--space-3);
    border: 1.5px solid var(--color-rule);
    border-radius: 0.5rem;
    background: var(--color-bg);
    color: var(--color-ink);
    font: inherit;
    /* 16px minimum : en dessous, iOS zoome sur le champ au focus. */
    font-size: 1rem;
}

.field:focus-visible {
    border-color: var(--color-ink);
    outline: none;
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 2.75rem;
    padding: 0 var(--space-3);
    border: 1.5px solid var(--color-ink);
    border-radius: 0.5rem;
    background: var(--color-ink);
    color: var(--color-bg);
    font: inherit;
    font-family: var(--font-title);
    font-size: 0.9375rem;
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
}

.button.is-quiet {
    border-color: var(--color-rule);
    background: transparent;
    color: var(--color-ink);
}

.button.is-square {
    width: 2.75rem;
    padding: 0;
}

.button:disabled {
    color: var(--color-rule);
    cursor: default;
}

.button:focus-visible {
    outline: 2px solid var(--color-ink);
    outline-offset: 2px;
}

/* Formulaire en colonne (comptes) */
.form {
    display: grid;
    gap: var(--space-2);
    margin-bottom: var(--space-3);
}

.form .field {
    width: 100%;
}

.form .button {
    justify-self: start;
    margin-top: var(--space-2);
}

.label {
    margin-top: var(--space-2);
    font-size: 0.9375rem;
    font-weight: 600;
}

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

.checkbox {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin-top: var(--space-2);
    font-size: 0.9375rem;
}

.checkbox input {
    width: 1.125rem;
    height: 1.125rem;
    margin: 0;
    accent-color: var(--color-ink);
}

select.field {
    appearance: none;
}

.form-links {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2) var(--space-4);
    margin: var(--space-4) 0 0;
    font-size: 0.9375rem;
}

.message {
    margin: 0 0 var(--space-3);
    padding: var(--space-2) var(--space-3);
    border: 1.5px solid var(--color-rule);
    border-radius: 0.5rem;
    font-size: 0.9375rem;
}

.message.is-error {
    border-color: var(--color-ink);
}

/* ---------- Liste des habitudes ---------- */
.habit-list {
    margin: var(--space-4) 0 0;
    padding: 0;
    list-style: none;
}

.habit-item {
    display: grid;
    gap: var(--space-2);
    padding: var(--space-3) 0;
    border-top: 1px solid var(--color-rule);
}

.habit-item.is-archived {
    grid-template-columns: 1fr auto;
    align-items: center;
    color: var(--color-muted);
}

.habit-item-title {
    overflow-wrap: anywhere;
}

.habit-actions {
    display: flex;
    gap: var(--space-2);
}

.habit-actions-end {
    margin-left: auto;
}

.empty {
    padding: calc(2 * var(--space-4)) 0;
    color: var(--color-muted);
    text-align: center;
}

/* ---------- Message temporaire ---------- */
.toast {
    position: fixed;
    left: 50%;
    bottom: calc(var(--tab-bar-height) + var(--space-3) + env(safe-area-inset-bottom));
    z-index: 20;
    transform: translateX(-50%);
    width: max-content;
    max-width: calc(100vw - 2 * var(--space-3));
    margin: 0;
    padding: var(--space-2) var(--space-3);
    border-radius: 0.5rem;
    background: var(--color-ink);
    color: var(--color-bg);
    font-size: 0.9375rem;
}
