*,
*::before,
*::after { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
  scroll-padding-top: 5rem;
  background: var(--bg);
}

body {
  margin: 0;
  min-width: 320px;
  color: var(--text-primary);
  background: var(--bg);
  font-family: var(--font-sans);
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button,
input,
a { font: inherit; }

button,
a { -webkit-tap-highlight-color: transparent; }

button { color: inherit; }
a { color: inherit; text-decoration: none; }
p, h1, h2, h3, h4 { margin-top: 0; }

::selection { color: var(--bg); background: var(--accent); }
:focus-visible { outline: 1px solid var(--accent); outline-offset: 4px; }

.page-frame {
  width: min(100%, var(--container-width));
  min-height: 100vh;
  margin: 0 auto;
  padding: 0;
  overflow: clip;
  background: var(--bg);
}

.page-shell { min-height: 100vh; background: var(--bg); }
.section-pad { padding-right: var(--page-gutter); padding-left: var(--page-gutter); }

.site-header {
  position: relative;
  z-index: 100;
  background: rgba(17, 19, 17, 0.92);
}

.navbar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto minmax(280px, 1fr);
  align-items: center;
  min-height: 78px;
  padding: 0 var(--page-gutter);
  border: 0;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  color: var(--text-primary);
  background: transparent;
  box-shadow: none;
  backdrop-filter: blur(14px);
}

.brand {
  display: inline-flex;
  align-items: center;
  justify-self: start;
  gap: 0.9rem;
}

.brand-mark {
  display: grid;
  grid-template-columns: repeat(2, 7px);
  grid-template-rows: repeat(2, 7px);
  gap: 4px;
  width: 40px;
  height: 40px;
  padding: 9px;
  border: 1px solid rgba(255, 255, 255, 0.85);
  border-radius: 8px;
  background: var(--text-primary);
}

.brand-mark i { display: block; border-radius: 1px; background: var(--bg); }
.brand-mark i:first-child { grid-row: span 2; }

.brand-copy { display: grid; gap: 0.12rem; }
.brand-copy strong { font-size: 0.78rem; font-weight: 650; letter-spacing: 0.16em; }
.brand-copy small { color: var(--text-secondary); font-size: 0.64rem; letter-spacing: 0.1em; }

.nav-links {
  display: flex;
  align-items: stretch;
  justify-content: center;
  gap: clamp(1.5rem, 3.4vw, 3.4rem);
  height: 78px;
}

.nav-links > a,
.nav-dropdown-trigger {
  position: relative;
  display: inline-flex;
  align-items: center;
  padding: 0;
  border: 0;
  border-radius: 0;
  color: var(--text-secondary);
  background: transparent;
  font-size: 0.8rem;
  cursor: pointer;
  transition: color 220ms ease, opacity 220ms ease;
}

.nav-links > a:hover,
.nav-links > a.active,
.nav-dropdown-trigger:hover,
.nav-dropdown-trigger.active,
.nav-dropdown.open .nav-dropdown-trigger {
  color: var(--text-primary);
  background: transparent;
  transform: none;
}

.nav-links > a::after,
.nav-dropdown-trigger::after {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  height: 1px;
  background: var(--accent);
  content: "";
  opacity: 0;
  transform: scaleX(0.4);
  transition: opacity 220ms ease, transform 220ms var(--ease);
}

.nav-links > a.active::after,
.nav-dropdown-trigger.active::after {
  opacity: 1;
  transform: scaleX(1);
}

.nav-dropdown { position: relative; display: flex; }
.nav-dropdown-trigger { gap: 0.42rem; }
.nav-dropdown-trigger svg {
  width: 12px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.5;
  transition: transform 220ms ease;
}

.nav-dropdown:hover .nav-dropdown-trigger svg,
.nav-dropdown.open .nav-dropdown-trigger svg { transform: rotate(180deg); }

.chapter-menu {
  position: absolute;
  z-index: 120;
  top: 100%;
  left: 50%;
  width: 350px;
  padding: 0.65rem;
  border: 1px solid var(--divider);
  border-radius: 8px;
  background: rgba(25, 27, 25, 0.98);
  box-shadow: 0 18px 45px rgba(0, 0, 0, 0.28);
  opacity: 0;
  visibility: hidden;
  transform: translate(-50%, -6px);
  pointer-events: none;
  transition: opacity 220ms ease, transform 220ms var(--ease), visibility 220ms ease;
}

