/* ============================================================================
   base.css — design system condiviso di Ludwing SVG Tools
   ----------------------------------------------------------------------------
   Contiene SOLO ciò che è comune a tutte le pagine del sito:
     · token (tipografia, spaziature, raggi, transizioni)
     · le due palette (tema scuro / tema chiaro)
     · la "chrome" del sito: header con navigazione, hero, footer
     · i componenti condivisi dai due tool: pannelli, campi, switch,
       slider, pulsanti, card di anteprima
   Le regole specifiche di un singolo tool stanno in puzzle.css / clock.css,
   che vengono caricati DOPO questo file.
   ========================================================================== */

/* ---------------------------------------------------------------- token --- */
:root {
  --font-body: "Inter", system-ui, sans-serif;
  --font-display: "Sora", system-ui, sans-serif;

  --text-xs: clamp(0.75rem, .7rem + .25vw, .875rem);
  --text-sm: clamp(0.875rem, .8rem + .35vw, 1rem);
  --text-base: clamp(1rem, .95rem + .25vw, 1.125rem);
  --text-lg: clamp(1.125rem, 1rem + .75vw, 1.5rem);
  --text-xl: clamp(1.5rem, 1.2rem + 1.25vw, 2.25rem);

  --sp1: .25rem;  --sp2: .5rem;   --sp3: .75rem;  --sp4: 1rem;
  --sp5: 1.25rem; --sp6: 1.5rem;  --sp8: 2rem;    --sp10: 2.5rem; --sp12: 3rem;

  --r-sm: .375rem; --r-md: .5rem; --r-lg: .75rem;
  --r-xl: 1rem;    --r-2xl: 1.5rem; --r-full: 9999px;

  --ease: 180ms cubic-bezier(0.16, 1, 0.3, 1);
  --header-h: 60px;
}

/* Un unico accento per tutto il sito (viola), declinato nei due temi.
   --on-accent è il colore del testo che sta SOPRA l'accento: va cambiato
   insieme all'accento, altrimenti si perde il contrasto. */
[data-theme="dark"] {
  --bg: #0d0d0f; --surface: #131316; --s2: #18181c; --s3: #1e1e24;
  --border: rgba(255, 255, 255, .07); --border2: rgba(255, 255, 255, .12);
  --text: #e8e8ed; --muted: #8a8a96; --faint: #6f6f7d;
  --accent: #7c6ee6; --accent-h: #9182f0; --on-accent: #ffffff;
  --ag: rgba(124, 110, 230, .18); --as: rgba(124, 110, 230, .10);
  --green: #34d399; --green-h: #6ee7b7; --gg: rgba(52, 211, 153, .15);
  --on-green: #0a1a12;
  --danger: #f87171;
  --sh-md: 0 4px 16px rgba(0, 0, 0, .5);
  --canvas: #ffffff;
}

[data-theme="light"] {
  --bg: #f6f6f9; --surface: #ffffff; --s2: #f1f1f5; --s3: #e6e6ec;
  --border: rgba(18, 16, 30, .09); --border2: rgba(18, 16, 30, .16);
  --text: #1b1a22; --muted: #5d5b6a; --faint: #86849a;
  --accent: #6353d8; --accent-h: #5243c2; --on-accent: #ffffff;
  --ag: rgba(99, 83, 216, .16); --as: rgba(99, 83, 216, .09);
  --green: #12916a; --green-h: #0d7857; --gg: rgba(18, 145, 106, .16);
  --on-green: #ffffff;
  --danger: #d13b3b;
  --sh-md: 0 4px 16px rgba(18, 16, 30, .10);
  --canvas: #ffffff;
}

