@import url("./tokens.css");

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; scroll-padding-top: calc(var(--header-h) + 12px); }
body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  line-height: var(--lh-base);
  color: var(--c-text);
  background: var(--c-bg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
img, svg { max-width: 100%; height: auto; display: block; }
button { font-family: inherit; }

/* Skip-to-content for keyboard */
.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--c-primary);
  color: #fff;
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-sm);
  z-index: 1000;
}
.skip-link:focus { left: var(--sp-3); top: var(--sp-3); }

/* Focus ring */
:focus-visible {
  outline: 3px solid var(--c-accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ---------- Typography ---------- */
h1, h2, h3, h4 {
  color: var(--c-text);
  line-height: var(--lh-tight);
  letter-spacing: -0.01em;
  margin: 0 0 var(--sp-4);
}
h1 { font-size: var(--fs-3xl); font-weight: 700; }
h2 { font-size: var(--fs-2xl); font-weight: 650; margin-top: var(--sp-12); }
h3 { font-size: var(--fs-xl); font-weight: 600; margin-top: var(--sp-8); color: var(--c-secondary-600); }
h4 { font-size: var(--fs-lg); font-weight: 600; margin-top: var(--sp-6); }
p { margin: 0 0 var(--sp-4); }

a {
  color: var(--c-primary);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: color var(--t-fast), border-color var(--t-fast), background var(--t-fast);
}
a:hover {
  color: var(--c-primary-700);
  border-bottom-color: var(--c-primary);
}
a:visited { color: var(--c-primary); }

/* Heading anchor link (silent) */
a.heading-link {
  color: inherit;
  border-bottom: none;
}
a.heading-link:hover { color: var(--c-primary); border-bottom: none; }

/* Scroll-target offset for headings under the sticky header */
h1[id], h2[id], h3[id], h4[id] {
  scroll-margin-top: calc(var(--header-h) + 16px);
}

/* ---------- Layout ---------- */
.container {
  width: 100%;
  max-width: var(--container-max);
  margin: 0 auto;
  padding: 0 var(--sp-6);
}
@media (min-width: 1100px) {
  .container { padding: 0 var(--sp-10); }
}

main { flex: 1 0 auto; }

/* ---------- Header ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: saturate(160%) blur(10px);
  -webkit-backdrop-filter: saturate(160%) blur(10px);
  border-bottom: 1px solid var(--c-border);
}
.site-header .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: var(--header-h);
  gap: var(--sp-6);
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-3);
  color: var(--c-text);
  font-weight: 700;
  font-size: var(--fs-md);
  border-bottom: none;
  letter-spacing: -0.01em;
}
.brand:hover { color: var(--c-primary); border-bottom: none; }
.brand svg { width: 32px; height: 32px; }
.brand-text { display: inline-flex; flex-direction: column; line-height: 1.1; }
.brand-text small { color: var(--c-text-muted); font-weight: 500; font-size: 0.75rem; letter-spacing: 0.02em; }

/* Primary nav */
.nav-primary {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}
.nav-primary a {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r-sm);
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--c-text-muted);
  border-bottom: 2px solid transparent;
  transition: color var(--t-fast), background var(--t-fast), border-color var(--t-fast);
}
.nav-primary a svg { width: 18px; height: 18px; flex: none; }
.nav-primary a:hover {
  color: var(--c-primary);
  background: var(--c-primary-050);
  border-bottom-color: transparent;
}
.nav-primary a[aria-current="page"] {
  color: var(--c-primary);
  background: var(--c-primary-050);
  border-bottom-color: var(--c-primary);
}

/* Mobile menu */
.nav-toggle {
  display: none;
  background: none;
  border: 1px solid var(--c-border);
  color: var(--c-text);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r-sm);
  cursor: pointer;
}
@media (max-width: 880px) {
  .nav-primary {
    position: fixed;
    top: var(--header-h);
    right: 0;
    bottom: 0;
    width: min(320px, 80vw);
    background: var(--c-surface);
    border-left: 1px solid var(--c-border);
    flex-direction: column;
    align-items: stretch;
    padding: var(--sp-4);
    gap: var(--sp-1);
    transform: translateX(110%);
    transition: transform var(--t-base);
    box-shadow: var(--sh-lg);
  }
  .nav-primary.open { transform: translateX(0); }
  .nav-primary a { padding: var(--sp-3); font-size: var(--fs-md); }
  .nav-toggle { display: inline-flex; align-items: center; gap: var(--sp-2); }
}

