/* ─────────────────────────────────────────────
   nettare — stile
   ───────────────────────────────────────────── */

:root {
  --bg: #ffffff;
  --fg: #0a0a0a;
  --muted: #8a8a8a;
  --red: #ff2d20;

  --font: Menlo, "DejaVu Sans Mono", Monaco, Consolas, ui-monospace, monospace;

  --margin: 40px;
  --gutter: 24px;
  --cols: 12;

  --ease: cubic-bezier(.22, 1, .36, 1);       /* out-expo morbido */
  --ease-io: cubic-bezier(.65, 0, .35, 1);
  --dur: .9s;
}

@media (max-width: 760px) {
  :root { --margin: 20px; --gutter: 16px; --cols: 6; }
}

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

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  font-size: 13px;
  line-height: 1.7;
  letter-spacing: -.01em;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

::selection { background: var(--red); color: #fff; }

a, button {
  color: inherit;
  font: inherit;
  text-decoration: none;
  background: none;
  border: 0;
  cursor: pointer;
}

ul { list-style: none; }

/* ── cursore + inchiostro ───────────────────── */

#ink {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;              /* sempre sotto ai testi */
  pointer-events: none;
  transition: opacity .6s var(--ease-io);
}
#ink.is-fading { opacity: 0; }

#cursor {
  position: fixed;
  left: 0; top: 0;
  width: 12px; height: 12px;
  margin: -6px 0 0 -6px;
  border-radius: 50%;
  background: var(--red);
  border: 1.5px solid var(--red);
  pointer-events: none;
  z-index: 100;
  opacity: 0;
  transition:
    width .45s var(--ease), height .45s var(--ease), margin .45s var(--ease),
    background-color .3s var(--ease), opacity .3s var(--ease);
  will-change: transform;
}
#cursor.is-visible { opacity: 1; }
#cursor.is-hover {
  width: 40px; height: 40px;
  margin: -20px 0 0 -20px;
  background: transparent;
}
#cursor.is-down { width: 8px; height: 8px; margin: -4px 0 0 -4px; }

@media (hover: hover) and (pointer: fine) {
  html, a, button { cursor: none; }
}
@media (hover: none), (pointer: coarse) {
  #cursor { display: none; }
}

/* ── header pagine interne ─────────────────── */

.bar {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 10;
  display: flex;
  justify-content: space-between;
  padding: calc(var(--margin) - 8px) var(--margin);
  padding-top: max(calc(var(--margin) - 8px), env(safe-area-inset-top));
  pointer-events: none;
}
.bar::before {
  content: "";
  position: absolute;
  inset: 0 0 -24px 0;
  z-index: -1;
  background: linear-gradient(var(--bg) 60%, rgba(255,255,255,0));
  opacity: 0;
  transition: opacity .7s var(--ease);
}
body:not([data-route="home"]) .bar::before { opacity: 1; }
.bar a {
  pointer-events: auto;
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity .7s var(--ease), transform .7s var(--ease);
}
body:not([data-route="home"]) .bar a {
  opacity: 1;
  transform: none;
  transition-delay: .25s;
}
.bar__close { color: var(--muted); }
.bar a:hover { color: var(--fg); }

/* ── viste ─────────────────────────────────── */

main { position: relative; z-index: 1; height: 100%; }

.view {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  visibility: hidden;
  opacity: 0;
  filter: blur(6px);
  transform: translateY(10px) scale(.995);
  transition:
    opacity .6s var(--ease-io),
    filter .6s var(--ease-io),
    transform .8s var(--ease),
    visibility 0s linear .8s;
}
.view.is-active {
  visibility: visible;
  opacity: 1;
  filter: none;
  transform: none;
  transition-delay: .18s, .18s, .18s, 0s;
}
.view.is-leaving { transform: translateY(-10px) scale(.995); }

/* reveal a cascata dentro la vista */
.r {
  opacity: 0;
  transform: translateY(14px);
  transition: opacity .9s var(--ease), transform 1.1s var(--ease);
}
.view.is-active .r {
  opacity: 1;
  transform: none;
  transition-delay: calc(.3s + var(--i, 0) * .08s);
}

/* ── griglia ───────────────────────────────── */

.grid {
  display: grid;
  grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  column-gap: var(--gutter);
  row-gap: 48px;
  padding: calc(var(--margin) * 3.5) var(--margin) calc(var(--margin) * 2.5);
  min-height: 100%;
  align-content: start;
}

.label {
  grid-column: 1 / -1;
  font-size: 11px;
  letter-spacing: .04em;
  color: var(--muted);
}
.label--muted { color: var(--muted); }

