/* Dedicated touch-first shell for phones and installed Luna web apps. */
.mobile-app-nav { display: none; }
@media (max-width: 760px) {
  html { scroll-padding-top: calc(68px + env(safe-area-inset-top)); }
  body {
    max-width: 100%;
    overflow-x: clip;
    padding-bottom: calc(72px + env(safe-area-inset-bottom));
  }

  .header {
    position: sticky;
    top: 0;
    z-index: 35;
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 9px;
    width: 100%;
    height: auto;
    min-height: calc(58px + env(safe-area-inset-top));
    padding: calc(env(safe-area-inset-top) + 6px) 10px 6px;
    background: color-mix(in srgb, var(--bg) 94%, transparent);
    backdrop-filter: blur(20px);
  }

  .header .brand { flex: 0 0 auto; }
  .header .brand img {
    display: block;
    width: clamp(76px, 24vw, 96px);
    max-height: 42px;
    height: auto;
    object-fit: contain;
  }
  .header nav { display: none !important; }
  .header-actions {
    display: flex;
    flex: 1 1 auto;
    min-width: 0;
    justify-content: flex-end;
    gap: clamp(4px, 1.6vw, 9px);
    margin-left: auto;
  }
  .header-search {
    flex: 0 1 clamp(104px, 31vw, 190px);
    width: auto;
    min-width: 0;
  }
  .header-search:focus-within { width: auto; }
  .header-search-field {
    min-height: 42px;
    padding-inline: 9px;
    gap: 6px;
    border-radius: 12px;
  }
  .header-search-field input {
    min-width: 0;
    height: 40px;
    font-size: 16px !important;
  }
  .header-search-field input::placeholder { font-size: 11px; }
  .header-search-results {
    position: fixed;
    inset: calc(env(safe-area-inset-top) + 58px) 8px auto;
    width: auto;
    max-height: min(64dvh, 520px);
    border-radius: 16px;
  }
  .header-actions .notification-bell {
    width: 36px;
    min-width: 36px;
    height: 42px;
  }
  .header-actions .profile-menu-trigger {
    min-width: 38px;
    min-height: 44px;
    gap: 3px;
    padding: 2px;
  }
  .header-actions .avatar { width: 31px; height: 31px; }
  .profile-menu-chevron { font-size: 10px; }

  .mobile-app-nav {
    position: fixed;
    z-index: 24;
    right: 0;
    bottom: 0;
    left: 0;
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 2px;
    padding: 6px 5px calc(6px + env(safe-area-inset-bottom));
    border-top: 1px solid color-mix(in srgb, var(--accent) 20%, var(--line));
    background: color-mix(in srgb, var(--bg) 93%, transparent);
    box-shadow: 0 -10px 32px #0005;
    backdrop-filter: blur(22px) saturate(130%);
  }
  .mobile-app-nav a {
    display: grid;
    min-width: 0;
    min-height: 48px;
    align-content: center;
    justify-items: center;
    gap: 3px;
    padding: 4px 1px;
    border: 1px solid transparent;
    border-radius: 12px;
    color: color-mix(in srgb, var(--text) 63%, var(--muted));
    font-size: clamp(8px, 2.4vw, 10px);
    font-weight: 650;
    line-height: 1.1;
    text-align: center;
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
  }
  .mobile-app-nav svg {
    width: 18px;
    height: 18px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.7;
    stroke-linecap: round;
    stroke-linejoin: round;
  }
  .mobile-app-nav a.active {
    border-color: color-mix(in srgb, var(--accent) 20%, transparent);
    background: color-mix(in srgb, var(--accent) 11%, transparent);
    color: var(--accent);
  }
  .mobile-app-nav a:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
  }

  #content,
  #content > *,
  .page,
  .detail,
  .public-profile-page,
  .social-page,
  .community-page,
  .community-workspace {
    min-width: 0;
    max-width: 100%;
  }
  .page { padding-inline: 14px; }
  .section { margin-inline: 14px; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .rail { overscroll-behavior-x: contain; scroll-snap-type: x proximity; }
  .rail .card { scroll-snap-align: start; }
  .episode,
  .panel,
  .setting,
  .section-head,
  .page-heading,
  .detail .actions { min-width: 0; }
  .episode { align-items: flex-start; }
  .episode > div { min-width: 0; }

  input:not([type="checkbox"]):not([type="radio"]),
  select,
  textarea { max-width: 100%; font-size: 16px !important; }
  button,
  .button,
  summary { touch-action: manipulation; }
  dialog {
    width: min(100% - 20px, 560px);
    max-width: none;
    max-height: calc(100dvh - env(safe-area-inset-top) - 18px);
    overscroll-behavior: contain;
  }
  dialog .dialog-inner { padding: clamp(18px, 5vw, 26px); }
  .player { padding-top: env(safe-area-inset-top); }
  .player-bar { padding-inline: 10px; }
  .player-note { padding-bottom: max(8px, env(safe-area-inset-bottom)); }
  #luna-help { right: 12px; bottom: calc(82px + env(safe-area-inset-bottom)); }
  .luna-help-panel {
    right: 0;
    bottom: 58px;
    width: min(420px, calc(100vw - 24px));
    max-height: min(72dvh, 680px);
  }
  footer { padding-bottom: 14px; }
  #toast { bottom: calc(82px + env(safe-area-inset-bottom)); }
}

