/* ─── FONT (self-hosted, OFL) ────────────────────────────── */
@font-face { font-family: "Syne"; src: url("../fonts/syne-latin-700-normal.woff2") format("woff2"); font-weight: 700; font-display: swap; }
@font-face { font-family: "DM Mono"; src: url("../fonts/dm-mono-latin-400-normal.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "DM Mono"; src: url("../fonts/dm-mono-latin-300-normal.woff2") format("woff2"); font-weight: 300; font-display: swap; }

/* ─── TOKEN ──────────────────────────────────────────────── */
:root {
    --bg: #0a0a0a;
    --bg-raise: #121214;
    --nav-bg: rgba(10, 10, 10, 0.88);
    --line: rgba(255, 255, 255, 0.08);
    --line-hi: rgba(255, 255, 255, 0.16);
    --text: #efefef;
    --mid: #8d8d96;
    --dim: #5c5c66;

    /* accento del progetto: lavanda */
    --accent: #b49cff;
    --accent-ink: #0a0a0a;
    --accent-lo: rgba(180, 156, 255, 0.1);
    --accent-md: rgba(180, 156, 255, 0.22);
    --accent-hi: rgba(180, 156, 255, 0.36);

    --warn: #ff5c8a;
    --ok: #4ade80;

    --syne: "Syne", ui-sans-serif, system-ui, sans-serif;
    --mono: "DM Mono", ui-monospace, Menlo, Consolas, monospace;
    --ease: cubic-bezier(0.22, 1, 0.36, 1);
    --spring: cubic-bezier(0.34, 1.56, 0.64, 1);

    --pad: 1.5rem;
    --nav-h: 56px;
    color-scheme: dark;
}
[data-theme="light"] {
    --bg: #fafafa;
    --bg-raise: #f1f1f4;
    --nav-bg: rgba(250, 250, 250, 0.9);
    --line: rgba(0, 0, 0, 0.08);
    --line-hi: rgba(0, 0, 0, 0.16);
    --text: #17171a;
    --mid: #55555f;
    --dim: #8a8a94;

    --accent: #6d4fd6;
    --accent-ink: #ffffff;
    --accent-lo: rgba(109, 79, 214, 0.07);
    --accent-md: rgba(109, 79, 214, 0.15);
    --accent-hi: rgba(109, 79, 214, 0.28);

    --warn: #e0336a;
    --ok: #1f8a4c;
    color-scheme: light;
}
@media (min-width: 700px) { :root { --pad: 2rem; } }
@media (min-width: 960px) { :root { --pad: 3rem; } }

/* ─── RESET ──────────────────────────────────────────────── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    min-height: 100svh;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    color: var(--text);
    font-family: var(--mono);
    font-size: 15px;
    line-height: 1.7;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
}
a { color: inherit; text-decoration: none; }
button, input { font: inherit; color: inherit; background: none; border: 0; }
button { cursor: pointer; }
ol, ul { list-style: none; }
em { font-style: normal; color: var(--accent); }
svg { display: block; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 2px; }
::selection { background: var(--accent); color: var(--accent-ink); }
main:focus { outline: none; }

.sr-only {
    position: absolute; width: 1px; height: 1px; overflow: hidden;
    clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}
.skip {
    position: fixed; top: 0.5rem; left: 0.5rem; z-index: 300;
    padding: 0.6rem 1rem; border-radius: 999px;
    background: var(--accent); color: var(--accent-ink); font-size: 0.8rem;
    transform: translateY(-200%); transition: transform 0.25s var(--ease);
}
.skip:focus { transform: none; }

/* ─── NAV ────────────────────────────────────────────────── */
.nav {
    position: fixed;
    inset: 0 0 auto;
    z-index: 200;
    height: calc(var(--nav-h) + env(safe-area-inset-top));
    padding-top: env(safe-area-inset-top);
    padding-left: max(var(--pad), env(safe-area-inset-left));
    padding-right: max(var(--pad), env(safe-area-inset-right));
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    background: var(--nav-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--line);
}
.nav__logo {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    min-height: 44px;
    font-family: var(--syne);
    font-weight: 700;
    font-size: 1.05rem;
    letter-spacing: 0.01em;
}
/* stesso disegno di icons/favicon.svg, con i token del tema */
/* prompt da terminale: lo stesso disegno di icons/favicon.svg, con i token del tema */
.nav__mark { width: 22px; height: 22px; stroke-width: 2.4; color: var(--text); }
.nav__cursor { fill: var(--accent); stroke: none; animation: cursor 1.1s steps(1) 4 both; }
.nav__logo:hover .nav__cursor { animation: cursor 1.1s steps(1) infinite; }
@keyframes cursor { 50% { opacity: 0; } }

.nav__links { display: flex; align-items: center; gap: 1.1rem; }
.nav__btn {
    position: relative;
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    font-size: 0.72rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--mid);
    transition: color 0.25s;
}
.nav__btn:hover, .nav__btn.current { color: var(--text); }
.nav__text::after {
    content: "";
    position: absolute;
    left: 0; right: 0; bottom: 10px;
    height: 1px;
    background: var(--accent);
    transform: scaleX(0);
    transform-origin: left;
    transition: transform 0.35s var(--ease);
}
.nav__text.current::after, .nav__text:hover::after { transform: scaleX(1); }
.nav__icon { justify-content: center; width: 44px; margin-right: -12px; }
.nav__icon svg { width: 17px; height: 17px; }
.icon-sun, [data-theme="light"] .icon-moon { display: none; }
[data-theme="light"] .icon-sun { display: block; }
@media (max-width: 360px) { .nav__links { gap: 0.7rem; } }

/* barra di lettura: 2px sotto la nav, solo nella vista poesia */
.progress { position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; pointer-events: none; }
.progress i {
    display: block; height: 100%;
    background: var(--accent);
    transform: scaleX(var(--p, 0));
    transform-origin: left;
}

/* ─── LAYOUT ─────────────────────────────────────────────── */
main {
    flex: 1;
    width: 100%;
    max-width: 1100px;
    margin: 0 auto;
    padding: calc(var(--nav-h) + env(safe-area-inset-top) + 3.5rem) var(--pad) 5rem;
}
@media (min-width: 700px) { main { padding-top: calc(var(--nav-h) + 6rem); padding-bottom: 7rem; } }

.view > * { animation: up 0.7s var(--ease) both; }
.view > *:nth-child(2) { animation-delay: 80ms; }
.view > *:nth-child(3) { animation-delay: 160ms; }
.view > *:nth-child(4) { animation-delay: 240ms; }
@keyframes up { from { opacity: 0; transform: translateY(14px); } }

/* ─── TIPOGRAFIA ─────────────────────────────────────────── */
.tag {
    margin-bottom: 1.4rem;
    font-size: 0.68rem;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: var(--accent);
}
.label {
    font-size: 0.68rem;
    font-weight: 400;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--mid);
}
.display {
    font-family: var(--syne);
    font-weight: 700;
    font-size: clamp(3.4rem, 18vw, 7.5rem);
    line-height: 0.92;
    letter-spacing: -0.045em;
}
.display span { display: block; }
.lede {
    max-width: 42ch;
    margin-top: 1.6rem;
    font-size: 1rem;
    line-height: 1.7;
    color: var(--mid);
}
.actions { display: flex; flex-wrap: wrap; gap: 0.75rem; margin-top: 2.2rem; }

