/* ============================================================
   SYNCSUP — MOBILE RESPONSIVE + UI/UX POLISH
   Breakpoints:
     ≤ 1024px  Tablet
     ≤  768px  Mobile
     ≤  480px  Small mobile
   ============================================================ */

/* ===== GLOBAL QUALITY-OF-LIFE ===== */
* {
  -webkit-tap-highlight-color: transparent;
}

html {
  scroll-padding-top: calc(var(--header-h) + 16px);
}

/* Better tap targets — only for navigation and button elements */
.nav-link,
.tab-btn,
.btn-load-more,
.bottom-nav-item,
.share-btn,
.btn-cookie-accept,
.btn-cookie-decline,
.search-submit,
.search-toggle,
.theme-toggle,
.nav-toggle,
.back-to-top {
  min-height: 44px;
}


/* Smooth iOS momentum scrolling */
body {
  -webkit-overflow-scrolling: touch;
}

/* ===== TABLET (≤ 1024px) ===== */
@media (max-width: 1024px) {
  .container {
    padding: 0 20px;
  }

  /* Hero: stack into single column */
  .hero-grid {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .hero-card-main {
    grid-row: auto;
  }

  .hero-card-side {
    flex-direction: row;
  }

  /* Tighter two-column main layout */
  .main-layout {
    grid-template-columns: 1fr 290px;
    gap: 28px;
  }

  /* Keep 2-column article grid on tablet */
  .articles-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
  }

  /* Footer: 2-column */
  .footer-grid {
    grid-template-columns: 1fr 1fr;
    gap: 28px;
  }

  .footer-brand {
    grid-column: 1 / -1;
  }

  .main-nav {
    gap: 0;
  }

  .nav-link {
    font-size: 13px;
    padding: 6px 8px;
  }

  /* Related posts: 2-column on tablet */
  .related-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ===== MOBILE (≤ 768px) ===== */
@media (max-width: 768px) {
  :root {
    --header-h: 56px;
    --header-top-h: 0px;
  }

  /* Tighter container padding */
  .container {
    padding: 0 14px;
  }

  /* ── HEADER ── */
  .header-top {
    display: none;
  }

  .header-main {
    height: var(--header-h);
  }

  .header-main-inner {
    gap: 10px;
  }

  .site-logo {
    font-size: 22px;
    letter-spacing: -0.3px;
  }

  /* Hamburger menu */
  .nav-toggle {
    display: flex;
    order: -1;
    width: 40px;
    height: 40px;
    flex-shrink: 0;
  }

  /* ── MOBILE SLIDE-IN NAV ── */
  .main-nav {
    position: fixed;
    top: var(--header-h);
    left: 0;
    bottom: 0;
    width: min(300px, 85vw);
    background: var(--clr-bg-2);
    flex-direction: column;
    padding: 12px 0 env(safe-area-inset-bottom, 24px);
    border-right: 1px solid var(--clr-border);
    z-index: 101;
    transform: translateX(-110%);
    transition: transform 0.32s cubic-bezier(0.4, 0, 0.2, 1);
    overflow-y: auto;
    overscroll-behavior: contain;
    box-shadow: var(--shadow-lg);
  }

  .main-nav.mobile-open {
    transform: translateX(0);
  }

  .nav-link {
    padding: 15px 22px;
    font-size: 16px;
    border-radius: 0;
    border-bottom: 1px solid var(--clr-border);
    color: var(--clr-text);
    transition: background var(--transition), color var(--transition), padding-left 0.18s ease;
    display: flex;
    align-items: center;
    min-height: 52px;
  }

  .nav-link:last-child {
    border-bottom: none;
  }

  .nav-link:hover,
  .nav-link.active {
    background: var(--clr-bg-3);
    color: var(--clr-accent);
    padding-left: 30px;
  }

  /* ── SEARCH BAR ── */
  .search-input {
    font-size: 16px;
    /* Prevent iOS zoom on focus */
  }

  /* ── NEWS TICKER ── */
  .news-ticker {
    display: none;
  }

  /* ── HERO SECTION ── */
  .hero-section {
    padding: 16px 0;
  }

  .hero-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  /* Main hero card: overlapping text gradient  */
  .hero-card-main .card-body {
    padding: 16px 16px 14px;
  }

  .hero-card-main .card-title {
    font-size: clamp(18px, 5vw, 24px);
    line-height: 1.3;
  }

  /* Side cards: slim horizontal layout */
  .hero-card-side {
    flex-direction: row;
    height: 96px;
  }

  .hero-card-side .card-img {
    width: 96px;
    height: 96px;
    flex-shrink: 0;
  }

  .hero-card-side .card-body {
    padding: 10px 14px;
  }

  .hero-card-side .card-title {
    font-size: 14px;
    line-height: 1.35;
  }

  /* ── MAIN LAYOUT ── */
  .main-layout {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .site-main {
    padding: 24px 0 80px;
  }

  /* Sidebar: below articles, horizontal scrollable widgets */
  .sidebar {
    position: static;
    order: 2;
    margin-top: 32px;
  }

  /* ── CATEGORY TABS ── */
  .category-tabs {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    gap: 8px;
    padding-bottom: 8px;
    margin-bottom: 18px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    /* Fade edge */
    -webkit-mask-image: linear-gradient(to right, black 85%, transparent 100%);
    mask-image: linear-gradient(to right, black 85%, transparent 100%);
  }

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

  .tab-btn {
    flex-shrink: 0;
    padding: 7px 16px;
    font-size: 13px;
    white-space: nowrap;
  }

  /* ── ARTICLES GRID ── */
  /* Two columns on mobile with vertical cards for better visual appeal */
  .articles-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }

  /* Cards: full vertical layout on mobile */
  .article-card {
    display: flex;
    flex-direction: column;
    height: auto;
    animation: fadeInUp 0.35s ease both;
  }

  .article-card .card-img-wrap {
    width: 100%;
    height: auto;
    aspect-ratio: 16/9;
    flex-shrink: unset;
    border-radius: 0;
  }

  .article-card .card-body {
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: 1;
  }

  .article-card .card-title {
    font-family: var(--font-display);
    font-size: 14px;
    font-weight: 700;
    line-height: 1.35;
    margin: 0;
    color: var(--clr-text);
    /* 3-line clamp */
    display: -webkit-box;
    -webkit-line-clamp: 3;
    line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  /* Hide excerpt on mobile to save space */
  .article-card .card-excerpt {
    display: none;
  }

  /* Slimmer footer on mobile cards */
  .article-card .card-footer {
    margin-top: auto;
    padding-top: 8px;
    border-top: 1px solid var(--clr-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
  }

  .author-avatar {
    width: 22px;
    height: 22px;
    font-size: 9px;
  }

  .author-name {
    display: none;
  }

  .card-date {
    font-size: 11px;
  }

  .article-card .card-share {
    display: none;
  }

  /* ── LOAD MORE ── */
  .btn-load-more {
    width: 100%;
    padding: 14px;
    font-size: 15px;
    border-radius: var(--radius-md);
  }

  /* ── SIDEBAR WIDGETS ── */
  .sidebar-widget {
    padding: 18px;
  }

  /* Newsletter widget: row layout on mobile */
  .newsletter-form {
    flex-direction: row;
    gap: 8px;
  }

  .newsletter-form input {
    flex: 1;
    min-width: 0;
  }

  .newsletter-form button {
    flex-shrink: 0;
    padding: 10px 16px;
    white-space: nowrap;
  }

  /* Tags: allow full wrap */
  .tags-cloud {
    gap: 6px;
  }

  .tag-pill {
    font-size: 12px;
    padding: 5px 10px;
  }

  /* ── FOOTER ── */
  .footer-grid {
    grid-template-columns: 1fr;
    gap: 24px;
  }

  .footer-brand {
    grid-column: auto;
  }

  .footer-brand p {
    max-width: 100%;
    font-size: 14px;
  }

  .footer-bottom {
    flex-direction: column;
    gap: 6px;
    text-align: center;
    padding: 16px 0;
  }

  .footer-links ul {
    gap: 8px;
  }

  /* ── COOKIE BANNER ── */
  .cookie-inner {
    flex-direction: column;
    gap: 12px;
    align-items: flex-start;
    padding: 0 14px;
  }

  .cookie-inner p {
    font-size: 13px;
  }

  .cookie-actions {
    width: 100%;
    display: flex;
    gap: 8px;
  }

  .btn-cookie-accept,
  .btn-cookie-decline {
    flex: 1;
    text-align: center;
    padding: 10px 12px;
  }

  /* ── BACK TO TOP ── */
  .back-to-top {
    bottom: 78px;
    right: 14px;
    width: 40px;
    height: 40px;
  }

  /* ── ARTICLE PAGE ── */
  .article-hero {
    padding: 20px 0 0;
  }

  .article-title {
    font-size: clamp(22px, 6vw, 32px);
    letter-spacing: -0.3px;
  }

  .article-body {
    font-size: 16px;
    line-height: 1.85;
  }

  .article-body h2 {
    font-size: 22px;
    margin: 28px 0 12px;
  }

  .article-body h3 {
    font-size: 18px;
    margin: 22px 0 10px;
  }

  .article-body pre {
    padding: 14px 16px;
    font-size: 13px;
    margin: 16px -14px;
    /* Bleed to edges */
    border-radius: 0;
  }

  .article-body blockquote {
    margin: 20px -14px;
    padding: 14px 18px;
    font-size: 16px;
  }

  .article-meta-bar {
    gap: 10px;
    font-size: 13px;
  }

  /* Share bar: horizontal scroll */
  .share-bar {
    gap: 8px;
    overflow-x: auto;
    flex-wrap: nowrap;
    padding: 14px 0;
    scrollbar-width: none;
    -webkit-mask-image: linear-gradient(to right, black 80%, transparent 100%);
    mask-image: linear-gradient(to right, black 80%, transparent 100%);
  }

  .share-bar::-webkit-scrollbar {
    display: none;
  }

  .share-btn {
    flex-shrink: 0;
    padding: 8px 14px;
    font-size: 12px;
  }

  /* Article layout: single column */
  .article-layout {
    grid-template-columns: 1fr;
    padding: 16px 0 40px;
    gap: 0;
  }

  .article-sidebar {
    position: static;
    margin-top: 32px;
  }

  /* TOC: hide on mobile (shown via in-article float) */
  .widget-toc {
    display: none;
  }
}

/* ===== SMALL MOBILE (≤ 480px) ===== */
@media (max-width: 480px) {
  .container {
    padding: 0 12px;
  }

  .site-logo {
    font-size: 20px;
  }

  /* Hero: slightly smaller text */
  .hero-card-main .card-title {
    font-size: 17px;
  }

  .hero-card-side {
    height: 84px;
  }

  .hero-card-side .card-img {
    width: 84px;
    height: 84px;
  }

  .hero-card-side .card-title {
    font-size: 13px;
  }

  /* On very small screens: single-column article grid */
  .articles-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  /* Single-column cards: show excerpt again */
  .article-card {
    flex-direction: row;
    height: 110px;
  }

  .article-card .card-img-wrap {
    width: 110px;
    height: 110px;
    flex-shrink: 0;
    aspect-ratio: unset;
  }

  .article-card .card-body {
    padding: 10px 12px;
    justify-content: space-between;
  }

  .article-card .card-title {
    font-size: 14px;
    -webkit-line-clamp: 2;
    line-clamp: 2;
  }

  /* Compact sidebar */
  .sidebar-widget {
    padding: 14px;
  }

  /* Newsletter: stack vertically on small */
  .newsletter-form {
    flex-direction: column;
  }

  /* Related posts: 1 column */
  .related-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .related-card {
    display: flex;
    flex-direction: row;
    height: 88px;
  }

  .related-card img {
    width: 88px;
    height: 88px;
    aspect-ratio: unset;
    flex-shrink: 0;
  }

  .related-card-body {
    padding: 10px;
    display: flex;
    flex-direction: column;
    justify-content: center;
  }
}

/* ===== MOBILE BOTTOM NAVIGATION ===== */
.mobile-bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 60px;
  background: var(--clr-bg-2);
  border-top: 1px solid var(--clr-border);
  z-index: 98;
  padding: 0 6px;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  align-items: center;
  justify-content: space-around;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 -1px 0 var(--clr-border), var(--shadow-sm);
}

@media (max-width: 768px) {
  .mobile-bottom-nav {
    display: flex;
  }

  /* Body clearance for bottom nav */
  body {
    padding-bottom: calc(60px + env(safe-area-inset-bottom, 0px));
  }

  .site-footer {
    padding-bottom: 20px;
  }
}

.bottom-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  flex: 1;
  height: 100%;
  color: var(--clr-text-3);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  transition: color var(--transition);
  font-family: var(--font-body);
  text-decoration: none;
  border-radius: var(--radius-sm);
  position: relative;
}

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

/* Active indicator pill */
.bottom-nav-item.active::after {
  content: '';
  position: absolute;
  top: 6px;
  left: 50%;
  transform: translateX(-50%);
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--clr-accent);
  animation: popIn 0.2s ease;
}

