
:root {
  --bg: #f6f1e6;
  --bg-soft: #fbf7ed;
  --card: #ffffff;
  --ink: #1f1b14;
  --ink-soft: #5a4f3a;
  --muted: #8a7e63;
  --line: #e6ddc6;
  --accent: #6b8e3d;
  --accent-soft: #e9f0d8;
  --gold: #b58a3a;
  --shadow: 0 1px 2px rgba(40,30,10,.04), 0 8px 24px rgba(40,30,10,.06);
  --radius: 14px;
  --radius-sm: 8px;
  --topbar-h: 64px;
  --content-max: 820px;
  --content-w: clamp(640px, 92vw, 1180px);
}

[data-theme="dark"] {
  --bg: #14110c;
  --bg-soft: #1a1610;
  --card: #1f1a13;
  --ink: #ede4cf;
  --ink-soft: #c2b896;
  --muted: #8a7e63;
  --line: #2c2519;
  --accent: #a8c87a;
  --accent-soft: #2a3318;
  --gold: #d4a85a;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.3);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 1rem; }
body {
  margin: 0;
  font-family: 'Inter', -apple-system, Segoe UI, system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* Topbar */
.topbar {
  position: sticky; top: 0;
  display: flex; align-items: center; gap: 1rem;
  padding: 0 1.5rem;
  height: var(--topbar-h);
  background: color-mix(in srgb, var(--bg-soft) 88%, transparent);
  backdrop-filter: blur(14px) saturate(140%);
  -webkit-backdrop-filter: blur(14px) saturate(140%);
  border-bottom: 1px solid var(--line);
  z-index: 30;
}
.brand {
  display: flex; align-items: center; gap: .7rem;
  text-decoration: none; color: inherit;
}
.brand-mark {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--gold));
  color: #fff;
  display: grid; place-items: center;
  font-weight: 700; font-size: .78rem;
  letter-spacing: .5px;
  box-shadow: 0 2px 8px color-mix(in srgb, var(--accent) 30%, transparent);
  transition: transform .3s cubic-bezier(.34,1.56,.64,1);
}
.brand:hover .brand-mark { transform: rotate(360deg) scale(1.05); }
.brand-text { display: flex; flex-direction: column; line-height: 1; }
.brand-title {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 1.2rem; font-weight: 600;
  color: var(--ink);
}
.brand-sub { font-size: .7rem; color: var(--muted); letter-spacing: .5px; margin-top: 2px; }

.topnav {
  display: flex; gap: .25rem; margin-left: 1.5rem; flex: 1;
}
.topnav a {
  position: relative;
  padding: .5rem .9rem;
  color: var(--ink-soft); text-decoration: none;
  font-size: .9rem; font-weight: 500;
  border-radius: 8px;
  transition: color .2s, background .2s;
}
.topnav a:hover { color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, transparent); }
.topnav a.active { color: var(--accent); }
.topnav a.active::after {
  content: ""; position: absolute; bottom: -2px; left: 1rem; right: 1rem;
  height: 2px; background: linear-gradient(90deg, var(--accent), var(--gold));
  border-radius: 2px;
}

.top-actions { display: flex; align-items: center; gap: .5rem; margin-left: auto; }

.icon-btn {
  width: 38px; height: 38px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--card); color: var(--ink-soft);
  display: grid; place-items: center;
  cursor: pointer;
  transition: all .2s;
}
.icon-btn:hover { border-color: var(--accent); color: var(--accent); transform: translateY(-1px); }
.icon-btn .i-moon { display: none; }
[data-theme="dark"] .icon-btn .i-sun { display: none; }
[data-theme="dark"] .icon-btn .i-moon { display: inline; }