/* ---------------------------------------------------------------- reset --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: var(--font-body);
  font-size: var(--text-base);
  color: var(--text);
  background: var(--bg);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  transition: background var(--ease), color var(--ease);
}
img { display: block; max-width: 100%; }
button { cursor: pointer; background: none; border: none; font: inherit; color: inherit; }
input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }
[hidden] { display: none !important; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
  html { scroll-behavior: auto; }
}

/* ------------------------------------------------------ header del sito --- */
.site-header {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: var(--sp4);
  min-height: var(--header-h);
  padding: var(--sp3) var(--sp6);
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: var(--sp3); text-decoration: none; flex-shrink: 0; }
.brand-logo {
  width: 34px; height: 34px; border-radius: var(--r-full); overflow: hidden;
  border: 1px solid var(--border2); background: var(--s2); flex-shrink: 0;
  box-shadow: 0 0 0 3px var(--as);
}
.brand-logo img { width: 100%; height: 100%; object-fit: cover; }
.brand-text {
  font-family: var(--font-display); font-size: var(--text-sm);
  font-weight: 700; letter-spacing: -.01em; white-space: nowrap;
}
.brand-text em { font-style: normal; color: var(--accent-h); }

.site-nav { display: flex; gap: var(--sp1); margin-left: auto; }
.site-nav a {
  padding: 7px 14px; border-radius: var(--r-full);
  font-size: var(--text-xs); font-weight: 600; letter-spacing: .02em;
  color: var(--muted); text-decoration: none;
  transition: color var(--ease), background var(--ease);
  white-space: nowrap;
}
.site-nav a:hover { color: var(--text); background: var(--s2); }
/* Voce attiva derivata da body[data-page]: nessun JS, nessun "flash"
   al caricamento della pagina. */
body[data-page="home"]   .site-nav a[data-nav="home"],
body[data-page="puzzle"] .site-nav a[data-nav="puzzle"],
body[data-page="clock"]  .site-nav a[data-nav="clock"] {
  color: var(--accent-h); background: var(--as);
}

.site-actions { display: flex; align-items: center; gap: var(--sp3); flex-shrink: 0; }

.theme-toggle {
  position: relative; width: 34px; height: 34px; border-radius: var(--r-full);
  background: var(--s2); border: 1px solid var(--border2);
  display: flex; align-items: center; justify-content: center;
  color: var(--muted); transition: color var(--ease), border-color var(--ease);
}
.theme-toggle:hover { color: var(--accent-h); border-color: var(--accent); }
.theme-toggle svg { width: 17px; height: 17px; }
.theme-toggle .icon-sun { display: none; }
[data-theme="light"] .theme-toggle .icon-moon { display: none; }
[data-theme="light"] .theme-toggle .icon-sun { display: block; }

.lang-pill {
  position: relative; display: inline-flex;
  background: var(--s2); border: 1px solid var(--border2);
  border-radius: var(--r-full); padding: 3px;
}
.lang-pill::before {
  content: ""; position: absolute; top: 3px; bottom: 3px;
  width: calc(50% - 3px); border-radius: var(--r-full);
  background: var(--accent); box-shadow: 0 0 12px var(--ag);
  transition: transform 300ms cubic-bezier(0.34, 1.56, 0.64, 1);
  transform: translateX(0);
}
.lang-pill[data-lang="en"]::before { transform: translateX(100%); }
.lang-pill button {
  position: relative; z-index: 1; padding: 4px 13px; border-radius: var(--r-full);
  font-family: var(--font-display); font-size: var(--text-xs); font-weight: 700;
  letter-spacing: .08em; color: var(--faint); transition: color var(--ease);
  user-select: none; min-width: 46px; text-align: center;
}
.lang-pill button.active { color: var(--on-accent); }
.lang-pill button:not(.active):hover { color: var(--muted); }

