:root{
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               Oxygen, Ubuntu, Cantarell, "Helvetica Neue", Arial, "Noto Sans",
               "Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji", sans-serif;
  --bg: #0b0b10;
  --bg-alt: #101017;
  --fg: #e7e7ec;
  --fg-muted: #b7b7c7;
  --card: #141421e6;
  --border: #2a2a3a;
  --hover-surface: rgba(255,255,255,.06);
  --accent: #7c5cff;
  --accent-2: #3fd1ff;
  --shadow: 0 10px 30px rgba(0,0,0,.35);
  --radius: 16px;
  --rule-radius: 12px;
  --rule-border: 1px;
  --measure: 72ch;
}

@media (prefers-color-scheme: light){
  :root{
    --bg: #f6f7fb;
    --bg-alt: #eef0f6;
    --fg: #1b1b22;
    --fg-muted: #4a4a5e;
    --card: #ffffffcc;
    --border: #e6e8f0;
    --hover-surface: rgba(0,0,0,.06);
    --shadow: 0 12px 32px rgba(46,58,89,.08);
  }
}

:root[data-theme="dark"]{
  --bg: #0b0b10;
  --bg-alt: #101017;
  --fg: #e7e7ec;
  --fg-muted: #b7b7c7;
  --card: #141421e6;
  --border: #2a2a3a;
  --hover-surface: rgba(255,255,255,.06);
  --shadow: 0 10px 30px rgba(0,0,0,.35);
}

:root[data-theme="light"]{
  --bg: #f6f7fb;
  --bg-alt: #eef0f6;
  --fg: #1b1b22;
  --fg-muted: #4a4a5e;
  --card: #ffffffcc;
  --border: #e6e8f0;
  --hover-surface: rgba(0,0,0,.06);
  --shadow: 0 12px 32px rgba(46,58,89,.08);
}

*{ box-sizing: border-box; }
html, body{ height: 100%; }
body{
  margin:0;
  font-family: var(--font-sans);
  color: var(--fg);
  background:
    radial-gradient(1200px 600px at 10% -20%, rgba(124,92,255,.18), transparent 60%),
    radial-gradient(1000px 800px at 110% 10%, rgba(63,209,255,.18), transparent 60%),
    linear-gradient(180deg, var(--bg), var(--bg-alt) 60%, var(--bg) 100%);
  background-repeat: no-repeat, no-repeat, no-repeat;
  background-size: auto, auto, 100% 100%;
  background-attachment: fixed, fixed, fixed;
}

/* Layout */
.wrap{ max-width: min(1100px, 92vw); margin: 48px auto 80px; padding: 0 1rem; }

