/* ===========================================================================
   NOIR CHROMA — Mobile layer  (linked with media="(max-width: 900px)")
   ---------------------------------------------------------------------------
   Complete replacement for assets/css/mobile-redesign.css, which is NOT
   loaded for this skin (manifest: "legacy_mobile_layer": false). Because the
   legacy layer is gone, this file must also re-assert everything that
   assets/css/style.css:579-633 does inside its own @media (max-width:900px)
   block — otherwise the old dropdown-panel nav comes back.

   900px is the single mobile cutoff and matches, exactly:
     - the media attribute in the manifest
     - matchMedia('(max-width: 900px)') in assets/js/mobile-redesign.js:15
   CSS and behaviour therefore cannot disagree about what "mobile" means.

   assets/js/mobile-redesign.js is untouched. This file styles the DOM it
   injects: .mr-drawer-head / .mr-drawer-brand / .mr-drawer-close,
   .mr-backdrop, html.menu-open + body.menu-open, html.mr-has-drawer-head,
   .mr-bottomnav > .mr-bn-item > .mr-bn-icon + .mr-bn-label, and
   .gallery-tile.is-loaded.
   =========================================================================== */

/* ---- 0. Motion first ---------------------------------------------------- */
/* Declared before anything animates so the very first paint is already calm. */

@media (prefers-reduced-motion: reduce) {
  body[data-skin="noir"] .nav,
  body[data-skin="noir"] .mr-backdrop,
  body[data-skin="noir"] .mr-bottomnav,
  body[data-skin="noir"] .mr-bn-item,
  body[data-skin="noir"] .gallery-tile { transition: none; }

  body[data-skin="noir"] .gallery-tile:not(.is-loaded) .tile-img-wrap::before {
    animation: none;
  }
}


/* ---- 1. Resets ---------------------------------------------------------- */

/* This file is only ever linked when the noir skin is active, so a bare html
   selector cannot leak into another skin. Deliberately not written as
   html:has(body[data-skin="noir"]) — :has() is unsupported on older Android
   Chrome, which would silently drop the horizontal-overflow guard. */
html {
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}

body[data-skin="noir"] {
  overflow-x: hidden;
  /* The header becomes sticky (in flow) on mobile, so the fixed-header
     offset that style.css applies must come back off. */
  padding-top: 0;
  padding-bottom: calc(var(--n-bottomnav-h) + var(--n-safe-bottom) + var(--n-s2));
  -webkit-tap-highlight-color: transparent;
  touch-action: pan-y;

  --n-header-h: 58px;
  --n-gutter: 16px;
}

/* style.css:686 forces body{background:#F1F1F1 !important} under 600px.
   0-2-0 + !important beats 0-0-1 + !important. One of only two !important
   declarations in the whole skin, and it exists solely to cancel another. */
@media (max-width: 600px) {
  body[data-skin="noir"] { background: var(--n-bg) !important; }
}

body[data-skin="noir"][data-admin] { padding-bottom: 0; }

/* Scroll lock — mobile-redesign.js sets .menu-open on BOTH html and body. */
html.menu-open,
html.menu-open body[data-skin="noir"] {
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
}

body[data-skin="noir"] main,
body[data-skin="noir"] .container {
  padding-inline: max(var(--n-gutter), var(--n-safe-left)) max(var(--n-gutter), var(--n-safe-right));
}

/* iOS Safari zooms the viewport when a focused control's text is under 16px
   and will not zoom back out. Applies to every control, not just inputs. */
body[data-skin="noir"] input,
body[data-skin="noir"] select,
body[data-skin="noir"] textarea,
body[data-skin="noir"] button { font-size: 16px; }


/* ---- 2. Header ---------------------------------------------------------- */

body[data-skin="noir"] .header-wrap {
  position: sticky;
  top: 0;
  height: auto;
  min-height: calc(var(--n-header-h) + var(--n-safe-top));
  padding-top: var(--n-safe-top);
  background: rgba(11, 11, 13, .86);
  backdrop-filter: saturate(150%) blur(16px);
  -webkit-backdrop-filter: saturate(150%) blur(16px);
  transform: translate3d(0, 0, 0);
}

@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  body[data-skin="noir"] .header-wrap { background: var(--n-ink-1); }
}

body[data-skin="noir"] .header {
  min-height: var(--n-header-h);
  padding-inline: max(14px, var(--n-safe-left)) max(14px, var(--n-safe-right));
  gap: var(--n-s3);
}

body[data-skin="noir"] .brand-logo-img { height: 26px; max-width: 132px; }