.today-btn {
  margin: 1.5rem auto;
  display: flex; align-items: center; gap: .55rem;
  padding: .65rem 1.2rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 999px;
  cursor: pointer;
  font: inherit;
  font-weight: 500;
  font-size: .9rem;
  transition: transform .1s, box-shadow .2s, background .2s;
  box-shadow: 0 4px 12px color-mix(in srgb, var(--accent) 30%, transparent);
}
.today-btn:hover { transform: translateY(-1px); box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 35%, transparent); }

.librone-btn {
  display: flex; align-items: center; gap: .5rem;
  padding: .65rem .85rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 3px solid var(--gold);
  border-radius: var(--radius-sm);
  color: var(--ink-soft);
  text-decoration: none;
  font-size: .88rem;
  font-weight: 500;
  transition: all .15s;
}
.librone-btn:hover { border-color: var(--gold); background: color-mix(in srgb, var(--gold) 8%, var(--card)); color: var(--ink); }
.librone-btn svg { color: var(--gold); }
.today-btn .dot {
  width: 8px; height: 8px; background: #fff; border-radius: 50%;
  box-shadow: 0 0 0 4px rgba(255,255,255,.25);
  animation: pulse 2s infinite;
}
.today-date { margin-left: auto; font-size: .8rem; opacity: .85; font-weight: 400; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .5; } }

.search {
  position: relative;
  display: flex; align-items: center;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0 .65rem;
  color: var(--muted);
  transition: border-color .2s, box-shadow .2s;
}
.search:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}
.search input {
  flex: 1;
  border: 0; background: transparent;
  padding: .65rem .5rem;
  color: var(--ink);
  font: inherit;
  font-size: .9rem;
  outline: none;
}
.search .clear {
  background: none; border: 0; color: var(--muted);
  font-size: 1.3rem; line-height: 1; cursor: pointer;
  padding: 0 .25rem;
  opacity: 0; pointer-events: none; transition: opacity .15s;
}
.search.has-value .clear { opacity: 1; pointer-events: auto; }

.months {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(78px, 1fr));
  gap: 6px;
  margin-bottom: 1.5rem;
}
.months a {
  text-align: center;
  padding: .45rem .3rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink-soft);
  text-decoration: none;
  font-size: .78rem;
  font-weight: 500;
  transition: all .15s;
}
.months a:hover { border-color: var(--accent); color: var(--accent); }
.months a.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.cal {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1.2rem;
}
.cal-month { }
.cal-month h4 {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 1rem; font-weight: 600;
  margin: 0 0 .35rem;
  color: var(--ink-soft);
  letter-spacing: .3px;
}
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 3px;
}
.cal-grid a {
  aspect-ratio: 1;
  display: grid; place-items: center;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--ink-soft);
  text-decoration: none;
  font-size: .7rem;
  font-weight: 500;
  transition: all .12s;
}
.cal-grid a:hover { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.cal-grid a.today { background: var(--accent); border-color: var(--accent); color: #fff; box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 30%, transparent); }
.cal-grid a.match { background: var(--accent-soft); border-color: var(--accent); color: var(--ink); }

.count-line { text-align:center; color:var(--muted); font-size:.8rem; margin: 0 0 1.5rem; }

.cal-section { margin: 2rem 0 3rem; }
.section-title {
  font-family:'Cormorant Garamond',Georgia,serif;
  font-size: 1.6rem; font-weight: 600;
  text-align: center; color: var(--ink);
  margin: 0 0 1.2rem;
}
.section-title::after {
  content: ""; display: block; width: 50px; height: 2px;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
  margin: .5rem auto 0;
}

.menu-btn { display: none !important; }

/* Main */
.main {
  margin: 0 auto;
  padding: 2.5rem clamp(1rem, 3vw, 2.5rem) 5rem;
  width: var(--content-w);
  max-width: 100%;
}

.hero {
  background: linear-gradient(135deg, var(--accent-soft), var(--bg-soft));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 2rem 2.2rem;
  margin-bottom: 2.5rem;
  position: relative;
  overflow: hidden;
}
.hero::before {
  content: "";
  position: absolute;
  top: -40px; right: -40px;
  width: 200px; height: 200px;
  background: radial-gradient(circle, var(--gold), transparent 70%);
  opacity: .15;
  border-radius: 50%;
}
.hero-eyebrow {
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--accent);
  margin: 0 0 .4rem;
  font-weight: 600;
}
.hero h1 {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: clamp(1.8rem, 4vw, 2.6rem);
  font-weight: 600;
  margin: 0 0 .4rem;
  color: var(--ink);
  line-height: 1.15;
}
.hero-date {
  color: var(--ink-soft);
  margin: 0 0 1rem;
  font-size: .95rem;
}
.hero-link {
  display: inline-flex; align-items: center; gap: .3rem;
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
  font-size: .95rem;
  transition: gap .15s;
}
.hero-link:hover { gap: .55rem; }

.content { display: flex; flex-direction: column; gap: 1.5rem; }

article.reflection {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.75rem 2rem;
  scroll-margin-top: 1rem;
  box-shadow: var(--shadow);
  transition: border-color .2s, transform .2s;
  content-visibility: auto;
  contain-intrinsic-size: 1px 380px;
}
article.reflection:target {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 15%, transparent), var(--shadow);
}
article.reflection.hidden { display: none; }

