:root {
  --menu-bg: var(--mds-bg-panel);
  --menu-surface: var(--mds-surface-strong);
  --menu-border: var(--mds-border);
  --menu-border-strong: var(--mds-border-strong);
  --menu-text: var(--mds-text);
  --menu-muted: var(--mds-muted);
  --menu-accent: var(--mds-accent);
  --menu-accent-soft: var(--mds-accent-soft);
  --menu-button-bg: var(--mds-button-bg, var(--menu-accent));
  --menu-button-text: var(--mds-button-text);
}

body {
  margin: 0;
  font-family: var(--mds-font-body);
}

.topnav {
  position: sticky;
  top: 0;
  z-index: 120;
  background: transparent;
}

.topnav .container {
  position: relative;
  max-width: var(--mds-max);
  margin: 0 auto;
  padding: var(--mds-space-2) var(--mds-space-6);
  box-sizing: border-box;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  align-items: center;
  gap: var(--mds-space-2);
  border: 1px solid var(--menu-border);
  border-radius: 9999px;
  background: var(--menu-bg);
  backdrop-filter: blur(18px);
  isolation: isolate;
}

.topnav .container > * {
  min-width: 0;
}

.logo {
  display: inline-flex;
  align-items: center;
  position: relative;
  width: clamp(152px, 24vw, 220px);
  height: 38px;
}

.logo-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.logo-img--light {
  opacity: 0;
}

:root[data-theme="light"] .logo-img--dark {
  opacity: 0;
}

:root[data-theme="light"] .logo-img--light {
  opacity: 1;
}

.menu {
  display: flex;
  justify-content: center;
  min-width: 0;
}

.topnav__links {
  display: inline-flex;
  align-items: center;
  gap: var(--mds-space-1);
  padding: var(--mds-space-1);
  border-radius: 9999px;
  border: 1px solid var(--menu-border);
  background: var(--menu-surface);
}

.topnav__links a {
  padding: var(--mds-space-2);
  border-radius: 9999px;
  color: var(--menu-muted);
  font-size: var(--mds-text-sm);
  font-weight: 600;
  text-decoration: none;
}

.topnav__links a:hover,
.topnav__links a.active {
  background: var(--menu-accent-soft);
  color: var(--menu-text);
}

.topnav__links a:focus-visible {
  background: var(--menu-accent-soft);
  color: var(--menu-text);
  outline: 2px solid var(--mds-accent);
  outline-offset: 2px;
}

.topnav__links .book-btn {
  background: var(--menu-button-bg);
  color: var(--menu-button-text);
}

.topnav__links .book-btn:hover,
.topnav__links .book-btn:focus-visible,
.topnav__links .book-btn.active {
  background: var(--menu-button-bg);
  color: var(--menu-button-text);
}

.topnav__desktop-tools,
.topnav__mobile-tools {
  display: flex;
  align-items: center;
  gap: var(--mds-space-1);
}

.topnav__mobile-tools {
  display: none;
}

.lang-switch {
  display: inline-flex;
  align-items: center;
  gap: var(--mds-space-1);
  padding: var(--mds-space-1);
  border-radius: 9999px;
  border: 1px solid var(--menu-border);
  background: var(--menu-surface);
}

.lang-switch a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 42px;
  padding: var(--mds-space-1) var(--mds-space-2);
  border-radius: 9999px;
  color: var(--menu-muted);
  font-size: var(--mds-text-xs);
  font-weight: 800;
  letter-spacing: 0.1em;
  text-decoration: none;
}

.lang-switch a:hover {
  background: var(--menu-accent-soft);
  color: var(--menu-text);
}

.lang-switch a:focus-visible {
  background: var(--menu-accent-soft);
  color: var(--menu-text);
  outline: 2px solid var(--mds-accent);
  outline-offset: 2px;
}

.lang-switch a.is-active,
.lang-switch a.is-active:hover,
.lang-switch a.is-active:focus-visible {
  background: var(--menu-button-bg);
  color: var(--menu-button-text);
  -webkit-text-fill-color: var(--menu-button-text);
}

.topnav__theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--mds-space-1);
  min-width: 122px;
  padding: var(--mds-space-1) var(--mds-space-2);
  border-radius: 9999px;
  border: 1px solid var(--menu-border);
  background: var(--menu-surface);
  color: var(--menu-text);
  cursor: pointer;
}

.topnav__theme-toggle:hover,
.burger:hover {
  border-color: var(--menu-border-strong);
}

.topnav__theme-toggle:focus-visible,
.burger:focus-visible {
  outline: 2px solid var(--mds-accent);
  outline-offset: 2px;
  border-color: var(--menu-border-strong);
}

.topnav__theme-track {
  width: 42px;
  height: 24px;
  padding: calc(var(--mds-space-1) / 4);
  display: inline-flex;
  align-items: center;
  border-radius: 9999px;
  background: color-mix(in srgb, var(--menu-text) 14%, transparent 86%);
}

