/* ============================================
   Tarczyca - design system
   Paleta "motyl tarczycy": szmaragd + bursztyn + kość słoniowa
   Typografia: Spectral (display) + Archivo (body)
   ============================================ */

:root {
  /* Light */
  --bg: #f4efe4;
  --panel: #ece4d2;
  --panel2: #e4dac4;
  --border-strong: #d6c9ac;
  --border-soft: rgba(154, 65, 6, .14);
  --text: #22302a;
  --text-secondary: #55635c;
  --accent: #b45309;
  --accent-strong: #9a4106;
  --accent-subtle: rgba(180, 83, 9, .12);
  --accent2: #0f766e;
  --accent2-subtle: rgba(15, 118, 110, .12);
  --card-bg: #faf6ec;
  --code-bg: #eae2cf;
  --shadow: 0 1px 2px rgba(34, 48, 42, .06), 0 8px 24px rgba(34, 48, 42, .07);
  --shadow-hover: 0 2px 4px rgba(34, 48, 42, .08), 0 14px 32px rgba(34, 48, 42, .12);
  --header-bg: rgba(244, 239, 228, .92);
  --header-glow: linear-gradient(90deg, transparent, rgba(180, 83, 9, .35), transparent);
  --hero-grad: linear-gradient(135deg, #0f2e22 0%, #14513c 55%, #0c1f17 100%);
  --hero-text: #f2ecdd;
  --hero-dim: #b9c4b8;
  --hero-accent: #f5a524;
  --radius: 14px;
  --transition: all .2s ease-out;
  --font-display: 'Spectral', Georgia, serif;
  --font-body: 'Archivo', 'Segoe UI', system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c1f17;
    --panel: #12291f;
    --panel2: #183526;
    --border-strong: #2c4a3b;
    --border-soft: rgba(245, 165, 36, .16);
    --text: #ece6d8;
    --text-secondary: #a9b4a9;
    --accent: #f59e0b;
    --accent-strong: #fbbf24;
    --accent-subtle: rgba(245, 158, 11, .14);
    --accent2: #2dd4bf;
    --accent2-subtle: rgba(45, 212, 191, .12);
    --card-bg: #10241b;
    --code-bg: #173127;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .35);
    --shadow-hover: 0 2px 4px rgba(0, 0, 0, .35), 0 14px 32px rgba(0, 0, 0, .5);
    --header-bg: rgba(12, 31, 23, .92);
    --header-glow: linear-gradient(90deg, transparent, rgba(245, 158, 11, .28), transparent);
    --hero-grad: linear-gradient(135deg, #081711 0%, #0f2e22 55%, #0a1e15 100%);
    --hero-text: #f2ecdd;
    --hero-dim: #aebaa9;
    --hero-accent: #f5a524;
  }
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html {
  scroll-behavior: smooth;
  overflow-x: clip;
}

body {
  font-family: var(--font-body);
  font-size: 17px;
  line-height: 1.7;
  color: var(--text);
  background: var(--bg);
  /* Dwa subtelne radial-gradient na przeciwległych rogach */
  background-image:
    radial-gradient(ellipse 900px 500px at 110% -10%, rgba(180, 83, 9, .07), transparent 60%),
    radial-gradient(ellipse 800px 500px at -10% 110%, rgba(15, 118, 110, .08), transparent 60%);
  background-attachment: fixed;
  min-height: 100vh;
  transition: background-color .3s ease, color .3s ease;
}

a { color: var(--accent-strong); text-decoration: none; }
a:hover { text-decoration: underline; }
@media (prefers-color-scheme: dark) {
  a { color: var(--accent-strong); }
}

img { max-width: 100%; height: auto; }

.skip-link {
  position: absolute; left: -9999px; top: 0;
  background: var(--accent); color: #fff;
  padding: .6em 1.2em; border-radius: 0 0 8px 0;
  z-index: 300; font-weight: 600;
}
.skip-link:focus { left: 0; }

/* ============ HEADER ============ */
.app-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 62px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 22px;
  background: var(--header-bg);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-soft);
  z-index: 100;
}
.app-header::after {
  content: '';
  position: absolute;
  left: 0; right: 0; bottom: -1px;
  height: 2px;
  background: var(--header-glow);
  opacity: .3;
  pointer-events: none;
}

.logo-mark { font-size: 1.45rem; line-height: 1; }
.logo-text { font-family: var(--font-display); font-weight: 700; font-size: 1.22rem; letter-spacing: .01em; white-space: nowrap; }
.logo-text a { color: var(--text); }
.logo-text a:hover { text-decoration: none; }