@media (max-width: 380px) {
  .header { gap: 6px; padding-inline: 8px; }
  .header .brand img { width: 72px; }
  .header-actions { gap: 4px; }
  .header-search { flex-basis: clamp(92px, 29vw, 118px); }
  .header-search-field > span { font-size: 18px; }
  .header-search-field input::placeholder { color: transparent; }
  .mobile-app-nav { padding-inline: 3px; gap: 1px; }
  .mobile-app-nav a { font-size: 8px; }
  .mobile-app-nav svg { width: 17px; height: 17px; }
  .rail .card { flex-basis: 112px; }
}

@media (display-mode: standalone) and (max-width: 760px) {
  .header { padding-top: calc(env(safe-area-inset-top) + 7px); }
  .mobile-app-nav { padding-bottom: calc(8px + env(safe-area-inset-bottom)); }
}

@media (prefers-reduced-motion: reduce) {
  .mobile-app-nav a { scroll-behavior: auto; transition: none; }
}

/* Offer a touch-friendly home-screen install action on phones and tablets. */
.mobile-install-prompt { display: none; }
@media (max-width: 1000px) {
  /* Keep native touch scrolling and swipe gestures without painting scrollbars. */
  html,
  body,
  body * {
    scrollbar-width: none;
    -ms-overflow-style: none;
  }
  html::-webkit-scrollbar,
  body::-webkit-scrollbar,
  body *::-webkit-scrollbar { display: none; width: 0; height: 0; }
  .rail,
  .social-feed,
  .social-sidebar,
  .social-friends-panel,
  .luna-help-messages,
  .notification-list,
  dialog { -webkit-overflow-scrolling: touch; }

  .mobile-install-prompt {
    display: flex;
    align-items: center;
    gap: 11px;
    min-width: 0;
    margin: 12px 14px 0;
    padding: 11px 12px;
    border: 1px solid color-mix(in srgb, var(--accent) 34%, var(--line));
    border-radius: 16px;
    background: linear-gradient(115deg, color-mix(in srgb, var(--accent) 13%, var(--panel)), color-mix(in srgb, var(--panel) 92%, transparent));
    box-shadow: 0 10px 28px #0002;
  }
  .mobile-install-prompt-icon {
    display: grid;
    place-items: center;
    flex: 0 0 42px;
    width: 42px;
    height: 42px;
    overflow: hidden;
    border: 1px solid color-mix(in srgb, var(--accent) 27%, var(--line));
    border-radius: 13px;
    background: color-mix(in srgb, var(--bg) 74%, var(--accent));
  }
  .mobile-install-prompt-icon img { display: block; width: 32px; height: 32px; object-fit: contain; }
  .mobile-install-prompt-copy { display: grid; flex: 1 1 auto; min-width: 0; gap: 3px; }
  .mobile-install-prompt-copy strong { color: var(--text); font-size: 12px; line-height: 1.3; }
  .mobile-install-prompt-copy small { color: var(--muted); font-size: 10px; line-height: 1.4; }
  .mobile-install-prompt-action { flex: none; min-height: 38px; padding: 8px 12px; border-radius: 11px; font-size: 11px; }
  .mobile-install-prompt-close { display: grid; place-items: center; align-self: flex-start; flex: 0 0 28px; width: 28px; height: 28px; margin: -5px -5px 0 -6px; padding: 0; border: 1px solid transparent; border-radius: 9px; background: transparent; color: var(--muted); font-size: 19px; line-height: 1; }
  .mobile-install-prompt-close:hover { border-color: var(--line); color: var(--text); }
}

/* Put the assistant composer and chat directly in the visible viewport while a
   phone keyboard is open, instead of leaving them behind the bottom app bar. */
