.rail-nav { display: none; }
.rail-tools { display: none; }
.rail-handle { display: none; }
.rail-handle-left { display: none; }
.rail-toast, .rail-intro { display: none; }
.hdr-theme-toggle.rail-toggle-btn { display: none; }

@media (max-width: 640px) and (min-height: 501px) {

  html[data-theme] .hdr-theme-toggle.rail-toggle-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: var(--icon-fill);
    color: var(--ink-mid);
  }
  html[data-theme] .rail-toggle-btn svg { flex: none; width: 16px; height: 16px; }
  html[data-theme] .rail-toggle-btn[aria-pressed="true"] { background: var(--ink); color: var(--paper); }

  html.mobile-rail,
  html.mobile-rail:root[data-theme] {
    --rail-w: 48px;
    --hdr-h: 0px;
  }

  html.mobile-rail body { padding-right: var(--rail-w); }

  html.mobile-rail[data-theme] .hdr {
    top: 0;
    bottom: 0;
    left: auto;
    right: 0;
    width: var(--rail-w);
    height: auto;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    gap: 6px;
    padding: calc(env(safe-area-inset-top, 0px) + 10px) 0 calc(env(safe-area-inset-bottom, 0px) + 12px);
    border-bottom: 0;
    border-left: 1px solid var(--rule);
    overflow: hidden;
  }

  html.mobile-rail[data-theme] .rail-nav {
    order: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    flex: none;
  }
  html.mobile-rail[data-theme] .rail-nav::after {
    content: "";
    width: 16px;
    height: 1px;
    margin: 8px 0 6px;
    background: var(--rule);
  }
  html.mobile-rail[data-theme] .rail-nav-btn {
    width: 36px;
    height: 36px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: 1px solid var(--rule);
    border-radius: 50%;
    color: var(--ink-mid);
    cursor: pointer;
  }
  html.mobile-rail[data-theme] .rail-nav-btn svg { width: 18px; height: 18px; flex: none; }
  html.mobile-rail[data-theme] .rail-nav-btn.active { background: var(--ink); color: var(--paper); }

  html.mobile-rail[data-theme] .feed-tabs { display: none; }

  html.mobile-rail[data-theme] .hdr-actions { display: contents; }
  html.mobile-rail[data-theme] .hdr-actions > * { order: 2; flex: none; }
  html.mobile-rail[data-theme] #btnHdrBurger { order: 1; }
  html.mobile-rail[data-theme] #btnSearchHeader,
  html.mobile-rail[data-theme] #btnMyProfile {
    width: 34px;
    padding: 0;
    justify-content: center;
    overflow: hidden;
  }
  html.mobile-rail[data-theme] #btnMyProfile { font-size: 0; }

  html.mobile-rail[data-theme] .hdr-logo {
    order: 4;
    margin-top: auto;
    padding: 12px 0 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    width: 34px;
    min-height: 0;
    flex: 0 1 auto;
    white-space: nowrap;
    overflow: hidden;
    font-size: .8rem;
    line-height: 1;
  }

  html.mobile-rail[data-theme] .hdr-logo::before { content: none; display: none; }
  html.mobile-rail[data-theme] .hdr-logo-txt {
    display: block;
    -webkit-writing-mode: vertical-rl;
    writing-mode: vertical-rl;
    text-orientation: mixed;
    white-space: nowrap;
  }
  html.mobile-rail[data-theme] .hdr-logo-txt::before {
    content: "/";
    color: var(--red, #de2323);
    margin-inline-end: .3em;
  }

  html.mobile-rail[data-theme] .on-air-bar { right: var(--rail-w); }

  html.mobile-rail[data-theme] .site-footer { display: none; }
  html.mobile-rail[data-theme] .rail-tools {
    order: 3;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    flex: none;
    margin-top: 6px;
  }
  html.mobile-rail[data-theme] .rail-tools::before {
    content: "";
    width: 16px;
    height: 1px;
    margin-bottom: 6px;
    background: var(--rule);
  }
  html.mobile-rail[data-theme] .rail-tool-btn {
    width: 30px;
    height: 30px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 50%;
    background: var(--icon-fill);
    color: var(--ink-mid);
    cursor: pointer;
  }
  html.mobile-rail[data-theme] .rail-tool-btn svg { width: 15px; height: 15px; flex: none; }
  html.mobile-rail[data-theme] .rail-tool-btn.active,
  html.mobile-rail[data-theme] .rail-tool-btn[aria-pressed="true"] { background: var(--ink); color: var(--paper); }

  html.mobile-rail[data-theme] #viewAuth { padding: 20px 14px 28px; }
  html.mobile-rail[data-theme] #viewAuth .auth-card {
    width: 100%;
    max-width: 420px;
    margin: 0 auto;
    padding: 26px 20px 22px;
    border: 1px solid var(--rule);
    border-radius: 22px;
    background: var(--paper);
    box-sizing: border-box;
  }
  html.mobile-rail[data-theme] #viewAuth .auth-panel-heading {
    margin: 0 0 4px;
    font-size: 1.5rem;
    line-height: 1.1;
    letter-spacing: .02em;
  }
  html.mobile-rail[data-theme] #viewAuth .auth-field { display: flex; flex-direction: column; gap: 8px; }
  html.mobile-rail[data-theme] #viewAuth .auth-field label {
    font-size: .8rem;
    color: var(--ink-mid);
  }
  html.mobile-rail[data-theme] #viewAuth .auth-field input {
    width: 100%;
    box-sizing: border-box;
    padding: 14px 16px;
    font-size: 16px;
    border-radius: 14px;
  }
  html.mobile-rail[data-theme] #viewAuth .btn-primary,
  html.mobile-rail[data-theme] #viewAuth .btn-ghost {
    width: 100%;
    min-height: 50px;
    margin-top: 4px;
  }

  html.mobile-rail[data-theme] #viewAuth .hero-divider {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 6px 0;
    font-size: .7rem;
    letter-spacing: .14em;
    color: var(--ink-mid);
  }
  html.mobile-rail[data-theme] #viewAuth .hero-divider::before,
  html.mobile-rail[data-theme] #viewAuth .hero-divider::after {
    content: "";
    flex: 1;
    height: 1px;
    background: var(--rule);
    border: 0;
  }

  html.mobile-rail[data-theme] #viewAuth #btnShowUsernameLogin {
    width: 100%;
    padding: 13px 16px;
    border: 1px solid var(--rule);
    border-radius: 999px;
    background: none;
    cursor: pointer;
  }
  html.mobile-rail[data-theme] #viewAuth .auth-switch,
  html.mobile-rail[data-theme] #viewAuth .auth-back {
    text-align: center;
    padding: 8px 0;
  }
  html.mobile-rail[data-theme] #viewAuth #panelLogin,
  html.mobile-rail[data-theme] #viewAuth #panelLoginPassword,
  html.mobile-rail[data-theme] #viewAuth #panelAnon {
    gap: 14px !important;
  }

  html.mobile-rail[data-theme] main#mainContent {
    padding-top: calc(env(safe-area-inset-top, 0px) + 12px);
    margin-top: 0;

    padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 24px);
  }
  html.mobile-rail[data-theme] main#mainContent > .view,
  html.mobile-rail[data-theme] #viewMenu,
  html.mobile-rail[data-theme] #viewAuth {
    margin-top: 0;
    padding-top: 0;
  }
  html.mobile-rail[data-theme] #viewAuth { padding-top: 8px; }

  html.mobile-rail[data-theme] .hdr { transition: transform .25s ease; }
  html.mobile-rail.rail-hide[data-theme] .hdr { transform: translateX(calc(100% - 18px)) !important; }

  html.mobile-rail[data-theme] .rail-handle {
    position: absolute;
    left: 0;
    top: 50%;
    width: 18px;
    height: 72px;
    margin-top: -36px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: 0;
    cursor: pointer;
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s ease;
  }
  html.mobile-rail[data-theme] .rail-handle::before {
    content: "";
    width: 4px;
    height: 36px;
    border-radius: 2px;
    background: var(--ink-mid);
    opacity: .6;
  }
  html.mobile-rail.rail-hide[data-theme] .rail-handle { opacity: 1; pointer-events: auto; }

  html.mobile-rail[data-theme] #recordFab { transition: transform .25s ease, opacity .2s ease; }
  html.mobile-rail.rail-hide[data-theme] #recordFab {
    transform: translateX(calc(100% + 60px)) !important;
    opacity: 0 !important;
    pointer-events: none !important;
  }
  @media (prefers-reduced-motion: reduce) {
    html.mobile-rail[data-theme] .hdr,
    html.mobile-rail[data-theme] #recordFab,
    html.mobile-rail[data-theme] .rail-handle { transition: none; }
  }

  html.mobile-rail[data-theme] #feedStickyTop {

    display: flex;
    flex-direction: column;
    gap: .6rem;
    position: sticky;
    top: calc(env(safe-area-inset-top, 0px) + 4px);
    z-index: 6;
    padding: 6px 0 8px;
    background: var(--paper);
    transition: transform .25s ease, top .25s ease, box-shadow .25s ease;
  }
  html.mobile-rail[data-theme] #feedPromptBanner {
    position: sticky;
    top: calc(env(safe-area-inset-top, 0px) + 4px + var(--rail-sticky-h, 64px));
    z-index: 5;
    background: var(--paper);
    transition: transform .25s ease, top .25s ease, box-shadow .25s ease;
  }
  html.mobile-rail.rail-hide[data-theme] #feedStickyTop,
  html.mobile-rail.rail-hide[data-theme] #feedPromptBanner {
    transform: translateX(calc(-100% - 24px));
  }

  html.mobile-rail[data-theme] .rail-handle-left {
    position: fixed;
    left: 0;
    top: 50%;
    margin-top: -27px;
    width: 38px;
    height: 54px;
    padding: 0 4px 0 0;
    z-index: 40;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--ink);
    color: var(--paper);
    border: 0;
    border-radius: 0 27px 27px 0;
    box-shadow: 0 2px 10px rgba(0,0,0,.22);
    cursor: pointer;
    touch-action: none;
    opacity: 0;
    transform: translateX(-100%);
    pointer-events: none;
    transition: opacity .2s ease, transform .25s ease;
  }
  html.mobile-rail[data-theme] .rail-handle-left svg { width: 18px; height: 18px; flex: none; }

  html.mobile-rail.rail-hide[data-theme]:has(#viewFeed.active) .rail-handle-left {
    opacity: 1;
    transform: translateX(0);
    pointer-events: auto;
  }
  @media (prefers-reduced-motion: reduce) {
    html.mobile-rail[data-theme] #feedStickyTop,
    html.mobile-rail[data-theme] #feedPromptBanner,
    html.mobile-rail[data-theme] .rail-handle-left { transition: none; }
  }

  html.mobile-rail[data-theme] #feedStickyTop,
  html.mobile-rail[data-theme] #feedPromptBanner {
    background: var(--paper);
    background: color-mix(in srgb, var(--paper) 93%, var(--ink) 7%);
    border: 1px solid var(--rule);
    border-radius: 16px;
    box-shadow: 0 8px 16px -10px rgba(0,0,0,.4);
    box-sizing: border-box;
  }
  html.mobile-rail[data-theme] #feedStickyTop {
    padding: 10px;
    margin: 0 0 6px;
  }
  html.mobile-rail[data-theme] #feedPromptBanner { margin-top: 0; }

  /* Keep the search card the same width as the banner and cast cards when the
     desktop window is narrowed (rail on, but wider than a phone). */
  html.mobile-rail[data-theme] .feed-controls-extra {
    width: 100%;
    max-width: none;
    margin-left: 0;
    margin-right: 0;
    box-sizing: border-box;
  }
  html.mobile-rail[data-theme] #feedStickyTop {
    width: 100%;
    max-width: none;
    margin-left: 0;
    margin-right: 0;
    align-self: stretch;
    justify-self: stretch;
  }

  html.mobile-rail.rail-searching[data-theme] #feedTitle,
  html.mobile-rail.rail-searching[data-theme] .feed-header > h1,
  html.mobile-rail.rail-searching[data-theme] .feed-header .feed-title { display: none !important; }

  html.mobile-rail[data-theme]:has(#feedSearchTrigger:not(:placeholder-shown)) #feedTitle,
  html.mobile-rail[data-theme]:has(#feedSearchTrigger:not(:placeholder-shown)) .feed-header > h1,
  html.mobile-rail[data-theme]:has(#feedSearchTrigger:not(:placeholder-shown)) .feed-header .feed-title { display: none !important; }

  html.mobile-rail[data-theme] #feedList .search-section:has(> .search-casts) > h2 { display: none; }

  html.mobile-rail[data-theme] .rail-pin-btn .ic-locked { display: none; }
  html.mobile-rail[data-theme] .rail-pin-btn[aria-pressed="true"] .ic-locked { display: block; }
  html.mobile-rail[data-theme] .rail-pin-btn[aria-pressed="true"] .ic-unlocked { display: none; }

  html.mobile-rail[data-theme] .rail-toast {
    display: block;
    position: fixed;
    right: calc(var(--rail-w) + 8px);
    top: 50%;
    transform: translate(8px, -50%);
    z-index: 9990;
    max-width: calc(100vw - var(--rail-w) - 24px);
    padding: 7px 12px;
    border-radius: 999px;
    background: var(--ink);
    color: var(--paper);
    font-size: .78rem;
    line-height: 1.2;
    white-space: nowrap;
    box-shadow: 0 4px 14px rgba(0,0,0,.25);
    opacity: 0;
    pointer-events: none;
    transition: opacity .18s ease, transform .18s ease;
  }
  html.mobile-rail[data-theme] .rail-toast.show { opacity: 1; transform: translate(0, -50%); }

  html.mobile-rail[data-theme] .rail-intro {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 9995;
    background: rgba(0,0,0,.18);
    animation: rail-intro-in .22s ease both;
    pointer-events: none;
  }
  html.mobile-rail[data-theme] .rail-intro-catch {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: var(--rail-w);
    pointer-events: auto;
  }
  html.mobile-rail[data-theme] .rail-intro-pill {
    position: absolute;
    transform: translateY(-50%);
    max-width: calc(100vw - var(--rail-w) - 24px);
    padding: 6px 11px;
    border-radius: 999px;
    background: var(--ink);
    color: var(--paper);
    font-size: .78rem;
    line-height: 1.2;
    white-space: nowrap;
    box-shadow: 0 3px 10px rgba(0,0,0,.25);
  }
  html.mobile-rail[data-theme] .rail-intro-hint {
    position: absolute;
    left: 50%;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 28px);
    transform: translateX(calc(-50% - var(--rail-w) / 2));
    padding: 6px 12px;
    border-radius: 999px;
    background: var(--paper);
    color: var(--ink-mid);
    border: 1px solid var(--rule);
    font-size: .72rem;
    white-space: nowrap;
  }
  @keyframes rail-intro-in { from { opacity: 0; } to { opacity: 1; } }
  @media (prefers-reduced-motion: reduce) {
    html.mobile-rail[data-theme] .rail-toast,
    html.mobile-rail[data-theme] .rail-intro { transition: none; animation: none; }
  }

  html.mobile-rail[data-theme] .rail-nav,
  html.mobile-rail[data-theme] .hdr-actions > *,
  html.mobile-rail[data-theme] .rail-tools { transition: opacity .4s ease; }
  html.mobile-rail[data-theme] .hdr-logo { transition: opacity .35s ease; }

  html.mobile-rail.rail-splash[data-theme] .rail-nav,
  html.mobile-rail.rail-splash[data-theme] .hdr-actions > *,
  html.mobile-rail.rail-splash[data-theme] .rail-tools {
    opacity: 0;
    pointer-events: none;
  }
  html.mobile-rail.rail-splash[data-theme] .hdr-logo {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: auto;
    margin: 0;
    padding: 0;
    overflow: visible;
    font-size: 1.05rem;
    opacity: 1;
    z-index: 2;
  }
  html.mobile-rail.rail-splash.rail-splash-out[data-theme] .rail-nav,
  html.mobile-rail.rail-splash.rail-splash-out[data-theme] .hdr-actions > *,
  html.mobile-rail.rail-splash.rail-splash-out[data-theme] .rail-tools {
    opacity: 1;
    pointer-events: auto;
  }
  html.mobile-rail.rail-splash.rail-splash-out[data-theme] .hdr-logo { opacity: 0; }
  html.mobile-rail.rail-splash-end[data-theme] .hdr-logo { animation: rail-logo-in .6s ease both; }
  @keyframes rail-logo-in { from { opacity: 0; } to { opacity: 1; } }
  @media (prefers-reduced-motion: reduce) {
    html.mobile-rail[data-theme] .rail-nav,
    html.mobile-rail[data-theme] .hdr-actions > *,
    html.mobile-rail[data-theme] .rail-tools,
    html.mobile-rail[data-theme] .hdr-logo { transition: none; animation: none; }
  }

  html.mobile-rail.rail-logo-hide[data-theme] .hdr-logo { visibility: hidden; }

  html.mobile-rail.rail-logo-slash[data-theme] .hdr-logo-word { display: none; }
  html.mobile-rail.rail-logo-slash[data-theme] .hdr-logo-txt {
    -webkit-writing-mode: horizontal-tb;
    writing-mode: horizontal-tb;
  }
  html.mobile-rail.rail-logo-slash[data-theme] .hdr-logo-txt::before {
    margin: 0;
    font-size: 1.5rem;
    line-height: 1;
  }

  html.mobile-rail[data-theme] .cast-stats {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    align-items: center;
    row-gap: 2px;
    column-gap: 0;
  }
  html.mobile-rail[data-theme] .cast-stats > .cast-dot { display: none; }

  html.mobile-rail[data-theme] .cast-stats > span:first-child {
    grid-row: 1;
    grid-column: 1 / 5;
    justify-self: start;
    white-space: nowrap;
  }
  html.mobile-rail[data-theme] .cast-stats > .cast-more {
    grid-row: 1;
    grid-column: 5;
    justify-self: end;
  }

  html.mobile-rail[data-theme] .cast-stats > .cast-like,
  html.mobile-rail[data-theme] .cast-stats > .cast-repost,
  html.mobile-rail[data-theme] .cast-stats > .cast-replies,
  html.mobile-rail[data-theme] .cast-stats > .cast-share,
  html.mobile-rail[data-theme] .cast-stats > .cast-bookmark {
    grid-row: 2;
    justify-self: stretch;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .25rem;
    min-height: 38px;
    padding: 0;
    white-space: nowrap;
  }
  html.mobile-rail[data-theme] .cast-stats > .cast-share svg,
  html.mobile-rail[data-theme] .cast-stats > .cast-bookmark svg { width: 18px; height: 18px; }
  html.mobile-rail[data-theme] .cast-stats > .cast-more-btn,
  html.mobile-rail[data-theme] .cast-stats .cast-more-btn { min-width: 38px; min-height: 30px; }

  html.mobile-rail[data-theme] .profile-actions {
    flex-wrap: wrap;
    row-gap: .5rem;
    max-width: 100%;
  }

  html.mobile-rail[data-theme] .profile-share-url {
    flex-wrap: wrap;
    row-gap: .5rem;
  }
  html.mobile-rail[data-theme] .profile-share-url #profileShareUrlInput {
    flex: 1 1 100% !important;
    width: 100%;
    text-overflow: ellipsis;
  }

  /* profile actions: compact hairline pills, same look as all / signed / unsigned */
  html.mobile-rail[data-theme] .profile-actions,
  html.mobile-rail[data-theme] .profile-share-url {
    display: flex;
    flex-wrap: nowrap;
    gap: .5rem;
    margin-top: 0;
  }
  html.mobile-rail[data-theme] .profile-actions .btn-ghost,
  html.mobile-rail[data-theme] .profile-share-url .btn-ghost {
    flex: 1 1 0;
    width: auto !important;
    min-width: 0;
    height: 34px !important;
    padding: 0 .5rem !important;
    border: 1px solid var(--rule) !important;
    border-radius: 999px !important;
    font-size: .8rem !important;
    letter-spacing: 0;
    white-space: nowrap;
  }
  /* the url box is redundant on mobile: the copy button copies shareUrl itself */
  html.mobile-rail[data-theme] .profile-share-url #profileShareUrlInput {
    display: none;
  }
}

