/* Shared brand design system and persistent header shell for every public Marupopo page. */
:root {
  color-scheme: light;

  /* Canonical brand palette. Keep these names mirrored by website_maru_editor/src/brand-system.css. */
  --brand-bg: #fffaf0;
  --brand-paper: #fffef9;
  --brand-surface: #ffffff;
  --brand-surface-soft: #fff8dd;
  --brand-surface-muted: #f8f4eb;
  --brand-ink: #3f372f;
  --brand-muted: #746b62;
  --brand-line: rgba(63,55,47,.12);
  --brand-yellow: #ffd95e;
  --brand-yellow-soft: #fff1b7;
  --brand-yellow-pale: #fff8dd;
  --brand-mint: #bfe8d8;
  --brand-mint-dark: #397b69;
  --brand-pink: #ffd9df;
  --brand-blue: #dff2ff;

  /* Canonical typography scale. */
  --brand-font-body: "Noto Sans JP", "Hiragino Sans", "Yu Gothic", "Meiryo", sans-serif;
  --brand-font-display: "Zen Maru Gothic", "Noto Sans JP", "Hiragino Maru Gothic ProN", sans-serif;
  --brand-text-xs: .75rem;
  --brand-text-sm: .875rem;
  --brand-text-base: 1rem;
  --brand-text-lg: 1.125rem;
  --brand-heading-card: 1.25rem;
  --brand-heading-section: clamp(1.75rem, 3.9vw, 3.35rem);
  --brand-heading-page: clamp(2.35rem, 5vw, 4.35rem);

  /* Canonical spacing rhythm. */
  --brand-space-1: 4px;
  --brand-space-2: 8px;
  --brand-space-3: 12px;
  --brand-space-4: 16px;
  --brand-space-5: 24px;
  --brand-space-6: 32px;
  --brand-space-7: 48px;
  --brand-space-8: 64px;
  --brand-section-space: 108px;
  --brand-gutter: 48px;
  --brand-gutter-tablet: 34px;
  --brand-gutter-mobile: 28px;

  /* Canonical shape and elevation scale. */
  --brand-radius-sm: 10px;
  --brand-radius-md: 17px;
  --brand-radius-lg: 24px;
  --brand-radius-xl: 34px;
  --brand-radius-2xl: 42px;
  --brand-radius-pill: 999px;
  --brand-shadow-xs: 0 5px 16px rgba(84,65,33,.07);
  --brand-shadow-sm: 0 9px 26px rgba(92,71,36,.09);
  --brand-shadow-md: 0 18px 54px rgba(92,71,36,.11);
  --brand-shadow-lg: 0 24px 70px rgba(94,68,48,.10);
  --brand-container: 1180px;

  /* Backward-compatible public-site aliases. Existing pages consume these names. */
  --bg: var(--brand-bg);
  --paper: var(--brand-paper);
  --ink: var(--brand-ink);
  --muted: var(--brand-muted);
  --yellow: var(--brand-yellow);
  --yellow-soft: var(--brand-yellow-soft);
  --yellow-pale: var(--brand-yellow-pale);
  --mint: var(--brand-mint);
  --mint-dark: var(--brand-mint-dark);
  --pink: var(--brand-pink);
  --blue: var(--brand-blue);
  --line: var(--brand-line);
  --shadow: var(--brand-shadow-md);
  --shadow-sm: var(--brand-shadow-sm);
  --radius-xl: var(--brand-radius-xl);
  --radius-lg: var(--brand-radius-lg);
  --radius-md: var(--brand-radius-md);
  --radius: var(--brand-radius-lg);
  --container: var(--brand-container);
  --font-body: var(--brand-font-body);
  --font-display: var(--brand-font-display);
  --cream: var(--brand-yellow-pale);

  /* Shared-shell aliases. */
  --shell-bg: var(--brand-bg);
  --shell-paper: var(--brand-paper);
  --shell-ink: var(--brand-ink);
  --shell-line: var(--brand-line);
  --shell-yellow: var(--brand-yellow);
  --shell-yellow-pale: var(--brand-yellow-pale);
  --shell-shadow: var(--brand-shadow-sm);
  --shell-width: var(--brand-container);
}

.site-header.shared-site-header .sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

.site-header.shared-site-header,
body .seo-header {
  position: sticky;
  top: 0;
  z-index: 100;
  border-bottom: 1px solid transparent;
  background: rgba(255,250,240,.94);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  box-shadow: var(--brand-shadow-xs);
}

.site-header.shared-site-header.is-scrolled,
body .seo-header { border-bottom-color: var(--shell-line); }

