/* =========================================================================
   Follonica Economy — design system
   A small, framework-free stylesheet. Light + dark aware.
   ========================================================================= */

/* ---- Design tokens ---------------------------------------------------- */
:root {
  color-scheme: light dark;

  /* Brand palette — Tyrrhenian sea, Maremma earth, cast iron */
  --sea:        #0e7490; /* teal   — the Gulf of Follonica          */
  --sea-soft:   #cff3f6;
  --terracotta: #c05e3c; /* Maremma clay / roof tiles               */
  --gold:       #b7791f; /* summer light, wheat                     */
  --sage:       #4d7c5f; /* pinewood (the pineta)                   */
  --iron:       #334155; /* the foundry heritage                    */

  /* Semantic colors (light) */
  --bg:         #faf7f2;
  --surface:    #ffffff;
  --surface-2:  #f4efe7;
  --ink:        #1f2933;
  --muted:      #5b6672;
  --border:     #e7ded1;
  --accent:     var(--sea);
  --accent-ink: #ffffff;
  --shadow:     0 1px 2px rgba(31,41,51,.05), 0 8px 24px rgba(31,41,51,.06);

  /* Categorical chart palette (light) */
  --c1: #0e7490; /* sea      */
  --c2: #c05e3c; /* terracotta */
  --c3: #b7791f; /* gold     */
  --c4: #4d7c5f; /* sage     */
  --c5: #6b7f99; /* slate    */
  --grid: #e7ded1;

  --maxw: 1080px;
  --radius: 14px;
  --font-body: "Inter", system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  --font-display: "Fraunces", Georgia, "Times New Roman", serif;
}

/* Dark palette tokens.
   Applied in two situations, so the theme works on every platform:
     1. The visitor explicitly chose dark via the toggle  -> html[data-theme="dark"]
     2. The OS reports a dark preference AND the visitor has not overridden it
        to light                                           -> :not([data-theme="light"])
   Older approaches only redeclared these variables inside the
   prefers-color-scheme media query, so the manual toggle changed nothing
   unless the OS itself was in dark mode — which is why tapping the toggle
   did nothing on iPad/iPadOS (usually kept in light mode).
   The two blocks below are intentionally identical; keep them in sync. */
html[data-theme="dark"] {
  --bg:        #0f1720;
  --surface:   #17212c;
  --surface-2: #1d2937;
  --ink:       #e8eef4;
  --muted:     #9fb0c0;
  --border:    #2a3745;
  --accent:    #38bdf8;
  --accent-ink:#06222e;
  --sea-soft:  #123240;
  --shadow:    0 1px 2px rgba(0,0,0,.3), 0 10px 30px rgba(0,0,0,.35);

  --c1: #38bdf8;
  --c2: #f0a17e;
  --c3: #e9c46a;
  --c4: #86c79b;
  --c5: #a7b8cc;
  --grid: #2a3745;
}

@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) {
    --bg:        #0f1720;
    --surface:   #17212c;
    --surface-2: #1d2937;
    --ink:       #e8eef4;
    --muted:     #9fb0c0;
    --border:    #2a3745;
    --accent:    #38bdf8;
    --accent-ink:#06222e;
    --sea-soft:  #123240;
    --shadow:    0 1px 2px rgba(0,0,0,.3), 0 10px 30px rgba(0,0,0,.35);

    --c1: #38bdf8;
    --c2: #f0a17e;
    --c3: #e9c46a;
    --c4: #86c79b;
    --c5: #a7b8cc;
    --grid: #2a3745;
  }
}

/* Keep native form controls / scrollbars in step with the chosen theme */
html[data-theme="light"] { color-scheme: light; }
html[data-theme="dark"]  { color-scheme: dark; }