/* url row under the profile actions (was inline in app.js) */
.profile-share-url { display: flex; gap: .6rem; align-items: center; margin-top: .6rem; }

/* ── Profile actions as icon buttons ──
   Label-only text buttons stay in the desktop sidebar. Everywhere the profile is a
   single column (under 900px, or classic layout) they become round icon buttons in a
   row after the back button; in rail mode they move to a second rail. */
#profileRail .pic, #profileRail .pic-done { display: none; }
@media (max-width: 899px) {
  /* ROW LAYOUT: icons sit on the same line as the back button */
  #profileControls {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    gap: .6rem;
    width: 100%;
    max-width: 640px;
  }
  #profileControls .feed-header { flex: 0 0 auto; width: auto; }
  #profileRail {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    gap: .5rem;
    flex: 1 1 auto;
    min-width: 0;
  }

  /* icon buttons: soft filled circles, same as the rail icons */
  #profileRail .btn-ghost {
    flex: none;
    width: 42px !important;
    height: 42px !important;
    min-width: 0;
    padding: 0 !important;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: relative;
    border: 0 !important;
    border-radius: 50% !important;
    background: var(--icon-fill) !important;
    color: var(--ink-mid) !important;
    box-shadow: none !important;
    font-size: 0 !important;
    letter-spacing: 0;
    transform: none;
    cursor: pointer;
  }
  #profileRail .btn-ghost:hover,
  #profileRail .btn-ghost:focus-visible { color: var(--ink) !important; opacity: 1; transform: none; }
  #profileRail .btn-ghost:active { transform: scale(.94); }
  #profileRail .pic { display: block; width: 18px; height: 18px; flex: none; }
  #profileRail .pic-done { display: none; }
  #profileRail .is-done .pic { display: none; }
  #profileRail .is-done .pic-done { display: block; }
  /* the label stays for screen readers only */
  #profileRail .plabel {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
  }
  /* follow: one icon per state */
  #profileRail #btnFollow .pic { display: none; }
  #profileRail #btnFollow[data-status="none"] .pic-s-none,
  #profileRail #btnFollow[data-status="pending"] .pic-s-pending,
  #profileRail #btnFollow[data-status="approved"] .pic-s-approved { display: block; }
  /* following / editing = filled dark, like an active rail icon */
  #profileRail #btnFollow[data-status="approved"],
  #profileRail #btnEditStation[aria-expanded="true"] {
    background: var(--ink) !important;
    color: var(--paper) !important;
  }
  /* report is deliberately quiet */
  #profileRail #btnReportUser { opacity: .7; }
  /* the url box is redundant: the copy button copies shareUrl itself */
  #profileRail .profile-share-url #profileShareUrlInput { display: none; }
  #profileRail .profile-actions,
  #profileRail .profile-share-url { display: contents !important; margin: 0 !important; }
}