.topnav__theme-thumb {
  width: 20px;
  height: 20px;
  border-radius: 9999px;
  background: var(--menu-accent);
  transform: translateX(0);
}

:root[data-theme="light"] .topnav__theme-thumb {
  transform: translateX(18px);
}

.topnav__theme-label {
  min-width: 4.8rem;
  font-size: var(--mds-text-sm);
  font-weight: 700;
  white-space: nowrap;
  text-align: left;
}

.burger {
  display: none;
  width: 44px;
  height: 44px;
  padding: 0;
  aspect-ratio: 1 / 1;
  flex: 0 0 44px;
  border: 1px solid var(--menu-border);
  border-radius: 9999px;
  background: var(--menu-surface);
  color: var(--menu-text);
  line-height: 0;
  touch-action: manipulation;
  position: relative;
  cursor: pointer;
}

.burger span {
  position: absolute;
  left: 12px;
  right: 12px;
  height: 2px;
  border-radius: 9999px;
  background: currentColor;
}

.burger span:nth-child(1) {
  top: 14px;
}

.burger span:nth-child(2) {
  top: 20px;
}

.burger span:nth-child(3) {
  top: 26px;
}

.topnav.open .burger span:nth-child(1) {
  top: 20px;
  transform: rotate(45deg);
}

.topnav.open .burger span:nth-child(2) {
  opacity: 0;
}

.topnav.open .burger span:nth-child(3) {
  top: 20px;
  transform: rotate(-45deg);
}

@media (max-width: 1100px) {
  .topnav {
    top: 0;
  }

  .topnav .container {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: var(--mds-space-1);
    padding: var(--mds-space-1) var(--mds-space-2);
    border-radius: var(--mds-radius-lg);
    overflow: visible;
  }

  .logo {
    width: clamp(124px, 38vw, 156px);
    height: 26px;
  }

  .topnav__desktop-tools {
    display: none;
  }

  .burger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    justify-self: end;
    width: 46px;
    height: 46px;
    flex-basis: 46px;
  }

  .menu {
    position: absolute;
    left: 0;
    right: 0;
    top: calc(100% + var(--mds-space-1));
    display: grid;
    gap: var(--mds-space-1);
    max-height: 0;
    opacity: 0;
    overflow: hidden;
    pointer-events: none;
  }

  .topnav.open .menu {
    max-height: min(420px, calc(100dvh - 92px));
    opacity: 1;
    pointer-events: auto;
  }

  .topnav__links {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
    gap: var(--mds-space-1);
    padding: var(--mds-space-1);
    max-height: min(420px, calc(100dvh - 92px));
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--mds-radius-lg);
    background: color-mix(in srgb, var(--mds-bg-soft) 92%, transparent 8%);
  }

  .topnav__links a {
    width: 100%;
    padding: var(--mds-space-2);
    border: 1px solid var(--menu-border);
    text-align: left;
    background: color-mix(in srgb, var(--mds-bg-soft) 80%, transparent 20%);
  }

  .topnav__mobile-tools {
    display: grid;
    grid-template-columns: 1fr;
    align-items: stretch;
    gap: var(--mds-space-1);
    padding-top: var(--mds-space-1);
    border-top: 1px solid var(--menu-border);
  }

  .topnav__mobile-tools .lang-switch {
    width: 100%;
    justify-content: flex-start;
    gap: var(--mds-space-1);
    padding: var(--mds-space-1);
  }

  .topnav__mobile-tools .lang-switch a {
    flex: 1 1 0;
    min-width: 0;
    padding: var(--mds-space-1) var(--mds-space-2);
    font-size: var(--mds-text-xs);
    letter-spacing: 0.1em;
    white-space: nowrap;
  }

  .topnav__mobile-tools .topnav__theme-toggle {
    width: 100%;
    min-width: 0;
    padding: var(--mds-space-1) var(--mds-space-2);
    gap: var(--mds-space-1);
    justify-content: space-between;
  }

  .topnav__mobile-tools .topnav__theme-label {
    min-width: 0;
    font-size: var(--mds-text-xs);
    text-align: right;
  }
}

@media (max-width: 640px) {
  .topnav .container {
    padding-inline: var(--mds-space-2);
  }
}

@media (prefers-reduced-motion: no-preference) {
  .logo-img,
  .topnav__links a,
  .lang-switch a,
  .topnav__theme-toggle,
  .topnav__theme-thumb,
  .burger span,
  .menu {
    transition:
      background 220ms ease,
      border-color 220ms ease,
      color 220ms ease,
      max-height 220ms ease,
      opacity 220ms ease,
      transform 220ms ease;
  }

  .topnav__theme-toggle:hover {
    transform: translateY(-2px);
  }

  @media (max-width: 1100px) {
    .menu {
      transform: translateY(calc(var(--mds-space-1) * -1));
    }

    .topnav.open .menu {
      transform: translateY(0);
    }
  }
}