/* ------------------------------------------------------------------ hero --- */
.hero {
  position: relative; overflow: hidden;
  padding: var(--sp10) var(--sp6);
  display: flex; align-items: center; justify-content: center;
  gap: var(--sp8); flex-wrap: wrap;
  border-bottom: 1px solid var(--border);
}
.hero::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background:
    radial-gradient(ellipse 80% 60% at 70% 50%, var(--ag) 0%, transparent 70%),
    radial-gradient(ellipse 40% 40% at 20% 80%, var(--gg) 0%, transparent 60%);
  opacity: .8;
}
.hero-body { position: relative; display: flex; flex-direction: column; gap: var(--sp3); max-width: 560px; }
.badge {
  display: inline-flex; align-items: center; gap: var(--sp2);
  background: var(--as); border: 1px solid var(--ag);
  border-radius: var(--r-full); padding: 3px 12px;
  font-family: var(--font-display); font-size: var(--text-xs); font-weight: 600;
  color: var(--accent-h); letter-spacing: .06em; text-transform: uppercase;
  width: fit-content;
}
.badge-dot { width: 6px; height: 6px; border-radius: var(--r-full); background: var(--accent); box-shadow: 0 0 6px var(--accent); }
.hero-title { font-family: var(--font-display); font-size: var(--text-xl); font-weight: 700; line-height: 1.1; letter-spacing: -.02em; }
.hero-title em { font-style: normal; color: var(--accent-h); }
.hero-sub { font-size: var(--text-sm); color: var(--muted); line-height: 1.6; }
.hero-links { display: flex; gap: var(--sp3); flex-wrap: wrap; margin-top: var(--sp2); align-items: center; }

.chip {
  display: inline-flex; align-items: center; gap: var(--sp2);
  padding: 7px 14px; border-radius: var(--r-lg);
  font-size: var(--text-xs); font-weight: 600; text-decoration: none;
  transition: transform var(--ease), filter var(--ease); letter-spacing: .02em;
}
.chip:hover { transform: translateY(-1px); filter: brightness(1.12); }
.chip svg { width: 13px; height: 13px; }
.chip-fire { background: linear-gradient(135deg, rgba(251, 146, 60, .15), rgba(239, 68, 68, .15)); border: 1px solid rgba(251, 146, 60, .3); color: #d97a26; }
[data-theme="dark"] .chip-fire { color: #fb923c; }
.chip-maker { background: var(--as); border: 1px solid var(--ag); color: var(--accent-h); }

.tool-header { text-align: center; padding: var(--sp8) var(--sp4) var(--sp6); }
.tool-header h1 { font-family: var(--font-display); font-size: var(--text-lg); font-weight: 600; letter-spacing: -.01em; }
.tool-header p { font-size: var(--text-sm); color: var(--muted); margin-top: var(--sp2); }

/* --------------------------------------------------------------- layout --- */
.workspace {
  display: flex; gap: var(--sp6);
  padding: 0 var(--sp6) var(--sp12);
  max-width: 1320px; margin: 0 auto;
  flex-wrap: wrap; align-items: flex-start;
}
/* L'anteprima resta agganciata in vista mentre si scorre la colonna dei
   controlli, che è quasi sempre più alta. Solo da 900px in su: sotto,
   il layout è già impilato in un'unica colonna. */
@media (min-width: 900px) {
  .preview { position: sticky; top: calc(var(--header-h) + var(--sp4)); align-self: flex-start; }
}

/* ------------------------------------------------------------ pannelli --- */
.panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-2xl); padding: var(--sp6); box-shadow: var(--sh-md);
}
.section-label {
  font-size: var(--text-xs); font-weight: 600; letter-spacing: .08em;
  text-transform: uppercase; color: var(--faint); margin-bottom: var(--sp4);
}
.sep { height: 1px; background: var(--border); margin: var(--sp5) 0; }

/* ---------------------------------------------------------------- campi --- */
.field { margin-bottom: var(--sp4); }
.field label { display: block; font-size: var(--text-xs); font-weight: 500; color: var(--muted); margin-bottom: var(--sp2); letter-spacing: .02em; }
.field input[type="number"],
.field input[type="text"],
.field select {
  width: 100%; background: var(--s2); border: 1px solid var(--border);
  border-radius: var(--r-md); color: var(--text);
  font-size: var(--text-sm); font-weight: 500; padding: 9px 12px;
  outline: none; transition: border-color var(--ease), box-shadow var(--ease);
}
.field input:focus, .field select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--ag); }
.field select {
  appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238a8a96' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; background-size: 16px;
  padding-right: 32px;
}
.field input[type="color"] { width: 100%; height: 38px; background: var(--s2); border: 1px solid var(--border); border-radius: var(--r-md); padding: 3px; cursor: pointer; }
.field input.invalid { border-color: var(--danger) !important; box-shadow: 0 0 0 3px rgba(239, 68, 68, .2) !important; }
.field-error { font-size: var(--text-xs); color: var(--danger); margin-top: var(--sp1); min-height: 1em; display: none; }
.field-error.show { display: block; }
.hint { font-size: var(--text-xs); color: var(--faint); margin-top: var(--sp1); line-height: 1.5; }