.hero{ text-align: center; margin: 0 auto 28px; max-width: var(--measure); }
.logo{
  font-size: clamp(2rem, 3.2vw, 2.6rem);
  font-weight: 800; letter-spacing: .2px; line-height: 1.2;
  margin: 40px 0 10px;
}
.logo .em{
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.subtitle{ color: var(--fg-muted); margin: 0 auto; line-height: 1.6; }

/* Card */
.card{
  margin: 28px auto 0; background: var(--card);
  backdrop-filter: blur(6px);
  border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: clamp(16px, 2.8vw, 28px);
  max-width: var(--measure);
}
.proemio{
  font-size: 0.98rem; color: var(--fg-muted);
  border-left: 3px solid var(--accent); padding-left: 12px; margin: 6px 0 18px;
}

/* Ordened list and rules */
ol.rules{ list-style: none; margin: 0; padding: 0; }
.rules{
  display: grid; grid-template-columns: 1fr;
  gap: 14px; margin-top: 10px;
}
.rule{
  padding: 16px 14px 14px;
  border: 1px solid var(--border);
  border-radius: var(--rule-radius);
  background: linear-gradient(180deg, rgba(255,255,255,.03), transparent);
  position: relative;
  overflow: hidden;
  /* When we navigate by #anchor, it avoids "sticking" at the top and highlights */
  scroll-margin-top: 24px;
}
.rule::before{
  content:"";
  position:absolute;
  left: var(--rule-border);
  right: var(--rule-border);
  top: var(--rule-border);
  height: 3px;
  border-radius:
    calc(var(--rule-radius) - var(--rule-border))
    calc(var(--rule-radius) - var(--rule-border)) 0 0;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  opacity: .9;
}
.rule h2{
  margin: 6px 0 6px;
  font-size: 1.12rem;
  letter-spacing: .2px;
}
.rule p{
  margin: 0; line-height: 1.65; font-size: 0.995rem;
}

/* Highlight the anchor target (permalink #) */
.rule:target{
  outline: none;
  box-shadow: inset 0 0 0 2px var(--accent), 0 0 0 2px color-mix(in srgb, var(--accent) 25%, transparent);
}

/* Permalink # next to the title */
.permalink{ margin-left:.35rem; text-decoration:none; opacity:.7; }
.permalink:hover, .permalink:focus-visible{
  text-decoration: underline; text-decoration-style: dotted; opacity:1;
}

/* Footer */
.footer{ text-align: center; color: var(--fg-muted); font-size: .92rem; margin-top: 18px; }
.small{ font-size: .86rem; color: var(--fg-muted); }

/* Table of Content (ToC) */
.toc{
  display:flex;
  flex-wrap:wrap;
  gap:8px;
  margin:14px 0 8px;
  justify-content:center;
  align-items:center;
  width:100%;
}
.toc a{
  text-decoration:none; padding:6px 10px;
  border:1px solid var(--border); border-radius:999px;
  color: var(--fg); font-size:.9rem; transition: transform .06s ease;
}
.toc a:hover{ transform: translateY(-1px); }

/* Selection */
::selection{ background: #8f7bff33; }

/* Hero actions */
.hero-actions{ display:flex; justify-content:flex-end; gap:8px; margin:10px 0 0; }
@media (max-width: 640px){ .hero-actions{ justify-content:center; } }

/* Language selector */
.lang{ position:relative; }
.lang__button{
  display:flex; align-items:center; gap:8px;
  padding:10px 14px; min-height:44px; cursor:pointer;
  border:1px solid var(--border); border-radius:999px;
  background: linear-gradient(180deg, rgba(255,255,255,.06), rgba(255,255,255,.02));
  color:var(--fg); box-shadow: var(--shadow);
  transition: transform .06s ease;
}
.lang__button:hover{ transform: translateY(-1px); }
.lang__button:focus-visible{ outline:2px solid var(--accent); outline-offset:2px; }

.lang__icon{ width:18px; height:18px; opacity:.9; }
.lang__caret{ width:18px; height:18px; margin-left:4px; transition: transform .15s ease; }
.lang[data-open="true"] .lang__caret{ transform: rotate(180deg); }

.lang__list{
  position:absolute; right:0; margin-top:8px; z-index:20;
  width:max-content; min-width:220px; padding:6px;
  border:1px solid var(--border); border-radius:12px;
  background: var(--card); backdrop-filter: blur(6px);
  box-shadow: var(--shadow); list-style:none; display:none;
}
.lang[data-open="true"] .lang__list{ display:block; }

.lang__list li a{
  display:flex; align-items:center; gap:8px;
  padding:10px 12px; border-radius:10px; text-decoration:none;
  color: var(--fg);
}
.lang__list a[aria-current="page"]{ border:1px dashed var(--border); }
.lang__list li a:hover,
.lang__list li a:focus-visible{
  background: var(--hover-surface);
  outline:none;
}

.lang__fallback{ margin-top:8px; text-align:right; color:var(--fg-muted); }

/* Theme button */
.theme__button{
  display:flex; align-items:center; gap:8px;
  padding:10px 14px; min-height:44px; cursor:pointer;
  border:1px solid var(--border); border-radius:999px;
  background: linear-gradient(180deg, rgba(255,255,255,.06), rgba(255,255,255,.02));
  color:var(--fg); box-shadow: var(--shadow);
  transition: transform .06s ease;
}
.theme__button:hover{ transform: translateY(-1px); }
.theme__button:focus-visible{ outline:2px solid var(--accent); outline-offset:2px; }
.theme__icon{ width:18px; height:18px; opacity:.9; }
.theme__label{ font-weight:600; }

/* Show only the icon consistent with the current theme */
:root[data-theme="dark"]  .theme__icon-sun{ display:inline-block; }
:root[data-theme="dark"]  .theme__icon-moon{ display:none; }
:root[data-theme="light"] .theme__icon-sun{ display:none; }
:root[data-theme="light"] .theme__icon-moon{ display:inline-block; }

/* No user preference (auto by OS): display icon according to media query */
@media (prefers-color-scheme: dark){
  :root:not([data-theme]) .theme__icon-sun{ display:inline-block; }
  :root:not([data-theme]) .theme__icon-moon{ display:none; }
}
@media (prefers-color-scheme: light){
  :root:not([data-theme]) .theme__icon-sun{ display:none; }
  :root:not([data-theme]) .theme__icon-moon{ display:inline-block; }
}

/* Visible focus */
.toc a:focus-visible,
.lang__list a:focus-visible,
.lang__button:focus-visible,
.theme__button:focus-visible{
  outline:2px solid var(--accent);
  outline-offset:2px;
  border-radius:8px;
}

/* A11y utilities */
.visually-hidden{
  position:absolute !important; width:1px;height:1px; padding:0;margin:-1px;
  overflow:hidden; clip:rect(0 0 0 0); white-space:nowrap; border:0;
}

/* Skip link */
.skip-link{
  position:absolute; left:-9999px; top:auto; width:1px; height:1px; overflow:hidden;
}
.skip-link:focus{
  left:16px; top:12px; width:auto; height:auto; padding:8px 12px; border-radius:8px;
  background:#000; color:#fff; z-index:9999;
}

/* Respects movement preference */
@media (prefers-reduced-motion: reduce){
  *{ animation:none !important; transition:none !important; }
  .lang__button:hover,
  .toc a:hover,
  .theme__button:hover{ transform:none !important; }
}
