*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans SC", sans-serif;
  background: var(--bg-paper);
  color: var(--text-main);
  line-height: 1.75;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

:root {
  --bg-dark: #140E25;
  --bg-paper: #F5F0E5;
  --text-main: #191523;
  --brand: #5214EB;
  --accent: #C8ED6E;
  --text-light: #F5F0E5;
  --border-color: rgba(25, 21, 35, 0.16);
  --radius-card: 8px;
  --radius-btn: 6px;
  --section-y: clamp(5rem, 10vw, 9rem);
  --gap: clamp(1.5rem, 3vw, 2.5rem);
  --content-max: 1120px;
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans SC", sans-serif;
}

h1, h2, h3, h4, h5, h6 {
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.1;
  color: inherit;
}

h1 {
  font-size: clamp(2.4rem, 6vw, 4.5rem);
  margin-bottom: 0.5em;
}

h2 {
  font-size: clamp(1.6rem, 3vw, 2.4rem);
  line-height: 1.25;
  margin-bottom: var(--gap);
}

h3 {
  font-size: clamp(1.2rem, 2vw, 1.5rem);
  margin-bottom: 0.5em;
}

p {
  margin-bottom: 1em;
  max-width: 38em;
}

a {
  color: var(--brand);
  text-decoration: underline;
  text-underline-offset: 3px;
  transition: color 0.2s ease;
}

.dark-mode {
  background: var(--bg-dark);
  color: var(--text-light);
}

.dark-mode a {
  color: var(--accent);
}

.paper-mode {
  background: var(--bg-paper);
  color: var(--text-main);
}

.paper-mode a {
  color: var(--brand);
}

.container {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 0 var(--gap);
}

section {
  padding-block: var(--section-y);
}

.grid {
  display: grid;
  gap: var(--gap);
}

.grid-2 {
  grid-template-columns: repeat(auto-fit, minmax(0, 1fr));
}

.grid-3 {
  grid-template-columns: repeat(auto-fit, minmax(0, 1fr));
}

.flex {
  display: flex;
  gap: var(--gap);
  align-items: center;
  flex-wrap: wrap;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5em;
  padding: 0.75em 1.5em;
  border-radius: var(--radius-btn);
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: transform 0.2s ease, filter 0.2s ease;
  height: 48px;
  font-size: 1rem;
  border: none;
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent);
  color: var(--bg-dark);
}

.btn-primary:hover {
  transform: translateY(-1px);
  filter: brightness(0.95);
}

.btn-secondary {
  background: transparent;
  border: 1px solid var(--text-main);
  color: var(--text-main);
}

.dark-mode .btn-secondary {
  border-color: var(--text-light);
  color: var(--text-light);
}

.btn:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

/* Cards */
.card {
  background: var(--bg-paper);
  border: 1px solid rgba(25, 21, 35, 0.16);
  border-radius: var(--radius-card);
  padding: 1.5em;
  transition: transform 0.2s ease;
}

.dark-mode .card {
  background: rgba(245, 240, 229, 0.05);
  border-color: rgba(245, 240, 229, 0.16);
}

.card:hover {
  transform: translateY(-2px);
}

/* Table */
.table-wrapper {
  overflow-x: auto;
  margin: 1em 0;
}

table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

th, td {
  padding: 0.75em 1em;
  border-bottom: 1px solid var(--border-color);
}

th {
  font-weight: 600;
}

.dark-mode th, .dark-mode td {
  border-color: rgba(245, 240, 229, 0.16);
}

/* FAQ */
details {
  margin-bottom: 1em;
  border: 1px solid rgba(25, 21, 35, 0.16);
  border-radius: var(--radius-card);
  padding: 1em;
  transition: border-color 0.2s ease;
}

summary {
  cursor: pointer;
  font-weight: 600;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.5em;
}

summary::-webkit-details-marker {
  display: none;
}

details[open] summary {
  margin-bottom: 0.5em;
}

.dark-mode details {
  border-color: rgba(245, 240, 229, 0.16);
}

/* Header/Footer */
header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-paper);
  border-bottom: 1px solid var(--border-color);
  padding: 0.75em 0;
}

.dark-mode header {
  background: var(--bg-dark);
  border-color: rgba(245, 240, 229, 0.16);
}

nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.nav-links {
  display: flex;
  gap: 1.5em;
  list-style: none;
}

.nav-links a {
  color: inherit;
  text-decoration: none;
  font-weight: 500;
  padding: 0.25em 0;
  border-bottom: 2px solid transparent;
}

.nav-links a:hover, .nav-links a[aria-current="page"] {
  color: var(--brand);
  border-bottom-color: var(--brand);
}

.dark-mode .nav-links a:hover, .dark-mode .nav-links a[aria-current="page"] {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.footer-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--gap);
  padding-top: var(--gap);
}

.footer-links {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.5em;
}

.footer-links a {
  color: inherit;
  text-decoration: none;
  opacity: 0.8;
}

.footer-links a:hover {
  opacity: 1;
}

/* SVG Container & Animations */
.svg-container {
  width: 100%;
  height: auto;
  max-width: 100%;
  overflow: hidden;
}

.svg-container svg {
  width: 100%;
  height: auto;
}

@keyframes drawPath {
  0% { stroke-dashoffset: 1; }
  100% { stroke-dashoffset: 0; }
}

@keyframes floatBubble {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

@keyframes pulseNode {
  0%, 100% { opacity: 0.3; transform: scale(0.8); }
  50% { opacity: 1; transform: scale(1.1); }
}

@keyframes slideInPanel {
  from { opacity: 0; transform: translateX(-10px); }
  to { opacity: 1; transform: translateX(0); }
}

.anim-draw {
  pathLength: 1;
  stroke-dasharray: 1;
  stroke-dashoffset: 0;
  animation: drawPath 2s ease forwards;
}

.anim-float {
  animation: floatBubble 4s ease-in-out infinite;
}

.anim-pulse {
  animation: pulseNode 3s ease-in-out infinite;
  transform-origin: center;
  transform-box: fill-box;
}

.anim-slide {
  animation: slideInPanel 0.8s ease forwards;
  opacity: 0;
}

/* Utilities */
.label {
  display: inline-block;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  margin-bottom: 0.5em;
}

.paper-mode .label { color: var(--brand); }
.dark-mode .label { color: var(--accent); }

.hl { color: var(--brand); }
.dark-mode .hl { color: var(--accent); }

.step-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: var(--accent);
  color: var(--bg-dark);
  font-weight: 700;
  font-size: 0.85rem;
  border-radius: 6px;
  margin-right: 0.5em;
}

.flow-arrow {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--brand);
  font-size: 1.5rem;
}

.dark-mode .flow-arrow { color: var(--accent); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .anim-draw, .anim-float, .anim-pulse, .anim-slide {
    animation: none !important;
  }
}

@media (max-width: 768px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .flex-col-mobile { flex-direction: column; align-items: flex-start; }
  .step-row { flex-direction: column; }
  .flow-row { flex-direction: column; }
  .flow-arrow { transform: rotate(90deg); margin: 0.5em 0; }
}
