/* FoundSchool 2.0 — native-like mobile layer */
:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --mobile-header-h: 58px;
  --mobile-tabbar-h: 62px;
}

@media (max-width: 768px) {
  html { scroll-padding-top: calc(var(--mobile-header-h) + var(--safe-top) + 10px); }
  body {
    padding-bottom: calc(var(--mobile-tabbar-h) + var(--safe-bottom));
    overscroll-behavior-y: contain;
    -webkit-tap-highlight-color: transparent;
  }
  .container { width: min(100% - 28px, var(--container)); }

  .app-header {
    height: calc(var(--mobile-header-h) + var(--safe-top));
    padding-top: var(--safe-top);
    background: rgba(255,255,255,.94);
  }
  [data-theme="dark"] .app-header { background: rgba(16,23,34,.94); }
  .app-header__inner { width: 100%; padding-inline: 14px; gap: 8px; }
  .brand-mark { width: 34px; height: 34px; border-radius: 11px; }
  .brand-mark span { font-size: 12px; }
  .brand-copy strong { font-size: 14px; }
  .brand-copy small, .desktop-nav, .desktop-signin, .language-picker { display: none; }
  .header-search {
    order: 2; width: auto; flex: 1; min-width: 0; min-height: 36px; margin-inline-start: 2px;
    padding-inline: 11px; border-radius: 13px; box-shadow: none; font-size: 12px;
  }
  .header-search kbd { display: none; }
  .header-search svg { width: 17px; height: 17px; }
  .header-actions { order: 3; }
  .header-actions .icon-button { width: 36px; min-width: 36px; height: 36px; border: 0; background: var(--surface-2); }
  .account-button { width: 36px; min-width: 36px; height: 36px; }

  .home-hero { padding: 36px 0 32px; }
  .hero-grid { display: block; }
  .hero-copy { text-align: start; }
  .eyebrow { font-size: 10px; }
  .hero-copy h1 { margin: 13px 0 13px; font-size: clamp(34px, 10.4vw, 46px); line-height: 1.08; letter-spacing: -.052em; }
  .hero-copy > p { font-size: 14px; line-height: 1.72; }
  .hero-search { min-height: 54px; margin-top: 23px; border-radius: 17px; box-shadow: var(--shadow-1); font-size: 13px; }
  .hero-search kbd { display: none; }
  .hero-metrics { justify-content: space-between; gap: 10px; margin-top: 20px; padding: 14px 4px 0; border-top: 1px solid var(--line); }
  .hero-metrics div { flex-direction: column; align-items: center; gap: 0; flex: 1; }
  .hero-metrics strong { font-size: 18px; }
  .hero-metrics span { font-size: 10px; }
  .hero-workspace { display: none; }

  .trust-strip { border-top: 0; }
  .trust-grid { display: flex; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none; padding: 12px 14px; gap: 9px; }
  .trust-grid::-webkit-scrollbar { display: none; }
  .trust-grid article {
    flex: 0 0 82%; min-width: 0; padding: 14px; border: 1px solid var(--line) !important;
    border-radius: 16px; background: var(--surface); scroll-snap-align: start;
  }
  .feature-icon { width: 40px; height: 40px; border-radius: 12px; }
  .feature-icon svg { width: 20px; height: 20px; }
  .trust-grid h2 { font-size: 13px; }
  .trust-grid p { font-size: 10px; }

  .home-section { padding-block: 44px; }
  .section-heading { align-items: end; margin-bottom: 18px; }
  .section-heading h2 { margin-top: 4px; font-size: 27px; }
  .section-heading > a { font-size: 12px; }
  .section-kicker { font-size: 10px; }
  .popular-grid { grid-template-columns: repeat(2, minmax(0,1fr)); gap: 10px; }
  .popular-card { min-height: 176px; padding: 15px; border-radius: 17px; box-shadow: none; }
  .popular-card:hover { transform: none; box-shadow: none; }
  .tool-icon { width: 40px; height: 40px; border-radius: 12px; font-size: 10px; }
  .popular-card h3 { margin-top: 13px; font-size: 13px; }
  .popular-card p { display: -webkit-box; overflow: hidden; -webkit-box-orient: vertical; -webkit-line-clamp: 3; font-size: 10px; }
  .card-arrow { inset-inline-end: 13px; bottom: 11px; font-size: 17px; }

  .tools-directory { padding: 44px 0 50px; }
  .category-chips { margin-inline: -14px; padding-inline: 14px; margin-bottom: 17px; }
  .category-chip { padding: 8px 13px; font-size: 11px; }
  .directory-grid { grid-template-columns: 1fr; gap: 8px; }
  .directory-card { min-height: 84px; padding: 12px; border-radius: 15px; box-shadow: none; }
  .directory-card .tool-icon { width: 42px; height: 42px; }
  .directory-card h3 { font-size: 13px; }
  .directory-card p { -webkit-line-clamp: 1; font-size: 10px; }
  .directory-card > svg { width: 16px; height: 16px; }

  .seo-section { display: block; padding-block: 47px; }
  .seo-copy h2 { font-size: 29px; }
  .seo-copy p { font-size: 14px; }
  .compact-faq { margin-top: 30px; }
  .compact-faq summary { padding: 15px; font-size: 13px; }
  .compact-faq details p { padding: 0 15px 15px; font-size: 12px; }

  /* Tool page becomes a full-screen app workspace */
  .tool-shell { min-height: calc(100vh - var(--mobile-header-h)); }
  .tool-shell__top { height: 0; }
  .breadcrumb { display: none; }
  .mobile-back {
    position: fixed; top: calc(var(--safe-top) + 11px); inset-inline-start: 12px; z-index: 900;
    display: grid; place-items: center; width: 36px; height: 36px; border-radius: 12px;
    background: var(--surface-2); color: var(--ink); font-size: 20px;
  }
  body[data-tool]:not([data-tool=""]) .app-header .brand { visibility: hidden; width: 34px; }

  .tool-intro { padding: 18px 0 16px; }
  .tool-intro__inner { gap: 12px; align-items: start; }
  .tool-title-icon { width: 52px; height: 52px; border-radius: 16px; font-size: 10px; }
  .tool-meta-row { margin-bottom: 3px; font-size: 9px; }
  .privacy-badge { display: none; }
  .tool-intro h1 { font-size: 23px; letter-spacing: -.032em; }
  .tool-intro p { margin-top: 5px; font-size: 12px; line-height: 1.55; }

  .tool-layout { width: 100%; display: block; padding: 10px 0 28px; }
  .tool-workspace { display: flex; flex-direction: column; gap: 0; }
  .workspace-panel { border-inline: 0; border-radius: 0; box-shadow: none; }
  .workspace-panel__header { min-height: 50px; padding: 8px 14px; }
  .workspace-panel__header h2 { font-size: 13px; }
  .panel-step { width: 23px; height: 23px; border-radius: 7px; }
  .text-button, .icon-text-button { min-height: 32px; padding-inline: 8px; font-size: 11px; }
  .workspace-textarea { min-height: 190px; padding: 15px 14px; resize: none; font-size: 16px; line-height: 1.65; }
  .secondary-textarea { min-height: 155px; }
  .secondary-input-wrap > label { padding-inline: 14px; }
  .option-grid { padding: 11px 14px; }
  .option-grid.two-cols { grid-template-columns: 1fr; }
  .option-grid input, .option-grid select { height: 44px; font-size: 16px; }
  .live-stats { overflow-x: auto; grid-template-columns: repeat(4, minmax(85px, 1fr)); scrollbar-width: none; }
  .live-stats::-webkit-scrollbar { display: none; }
  .live-stats div { min-width: 85px; padding: 9px 6px; }
  .live-stats strong { font-size: 13px; }
  .live-stats span { font-size: 9px; }

  .tool-actionbar {
    position: sticky; bottom: calc(var(--mobile-tabbar-h) + var(--safe-bottom)); z-index: 120;
    display: grid; grid-template-columns: repeat(auto-fit, minmax(130px,1fr)); gap: 8px;
    padding: 10px 14px; border-block: 1px solid var(--line); background: rgba(255,255,255,.94); backdrop-filter: blur(16px);
  }
  [data-theme="dark"] .tool-actionbar { background: rgba(16,23,34,.94); }
  .primary-action { width: 100%; min-width: 0; min-height: 46px; padding-inline: 12px; border-radius: 13px; font-size: 12px; box-shadow: none; }
  .primary-action svg { width: 16px; height: 16px; }
  .output-panel { margin-top: 10px; border-top: 1px solid var(--line); }
  .output-panel .workspace-panel__header { align-items: flex-start; flex-direction: column; gap: 5px; }
  .output-panel .panel-actions { width: 100%; justify-content: space-between; }
  .output-textarea { min-height: 190px; }
  .result-status { font-size: 10px; }
  .tool-sidebar { display: none; }
  .tool-content { display: block; width: 100%; padding: 0 0 26px; }
  .content-card { margin-top: 8px; padding: 19px 14px; border-inline: 0; border-radius: 0; }
  .content-card h2 { font-size: 18px; }
  .content-card p { font-size: 13px; }
  .related-section { padding: 28px 14px 0; }
  .related-grid { grid-template-columns: 1fr; }

  /* Legacy pages */
  .tool-hero { padding: 26px 0 20px; }
  .tool-hero h1 { font-size: 28px; }
  .tool-hero p { font-size: 13px; }
  .tool-page { padding: 20px 0 40px; }
  .tools-grid { grid-template-columns: 1fr; }
  .card { padding: 16px; border-radius: 15px; }
  .btn { min-height: 44px; }

  /* Native bottom navigation */
  .site-footer { display: none; }
  .mobile-tabbar {
    position: fixed; inset-inline: 0; bottom: 0; z-index: 1000;
    display: grid; grid-template-columns: repeat(4, 1fr);
    height: calc(var(--mobile-tabbar-h) + var(--safe-bottom));
    padding: 4px 6px var(--safe-bottom); border-top: 1px solid var(--line);
    background: rgba(255,255,255,.96); backdrop-filter: blur(18px) saturate(160%);
    box-shadow: 0 -8px 24px rgba(20,35,60,.07);
  }
  [data-theme="dark"] .mobile-tabbar { background: rgba(16,23,34,.96); }
  .tabbar-item {
    position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    border: 0; border-radius: 12px; color: var(--ink-faint); background: transparent; font-size: 9px; font-weight: 750; cursor: pointer;
  }
  .tabbar-item svg { width: 22px; height: 22px; }
  .tabbar-item.is-active { color: var(--primary); }
  .tabbar-item.is-active::before { content: ""; position: absolute; top: 0; width: 22px; height: 3px; border-radius: 0 0 4px 4px; background: var(--primary); }
  .tabbar-item:active { background: var(--primary-soft); }

  /* Bottom sheets */
  .sheet-backdrop {
    position: fixed; inset: 0; z-index: 1400; display: block;
    opacity: 0; background: rgba(8, 15, 28, .52); backdrop-filter: blur(2px); transition: opacity .24s ease;
  }
  .sheet-backdrop.is-open { opacity: 1; }
  .app-sheet {
    position: fixed; inset-inline: 0; bottom: 0; z-index: 1500; display: block;
    max-height: min(86vh, 760px); overflow: hidden; transform: translateY(105%);
    border-radius: 24px 24px 0 0; background: var(--surface); box-shadow: var(--shadow-3);
    padding-bottom: var(--safe-bottom); transition: transform .28s cubic-bezier(.2,.8,.2,1);
  }
  .app-sheet.is-open { transform: translateY(0); }
  .sheet-handle { width: 38px; height: 4px; margin: 9px auto 6px; border-radius: 999px; background: var(--line-strong); }
  .sheet-header, .sheet-title-row { display: flex; align-items: center; gap: 9px; padding: 8px 14px 12px; border-bottom: 1px solid var(--line); }
  .sheet-title-row { justify-content: space-between; }
  .sheet-title-row h2 { margin: 0; font-size: 18px; }
  .sheet-search-field { display: flex; align-items: center; gap: 9px; flex: 1; height: 46px; padding: 0 12px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface-2); }
  .sheet-search-field svg { width: 19px; height: 19px; color: var(--ink-faint); }
  .sheet-search-field input { width: 100%; border: 0; outline: 0; background: transparent; font-size: 16px; }
  .sheet-close { display: grid; place-items: center; flex: 0 0 auto; width: 40px; height: 40px; border: 0; border-radius: 12px; background: var(--surface-2); cursor: pointer; font-size: 24px; }
  .search-results { max-height: calc(86vh - 90px); overflow-y: auto; padding: 8px 12px 18px; }
  .search-result-item { display: grid; grid-template-columns: auto minmax(0,1fr) auto; align-items: center; gap: 11px; min-height: 68px; padding: 9px; border-bottom: 1px solid var(--line); }
  .search-result-item:last-child { border-bottom: 0; }
  .search-result-item .tool-icon { width: 40px; height: 40px; }
  .search-result-item strong { display: block; font-size: 13px; }
  .search-result-item small { display: block; overflow: hidden; color: var(--ink-faint); font-size: 10px; white-space: nowrap; text-overflow: ellipsis; }
  .search-result-item > svg { width: 16px; height: 16px; color: var(--ink-faint); }
  .search-empty { padding: 44px 18px; text-align: center; color: var(--ink-faint); }

  .more-sheet { max-height: 76vh; overflow-y: auto; }
  .more-grid { display: grid; grid-template-columns: repeat(2,1fr); gap: 10px; padding: 14px; }
  .more-grid a, .more-grid button { display: flex; align-items: center; gap: 11px; min-height: 58px; padding: 12px; border: 1px solid var(--line); border-radius: 15px; background: var(--surface-2); cursor: pointer; font-size: 12px; font-weight: 750; }
  .more-grid svg { width: 22px; height: 22px; color: var(--primary); }
  .sheet-languages { display: grid; grid-template-columns: repeat(2,1fr); gap: 7px; padding: 0 14px 18px; }
  .sheet-languages a { padding: 10px; border: 1px solid var(--line); border-radius: 12px; color: var(--ink-soft); font-size: 11px; }
  .sheet-languages a.is-current { color: var(--primary); border-color: var(--primary); background: var(--primary-soft); }

  .toast { bottom: calc(var(--mobile-tabbar-h) + var(--safe-bottom) + 14px); max-width: calc(100vw - 32px); white-space: nowrap; }
  .network-status { bottom: calc(var(--mobile-tabbar-h) + var(--safe-bottom) + 14px); }
}

