/* Android / mobile app layout */
:root {
  --mobile-nav-h: 64px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

html {
  -webkit-tap-highlight-color: transparent;
}

body.has-mobile-nav {
  padding-bottom: calc(var(--mobile-nav-h) + var(--safe-bottom));
}

.header {
  padding-top: calc(12px + var(--safe-top));
}

.mobile-bottom-nav {
  display: none;
}

.pwa-install-banner {
  display: none;
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(var(--mobile-nav-h) + var(--safe-bottom) + 12px);
  z-index: 200;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  align-items: center;
  gap: 12px;
}

.pwa-install-banner.visible {
  display: flex;
}

.pwa-install-banner p {
  flex: 1;
  font-size: 0.85rem;
  margin: 0;
}

.pwa-install-banner button {
  flex-shrink: 0;
}

@media (max-width: 900px) {
  html,
  body {
    overflow-x: clip;
  }

  .main {
    max-width: 100%;
    padding: 16px 12px;
    overflow-x: clip;
  }

  /* Header — compact logo, hide nav duplicated in bottom bar */
  .header {
    padding-left: 10px;
    padding-right: 10px;
    min-height: 52px;
    overflow: hidden;
  }

  .header .nav {
    gap: 6px;
    padding-bottom: 10px;
    flex-wrap: nowrap;
    min-width: 0;
    flex-shrink: 1;
    justify-content: flex-end;
  }

  .header .nav-link[href="/discover"],
  .header .nav-link[href="/leaderboard"],
  .header .nav-link[href="/badges"],
  .header .nav-link[href="/creditos"] {
    display: none;
  }

  .header .nav .btn-primary[href="/upload"] {
    display: none;
  }

  .logo {
    padding-left: 58px;
    min-height: 40px;
    padding-bottom: 8px;
    flex-shrink: 0;
  }

  .logo-img {
    left: -2px;
    bottom: -18px;
    width: 56px;
    height: 56px;
  }

  .logo-text {
    font-size: 1.05rem;
    letter-spacing: 0.07em;
  }

  .header .nav-link span,
  .header .nav-profile > span:not(.nav-avatar),
  .header .nav-staff-badge,
  .header .btn span {
    display: none;
  }

  .header .nav-profile .nav-avatar {
    display: block;
  }

  .header .nav-profile {
    gap: 0;
    padding: 0;
  }

  .header .btn,
  .header .nav-link {
    padding: 10px;
    min-width: 44px;
    min-height: 44px;
    justify-content: center;
  }

  .header .nav-avatar {
    width: 36px;
    height: 36px;
  }

  .header .nav-link.nav-notifications span:not(.nav-notif-badge) {
    display: none;
  }

  /* Mobile bottom nav */
  .mobile-bottom-nav {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 150;
    height: calc(var(--mobile-nav-h) + var(--safe-bottom));
    padding: 0 2px var(--safe-bottom);
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    justify-content: stretch;
    align-items: stretch;
  }

  .mobile-nav-item .mobile-nav-icon-wrap {
    position: relative;
  }

  .mobile-nav-item {
    display: flex;
    flex: 1 1 0;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 6px 2px;
    min-width: 0;
    min-height: 44px;
    color: var(--text-muted);
    font-size: 0.6rem;
    font-weight: 600;
    line-height: 1.1;
    border: none;
    background: none;
    cursor: pointer;
    text-decoration: none;
    text-align: center;
  }

  .mobile-nav-item span {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-nav-item.active,
  .mobile-nav-item:hover {
    color: var(--accent);
  }

  .mobile-nav-item .oa-icon {
    width: 22px;
    height: 22px;
    flex-shrink: 0;
  }

  .footer {
    display: none;
  }

  /* Discover / masonry grid */
  .page-title {
    font-size: 1.45rem;
  }

  .page-subtitle {
    font-size: 0.9rem;
    margin-bottom: 16px;
  }

  .masonry {
    column-count: 2;
    column-gap: 12px;
  }

  .card-wrap {
    margin-bottom: 12px;
  }

  .card-overlay {
    padding: 10px;
  }

  .card-title {
    font-size: 0.88rem;
  }

  /* Profile page */
  .profile-page {
    --profile-banner-min-h: 120px;
    --profile-banner-max-h: 180px;
    --profile-avatar-size: 96px;
    --profile-header-overlap: 54px;
    margin: -16px -12px 0;
    padding-bottom: 16px;
  }

  .profile-header-custom {
    flex-wrap: wrap;
    margin-left: 12px;
    margin-right: 12px;
    margin-bottom: 24px;
    gap: 12px 14px;
  }

  .profile-body {
    padding-top: calc(var(--profile-header-overlap) - 14px);
    width: 100%;
  }

  .profile-top-row {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .profile-name-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
  }

  .profile-display-name {
    font-size: clamp(1.25rem, 5vw, 1.6rem);
  }

  .profile-discord {
    white-space: normal;
    word-break: break-word;
    font-size: 0.88rem;
  }

  .profile-bio {
    font-size: 0.92rem;
    margin-top: 10px;
  }

  .profile-social-links {
    gap: 8px;
    margin-top: 12px;
  }

  .profile-social-link {
    width: 44px;
    height: 44px;
  }

  .profile-achievement-badges {
    gap: 6px;
    margin-top: 10px;
  }

  .achievement-badge {
    font-size: 0.7rem;
    max-width: 100%;
  }

  .achievement-badge-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 9rem;
  }

  .profile-actions {
    margin-left: 0;
    width: 100%;
    justify-content: flex-start;
    flex-wrap: wrap;
    gap: 8px;
    align-self: stretch;
  }

  .profile-actions .btn {
    min-height: 44px;
  }

  .profile-stats {
    flex-wrap: wrap;
    gap: 4px 8px;
    font-size: 0.85rem;
  }

  .category-tabs.profile-tabs {
    margin: 0 12px 16px;
    gap: 6px;
  }

  .category-tabs .tab {
    padding: 8px 14px;
    font-size: 0.82rem;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
  }

  .profile-page .profile-masonry {
    padding: 0 12px;
  }

  .profile-page .profile-masonry.cols-3,
  .profile-page .profile-masonry.cols-4 {
    column-count: 2;
  }

  /* Post detail */
  .post-layout {
    grid-template-columns: 1fr;
    gap: 20px;
  }

  .post-image-wrap {
    max-height: min(65vh, 600px);
    min-height: 0;
  }

  .post-image-wrap.is-portrait.is-frame-ready {
    max-width: 100%;
  }


  .post-image-carousel .carousel-arrow {
    width: 40px;
    height: 40px;
    font-size: 1.5rem;
    opacity: 0.92;
  }

  .post-image-carousel .carousel-arrow[hidden] {
    display: flex;
    opacity: 0.35;
    pointer-events: none;
  }

  .post-image-carousel .carousel-swipe-hint {
    display: block;
    position: absolute;
    bottom: 44px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 2;
    margin: 0;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.9);
    background: rgba(0, 0, 0, 0.45);
    pointer-events: none;
    white-space: nowrap;
  }

  .post-title {
    font-size: 1.2rem;
  }

  .post-sidebar {
    gap: 12px;
  }

  .vote-btn {
    min-height: 44px;
    padding: 10px 16px;
  }

  /* Edit profile */
  .edit-profile-page {
    padding: 0 12px 32px;
  }

  .edit-page-header h1 {
    font-size: 1.35rem;
  }

  .edit-tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 6px;
    margin-left: -12px;
    margin-right: -12px;
    padding: 0 12px 4px;
  }

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

  .edit-tab-btn {
    flex-shrink: 0;
    padding: 10px 14px;
    font-size: 0.82rem;
    min-height: 44px;
  }

  .edit-preview-panel {
    position: static;
    top: auto;
  }

  .edit-panel-form {
    padding: 16px;
  }

  .edit-field-grid {
    grid-template-columns: 1fr;
  }

  .profile-preview-box {
    --profile-banner-min-h: 72px;
    --profile-banner-max-h: 96px;
    --profile-avatar-size: 64px;
    --profile-header-overlap: 32px;
  }

  .profile-preview-box .profile-header-custom {
    margin-left: 12px;
    margin-right: 12px;
  }

  .banner-position-frame,
  .current-banner img {
    max-width: 100%;
  }

  .theme-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }

  /* Login */
  .login-page {
    min-height: 50vh;
    padding: 0 4px;
  }

  .login-card {
    width: 100%;
    max-width: 100%;
    padding: 28px 20px;
    margin: 0 auto;
  }

  .login-logo {
    width: 100px;
    height: 100px;
  }

  .login-card h1 {
    font-size: 1.35rem;
  }

  .login-card .btn-lg {
    width: 100%;
    min-height: 48px;
    justify-content: center;
  }
}

@media (max-width: 480px) {
  .logo {
    padding-left: 52px;
  }

  .logo-img {
    width: 50px;
    height: 50px;
    bottom: -14px;
  }

  .logo-text {
    font-size: 0.95rem;
  }

  .masonry,
  .profile-page .profile-masonry,
  .profile-page .profile-masonry.cols-2,
  .profile-page .profile-masonry.cols-3,
  .profile-page .profile-masonry.cols-4 {
    column-count: 1;
  }

  .profile-page {
    --profile-banner-min-h: 100px;
    --profile-banner-max-h: 150px;
    --profile-avatar-size: 84px;
    --profile-header-overlap: 48px;
  }

  .profile-actions .btn span {
    display: none;
  }

  .profile-actions .btn {
    padding: 10px 12px;
    min-width: 44px;
  }

  .mobile-nav-item {
    font-size: 0.55rem;
    padding: 5px 1px;
  }
}

@media (max-width: 360px) {
  .mobile-nav-item span {
    display: none;
  }

  .mobile-nav-item {
    gap: 0;
    padding: 8px 2px;
  }
}

@media (display-mode: standalone) {
  .pwa-install-banner {
    display: none !important;
  }
}
