/* Site chrome: header bar + fullscreen menu panel.
   Rich-rollout stage 0 (2026-11-11): the panel is a sibling of the header
   nav (emitted by siteHeader() in site-navigation.mjs), never a descendant,
   so no ancestor backdrop-filter/filter can become its containing block.
   Defect fixes D1-D6 from the rollout plan are implemented here and in
   menu.js: scroll lock, panel-internal scrolling, chrome kept on the top
   layer in paper colour, progress bar below the panel, open/close
   transitions, Esc / backdrop click to close.
   Fix round 2 (2026-11-11): the header bar itself is position:fixed, as in
   the canonical rich design (.site-header) — in round 1 it sat in normal
   flow, so past ~60px of scroll the toggle left the viewport and any real
   click first scrolled the page back to the top. The panel remains a
   body-level sibling, so the header's own backdrop-filter (its .scrolled
   ground) can never become the panel's containing block. */
:root{
  --menu-paper:#faf7ef;
  --menu-navy:#1e2742;
  --menu-navy-deep:#121830;
  --menu-gold:#b08d2a;
  --menu-gold-bright:#e9d9a8;
  --menu-hair-paper:rgba(250,247,239,.22);
  --menu-mincho:"Hiragino Mincho ProN","Hiragino Mincho Pro","YuMincho","Yu Mincho","Noto Serif JP","Songti SC",serif;
  --menu-ease:cubic-bezier(.22,.9,.26,1);
}
html{scrollbar-gutter:stable}
/* Layout compensation for the fixed header: the bar is 76px tall (14px
   padding + 48px controls + 14px padding) and no longer occupies flow
   space, so the body keeps that much room at the top and no page head can
   slide under the bar. This is a uniform offset preserving the pre-fixed
   layout on every page type; stage 1 may replace it with per-type hero
   designs that run under the transparent bar. */
body{padding-top:76px}
/* Scroll lock while the menu is open. overflow:hidden stops user scrolling;
   overflow:clip additionally makes the root a non-scroll container, so even
   programmatic scrolls cannot move the page behind the panel (D1). */
html.menu-open,body.menu-open{overflow:hidden;overflow:clip}
/* rich.css carries Lenis's own .lenis-stopped overflow rule at higher
   specificity; the menu lock must win over it while both apply. */
html.menu-open.lenis-stopped{overflow:clip}

