/*
 * Zero Next One BASE NIIKAPPU
 * Persistent header language selector — Phase 3A
 * Existing hamburger/footer JP / EN controls are intentionally untouched.
 */

.l-header-language {
  position: relative;
  z-index: 8;
  flex: 0 0 auto;
  order: 2;
  color: inherit;
  pointer-events: auto;
}

.l-header-language__button {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  width: 44px;
  min-width: 44px;
  height: 40px;
  padding: 0;
  border: 1px solid rgba(21, 39, 61, 0.16);
  border-radius: 13px;
  color: inherit;
  background: rgba(255, 252, 245, 0.42);
  box-shadow:
    0 5px 14px rgba(21, 39, 61, 0.07),
    inset 0 1px 0 rgba(255, 255, 255, 0.45);
  -webkit-backdrop-filter: blur(10px) saturate(1.04);
  backdrop-filter: blur(10px) saturate(1.04);
  cursor: pointer;
  appearance: none;
  transition:
    transform 0.2s ease,
    border-color 0.2s ease,
    background-color 0.2s ease,
    box-shadow 0.2s ease;
}

.l-header-language__button:hover,
.l-header-language__button:focus-visible,
.l-header-language.is-open .l-header-language__button {
  transform: translateY(-1px);
  border-color: rgba(21, 39, 61, 0.3);
  background: rgba(255, 252, 245, 0.68);
  box-shadow:
    0 8px 18px rgba(21, 39, 61, 0.12),
    inset 0 1px 0 rgba(255, 255, 255, 0.58);
}

.l-header-language__button:focus-visible,
.l-header-language__option:focus-visible {
  outline: 2px solid rgba(203, 163, 88, 0.92);
  outline-offset: 3px;
}

.l-header-language__current-flag,
.l-header-language__flag {
  display: block;
  width: 24px;
  height: 16px;
  object-fit: cover;
  border-radius: 2px;
  box-shadow: 0 0 0 1px rgba(21, 39, 61, 0.15);
}

.l-header-language__chevron {
  display: block;
  width: 6px;
  height: 6px;
  margin-top: -3px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  opacity: 0.72;
  transform: rotate(45deg);
  transition: transform 0.2s ease, margin-top 0.2s ease;
}

.l-header-language.is-open .l-header-language__chevron {
  margin-top: 3px;
  transform: rotate(225deg);
}

.l-header-language__menu {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  z-index: 12;
  width: min(270px, calc(100vw - 28px));
  padding: 12px;
  color: #15273d;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.75), rgba(255, 255, 255, 0.22)),
    #f7f1e4;
  border: 1px solid rgba(74, 55, 32, 0.14);
  border-radius: 17px;
  box-shadow:
    0 20px 44px rgba(10, 23, 34, 0.2),
    0 2px 6px rgba(10, 23, 34, 0.08),
    inset 0 1px 0 rgba(255, 255, 255, 0.7);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translate3d(0, -6px, 0) scale(0.98);
  transform-origin: top right;
  transition:
    opacity 0.16s ease,
    visibility 0.16s ease,
    transform 0.16s ease;
}

.l-header-language.is-open .l-header-language__menu {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translate3d(0, 0, 0) scale(1);
}

