/* =========================================================
   Responsive + image-fit layer (loaded last on every page)
   Keeps all pages usable from 320px phones through desktop.
   ========================================================= */

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-padding-top: 92px;
}

body {
  min-width: 320px;
  overflow-x: clip;
}

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

img {
  height: auto;
  object-position: center;
}

figure {
  max-width: 100%;
  margin-inline: 0;
}

/* Prevent grid/flex children and long Thai/English text from forcing overflow. */
.container,
.hero-grid,
.article-shell,
.article-grid,
.news-layout,
.news-stack,
.analysis-grid,
.guide-grid,
.cards,
.steps,
.about-card,
.footer-grid,
.match,
.match-box,
.scorecard,
.hero-copy,
.article,
.side-card,
.card,
.news-body,
.feature-body,
.analysis-card,
.guide-card,
.footer-col,
.footer-brand,
.team,
.confidence,
.section-head,
.cta-content {
  min-width: 0;
}

h1,
h2,
h3,
h4,
p,
li,
a,
span,
strong {
  overflow-wrap: anywhere;
}

pre,
code {
  max-width: 100%;
  overflow-x: auto;
}

/* ---------- Shared image rules ---------- */
.hero-art,
.hero-card,
.about-logo-wrap,
.feature-card,
.news-thumb,
.article-media,
.image-frame {
  overflow: hidden;
}

/* Brand/artwork must remain fully visible — never crop it. */
.hero-logo,
.about-logo,
.hero-art > img,
.about-logo-wrap > img,
.drawer-title img,
.brand-logo,
.author-avatar,
img[src*="guru-khang-ban-logo"] {
  object-fit: contain !important;
}

.hero-logo,
.about-logo,
.hero-art > img,
.about-logo-wrap > img {
  width: 100%;
  height: 100%;
  max-height: 100%;
}

/* Registration guide and article illustrations keep their natural ratio. */
.hero-card img,
.article img:not(.author-avatar),
.article-media img,
.image-frame img,
img[src*="bb3101-register-guide"] {
  width: 100% !important;
  max-width: 100% !important;
  height: auto !important;
  aspect-ratio: auto !important;
  object-fit: contain !important;
}

img[src*="bb3101-register-guide"] {
  background: #090909;
  border-radius: 16px;
}

/* Thumbnail-style boxes may crop, but only inside their dedicated frame. */
.news-thumb img,
.card-cover img,
.thumbnail img,
.feature-visual img {
  width: 100%;
  height: 100%;
  object-fit: cover !important;
}

/* Stable artwork frames avoid layout shift while still showing all of the image. */
.hero-art {
  isolation: isolate;
}

.hero-art > img,
.hero-logo {
  padding: clamp(8px, 2vw, 22px);
}

.about-logo-wrap > img,
.about-logo {
  padding: clamp(10px, 2.5vw, 26px);
}

/* Buttons and interactive items remain easy to tap. */
button,
.btn,
.nav-link,
.filter-btn,
.footer-links a,
.related a {
  touch-action: manipulation;
}

.btn,
.mobile-toggle,
.drawer-close,
.filter-btn {
  min-height: 44px;
}

/* Header / drawer safe-area handling. */
.site-header .nav-menu {
  height: 100vh !important;
  height: 100dvh !important;
  padding-top: max(18px, env(safe-area-inset-top)) !important;
  padding-bottom: max(18px, env(safe-area-inset-bottom)) !important;
  overscroll-behavior: contain;
}

.site-header .menu-overlay {
  overscroll-behavior: contain;
}