.chapter-menu::before {
  position: absolute;
  right: 0;
  bottom: 100%;
  left: 0;
  height: 0.75rem;
  content: "";
}

.nav-dropdown:hover .chapter-menu,
.nav-dropdown.open .chapter-menu {
  opacity: 1;
  visibility: visible;
  transform: translate(-50%, 0);
  pointer-events: auto;
}

.chapter-menu-item {
  display: grid;
  grid-template-columns: 44px 1fr auto;
  align-items: center;
  gap: 0.85rem;
  min-height: 72px;
  padding: 0.65rem;
  border: 1px solid transparent;
  border-radius: 6px;
}

.chapter-menu-item.available { transition: background 200ms ease, border-color 200ms ease; }
.chapter-menu-item.available:hover,
.chapter-menu-item.available:focus-visible { border-color: var(--border); background: var(--surface-secondary); }

.chapter-menu-number {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 1px solid var(--divider);
  border-radius: 6px;
  color: var(--accent);
  font-size: 0.66rem;
  font-weight: 650;
  letter-spacing: 0.08em;
}

.chapter-menu-copy { display: grid; gap: 0.25rem; }
.chapter-menu-copy small {
  color: var(--accent-secondary);
  font-size: 0.5rem;
  font-weight: 650;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
.chapter-menu-copy strong { color: var(--text-primary); font-size: 0.72rem; font-weight: 560; }
.chapter-menu-arrow { color: var(--accent); }

.chapter-menu-item.planned { margin-top: 0.2rem; color: var(--text-muted); background: rgba(255, 255, 255, 0.025); }
.chapter-menu-item.planned .chapter-menu-number,
.chapter-menu-item.planned .chapter-menu-copy small,
.chapter-menu-item.planned .chapter-menu-copy strong { color: var(--text-muted); }

.navbar-actions {
  display: inline-flex;
  align-items: center;
  justify-self: end;
  gap: 0.8rem;
}

.search-trigger {
  display: grid;
  width: 42px;
  height: 42px;
  padding: 0;
  place-items: center;
  border: 0;
  color: var(--text-secondary);
  background: transparent;
  cursor: pointer;
  transition: color 200ms ease, opacity 200ms ease;
}
.search-trigger:hover { color: var(--text-primary); }
.search-trigger svg { width: 20px; fill: none; stroke: currentColor; stroke-width: 1.5; }

.language-switch {
  display: inline-flex;
  align-items: center;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

.language-switch button {
  display: grid;
  min-width: 50px;
  height: 42px;
  padding: 0 0.8rem;
  place-items: center;
  border: 0;
  border-radius: 7px;
  color: var(--text-muted);
  background: transparent;
  font-size: 0.66rem;
  font-weight: 620;
  cursor: pointer;
  transition: color 200ms ease, background 200ms ease;
}
.language-switch button:hover { color: var(--text-primary); }
.language-switch button.active { color: var(--bg); background: var(--accent); box-shadow: none; }

.chapter-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.8rem;
  min-height: 42px;
  padding: 0 1.15rem;
  border: 1px solid var(--text-primary);
  border-radius: 8px;
  color: var(--bg);
  background: var(--text-primary);
  font-size: 0.67rem;
  font-weight: 650;
  letter-spacing: 0.14em;
  box-shadow: none;
  transition: opacity 200ms ease, transform 200ms var(--ease);
}
.chapter-pill:hover { opacity: 0.82; transform: translateY(-2px); box-shadow: none; }

.chapter-pill svg,
.button svg {
  width: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.5;
}

.gradient-text { color: var(--accent); background: none; -webkit-background-clip: initial; background-clip: initial; }

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.8rem;
  min-height: 52px;
  padding: 0 1.45rem;
  border: 1px solid var(--divider);
  border-radius: 8px;
  font-size: 0.75rem;
  font-weight: 620;
  cursor: pointer;
  transition: opacity 220ms ease, transform 220ms var(--ease), color 220ms ease, background 220ms ease;
}
.button:hover { transform: translateY(-2px); }
.button-primary { color: var(--bg); border-color: var(--accent); background: var(--accent); box-shadow: none; }
.button-primary:hover { color: var(--bg); background: var(--accent-secondary); box-shadow: none; }
.button-secondary { color: var(--text-primary); border-color: var(--divider); background: transparent; box-shadow: none; }
.button-secondary:hover { border-color: rgba(255, 255, 255, 0.34); background: var(--surface); }