@media (max-width: 380px) {
  .popular-grid { grid-template-columns: 1fr; }
  .popular-card { min-height: 145px; }
  .hero-copy h1 { font-size: 32px; }
  .tool-actionbar { grid-template-columns: 1fr; }
  .live-stats { grid-template-columns: repeat(4, 82px); }
}

@media (max-width: 768px) and (orientation: landscape) {
  :root { --mobile-tabbar-h: 52px; }
  .workspace-textarea { min-height: 125px; }
  .tool-intro { padding-block: 10px; }
  .app-sheet { max-height: 94vh; }
}

@media (max-width: 768px) {
  .category-quick-tools {
    margin: 8px 10px 2px;
    padding: 11px 10px 10px;
    border-radius: 16px;
    box-shadow: 0 5px 16px rgba(30,52,82,.045);
  }
  .quick-tools__heading { display: block; margin-bottom: 9px; }
  .quick-tools__title-row { gap: 8px; }
  .quick-tools__spark { width: 30px; height: 30px; border-radius: 9px; }
  .quick-tools__spark svg { width: 16px; height: 16px; }
  .quick-tools__heading h2 { font-size: 12.5px; }
  .quick-tools__eyebrow { font-size: 8px; }
  .quick-tools__heading p { max-width: none; margin-top: 5px; padding-inline-start: 38px; font-size: 9.5px; line-height: 1.45; text-align: start; }
  .quick-tools__category { margin-inline-start: auto; padding: 4px 7px; font-size: 8px; }
  .quick-tools__rail {
    width: calc(100% + 10px);
    gap: 7px;
    margin-inline-end: -10px;
    padding-inline-end: 10px;
    padding-bottom: 3px;
    scroll-snap-type: x mandatory;
    scrollbar-width: none;
    overscroll-behavior-inline: contain;
    -webkit-overflow-scrolling: touch;
  }
  .quick-tools__rail::-webkit-scrollbar { display: none; }
  .quick-tool-chip {
    flex: 0 0 clamp(155px, 48vw, 190px);
    min-height: 50px;
    padding: 7px 8px;
    border-radius: 12px;
    box-shadow: none;
  }
  .quick-tool-chip__icon { width: 32px; height: 32px; border-radius: 9px; font-size: 8px; }
  .quick-tool-chip__copy strong { font-size: 10.5px; }
  .quick-tool-chip__copy small { font-size: 8px; }
  .quick-tool-chip__arrow { width: 14px; height: 14px; }

  .tool-page .category-quick-tools { margin-inline: 0; }
}

@media (max-width: 768px) {
  /* AI workspaces use an inline desktop grid; stack them so the quick tools stay full-width on phones. */
  .tool-page > .container > div[style*="grid-template-columns:1fr 1fr"] {
    grid-template-columns: minmax(0, 1fr) !important;
  }
}