/* ---------- Tablet ---------- */
@media (max-width: 1024px) {
  .article-shell,
  .article-grid,
  .hero-grid,
  .news-layout,
  .about-card {
    grid-template-columns: 1fr !important;
  }

  .sidebar {
    position: static !important;
    top: auto !important;
  }

  .hero-art {
    width: min(100%, 680px);
    min-height: 0 !important;
    aspect-ratio: 1 / 1;
    margin-inline: auto;
    padding: clamp(12px, 3vw, 28px) !important;
  }

  .hero-card {
    width: min(100%, 860px);
    margin-inline: auto;
  }

  .analysis-grid,
  .guide-grid,
  .cards,
  .steps {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  .footer-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  .footer-brand {
    grid-column: 1 / -1 !important;
    max-width: none !important;
  }

  .section-head {
    align-items: flex-start !important;
  }
}

/* ---------- Phones / small tablets ---------- */
@media (max-width: 768px) {
  :root {
    --mobile-gutter: 20px;
  }

  .container {
    width: min(calc(100% - var(--mobile-gutter)), var(--max)) !important;
  }

  .topbar-inner {
    min-height: 34px !important;
    justify-content: center !important;
    text-align: center;
    line-height: 1.4;
  }

  .topbar-inner > span:last-child {
    display: none !important;
  }

  .site-header .nav-wrap,
  .nav-wrap {
    min-height: 66px !important;
    gap: 10px !important;
    grid-template-columns: minmax(0, 1fr) auto !important;
  }

  .site-header .nav-spacer {
    display: none !important;
  }

  .site-header .brand,
  .brand {
    min-width: 0 !important;
  }

  .site-header .brand-logo,
  .brand-logo {
    width: 44px !important;
    height: 44px !important;
    flex: 0 0 44px;
  }

  .site-header .brand-copy,
  .brand-copy {
    min-width: 0;
  }

  .site-header .brand-copy strong,
  .brand-copy strong {
    font-size: .95rem !important;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .site-header .brand-copy span,
  .brand-copy span {
    display: none !important;
  }

  .site-header .nav-actions,
  .nav-actions {
    gap: 8px !important;
  }

  .site-header .nav-actions .btn-sm,
  .site-header .nav-actions .btn-dark,
  .nav-actions .btn-sm,
  .nav-actions .btn-dark {
    display: none !important;
  }

  .site-header .mobile-toggle,
  .mobile-toggle {
    width: 44px !important;
    height: 44px !important;
    flex: 0 0 44px;
  }

  .site-header .nav-menu {
    width: min(390px, calc(100% - 12px)) !important;
    padding-inline: 16px !important;
  }

  .site-header .nav-link {
    padding: 13px 14px !important;
    font-size: .94rem !important;
  }

  .section {
    padding: 54px 0 !important;
  }

  .section-tight {
    padding: 44px 0 !important;
  }

  .hero {
    min-height: 0 !important;
    padding: 42px 0 34px !important;
  }

  .hero-grid {
    gap: 26px !important;
  }

  .hero-copy {
    text-align: left !important;
  }

  .hero h1 {
    font-size: clamp(2.35rem, 12vw, 3.65rem) !important;
    line-height: 1.02 !important;
    letter-spacing: -.045em !important;
  }

  .hero p,
  .hero-lead,
  .section-copy,
  .lead {
    font-size: .96rem !important;
  }

  .hero-actions,
  .cta-actions {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 10px !important;
    width: 100%;
  }

  .hero-actions .btn,
  .cta-actions .btn,
  .side-card .btn {
    width: 100% !important;
    white-space: normal !important;
    text-align: center;
  }

  .hero-meta {
    display: grid !important;
    grid-template-columns: 1fr !important;
    justify-content: start !important;
    gap: 8px !important;
  }

  .hero-art {
    width: min(100%, 520px) !important;
    min-height: 0 !important;
    aspect-ratio: 1 / 1 !important;
    margin: 0 auto !important;
    padding: 12px !important;
    border-radius: 24px !important;
  }

  .hero-art > img,
  .hero-logo {
    width: 100% !important;
    height: 100% !important;
    padding: 10px !important;
  }

  .floating-card {
    min-width: 126px !important;
    max-width: 46%;
    padding: 9px 11px !important;
    border-radius: 14px !important;
  }

  .floating-card small {
    font-size: .62rem !important;
  }

  .floating-card strong {
    font-size: .77rem !important;
  }

  .mini-strip-grid,
  .analysis-grid,
  .guide-grid,
  .cards,
  .steps,
  .scorecard,
  .about-points,
  .footer-grid {
    grid-template-columns: 1fr !important;
  }

  .mini-item,
  .mini-item:nth-child(n) {
    border-left: 0 !important;
    border-top: 1px solid rgba(255,255,255,.09) !important;
  }

  .mini-item:first-child {
    border-top: 0 !important;
  }

  .section-head {
    display: flex !important;
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 14px !important;
    margin-bottom: 24px !important;
  }

  .section-title {
    font-size: clamp(1.85rem, 8vw, 2.55rem) !important;
  }

  .feature-card {
    min-height: 430px !important;
    border-radius: 22px !important;
  }

  .feature-body,
  .article,
  .side-card,
  .cta,
  .card,
  .step,
  .analysis-card,
  .guide-card {
    padding: 18px !important;
  }

  .news-layout,
  .news-stack {
    grid-template-columns: 1fr !important;
    gap: 14px !important;
  }

  .news-card {
    grid-template-columns: 96px minmax(0, 1fr) !important;
    gap: 12px !important;
    min-height: 0 !important;
    border-radius: 18px !important;
  }

  .news-thumb {
    min-height: 100% !important;
    aspect-ratio: 1 / 1 !important;
  }

  .news-body {
    padding: 15px 14px 15px 0 !important;
  }

  .news-body h3 {
    font-size: 1rem !important;
    line-height: 1.35 !important;
  }

  .news-body p {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
    overflow: hidden;
  }

  .filter-row {
    display: flex !important;
    flex-wrap: nowrap !important;
    gap: 8px !important;
    margin-inline: calc(var(--mobile-gutter) / -2) !important;
    padding: 2px calc(var(--mobile-gutter) / 2) 10px !important;
    overflow-x: auto !important;
    overscroll-behavior-inline: contain;
    scrollbar-width: none;
    scroll-snap-type: x proximity;
  }

  .filter-row::-webkit-scrollbar {
    display: none;
  }

  .filter-btn {
    flex: 0 0 auto;
    scroll-snap-align: start;
    white-space: nowrap;
  }

  .analysis-card {
    min-height: 0 !important;
    border-radius: 18px !important;
  }

  .analysis-top {
    align-items: flex-start !important;
    gap: 12px !important;
  }

  .analysis-top > span:last-child {
    white-space: nowrap;
  }

  .match {
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr) !important;
    gap: 10px !important;
  }

  .team {
    min-width: 0;
    text-align: center;
  }

  .team-badge {
    width: 54px !important;
    height: 54px !important;
    border-radius: 17px !important;
  }

  .confidence {
    display: flex !important;
    align-items: center !important;
    flex-wrap: wrap !important;
    gap: 12px !important;
  }

  .confidence .btn {
    margin-left: auto;
  }

  .article-shell,
  .article-grid {
    gap: 18px !important;
  }

  .article {
    border-radius: 20px !important;
  }

  .article h2 {
    font-size: clamp(1.35rem, 6vw, 1.75rem) !important;
    margin-top: 34px !important;
  }

  .article h3 {
    font-size: 1.08rem !important;
  }

  .hero-card {
    padding: 10px !important;
    border-radius: 20px !important;
  }

  .hero-card img,
  img[src*="bb3101-register-guide"] {
    width: 100% !important;
    height: auto !important;
    max-height: none !important;
    object-fit: contain !important;
    border-radius: 13px !important;
  }

  .image-caption {
    margin: 9px 3px 1px !important;
    font-size: .72rem !important;
    line-height: 1.45;
  }

  .about-card {
    padding: 16px !important;
    border-radius: 22px !important;
  }

  .about-logo-wrap {
    min-height: 0 !important;
    aspect-ratio: 1 / 1;
    border-radius: 18px !important;
  }

  .about-logo-wrap > img,
  .about-logo {
    width: 100% !important;
    height: 100% !important;
    padding: 12px !important;
  }

  .cta-box {
    padding: 28px 18px !important;
    border-radius: 22px !important;
  }

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

  .footer-bottom {
    flex-direction: column !important;
    align-items: flex-start !important;
  }

  .modal {
    padding: 10px !important;
  }

  .modal-dialog {
    max-height: calc(100dvh - 20px) !important;
    border-radius: 18px !important;
  }

  .modal-head,
  .modal-body {
    padding: 16px !important;
  }
}

/* ---------- Narrow phones ---------- */
@media (max-width: 480px) {
  :root {
    --mobile-gutter: 16px;
  }

  .site-header .nav-menu {
    width: 100% !important;
    border-left: 0 !important;
  }

  .site-header .brand-copy strong,
  .brand-copy strong {
    font-size: .9rem !important;
  }

  .hero h1 {
    font-size: clamp(2.2rem, 11.5vw, 3.2rem) !important;
  }

  .hero-art {
    width: min(100%, 390px) !important;
  }

  .floating-card {
    max-width: 49%;
  }

  .news-card {
    grid-template-columns: 1fr !important;
  }

  .news-thumb {
    min-height: 108px !important;
    aspect-ratio: 16 / 7 !important;
  }

  .news-body {
    padding: 15px !important;
  }

  .match {
    gap: 6px !important;
  }

  .team-badge {
    width: 50px !important;
    height: 50px !important;
  }

  .confidence {
    align-items: stretch !important;
  }

  .confidence-copy,
  .confidence .btn {
    width: 100% !important;
    margin-left: 0 !important;
  }

  .tag-row {
    gap: 6px !important;
  }

  .tag {
    font-size: .7rem !important;
  }

  .breadcrumbs {
    font-size: .78rem !important;
    margin-bottom: 18px !important;
  }

  .article,
  .side-card,
  .card,
  .step,
  .analysis-card,
  .guide-card {
    padding: 16px !important;
  }
}

@media (max-width: 360px) {
  .site-header .brand-copy strong,
  .brand-copy strong {
    max-width: 150px;
  }

  .hero h1 {
    font-size: 2.12rem !important;
  }

  .floating-card {
    display: none !important;
  }

  .team-badge {
    width: 46px !important;
    height: 46px !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: .01ms !important;
  }

  .reveal {
    opacity: 1 !important;
    transform: none !important;
  }
}