.panel-card { border: 1px solid var(--border); border-radius: 10px; background: var(--surface); box-shadow: none; }

.section-heading {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 520px);
  align-items: end;
  gap: 3rem;
  margin-bottom: 4rem;
}
.section-heading > div { position: relative; }
.section-number {
  display: block;
  margin-bottom: 1rem;
  color: var(--accent);
  font-size: 0.68rem;
  font-weight: 650;
  line-height: 1;
  letter-spacing: 0.16em;
}
.eyebrow {
  margin-bottom: 1rem;
  color: var(--text-muted);
  font-size: 0.62rem;
  font-weight: 620;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}
.section-heading h2 {
  margin-bottom: 0;
  font-size: clamp(2.3rem, 4.6vw, 4.6rem);
  font-weight: 580;
  line-height: 1.08;
  letter-spacing: -0.055em;
}
.section-intro {
  max-width: 640px;
  margin-bottom: 0;
  color: var(--text-secondary);
  font-size: 0.92rem;
  line-height: 1.85;
}
.lesson-section { padding-top: var(--section-space); padding-bottom: var(--section-space); }
.section-tint { border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); background: var(--bg-alt); }

.scroll-progress { position: fixed; z-index: 1000; top: 0; left: 0; width: 100%; height: 2px; background: transparent; }
.scroll-progress span { display: block; width: 0; height: 100%; background: var(--accent); }

.back-to-top {
  position: fixed;
  z-index: 90;
  right: 1.5rem;
  bottom: 1.5rem;
  display: grid;
  width: 46px;
  height: 46px;
  place-items: center;
  border: 1px solid var(--divider);
  border-radius: 8px;
  color: var(--text-primary);
  background: rgba(25, 27, 25, 0.95);
  box-shadow: none;
  cursor: pointer;
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity 200ms ease, transform 200ms var(--ease);
}
.back-to-top.visible { opacity: 1; transform: translateY(0); pointer-events: auto; }
.back-to-top:hover { color: var(--accent); transform: translateY(-2px); }
.back-to-top svg { width: 18px; fill: none; stroke: currentColor; stroke-width: 1.5; }

.toast {
  position: fixed;
  z-index: 300;
  bottom: 1.75rem;
  left: 50%;
  padding: 0.78rem 1rem;
  border: 1px solid var(--divider);
  border-radius: 8px;
  color: var(--text-primary);
  background: var(--surface-secondary);
  box-shadow: 0 14px 35px rgba(0, 0, 0, 0.25);
  font-size: 0.74rem;
  opacity: 0;
  transform: translate(-50%, 12px);
  pointer-events: none;
  transition: opacity 200ms ease, transform 200ms ease;
}
.toast.visible { opacity: 1; transform: translate(-50%, 0); }

.site-footer {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 2.5rem;
  padding-top: 2.6rem;
  padding-bottom: 2.6rem;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  background: var(--bg);
  font-size: 0.65rem;
}
.site-footer p { margin: 0; }
.footer-brand .brand-mark { border-color: var(--divider); background: var(--text-primary); }
.footer-brand .brand-copy strong { color: var(--text-primary); }
.footer-brand .brand-copy small { color: var(--text-muted); }

@media (max-width: 1080px) {
  .navbar { grid-template-columns: 1fr auto; }
  .nav-links { display: none; }
  .navbar-actions { margin-left: auto; }
}

@media (max-width: 720px) {
  :root { --page-gutter: 1.25rem; --section-space: 5.5rem; }
  .navbar { min-height: 68px; }
  .brand-mark { width: 36px; height: 36px; padding: 8px; }
  .search-trigger { display: none; }
  .language-switch button { min-width: 38px; height: 38px; padding: 0 0.55rem; }
  .chapter-pill { min-height: 38px; padding: 0 0.8rem; }
  .chapter-pill svg { display: none; }
  .section-heading { grid-template-columns: 1fr; gap: 1.5rem; margin-bottom: 2.5rem; }
  .site-footer { grid-template-columns: 1fr; gap: 0.7rem; }
}

@media (max-width: 460px) {
  .brand-copy small { display: none; }
  .brand-copy strong { font-size: 0.68rem; }
  .navbar-actions { gap: 0.45rem; }
  .language-switch button { min-width: 33px; height: 36px; }
  .chapter-pill { padding: 0 0.68rem; font-size: 0.6rem; }
}

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