/* ── home ──────────────────────────────────── */

.home {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
}

.home__word {
  font-size: 15px;
  letter-spacing: .02em;
  padding: 12px 18px;
  transform: translateY(0);
  transition: transform 1s var(--ease);
}
.home.is-open .home__word { transform: translateY(-58px); }

.split .ch {
  display: inline-block;
  opacity: 0;
  transform: translateY(.6em);
  filter: blur(4px);
  animation: chIn 1.1s var(--ease) forwards;
  animation-delay: calc(.15s + var(--c) * .055s);
}
@keyframes chIn { to { opacity: 1; transform: none; filter: none; } }

.menu {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -18px);
  pointer-events: none;
}
.home.is-open .menu { pointer-events: auto; }

.menu ul { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.menu li { overflow: hidden; }
.menu a {
  display: block;
  padding: 3px 10px;
  color: var(--muted);
  transition: color .3s var(--ease);
}
.menu a span {
  display: block;
  transform: translateY(110%);
  transition: transform .7s var(--ease);
}
.menu li:nth-child(1) a span { transition-delay: .00s; }
.menu li:nth-child(2) a span { transition-delay: .04s; }
.menu li:nth-child(3) a span { transition-delay: .08s; }
.home.is-open .menu li:nth-child(1) a span { transition-delay: .18s; }
.home.is-open .menu li:nth-child(2) a span { transition-delay: .25s; }
.home.is-open .menu li:nth-child(3) a span { transition-delay: .32s; }
.home.is-open .menu a span { transform: none; }
.menu a:hover, .menu a:focus-visible { color: var(--fg); }

/* ── bio ───────────────────────────────────── */

.col p + p { margin-top: 1.7em; }
.col p {
  text-align: justify;
  text-justify: inter-word;
  hyphens: auto;
  -webkit-hyphens: auto;
}
.col--en { grid-column: 1 / span 5; }
.col--it { grid-column: 7 / span 5; }

.col a { position: relative; }
.col a {
  color: var(--fg);
  background-image: linear-gradient(var(--red), var(--red));
  background-size: 0% 1px;
  background-position: 0 100%;
  background-repeat: no-repeat;
  transition: background-size .6s var(--ease), color .3s;
  border-bottom: 1px solid rgba(10,10,10,.18);
}
.col a:hover { background-size: 100% 1px; }

/* ── mostra ────────────────────────────────── */

.center {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  text-align: center;
}
.title { font-size: 15px; font-weight: 400; letter-spacing: .02em; }

/* ── portfolio ─────────────────────────────── */

.links {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  margin-top: 14px;
}
.links a {
  display: block;
  padding: 3px 10px;
  color: var(--muted);
  transition: color .3s var(--ease);
}
.links a:hover, .links a:focus-visible { color: var(--fg); }

/* ── libro sfogliabile ─────────────────────── */

.bookpage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 40px;
  padding: calc(var(--margin) * 2.5) var(--margin) calc(var(--margin) * 3);
}

.flip { display: flex; flex-direction: column; align-items: center; gap: 28px; }

.book {
  position: relative;
  height: min(74vh, calc((100vw - 2 * var(--margin)) / 1.56));
  aspect-ratio: 1.56;
  user-select: none;
  -webkit-user-select: none;
  touch-action: pan-y;
}
.book.is-single {
  height: min(64vh, calc((100vw - 2 * var(--margin)) / .78));
  aspect-ratio: .78;
}

.book__stage {
  position: absolute;
  inset: 0;
  perspective: 2600px;
  transform-style: preserve-3d;
  transition: transform 1s var(--ease);
}
.book.is-cover .book__stage { transform: translateX(-25%); }
.book.is-end .book__stage { transform: translateX(25%); }

.pg, .leaf__face {
  position: absolute;
  top: 0;
  height: 100%;
  background: #fff;
  overflow: hidden;
}
.pg { width: 50%; }

/* un'unica ombra per tutto il libro: si allarga e si stringe con morbidezza
   (copertina → libro aperto → retro), mai sotto le singole pagine */
.book__shadow {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  box-shadow: 0 30px 60px -30px rgba(0,0,0,.28), 0 0 0 1px rgba(0,0,0,.04);
  transition: left 1s var(--ease), width 1s var(--ease);
}
.book.is-cover .book__shadow { left: 50%; width: 50%; }
.book.is-end .book__shadow { width: 50%; }
.pg--l { left: 0; }
.pg--r { left: 50%; }
.pg.is-empty { visibility: hidden; }
.pg img, .leaf__face img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
}