/* ---------- Footer ---------- */
.site-footer {
  flex-shrink: 0;
  margin-top: var(--sp-20);
  background: linear-gradient(180deg, var(--c-surface) 0%, var(--c-surface-2) 100%);
  border-top: 1px solid var(--c-border);
  padding: var(--sp-12) 0 var(--sp-8);
  color: var(--c-text-muted);
  font-size: var(--fs-sm);
}
.footer-grid {
  display: grid;
  grid-template-columns: 1.4fr repeat(3, 1fr);
  gap: var(--sp-8);
}
@media (max-width: 880px) { .footer-grid { grid-template-columns: 1fr 1fr; } }
@media (max-width: 560px) { .footer-grid { grid-template-columns: 1fr; } }
.footer-col h4 {
  margin: 0 0 var(--sp-3);
  font-size: var(--fs-sm);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--c-secondary-600);
}
.footer-col ul { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: var(--sp-2); }
.footer-col a { color: var(--c-text); }
.footer-col a:hover { color: var(--c-primary); }
.footer-bottom {
  margin-top: var(--sp-10);
  padding-top: var(--sp-6);
  border-top: 1px solid var(--c-border);
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--sp-3);
  color: var(--c-text-subtle);
}

/* ---------- Home ---------- */
.hero {
  padding: var(--sp-16) 0 var(--sp-12);
  text-align: center;
}
.hero-logo {
  display: flex;
  justify-content: center;
  margin-bottom: var(--sp-8);
}
.hero-logo svg {
  width: clamp(140px, 22vw, 240px);
  height: auto;
  filter: drop-shadow(0 14px 40px rgba(15, 110, 110, 0.18));
  transition: transform var(--t-slow);
}
.hero-logo svg:hover { transform: translateY(-4px) scale(1.02); }
.hero h1 {
  font-size: clamp(2rem, 4.2vw, 3.4rem);
  background: linear-gradient(135deg, var(--c-primary) 0%, var(--c-secondary) 50%, var(--c-accent) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  margin-bottom: var(--sp-4);
}
.hero-tagline {
  font-size: var(--fs-lg);
  color: var(--c-text-muted);
  max-width: 70ch;
  margin: 0 auto var(--sp-8);
}

.hero-paragraphs {
  margin: 0 0 var(--sp-10);
  text-align: left;
  font-size: var(--fs-md);
  color: var(--c-text);
}
.hero-paragraphs p { line-height: var(--lh-loose); }
@media (min-width: 1100px) {
  .hero-paragraphs {
    columns: 2;
    column-gap: var(--sp-12);
    column-rule: 1px solid var(--c-border);
  }
  .hero-paragraphs p { break-inside: avoid; }
}

.cta-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--sp-6);
  margin: var(--sp-8) 0 var(--sp-16);
}
@media (max-width: 900px) { .cta-grid { grid-template-columns: 1fr; } }