body[data-skin="noir"] .menu-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  padding: 10px;
  border-radius: var(--n-r-sm);
  gap: 6px;
  transition: background var(--n-dur-fast) var(--n-ease),
              transform var(--n-dur-fast) var(--n-ease);
}
body[data-skin="noir"] .menu-btn:active {
  background: var(--n-surface-2);
  transform: scale(.96);
}

body[data-skin="noir"] .icon-bar {
  width: 22px;
  transition: transform var(--n-dur) var(--n-ease), opacity var(--n-dur-fast) var(--n-ease);
}
body[data-skin="noir"] #menu-toggle:checked + .menu-btn .icon-bar:nth-child(1) {
  transform: translateY(8px) rotate(45deg);
}
body[data-skin="noir"] #menu-toggle:checked + .menu-btn .icon-bar:nth-child(2) { opacity: 0; }
body[data-skin="noir"] #menu-toggle:checked + .menu-btn .icon-bar:nth-child(3) {
  transform: translateY(-8px) rotate(-45deg);
}


/* ---- 3. Drawer ---------------------------------------------------------- */
/* Opened by EITHER the checkbox (works with JS off) OR html.menu-open (set by
   mobile-redesign.js, which also drives the backdrop and the scroll lock).
   With JS on, the two always flip together — the JS listens to the checkbox
   and resets it in closeMenu(). */

body[data-skin="noir"] .nav {
  position: fixed;
  top: 0;
  bottom: 0;
  left: auto;
  right: auto;
  inset-inline-end: 0;
  width: min(84vw, 330px);
  min-height: 100vh;       /* fallback first — 100dvh below wins where known */
  height: 100dvh;
  z-index: 1500;
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 0;
  background: var(--n-ink-1);
  border-bottom: 0;
  border-inline-start: 1px solid var(--n-border);
  box-shadow: -12px 0 48px rgba(0, 0, 0, .6);
  opacity: 1;
  visibility: hidden;
  transform: translate3d(100%, 0, 0);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  transition: transform var(--n-dur-slow) var(--n-ease-emph),
              visibility var(--n-dur-slow) var(--n-ease-emph);
}

/* transform has no logical equivalent — the only [dir] exception in the skin. */
html[dir="rtl"] body[data-skin="noir"] .nav {
  transform: translate3d(-100%, 0, 0);
  box-shadow: 12px 0 48px rgba(0, 0, 0, .6);
}

body[data-skin="noir"] #menu-toggle:checked ~ .nav,
html.menu-open body[data-skin="noir"] .nav {
  transform: translate3d(0, 0, 0);
  visibility: visible;
  opacity: 1;
}

/* A gradient hairline down the drawer's leading edge. */
body[data-skin="noir"] .nav::before {
  content: '';
  position: fixed;
  inset-block: 0;
  inset-inline-end: min(84vw, 330px);
  width: 2px;
  background: var(--n-grad);
  opacity: 0;
  transition: opacity var(--n-dur-slow) var(--n-ease);
  pointer-events: none;
}
body[data-skin="noir"] #menu-toggle:checked ~ .nav::before,
html.menu-open body[data-skin="noir"] .nav::before { opacity: .9; }

body[data-skin="noir"] .mr-backdrop {
  position: fixed;
  inset: 0;
  z-index: 999;
  background: var(--n-scrim);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--n-dur) var(--n-ease);
}
html.menu-open body[data-skin="noir"] .mr-backdrop,
html.menu-open .mr-backdrop {
  opacity: 1;
  pointer-events: auto;
}

body[data-skin="noir"] .mr-drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
  flex-shrink: 0;
  padding-inline: var(--n-s5);
  padding-top: calc(var(--n-s2) + var(--n-safe-top));
  border-bottom: 1px solid var(--n-border);
}
body[data-skin="noir"] .mr-drawer-brand {
  font-family: var(--n-font-display);
  font-size: var(--n-fz-base);
  font-weight: var(--n-fw-bold);
  letter-spacing: .04em;
  color: var(--n-fg);
}
body[data-skin="noir"] .mr-drawer-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: var(--n-r-sm);
  background: transparent;
  color: var(--n-text-muted);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  transition: background var(--n-dur-fast) var(--n-ease), color var(--n-dur-fast) var(--n-ease);
}
body[data-skin="noir"] .mr-drawer-close:active {
  background: var(--n-surface-2);
  color: var(--n-fg);
}

/* Drawer links — the desktop underline pseudo is retired here. */
body[data-skin="noir"] .nav .nav-link {
  width: 100%;
  min-height: 52px;
  height: auto;
  display: flex;
  align-items: center;
  padding: 14px var(--n-s5);
  font-size: var(--n-fz-lg);
  font-weight: var(--n-fw-med);
  letter-spacing: 0;
  text-transform: none;
  color: var(--n-text-muted);
  border: 0;
  position: relative;
  transition: background var(--n-dur-fast) var(--n-ease), color var(--n-dur-fast) var(--n-ease);
}
body[data-skin="noir"] .nav .nav-link::after { display: none; }
body[data-skin="noir"] .nav .nav-link:active { background: var(--n-surface-2); }