.r-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 1rem;
  margin-bottom: 1rem;
  padding-bottom: .8rem;
  border-bottom: 1px solid var(--line);
}
.r-date {
  font-size: .8rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  font-weight: 500;
  white-space: nowrap;
}
.r-title {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 1.55rem;
  font-weight: 600;
  margin: 0;
  color: var(--ink);
  line-height: 1.25;
  flex: 1;
}

.r-body {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 1.5rem;
  align-items: start;
}
.r-body.no-img { grid-template-columns: 1fr; }
.r-img {
  border-radius: var(--radius-sm);
  width: 100%;
  height: auto;
  display: block;
  border: 1px solid var(--line);
  background: var(--bg-soft);
}
.r-quote {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 1.15rem;
  line-height: 1.55;
  font-style: italic;
  color: var(--ink);
  margin: 0 0 .4rem;
  padding-left: 1rem;
  border-left: 3px solid var(--gold);
}
.r-source {
  font-size: .82rem;
  color: var(--muted);
  margin: 0 0 1.2rem;
  font-style: italic;
}
.r-text {
  margin: 0;
  color: var(--ink-soft);
  font-size: .98rem;
}

.empty {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--muted);
}

.page-foot {
  margin-top: 3rem;
  padding-top: 2rem;
  border-top: 1px solid var(--line);
  text-align: center;
  color: var(--muted);
  font-size: .82rem;
}
.page-foot a { color: var(--ink-soft); }

@media (max-width: 900px) {
  .topbar { padding: 0 1rem; gap: .5rem; }
  .brand-text { display: none; }
  .topnav { position: fixed; top: var(--topbar-h); left: 0; right: 0; flex-direction: column;
    background: var(--bg-soft); border-bottom: 1px solid var(--line); padding: .8rem; gap: .25rem;
    transform: translateY(-150%); transition: transform .25s ease; box-shadow: 0 8px 24px rgba(0,0,0,.1); }
  .topnav.open { transform: translateY(0); }
  .topnav a { padding: .65rem 1rem; border-radius: 8px; }
  .menu-btn { display: grid !important; }
  .search { max-width: 140px; }
  .main { padding: 1.5rem 1rem 4rem; }
  .hero { padding: 1.5rem 1.4rem; }
  article.reflection { padding: 1.3rem 1.4rem; }
  .r-body { grid-template-columns: 1fr; }
  .r-img { max-width: 240px; margin: 0 auto; }
  .r-head { flex-direction: column; align-items: flex-start; gap: .3rem; }
}

@media print {
  .topbar, .menu-btn, .hero, .page-foot, #progress-bar, #scroll-top { display: none; }
  .main { margin: 0; padding: 0; max-width: none; }
  article.reflection { box-shadow: none; border: none; page-break-inside: avoid; padding: 1rem 0; }
}