@media (max-width: 1000px) {
  body.mobile-assistant-input-active { overflow: hidden; }
  body.mobile-assistant-input-active .header,
  body.mobile-assistant-input-active .mobile-app-nav,
  body.mobile-assistant-input-active > footer { display: none !important; }
  body.mobile-assistant-input-active #luna-help {
    position: fixed;
    z-index: 1200;
    inset: var(--mobile-visual-top, 0px) 8px auto;
    display: flex;
    height: calc(var(--mobile-visual-height, 100dvh) - 12px);
    width: auto;
    bottom: auto;
    right: 8px;
    left: 8px;
  }
  body.mobile-assistant-input-active .luna-help-toggle { display: none; }
  body.mobile-assistant-input-active .luna-help-panel {
    position: relative;
    inset: auto;
    flex: 1;
    width: 100%;
    height: 100%;
    max-height: none;
    min-height: 0;
    border-radius: 16px;
  }
  body.mobile-assistant-input-active .luna-help-head { flex: none; padding: 10px 13px; }
  body.mobile-assistant-input-active .luna-help-messages { min-height: 0; }
  body.mobile-assistant-input-active .luna-help-suggestions { flex: none; }
  body.mobile-assistant-input-active .luna-help-status { flex: none; }
  body.mobile-assistant-input-active .luna-help-form { flex: none; padding-bottom: max(12px, env(safe-area-inset-bottom)); }
  body.mobile-assistant-input-active .luna-help-foot { display: none; }
}

/* Keep sign-in and verification dialogs inside the visible area while a
   numeric keyboard is open, with all fields reachable by swiping. */
@media (max-width: 1000px) {
  body.mobile-auth-input-active { overflow: hidden; }
  body.mobile-auth-input-active dialog.auth-dialog[open] {
    position: fixed;
    top: var(--mobile-visual-top, 0px);
    left: 50%;
    width: min(500px, calc(100vw - 16px));
    max-width: none;
    max-height: calc(var(--mobile-visual-height, 100dvh) - 12px);
    margin: 0;
    padding: 0;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    transform: translateX(-50%);
    border-radius: 16px;
  }
  body.mobile-auth-input-active .auth-dialog-inner { padding: 20px 18px; }
  body.mobile-auth-input-active .auth-brand { width: 100px; height: 43px; margin-bottom: 12px; }
  body.mobile-auth-input-active .auth-dialog .auth-field { margin-top: 11px; }
  body.mobile-auth-input-active .auth-dialog .auth-field > input { min-height: 46px; }
  body.mobile-auth-input-active .auth-dialog .auth-tabs { margin: 15px 0 13px; }
}

/* Touch-first playback controls: keep the title and actions visible above the
   video, respect device safe areas, and leave the picture to the player. */
@media (max-width: 760px) {
  #player.player:not([hidden]) {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100dvh;
    min-height: 0;
    padding-top: env(safe-area-inset-top);
    padding-bottom: 0;
    overflow: hidden;
    background: #030508;
  }
  #player .player-bar {
    z-index: 2;
    flex: none;
    display: grid;
    grid-template-columns: minmax(84px, auto) minmax(0, 1fr) 44px;
    align-items: center;
    gap: 7px;
    min-height: 58px;
    padding: 7px 9px;
    border-bottom: 1px solid #ffffff12;
    background: linear-gradient(180deg, #111724f5, #0b0f18ed);
  }
  #player .player-bar .button {
    min-width: 0;
    min-height: 42px;
    gap: 5px;
    padding: 8px 9px;
    border-radius: 11px;
    font-size: 11px;
    white-space: nowrap;
  }
  #player #player-close { justify-self: start; }
  #player #player-title {
    display: block;
    min-width: 0;
    overflow: hidden;
    color: #f0f4fb;
    font-size: 12px;
    font-weight: 650;
    text-align: center;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  #player #player-next-source { grid-column: 2; grid-row: 2; justify-self: center; min-height: 36px; }
  #player #player-fullscreen {
    display: grid;
    grid-column: 3;
    grid-row: 1;
    place-items: center;
    width: 44px;
    min-width: 44px;
    height: 44px;
    padding: 0;
    overflow: hidden;
    font-size: 0;
  }
  #player #player-fullscreen::after { content: '⛶'; font-size: 22px; line-height: 1; }
  #player .player-frame {
    display: grid;
    flex: 1 1 auto;
    width: 100%;
    min-width: 0;
    min-height: 0;
    place-items: center;
    background: #000;
  }
  #player .player-frame iframe { width: 100%; height: 100%; min-height: 0; background: #000; }
  #player .player-note {
    flex: none;
    margin: 0;
    padding: 9px 12px max(9px, env(safe-area-inset-bottom));
    border-top: 1px solid #ffffff12;
    background: #0b0f18;
    color: #a1adbd;
    font-size: 10px;
    line-height: 1.45;
    text-align: left;
  }
}

@media (max-width: 380px) {
  #player .player-bar { grid-template-columns: minmax(78px, auto) minmax(0, 1fr) 42px; gap: 5px; padding-inline: 7px; }
  #player .player-bar .button { padding-inline: 7px; font-size: 10px; }
  #player #player-fullscreen { width: 42px; min-width: 42px; }
  #player #player-title { font-size: 11px; }
}