/* ---------- header bar ---------- */
.site-menu{box-sizing:border-box;position:fixed;top:0;left:0;right:0;z-index:90;padding:14px clamp(18px,4vw,44px);display:flex;align-items:center;justify-content:space-between;font:14px/1.5 -apple-system,BlinkMacSystemFont,"Yu Gothic",sans-serif;color:#222;transition:background .5s var(--menu-ease),box-shadow .5s var(--menu-ease)}
/* Scrolled ground (canonical .site-header.scrolled): paper at 86% with a
   blur and a hairline under the bar. The class is toggled from menu.js
   past 40px of scroll. The panel is not a descendant of this bar, so this
   backdrop-filter is safe (see the round-2 note at the top of this file). */
.site-menu.scrolled{background:rgba(250,247,239,.86);backdrop-filter:blur(14px);-webkit-backdrop-filter:blur(14px);box-shadow:0 1px 0 rgba(30,39,66,.16)}
.site-menu details{position:relative}
.site-menu summary{list-style:none;cursor:pointer;width:48px;height:48px;display:flex;align-items:center;justify-content:center;border-radius:999px;background:transparent;border:1px solid #ded8cb}
.site-menu summary::-webkit-details-marker{display:none}
.site-menu summary:hover{background:rgba(20,38,79,.05)}
.site-menu summary:focus-visible,.site-menu a:focus-visible,.menu-toggle:focus-visible{outline:2px solid #222;outline-offset:4px}
.site-menu a{display:block;padding:12px 16px;color:inherit;text-decoration:none;white-space:nowrap}
.site-menu a:hover{background:rgba(20,38,79,.05)}
.site-menu a[aria-current]{text-decoration:underline;text-underline-offset:4px}
.language-links{background:#fffdf7;border-color:#ded8cb;border-radius:12px}

/* ---------- menu toggle button ---------- */
.menu-toggle{box-sizing:border-box;width:48px;height:48px;flex:none;display:flex;align-items:center;justify-content:center;padding:0;border-radius:999px;background:transparent;border:1px solid #ded8cb;color:inherit;cursor:pointer}
.menu-toggle:hover{background:rgba(20,38,79,.05)}
.menu-icon{display:inline-flex;flex-direction:column;gap:5px}
.menu-icon i{display:block;width:22px;height:2px;background:currentColor;transition:transform .45s var(--menu-ease),opacity .3s var(--menu-ease)}
.menu-toggle[aria-expanded="true"] .menu-icon i:nth-child(1){transform:translateY(7px) rotate(45deg)}
.menu-toggle[aria-expanded="true"] .menu-icon i:nth-child(2){opacity:0}
.menu-toggle[aria-expanded="true"] .menu-icon i:nth-child(3){transform:translateY(-7px) rotate(-45deg)}

/* ---------- header chrome while the menu is open (D3/D4) ---------- */
/* The bar is already fixed with this exact geometry; opening only lifts
   it above the panel (z 120), switches the chrome to paper, and drops the
   scrolled ground so the navy panel shows through cleanly.
   Overflow fix (2026-11-14): now that the panel scrolls, a transparent
   bar would let links slide under the wordmark and controls and collide
   with them mid-scroll. The open bar therefore carries the panel's own
   navy as its ground — visually one continuous navy surface, since the
   panel's gradient starts at the same navy — plus a soft navy shadow
   under the bar so links pass beneath it without a hard cut. */
body.menu-open .site-menu{z-index:120;color:var(--menu-paper);background:var(--menu-navy);backdrop-filter:none;-webkit-backdrop-filter:none;box-shadow:0 22px 26px -14px rgba(18,24,48,.8)}
body.menu-open .site-menu .brand-logo{filter:brightness(0) invert(1)}
body.menu-open .site-menu summary,body.menu-open .menu-toggle{border-color:var(--menu-hair-paper);color:var(--menu-paper)}
body.menu-open .site-menu summary:hover,body.menu-open .menu-toggle:hover{background:rgba(250,247,239,.08)}
body.menu-open .site-menu summary:focus-visible,body.menu-open .site-menu a:focus-visible,body.menu-open .menu-toggle:focus-visible{outline-color:var(--menu-gold-bright)}

/* ---------- fullscreen panel (R8) ---------- */
/* Overflow fix (2026-11-14, Asahi's iPhone report): the panel declared
   overflow-y:auto all along, but it could not actually be scrolled —
   menu.js stops Lenis while the menu is open, and Lenis's virtual-scroll
   handler preventDefaults every wheel/touchmove that does not cross a
   [data-lenis-prevent] element, so all scroll gestures over the panel
   were swallowed and the last links stayed cut off below the fold.
   siteHeader() now emits data-lenis-prevent on the panel, which makes
   Lenis leave the panel's native scrolling alone. The bottom padding
   additionally clears the iOS home-indicator / browser-bar area via
   safe-area-inset-bottom, so the final link can rest fully visible. */
.menu-panel{
  position:fixed;top:0;left:0;width:100vw;height:100dvh;z-index:110;
  box-sizing:border-box;
  background:linear-gradient(160deg,var(--menu-navy) 0%,var(--menu-navy-deep) 78%);
  padding:104px clamp(22px,8vw,110px) calc(56px + env(safe-area-inset-bottom, 0px));
  overflow-y:auto;overscroll-behavior:contain;
  opacity:0;visibility:hidden;
  transition:opacity .3s cubic-bezier(.4,0,1,1),visibility 0s linear .3s;
}
/* "More below" cue: a soft navy fade pinned to the panel's bottom edge
   while the list overflows (sticky at the scrollport's bottom). It rests
   in the empty space after the last link once fully scrolled, and over
   plain navy when the list fits, so it never covers a link. */
.menu-panel::after{
  content:"";display:block;position:sticky;bottom:0;height:44px;
  margin-top:8px;pointer-events:none;
  background:linear-gradient(to bottom,rgba(18,24,48,0),var(--menu-navy-deep));
}
/* (No ::before scrim: the open-state header ground below handles the
   top edge instead — see the D3/D4 chrome rule.) */
.menu-panel.is-open{opacity:1;visibility:visible;transition:opacity .35s cubic-bezier(0,0,.2,1),visibility 0s}
.menu-panel .menu-links{display:flex;flex-direction:column;gap:2px;align-items:flex-start;max-height:none;overflow:visible}
.menu-panel .menu-links a{
  color:var(--menu-paper);text-decoration:none;
  font-family:var(--menu-mincho);
  font-size:clamp(22px,3.6vw,34px);line-height:1.5;letter-spacing:.04em;
  padding:4px 0;width:fit-content;max-width:100%;position:relative;white-space:normal;
}
.menu-panel .menu-links a::after{content:"";position:absolute;left:0;bottom:2px;height:1px;width:100%;background:var(--menu-gold);transform:scaleX(0);transform-origin:0 50%;transition:transform .5s var(--menu-ease)}
.menu-panel .menu-links a:hover::after{transform:scaleX(1)}
.menu-panel .menu-links a:focus-visible{outline:2px solid var(--menu-gold-bright);outline-offset:4px}
.menu-panel .menu-links a[aria-current="page"]{text-decoration:underline;text-decoration-color:var(--menu-gold);text-underline-offset:7px}
.menu-panel .menu-links a.declaration-menu-link{color:var(--menu-gold-bright)}
/* Enrollment entry (JA only, Asahi 2026-11-13): the one light block on
   the navy panel — paper fill, navy text, gold ring (line) and gold
   diamond (point), so the dedicated enrollment page is identifiable
   at a glance without disturbing the panel's typography. */
.menu-panel .menu-links a.enroll-menu-link{
  background:var(--menu-paper);color:var(--menu-navy);
  padding:8px 20px 8px 16px;margin:10px 0 12px;
  box-shadow:inset 0 0 0 1px var(--menu-gold);
}
.menu-panel .menu-links a.enroll-menu-link::before{content:"◆";color:var(--menu-gold);font-size:.6em;margin-right:.6em;vertical-align:.16em}
.menu-panel .menu-links a.enroll-menu-link::after{content:none}
.menu-panel .menu-links a.enroll-menu-link:hover{background:#fff}
/* Accordion categories (2026-11-16 menu reorganization): category
   headers are real <button> elements interleaved in the same flat flow
   as the links — category members stay direct children of .menu-links
   (the blog check counts .menu-links>a) and collapse via the hidden
   attribute rather than a wrapper, which also keeps the panel free of
   nested divs for build-i18n's strip regex. The enroll-menu-link rules
   above are retained for history; the enrollment entry now renders as
   a normal category member and no longer carries that class. */
.menu-panel .menu-links a[hidden]{display:none}
.menu-panel .menu-links .menu-cat-toggle{
  appearance:none;-webkit-appearance:none;background:none;border:0;cursor:pointer;
  font-family:var(--menu-mincho);color:var(--menu-paper);
  font-size:clamp(21px,3.3vw,31px);line-height:1.5;letter-spacing:.04em;
  padding:4px 0;margin:20px 0 0;width:fit-content;max-width:100%;
  display:flex;align-items:center;gap:.55em;text-align:left;position:relative;
}
.menu-panel .menu-links .menu-cat-toggle .menu-cat-caret{color:var(--menu-gold);font-size:.52em;line-height:1;transition:transform .35s var(--menu-ease)}
.menu-panel .menu-links .menu-cat-toggle[aria-expanded="true"] .menu-cat-caret{transform:rotate(180deg)}
.menu-panel .menu-links .menu-cat-toggle:focus-visible{outline:2px solid var(--menu-gold-bright);outline-offset:4px}
.menu-panel .menu-links a.menu-cat-link{padding-left:clamp(20px,3.2vw,32px)}
/* The standalone paid entry keeps its 20px separation from the group
   above. It was previously the panel's last anchor (:last-of-type);
   since the Database category follows it (2026-11-17) the rule now
   targets the paid link itself (every locale path ends /paid-content/). */
.menu-panel .menu-links a[href$="/paid-content/"]{margin-top:20px}
@media (prefers-reduced-motion: no-preference){
  .menu-panel.is-open .menu-links a{animation:menuLinkIn .6s var(--menu-ease) backwards}
  .menu-panel.is-open .menu-links .menu-cat-toggle{animation:menuLinkIn .6s var(--menu-ease) backwards;animation-delay:.06s}
  .menu-panel.is-open .menu-links a:nth-child(1){animation-delay:.04s}
  .menu-panel.is-open .menu-links a:nth-child(2){animation-delay:.08s}
  .menu-panel.is-open .menu-links a:nth-child(3){animation-delay:.12s}
  .menu-panel.is-open .menu-links a:nth-child(4){animation-delay:.16s}
  .menu-panel.is-open .menu-links a:nth-child(5){animation-delay:.20s}
  .menu-panel.is-open .menu-links a:nth-child(6){animation-delay:.24s}
  .menu-panel.is-open .menu-links a:nth-child(7){animation-delay:.28s}
  .menu-panel.is-open .menu-links a:nth-child(8){animation-delay:.32s}
  .menu-panel.is-open .menu-links a:nth-child(9){animation-delay:.36s}
  .menu-panel.is-open .menu-links a:nth-child(10){animation-delay:.40s}
  .menu-panel.is-open .menu-links a:nth-child(11){animation-delay:.44s}
  .menu-panel.is-open .menu-links a:nth-child(12){animation-delay:.48s}
  .menu-panel.is-open .menu-links a:nth-child(13){animation-delay:.52s}
}
@keyframes menuLinkIn{from{opacity:0;transform:translateY(18px)}to{opacity:1;transform:none}}
@media (max-width:820px){
  .menu-panel{padding:96px 24px calc(40px + env(safe-area-inset-bottom, 0px))}
}
@media (prefers-reduced-motion: reduce){
  .site-menu{transition:none}
  .menu-panel,.menu-panel.is-open{transition:none}
  .menu-icon i{transition:none}
  .menu-panel .menu-links a::after{transition:none}
  .menu-panel .menu-links .menu-cat-toggle .menu-cat-caret{transition:none}
}
@media print{
  body{padding-top:0}
  .menu-panel,.menu-toggle{display:none!important}
}
