/* =========================================================
   Language switcher
   Wrapper is position:relative; menu is position:absolute below the button.
   No transforms, no centering — just top:100%; right:0.
   ========================================================= */

.lang-switcher {
  position: relative;
  display: inline-flex;   /* shrink wrapper to button width */
}

.lang-btn {
  display: inline-flex; align-items: center; gap: 8px;
  height: 38px;
  padding: 0 12px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-1);
  background: var(--surface);
  border: 1px solid var(--line);
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease;
}
.lang-btn:hover { background: var(--bg-sunken); border-color: var(--line-strong); }
.lang-btn[aria-expanded="true"] {
  background: var(--bg-sunken);
  border-color: var(--accent);
}
.lang-btn .lang-globe { display: none; }
img.lang-flag { display: inline-block; width: 20px; height: 15px; object-fit: cover; border-radius: 2px; vertical-align: middle; box-shadow: 0 0 0 1px rgba(0,0,0,0.08); }
.lang-btn .lang-code {
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.06em;
  font-weight: 700;
}
.lang-btn svg.lang-caret { opacity: .6; }

/* Dropdown — position straight below the button, right-edge aligned */
.lang-menu {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 8px;
  width: 220px;
  list-style: none;
  margin-bottom: 0;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  z-index: 1000;
  max-height: min(60vh, 480px);
  overflow-y: auto;
  overscroll-behavior: contain;
}
.lang-menu[hidden] { display: none; }

.lang-menu li { margin: 0; }
.lang-menu a {
  display: grid;
  grid-template-columns: 24px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: 8px;
  color: var(--ink-1);
  text-decoration: none;
  font-size: 15px;
  transition: background .12s ease;
}
.lang-menu a:hover { background: var(--bg-sunken); }
.lang-menu a.is-active {
  background: var(--bg-sunken);
  color: var(--ink-1);
  font-weight: 600;
}
.lang-menu .lang-code-mini {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--ink-3);
  text-align: left;
}
.lang-menu a:hover .lang-code-mini,
.lang-menu a.is-active .lang-code-mini { color: var(--ink-1); }
.lang-menu img.lang-flag { width: 24px; height: 18px; }
.lang-menu .lang-label { font-weight: 500; }
.lang-menu a.is-active .lang-label { font-weight: 600; }

/* Custom scrollbar */
.lang-menu::-webkit-scrollbar { width: 6px; }
.lang-menu::-webkit-scrollbar-track { background: transparent; }
.lang-menu::-webkit-scrollbar-thumb {
  background: var(--line-strong);
  border-radius: 3px;
}
.lang-menu::-webkit-scrollbar-thumb:hover { background: var(--ink-3); }

/* RTL — flip anchor to left edge of button */
html[dir="rtl"] .lang-menu { right: auto; left: 0; }
html[dir="rtl"] body { text-align: right; }


/* =========================================================
   Mobile drawer menu (half-width)
   ========================================================= */
.m-menu-backdrop {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.55);
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s ease;
  z-index: 998;
  backdrop-filter: blur(2px);
}
.m-menu-backdrop.open { opacity: 1; pointer-events: auto; }

.m-menu {
  position: fixed;
  top: 0; right: 0;
  width: min(78vw, 340px);
  height: 100dvh;
  background: var(--surface);
  border-left: 1px solid var(--line);
  box-shadow: -16px 0 48px rgba(0, 0, 0, 0.55);
  transform: translateX(105%);
  transition: transform .28s cubic-bezier(.4,.1,.25,1);
  z-index: 999;
  display: flex; flex-direction: column;
  overflow-y: auto;
}
.m-menu.open { transform: translateX(0); }

.m-menu-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.m-menu-brand {
  display: inline-flex; align-items: center; gap: 8px;
  text-decoration: none;
  color: var(--ink-1);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 15px;
}
.m-menu-close {
  width: 36px; height: 36px;
  border-radius: 10px;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink-2);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .12s ease, color .12s ease;
}
.m-menu-close:hover { background: var(--bg-sunken); color: var(--ink-1); }

.m-menu-nav {
  flex: 1;
  display: flex; flex-direction: column;
  padding: 14px 10px;
  gap: 2px;
}
.m-menu-nav .m-link {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 14px;
  border-radius: 12px;
  color: var(--ink-2);
  text-decoration: none;
  font-size: 15px;
  font-weight: 500;
  transition: background .12s ease, color .12s ease;
}
.m-menu-nav .m-link:hover,
.m-menu-nav .m-link.is-active {
  background: var(--bg-sunken);
  color: var(--ink-1);
}
.m-menu-nav .m-link svg { flex-shrink: 0; color: var(--ink-3); }
.m-menu-nav .m-link:hover svg,
.m-menu-nav .m-link.is-active svg { color: var(--accent-hover); }

.m-menu-foot {
  display: flex; gap: 16px;
  padding: 14px 22px 22px;
  border-top: 1px solid var(--line);
  flex-shrink: 0;
}
.m-menu-foot a { color: var(--ink-3); font-size: 13px; text-decoration: none; }
.m-menu-foot a:hover { color: var(--ink-1); }

html[dir="rtl"] .m-menu {
  right: auto; left: 0;
  border-left: 0; border-right: 1px solid var(--line);
  transform: translateX(-105%);
  box-shadow: 16px 0 48px rgba(0, 0, 0, 0.55);
}
html[dir="rtl"] .m-menu.open { transform: translateX(0); }

body.menu-open { overflow: hidden; }