/* same, with the classic layout on at any width */

/* ROW LAYOUT: icons sit on the same line as the back button */
html.classic-layout #profileControls {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: flex-start;
  gap: .6rem;
  width: 100%;
  max-width: 640px;
}
html.classic-layout #profileControls .feed-header { flex: 0 0 auto; width: auto; }
html.classic-layout #profileRail {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: center;
  gap: .5rem;
  flex: 1 1 auto;
  min-width: 0;
}

/* icon buttons: soft filled circles, same as the rail icons */
html.classic-layout #profileRail .btn-ghost {
  flex: none;
  width: 42px !important;
  height: 42px !important;
  min-width: 0;
  padding: 0 !important;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: relative;
  border: 0 !important;
  border-radius: 50% !important;
  background: var(--icon-fill) !important;
  color: var(--ink-mid) !important;
  box-shadow: none !important;
  font-size: 0 !important;
  letter-spacing: 0;
  transform: none;
  cursor: pointer;
}
html.classic-layout #profileRail .btn-ghost:hover,
html.classic-layout #profileRail .btn-ghost:focus-visible { color: var(--ink) !important; opacity: 1; transform: none; }
html.classic-layout #profileRail .btn-ghost:active { transform: scale(.94); }
html.classic-layout #profileRail .pic { display: block; width: 18px; height: 18px; flex: none; }
html.classic-layout #profileRail .pic-done { display: none; }
html.classic-layout #profileRail .is-done .pic { display: none; }
html.classic-layout #profileRail .is-done .pic-done { display: block; }
/* the label stays for screen readers only */
html.classic-layout #profileRail .plabel {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}
/* follow: one icon per state */
html.classic-layout #profileRail #btnFollow .pic { display: none; }
html.classic-layout #profileRail #btnFollow[data-status="none"] .pic-s-none,
html.classic-layout #profileRail #btnFollow[data-status="pending"] .pic-s-pending,
html.classic-layout #profileRail #btnFollow[data-status="approved"] .pic-s-approved { display: block; }
/* following / editing = filled dark, like an active rail icon */
html.classic-layout #profileRail #btnFollow[data-status="approved"],
html.classic-layout #profileRail #btnEditStation[aria-expanded="true"] {
  background: var(--ink) !important;
  color: var(--paper) !important;
}
/* report is deliberately quiet */
html.classic-layout #profileRail #btnReportUser { opacity: .7; }
/* the url box is redundant: the copy button copies shareUrl itself */
html.classic-layout #profileRail .profile-share-url #profileShareUrlInput { display: none; }
html.classic-layout #profileRail .profile-actions,
html.classic-layout #profileRail .profile-share-url { display: contents !important; margin: 0 !important; }