/* ─── BOTTONI ────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 48px;
    padding: 0 1.6rem;
    border-radius: 999px;
    background: var(--accent);
    color: var(--accent-ink);
    border: 1px solid transparent;
    font-size: 0.85rem;
    letter-spacing: 0.04em;
    transition: transform 0.25s var(--ease), background 0.2s, border-color 0.2s, color 0.2s;
}
.btn:hover { transform: translateY(-2px); }
.btn:active { transform: scale(0.97); }
.btn--ghost { background: transparent; color: var(--text); border-color: var(--line-hi); }
.btn--ghost:hover { color: var(--accent); border-color: var(--accent); }

/* ─── INDICE ─────────────────────────────────────────────── */
.index { margin-top: 5rem; }
@media (min-width: 700px) { .index { margin-top: 7rem; } }
.index__head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem 2rem;
    margin-bottom: 1rem;
}
.search {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex: 1 1 260px;
    max-width: 340px;
    min-height: 44px;
    border-bottom: 1px solid var(--line-hi);
    color: var(--mid);
    transition: border-color 0.25s, color 0.25s;
}
.search:focus-within { border-color: var(--accent); color: var(--accent); }
.search svg { width: 16px; height: 16px; flex: none; }
.search input { flex: 1; min-width: 0; height: 44px; font-size: 0.85rem; color: var(--text); outline: none; }
.search input::placeholder { color: var(--mid); }
.search input::-webkit-search-cancel-button { filter: grayscale(1); }

