/**
 * RummyTrail responsive / mobile optimization
 * Target widths: 360, 375, 390, 430, 768, 1024, 1440
 */

html {
  overflow-x: clip;
}

body {
  font-size: 16px;
  line-height: 1.6;
  overflow-x: clip;
  max-width: 100%;
}

img,
svg,
video,
iframe {
  max-width: 100%;
  height: auto;
}

.site-header__bar {
  width: min(100%, var(--container));
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.nav-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 44px;
  min-height: 44px;
  margin: 0;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--accent-dark);
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  font-weight: 800;
}

.nav-toggle__box {
  display: grid;
  gap: 4px;
  width: 18px;
}

.nav-toggle__bar {
  display: block;
  height: 2px;
  width: 100%;
  background: currentColor;
  border-radius: 2px;
  transition: transform 0.18s ease, opacity 0.18s ease;
}

.nav-toggle[aria-expanded="true"] .nav-toggle__bar:nth-child(1) {
  transform: translateY(6px) rotate(45deg);
}
.nav-toggle[aria-expanded="true"] .nav-toggle__bar:nth-child(2) {
  opacity: 0;
}
.nav-toggle[aria-expanded="true"] .nav-toggle__bar:nth-child(3) {
  transform: translateY(-6px) rotate(-45deg);
}

.nav-toggle__label {
  line-height: 1;
}

/* ---------- Mobile / small tablets (< 768px) ---------- */
@media (max-width: 767.98px) {
  .site-header {
    min-height: 52px;
    padding: 6px 12px;
    position: sticky;
    top: 0;
    z-index: 40;
  }

  .admin-bar .site-header {
    top: 46px;
  }

  .site-header__bar {
    justify-content: space-between;
    width: 100%;
  }

  .brand {
    width: auto;
    max-width: calc(100% - 96px);
    justify-content: flex-start;
    gap: 8px;
    font-size: 16px;
  }

  .brand-mark {
    width: 36px;
    height: 36px;
    flex-basis: 36px;
    border-radius: 9px;
  }

  .brand--custom .custom-logo {
    height: 32px;
    max-width: min(180px, 58vw);
  }

  .nav-toggle {
    display: inline-flex;
    flex: 0 0 auto;
  }

  .site-nav {
    display: none;
    overflow: visible;
    border-bottom: 1px solid var(--line);
    background: var(--surface);
  }

  .site-nav.is-open {
    display: block;
  }

  .site-nav .nav-inner {
    width: 100%;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
  }

  .site-nav .nav-inner > li {
    width: 100%;
    border-bottom: 1px solid var(--line);
  }

  .site-nav .nav-inner > li:last-child {
    border-bottom: 0;
  }

  .site-nav a,
  .site-nav .nav-inner > li > a {
    display: flex;
    align-items: center;
    min-height: 44px;
    padding: 12px 16px;
    border-left: 0 !important;
    border-right: 0 !important;
    white-space: normal;
    line-height: 1.35;
  }

  .site-main {
    width: min(calc(100% - 20px), var(--container));
    padding: 12px 0 28px;
    min-height: 50vh;
  }

  .home-hero,
  .directory-hero,
  .compact-hero {
    padding: 16px 14px 14px;
    border-radius: 14px;
    margin-bottom: 12px;
  }

  .home-hero h1,
  .directory-hero h1,
  .hero h1 {
    font-size: clamp(22px, 6.4vw, 28px);
    line-height: 1.2;
  }

  .hero > p,
  .home-hero > p,
  .directory-hero > p {
    margin-top: 8px;
    font-size: 15px;
    line-height: 1.55;
  }

  .home-hero__search-block {
    max-width: 100%;
    margin-top: 12px;
  }

  .home-hero__search,
  .search-wrap {
    width: 100%;
    max-width: none;
    margin-top: 0;
  }

  .search-wrap input[type="search"],
  .search-wrap input[type="text"] {
    width: 100%;
    min-height: 44px;
    height: 44px;
    font-size: 16px; /* prevent iOS zoom */
  }

  .home-hero__meta {
    margin-top: 8px;
    font-size: 12px;
  }

  /* Mobile homepage: tutorials stay limited; Featured Apps shows full query count */
  .home-section--tutorials .post-list > .post-card:nth-child(n + 3) {
    display: none;
  }

  .app-grid--updates {
    gap: 8px;
  }

  .app-card--rail {
    grid-template-columns: 52px minmax(0, 1fr);
    padding: 10px 12px;
  }

  .app-card--rail .app-icon {
    width: 52px;
    height: 52px;
  }

  .post-card__media {
    max-height: 120px;
  }

  .post-card--text {
    padding: 12px;
  }

  .tax-chips {
    display: flex;
    flex-wrap: nowrap;
    gap: 8px;
    margin: 0 0 14px;
    padding-bottom: 4px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
  }

  .tax-chips a {
    flex: 0 0 auto;
    min-height: 44px;
    padding: 8px 14px;
  }

  .home-section {
    margin: 18px 0;
  }

  .section-heading {
    margin: 4px 0 12px;
    gap: 8px;
  }

  .section-heading h2 {
    font-size: clamp(20px, 5.5vw, 24px);
  }

  .section-heading p {
    font-size: 14px;
    line-height: 1.5;
  }

  .app-grid {
    grid-template-columns: 1fr !important;
    gap: 10px;
  }

  .app-card--grid {
    grid-template-columns: 64px minmax(0, 1fr);
    gap: 10px;
    padding: 12px;
    border-radius: 12px;
  }

  .app-card--grid .app-icon {
    width: 64px;
    height: 64px;
    border-radius: 14px;
  }

  .app-card__body h3 {
    font-size: 16px;
    white-space: normal;
  }

  .app-card__desc {
    display: none;
  }

  .app-card__refs {
    margin-top: 8px;
    padding-top: 8px;
  }

  .button,
  .button--small,
  .app-card__cta {
    min-height: 44px;
    padding: 10px 14px;
    font-size: 14px;
  }

  .home-section__cta {
    margin-top: 14px;
  }

  .home-safety {
    padding: 14px;
  }

  .safety-list li {
    margin: 8px 0;
    line-height: 1.55;
  }

  .post-card-panel {
    padding: 14px;
  }

  .post-card {
    grid-template-columns: 1fr;
  }

  .pagination a,
  .pagination span,
  .page-numbers {
    min-width: 44px;
    min-height: 44px;
  }

  .sticky-download {
    min-height: 60px;
    max-height: 68px;
    padding: 8px 12px;
    gap: 10px;
  }

  .sticky-download .button {
    min-height: 44px;
    min-width: 44px;
    padding: 10px 14px;
    font-size: 13px;
  }

  body.sticky-download-active .site-main,
  body.sticky-download-active .site-footer {
    padding-bottom: 84px;
  }

  .promo {
    margin: 8px 0;
  }

  body.nav-is-open {
    overflow: hidden;
  }
}