@keyframes popIn {
  from {
    transform: translateX(-50%) scale(0);
  }

  to {
    transform: translateX(-50%) scale(1);
  }
}

.bottom-nav-item svg {
  transition: transform var(--transition);
}

.bottom-nav-item.active svg {
  transform: scale(1.1) translateY(-1px);
}

/* ===== TOUCH FEEDBACK ===== */
@media (hover: none) and (pointer: coarse) {
  .article-card:active {
    transform: scale(0.975);
    opacity: 0.9;
    transition: transform 0.12s ease, opacity 0.12s ease;
  }

  .tab-btn:active {
    transform: scale(0.96);
    opacity: 0.8;
    transition: transform 0.1s ease, opacity 0.1s ease;
  }

  .share-btn:active,
  .btn-load-more:active,
  .btn-cookie-accept:active {
    opacity: 0.75;
    transform: scale(0.97);
    transition: transform 0.1s ease, opacity 0.1s ease;
  }

  .hero-card-main:active,
  .hero-card-side:active {
    opacity: 0.88;
    transition: opacity 0.12s ease;
  }

  .tag-pill:active {
    background: var(--clr-accent);
    color: #fff;
  }

  .nav-link:active {
    background: var(--clr-bg-3);
    color: var(--clr-accent);
  }

  .bottom-nav-item:active {
    transform: scale(0.9);
    transition: transform 0.1s ease;
  }
}