body[data-skin="noir"] .nav .nav-link.active {
  color: var(--n-fg);
  font-weight: var(--n-fw-bold);
  background: rgba(255, 61, 139, .07);
}
body[data-skin="noir"] .nav .nav-link.active::before {
  content: '';
  position: absolute;
  inset-inline-start: 0;
  top: 50%;
  width: 3px;
  height: 22px;
  border-radius: 0 3px 3px 0;
  background: var(--n-grad);
  transform: translateY(-50%);
}

html.mr-has-drawer-head body[data-skin="noir"] .nav .nav-link:first-of-type { margin-top: var(--n-s2); }
html:not(.mr-has-drawer-head) body[data-skin="noir"] .nav .nav-link:first-child {
  margin-top: calc(var(--n-s4) + var(--n-safe-top));
}

body[data-skin="noir"] .nav .nav-link--admin {
  font-size: var(--n-fz-sm);
  color: var(--n-text-dim);
  border-top: 1px solid var(--n-border);
  margin-top: var(--n-s3);
}
body[data-skin="noir"] .nav .nav-link--lang {
  margin-top: auto;
  height: auto;
  border: 0;
  border-top: 1px solid var(--n-border);
  border-radius: 0;
  font-weight: var(--n-fw-bold);
  color: var(--n-accent);
  padding-bottom: calc(var(--n-s4) + var(--n-safe-bottom));
}


/* ---- 4. Bottom tab bar -------------------------------------------------- */

body[data-skin="noir"] .mr-bottomnav {
  position: fixed;
  inset-inline: 0;
  bottom: 0;
  z-index: 1100;
  display: flex;
  align-items: stretch;
  justify-content: space-around;
  height: calc(var(--n-bottomnav-h) + var(--n-safe-bottom));
  padding: 0 var(--n-safe-right) var(--n-safe-bottom) var(--n-safe-left);
  background: rgba(11, 11, 13, .88);
  backdrop-filter: saturate(150%) blur(18px);
  -webkit-backdrop-filter: saturate(150%) blur(18px);
  border-top: 1px solid var(--n-border);
  transform: translate3d(0, 0, 0);
  transition: transform var(--n-dur) var(--n-ease), opacity var(--n-dur) var(--n-ease);
}

@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  body[data-skin="noir"] .mr-bottomnav { background: var(--n-ink-1); }
}

body[data-skin="noir"] .mr-bottomnav::before {
  content: '';
  position: absolute;
  inset-inline: 0;
  top: -1px;
  height: 1px;
  background: var(--n-grad-line);
  opacity: .5;
  pointer-events: none;
}

body[data-skin="noir"] .mr-bn-item {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-height: 100%;
  padding: 6px 4px;
  border: 0;
  background: transparent;
  color: var(--n-text-dim);
  text-decoration: none;
  font-size: var(--n-fz-xs);
  font-weight: var(--n-fw-med);
  transition: color var(--n-dur-fast) var(--n-ease), transform var(--n-dur-fast) var(--n-ease);
}
body[data-skin="noir"] .mr-bn-item:active {
  transform: scale(.94);
  color: var(--n-fg);
}
body[data-skin="noir"] .mr-bn-item.is-active { color: var(--n-fg); }

