/* mobile: nav. phones only, desktop must stay unchanged.
   phones get a full-width top bar (brand, join, menu) and a full-screen sheet.
   the sheet is .rail-links itself, so the rail must not create a containing block
   (no transform, no filter on .rail); the bar fill lives on ::before instead. */

.rail-extra { display: none; }

@media (max-width: 760px), (max-height: 500px) and (pointer: coarse) {
  .rail {
    top: 0; left: 0; right: 0; z-index: 60;
    display: flex; align-items: center; gap: 8px;
    padding: calc(env(safe-area-inset-top) + 10px) var(--g) 10px;
    border-radius: 0; background: none; box-shadow: none;
    -webkit-backdrop-filter: none; backdrop-filter: none;
    transform: none; animation: none;
  }
  .motion .rail { animation: none; }
  .rail::before {
    content: ""; position: absolute; inset: 0; z-index: 0; pointer-events: none;
    background: color-mix(in srgb, var(--bg) 88%, transparent);
    -webkit-backdrop-filter: blur(14px) saturate(1.3); backdrop-filter: blur(14px) saturate(1.3);
    box-shadow: inset 0 -1px 0 var(--glass-edge);
    opacity: 0; transition: opacity .3s ease;
  }
  .rail.is-scrolled::before { opacity: 1; }
  .rail.open::before { opacity: 0; transition-duration: .15s; }
  .rail > :not(.rail-links) { position: relative; z-index: 2; }

  .rail-brand {
    display: inline-flex; align-items: center; min-height: 44px; margin-right: auto; padding: 0 8px 0 0;
    font-size: 19px; letter-spacing: .14em; text-indent: 0; border-radius: 0; background: none;
  }
  .rail-brand:hover { background: none; }

  .rail > .btn-brass { min-height: 44px; margin-left: 0; padding: 0 18px; font-size: 13px; transition: transform .5s var(--ease), filter .25s ease, opacity .2s ease, visibility 0s; }
  .rail.open > .btn-brass { opacity: 0; visibility: hidden; transition: opacity .15s ease, visibility 0s linear .15s; }

  .rail-menu {
    display: inline-flex; align-items: center; justify-content: center; gap: 10px;
    min-width: 0; width: 96px; min-height: 44px; padding: 0 14px;
    border: 0; border-radius: 8px; background: none;
    box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--ink) 24%, transparent);
    font: 600 15px/1 var(--body); color: var(--ink);
    -webkit-tap-highlight-color: transparent;
  }
  .rail-menu::before {
    content: ""; flex: none; width: 16px; height: 8px;
    background:
      linear-gradient(currentColor, currentColor) 0 0 / 100% 1.5px no-repeat,
      linear-gradient(currentColor, currentColor) 0 100% / 100% 1.5px no-repeat;
    transition: background-position .3s var(--ease);
  }
  /* the two rules close into one: the sheet folds back into the bar */
  .rail.open .rail-menu::before { background-position: 0 50%, 0 50%; }
  .rail-menu:active { background: rgba(194, 159, 128, .14); }

  /* the sheet */
  .rail-links {
    position: fixed; inset: 0; z-index: 1;
    display: flex; flex-direction: column; align-items: stretch; gap: 0;
    padding: calc(env(safe-area-inset-top) + 64px + 3svh) var(--g) calc(env(safe-area-inset-bottom) + 22px);
    border-radius: 0; box-shadow: none;
    background: var(--bg);
    -webkit-backdrop-filter: none; backdrop-filter: none;
    overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
    visibility: hidden; opacity: 0;
    transition: opacity .24s ease, visibility 0s linear .24s;
  }
  .rail.open .rail-links { display: flex; visibility: visible; opacity: 1; transition: opacity .24s ease; }

  .rail-links .rail-link {
    display: flex; align-items: center; justify-content: space-between; gap: 16px;
    min-height: 64px; padding: 10px 2px; border-radius: 0;
    border-bottom: 1px solid color-mix(in srgb, var(--ink) 14%, transparent);
    font: 500 clamp(28px, 8.4vw, 38px)/1.1 var(--serif); letter-spacing: .01em;
    color: var(--ink); background: none;
    -webkit-tap-highlight-color: transparent;
  }
  .rail-links .rail-link:first-child { border-top: 1px solid color-mix(in srgb, var(--ink) 14%, transparent); }
  .rail-links .rail-link:hover { background: none; }
  .rail-links .rail-link:active { color: var(--accent-text); }
  .rail-links .rail-link[aria-current="page"] { color: var(--accent-text); }
  .rail-links .rail-link[aria-current="page"]::after {
    content: ""; flex: none; width: 20px; height: 20px; background: currentColor;
    -webkit-mask: var(--palm) center / contain no-repeat; mask: var(--palm) center / contain no-repeat;
  }

  .rail-extra { display: flex; flex-direction: column; gap: 14px; margin-top: auto; padding-top: 32px; }
  .rail .rail-join { width: 100%; min-height: 56px; margin: 0; padding: 0 20px; font-size: 16px; letter-spacing: .12em; text-indent: .12em; }

  .rail-theme {
    display: grid; grid-template-columns: 1fr 1fr; padding: 3px; border-radius: 10px;
    box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--ink) 18%, transparent);
  }
  .rail-theme button {
    min-height: 44px; border: 0; border-radius: 7px; background: none;
    font: 600 14px/1 var(--body); color: var(--ink-2);
    -webkit-tap-highlight-color: transparent; transition: background-color .25s ease, color .25s ease;
  }
  .rail-theme button[aria-pressed="true"] { background: rgba(194, 159, 128, .2); color: var(--ink); }

  /* entrance: links settle in one after another */
  .rail-links > * { transition: opacity .3s ease, transform .45s var(--ease); }
  .rail:not(.open) .rail-links > * { opacity: 0; transform: translateY(10px); transition-duration: 0s; }
  .rail.open .rail-links > :nth-child(2) { transition-delay: .03s; }
  .rail.open .rail-links > :nth-child(3) { transition-delay: .06s; }
  .rail.open .rail-links > :nth-child(4) { transition-delay: .09s; }
  .rail.open .rail-links > :nth-child(5) { transition-delay: .12s; }

  html.menu-open, html.menu-open body { overflow: hidden; }
}

/* landscape phones: links on the left, join and theme on the right */
@media (max-height: 500px) and (orientation: landscape) and (pointer: coarse), (max-width: 760px) and (max-height: 500px) {
  .rail { padding-top: max(8px, env(safe-area-inset-top)); padding-bottom: 8px; }
  .rail-links {
    display: grid; grid-template-columns: 1fr minmax(240px, 38%); grid-auto-flow: column; grid-template-rows: repeat(4, auto);
    column-gap: 48px; align-content: center;
    padding-top: calc(60px + 8px); padding-bottom: max(16px, env(safe-area-inset-bottom));
  }
  .rail.open .rail-links { display: grid; }
  .rail-links .rail-link { min-height: 52px; font-size: 26px; }
  .rail-extra { grid-column: 2; grid-row: 1 / span 4; align-self: end; margin: 0; padding: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .rail-links, .rail-links > *, .rail-menu::before { transition: none !important; }
  .rail:not(.open) .rail-links > * { transform: none; }
}