.cta-card {
  display: block;
  text-align: left;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-lg);
  padding: var(--sp-6);
  text-decoration: none;
  color: var(--c-text);
  box-shadow: var(--sh-sm);
  transition: transform var(--t-base), box-shadow var(--t-base), border-color var(--t-base);
  border-bottom: 1px solid var(--c-border);
}
.cta-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--sh-lg);
  border-color: var(--c-primary-100);
  color: var(--c-text);
}
.cta-card .icon-wrap {
  width: 56px;
  height: 56px;
  border-radius: var(--r-md);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: var(--sp-4);
}
.cta-card.tone-ingest .icon-wrap     { background: linear-gradient(135deg, #E1F1F0, #C9E5E3); }
.cta-card.tone-architecture .icon-wrap { background: linear-gradient(135deg, #DFE6EF, #C7D4E3); }
.cta-card.tone-inventory .icon-wrap  { background: linear-gradient(135deg, #FBEAD0, #F5D9A8); }
.cta-card .icon-wrap svg { width: 32px; height: 32px; }
.cta-card h3 { margin: 0 0 var(--sp-2); font-size: var(--fs-lg); color: var(--c-text); }
.cta-card p { color: var(--c-text-muted); font-size: var(--fs-sm); margin: 0; }
.cta-card .cta-arrow {
  display: inline-flex;
  margin-top: var(--sp-4);
  color: var(--c-primary);
  font-weight: 600;
  font-size: var(--fs-sm);
  align-items: center;
  gap: var(--sp-1);
  transition: gap var(--t-fast);
}
.cta-card:hover .cta-arrow { gap: var(--sp-3); }

.section-overview {
  margin-bottom: var(--sp-12);
}
.section-overview h2 { text-align: center; }
.section-overview > p { text-align: center; color: var(--c-text-muted); }

.deep-links {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--sp-6);
  margin-top: var(--sp-8);
}
@media (max-width: 900px) { .deep-links { grid-template-columns: 1fr; } }
.deep-links section {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  padding: var(--sp-5);
}
.deep-links h3 { margin-top: 0; font-size: var(--fs-md); }
.deep-links ul { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: var(--sp-2); }
.deep-links a { font-size: var(--fs-sm); }

/* ---------- Article (content) ---------- */
.page-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--sp-8);
  padding: var(--sp-8) 0 var(--sp-16);
}
@media (min-width: 1100px) {
  .page-layout {
    grid-template-columns: minmax(0, 1fr) 260px;
    gap: var(--sp-12);
  }
}
.article {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-lg);
  padding: clamp(var(--sp-5), 3vw, var(--sp-10));
  box-shadow: var(--sh-sm);
  max-width: 100%;
  min-width: 0;
}
.article > * { max-width: 100%; }
.article p, .article li {
  color: var(--c-text);
  font-size: var(--fs-md);
  line-height: var(--lh-loose);
}
.article ul, .article ol { padding-left: 1.5em; margin: 0 0 var(--sp-4); }
.article li { margin-bottom: var(--sp-2); }

.article h1 {
  font-size: clamp(1.875rem, 3.2vw, 2.6rem);
  background: linear-gradient(120deg, var(--c-primary) 0%, var(--c-secondary) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  margin-bottom: var(--sp-6);
}
.article h2 {
  position: relative;
  padding-left: var(--sp-4);
}
.article h2::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.25em;
  bottom: 0.25em;
  width: 4px;
  background: linear-gradient(180deg, var(--c-primary), var(--c-accent));
  border-radius: 2px;
}

/* Breadcrumbs */
.breadcrumbs {
  font-size: var(--fs-sm);
  color: var(--c-text-muted);
  margin-bottom: var(--sp-4);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-1) var(--sp-2);
}
.breadcrumbs ol { list-style: none; padding: 0; margin: 0; display: contents; }
.breadcrumbs li { display: inline-flex; align-items: center; gap: var(--sp-2); }
.breadcrumbs li + li::before {
  content: "›";
  color: var(--c-text-subtle);
  margin-right: var(--sp-1);
}
.breadcrumbs a {
  color: var(--c-text-muted);
  border-bottom: none;
}
.breadcrumbs a:hover { color: var(--c-primary); }
.breadcrumbs [aria-current="page"] { color: var(--c-text); font-weight: 500; }

/* Inline code */
.article :not(pre) > code {
  font-family: var(--font-mono);
  font-size: 0.92em;
  background: var(--c-code-inline-bg);
  color: var(--c-primary-700);
  padding: 0.08em 0.4em;
  border-radius: 4px;
  border: 0;
}

/* Codeblocks */
.codeblock {
  position: relative;
  margin: var(--sp-6) 0;
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  background: var(--c-code-bg);
  overflow: hidden;
}
.codeblock pre {
  margin: 0;
  padding: var(--sp-5) var(--sp-5);
  overflow-x: auto;
  background: transparent;
  font-family: var(--font-mono);
  font-size: 0.875rem;
  line-height: 1.6;
  color: var(--c-code-text);
}
.codeblock pre code { background: transparent; padding: 0; }
.codeblock::before {
  content: attr(data-lang);
  position: absolute;
  top: 8px;
  left: 14px;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--c-text-subtle);
  pointer-events: none;
}
.codeblock pre {
  padding-top: calc(var(--sp-5) + 12px);
}
.copy-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  color: var(--c-text-muted);
  font-size: var(--fs-xs);
  padding: 4px 10px;
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: color var(--t-fast), background var(--t-fast), border-color var(--t-fast);
}
.copy-btn:hover { color: var(--c-primary); border-color: var(--c-primary-100); background: var(--c-primary-050); }
.copy-btn.copied { color: var(--c-success); border-color: var(--c-success); }