body[data-skin="noir"] .mr-bn-icon {
  position: relative;
  width: 24px;
  height: 24px;
  display: block;
  pointer-events: none;
}
body[data-skin="noir"] .mr-bn-icon svg {
  width: 100%;
  height: 100%;
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
/* The active tab is marked by a chromatic dot, so the cue does not depend on
   colour alone once the icon itself is already currentColor. */
body[data-skin="noir"] .mr-bn-item.is-active .mr-bn-icon::after {
  content: '';
  position: absolute;
  inset-inline: 50%;
  bottom: -5px;
  width: 4px;
  height: 4px;
  margin-inline-start: -2px;
  border-radius: 50%;
  background: var(--n-accent);
}
body[data-skin="noir"] .mr-bn-label {
  pointer-events: none;
  white-space: nowrap;
}

html.menu-open body[data-skin="noir"] .mr-bottomnav,
body[data-skin="noir"].mr-chrome-hidden .mr-bottomnav {
  transform: translate3d(0, 110%, 0);
  opacity: 0;
  pointer-events: none;
}


/* ---- 5. Gallery --------------------------------------------------------- */
/* Two uniform columns. The desktop structure (aspect-ratio tile + absolutely
   positioned .tile-img-wrap) is kept as-is, so there is nothing to unwind. */

body[data-skin="noir"] .gallery-grid {
  grid-template-columns: repeat(2, 1fr);
  gap: 3px;
}

body[data-skin="noir"] .gallery-tile {
  border-radius: var(--n-r-xs);
  transition: transform var(--n-dur-fast) var(--n-ease);
  transform: translate3d(0, 0, 0);
}
body[data-skin="noir"] .gallery-tile:active { transform: scale(.985) translate3d(0, 0, 0); }
body[data-skin="noir"] .gallery-tile:hover img { transform: none; filter: brightness(.92); }

/* Skeleton shimmer until mobile-redesign.js adds .is-loaded (it re-attaches
   to infinite-scroll tiles through a MutationObserver, so this covers them). */
body[data-skin="noir"] .gallery-tile:not(.is-loaded) .tile-img-wrap::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background: linear-gradient(90deg,
                var(--n-ink-2) 0%,
                var(--n-ink-4) 50%,
                var(--n-ink-2) 100%);
  background-size: 200% 100%;
  animation: noir-shimmer 1.4s linear infinite;
}
body[data-skin="noir"] .gallery-tile:not(.is-loaded) img { opacity: 0; }
body[data-skin="noir"] .gallery-tile.is-loaded .tile-img-wrap::before { display: none; }
body[data-skin="noir"] .gallery-tile img { transition: opacity var(--n-dur) var(--n-ease); }

@keyframes noir-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Ad tiles span the full row so they sit between gallery rows instead of
   fighting the 2-column rhythm. */
body[data-skin="noir"] .feed-tile {
  grid-column: 1 / -1;
  grid-row: auto;
  aspect-ratio: 16 / 9;
  border-radius: var(--n-r-sm);
}


/* ---- 6. Touch targets --------------------------------------------------- */

body[data-skin="noir"] .btn {
  min-height: 46px;
  padding-inline: 1.4rem;
}
body[data-skin="noir"] .btn.sm { min-height: 38px; }

body[data-skin="noir"] .chip,
body[data-skin="noir"] .tag-pill {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
}

body[data-skin="noir"] .color-chip { min-height: 40px; }


/* ---- 7. Footer ---------------------------------------------------------- */

body[data-skin="noir"] .csh { padding: var(--n-s7) var(--n-s4); }
body[data-skin="noir"] .csh-frame { padding: var(--n-s6) var(--n-s5); }
body[data-skin="noir"] .csh-corner { opacity: .22; }
body[data-skin="noir"] .csh-card:hover { transform: none; box-shadow: none; }
body[data-skin="noir"] .csh-card:active { transform: scale(.97); }
body[data-skin="noir"] .csh-cta:hover { transform: none; box-shadow: none; }

body[data-skin="noir"] .sfd-inner {
  padding-inline: max(var(--n-s4), var(--n-safe-left)) max(var(--n-s4), var(--n-safe-right));
}
/* The tab bar already reserves space via body padding-bottom; the footer only
   needs to clear the notch inset itself. */
body[data-skin="noir"] .sfd-base { padding-bottom: var(--n-safe-bottom); }


/* ---- 8. Reading pages --------------------------------------------------- */

body[data-skin="noir"] .story-content,
body[data-skin="noir"] .ph-body,
body[data-skin="noir"] .container-reading,
body[data-skin="noir"] .a11y-statement-body {
  max-width: 100%;
  font-size: var(--n-fz-lg);
  line-height: var(--n-lh-read);
}


/* ---- 9. Small phones ---------------------------------------------------- */

@media (max-width: 380px) {
  body[data-skin="noir"] {
    --n-gutter: 12px;
    --n-bottomnav-h: 58px;
  }
  body[data-skin="noir"] .brand-logo-img { height: 22px; max-width: 110px; }
  body[data-skin="noir"] .mr-bn-label { font-size: 10px; }
  body[data-skin="noir"] .mr-bn-icon { width: 22px; height: 22px; }
  body[data-skin="noir"] .gallery-grid { gap: 2px; }
}


/* ---- 10. Landscape phones ---------------------------------------------- */
/* Vertical space is the scarce resource here: shrink the chrome, and give the
   gallery more columns since horizontal space is suddenly plentiful. */

@media (orientation: landscape) and (max-height: 500px) {
  body[data-skin="noir"] {
    --n-header-h: 48px;
    --n-bottomnav-h: 52px;
  }
  body[data-skin="noir"] .gallery-grid { grid-template-columns: repeat(3, 1fr); }
  body[data-skin="noir"] .mr-drawer-head { height: 52px; }
  body[data-skin="noir"] .nav .nav-link { min-height: 44px; padding-block: 10px; }
  body[data-skin="noir"] .csh { padding-block: var(--n-s5); }
}
