/* ============================================================
   MU SANTA FE — Mobile layout and fixed-control safe zones
   Loaded last on every public/system page.
   ============================================================ */

:root {
  --mf-mobile-edge: 8px;
  --mf-mobile-control: 40px;
  --mf-mobile-music-width: 118px;
  --mf-mobile-streams-width: 86px;
  --mf-mobile-safe-bottom: env(safe-area-inset-bottom, 0px);
}

.social-float-dock,
.social-float-links {
  display: contents;
}

.social-float-toggle {
  display: none;
}

@media (max-width: 767.98px) {
  html {
    scroll-padding-top: 82px;
  }

  body {
    min-width: 0;
    padding-bottom: calc(64px + var(--mf-mobile-safe-bottom));
    overflow-x: hidden;
  }

  img,
  video,
  canvas,
  svg {
    max-width: 100%;
  }

  button,
  select,
  input,
  textarea {
    max-width: 100%;
  }

  input,
  select,
  textarea {
    font-size: 16px;
  }

  /* Main navigation */
  #mainNav {
    padding-block: 7px;
  }

  #mainNav .container {
    max-width: 100%;
    padding-inline: 12px;
  }

  #mainNav .navbar-brand {
    min-width: 0;
    margin-right: 8px;
  }

  #mainNav .nav-logo-main {
    width: auto;
    height: 56px;
    max-width: 104px;
  }

  #mainNav .navbar-toggler {
    width: 56px;
    min-height: 40px;
    padding: 6px 10px;
    border-radius: 7px;
  }

  #mainNav .navbar-collapse {
    max-height: calc(100dvh - 76px);
    padding: 10px 2px 14px;
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  #mainNav .navbar-nav {
    gap: 4px !important;
  }

  #mainNav .navbar-nav .nav-link,
  #mainNav .navbar-nav .btn {
    min-height: 42px;
  }

  #mainNav .nav-session-item {
    grid-template-columns: 1fr;
  }

  /* Ranking: all data remains visible without a 790px-wide table. */
  .fallen-live-section {
    min-height: 0;
  }

  .fallen-ranking-panel {
    padding: 18px 12px;
  }

  .fallen-panel-head {
    margin-bottom: 16px;
  }

  .fallen-rank-tabs {
    margin-inline: -2px;
    padding-bottom: 10px;
    scroll-snap-type: x proximity;
  }

  .fallen-rank-tabs button {
    min-height: 42px;
    scroll-snap-align: start;
  }

  .fallen-podium-wrap {
    min-height: 330px;
    margin: 12px 0 20px;
  }

  .fallen-podium-info {
    top: 0;
    width: calc(100% - 24px);
    text-align: center;
    white-space: normal;
  }

  .fallen-podium {
    padding-top: 34px;
  }

  .fallen-podium__art-wrap {
    width: min(72vw, 250px);
    height: 225px;
  }

  .fallen-podium__pedestal {
    width: min(76vw, 250px);
  }

  .fallen-podium__name {
    max-width: 100%;
    overflow-wrap: anywhere;
    text-align: center;
  }

  .fallen-table-wrap {
    overflow: visible;
    border: 0;
    background: transparent;
  }

  .fallen-data-table {
    display: block;
    width: 100%;
    min-width: 0;
  }

  .fallen-data-table thead {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    white-space: nowrap;
  }

  .fallen-data-table tbody {
    display: grid;
    gap: 9px;
  }

  .fallen-data-table tbody tr {
    display: grid;
    grid-template-columns: 32px 44px minmax(0, 1fr) auto auto 20px;
    grid-template-areas:
      "rank avatar name name name status"
      "rank avatar class class class class"
      "rank avatar level resets masters masters";
    gap: 3px 8px;
    align-items: center;
    min-width: 0;
    padding: 10px 9px;
    border: 1px solid rgba(90, 215, 255, 0.18);
    border-radius: 7px;
    background:
      linear-gradient(90deg, rgba(90, 215, 255, 0.055), transparent 38%),
      rgba(2, 9, 14, 0.78);
  }

  .fallen-data-table tbody td {
    min-width: 0;
    padding: 2px;
    border: 0;
  }

  .fallen-data-table tbody td:nth-child(1) {
    grid-area: rank;
    align-self: stretch;
    display: grid;
    place-items: center;
  }

  .fallen-data-table tbody td:nth-child(2) { grid-area: avatar; }
  .fallen-data-table tbody td:nth-child(3) { grid-area: name; }
  .fallen-data-table tbody td:nth-child(4) {
    grid-area: class;
    overflow: hidden;
    color: rgba(238, 248, 255, 0.58);
    font-size: 0.75rem;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .fallen-data-table tbody td:nth-child(5) { grid-area: level; }
  .fallen-data-table tbody td:nth-child(6) { grid-area: resets; }
  .fallen-data-table tbody td:nth-child(7) { grid-area: masters; }
  .fallen-data-table tbody td:nth-child(8) {
    grid-area: status;
    justify-self: end;
  }

  .fallen-data-table tbody td:nth-child(5),
  .fallen-data-table tbody td:nth-child(6),
  .fallen-data-table tbody td:nth-child(7) {
    color: rgba(238, 248, 255, 0.78);
    font-family: var(--font-title);
    font-size: 0.68rem;
    white-space: nowrap;
  }

  .fallen-data-table tbody td:nth-child(5)::before {
    content: "LV ";
    color: rgba(90, 215, 255, 0.62);
  }

  .fallen-data-table tbody td:nth-child(6)::before {
    content: "R ";
    color: rgba(90, 215, 255, 0.62);
  }

  .fallen-data-table tbody td:nth-child(7)::before {
    content: "MR ";
    color: rgba(90, 215, 255, 0.62);
  }

  .fallen-data-table[data-ranking-mode="killer"] tbody td:nth-child(7)::before {
    content: "K ";
  }

  .fallen-data-table tbody td[colspan] {
    grid-area: 1 / 1 / -1 / -1;
    padding: 18px 10px;
    text-align: center;
  }

  .fallen-avatar {
    width: 40px;
    height: 40px;
  }

  .fallen-char-link {
    display: block;
    overflow: hidden;
    font-size: 0.78rem;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* Four global social links collapse into one mobile control. */
  .social-float-dock {
    position: fixed;
    right: calc(var(--mf-mobile-edge) + var(--mf-mobile-streams-width) + 6px);
    bottom: calc(var(--mf-mobile-edge) + var(--mf-mobile-safe-bottom));
    z-index: 99970;
    display: grid;
    justify-items: end;
  }

  .social-float-toggle {
    display: grid;
    width: var(--mf-mobile-control);
    height: var(--mf-mobile-control);
    padding: 0;
    place-items: center;
    border: 1px solid rgba(90, 215, 255, 0.68);
    border-radius: 12px;
    color: #dff8ff;
    background:
      radial-gradient(circle at 48% 25%, rgba(223, 248, 255, 0.18), transparent 40%),
      linear-gradient(155deg, rgba(8, 35, 52, 0.98), rgba(3, 10, 16, 0.98));
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.52), 0 0 18px rgba(90, 215, 255, 0.16);
    font-size: 1.08rem;
  }

  .social-float-toggle:focus-visible {
    outline: 2px solid #8feaff;
    outline-offset: 3px;
  }

  .social-float-links {
    position: absolute;
    right: 0;
    bottom: calc(100% + 8px);
    display: flex;
    flex-direction: column-reverse;
    gap: 7px;
    visibility: hidden;
    opacity: 0;
    pointer-events: none;
    transform: translateY(9px) scale(0.94);
    transform-origin: bottom right;
    transition: opacity 160ms ease, transform 160ms ease, visibility 160ms;
  }

  .social-float-dock.is-open .social-float-links {
    visibility: visible;
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0) scale(1);
  }

  .social-float-dock .whatsapp-float,
  .social-float-dock .discord-float,
  .social-float-dock .instagram-float,
  .social-float-dock .youtube-float {
    position: static;
    width: 40px;
    height: 40px;
    font-size: 1.08rem;
  }

  /* Events sits above music instead of sliding under it. */
  .events-side-tab {
    top: auto;
    left: calc(var(--mf-mobile-edge) + var(--mf-mobile-music-width) + 6px);
    bottom: calc(var(--mf-mobile-edge) + var(--mf-mobile-safe-bottom));
    width: var(--mf-mobile-control);
    min-width: var(--mf-mobile-control);
    height: var(--mf-mobile-control);
    min-height: var(--mf-mobile-control);
    padding: 0;
    justify-content: center;
    border: 1px solid rgba(90, 215, 255, 0.68);
    border-radius: 12px;
    transform: none;
  }

  .events-side-tab:hover,
  .events-side-tab:focus-visible {
    transform: translateY(-2px);
  }

  .events-side-tab span {
    display: none;
  }

  .events-side-tab i {
    width: 29px;
    height: 29px;
    flex-basis: 29px;
    font-size: 1rem;
  }

  .wiki-side-tab {
    top: auto;
    left: calc(var(--mf-mobile-edge) + var(--mf-mobile-music-width) + 6px);
    bottom: calc(var(--mf-mobile-edge) + var(--mf-mobile-safe-bottom) + var(--mf-mobile-control) + 7px);
  }

  /* Bottom pair: music left, Streams right. */
  .fallen-music-player {
    left: max(var(--mf-mobile-edge), env(safe-area-inset-left));
    bottom: calc(var(--mf-mobile-edge) + var(--mf-mobile-safe-bottom));
    width: var(--mf-mobile-music-width);
    height: var(--mf-mobile-control);
    gap: 6px;
    padding: 5px 7px 5px 5px;
    background: rgba(3, 12, 19, 0.97);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }

  .fallen-music-toggle {
    flex-basis: 29px;
    width: 29px;
    height: 29px;
  }

  .fallen-music-volume {
    grid-template-columns: 14px minmax(0, 1fr);
    gap: 4px;
  }

  .fallen-music-volume svg {
    width: 14px;
    height: 14px;
  }

  /* System pages and admin panels */
  .system-topbar,
  .admin-topbar {
    position: sticky;
    top: 0;
    z-index: 1000;
    align-items: center;
    gap: 7px;
    padding: 7px 9px 5px;
    background: rgba(3, 10, 16, 0.97);
    backdrop-filter: none;
  }

  .system-brand {
    align-self: center;
    min-width: 0;
  }

  .system-brand img {
    width: 104px;
    height: 48px;
    max-height: 48px;
  }

  .system-nav {
    width: 100%;
    flex-wrap: nowrap;
    justify-content: flex-start;
    gap: 6px;
    padding: 1px 0 6px;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
    scroll-snap-type: x proximity;
  }

  .system-nav::-webkit-scrollbar {
    display: none;
  }

  .system-nav a,
  .system-nav button,
  .system-nav .system-session {
    flex: 0 0 auto;
    width: auto !important;
    min-height: 40px;
    padding: 8px 10px;
    scroll-snap-align: start;
    white-space: nowrap;
  }

  .system-nav .system-session {
    max-width: 170px;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .system-shell,
  .admin-shell {
    width: calc(100% - 16px);
    padding: 22px 0 68px;
  }

  .system-hero {
    gap: 14px;
    margin-bottom: 20px;
  }

  .system-hero h1,
  .admin-head h1,
  .admin-guard h1 {
    font-size: clamp(1.85rem, 10vw, 2.7rem);
    overflow-wrap: anywhere;
  }

  .system-kicker,
  .eyebrow {
    letter-spacing: 0.18em;
  }

  .system-quick-panel,
  [data-mu-account-panel],
  [data-mu-wallet-panel],
  .wallet-panel,
  .system-panel,
  .admin-panel,
  [data-mu-state],
  [data-mu-profile-card],
  [data-mu-equipment-card],
  [data-mu-profile-characters],
  [data-mu-profile-siblings],
  [data-mu-market-card],
  [data-mu-market-slot],
  [data-mu-shop-card],
  [data-mu-pack-card],
  [data-mu-event-card],
  [data-mu-character-card],
  .admin-guard,
  .admin-app section,
  [data-mu-shop-admin-guard],
  [data-mu-shop-admin-app] > section {
    padding: 14px;
  }

  [data-mu-profile-characters],
  [data-mu-profile-siblings],
  [data-mu-market-list],
  [data-mu-market-warehouse],
  [data-mu-webshop-list],
  [data-mu-events-view],
  [data-mu-events],
  .admin-grid {
    grid-template-columns: 1fr;
  }

  [data-mu-character-card],
  [data-mu-profile-character] {
    min-width: 0;
  }

  [data-mu-character-card] {
    grid-template-columns: 58px minmax(0, 1fr);
  }

  .admin-tabs {
    flex-wrap: nowrap;
    margin: 16px 0;
    padding-bottom: 5px;
    overflow-x: auto;
    scrollbar-width: none;
    scroll-snap-type: x proximity;
  }

  .admin-tabs::-webkit-scrollbar {
    display: none;
  }

  .admin-tab {
    flex: 0 0 auto;
    min-height: 42px;
    scroll-snap-align: start;
  }

  .admin-actions {
    display: grid;
    grid-template-columns: 1fr;
    gap: 9px;
  }

  .admin-actions button,
  .admin-actions a,
  .system-action {
    width: 100%;
    justify-content: center;
  }

  .pack-excellent-options {
    grid-template-columns: 1fr;
  }

  dialog[data-auth-modal] {
    max-height: calc(100dvh - 18px);
    overflow-y: auto;
  }

  .system-auth-panel {
    padding: 20px 16px;
  }

  .modal-dialog {
    margin: 8px;
  }

  .modal-content {
    max-height: calc(100dvh - 16px);
    overflow-y: auto;
  }

}

@media (max-width: 380px) {
  .fallen-music-player {
    width: var(--mf-mobile-music-width);
  }

  .fallen-ranking-panel {
    padding-inline: 9px;
  }

  .fallen-data-table tbody tr {
    grid-template-columns: 29px 40px minmax(0, 1fr) auto auto 18px;
    gap-inline: 6px;
    padding-inline: 7px;
  }

  .fallen-avatar {
    width: 37px;
    height: 37px;
  }

}

@media (prefers-reduced-motion: reduce) {
  .social-float-links {
    transition: none;
  }
}