.site-shell-container,
body .seo-header .seo-shell {
  width: min(calc(100% - var(--brand-gutter)), var(--shell-width));
  margin-inline: auto;
}

.site-header.shared-site-header .header-inner,
body .seo-header .seo-header-inner {
  min-height: 80px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--brand-space-5);
}

.site-header.shared-site-header .brand,
body .seo-header .seo-brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
  color: var(--shell-ink);
  text-decoration: none;
  flex: 0 0 auto;
}

.site-header.shared-site-header .brand img,
body .seo-header .seo-brand img {
  width: 52px;
  height: 52px;
  flex: 0 0 auto;
  object-fit: contain;
  border-radius: var(--brand-radius-md);
  background: var(--brand-surface);
  box-shadow: var(--brand-shadow-xs);
}

.site-header.shared-site-header .brand span,
body .seo-header .seo-brand span {
  display: grid;
  min-width: 0;
  line-height: 1.2;
}

.site-header.shared-site-header .brand small,
body .seo-header .seo-brand small {
  color: var(--shell-ink);
  font-size: .62rem;
  font-weight: 600;
  letter-spacing: .06em;
}

.site-header.shared-site-header .brand strong,
body .seo-header .seo-brand strong {
  color: var(--shell-ink);
  font-family: var(--brand-font-display);
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: .05em;
}

.site-header.shared-site-header .global-nav,
body .seo-header .seo-nav {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px 19px;
  min-width: 0;
  max-width: 100%;
  font-size: .82rem;
  font-weight: 700;
}

.site-header.shared-site-header .global-nav a,
body .seo-header .seo-nav a {
  position: relative;
  padding: 10px 2px;
  color: var(--shell-ink);
  text-decoration: none;
  white-space: nowrap;
  border: 0;
}

.site-header.shared-site-header .global-nav a::after,
body .seo-header .seo-nav a::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: 3px;
  width: 100%;
  height: 3px;
  border-radius: var(--brand-radius-pill);
  background: var(--shell-yellow);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform .2s ease;
}

.site-header.shared-site-header .global-nav a:hover::after,
.site-header.shared-site-header .global-nav a:focus-visible::after,
.site-header.shared-site-header .global-nav a[aria-current="page"]::after,
body .seo-header .seo-nav a:hover::after,
body .seo-header .seo-nav a:focus-visible::after,
body .seo-header .seo-nav a[aria-current="page"]::after { transform: scaleX(1); }

.site-header.shared-site-header .nav-contact {
  padding-inline: 15px;
  border-radius: var(--brand-radius-pill);
  background: var(--shell-yellow-pale);
}

.site-header.shared-site-header .menu-button {
  display: none;
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  place-content: center;
  gap: 5px;
  border: 0;
  border-radius: 13px;
  background: var(--shell-yellow);
  color: var(--shell-ink);
  cursor: pointer;
}

.site-header.shared-site-header .menu-button span:not(.sr-only) {
  display: block;
  width: 20px;
  height: 2px;
  border-radius: var(--brand-radius-pill);
  background: currentColor;
  transition: transform .2s ease, opacity .2s ease;
}

.site-header.shared-site-header .menu-button[aria-expanded="true"] span:nth-of-type(2) { transform: translateY(7px) rotate(45deg); }
.site-header.shared-site-header .menu-button[aria-expanded="true"] span:nth-of-type(3) { opacity: 0; }
.site-header.shared-site-header .menu-button[aria-expanded="true"] span:nth-of-type(4) { transform: translateY(-7px) rotate(-45deg); }
body.menu-open { overflow: hidden; }

:where(a, button, input, select, textarea):focus-visible {
  outline: 3px solid #6b5317;
  outline-offset: 4px;
  border-radius: 8px;
}

.book-choice-reason {
  display: grid;
  gap: var(--brand-space-1);
  margin: var(--brand-space-2) 0 2px;
  color: var(--brand-muted);
  font-size: .76rem;
  line-height: 1.65;
}

.book-choice-reason span {
  width: fit-content;
  padding: 3px 9px;
  border-radius: var(--brand-radius-pill);
  background: var(--brand-yellow-pale);
  color: #80601c;
  font-size: .62rem;
  font-weight: 800;
  letter-spacing: .04em;
}

.work-caption {
  margin: 10px 4px 0;
  color: var(--brand-muted);
  font-size: .78rem;
  font-weight: 600;
  line-height: 1.65;
}

.next-event-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px 18px;
  margin-top: 18px;
}

.next-event-links a {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: .86rem;
  font-weight: 800;
  text-underline-offset: .22em;
}

/* Shared public-page surface contract.
 * Higher selector specificity lets these design-system values survive later page-specific
 * brand layers without disturbing each page's layout or content-specific composition. */
