/* ============================================================
   Enciclopedia Cannabis — Indice botanico theme
   Fraunces (display) + Source Sans 3 (body) + IBM Plex Mono (utility)
   Italian botanical reference with specimen tabs and editorial schede
   Design system: design-system/enciclopediacannabis/
   ============================================================ */

/* ============================================================
   Design Tokens
   ============================================================ */
:root {
  /* Colors */
  --color-primary: #173f35;
  --color-on-primary: #fffdf6;
  --color-secondary: #9d4e36;
  --color-accent: #e4b83f;
  --color-background: #f6f2e8;
  --color-foreground: #17201d;
  --color-muted: #5e6964;
  --color-border: #b8b8a8;
  --color-destructive: #a52d2d;
  --color-ring: #0b6e61;
  --color-surface: #fffdf6;
  --color-tip-surface: #e7f0e5;
  --color-warning-surface: #fbedd0;

  /* Typography scale — responsive via media queries */
  --type-display: 44px;
  --type-h1: 38px;
  --type-h2: 30px;
  --type-h3: 24px;
  --type-h4: 20px;
  --type-h5: 18px;
  --type-h6: 16px;
  --type-lead: 20px;
  --type-body: 17px;
  --type-ui: 16px;
  --type-small: 14px;
  --type-caption: 13px;
  --type-kicker: 12px;

  /* Spacing */
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
  --space-2xl: 3rem;
  --space-3xl: 4.5rem;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgb(23 32 29 / 0.08);
  --shadow-md: 0 8px 20px rgb(23 32 29 / 0.1);
  --shadow-lg: 0 16px 36px rgb(23 32 29 / 0.12);
  --shadow-xl: 0 28px 64px rgb(23 32 29 / 0.16);

  /* Radii */
  --radius-sm: 3px;
  --radius-md: 8px;
  --radius-lg: 16px;

  /* EC-specific notch clip-path for specimen tabs */
  --ec-notch: polygon(0 0, calc(100% - 18px) 0, 100% 18px, 100% 100%, 0 100%);

  /* Fonts */
  --font-display: "Fraunces", Georgia, serif;
  --font-body: "Source Sans 3", system-ui, -apple-system, sans-serif;
  --font-utility: "IBM Plex Mono", "Courier New", monospace;

  /* Layout */
  --rail-width-desktop: 88px;
  --rail-width-wide: 112px;
  --wrap-max: 1440px;
  --content-max: 1240px;
  --prose-max: 45rem;
}

@media (min-width: 64rem) {
  :root {
    --type-display: 72px;
    --type-h1: 56px;
    --type-h2: 38px;
    --type-h3: 28px;
    --type-h4: 22px;
    --type-lead: 22px;
    --type-body: 18px;
  }
}

@media (min-width: 90rem) {
  :root {
    --rail-width-desktop: 112px;
  }
}

/* ============================================================
   Base & Reset
   ============================================================ */
*, *::before, *::after {
  box-sizing: border-box;
}

* {
  margin: 0;
  padding: 0;
}

html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

body {
  background: var(--color-background);
  color: var(--color-foreground);
  font-family: var(--font-body);
  font-size: var(--type-body);
  line-height: 1.68;
  min-height: 100vh;
}

img, picture, video, canvas, svg {
  display: block;
  max-width: 100%;
}

input, button, textarea, select {
  font: inherit;
}

h1, h2, h3, h4, h5, h6 {
  overflow-wrap: break-word;
  font-family: var(--font-display);
  font-weight: 700;
  line-height: 1.12;
}

a {
  color: inherit;
  text-decoration: none;
}

/* ============================================================
   Focus & Interaction
   ============================================================ */
:where(a, button, input, textarea, summary):focus-visible {
  outline: 3px solid var(--color-ring);
  outline-offset: 3px;
}

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

/* ============================================================
   Skip Link
   ============================================================ */
.ec-skip-link {
  background: var(--color-primary);
  color: var(--color-on-primary);
  display: inline-block;
  font-weight: 700;
  left: 1rem;
  padding: 0.75rem 1.25rem;
  position: absolute;
  top: 1rem;
  transform: translateY(-200%);
  transition: transform 200ms ease-out;
  z-index: 9999;
}

.ec-skip-link:focus {
  transform: translateY(0);
}

/* ============================================================
   Desktop Index Rail (≥1024px)
   ============================================================ */
.ec-rail {
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  display: none;
  height: 100vh;
  left: 0;
  position: fixed;
  top: 0;
  width: var(--rail-width-desktop);
  z-index: 100;
}