.header-search {
  position: relative;
  margin-left: auto;
  width: min(420px, 42vw);
}
.search-icon {
  position: absolute;
  left: 12px; top: 50%;
  transform: translateY(-50%);
  font-size: .9rem;
  opacity: .55;
  pointer-events: none;
}
.header-search input {
  width: 100%;
  padding: 9px 14px 9px 36px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--card-bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: .9rem;
  outline: none;
  transition: border-color .2s ease, box-shadow .2s ease;
}
.header-search input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}

#search-results {
  position: absolute;
  top: calc(100% + 8px);
  left: 0; right: 0;
  background: var(--card-bg);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  box-shadow: var(--shadow-hover);
  overflow: hidden;
  display: none;
  z-index: 200;
}
#search-results a {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-soft);
  color: var(--text);
}
#search-results a:last-child { border-bottom: none; }
#search-results a:hover { background: var(--accent-subtle); text-decoration: none; }
#search-results a > span { font-size: 1.1rem; }
#search-results strong { font-size: .88rem; display: block; }
.sr-excerpt { font-size: .76rem; color: var(--text-secondary); display: block; }

.mobile-menu-btn {
  display: none;
  background: none;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  font-size: 1.15rem;
  width: 40px; height: 40px;
  cursor: pointer;
  color: var(--text);
  flex-shrink: 0;
}

/* ============ SIDEBAR ============ */
.sidebar {
  position: fixed;
  top: 62px; left: 0; bottom: 0;
  width: 300px;
  overflow-y: auto;
  padding: 20px 16px 40px;
  background: var(--panel);
  border-right: 1px solid var(--border-soft);
  z-index: 90;
  scrollbar-width: thin;
}
.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }

.sidebar-nav { list-style: none; }
.sidebar-nav li a {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 12px;
  margin: 1px 0;
  border-radius: 8px;
  color: var(--text);
  font-size: .9rem;
  line-height: 1.4;
  transition: var(--transition);
}
.sidebar-nav li a:hover {
  background: var(--accent-subtle);
  text-decoration: none;
  transform: translateX(2px);
}
.sidebar-nav li a.active {
  background: var(--accent-subtle);
  color: var(--accent-strong);
  font-weight: 600;
  box-shadow: inset 3px 0 0 var(--accent);
}
.nav-section {
  margin-top: 18px;
  padding: 0 12px 4px;
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--text-secondary);
}
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .5);
  z-index: 85;
}

/* ============ MAIN ============ */
.main-content {
  margin-left: 300px;
  padding: 84px 40px 70px;
  max-width: 1060px;
  min-height: 100vh;
}