/* === Effetti grafici condivisi === */
body { position: relative; }
body::before {
  content:""; position:fixed; inset:0; pointer-events:none; z-index:0;
  background-image:
    radial-gradient(circle at 20% 30%, rgba(181,138,58,.06), transparent 40%),
    radial-gradient(circle at 80% 70%, rgba(107,142,61,.05), transparent 45%),
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='180' height='180'><filter id='n'><feTurbulence baseFrequency='.85' numOctaves='2' seed='5'/><feColorMatrix values='0 0 0 0 .65 0 0 0 0 .55 0 0 0 0 .35 0 0 0 .07 0'/></filter><rect width='180' height='180' filter='url(%23n)'/></svg>");
  background-size: auto, auto, 180px 180px;
}
body > * { position: relative; z-index: 1; }
.topbar { z-index: 30 !important; }

#progress-bar {
  position: fixed; top: 0; left: 0; height: 3px; width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--gold), var(--accent));
  background-size: 200% 100%; z-index: 100;
  box-shadow: 0 0 10px color-mix(in srgb, var(--gold) 60%, transparent);
  animation: shimmer 4s linear infinite;
  transition: width .15s ease-out;
}
@keyframes shimmer { from { background-position: 0% 0; } to { background-position: 200% 0; } }

article.reflection {
  opacity: 0; transform: translateY(20px);
  transition: opacity .6s ease-out, transform .6s ease-out, border-color .2s, box-shadow .3s;
}
article.reflection.visible { opacity: 1; transform: translateY(0); }
article.reflection:hover {
  border-color: color-mix(in srgb, var(--gold) 45%, var(--line));
  box-shadow: 0 4px 16px rgba(181,138,58,.12), 0 1px 3px rgba(40,30,10,.06);
  transform: translateY(-2px);
}

article.reflection .r-text::first-letter {
  font-family:'Cormorant Garamond', Georgia, serif;
  font-size: 2.8rem; font-weight: 600;
  float: left; line-height: .85;
  padding: .2rem .45rem 0 0; color: var(--gold);
}

.hero h1 {
  background: linear-gradient(135deg, var(--ink) 0%, var(--gold) 60%, var(--ink) 100%);
  background-size: 200% auto; background-clip: text; -webkit-background-clip: text;
  color: transparent;
  animation: textShine 8s linear infinite;
}
@keyframes textShine { from { background-position: 0% 50%; } to { background-position: 200% 50%; } }

#scroll-top {
  position: fixed; bottom: 1.5rem; right: 1.5rem; z-index: 50;
  width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--card); color: var(--gold);
  display: grid; place-items: center; cursor: pointer;
  opacity: 0; transform: scale(.6) translateY(20px); pointer-events: none;
  transition: opacity .3s, transform .3s, box-shadow .3s;
  box-shadow: 0 4px 14px rgba(40,30,10,.12);
}
#scroll-top.show { opacity: 1; transform: scale(1) translateY(0); pointer-events: auto; }
#scroll-top:hover { box-shadow: 0 6px 22px rgba(181,138,58,.35); color: var(--accent); }

.search { max-width: 280px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
  article.reflection { opacity: 1; transform: none; }
}

/* === Feature buttons === */
.r-actions { display: flex; gap: .35rem; align-items: center; margin: 0 0 1rem; flex-wrap: wrap; }
.act-btn {
  width: 30px; height: 30px; border: 1px solid var(--line); background: transparent;
  border-radius: 6px; color: var(--muted); cursor: pointer;
  display: grid; place-items: center; transition: all .2s;
}
.act-btn:hover { color: var(--accent); border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, transparent); }
.act-btn.active { color: var(--gold); border-color: var(--gold); background: color-mix(in srgb, var(--gold) 12%, transparent); }
.bookmark-btn.active svg path { fill: currentColor; }
.tts-btn.playing { color: var(--accent); border-color: var(--accent); animation: pulse-tts 1s ease-in-out infinite; }
@keyframes pulse-tts { 0%,100% { opacity: 1; } 50% { opacity: .6; } }
.copy-btn.copied { color: var(--accent); border-color: var(--accent); }
.rt-badge { display: inline-flex; align-items: center; gap: .25rem; font-size: .72rem; color: var(--muted); margin-right: auto; }
.rt-badge svg { opacity: .7; }