/* ---- Reset-ish -------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  margin: 0;
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

img { max-width: 100%; display: block; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { font-family: var(--font-display); line-height: 1.15; font-weight: 600; }
h1 { font-size: clamp(2.1rem, 5vw, 3.4rem); letter-spacing: -.01em; margin: 0 0 .4em; }
h2 { font-size: clamp(1.5rem, 3.2vw, 2.1rem); margin: 0 0 .5em; }
h3 { font-size: 1.2rem; margin: 0 0 .4em; }

.lead { font-size: 1.18rem; color: var(--muted); max-width: 60ch; }

/* ---- Layout ----------------------------------------------------------- */
.container { width: min(100% - 2.5rem, var(--maxw)); margin-inline: auto; }
section { padding: clamp(2.5rem, 6vw, 4.5rem) 0; }
.eyebrow {
  text-transform: uppercase; letter-spacing: .16em; font-size: .74rem;
  font-weight: 700; color: var(--accent); font-family: var(--font-body);
  display: inline-block; margin-bottom: .6rem;
}

/* ---- Header / nav ----------------------------------------------------- */
.site-header {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(140%) blur(10px);
  border-bottom: 1px solid var(--border);
}
.nav {
  display: flex; align-items: center; gap: 1rem;
  padding: .7rem 0; width: min(100% - 2.5rem, var(--maxw)); margin-inline: auto;
}
.brand { display: flex; align-items: center; gap: .55rem; font-family: var(--font-display); font-weight: 600; font-size: 1.15rem; color: var(--ink); }
.brand:hover { text-decoration: none; }
.brand .mark { width: 30px; height: 30px; }
.nav-links { display: flex; gap: .25rem; margin-left: auto; align-items: center; }
.nav-links a {
  color: var(--muted); padding: .45rem .7rem; border-radius: 9px; font-size: .93rem; font-weight: 500;
}
.nav-links a:hover { color: var(--ink); background: var(--surface-2); text-decoration: none; }
.nav-links a[aria-current="page"] { color: var(--accent); background: var(--sea-soft); }
.theme-toggle {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--ink);
  width: 38px; height: 38px; border-radius: 10px; cursor: pointer; font-size: 1rem;
  display: grid; place-items: center;
}
.nav-toggle { display: none; background: none; border: 1px solid var(--border); border-radius: 10px; width: 40px; height: 40px; cursor: pointer; color: var(--ink); }

@media (max-width: 720px) {
  .nav-toggle { display: grid; place-items: center; }
  .nav-links {
    position: absolute; top: 100%; left: 0; right: 0; flex-direction: column; align-items: stretch;
    background: var(--surface); border-bottom: 1px solid var(--border); padding: .5rem 1.25rem 1rem;
    gap: .1rem; box-shadow: var(--shadow); display: none;
  }
  .nav-links.open { display: flex; }
  .nav-links a { padding: .7rem .5rem; }
  .theme-toggle { margin-top: .4rem; }
}

/* ---- Hero ------------------------------------------------------------- */
.hero {
  position: relative; overflow: hidden;
  background:
    radial-gradient(120% 90% at 80% -10%, color-mix(in srgb, var(--sea) 22%, transparent), transparent 60%),
    radial-gradient(90% 80% at -10% 10%, color-mix(in srgb, var(--gold) 16%, transparent), transparent 55%);
  border-bottom: 1px solid var(--border);
}
.hero .container { padding-top: clamp(2.5rem, 7vw, 5rem); padding-bottom: clamp(2.5rem, 7vw, 5rem); }
.hero-grid { display: grid; grid-template-columns: 1.1fr .9fr; gap: 2.5rem; align-items: center; }
@media (max-width: 820px) { .hero-grid { grid-template-columns: 1fr; } }

.btn {
  display: inline-flex; align-items: center; gap: .5rem; cursor: pointer;
  padding: .7rem 1.15rem; border-radius: 11px; font-weight: 600; font-size: .95rem;
  border: 1px solid transparent; font-family: var(--font-body);
}
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { text-decoration: none; filter: brightness(1.05); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--ink); }
.btn-ghost:hover { background: var(--surface-2); text-decoration: none; }
.btn-row { display: flex; gap: .7rem; flex-wrap: wrap; margin-top: 1.5rem; }

/* ---- Cards & grids ---------------------------------------------------- */
.grid { display: grid; gap: 1.25rem; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 820px) { .grid-3, .grid-4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 560px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.4rem; box-shadow: var(--shadow);
}
.card h3 { margin-top: 0; }
.card .icon { font-size: 1.6rem; line-height: 1; margin-bottom: .5rem; }
.card p { color: var(--muted); margin-bottom: 0; }