.loading { display: flex; justify-content: center; padding-top: 100px; }
.spinner {
  width: 40px; height: 40px;
  border: 3px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============ ARTICLE ============ */
.content-article {
  animation: fadeUp .28s ease-out;
}
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.breadcrumbs {
  font-size: .8rem;
  color: var(--text-secondary);
  margin-bottom: 14px;
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}
.breadcrumbs a { color: var(--text-secondary); }
.breadcrumbs a:hover { color: var(--accent-strong); }

.content-article h1 {
  font-family: var(--font-display);
  font-size: clamp(1.75rem, 3.4vw, 2.4rem);
  font-weight: 700;
  line-height: 1.22;
  margin: 0 0 10px;
  text-wrap: balance;
  color: var(--text);
}
.content-article h2 {
  font-family: var(--font-display);
  font-size: 1.42rem;
  font-weight: 700;
  margin: 1.7em 0 .55em;
  padding-bottom: .28em;
  border-bottom: 2px solid var(--border-soft);
  color: var(--text);
  text-wrap: balance;
  scroll-margin-top: 84px;
}
.content-article h3 {
  font-family: var(--font-display);
  font-size: 1.12rem;
  font-weight: 600;
  margin: 1.35em 0 .45em;
  color: var(--text);
  text-wrap: balance;
  scroll-margin-top: 84px;
}
.content-article p { margin: .8em 0; }
.content-article ul, .content-article ol { margin: .8em 0 .8em 1.4em; }
.content-article li { margin: .35em 0; }
.content-article strong { font-weight: 600; }

.article-meta {
  color: var(--text-secondary);
  font-size: .92rem;
  margin-bottom: 18px;
  padding: 10px 14px;
  background: var(--accent2-subtle);
  border-left: 3px solid var(--accent2);
  border-radius: 0 8px 8px 0;
}

/* TOC */
.article-toc {
  background: var(--panel);
  border: 1px solid var(--border-soft);
  border-radius: 12px;
  padding: 16px 18px;
  margin: 1.4em 0 1.8em;
}
.article-toc h3 {
  font-size: .78rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin: 0 0 10px;
}
.article-toc a {
  display: block;
  padding: 4px 0;
  color: var(--text);
  font-size: .88rem;
  line-height: 1.45;
}
.article-toc a:hover { color: var(--accent-strong); }
.article-toc .toc-h3 { padding-left: 16px; font-size: .83rem; color: var(--text-secondary); }

/* Boxes */
.info-box {
  background: var(--accent2-subtle);
  border-left: 4px solid var(--accent2);
  border-radius: 0 10px 10px 0;
  padding: 14px 18px;
  margin: 1.3em 0;
}
.info-box p { margin: .3em 0; }
.warning-box {
  background: var(--accent-subtle);
  border-left: 4px solid var(--accent);
  border-radius: 0 10px 10px 0;
  padding: 14px 18px;
  margin: 1.3em 0;
}
.warning-box p { margin: .3em 0; }
.key-takeaways {
  background: var(--panel);
  border: 1px solid var(--border-soft);
  border-radius: 12px;
  padding: 16px 20px;
  margin: 1.4em 0;
}
.key-takeaways h3 {
  font-size: .78rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin: 0 0 8px;
}
.key-takeaways ul { margin: .3em 0 .3em 1.2em; }
.key-takeaways li { margin: .25em 0; font-size: .95rem; }
.takeaway-box {
  background: var(--panel);
  border-radius: 12px;
  padding: 16px 20px;
  margin: 1.4em 0;
  border: 1px solid var(--border-soft);
}

/* Tables */
.table-responsive {
  overflow-x: auto;
  margin: 1.4em 0;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
}
.table-responsive table { width: 100%; border-collapse: collapse; min-width: 480px; }
.table-responsive th, .table-responsive td {
  padding: 10px 14px;
  text-align: left;
  font-size: .9rem;
  border-bottom: 1px solid var(--border-soft);
  vertical-align: top;
}
.table-responsive th {
  background: var(--panel2);
  font-weight: 600;
  font-size: .85rem;
  letter-spacing: .02em;
  white-space: nowrap;
}
.table-responsive tr:last-child td { border-bottom: none; }
.table-responsive tr:nth-child(even) td { background: rgba(0, 0, 0, .02); }
@media (prefers-color-scheme: dark) {
  .table-responsive tr:nth-child(even) td { background: rgba(255, 255, 255, .025); }
}
.compare-table th:first-child { min-width: 160px; }
.error-table { width: 100%; border-collapse: collapse; }
.error-table th, .error-table td {
  padding: 10px 14px;
  text-align: left;
  font-size: .9rem;
  border-bottom: 1px solid var(--border-soft);
}

/* FAQ */
.faq-item {
  background: var(--panel);
  border: 1px solid var(--border-soft);
  border-radius: 12px;
  padding: 16px 20px;
  margin: 12px 0;
}
.faq-item h3 { margin: 0 0 .45em; font-size: 1.02rem; color: var(--accent-strong); }
.faq-item p { margin: .3em 0; }

/* Glossary */
dl.glossary { margin: 1.2em 0; }
dl.glossary dt { font-weight: 600; margin-top: 1.15em; color: var(--text); }
dl.glossary dt:first-child { margin-top: 0; }
dl.glossary dd { margin: .15em 0 0; color: var(--text-secondary); }

/* Related */
.related-box {
  margin-top: 2.4em;
  padding-top: 1.6em;
  border-top: 2px solid var(--border-soft);
}
.related-box h3 {
  font-size: .8rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin-bottom: 12px;
}
.related-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 10px;
  color: var(--text);
  font-size: .92rem;
  transition: var(--transition);
}
.related-link:hover {
  background: var(--accent-subtle);
  text-decoration: none;
  transform: translateX(3px);
}
.related-icon { font-size: 1.1rem; }

/* ============ HOME ============ */
.home-hero {
  position: relative;
  background: var(--hero-grad);
  border-radius: 20px;
  padding: 46px 44px 40px;
  margin-bottom: 42px;
  overflow: hidden;
  color: var(--hero-text);
}
.home-hero::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 420px 260px at 82% 18%, rgba(245, 165, 36, .16), transparent 65%),
    radial-gradient(ellipse 300px 220px at 8% 88%, rgba(45, 212, 191, .10), transparent 65%);
  pointer-events: none;
}

.hero-eyebrow {
  display: inline-block;
  font-size: .75rem;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--hero-accent);
  margin-bottom: 12px;
}
.home-hero h1 {
  font-family: var(--font-display);
  font-size: clamp(1.9rem, 4vw, 2.7rem);
  font-weight: 700;
  line-height: 1.18;
  margin-bottom: 12px;
  text-wrap: balance;
  color: var(--hero-text);
  max-width: 58%;
}
.hero-sub {
  color: var(--hero-dim);
  font-size: 1.02rem;
  line-height: 1.65;
  max-width: 56%;
  margin-bottom: 22px;
}