@media (min-width: 64rem) {
  .ec-rail {
    display: flex;
    flex-direction: column;
  }

  body {
    padding-left: var(--rail-width-desktop);
  }
}

.ec-rail__inner {
  display: flex;
  flex-direction: column;
  padding: var(--space-lg) var(--space-md);
  height: 100%;
}

.ec-rail__brand {
  display: block;
  margin-bottom: var(--space-2xl);
}

.ec-mark {
  display: block;
}

.ec-index-nav {
  display: flex;
  flex-direction: column;
  flex: 1;
  gap: var(--space-sm);
}

.ec-index-nav__link {
  color: var(--color-foreground);
  display: inline-flex;
  font-size: var(--type-ui);
  font-weight: 600;
  min-height: 44px;
  padding: 0.75rem 0;
  position: relative;
  text-decoration: none;
  transition: color 180ms ease-out;
}

.ec-index-nav__link:hover {
  color: var(--color-primary);
}

.ec-index-nav__link[aria-current="page"] {
  color: var(--color-primary);
}

.ec-index-nav__link[aria-current="page"]::after {
  background: var(--color-accent);
  bottom: 0;
  content: "";
  height: 4px;
  left: 0;
  position: absolute;
  width: 2.5rem;
}

.ec-rail__search {
  margin-top: auto;
}

.ec-icon-action {
  align-items: center;
  background: transparent;
  border: 1px solid transparent;
  color: var(--color-foreground);
  cursor: pointer;
  display: inline-flex;
  height: 44px;
  justify-content: center;
  padding: 0;
  transition: background-color 180ms ease-out, border-color 180ms ease-out;
  width: 44px;
}

.ec-icon-action:hover {
  background: var(--color-background);
  border-color: var(--color-border);
}

/* ============================================================
   Mobile Masthead
   ============================================================ */
.ec-mast {
  background: var(--color-primary);
  color: var(--color-on-primary);
  position: relative;
  z-index: 90;
}

@media (min-width: 64rem) {
  .ec-mast {
    display: none;
  }
}

.ec-mast__inner {
  align-items: center;
  display: flex;
  justify-content: space-between;
  min-height: 52px;
  padding: var(--space-sm) var(--space-lg);
}

.ec-mast__wordmark {
  color: var(--color-on-primary);
  font-family: var(--font-utility);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-decoration: none;
}

.ec-mast__menu-toggle {
  align-items: center;
  background: transparent;
  border: 1px solid transparent;
  color: var(--color-on-primary);
  cursor: pointer;
  display: flex;
  height: 44px;
  justify-content: center;
  padding: 0;
  width: 44px;
}

.ec-mobile-nav {
  background: var(--color-primary);
  border-top: 1px solid rgb(255 253 246 / 0.2);
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
  padding: var(--space-md) var(--space-lg);
}

.ec-mobile-nav a {
  color: var(--color-on-primary);
  display: block;
  font-size: var(--type-ui);
  font-weight: 600;
  min-height: 44px;
  padding: 0.75rem 0;
  text-decoration: none;
}

.ec-mobile-nav a[aria-current="page"] {
  text-decoration: underline;
  text-decoration-color: var(--color-accent);
  text-decoration-thickness: 0.14em;
  text-underline-offset: 0.18em;
}

.ec-mobile-nav__search {
  align-items: center;
  background: transparent;
  border: 1px solid var(--color-on-primary);
  color: var(--color-on-primary);
  cursor: pointer;
  display: flex;
  font-weight: 600;
  gap: var(--space-sm);
  justify-content: center;
  margin-top: var(--space-md);
  min-height: 44px;
  padding: 0.75rem 1.125rem;
}

/* ============================================================
   Main Content Area
   ============================================================ */
main {
  min-height: 50vh;
  padding: clamp(1.25rem, 4vw, 2rem);
}

@media (min-width: 48rem) {
  main {
    padding: clamp(2rem, 5vw, 3rem);
  }
}

/* ============================================================
   Footer
   ============================================================ */
.ec-footer {
  border-top: 1px solid var(--color-border);
  margin-top: var(--space-3xl);
  padding: var(--space-2xl) clamp(1.25rem, 4vw, 2rem);
}

.ec-footer__inner {
  display: grid;
  gap: var(--space-2xl);
  grid-template-columns: 1fr;
  max-width: var(--content-max);
}

@media (min-width: 48rem) {
  .ec-footer__inner {
    grid-template-columns: 1.5fr 1fr;
  }
}

@media (min-width: 64rem) {
  .ec-footer__inner {
    grid-template-columns: 2fr 1fr 1fr;
  }
}