html body {
  color: var(--brand-ink);
  background: var(--brand-bg);
  font-family: var(--brand-font-body);
  font-size: var(--brand-text-base);
}

html body .section-pad { padding-block: var(--brand-section-space); }
html body .section-heading h2,
html body .next-event h2,
html body .sticker-copy h2 { font-size: var(--brand-heading-section); }
html body .button { border-radius: var(--brand-radius-pill); }

html body .seo-main { background-color: var(--brand-bg); }
html body .seo-shell { width: min(calc(100% - var(--brand-gutter)), var(--brand-container)); }
html body .seo-hero {
  border-radius: var(--brand-radius-2xl);
  box-shadow: var(--brand-shadow-md);
}
html body .seo-hero h1 {
  font-family: var(--brand-font-display);
  font-size: var(--brand-heading-page);
}
html body .seo-section { margin-top: clamp(var(--brand-space-8), 9vw, var(--brand-section-space)); }
html body .seo-section-heading { margin-bottom: var(--brand-space-7); }
html body .seo-section h2 {
  font-family: var(--brand-font-display);
  font-size: var(--brand-heading-section);
}
html body .seo-section h3,
html body .seo-discover h2 { font-family: var(--brand-font-display); }
html body .seo-card,
html body .seo-note,
html body .seo-preferred-source {
  border-radius: var(--brand-radius-lg);
}
html body .seo-card { box-shadow: var(--brand-shadow-xs); }
html body .seo-split {
  border-radius: var(--brand-radius-xl);
  box-shadow: var(--brand-shadow-sm);
}
html body .seo-discover-grid a { border-radius: var(--brand-radius-md); }

@media (max-width: 980px) {
  .site-header.shared-site-header .global-nav,
  body .seo-header .seo-nav { gap: 6px 13px; font-size: .76rem; }
}

@media (max-width: 820px) {
  html body .seo-shell,
  .site-shell-container,
  body .seo-header .seo-shell { width: min(calc(100% - var(--brand-gutter-tablet)), var(--shell-width)); }
  .site-header.shared-site-header .header-inner,
  body .seo-header .seo-header-inner { min-height: 72px; }

  .site-header.shared-site-header .menu-button { display: grid; }
  .site-header.shared-site-header .global-nav {
    position: fixed;
    top: 72px;
    right: max(16px, env(safe-area-inset-right));
    left: auto;
    width: min(320px, calc(100vw - 32px));
    max-height: calc(100dvh - 88px);
    overflow-y: auto;
    display: grid;
    gap: 0;
    padding: 10px;
    border: 1px solid var(--shell-line);
    border-radius: 21px;
    background: var(--brand-surface);
    box-shadow: var(--shell-shadow);
    opacity: 0;
    transform: translateY(-10px) scale(.98);
    transform-origin: top right;
    pointer-events: none;
    transition: opacity .2s ease, transform .2s ease;
  }
  .site-header.shared-site-header .global-nav.is-open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
  }
  .site-header.shared-site-header .global-nav a {
    padding: 13px 14px;
    border-radius: 13px;
    font-size: .9rem;
    white-space: normal;
  }
  .site-header.shared-site-header .global-nav a:hover,
  .site-header.shared-site-header .global-nav a:focus-visible { background: var(--shell-yellow-pale); }
  .site-header.shared-site-header .global-nav a::after { display: none; }
  .site-header.shared-site-header .nav-contact { background: transparent; }

  /* Compatibility until generated SEO pages are normalized by apply-site-shell.mjs. */
  body .seo-header { position: static; }
  body .seo-header .seo-header-inner { align-items: stretch; flex-direction: column; gap: 8px; padding: 12px 0; }
  body .seo-header .seo-nav {
    width: 100%;
    justify-content: flex-start;
    flex-wrap: nowrap;
    gap: 4px 14px;
    overflow-x: auto;
    scrollbar-width: thin;
  }
}

@media (max-width: 640px) {
  html body .seo-shell,
  .site-shell-container,
  body .seo-header .seo-shell { width: min(calc(100% - var(--brand-gutter-mobile)), var(--shell-width)); }
  .site-header.shared-site-header .brand img,
  body .seo-header .seo-brand img { width: 45px; height: 45px; }
  .site-header.shared-site-header .brand strong,
  body .seo-header .seo-brand strong { font-size: 1.02rem; }
  .site-header.shared-site-header .brand small,
  body .seo-header .seo-brand small { font-size: .58rem; }

  .site-header.shared-site-header .global-nav {
    right: max(14px, env(safe-area-inset-right));
    width: min(224px, calc(100vw - 28px));
  }

  .hero h1,
  .story-copy h2,
  .cms-image-text[data-cms-id="coloring-glasses"] h2 {
    white-space: normal;
    text-wrap: balance;
  }

  .social-card:not(.social-mail) .qr-wrap { display: none; }
  .social-card:not(.social-mail) {
    grid-template-columns: minmax(0, 1fr);
    min-height: 96px;
    padding: 18px 48px 18px 18px;
  }

  .next-event-links { align-items: stretch; flex-direction: column; }
  .next-event-links a { justify-content: center; min-height: 44px; }
  .work-caption { font-size: .72rem; }
}

