/* ==========================================================================
   KataneZ3D — Design tokens (unica fonte di verità per colori e font)
   Stile: Minimalism & Swiss Style (skill ui-ux-pro-max)
   I colori sono canali RGB, così Tailwind può applicare l'opacità:
   es. bg-bg/90  ->  rgb(var(--c-bg) / 0.9)
   ========================================================================== */

:root {
  /* Font */
  --font-heading: "Outfit", ui-sans-serif, system-ui, sans-serif;
  --font-body: "Work Sans", ui-sans-serif, system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

  /* Colori — modalità chiara */
  --c-bg: 248 250 252;          /* #F8FAFC */
  --c-surface: 255 255 255;     /* #FFFFFF */
  --c-fg: 2 6 23;               /* #020617 */
  --c-muted: 232 236 241;       /* #E8ECF1 */
  --c-muted-fg: 71 85 105;      /* #475569 */
  --c-primary: 15 23 42;        /* #0F172A */
  --c-on-primary: 255 255 255;  /* #FFFFFF */
  --c-accent: 194 65 12;        /* #C2410C */
  --c-on-accent: 255 255 255;   /* #FFFFFF */
  --c-line: 226 232 240;        /* #E2E8F0 */
  --c-danger: 220 38 38;        /* #DC2626 */
  --c-success: 21 128 61;       /* #15803D */
  --c-ring: 194 65 12;          /* focus ring = accento */

  --radius: 0.5rem;
  --ease: cubic-bezier(0.2, 0, 0, 1);
  --dur: 200ms;

  color-scheme: light;
}

.dark {
  --c-bg: 11 17 32;             /* #0B1120 */
  --c-surface: 17 24 39;        /* #111827 */
  --c-fg: 241 245 249;          /* #F1F5F9 */
  --c-muted: 30 41 59;          /* #1E293B */
  --c-muted-fg: 148 163 184;    /* #94A3B8 */
  --c-primary: 226 232 240;     /* #E2E8F0 */
  --c-on-primary: 15 23 42;     /* #0F172A */
  --c-accent: 251 146 60;       /* #FB923C */
  --c-on-accent: 11 17 32;      /* #0B1120 */
  --c-line: 30 41 59;           /* #1E293B */
  --c-danger: 248 113 113;      /* #F87171 */
  --c-success: 74 222 128;      /* #4ADE80 */
  --c-ring: 251 146 60;

  color-scheme: dark;
}

/* ---------- Base ---------- */
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }

body {
  background-color: rgb(var(--c-bg));
  color: rgb(var(--c-fg));
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { font-family: var(--font-heading); line-height: 1.15; text-wrap: balance; }
p { text-wrap: pretty; }

/* Focus visibile da tastiera, sempre */
:focus-visible {
  outline: 3px solid rgb(var(--c-ring));
  outline-offset: 3px;
  border-radius: 4px;
}

/* ---------- Componenti ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
  min-height: 44px; padding: 0.625rem 1.25rem;
  border-radius: var(--radius); border: 1px solid transparent;
  font-family: var(--font-heading); font-weight: 600; font-size: 0.975rem;
  text-decoration: none; cursor: pointer;
  transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease),
              border-color var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: rgb(var(--c-accent)); color: rgb(var(--c-on-accent)); }
.btn-primary:hover { background: rgb(var(--c-accent) / 0.88); }
.btn-secondary { background: transparent; color: rgb(var(--c-fg)); border-color: rgb(var(--c-fg) / 0.25); }
.btn-secondary:hover { border-color: rgb(var(--c-fg)); background: rgb(var(--c-fg) / 0.04); }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; border-radius: var(--radius);
  color: rgb(var(--c-fg)); background: transparent; border: 1px solid rgb(var(--c-line));
  cursor: pointer; transition: background-color var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.icon-btn:hover { background: rgb(var(--c-muted)); }

.nav-link {
  display: flex; align-items: center; min-height: 44px; padding: 0 0.875rem;
  border-radius: var(--radius); font-weight: 500; color: rgb(var(--c-muted-fg));
  text-decoration: none; transition: color var(--dur) var(--ease), background-color var(--dur) var(--ease);
}
.nav-link:hover { color: rgb(var(--c-fg)); background: rgb(var(--c-muted) / 0.6); }
.nav-link[aria-current="page"] { color: rgb(var(--c-fg)); box-shadow: inset 0 -2px 0 rgb(var(--c-accent)); }

.card {
  background: rgb(var(--c-surface)); border: 1px solid rgb(var(--c-line));
  border-radius: calc(var(--radius) * 1.5);
  transition: border-color var(--dur) var(--ease), transform var(--dur) var(--ease);
}
a.card:hover, .card-hover:hover { border-color: rgb(var(--c-accent) / 0.6); }

.text-link {
  color: rgb(var(--c-accent)); font-weight: 600; text-decoration: underline;
  text-decoration-thickness: 1px; text-underline-offset: 4px;
}
.text-link:hover { text-decoration-thickness: 2px; }

/* Etichetta tecnica in monospace */
.tag {
  display: inline-flex; align-items: center; gap: 0.375rem;
  font-family: var(--font-mono); font-size: 0.75rem; letter-spacing: 0.02em;
  text-transform: uppercase; color: rgb(var(--c-muted-fg));
}
.tag::before { content: ""; width: 0.5rem; height: 0.5rem; background: rgb(var(--c-accent)); }

/* Griglia millimetrata da disegno tecnico */
.bg-blueprint {
  background-image:
    linear-gradient(rgb(var(--c-line)) 1px, transparent 1px),
    linear-gradient(90deg, rgb(var(--c-line)) 1px, transparent 1px);
  background-size: 32px 32px;
  background-position: -1px -1px;
}

/* Contenitore immagini segnaposto */
.media {
  background-color: rgb(var(--c-muted));
  overflow: hidden;
}
.media img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* ---------- Modulo ---------- */
.field-label { display: block; font-weight: 600; margin-bottom: 0.375rem; }
.field {
  width: 100%; min-height: 44px; padding: 0.625rem 0.875rem;
  background: rgb(var(--c-surface)); color: rgb(var(--c-fg));
  border: 1px solid rgb(var(--c-muted-fg) / 0.6); border-radius: var(--radius);
  font: inherit; transition: border-color var(--dur) var(--ease);
}
.field::placeholder { color: rgb(var(--c-muted-fg)); }
.field:hover { border-color: rgb(var(--c-fg) / 0.6); }
.field:focus-visible { outline-offset: 1px; border-color: rgb(var(--c-ring)); }
.field[aria-invalid="true"] { border-color: rgb(var(--c-danger)); border-width: 2px; }
.field-error { color: rgb(var(--c-danger)); font-size: 0.9rem; margin-top: 0.375rem; font-weight: 500; }

/* ---------- Movimento ridotto ---------- */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.01ms !important; animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Filtri attivi per la galleria */
.filter-btn.active {
  background-color: rgb(var(--c-accent));
  color: rgb(var(--c-on-accent));
  border-color: transparent;
}


/* Modal - assicura visibilità quando .hidden è rimossa */
#project-modal:not(.hidden) {
  display: flex !important;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  position: fixed !important;
  inset: 0 !important;
  z-index: 1000 !important;
}

