:root {
  --mobile-nav-height: 64px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --touch-target: 44px;
}

/* Small source images fill the card cell while object-fit supplies letterboxing. */
.meme-visual.low-resolution img {
  width: 100%; height: 100%; max-width: none; max-height: none; margin: 0; object-fit: contain;
}
.secondary-filter-toggle,.creator-filter-toggle { display: none; }
.secondary-filter-body { display: contents; }
:where(button,a,input,select,textarea) { touch-action: manipulation; }
.close-modal,.detail-back,.review-close { min-width: var(--touch-target); min-height: var(--touch-target); }
.modal-backdrop { overscroll-behavior: contain; }
.modal { max-height: min(90dvh,calc(100dvh - 24px)); overscroll-behavior: contain; }
.modal:has(.rich-detail) { max-height: calc(100dvh - 24px); }
.rich-detail-image { max-height: min(480px,calc(100dvh - 310px)); }
.creator-page,.admin-page-body { min-height: 100dvh; }
.creator-shell { min-height: calc(100dvh - 74px); }
.creator-sidebar { height: calc(100dvh - 74px); }
.control-panel { max-height: calc(100dvh - 116px); overflow: auto; overscroll-behavior: contain; }

@media (max-width:800px) {
  body { padding-bottom: calc(var(--mobile-nav-height) + var(--safe-bottom)); }
  .mobile-nav { min-height: calc(var(--mobile-nav-height) + var(--safe-bottom)); }
  .hero-section { padding: 20px 16px 18px; }
  .hero-copy h1,.locale-en .hero-copy h1 { font-size: clamp(34px,10.5vw,46px); line-height: 1.04; }
  .hero-desc { margin-top: 12px; font-size: 14px; }
  .hero-card { display: none; }
  .toolbar-section,.content-grid,.tag-section,.ranking-section,.ad-slot-section { padding-right: 16px; padding-left: 16px; }
  .toolbar-section { padding-top: 14px; }
  .search-wrap { width: 100%; max-width: none; height: 48px; }
  .mobile-category-filter,.filter-group { margin-top: 14px; }
  .secondary-filter-toggle,.creator-filter-toggle {
    display: flex; align-items: center; justify-content: space-between; width: 100%;
    min-height: var(--touch-target); margin-top: 12px; padding: 9px 13px;
    border: 1px solid var(--line); border-radius: 11px; background: var(--surface);
    color: var(--text); font: inherit; font-size: 13px; font-weight: 700; cursor: pointer;
  }
  .secondary-filter-toggle::after,.creator-filter-toggle::after {
    content: '\2304'; color: var(--acid); font-size: 18px; transition: transform .16s ease;
  }
  .secondary-filter-panel.is-open .secondary-filter-toggle::after,
  .template-filters.is-open .creator-filter-toggle::after { transform: rotate(180deg); }
  .secondary-filter-body,.template-filter-body { display: none; }
  .secondary-filter-panel.is-open .secondary-filter-body,.template-filters.is-open .template-filter-body { display: block; }
  .secondary-filter-body .toolbar-row { margin: 14px 0 0; }
  .ranking-section { padding-top: 18px; padding-bottom: 34px; }
  .ranking-head { margin-bottom: 14px; }
  .ranking-head h2 { font-size: 23px; }
  .period-tabs { overflow-x: auto; scrollbar-width: none; }
  .period-tabs::-webkit-scrollbar { display: none; }
  .period-tab { flex: 0 0 auto; min-height: var(--touch-target); }
  .modal-backdrop { align-items: end; padding: 8px 8px calc(8px + var(--safe-bottom)); }
  .modal { width: 100%; max-height: min(92dvh,calc(100dvh - 16px - var(--safe-bottom))); padding: 22px 16px calc(18px + var(--safe-bottom)); border-radius: 18px; }
  .close-modal { top: 8px; right: 8px; display: grid; place-items: center; padding: 0; }
  .modal:has(.rich-detail) { max-height: calc(100dvh - 16px - var(--safe-bottom)); padding: 10px 12px calc(12px + var(--safe-bottom)); overflow: auto; }
  .rich-detail-heading { min-height: var(--touch-target); margin-bottom: 8px; padding-right: 42px; }
  .rich-detail-heading strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .rich-detail-image { max-height: min(52dvh,calc(100dvh - 300px)); }
  .detail-media:has(.random-detail-arrow) { width: 100%; padding-bottom: 0; }
  .random-detail-arrow { top: 50%; bottom: auto; width: var(--touch-target); height: 56px; transform: translateY(-50%); background: #080a0ddd; }
  .random-detail-arrow.previous { left: 8px; }
  .random-detail-arrow.next { right: 8px; }
  .random-detail-arrow:hover:not(:disabled),.random-detail-arrow:focus-visible { transform: translateY(-50%) scale(1.04); }
  .detail-tool,.detail-share button,.primary-action,.secondary-action { min-height: var(--touch-target); }
  .creator-main { padding: 26px 16px calc(84px + var(--safe-bottom)); }
  .creator-heading h1 { font-size: clamp(36px,11vw,44px); }
  .creator-heading p { margin-top: 12px; font-size: 14px; }
  .creator-kind-tabs { margin: 22px 0 18px; }
  .creator-filter { gap: 9px; }
  .template-filters { display: block; margin-bottom: 18px; padding: 0; border: 0; background: transparent; }
  .template-filter-body { margin-top: 10px; padding: 12px; border: 1px solid var(--line); border-radius: 14px; background: #111318; }
  .filter-line + .filter-line { margin-top: 12px; }
  .template-grid { grid-template-columns: repeat(2,minmax(0,1fr)); gap: 10px; }
  .template-card-copy { padding: 12px; }
  .template-card-copy h2 { font-size: 15px; }
  .template-card-copy p { display: -webkit-box; overflow: hidden; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
  .control-panel { max-height: none; }
}

@media (max-width:420px) {
  .template-grid { grid-template-columns: 1fr; }
  .meme-grid,.ranking-grid { gap: 10px; }
  .meme-title { font-size: 13px; }
}

@media (min-width:801px) and (max-width:1500px) {
  .hero-section { grid-template-columns: minmax(0,1fr) minmax(300px,36%); gap: 42px; }
  .hero-copy h1 { font-size: clamp(46px,4.6vw,64px); }
  .creator-main { padding-right: 32px; padding-left: 32px; }
}

@media (min-width:801px) and (max-height:820px) {
  .hero-section { padding-top: 42px; padding-bottom: 36px; }
  .hero-card { height: 230px; }
  .hero-copy h1 { font-size: clamp(44px,4.4vw,60px); }
  .hero-desc { margin-top: 18px; }
}