/* Wide detail heroes must reserve enough inline measure for short Japanese titles.
 * seo-brand.css loads later, so only the desktop font scale is capped here. The
 * existing JS wrapping policy remains free to use its emergency fallback if needed. */
@media (min-width: 1041px) {
  body .seo-main .seo-hero h1 {
    font-size: clamp(2.15rem, 3.35vw, 3.1rem) !important;
    line-height: 1.26 !important;
  }
}

/* Japanese editorial headings need ideographic measure, not the Latin zero-width ch unit.
 * The source presentation layer uses ch, which can squeeze CJK text into orphan fragments.
 * Override it after seo-video.css with em-based limits that map to Japanese glyph width. */
@media (min-width: 621px) {
  body .seo-main .seo-section[aria-labelledby$="-origin-title"] h2 {
    max-width: 20em;
  }
  body .seo-main .seo-section[aria-labelledby*="-chapter-"] h2 {
    max-width: 22em;
  }
}

/* Safari/WebView final safety for long-form story headings only.
 * Server-generated <wbr> points and the shared JS policy own word breaking; this
 * layer guarantees geometry and balances authored break opportunities before an
 * emergency character-level fallback is ever considered. */
@media (max-width: 620px) {
  body .seo-main .seo-section[aria-labelledby$="-origin-title"] h2,
  body .seo-main .seo-section[aria-labelledby$="-aims-title"] h2,
  body .seo-main .seo-section[aria-labelledby*="-chapter-"] h2 {
    box-sizing: border-box;
    display: block;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    margin-inline: 0;
    padding-inline: 0;
    white-space: normal !important;
    line-break: strict !important;
    text-wrap: balance !important;
    font-size: clamp(1.42rem, 5.8vw, 1.62rem) !important;
    line-height: 1.42 !important;
    letter-spacing: 0 !important;
  }
}

/* Extreme narrow-width pages must reduce type before main.js is forced into
 * character-level overflow wrapping. seo-brand.css loads later, so these caps
 * intentionally use !important and apply only to the 320/360px diagnostic band. */
@media (max-width: 360px) {
  body .seo-main .seo-hero h1 {
    font-size: clamp(1.3rem, 6vw, 1.48rem) !important;
    line-height: 1.32 !important;
    text-wrap: balance !important;
  }
}

@media (max-width: 340px) {
  body .seo-main .seo-event-copy h3 {
    font-size: 1.1rem !important;
    line-height: 1.55 !important;
    text-wrap: balance !important;
  }
  body .seo-main .seo-section[aria-labelledby$="-aims-title"] .seo-card-body {
    padding-inline: 16px;
  }
  body .seo-main .seo-section[aria-labelledby$="-aims-title"] .seo-card h3 {
    font-size: 1rem !important;
    line-height: 1.58 !important;
    text-wrap: balance !important;
  }
}

/* Keep the persistent site shell visually anchored while page content changes. */
@media (prefers-reduced-motion: no-preference) {
  @view-transition {
    navigation: auto;
  }

  .site-header.shared-site-header,
  body .seo-header {
    view-transition-name: marupopo-header;
  }

  ::view-transition-group(root) {
    animation-duration: 260ms;
    animation-timing-function: cubic-bezier(.22,.61,.36,1);
  }

  ::view-transition-old(root) {
    animation: 140ms ease-in both marupopo-page-out;
  }

  ::view-transition-new(root) {
    animation: 260ms cubic-bezier(.22,.61,.36,1) both marupopo-page-in;
  }

  ::view-transition-group(marupopo-header) {
    animation-duration: 220ms;
    animation-timing-function: cubic-bezier(.22,.61,.36,1);
  }

  @keyframes marupopo-page-out {
    to { opacity: .88; transform: translateY(-3px); }
  }

  @keyframes marupopo-page-in {
    from { opacity: .001; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
  }
}

@media (prefers-reduced-motion: reduce) {
  .site-header.shared-site-header *,
  body .seo-header * { transition-duration: .01ms !important; }
}
