.header-tools {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: none;
}

.header-tool {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 10px;
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
}

.header-tool:hover,
.header-language[open] > summary {
  border-color: var(--line);
}

.header-tools svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
}

.header-tools :is(.header-action, .page-header-action) {
  margin-inline-start: 8px;
  white-space: nowrap;
}

.header-language {
  position: relative;
}

.header-language summary::-webkit-details-marker {
  display: none;
}

.header-language-options {
  position: absolute;
  z-index: 1;
  top: calc(100% + 7px);
  right: 0;
  display: grid;
  min-width: 132px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--paper);
  box-shadow: 0 8px 25px #2b1a071e;
}

.header-language-options button,
.header-drawer-language button {
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--ink);
  font: 500 14px var(--body);
  cursor: pointer;
}

.header-language-options button {
  text-align: left;
}

.header-tools [data-site-language][aria-pressed='true'] {
  border-color: var(--line);
  background: #efe6d8;
}

.header-menu-toggle {
  display: none;
}

html[data-chapter='opening'] .site-header .header-menu-toggle {
  display: grid;
}

body:has(.header-drawer[open]) {
  overflow: hidden;
}

dialog.header-drawer {
  position: fixed;
  inset: 0 0 0 auto;
  width: min(390px, calc(100% - 28px)) !important;
  height: 100dvh;
  max-height: none !important;
  margin: 0;
  padding: max(18px, env(safe-area-inset-top)) 24px max(24px, env(safe-area-inset-bottom));
  overflow: auto;
  overscroll-behavior: contain;
  border: 0;
  border-left: 1px solid var(--line);
  border-radius: 0 !important;
  background: var(--paper);
  box-shadow: -12px 0 48px #2b1a0724;
  color: var(--ink);
}

.header-drawer::backdrop {
  background: #24190f66;
}

.header-drawer-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
}

.header-drawer-top h2 {
  font: 500 30px var(--title);
}

.header-drawer-search {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 15px;
  margin-bottom: 12px;
}

.header-drawer-links {
  display: grid;
}

.header-drawer-links a {
  padding: 11px 2px;
  border-bottom: 1px solid var(--line);
  font-size: 16px;
}

.header-drawer-links a[aria-current='page'] {
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 5px;
}

.header-drawer-language {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 18px;
}

@media (max-width: 1080px) {
  .site-header > .header-nav,
  .page-header > .page-nav,
  .header-language {
    display: none;
  }

  .header-menu-toggle {
    display: grid;
  }

  .header-tools :is(.header-action, .page-header-action) {
    margin-inline: 4px;
  }
}

@media (max-width: 480px) {
  .site-header,
  .page-header {
    padding-inline: 16px;
    gap: 6px;
  }

  .header-tools {
    gap: 2px;
  }

  .site-header .header-logo,
  .page-header .header-logo {
    width: clamp(88px, 26vw, 112px);
  }

  .header-tools :is(.header-action, .page-header-action) {
    font-size: 13px;
    padding-inline: 9px;
  }
}

@media (max-width: 360px) {
  .header-search {
    display: none;
  }
}

@media (prefers-reduced-motion: no-preference) {
  .header-drawer[open] {
    animation: header-drawer-enter 180ms ease-out;
  }

  @keyframes header-drawer-enter {
    from { transform: translateX(100%); }
    to { transform: translateX(0); }
  }
}