/* Stat tiles */
.stat { text-align: left; }
.stat .num { font-family: var(--font-display); font-size: clamp(1.8rem, 4vw, 2.6rem); font-weight: 600; color: var(--ink); line-height: 1; }
.stat .num .unit { font-size: .55em; color: var(--accent); margin-left: .1em; }
.stat .label { color: var(--muted); font-size: .92rem; margin-top: .35rem; }

/* Chart figure */
.chart-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.4rem 1.4rem 1rem; box-shadow: var(--shadow); }
.chart-card h3 { margin: 0 0 .2rem; }
.chart-card .sub { color: var(--muted); font-size: .9rem; margin: 0 0 1rem; }
figure { margin: 0; }
figcaption { color: var(--muted); font-size: .82rem; margin-top: .6rem; }
.legend { display: flex; flex-wrap: wrap; gap: .4rem 1rem; margin-top: .8rem; font-size: .86rem; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: .4rem; }
.legend i { width: 11px; height: 11px; border-radius: 3px; display: inline-block; }

/* SVG chart primitives */
.chart svg { width: 100%; height: auto; overflow: visible; }
.chart .axis text { fill: var(--muted); font-size: 11px; font-family: var(--font-body); }
.chart .grid-line { stroke: var(--grid); stroke-width: 1; }
.chart .bar { transition: opacity .2s; }
.chart .val { fill: var(--ink); font-size: 11px; font-weight: 600; font-family: var(--font-body); }

/* Timeline */
.timeline { position: relative; margin: 1rem 0 0; padding-left: 1.5rem; }
.timeline::before { content: ""; position: absolute; left: 6px; top: .4rem; bottom: .4rem; width: 2px; background: var(--border); }
.timeline li { position: relative; list-style: none; margin: 0 0 1.6rem; }
.timeline li::before { content: ""; position: absolute; left: -1.5rem; top: .35rem; width: 13px; height: 13px; border-radius: 50%; background: var(--accent); border: 3px solid var(--bg); }
.timeline .year { font-family: var(--font-display); font-weight: 600; color: var(--accent); }
.timeline p { margin: .1rem 0 0; color: var(--muted); }

/* Prose */
.prose p, .prose li { color: var(--ink); }
.prose h2 { margin-top: 2rem; }
.prose a { text-decoration: underline; text-underline-offset: 2px; }
.note {
  border-left: 3px solid var(--gold); background: var(--surface-2);
  padding: .9rem 1.1rem; border-radius: 0 10px 10px 0; color: var(--muted); font-size: .92rem;
}
.pill { display: inline-block; padding: .2rem .6rem; border-radius: 999px; background: var(--sea-soft); color: var(--accent); font-size: .78rem; font-weight: 600; }

/* ---- Footer ----------------------------------------------------------- */
.site-footer { border-top: 1px solid var(--border); background: var(--surface); margin-top: 2rem; }
.site-footer .container { padding: 2.2rem 0; display: flex; flex-wrap: wrap; gap: 1rem 2rem; align-items: center; justify-content: space-between; }
.site-footer p { margin: 0; color: var(--muted); font-size: .88rem; }
.site-footer nav { display: flex; gap: 1rem; flex-wrap: wrap; }
.site-footer nav a { color: var(--muted); font-size: .88rem; }

/* ---- Reveal on scroll ------------------------------------------------- */
/* Only hide when JS is present (html.js), so no-JS visitors still see it. */
html.js .reveal { opacity: 0; transform: translateY(14px); transition: opacity .6s ease, transform .6s ease; }
html.js .reveal.in { opacity: 1; transform: none; }
@media (prefers-reduced-motion: reduce) { html.js .reveal { opacity: 1; transform: none; transition: none; } }

/* Skip link */
.skip { position: absolute; left: -999px; top: 0; background: var(--accent); color: var(--accent-ink); padding: .6rem 1rem; border-radius: 0 0 8px 0; z-index: 100; }
.skip:focus { left: 0; }