article.reflection.bookmarked { background: linear-gradient(to right, color-mix(in srgb, var(--gold) 4%, var(--card)), var(--card)); }
article.reflection.visited::before {
  content: ""; position: absolute; top: 1rem; left: -8px;
  width: 4px; height: 24px; background: var(--accent); border-radius: 2px; opacity: .6;
}
article.reflection { position: relative; }

#bookmarks-panel {
  position: fixed; top: 70px; right: 1rem; z-index: 60;
  width: 340px; max-height: 70vh; overflow-y: auto;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: 0 12px 40px rgba(40,30,10,.18);
  padding: 1rem; display: none;
}
#bookmarks-panel.open { display: block; }
#bookmarks-panel h3 { margin: 0 0 .8rem; font-family: 'Cormorant Garamond', Georgia, serif; color: var(--gold); }
#bookmarks-panel .empty-bm { color: var(--muted); font-size: .85rem; }
#bookmarks-panel ul { list-style: none; margin: 0; padding: 0; }
#bookmarks-panel li { padding: .4rem 0; border-bottom: 1px solid var(--line); }
#bookmarks-panel li a { color: var(--ink-soft); text-decoration: none; font-size: .85rem; }
#bookmarks-panel li a:hover { color: var(--gold); }
@media (max-width: 900px) { #bookmarks-panel { right: .5rem; left: .5rem; width: auto; } }

/* === Timeline laterale === */
#timeline {
  position: fixed;
  top: calc(var(--topbar-h) + 1rem);
  bottom: 1rem;
  right: 1.2rem;
  width: 78px;
  z-index: 25;
  display: flex; flex-direction: column;
  justify-content: stretch;
  padding: .35rem 0;
  pointer-events: auto;
  overflow: hidden;
}
.tl-month {
  font-size: .82rem;
  font-weight: 600;
  color: var(--gold);
  letter-spacing: .8px;
  text-align: center;
  padding: .28rem 0 .18rem;
  margin-top: .3rem;
  opacity: .85;
  text-transform: uppercase;
  font-family: 'Inter', sans-serif;
}
.tl-tick {
  display: block;
  flex: 1 1 0;
  min-height: 0;
  margin: 0 auto;
  width: 28px;
  background: var(--line);
  border-radius: 2px;
  transition: width .15s ease-out, background .15s, transform .15s;
  position: relative;
  text-decoration: none;
}
.tl-tick:hover {
  width: 48px;
  background: var(--accent);
  transform: scaleY(1.8);
  z-index: 2;
}
.tl-tick.current {
  background: var(--gold);
  width: 42px;
}
.tl-tick.today {
  background: var(--accent);
  width: 40px;
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 30%, transparent);
}

.tl-tip {
  position: fixed;
  right: 60px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .5rem .8rem;
  font-size: .8rem;
  color: var(--ink);
  box-shadow: 0 6px 18px rgba(40,30,10,.15);
  pointer-events: none;
  opacity: 0;
  transform: translateY(-50%) translateX(8px);
  transition: opacity .15s, transform .15s;
  z-index: 100;
  max-width: 260px;
  line-height: 1.35;
}
.tl-tip.show { opacity: 1; transform: translateY(-50%) translateX(0); }
.tl-tip strong { color: var(--gold); font-family: 'Cormorant Garamond', Georgia, serif; font-size: .92rem; }

@media (max-width: 900px) {
  #timeline { display: none; }
  .tl-tip { display: none; }
}