.hero-art {
  position: absolute;
  top: 50%;
  right: 30px;
  transform: translateY(-50%);
  width: 300px;
  height: 300px;
  opacity: .95;
  pointer-events: none;
}
.hero-art svg { width: 100%; height: 100%; }

/* Motyl tarczycy: płaty rysują się, puls energii */
.thyroid-lobe { stroke-dasharray: 340; stroke-dashoffset: 340; animation: drawLobe 1.6s ease-out forwards; }
.thyroid-isthmus { stroke-dasharray: 120; stroke-dashoffset: 120; animation: drawIsth 1s .5s ease-out forwards; }
@keyframes drawLobe { to { stroke-dashoffset: 0; } }
@keyframes drawIsth { to { stroke-dashoffset: 0; } }
.pulse-ring {
  transform-origin: 100px 100px;
  animation: pulseRing 3.2s ease-out infinite;
}
.pulse-ring.r2 { animation-delay: 1.1s; }
.pulse-ring.r3 { animation-delay: 2.2s; }
@keyframes pulseRing {
  0% { transform: scale(.35); opacity: .75; }
  75% { transform: scale(1.05); opacity: 0; }
  100% { transform: scale(1.05); opacity: 0; }
}
.molecule-dot { animation: bob 4s ease-in-out infinite; }
.molecule-dot.m2 { animation-delay: .9s; }
.molecule-dot.m3 { animation-delay: 1.7s; }
@keyframes bob {
  0%, 100% { transform: translateY(0); opacity: .55; }
  50% { transform: translateY(-7px); opacity: 1; }
}

.stats-row {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  margin-top: 6px;
  position: relative;
  z-index: 2;
}
.stat-card {
  background: rgba(255, 255, 255, .07);
  border: 1px solid rgba(255, 255, 255, .12);
  border-radius: 12px;
  padding: 12px 20px;
  text-align: center;
  min-width: 108px;
}
.stat-card .num {
  display: block;
  font-family: var(--font-display);
  font-size: 1.55rem;
  font-weight: 700;
  color: var(--hero-accent);
  line-height: 1.1;
}
.stat-card .label {
  display: block;
  font-size: .72rem;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--hero-dim);
  margin-top: 4px;
}

.home-section-label {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-display);
  font-size: 1.28rem;
  font-weight: 700;
  margin: 38px 0 16px;
  color: var(--text);
}
.accent-bar {
  width: 5px;
  height: 1.35em;
  background: linear-gradient(180deg, var(--accent), var(--accent2));
  border-radius: 3px;
  flex-shrink: 0;
}

.home-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}
.home-card {
  display: block;
  background: var(--card-bg);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 18px 20px;
  color: var(--text);
  box-shadow: var(--shadow);
  transition: var(--transition);
}
.home-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-hover);
  border-color: var(--accent);
  text-decoration: none;
}
.card-icon { font-size: 1.45rem; display: block; margin-bottom: 8px; }
.home-card h3 {
  font-family: var(--font-display);
  font-size: .98rem;
  font-weight: 600;
  line-height: 1.35;
  margin-bottom: 6px;
  color: var(--text);
}
.home-card p {
  font-size: .85rem;
  line-height: 1.55;
  color: var(--text-secondary);
  margin: 0;
}

/* ============ RESPONSIVE ============ */
@media (max-width: 1100px) {
  .home-hero h1 { max-width: 66%; }
  .hero-sub { max-width: 64%; }
  .hero-art { width: 240px; height: 240px; right: 16px; }
}
@media (max-width: 900px) {
  .main-content { margin-left: 0; padding: 76px 18px 50px; }
  .mobile-menu-btn { display: block; }
  .sidebar {
    transform: translateX(-100%);
    transition: transform .26s ease-out;
    box-shadow: 4px 0 24px rgba(0, 0, 0, .18);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.show { display: block; }
  .header-search { width: auto; flex: 1; max-width: none; }
  .home-hero { padding: 34px 26px 30px; }
  .home-hero h1 { max-width: 100%; }
  .hero-sub { max-width: 100%; }
  .hero-art { display: none; }
  .home-grid { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
  .logo-text { font-size: 1.05rem; }
  .app-header { padding: 0 12px; gap: 10px; }
  .stats-row { gap: 10px; }
  .stat-card { min-width: 92px; padding: 10px 14px; }
  .content-article h1 { font-size: 1.6rem; }
  .home-card { padding: 15px 16px; }
}

/* ============ ACCESSIBILITY ============ */
:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
  .thyroid-lobe, .thyroid-isthmus { stroke-dashoffset: 0; }
}