.field input[type="file"] {
  width: 100%; background: var(--s2); border: 1px dashed var(--border2);
  border-radius: var(--r-md); color: var(--muted); font-size: var(--text-xs);
  padding: 10px 12px; cursor: pointer;
}
.field input[type="file"]::file-selector-button {
  background: var(--accent); color: var(--on-accent); border: none;
  border-radius: var(--r-sm); padding: 5px 10px;
  font-size: var(--text-xs); font-weight: 600; margin-right: var(--sp2); cursor: pointer;
}
.field input[type="file"]:focus-visible { outline: 2px solid var(--accent-h); outline-offset: 2px; }

.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp3); }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: var(--sp3); }
.input-row { display: flex; align-items: center; gap: var(--sp3); }
.input-row input[type="number"] { width: 76px; flex-shrink: 0; }
.input-row input[type="range"] { flex: 1; accent-color: var(--accent); cursor: pointer; height: 4px; }

/* ------------------------------------------------------- switch on/off --- */
.toggle-field {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp4);
  background: var(--s2); border: 1px solid var(--border); border-radius: var(--r-md);
  padding: 10px 14px; cursor: pointer; transition: border-color var(--ease);
  margin-bottom: var(--sp4);
}
.toggle-field:hover { border-color: var(--border2); }
.toggle-text { flex: 1; }
.toggle-text span { font-size: var(--text-sm); font-weight: 500; color: var(--text); display: block; }
.toggle-text small { font-size: var(--text-xs); color: var(--muted); }
.switch { position: relative; display: inline-block; width: 38px; height: 20px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; inset: 0; background: var(--s3); border: 1px solid var(--border2); border-radius: var(--r-full); transition: background var(--ease); }
.slider::before { content: ""; position: absolute; height: 14px; width: 14px; left: 2px; top: 2px; background: var(--muted); border-radius: var(--r-full); transition: transform var(--ease), background var(--ease); }
.switch input:checked + .slider { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(18px); background: var(--on-accent); }
/* L'input reale dello switch è invisibile (opacity:0) per lo styling custom:
   senza questa regola il focus da tastiera non sarebbe visibile su nulla. */
.switch input:focus-visible + .slider { outline: 2px solid var(--accent-h); outline-offset: 2px; }

/* ----------------------------------------------- slider + numero (combo) --- */
.slider-row { display: flex; align-items: center; gap: var(--sp3); }
.slider-row input[type="number"] { width: 62px; flex: 0 0 62px; text-align: center; padding: 9px 4px; }
.slider-row input[type="range"] { flex: 1; min-width: 0; }
input[type="range"].field-range { -webkit-appearance: none; appearance: none; width: 100%; height: 20px; background: transparent; cursor: pointer; margin: 0; }
input[type="range"].field-range::-webkit-slider-runnable-track { height: 4px; border-radius: var(--r-full); background: var(--s3); }
input[type="range"].field-range::-moz-range-track { height: 4px; border-radius: var(--r-full); background: var(--s3); }
input[type="range"].field-range::-webkit-slider-thumb {
  -webkit-appearance: none; margin-top: -7px; width: 17px; height: 17px; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--surface);
  box-shadow: 0 0 0 1px var(--border2), 0 2px 6px rgba(0, 0, 0, .3);
  transition: transform var(--ease), background var(--ease);
}
input[type="range"].field-range::-moz-range-thumb {
  width: 17px; height: 17px; border-radius: 50%; background: var(--accent);
  border: 2px solid var(--surface); box-shadow: 0 0 0 1px var(--border2), 0 2px 6px rgba(0, 0, 0, .3); cursor: pointer;
}
input[type="range"].field-range:hover::-webkit-slider-thumb { transform: scale(1.12); }
input[type="range"].field-range:active::-webkit-slider-thumb { background: var(--accent-h); }
input[type="range"].field-range:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 4px var(--ag); }
input[type="range"].field-range:focus-visible::-moz-range-thumb { box-shadow: 0 0 0 4px var(--ag); }
input[type="range"]:focus-visible { outline: 2px solid var(--accent-h); outline-offset: 3px; border-radius: var(--r-sm); }
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button { opacity: 1; cursor: pointer; }