/* piega centrale: ombra morbida verso la rilegatura */
.pg--l::after, .pg--r::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.pg--l::after { background: linear-gradient(to left, rgba(0,0,0,.14), rgba(0,0,0,0) 7%); }
.pg--r::after { background: linear-gradient(to right, rgba(0,0,0,.14), rgba(0,0,0,0) 7%); }

.book__spine {
  position: absolute;
  top: 0; bottom: 0;
  left: 50%;
  width: 1px;
  background: rgba(0,0,0,.08);
  transition: opacity .6s;
}
.book.is-cover .book__spine, .book.is-end .book__spine { opacity: 0; }

/* foglio che gira */
.leaf {
  position: absolute;
  top: 0;
  width: 50%;
  height: 100%;
  z-index: 5;
  transform-style: preserve-3d;
  will-change: transform;
}
.leaf--fwd { left: 50%; transform-origin: left center; }
.leaf--back { left: 0; transform-origin: right center; }
.leaf__face { inset: 0; width: 100%; backface-visibility: hidden; -webkit-backface-visibility: hidden; }
.leaf__face--back { transform: rotateY(180deg); }
.leaf__face.is-blank { background: #f6f6f6; }
.leaf__shade, .leaf__crease {
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: none;
}
/* la piega segue il lato della rilegatura di ciascuna faccia */
.leaf--fwd .leaf__face--front .leaf__crease,
.leaf--back .leaf__face--back .leaf__crease { background: linear-gradient(to right, rgba(0,0,0,.14), rgba(0,0,0,0) 7%); }
.leaf--fwd .leaf__face--back .leaf__crease,
.leaf--back .leaf__face--front .leaf__crease { background: linear-gradient(to left, rgba(0,0,0,.14), rgba(0,0,0,0) 7%); }
.leaf--single .leaf__face--front .leaf__crease { background: linear-gradient(to right, rgba(0,0,0,.1), rgba(0,0,0,0) 4%); }
.leaf__face.is-blank .leaf__crease { display: none; }
.leaf--fwd .leaf__face--front .leaf__shade,
.leaf--single .leaf__face--front .leaf__shade { background: linear-gradient(to left, rgba(0,0,0,.5), rgba(0,0,0,.05) 60%); }
.leaf--fwd .leaf__face--back .leaf__shade { background: linear-gradient(to left, rgba(0,0,0,.45), rgba(0,0,0,0) 40%); }
.leaf--back .leaf__face--front .leaf__shade { background: linear-gradient(to right, rgba(0,0,0,.5), rgba(0,0,0,.05) 60%); }
.leaf--back .leaf__face--back .leaf__shade { background: linear-gradient(to right, rgba(0,0,0,.45), rgba(0,0,0,0) 40%); }

/* mobile: una pagina alla volta */
.book.is-single .pg--l { display: none; }
.book.is-single .pg--r { left: 0; width: 100%; }
.book.is-single .pg--r::after { background: linear-gradient(to right, rgba(0,0,0,.1), rgba(0,0,0,0) 4%); }
.book.is-single .book__spine { display: none; }
.leaf--single { left: 0; width: 100%; transform-origin: left center; }

.flip__ui {
  display: flex;
  align-items: baseline;
  gap: 28px;
  font-size: 11px;
  letter-spacing: .04em;
  color: var(--muted);
}
.flip__ui button { color: var(--muted); padding: 4px 6px; transition: color .3s var(--ease), opacity .3s; }
.flip__ui button:hover { color: var(--fg); }
.flip__ui button:disabled { opacity: .3; pointer-events: none; }
.flip__count { font-variant-numeric: tabular-nums; min-width: 12ch; text-align: center; }

.booktext { width: min(560px, 100%); }
.booktext p {
  text-align: justify;
  text-justify: inter-word;
  hyphens: auto;
  -webkit-hyphens: auto;
}
.booktext p + p { margin-top: 1.7em; }

/* ── desktop largo ─────────────────────────── */

@media (min-width: 1200px) {
  .col--en { grid-column: 2 / span 4; }
  .col--it { grid-column: 8 / span 4; }
  .grid > .label { grid-column: 2 / -2; }
}

/* ── mobile ────────────────────────────────── */

@media (max-width: 760px) {
  body { font-size: 12.5px; }
  .grid { row-gap: 36px; padding-top: 110px; }
  .col--en, .col--it { grid-column: 1 / -1; }
  .col--it { padding-top: 36px; border-top: 1px solid rgba(10,10,10,.1); }
  .menu a, .links a { padding: 6px 14px; font-size: 14px; }
  .home.is-open .home__word { transform: translateY(-72px); }
  .menu { transform: translate(-50%, -24px); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
    transition-delay: 0s !important;
  }
}