/* Overlay - always visible when modal is open */
#project-modal:not(.hidden) > div[class*="bg-black"] {
  position: fixed !important;
  inset: 0 !important;
  background-color: rgba(0, 0, 0, 0.6) !important;
  backdrop-filter: blur(4px) !important;
  z-index: 50 !important;
  display: block !important;
}

/* Modal content wrapper - centered */
#project-modal:not(.hidden) > div[class*="relative"][class*="mx-auto"][class*="mt-10"] {
  position: relative !important;
  z-index: 51 !important;
  max-width: 56rem !important; /* max-w-4xl */
  width: 90% !important;
  margin-top: 2.5rem !important; /* mt-10 */
  margin-bottom: 2.5rem !important;
}

/* Modal card - ensure visible */
#project-modal:not(.hidden) div[class*="bg-surface"][class*="rounded-2xl"][class*="shadow-xl"] {
  display: block !important;
  visibility: visible !important;
  opacity: 1 !important;
  background-color: white !important;
}

/* Force overlay visibility */
#project-modal:not(.hidden) > div[class*="bg-black"] {
  position: fixed !important;
  inset: 0 !important;
  background-color: rgba(0, 0, 0, 0.6) !important;
  backdrop-filter: blur(4px) !important;
  z-index: 50 !important;
  display: block !important;
}

/* Modal thumbnails - ensure horizontal scroll works */
#modal-thumbs {
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: rgb(var(--c-accent)) transparent;
}
#modal-thumbs::-webkit-scrollbar {
  height: 6px;
}
#modal-thumbs::-webkit-scrollbar-track {
  background: transparent;
}
#modal-thumbs::-webkit-scrollbar-thumb {
  background-color: rgb(var(--c-accent));
  border-radius: 3px;
}
#modal-thumbs button {
  scroll-snap-align: start;
  flex-shrink: 0;
  position: relative;
  width: 72px;
  height: 72px;
}
#modal-thumbs button img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 0.5rem;
}

/* Modal body scroll styling */
#modal-body {
  scrollbar-width: thin;
  scrollbar-color: rgb(var(--c-muted-fg)) transparent;
}
#modal-body::-webkit-scrollbar {
  width: 6px;
}
#modal-body::-webkit-scrollbar-track {
  background: transparent;
}
#modal-body::-webkit-scrollbar-thumb {
  background-color: rgb(var(--c-muted-fg));
  border-radius: 3px;
}

/* Ensure modal card takes full available height */
#project-modal:not(.hidden) > div[class*="relative"][class*="mx-auto"][class*="mt-10"] > div[class*="bg-surface"] {
  max-height: calc(100vh - 5rem) !important;
  display: flex !important;
  flex-direction: column !important;
}