.l-header-language__menu-title {
  margin: 0;
  padding: 4px 8px 10px;
  color: rgba(21, 39, 61, 0.56);
  font-family: var(--font-ui, "Inter", sans-serif);
  font-size: 0.68rem;
  font-weight: 750;
  line-height: 1;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.l-header-language__list {
  display: grid;
  gap: 3px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.l-header-language__item {
  min-width: 0;
}

.l-header-language__option {
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 6px 9px;
  border-radius: 11px;
  color: #15273d;
  font-family: var(--font-ui, "Inter", sans-serif);
  font-size: 0.86rem;
  font-weight: 650;
  line-height: 1.25;
  letter-spacing: 0.01em;
  text-decoration: none;
  transition: background-color 0.16s ease, transform 0.16s ease;
}

.l-header-language__option[href]:hover,
.l-header-language__option[href]:focus-visible {
  background: rgba(21, 39, 61, 0.065);
  transform: translateX(1px);
}

.l-header-language__option.is-current {
  background: rgba(203, 163, 88, 0.13);
  color: #10263b;
}

.l-header-language__option.is-disabled {
  color: rgba(21, 39, 61, 0.48);
  cursor: not-allowed;
}

.l-header-language__option.is-disabled .l-header-language__flag {
  filter: saturate(0.55);
  opacity: 0.65;
}

.l-header-language__flag-frame {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 22px;
}

.l-header-language__option-label {
  min-width: 0;
}

.l-header-language__current-mark {
  color: #8b6a25;
  font-size: 0.82rem;
  font-weight: 800;
}

.l-header-language__status {
  padding: 3px 6px;
  border-radius: 999px;
  color: rgba(21, 39, 61, 0.5);
  background: rgba(21, 39, 61, 0.055);
  font-size: 0.59rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

/* Dark visual sections and open hamburger-menu rail. */
body[data-active-section="sec01"] .l-header-language__button,
body[data-active-section="sec04"] .l-header-language__button,
body[data-active-section="sec09"] .l-header-language__button,
body.is-menu-open .l-header-language__button {
  border-color: rgba(255, 250, 240, 0.22);
  color: #fffaf0;
  background: rgba(8, 18, 25, 0.2);
  box-shadow:
    0 6px 18px rgba(0, 0, 0, 0.11),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

body[data-active-section="sec01"] .l-header-language__button:hover,
body[data-active-section="sec04"] .l-header-language__button:hover,
body[data-active-section="sec09"] .l-header-language__button:hover,
body.is-menu-open .l-header-language__button:hover,
body[data-active-section="sec01"] .l-header-language__button:focus-visible,
body[data-active-section="sec04"] .l-header-language__button:focus-visible,
body[data-active-section="sec09"] .l-header-language__button:focus-visible,
body.is-menu-open .l-header-language__button:focus-visible {
  background: rgba(8, 18, 25, 0.36);
  border-color: rgba(255, 250, 240, 0.4);
}

@media (max-width: 1023px) {
  .l-site-header__brand {
    order: 1;
    max-width: calc(100% - 108px);
  }

  .l-header-language {
    order: 2;
  }

  .l-site-header__menu-button {
    order: 3;
  }

  .l-site-header__nav {
    order: 4;
  }

  .l-header-language__button {
    width: 42px;
    min-width: 42px;
    height: 42px;
    border-radius: 14px;
  }

  .l-header-language__menu {
    position: fixed;
    top: calc(var(--sp-header-top, 12px) + var(--sp-header-height, 58px) + 8px);
    right: max(var(--sp-header-side, 12px), env(safe-area-inset-right));
    width: min(274px, calc(100vw - 24px));
    max-height: calc(100dvh - var(--sp-header-height, 58px) - var(--sp-header-top, 12px) - 24px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
}

@media (min-width: 1024px) {
  .l-site-header__brand {
    order: 1;
  }

  .l-site-header__nav {
    order: 2;
    margin-left: auto;
  }

  .l-header-language {
    order: 3;
  }

  .l-site-header__menu-button {
    order: 4;
  }
}

@media (max-width: 374px) {
  .l-site-header__brand {
    max-width: calc(100% - 102px);
  }

  .l-header-language__button {
    width: 40px;
    min-width: 40px;
    height: 40px;
  }

  .l-header-language__current-flag {
    width: 22px;
    height: 15px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .l-header-language__button,
  .l-header-language__chevron,
  .l-header-language__menu,
  .l-header-language__option {
    transition: none !important;
  }
}

/* On desktop the new flag selector is the sole persistent language control.
   The existing JP / EN switch stays inside the hamburger overlay on mobile
   and remains in the footer at every width. */
@media (min-width: 1024px) {
  .l-language-switch--header {
    display: none !important;
  }
}

/* --------------------------------------------------------------------------
   Phase 3D.2: Mobile language control spacing and open-menu collision fix
   -------------------------------------------------------------------------- */
@media (max-width: 767px) {
  .l-site-header__inner {
    column-gap: 8px !important;
  }

  .l-site-header__brand {
    flex: 1 1 auto !important;
    min-width: 0 !important;
    max-width: none !important;
  }

  .l-header-language {
    flex: 0 0 56px;
  }

  .l-header-language__button {
    width: 56px;
    min-width: 56px;
    height: 44px;
    padding: 0 9px;
    gap: 7px;
    border-radius: 15px;
  }

  .l-header-language__current-flag {
    width: 25px;
    height: 17px;
  }

  .l-header-language__chevron {
    width: 7px;
    height: 7px;
    flex: 0 0 auto;
  }

  /* The overlay already contains its compact JP / EN control. Hiding the
     persistent selector leaves a clean, dedicated CLOSE control. */
  body.is-menu-open .l-header-language,
  html.is-menu-open .l-header-language {
    display: none !important;
  }

  body.is-menu-open .l-site-header__brand,
  html.is-menu-open .l-site-header__brand {
    max-width: calc(100% - 106px) !important;
  }
}

@media (max-width: 374px) {
  .l-header-language {
    flex-basis: 52px;
  }

  .l-header-language__button {
    width: 52px;
    min-width: 52px;
    height: 42px;
    padding-inline: 8px;
    gap: 6px;
  }

  .l-header-language__current-flag {
    width: 23px;
    height: 16px;
  }
}
