@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

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

html {
  font-size: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 1.125rem;
  line-height: 1.6;
  color: var(--text-primary);
  background: var(--bg-page);
}

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

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

a:focus-visible,
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

h1,
h2,
h3,
p {
  margin: 0 0 var(--space-md);
}

h1 {
  font-size: clamp(1.75rem, 3vw, 2.25rem);
  line-height: 1.2;
  font-weight: 700;
}

h2 {
  font-size: 1.25rem;
  font-weight: 600;
}

/* ——— Site shell: header → body(sidebar+main) → footer ——— */

.site-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.site-body {
  display: flex;
  flex: 1;
  min-height: 0;
  align-items: stretch;
}

.site-header {
  border-bottom: 1px solid var(--border);
  background: var(--bg-page);
  flex-shrink: 0;
  z-index: 50;
}

.site-header__inner {
  padding: var(--space-md) var(--space-xl);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  flex-wrap: wrap;
}

.site-header__brand {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
  min-width: 0;
}

.site-logo {
  font-weight: 700;
  font-size: 1.0625rem;
  color: var(--text-primary);
  text-decoration: none;
  line-height: 1.25;
}

.site-header__tagline {
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.site-nav {
  display: flex;
  gap: var(--space-md);
  flex-wrap: wrap;
}

.site-nav a {
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-weight: 500;
  text-decoration: none;
}

.site-nav a:hover {
  color: var(--accent);
  text-decoration: none;
}

/* ——— Sidebar + main (between header and footer) ——— */

.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: linear-gradient(180deg, #0f172a 0%, #111827 100%);
  color: var(--text-inverse);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  border-right: 1px solid rgb(255 255 255 / 6%);
}

.sidebar__brand {
  padding: var(--space-lg) var(--space-md) var(--space-md);
  border-bottom: 1px solid rgb(255 255 255 / 8%);
}

.sidebar__brand a {
  color: var(--text-inverse);
  text-decoration: none;
  font-weight: 700;
  font-size: 0.9375rem;
  line-height: 1.35;
  display: block;
}

.sidebar__brand small {
  display: block;
  margin-top: var(--space-sm);
  font-size: 0.75rem;
  font-weight: 400;
  line-height: 1.4;
  color: var(--text-inverse-muted);
}

.sidebar__nav {
  padding: var(--space-sm) 0 var(--space-md);
  flex: 1;
}

.sidebar__label {
  padding: var(--space-md) var(--space-md) var(--space-xs);
  font-size: 0.625rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: rgb(148 163 184 / 70%);
}

.sidebar__link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem var(--space-md);
  margin: 0.125rem 0.5rem;
  color: var(--text-inverse-muted);
  font-size: 0.875rem;
  font-weight: 500;
  text-decoration: none;
  border-radius: var(--radius);
  border-left: none;
  transition: background 0.15s, color 0.15s;
}

.sidebar__link-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.375rem;
  height: 1.375rem;
  flex-shrink: 0;
}

.sidebar__link-icon svg {
  width: 1.125rem;
  height: 1.125rem;
}

.sidebar__link-text {
  display: flex;
  flex-direction: column;
  gap: 0.0625rem;
  line-height: 1.25;
  min-width: 0;
}

.sidebar__link-sub {
  font-size: 0.6875rem;
  font-weight: 400;
  color: rgb(148 163 184 / 80%);
}

.sidebar__link.is-active .sidebar__link-sub {
  color: rgb(255 255 255 / 75%);
}

.sidebar__dot {
  width: 0.625rem;
  height: 0.625rem;
  border-radius: 50%;
  box-shadow: 0 0 0 2px rgb(255 255 255 / 15%);
}

.sidebar__dot--blue { background: var(--level-blue); }
.sidebar__dot--red { background: var(--level-red); }
.sidebar__dot--yellow { background: var(--level-yellow); }
.sidebar__dot--green { background: var(--level-green); }
.sidebar__dot--purple { background: var(--level-purple); }
.sidebar__dot--orange { background: var(--level-orange); }
.sidebar__dot--violet { background: var(--level-violet); }