.ec-footer__brand {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.ec-footer__brand strong {
  color: var(--color-primary);
  font-size: var(--type-h4);
  font-family: var(--font-display);
}

.ec-footer__brand p {
  color: var(--color-muted);
  font-size: var(--type-ui);
  max-width: 32rem;
}

.ec-footer__logo svg {
  display: block;
}

.ec-footer__nav {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.ec-footer__nav h2 {
  color: var(--color-primary);
  font-size: var(--type-ui);
  font-weight: 700;
  letter-spacing: 0.02em;
  margin-bottom: var(--space-xs);
  text-transform: uppercase;
}

.ec-footer__nav a {
  color: var(--color-foreground);
  font-size: var(--type-ui);
  text-decoration: none;
  transition: color 180ms ease-out;
}

.ec-footer__nav a:hover {
  color: var(--color-primary);
}

.ec-footer__count {
  color: var(--color-muted);
  font-size: var(--type-small);
}

.ec-footer__legal {
  color: var(--color-muted);
  font-size: var(--type-small);
  margin-top: var(--space-lg);
}

@media (min-width: 64rem) {
  .ec-footer__legal {
    grid-column: 1 / -1;
    margin-top: var(--space-xl);
  }
}

/* ============================================================
   Typography Components
   ============================================================ */
.ec-lead {
  color: var(--color-foreground);
  font-family: var(--font-display);
  font-size: var(--type-lead);
  font-weight: 600;
  line-height: 1.5;
}

/* ============================================================
   Links & Text Styles
   ============================================================ */
.ec-prose a,
.ec-text-link {
  color: var(--color-primary);
  text-decoration: underline;
  text-decoration-color: var(--color-accent);
  text-decoration-thickness: 0.14em;
  text-underline-offset: 0.18em;
  transition: text-decoration-thickness 180ms ease-out;
}

.ec-prose a:visited {
  color: #5f3a61;
}

.ec-prose a:hover,
.ec-text-link:hover {
  text-decoration-thickness: 0.22em;
}

/* ============================================================
   Buttons & Actions
   ============================================================ */
.ec-action {
  align-items: center;
  border: 1px solid transparent;
  cursor: pointer;
  display: inline-flex;
  font-family: var(--font-body);
  font-size: var(--type-ui);
  font-weight: 700;
  gap: var(--space-sm);
  justify-content: center;
  line-height: 1;
  min-height: 44px;
  padding: 0.75rem 1.125rem;
  text-decoration: none;
  transition: background-color 180ms ease-out, border-color 180ms ease-out, color 180ms ease-out, transform 180ms ease-out;
}

.ec-action--primary {
  background: var(--color-primary);
  color: var(--color-on-primary);
}

.ec-action--primary:hover {
  background: #0f3028;
  transform: translateY(-1px);
}

.ec-action--secondary {
  background: transparent;
  border-color: var(--color-primary);
  color: var(--color-primary);
}

.ec-action--secondary:hover {
  background: #e7ece7;
}

.ec-action--text {
  color: var(--color-primary);
  padding-inline: 0.5rem;
}

.ec-action[disabled] {
  cursor: not-allowed;
  opacity: 0.48;
  transform: none;
}

/* ============================================================
   Specimen Tabs & Badges
   ============================================================ */
.ec-specimen-tab {
  background: var(--color-primary);
  clip-path: var(--ec-notch);
  color: var(--color-on-primary);
  display: inline-flex;
  font-family: var(--font-utility);
  font-size: var(--type-kicker);
  font-weight: 600;
  gap: var(--space-sm);
  letter-spacing: 0.08em;
  line-height: 1.2;
  padding: 0.65rem 1.45rem 0.65rem 0.75rem;
  text-transform: uppercase;
}

.ec-topic-chip {
  border: 1px solid var(--color-border);
  border-radius: 999px;
  color: var(--color-primary);
  display: inline-flex;
  font-size: var(--type-small);
  padding: 0.45rem 0.75rem;
  text-decoration: none;
  transition: background-color 180ms ease-out, border-color 180ms ease-out;
}

.ec-topic-chip:hover {
  background: var(--color-surface);
  border-color: var(--color-primary);
}

/* ============================================================
   Story Sheets & Listing Surfaces
   ============================================================ */
.ec-story-sheet {
  border-top: 1px solid var(--color-border);
  display: grid;
  gap: var(--space-lg);
  grid-template-columns: minmax(8rem, 0.8fr) minmax(0, 1.6fr);
  padding-block: var(--space-xl);
}

.ec-story-sheet__media {
  aspect-ratio: 3 / 2;
  background: #dfe3d8;
  overflow: hidden;
}

.ec-story-sheet__media img {
  height: 100%;
  object-fit: cover;
  transition: transform 240ms ease-out;
  width: 100%;
}

.ec-story-sheet:hover img {
  transform: scale(1.018);
}

.ec-story-sheet__title {
  color: var(--color-foreground);
  font-family: var(--font-display);
  font-size: var(--type-h3);
  margin: 0 0 var(--space-sm);
}

@media (max-width: 47.99rem) {
  .ec-story-sheet {
    grid-template-columns: 1fr;
  }
}

/* ============================================================
   Breadcrumbs
   ============================================================ */
.ec-breadcrumbs {
  font-size: var(--type-small);
  margin-bottom: var(--space-lg);
}

.ec-breadcrumbs ol {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  list-style: none;
  margin: 0;
  padding: 0;
}

.ec-breadcrumbs li:not(:last-child)::after {
  color: var(--color-muted);
  content: "/";
  margin-left: 0.4rem;
}

.ec-breadcrumbs a {
  color: var(--color-primary);
  text-decoration: none;
}

.ec-breadcrumbs a:hover {
  text-decoration: underline;
}

.ec-breadcrumbs [aria-current="page"] {
  color: var(--color-muted);
}

/* ============================================================
   Pagination
   ============================================================ */
.ec-pagination {
  border-top: 1px solid var(--color-border);
  display: flex;
  gap: var(--space-sm);
  justify-content: space-between;
  padding-top: var(--space-xl);
}

.ec-pagination a,
.ec-pagination span {
  align-items: center;
  color: var(--color-foreground);
  display: inline-flex;
  justify-content: center;
  min-height: 44px;
  min-width: 44px;
  padding: 0.5rem 0.75rem;
  text-decoration: none;
  transition: background-color 180ms ease-out;
}

.ec-pagination a:hover {
  background: var(--color-surface);
}

.ec-pagination [aria-current="page"] {
  background: var(--color-primary);
  color: var(--color-on-primary);
}

/* ============================================================
   Prose Content (Article Body)
   ============================================================ */
.ec-prose {
  font-size: var(--type-body);
  line-height: 1.72;
  max-width: var(--prose-max);
}

.ec-prose > * {
  margin-block: 0;
}

.ec-prose > * + * {
  margin-top: 1.35em;
}

.ec-prose :where(h2, h3, h4) {
  color: var(--color-foreground);
  font-family: var(--font-display);
  scroll-margin-top: 6rem;
}

.ec-prose h2 {
  font-size: var(--type-h2);
  margin-top: 2.1em;
}

.ec-prose h3 {
  font-size: var(--type-h3);
  margin-top: 1.8em;
}

.ec-prose h4 {
  font-size: var(--type-h4);
  margin-top: 1.6em;
}

.ec-prose :where(ul, ol) {
  padding-left: 1.35em;
}

.ec-prose li + li {
  margin-top: 0.45em;
}

.ec-prose :where(ul, ol) :where(ul, ol) {
  margin-top: 0.45em;
}

.ec-prose blockquote {
  border-left: 6px solid var(--color-secondary);
  font-family: var(--font-display);
  font-size: 1.25em;
  margin-inline: 0;
  padding: 0.5rem 0 0.5rem 1.5rem;
}

.ec-prose code {
  background: #e8e4d9;
  border-radius: var(--radius-sm);
  font-family: var(--font-utility);
  font-size: 0.86em;
  padding: 0.12em 0.3em;
}

.ec-prose pre {
  background: #17201d;
  color: #f6f2e8;
  overflow-x: auto;
  padding: var(--space-lg);
}

.ec-prose pre code {
  background: transparent;
  color: inherit;
  padding: 0;
}

.ec-prose hr {
  border: 0;
  border-top: 1px solid var(--color-border);
  margin-block: var(--space-2xl);
}

/* ============================================================
   Images & Captions
   ============================================================ */
.ec-prose .content-image {
  margin-block: var(--space-2xl);
}

.ec-prose .content-image img {
  aspect-ratio: auto;
  display: block;
  height: auto;
  max-width: 100%;
  width: 100%;
}

.ec-prose .content-image figcaption {
  border-left: 3px solid var(--color-accent);
  color: var(--color-muted);
  font-size: var(--type-caption);
  margin-top: var(--space-sm);
  padding-left: var(--space-sm);
}

/* ============================================================
   Callouts
   ============================================================ */
.ec-prose .callout {
  border: 1px solid var(--color-border);
  border-left-width: 8px;
  padding: var(--space-lg);
}

.ec-prose .callout::before {
  display: block;
  font-family: var(--font-utility);
  font-size: var(--type-kicker);
  font-weight: 600;
  letter-spacing: 0.08em;
  line-height: 1.2;
  margin-bottom: var(--space-sm);
  text-transform: uppercase;
}

.callout--info {
  background: #e8efed;
  border-left-color: #286a70;
}

.callout--info::before {
  content: "Informazione";
}

.callout--tip {
  background: var(--color-tip-surface);
  border-left-color: #3e7045;
}

.callout--tip::before {
  content: "Consiglio";
}

.callout--warning {
  background: var(--color-warning-surface);
  border-left-color: #a66216;
}

.callout--warning::before {
  content: "Attenzione";
}

.callout--note {
  background: #eee9f1;
  border-left-color: #70527e;
}

.callout--note::before {
  content: "Nota";
}

/* ============================================================
   Tables
   ============================================================ */
.ec-table-scroll {
  max-width: 100%;
  overflow-x: auto;
}

.ec-table-scroll:focus-visible {
  outline: 3px solid var(--color-ring);
  outline-offset: 2px;
}

.ec-prose table {
  border-collapse: collapse;
  font-size: 1rem;
  min-width: 36rem;
  width: 100%;
}

.ec-prose :where(th, td) {
  border-bottom: 1px solid var(--color-border);
  padding: 0.75rem;
  text-align: left;
  vertical-align: top;
}

.ec-prose th {
  background: #e8e4d9;
  font-weight: 700;
}

.ec-prose tbody tr:nth-child(even) {
  background: rgb(255 253 246 / 0.55);
}

/* ============================================================
   Forms & Fields
   ============================================================ */
.ec-field {
  display: grid;
  gap: var(--space-sm);
}

.ec-field label {
  font-weight: 700;
}

.ec-field :where(input, textarea) {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  color: var(--color-foreground);
  font: inherit;
  min-height: 48px;
  padding: 0.75rem 0.875rem;
  transition: border-color 180ms ease-out;
}

.ec-field :where(input, textarea):focus {
  border-color: var(--color-primary);
}

.ec-field [aria-invalid="true"] {
  border-color: var(--color-destructive);
}

.ec-field__error {
  color: var(--color-destructive);
  font-size: var(--type-small);
  font-weight: 600;
}

/* ============================================================
   Structured Modules
   ============================================================ */

/* Recipe Summary */
.recipe-summary {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  clip-path: var(--ec-notch);
  padding: var(--space-xl);
}

.recipe-meta {
  display: grid;
  gap: var(--space-md);
  grid-template-columns: repeat(auto-fit, minmax(8rem, 1fr));
}

.recipe-meta div {
  border-top: 3px solid var(--color-accent);
  padding-top: var(--space-sm);
}

.recipe-meta dt {
  color: var(--color-muted);
  font-size: var(--type-small);
}

.recipe-meta dd {
  font-weight: 700;
  margin: 0.25rem 0 0;
}

/* FAQ Accordion */
.faq-item {
  border-top: 1px solid var(--color-border);
}

.faq-item summary {
  cursor: pointer;
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 700;
  list-style: none;
  min-height: 56px;
  padding: 1rem 3rem 1rem 0;
  position: relative;
}

.faq-item summary::after {
  content: "+";
  font-family: var(--font-utility);
  position: absolute;
  right: 0.5rem;
  top: 1rem;
}

.faq-item[open] summary::after {
  content: "−";
}

.faq-item__answer {
  max-width: var(--prose-max);
  padding: 0 3rem 1.5rem 0;
}

/* How-to Steps */
.howto-steps {
  counter-reset: ec-step;
  list-style: none;
  padding: 0;
}

.howto-step {
  counter-increment: ec-step;
  display: grid;
  gap: var(--space-md);
  grid-template-columns: 3.5rem 1fr;
  padding-block: var(--space-lg);
}

.howto-step::before {
  align-items: center;
  background: var(--color-primary);
  color: var(--color-on-primary);
  content: counter(ec-step, decimal-leading-zero);
  display: flex;
  font-family: var(--font-utility);
  height: 3rem;
  justify-content: center;
}

/* Responsive utilities for homepage */
@media (max-width: 767px) {
  section > div > a[style*="grid-template-columns"] {
    display: block !important;
  }
  
  section > div > a[style*="grid-template-columns"] > div:first-child {
    margin-bottom: var(--space-lg);
  }
}