/* -------------------------------------------------------------- pulsanti --- */
.btn-dl {
  display: flex; align-items: center; justify-content: center; gap: var(--sp2);
  width: 100%; padding: 11px; border-radius: var(--r-lg);
  font-size: var(--text-sm); font-weight: 600; letter-spacing: .02em;
  background: var(--green); color: var(--on-green);
  transition: background var(--ease), box-shadow var(--ease), transform var(--ease);
}
.btn-dl:hover { background: var(--green-h); box-shadow: 0 0 24px var(--gg); transform: translateY(-1px); }
.btn-dl:active { transform: scale(.98); }
.btn-dl svg { width: 16px; height: 16px; flex-shrink: 0; }
.btn-ghost {
  display: flex; align-items: center; justify-content: center; gap: var(--sp2);
  width: 100%; padding: 9px; border-radius: var(--r-lg);
  font-size: var(--text-xs); font-weight: 600; letter-spacing: .02em;
  background: transparent; border: 1px solid var(--border2); color: var(--muted);
  transition: border-color var(--ease), color var(--ease);
}
.btn-ghost:hover { border-color: var(--accent); color: var(--accent-h); }
.btn-ghost svg { width: 13px; height: 13px; }

/* --------------------------------------------------------- card anteprima --- */
.preview { flex: 1 1 520px; display: flex; flex-direction: column; gap: var(--sp4); }
.preview-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-2xl); overflow: hidden; box-shadow: var(--sh-md); }
.preview-topbar { display: flex; align-items: center; justify-content: space-between; padding: var(--sp4) var(--sp6); border-bottom: 1px solid var(--border); }
.preview-title { font-size: var(--text-xs); font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--faint); }
.preview-dots { display: flex; gap: 6px; }
.preview-dots span { width: 10px; height: 10px; border-radius: var(--r-full); }
#svg-wrapper { display: flex; align-items: center; justify-content: center; background: var(--canvas); padding: var(--sp6); overflow: hidden; }
.info-bar { padding: var(--sp3) var(--sp6); text-align: center; font-size: var(--text-xs); color: var(--muted); border-top: 1px solid var(--border); letter-spacing: .02em; }
.info-pill { font-size: var(--text-xs); color: var(--muted); background: var(--s2); border: 1px solid var(--border); border-radius: var(--r-full); padding: 4px 12px; }

/* ---------------------------------------------------------------- footer --- */
.site-footer {
  border-top: 1px solid var(--border);
  padding: var(--sp8) var(--sp6);
  display: flex; flex-direction: column; align-items: center; gap: var(--sp3);
  font-size: var(--text-xs); color: var(--faint); text-align: center;
}
.site-footer nav { display: flex; flex-wrap: wrap; justify-content: center; gap: var(--sp2) var(--sp4); }
.site-footer a { color: var(--muted); text-decoration: none; transition: color var(--ease); }
.site-footer a:hover { color: var(--accent-h); }
.footer-meta { display: flex; align-items: center; gap: var(--sp3); flex-wrap: wrap; justify-content: center; }

/* ------------------------------------------------------------- scrollbar --- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }

/* ------------------------------------------------------------ responsive --- */
@media (max-width: 760px) {
  .site-header { flex-wrap: wrap; gap: var(--sp3); padding: var(--sp3) var(--sp4); }
  .site-nav { order: 3; width: 100%; margin-left: 0; overflow-x: auto; }
  .site-actions { margin-left: auto; }
  .workspace { padding: 0 var(--sp4) var(--sp10); }
  .hero { padding: var(--sp8) var(--sp4); }
}
@media (max-width: 600px) {
  .row2, .row3 { grid-template-columns: 1fr; }
}