@media screen and (max-width: 782px) {
  .admin-bar .site-header {
    top: 46px;
  }
}

@media screen and (max-width: 600px) {
  .admin-bar .site-header {
    top: 0;
  }
}

/* Narrow phones (~360–390) */
@media (max-width: 390px) {
  .site-main {
    width: min(calc(100% - 16px), var(--container));
  }

  .brand {
    font-size: 15px;
  }

  .nav-toggle__label {
    /* icon-only to save space on very small screens */
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
  }

  .home-hero h1,
  .directory-hero h1 {
    font-size: 22px;
  }

  .app-card--grid {
    grid-template-columns: 56px minmax(0, 1fr);
  }

  .app-card--grid .app-icon {
    width: 56px;
    height: 56px;
  }
}

/* 430 and below extras */
@media (max-width: 430px) {
  .home-faq {
    padding: 12px 10px 10px;
  }

  .home-faq__header h2 {
    font-size: 19px;
  }

  .faq-section summary {
    min-height: 48px;
    padding: 11px 12px;
    gap: 10px;
  }

  .faq-section summary::after {
    flex-basis: 24px;
    width: 24px;
    font-size: 20px;
  }
}

/* Tablet portrait / small laptop */
@media (min-width: 768px) and (max-width: 1023.98px) {
  .site-header {
    min-height: 56px;
    padding: 8px 16px;
  }

  .site-header__bar {
    justify-content: center;
  }

  .nav-toggle {
    display: none;
  }

  .site-nav {
    display: block;
    overflow-x: auto;
  }

  .site-nav .nav-inner {
    width: max-content;
    min-width: 100%;
    flex-direction: row;
    justify-content: center;
  }

  .site-nav a,
  .site-nav .nav-inner > li > a {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    padding: 10px 14px;
  }

  .app-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .app-grid--compact {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .home-hero,
  .directory-hero {
    padding: 22px 20px;
  }

  .tax-chips {
    flex-wrap: wrap;
    overflow: visible;
  }
}

/* Desktop 1024+ — keep existing desktop patterns */
@media (min-width: 1024px) {
  .nav-toggle {
    display: none !important;
  }

  .site-nav {
    display: block !important;
  }

  .site-header__bar {
    justify-content: center;
  }
}

/* Large desktop */
@media (min-width: 1440px) {
  .site-main {
    width: min(calc(100% - 48px), var(--container));
  }
}

@media (prefers-reduced-motion: reduce) {
  .nav-toggle__bar {
    transition: none;
  }
}