/* ── RAIL MODE: a second, smaller rail just left of the main one ── */
@media (max-width: 640px) and (min-height: 501px) {
  html.mobile-rail[data-theme] { --rail2-w: 46px; }
  /* leave room for both rails while a profile is open */
  html.mobile-rail[data-theme]:has(#viewProfile.active) body {
    padding-right: calc(var(--rail-w) + var(--rail2-w));
  }
  html.mobile-rail[data-theme] #profileRail {
    position: fixed;
    top: calc(env(safe-area-inset-top, 0px) + 10px);
    right: var(--rail-w);
    width: var(--rail2-w);
    box-sizing: border-box;
    z-index: 99;
    flex-direction: column;
    flex: none;
    gap: 6px;
    padding: 8px 0;
    background: var(--paper);
    border: 1px solid var(--rule);
    border-right: 0;
    border-radius: 23px 0 0 23px;
    transition: transform .25s ease;
  }
  html.mobile-rail[data-theme] #profileRail .btn-ghost {
    width: 36px !important;
    height: 36px !important;
  }
  /* order: follow, share, invite, edit, copy link, report */
  html.mobile-rail[data-theme] #profileRail #btnCopyProfileUrl { order: 1; }
  html.mobile-rail[data-theme] #profileRail #btnReportUser { order: 2; }
  /* tucks away together with the main rail */
  html.mobile-rail.rail-hide[data-theme] #profileRail {
    transform: translateX(calc(100% + var(--rail-w)));
  }
  @media (prefers-reduced-motion: reduce) {
    html.mobile-rail[data-theme] #profileRail { transition: none; }
  }
}