/* ============================================================
   ENCRES — la couleur émotionnelle des textes
   Direction : revue littéraire, papier crème, encres aquarellées
   ============================================================ */

:root {
  --paper: #f7f1e5;
  --paper-deep: #efe6d4;
  --ink: #221c14;
  --ink-soft: #6b6052;
  --rule: #d8cdb8;
  --serif-display: "Fraunces", serif;
  --serif-body: "EB Garamond", serif;
}

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

html { scroll-behavior: smooth; }

body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif-body);
  font-size: 19px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

/* grain de papier */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1000;
  opacity: 0.5;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3CfeColorMatrix values='0 0 0 0 0.45 0 0 0 0 0.4 0 0 0 0 0.3 0 0 0 0.05 0'/%3E%3C/filter%3E%3Crect width='180' height='180' filter='url(%23n)'/%3E%3C/svg%3E");
}

.loading {
  text-align: center;
  padding: 6rem 1rem;
  font-style: italic;
  color: var(--ink-soft);
}

/* ============ GALERIE ============ */

.gallery {
  max-width: 880px;
  margin: 0 auto;
  padding: 4.5rem 1.5rem 6rem;
}

.masthead {
  text-align: center;
  margin-bottom: 4.5rem;
  animation: rise 0.9s cubic-bezier(.2,.7,.3,1) backwards;
}

.masthead .kicker {
  font-family: var(--serif-body);
  font-size: 0.8rem;
  letter-spacing: 0.45em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-bottom: 1.2rem;
}

.masthead h1 {
  font-family: var(--serif-display);
  font-optical-sizing: auto;
  font-size: clamp(3.2rem, 9vw, 5.6rem);
  font-weight: 380;
  line-height: 1;
  letter-spacing: 0.01em;
}

.masthead h1 .tinted {
  font-style: italic;
  background: linear-gradient(100deg,
    hsl(46 80% 42%), hsl(100 45% 38%), hsl(195 55% 40%),
    hsl(222 50% 45%), hsl(282 40% 45%), hsl(356 60% 45%));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.masthead .sub {
  margin-top: 1.4rem;
  font-style: italic;
  font-size: 1.1rem;
  color: var(--ink-soft);
  max-width: 34em;
  margin-inline: auto;
}

.masthead::after {
  content: "❦";
  display: block;
  margin-top: 2.2rem;
  color: var(--ink-soft);
  font-size: 1.1rem;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 1.4rem;
}

.card {
  display: block;
  text-decoration: none;
  color: inherit;
  background: var(--paper-deep);
  border: 1px solid var(--rule);
  padding: 1.5rem 1.8rem 1.3rem;
  position: relative;
  transition: transform 0.35s cubic-bezier(.2,.7,.3,1), box-shadow 0.35s;
  animation: rise 0.8s cubic-bezier(.2,.7,.3,1) backwards;
}
.card:nth-child(even) { animation-delay: 0.12s; }

@media (prefers-reduced-motion: reduce) {
  .masthead, .card { animation: none; }
}

.card:hover {
  transform: translateY(-4px);
  box-shadow: 0 18px 40px -18px rgba(60, 45, 20, 0.35);
}

.card .genre {
  font-size: 0.72rem;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.card h2 {
  font-family: var(--serif-display);
  font-weight: 450;
  font-size: 1.5rem;
  margin: 0.35rem 0 0.15rem;
  line-height: 1.15;
}

.card .byline {
  font-style: italic;
  font-size: 0.95rem;
  color: var(--ink-soft);
  margin-bottom: 1.1rem;
}

.card .strip {
  display: flex;
  height: 22px;
  border: 1px solid var(--rule);
  overflow: hidden;
}
.card .strip i { flex: 1 0 auto; }

.card .moods {
  margin-top: 0.75rem;
  font-size: 0.85rem;
  color: var(--ink-soft);
  font-style: italic;
}
.card .moods b {
  font-style: normal;
  font-weight: 600;
  color: var(--ink);
}

/* filtres par collection */
.filters {
  margin-top: 1.8rem;
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.4rem;
}
.filters .chip {
  text-decoration: none;
  font-size: 0.85rem;
  padding: 0.25rem 0.95rem 0.3rem;
}

/* intertitres de collection */
.collection-title {
  font-family: var(--serif-display);
  font-weight: 420;
  font-size: 1.4rem;
  margin: 3rem 0 1.2rem;
  display: flex;
  align-items: baseline;
  gap: 1rem;
}
.collection-title::after {
  content: "";
  flex: 1;
  border-bottom: 1px solid var(--rule);
  align-self: center;
}
.collection-title .count {
  font-family: var(--serif-body);
  font-style: italic;
  font-size: 0.9rem;
  color: var(--ink-soft);
}

/* ============ LECTURE ============ */

.reader-bar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--rule);
  padding: 0.7rem 1.5rem 0.85rem;
}