/* righe */
.rows { border-top: 1px solid var(--line); }
.row {
    position: relative;
    display: grid;
    grid-template-columns: 2.2rem 1fr auto;
    align-items: center;
    gap: 0 1rem;
    min-height: 58px;
    padding: 1rem 0;
    border-bottom: 1px solid var(--line);
    transition: padding-left 0.45s var(--ease);
    animation: up 0.6s var(--ease) both;
    animation-delay: calc(var(--k, 0) * 45ms + 80ms);
}
.row::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: -1;
    background: var(--accent-lo);
    transform: scaleX(0);
    transform-origin: left;
    transition: transform 0.45s var(--ease);
}
.row__idx { font-size: 0.68rem; color: var(--dim); font-variant-numeric: tabular-nums; }
.row__body { min-width: 0; }
.row__name {
    display: block;
    width: fit-content; /* il box segue il testo: il morph scala le parole, non la riga */
    font-family: var(--syne);
    font-weight: 700;
    font-size: 1.1rem;
    line-height: 1.3;
    letter-spacing: -0.01em;
    transition: color 0.25s;
}
.row__first {
    display: block;
    margin-top: 0.15rem;
    font-size: 0.78rem;
    color: var(--mid);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.row__meta { display: none; font-size: 0.72rem; color: var(--mid); font-variant-numeric: tabular-nums; }
.row__arrow { color: var(--accent); transition: transform 0.3s var(--ease); }
.row--prev .row__arrow { order: -1; }
@media (hover: hover) {
    .row:hover { padding-left: 0.8rem; }
    .row:hover::before { transform: scaleX(1); }
    .row:hover .row__name { color: var(--accent); }
    .row:hover .row__arrow { transform: translateX(4px); }
    .row--prev:hover .row__arrow { transform: translateX(-4px); }
}
@media (min-width: 700px) {
    .row { grid-template-columns: 3rem 1fr auto auto; gap: 0 1.5rem; }
    .row__meta { display: block; }
    .row__name { font-size: 1.15rem; }
}
.index .rows { isolation: isolate; }

/* ordine dell'indice */
.order { display: flex; gap: 0.4rem; margin-right: auto; }
.order button {
    min-height: 32px;
    padding: 0 0.85rem;
    border: 1px solid var(--line-hi);
    border-radius: 999px;
    font-size: 0.62rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--mid);
    transition: color 0.2s, border-color 0.2s, background 0.2s;
}
/* area di tocco da 44px senza ingrandire la pillola */
.order button { position: relative; }
.order button::after { content: ""; position: absolute; inset: -6px -2px; }
.order button:hover { color: var(--text); }
.order button[aria-pressed="true"] { color: var(--accent); border-color: var(--accent-hi); background: var(--accent-lo); }
.index__head .label { margin-right: 0.6rem; }

.empty { padding: 2rem 0; color: var(--mid); font-size: 0.9rem; }

/* ─── LETTURA ────────────────────────────────────────────── */
.view--poem { max-width: 720px; }
.poem__title {
    width: fit-content;
    max-width: 100%;
    font-family: var(--syne);
    font-weight: 700;
    font-size: clamp(2.4rem, 10vw, 4.4rem);
    line-height: 0.98;
    letter-spacing: -0.03em;
    overflow-wrap: break-word;
    hyphens: auto;
}
.poem__head .label { margin-top: 1.4rem; }
.poem__text {
    margin-top: 3.5rem;
    max-width: 46ch;
    font-size: 1rem;
    line-height: 2;
    color: var(--text);
}
@media (min-width: 700px) { .poem__text { margin-top: 4.5rem; font-size: 1.05rem; } }
.strofa { overflow-wrap: break-word; }
/* un verso troppo lungo va a capo rientrato, come nei libri */
.verso { display: block; white-space: pre-wrap; padding-left: 1.5em; text-indent: -1.5em; }
.strofa + .strofa { margin-top: 2em; }
.poem__nav { margin-top: 5rem; isolation: isolate; }
.poem__nav .row { grid-template-columns: 1fr auto; animation: none; }
.poem__nav .row--prev { grid-template-columns: auto 1fr; }
.poem__nav .row__meta { display: block; grid-column: 1 / -1; order: -2; margin-bottom: 0.1rem; }
.poem__nav .row__body { text-align: inherit; }
.poem__nav .row--next { text-align: right; }

.view--missing .poem__title { margin-top: 0; }

/* ─── TRANSIZIONI DI PAGINA ──────────────────────────────── */
/* durante il morph le viste non rifanno l'entrata dal basso */
.no-enter > *, .no-enter .row { animation: none; }
.vt-page::view-transition-group(titolo) { animation-duration: 0.6s; animation-timing-function: var(--ease); }
.vt-page::view-transition-old(titolo), .vt-page::view-transition-new(titolo) {
    height: 100%;
    object-fit: contain;
    object-position: left top;
    animation-duration: 0.6s;
    animation-timing-function: var(--ease);
}
.vt-page::view-transition-old(root) { animation: fade-out 0.25s var(--ease) both; }
.vt-page::view-transition-new(root) { animation: fade-in 0.45s var(--ease) 0.12s both; }
@keyframes fade-in { from { opacity: 0; } }
@keyframes fade-out { to { opacity: 0; } }
/* cambio tema: niente dissolvenza, il nuovo tema entra con il cerchio (theme.js) */
.vt-theme::view-transition-old(root), .vt-theme::view-transition-new(root) { animation: none; mix-blend-mode: normal; }

/* ─── FOOTER ─────────────────────────────────────────────── */
.footer {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    padding: 1.6rem var(--pad) calc(1.6rem + env(safe-area-inset-bottom));
    border-top: 1px solid var(--line);
    font-size: 0.75rem;
    color: var(--dim);
}
.footer a { display: inline-flex; align-items: center; min-height: 32px; align-self: flex-start; color: var(--mid); transition: color 0.2s; }
.footer a:hover { color: var(--text); }
@media (min-width: 700px) {
    .footer { flex-direction: row; align-items: center; justify-content: space-between; }
}

/* ─── MOVIMENTO RIDOTTO ──────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-delay: 0ms !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* firma e date, una per riga */
.poem__meta { display: flex; flex-direction: column; gap: 0.15rem; line-height: 1.6; }
.poem__meta span { color: var(--text); }