/* Tables */
.table-wrap { overflow-x: auto; margin: var(--sp-6) 0; border: 1px solid var(--c-border); border-radius: var(--r-md); }
.article table { border-collapse: collapse; width: 100%; font-size: var(--fs-sm); }
.article th, .article td { padding: var(--sp-3) var(--sp-4); text-align: left; border-bottom: 1px solid var(--c-border); }
.article th { background: var(--c-surface-2); color: var(--c-secondary-600); font-weight: 600; }
.article tbody tr:nth-child(even) { background: rgba(15, 110, 110, 0.02); }

/* Task lists (checkboxes) */
.article ul.contains-task-list { list-style: none; padding-left: 0; }
.article li.task-list-item { display: flex; align-items: flex-start; gap: var(--sp-2); }
.article li.task-list-item input[type="checkbox"] {
  margin-top: 0.35em;
  width: 18px;
  height: 18px;
  accent-color: var(--c-primary);
  cursor: pointer;
}
.article li.task-list-item.checked > :not(input) { text-decoration: line-through; color: var(--c-text-subtle); }

/* Mermaid container */
.mermaid {
  margin: var(--sp-6) 0;
  padding: var(--sp-5);
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  text-align: center;
  overflow-x: auto;
}

/* FAQ accordion */
.faq { display: flex; flex-direction: column; gap: var(--sp-3); margin: var(--sp-4) 0; }
.faq-item {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  padding: 0 var(--sp-5);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.faq-item[open] { border-color: var(--c-primary-100); box-shadow: var(--sh-sm); }
.faq-item summary {
  cursor: pointer;
  padding: var(--sp-4) 0;
  font-weight: 600;
  color: var(--c-text);
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
}
.faq-item summary::-webkit-details-marker { display: none; }
.faq-item summary::after {
  content: "+";
  font-size: 1.4em;
  color: var(--c-primary);
  transition: transform var(--t-base);
}
.faq-item[open] summary::after { content: "−"; }
.faq-body { padding: 0 0 var(--sp-4); border-top: 1px solid var(--c-border); padding-top: var(--sp-4); }

/* Related panel (sidebar) */
.related {
  align-self: start;
  position: sticky;
  top: calc(var(--header-h) + 16px);
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  padding: var(--sp-5);
  font-size: var(--fs-sm);
}
.related h2 {
  font-size: var(--fs-sm);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--c-secondary-600);
  margin: 0 0 var(--sp-3);
}
.related ul { list-style: none; padding: 0; margin: 0 0 var(--sp-4); display: flex; flex-direction: column; gap: var(--sp-2); }
.related li.current a { color: var(--c-primary); font-weight: 600; }
@media (max-width: 1099px) {
  .related { position: static; }
}

/* Toc */
.toc { font-size: var(--fs-sm); }
.toc h3 {
  font-size: var(--fs-sm);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--c-secondary-600);
  margin: var(--sp-4) 0 var(--sp-2);
}
.toc ul { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: var(--sp-1); }
.toc a { color: var(--c-text-muted); border-bottom: none; }
.toc a:hover { color: var(--c-primary); }