.sidebar__link:hover {
  background: rgb(255 255 255 / 6%);
  color: var(--text-inverse);
  text-decoration: none;
}

.sidebar__link.is-active {
  color: #fff;
  background: rgb(37 99 235 / 22%);
  box-shadow: inset 3px 0 0 var(--level-blue);
  border-radius: 0 var(--radius) var(--radius) 0;
}

[data-level='red'] .sidebar__link.is-active {
  background: rgb(220 38 38 / 22%);
  box-shadow: inset 3px 0 0 var(--level-red);
}

[data-level='blue'] .sidebar__link.is-active {
  background: rgb(37 99 235 / 22%);
  box-shadow: inset 3px 0 0 var(--level-blue);
}

.sidebar__note {
  padding: var(--space-md);
  margin: var(--space-sm);
  border-radius: var(--radius);
  background: rgb(255 255 255 / 4%);
  border: 1px solid rgb(255 255 255 / 8%);
}

.sidebar__note p {
  margin: 0;
  font-size: 0.75rem;
  line-height: 1.45;
  color: var(--text-inverse-muted);
}

.main__content {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  padding: var(--space-xl);
  --max-inner: var(--content-wide);
}

.main__content--narrow {
  --max-inner: var(--content-narrow);
}

.main__content > * {
  max-width: var(--max-inner);
}

.main__content .level-grid,
.main__content .secondary-links,
.main__content .topic-grid,
.main__content .hub-grid,
.main__content .expression-list {
  max-width: none;
}

/* ——— Footer ——— */

.site-footer {
  background: var(--bg-sidebar);
  color: var(--text-inverse-muted);
  padding: var(--space-2xl) var(--space-xl);
  flex-shrink: 0;
}

.site-footer__inner {
  max-width: 960px;
  margin: 0 auto;
  text-align: center;
}

.site-footer__title {
  color: var(--text-inverse);
  font-weight: 600;
  font-size: 1rem;
  margin-bottom: var(--space-xs);
}

.site-footer__links {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--space-sm) var(--space-lg);
  margin-bottom: var(--space-lg);
}

.site-footer__links a {
  color: var(--text-inverse-muted);
  font-size: 0.875rem;
  text-decoration: none;
}

.site-footer__links a:hover {
  color: var(--text-inverse);
}

.site-footer__copy {
  font-size: 0.8125rem;
  margin: 0;
}

.version-switcher {
  display: flex;
  justify-content: center;
  gap: var(--space-sm);
  margin-top: var(--space-lg);
  padding-top: var(--space-lg);
  border-top: 1px solid rgb(255 255 255 / 10%);
}

.version-switcher a {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.25rem 0.625rem;
  border-radius: 999px;
  color: var(--text-inverse-muted);
  text-decoration: none;
  border: 1px solid rgb(255 255 255 / 15%);
}

.version-switcher a:hover {
  color: var(--text-inverse);
  border-color: rgb(255 255 255 / 30%);
}

.version-switcher a.is-current {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ——— Mobile ——— */

.menu-toggle {
  display: none;
  position: fixed;
  bottom: var(--space-lg);
  right: var(--space-lg);
  z-index: 100;
  width: 3rem;
  height: 3rem;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 1.25rem;
  cursor: pointer;
  box-shadow: var(--shadow);
}

@media (max-width: 900px) {
  .menu-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 90;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }

  .sidebar.is-open {
    transform: translateX(0);
  }

  .sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgb(15 23 42 / 50%);
    z-index: 80;
  }

  .sidebar-backdrop.is-open {
    display: block;
  }

  .main__content {
    padding: var(--space-lg);
  }
}

@media print {
  .sidebar,
  .menu-toggle,
  .version-switcher,
  .site-header,
  .lesson-nav,
  .no-print {
    display: none !important;
  }

  .main__content {
    max-width: none;
    padding: 0;
  }
}