.reader-bar .row {
  max-width: 880px;
  margin: 0 auto;
  display: flex;
  align-items: baseline;
  gap: 1rem;
}

.back {
  font-size: 0.85rem;
  text-decoration: none;
  color: var(--ink-soft);
  letter-spacing: 0.08em;
  white-space: nowrap;
}
.back:hover { color: var(--ink); }

.reader-bar .title {
  font-family: var(--serif-display);
  font-size: 1.05rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.reader-bar .who {
  font-style: italic;
  font-size: 0.85rem;
  color: var(--ink-soft);
  white-space: nowrap;
}

.barcode-wrap {
  max-width: 880px;
  margin: 0.55rem auto 0;
  position: relative;
}

.barcode {
  display: flex;
  height: 30px;
  border: 1px solid var(--rule);
  overflow: hidden;
  cursor: pointer;
}
.barcode i {
  flex: 1 0 auto;
  transition: filter 0.15s;
}
.barcode i:hover { filter: brightness(0.82) saturate(1.3); }

.cursor {
  position: absolute;
  top: -5px;
  bottom: -5px;
  width: 2px;
  background: var(--ink);
  pointer-events: none;
  transition: left 0.1s linear;
}
.cursor::after {
  content: "";
  position: absolute;
  top: -4px; left: -3px;
  border: 4px solid transparent;
  border-top-color: var(--ink);
}

/* légende */
.legend {
  max-width: 880px;
  margin: 0.7rem auto 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.5rem;
}
.chip {
  font-family: var(--serif-body);
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  border: 1px solid var(--rule);
  background: transparent;
  color: var(--ink);
  border-radius: 999px;
  padding: 0.15rem 0.65rem 0.2rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  transition: background 0.2s, opacity 0.2s;
}
.chip .dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  display: inline-block;
}
.chip:hover { background: var(--paper-deep); }
.chip.active {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}
body.filtering .chip[data-emotion]:not(.active) { opacity: 0.55; }

/* boutons de zoom */
.zoom {
  margin-left: auto;
  display: flex;
  border: 1px solid var(--rule);
  align-self: center;
}
.zbtn {
  background: transparent;
  border: none;
  padding: 0.3rem 0.55rem;
  cursor: pointer;
  color: var(--ink-soft);
  display: flex;
  align-items: center;
  transition: background 0.2s, color 0.2s;
}
.zbtn svg { width: 15px; height: 15px; display: block; }
.zbtn + .zbtn { border-left: 1px solid var(--rule); }
.zbtn:hover { background: var(--paper-deep); color: var(--ink); }
.zbtn.active { background: var(--ink); color: var(--paper); }

/* mosaïque : le texte entier en très petit, flux continu (sans sauts de
   paragraphe), calé sur la largeur du code-barres */