/* ===== SMOOTH MOMENTUM SCROLLING ===== */
@media (max-width: 768px) {

  .articles-grid,
  .category-tabs,
  .main-nav,
  .share-bar {
    -webkit-overflow-scrolling: touch;
  }
}

/* ===== READING MODE: ARTICLE PAGE MOBILE ===== */
@media (max-width: 768px) {

  /* TOC floating access button */
  .toc-fab {
    display: flex;
    position: fixed;
    bottom: 76px;
    left: 16px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--clr-surface);
    border: 1px solid var(--clr-border);
    box-shadow: var(--shadow-md);
    align-items: center;
    justify-content: center;
    color: var(--clr-text-2);
    z-index: 50;
    cursor: pointer;
    transition: background var(--transition), color var(--transition);
  }

  .toc-fab:hover {
    background: var(--clr-accent);
    color: #fff;
  }

  /* Reading progress bar: thicker on mobile */
  .reading-progress {
    height: 3px;
    top: var(--header-h);
  }
}

/* ===== IMPROVED SEARCH ON MOBILE ===== */
@media (max-width: 768px) {
  .search-bar {
    padding: 10px 0;
  }

  .search-form {
    gap: 6px;
  }

  .search-submit {
    padding: 10px 14px;
    font-size: 13px;
    white-space: nowrap;
  }
}

/* ===== HERO SECTION — CARD HOVER ON MOBILE ===== */
/* Ensure no hover transform delays on mobile */
@media (hover: none) {

  .hero-card-main:hover,
  .hero-card-side:hover,
  .article-card:hover,
  .related-card:hover {
    transform: none;
    box-shadow: none;
  }
}

/* ===== PRINT ===== */
@media print {

  .site-header,
  .news-ticker,
  .sidebar,
  .mobile-bottom-nav,
  .back-to-top,
  .cookie-banner,
  .ad-slot,
  .share-bar,
  .related-posts {
    display: none !important;
  }

  body {
    padding-bottom: 0 !important;
  }

  .main-layout,
  .article-layout {
    grid-template-columns: 1fr;
  }

  .article-body {
    font-size: 12pt;
    color: #000;
    line-height: 1.7;
  }
}