.mobile-topbar,
.mobile-bottom-nav,
.mobile-more-scrim,
.mobile-more-sheet {
  display: none;
}

@media (max-width: 690px), (orientation: landscape) and (max-height: 500px) and (max-width: 940px) {
  :root {
    --mobile-topbar-height: 56px;
    --mobile-bottom-nav-height: 68px;
  }

  html {
    scroll-padding-top: calc(var(--mobile-topbar-height) + env(safe-area-inset-top, 0px) + 8px);
  }

  body.mobile-more-open {
    overflow: hidden;
  }

  body.auth-pending .mobile-topbar,
  body.auth-pending .mobile-bottom-nav,
  body.auth-pending .mobile-more-scrim,
  body.auth-pending .mobile-more-sheet,
  body.auth-open .mobile-topbar,
  body.auth-open .mobile-bottom-nav,
  body.auth-open .mobile-more-scrim,
  body.auth-open .mobile-more-sheet {
    display: none;
  }

  .app-shell {
    display: block;
    padding-top: calc(var(--mobile-topbar-height) + env(safe-area-inset-top, 0px));
    padding-bottom: calc(var(--mobile-bottom-nav-height) + env(safe-area-inset-bottom, 0px));
  }

  .sidebar {
    display: none;
  }

  .topbar {
    display: none;
  }

  .mobile-topbar {
    position: fixed;
    inset: 0 0 auto;
    z-index: 70;
    display: block;
    min-height: calc(var(--mobile-topbar-height) + env(safe-area-inset-top, 0px));
    padding-top: env(safe-area-inset-top, 0px);
    color: var(--ink-deep);
    border-bottom: 1px solid var(--border-subtle);
    background: rgba(255, 255, 255, 0.98);
  }

  .mobile-topbar__inner {
    display: grid;
    height: var(--mobile-topbar-height);
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 8px;
    padding-inline: max(16px, env(safe-area-inset-left, 0px)) max(12px, env(safe-area-inset-right, 0px));
  }

  .mobile-topbar__title {
    grid-column: 2;
    overflow: hidden;
    font-size: 18px;
    font-weight: 800;
    letter-spacing: -0.02em;
    line-height: 1.1;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-topbar__title:first-child {
    grid-column: 1 / 3;
  }

  .mobile-topbar__back,
  .mobile-topbar__notification {
    display: grid;
    width: 44px;
    height: 44px;
    place-items: center;
    padding: 0;
    color: var(--ink-soft);
    border: 0;
    border-radius: 10px;
    background: transparent;
  }

  .mobile-topbar__back:active,
  .mobile-topbar__notification:active {
    color: var(--ink-deep);
    background: var(--selection-yellow-soft);
    transform: scale(0.96);
  }

  .mobile-topbar__back svg,
  .mobile-topbar__notification svg {
    width: 22px;
    height: 22px;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 1.9;
  }

  .mobile-bottom-nav {
    position: fixed;
    inset: auto 0 0;
    z-index: 70;
    display: grid;
    min-height: calc(var(--mobile-bottom-nav-height) + env(safe-area-inset-bottom, 0px));
    grid-template-columns: repeat(var(--mobile-nav-count, 5), minmax(0, 1fr));
    align-items: start;
    padding: 4px max(4px, env(safe-area-inset-right, 0px)) env(safe-area-inset-bottom, 0px) max(4px, env(safe-area-inset-left, 0px));
    border-top: 1px solid var(--border-subtle);
    background: rgba(255, 255, 255, 0.98);
  }

  .mobile-bottom-nav__item {
    position: relative;
    display: grid;
    min-width: 0;
    min-height: 60px;
    place-items: center;
    align-content: center;
    gap: 2px;
    padding: 4px 2px 3px;
    color: var(--muted);
    border: 0;
    border-radius: 8px;
    background: transparent;
    font-size: 12px;
    font-weight: 700;
    line-height: 1.05;
    transition: color 180ms ease, background 120ms ease, transform 120ms var(--ease);
  }

  .mobile-bottom-nav__item::before {
    position: absolute;
    top: 0;
    width: 26px;
    height: 3px;
    border-radius: 0 0 4px 4px;
    background: transparent;
    content: '';
  }

  .mobile-bottom-nav__item svg {
    width: 30px;
    height: 28px;
    padding: 3px 4px;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 1.8;
    border-radius: 8px;
  }

  .mobile-bottom-nav__item span {
    display: block;
    overflow: hidden;
    width: 100%;
    text-align: center;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-bottom-nav__item.is-active {
    color: var(--ink-deep);
  }

  .mobile-bottom-nav__item.is-active::before {
    background: var(--selection-yellow-strong);
  }

  .mobile-bottom-nav__item.is-active svg {
    background: var(--selection-yellow);
  }

  .mobile-bottom-nav__item:active {
    background: var(--surface-recessed);
    transform: scale(0.97);
  }

  .mobile-more-scrim {
    position: fixed;
    inset: 0;
    z-index: 90;
    display: block;
    background: rgba(43, 41, 37, 0.28);
    animation: mobile-scrim-in 160ms ease-out both;
  }

  .mobile-more-sheet {
    position: fixed;
    inset: auto 0 0;
    z-index: 91;
    display: block;
    max-height: min(78dvh, 680px);
    overflow: auto;
    overscroll-behavior: contain;
    padding: 0 max(14px, env(safe-area-inset-right, 0px)) max(16px, env(safe-area-inset-bottom, 0px)) max(14px, env(safe-area-inset-left, 0px));
    color: var(--ink);
    border-top: 1px solid var(--border-strong);
    border-radius: 16px 16px 0 0;
    background: var(--white);
    box-shadow: 0 -18px 46px rgba(43, 41, 37, 0.16);
    animation: mobile-sheet-in 220ms var(--ease) both;
  }

  .mobile-more-scrim[hidden],
  .mobile-more-sheet[hidden] {
    display: none;
  }

  .mobile-more-sheet::before {
    display: block;
    width: 36px;
    height: 4px;
    margin: 8px auto 2px;
    border-radius: 4px;
    background: var(--rule);
    content: '';
  }

  .mobile-more-sheet__header {
    position: sticky;
    top: 0;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 2px 12px;
    border-bottom: 1px solid var(--border-subtle);
    background: var(--white);
  }

  .mobile-more-sheet__header h2,
  .mobile-more-sheet__header p {
    margin: 0;
  }

  .mobile-more-sheet__header h2 {
    font-size: 24px;
    letter-spacing: -0.025em;
  }

  .mobile-more-sheet__header p {
    margin-top: 2px;
    color: var(--muted);
    font-size: 14px;
  }

  .mobile-more-sheet__close {
    display: grid;
    width: 44px;
    height: 44px;
    flex: 0 0 auto;
    place-items: center;
    padding: 0;
    color: var(--ink-soft);
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
    background: var(--white);
  }

  .mobile-more-sheet__close svg {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-width: 1.8;
  }

  .mobile-more-sheet__nav {
    display: grid;
    padding: 4px 0 10px;
  }

  .mobile-more-sheet__item {
    display: grid;
    min-height: 62px;
    grid-template-columns: 42px minmax(0, 1fr) 20px;
    align-items: center;
    gap: 10px;
    padding: 8px 4px;
    color: var(--ink-soft);
    border: 0;
    border-bottom: 1px solid var(--border-subtle);
    border-radius: 0;
    background: transparent;
    text-align: left;
  }

  .mobile-more-sheet__item > svg {
    width: 18px;
    height: 18px;
    justify-self: end;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 1.8;
  }

  .mobile-more-sheet__item-icon {
    display: grid;
    width: 40px;
    height: 40px;
    place-items: center;
    border-radius: 10px;
    background: var(--surface-recessed);
  }

  .mobile-more-sheet__item-icon svg {
    width: 22px;
    height: 22px;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 1.8;
  }

  .mobile-more-sheet__item strong,
  .mobile-more-sheet__item small {
    display: block;
  }

  .mobile-more-sheet__item strong {
    color: var(--ink-deep);
    font-size: 16px;
    line-height: 1.15;
  }

  .mobile-more-sheet__item small {
    margin-top: 2px;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.2;
  }

  .mobile-more-sheet__item.is-active {
    background: var(--selection-yellow-soft);
  }

  .mobile-more-sheet__item.is-active .mobile-more-sheet__item-icon {
    color: var(--ink-deep);
    background: var(--selection-yellow);
  }

  .mobile-more-sheet__item:active {
    background: var(--surface-recessed);
  }

  .mobile-more-sheet__account {
    display: grid;
    gap: 12px;
    padding: 14px 2px 2px;
  }

  .mobile-more-sheet__identity {
    display: flex;
    min-width: 0;
    align-items: center;
    gap: 10px;
  }

  .mobile-more-sheet__identity > span:last-child {
    min-width: 0;
  }

  .mobile-more-sheet__identity strong,
  .mobile-more-sheet__identity small,
  .mobile-more-sheet__identity em {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-more-sheet__identity small {
    color: var(--muted);
    font-size: 13px;
  }

  .mobile-more-sheet__identity em {
    color: var(--muted-light);
    font-size: 12px;
    font-style: normal;
  }

  .mobile-more-sheet__account-actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 8px;
  }

  .mobile-more-sheet__account-actions button {
    display: flex;
    min-height: 46px;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 8px 10px;
    color: var(--ink-deep);
    border: 1px solid var(--border-strong);
    border-radius: 10px;
    background: var(--white);
    font-size: 14px;
    font-weight: 750;
  }

  .mobile-more-sheet__account-actions svg {
    width: 18px;
    height: 18px;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 1.8;
  }

  .mobile-more-sheet__account-actions .mobile-more-sheet__signout {
    grid-column: 1 / -1;
    justify-content: flex-start;
    color: var(--red);
    border-color: rgba(161, 61, 50, 0.28);
    background: var(--danger-surface);
  }

  .mobile-more-sheet__account > .account-emergency-status {
    margin: 0;
  }

  main {
    min-height: calc(100dvh - var(--mobile-topbar-height) - var(--mobile-bottom-nav-height) - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
    padding-bottom: 24px;
  }

  .notification-centre {
    inset: calc(8px + env(safe-area-inset-top, 0px)) max(8px, env(safe-area-inset-right, 0px)) calc(8px + env(safe-area-inset-bottom, 0px)) max(8px, env(safe-area-inset-left, 0px));
  }

  @keyframes mobile-sheet-in {
    from {
      opacity: 0.6;
      transform: translateY(24px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }

  @keyframes mobile-scrim-in {
    from { opacity: 0; }
    to { opacity: 1; }
  }
}

@media (max-width: 360px) {
  .mobile-bottom-nav__item {
    font-size: 12px;
  }

  .mobile-more-sheet__account-actions {
    grid-template-columns: 1fr;
  }
}

@media (orientation: landscape) and (max-height: 500px) and (max-width: 940px) {
  :root {
    --mobile-topbar-height: 50px;
    --mobile-bottom-nav-height: 58px;
  }

  .mobile-bottom-nav__item {
    min-height: 50px;
    grid-template-columns: 26px auto;
    justify-content: center;
    gap: 4px;
  }

  .mobile-bottom-nav__item svg {
    width: 26px;
    height: 26px;
  }

  .mobile-more-sheet {
    max-height: 88dvh;
  }

  .mobile-more-sheet__nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    column-gap: 18px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .mobile-bottom-nav__item,
  .mobile-more-scrim,
  .mobile-more-sheet {
    animation-duration: 1ms !important;
    transition-duration: 1ms !important;
  }
}