.reading.zoom-far {
  max-width: 880px;
  padding-top: 2.4rem;
  font-size: 7px;
  line-height: 2;
  text-align: justify;
}
.reading.zoom-far .reading-head, .reading.zoom-far .source-note { display: none; }
.reading.zoom-far p {
  display: inline;
  width: auto;
}
.reading.zoom-far p br { display: none; }
.reading.zoom-far .s {
  cursor: pointer;
  padding: 0.15em 0.3em;
  margin: 0;
  border-radius: 2px;
  background-color: var(--mos) !important;
}
.reading.zoom-far .s:hover { filter: brightness(0.9) saturate(1.3); }
body.filtering .reading.zoom-far .s:not(.match) {
  background-color: transparent !important;
}

/* corps du texte */
.reading {
  max-width: 680px;
  margin: 0 auto;
  padding: 3.5rem 1.5rem 7rem;
}

.reading-head {
  text-align: center;
  margin-bottom: 3.5rem;
}
.reading-head .genre {
  font-size: 0.75rem;
  letter-spacing: 0.4em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.reading-head h1 {
  font-family: var(--serif-display);
  font-weight: 400;
  font-size: clamp(2.4rem, 6vw, 3.6rem);
  margin: 0.6rem 0 0.4rem;
  line-height: 1.1;
}
.reading-head .byline {
  font-style: italic;
  font-size: 1.15rem;
  color: var(--ink-soft);
}
.reading-head::after {
  content: "";
  display: block;
  width: 70px;
  margin: 2rem auto 0;
  border-bottom: 1px solid var(--ink-soft);
}

.reading p {
  margin-bottom: 1.15em;
  text-align: justify;
  hyphens: auto;
  -webkit-hyphens: auto;
}

.s {
  border-radius: 3px;
  padding: 0.05em 0.15em;
  margin: 0 -0.15em;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
  transition: opacity 0.3s, background-color 0.3s;
  cursor: default;
}

body.filtering .s:not(.match) {
  opacity: 0.3;
  background-color: transparent !important;
}

.s.flash {
  animation: flash 1.6s ease-out;
}
@keyframes flash {
  0%, 35% { outline: 2px solid var(--ink); outline-offset: 2px; }
  100% { outline: 2px solid transparent; outline-offset: 2px; }
}

/* poèmes : vers non justifiés, strophes centrées, interligne aéré */
.reading.verse p {
  text-align: left;
  hyphens: none;
  -webkit-hyphens: none;
  width: fit-content;
  margin-inline: auto;
  margin-bottom: 1.8em;
  line-height: 2;
}

.source-note {
  margin-top: 4rem;
  text-align: center;
  font-size: 0.85rem;
  font-style: italic;
  color: var(--ink-soft);
}
.source-note a { color: inherit; }

/* tooltip */
#tooltip {
  position: fixed;
  z-index: 200;
  pointer-events: none;
  background: var(--ink);
  color: var(--paper);
  font-family: var(--serif-body);
  font-size: 0.82rem;
  letter-spacing: 0.05em;
  padding: 0.3rem 0.7rem 0.35rem;
  border-radius: 3px;
  white-space: nowrap;
  transform: translate(-50%, calc(-100% - 10px));
  box-shadow: 0 6px 18px -6px rgba(0,0,0,0.4);
}
#tooltip .dot {
  display: inline-block;
  width: 9px; height: 9px;
  border-radius: 50%;
  margin-right: 0.45rem;
  vertical-align: baseline;
}
#tooltip.rich {
  white-space: normal;
  max-width: 320px;
}
#tooltip.below {
  transform: translate(-50%, 16px);
}
#tooltip b { font-weight: 600; }
#tooltip.rich .excerpt {
  display: block;
  margin-top: 0.25rem;
  font-style: italic;
  opacity: 0.85;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(18px); }
  to   { opacity: 1; transform: translateY(0); }
}

@media (max-width: 640px) {
  body { font-size: 17px; }
  .reader-bar .who { display: none; }
  .reading p { text-align: left; }
}
