/* ===== Global H5 / mobile foundation ===== */
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  overflow-x: hidden;
  -webkit-tap-highlight-color: rgba(13, 110, 99, 0.12);
  padding-bottom: env(safe-area-inset-bottom, 0);
}

img,
svg,
video {
  max-width: 100%;
  height: auto;
}

a,
button,
input,
textarea,
select,
label {
  touch-action: manipulation;
}

/* Prevent iOS input zoom */
.field input[type="text"],
.field input[type="number"],
.field input[type="password"],
.field input[type="email"],
.field input[type="search"],
.field textarea,
.field select,
.unit-table input,
.tool-tdk-card input,
.tool-tdk-card textarea,
.login-card input,
.card input[type="text"],
.card input[type="password"],
.card input[type="number"],
.card textarea {
  font-size: 16px !important;
}

.nav-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(18, 32, 28, 0.42);
  backdrop-filter: blur(2px);
}

body.nav-open {
  overflow: hidden;
}

body.nav-open .nav-backdrop {
  display: block;
}

/* ===== Mobile layout (<=860px) ===== */
@media (max-width: 860px) {
  .page {
    width: min(100%, calc(100% - 1.2rem));
    padding: 1.1rem 0 calc(2.2rem + env(safe-area-inset-bottom, 0px));
  }

  .site-header {
    padding-top: env(safe-area-inset-top, 0);
  }

  .site-header-inner {
    width: min(100%, calc(100% - 1rem));
    min-height: 52px;
  }

  .site-logo-text {
    max-width: 42vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.92rem;
  }

  .nav-toggle {
    width: 44px;
    height: 44px;
  }

  /* Full-screen style drawer menu */
  .site-nav {
    position: fixed !important;
    left: 0 !important;
    right: 0 !important;
    top: auto !important;
    bottom: 0 !important;
    z-index: 60;
    max-height: min(78vh, 640px);
    overflow: auto;
    padding: 0.75rem 0.75rem calc(0.9rem + env(safe-area-inset-bottom, 0px)) !important;
    border-radius: 18px 18px 0 0 !important;
    border: 1px solid rgba(21, 36, 31, 0.12);
    background: rgba(247, 250, 248, 0.98) !important;
    box-shadow: 0 -16px 40px rgba(21, 36, 31, 0.18) !important;
    transform: translateY(110%);
    transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
    display: flex !important;
    pointer-events: none;
    visibility: hidden;
  }

  .site-header.is-open .site-nav {
    transform: translateY(0);
    pointer-events: auto;
    visibility: visible;
  }

  .site-nav-link,
  .nav-drop-btn {
    min-height: 44px;
    display: flex;
    align-items: center;
    font-size: 0.95rem;
  }

  .brand {
    font-size: clamp(2.4rem, 14vw, 3.4rem);
  }

  .hero {
    margin-bottom: 1.15rem;
  }

  .hero h1 {
    font-size: clamp(1.45rem, 6.5vw, 1.9rem);
  }

  .lede {
    font-size: 0.95rem;
  }

  .tool-card,
  .stage,
  .controls {
    border-radius: 16px;
    padding: 0.95rem;
  }

  .stage {
    min-height: 280px;
  }

  .drop {
    min-height: 200px;
    padding: 1.1rem;
  }

  .drop-title {
    font-size: 1.2rem;
  }

  .btn,
  .btn-main,
  .btn-soft,
  .btn-primary {
    min-height: 46px;
    width: 100%;
  }

  .row-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .row-actions .btn,
  .row-actions a.btn {
    width: 100%;
  }

  .check-grid {
    grid-template-columns: 1fr;
  }

  .check-item {
    min-height: 44px;
  }

  .sizes {
    grid-template-columns: repeat(3, 1fr);
  }

  .preview-sizes {
    gap: 0.5rem;
  }

  .unit-table th,
  .unit-table td {
    display: block;
    width: 100%;
    padding: 0.35rem 0;
    border: 0;
  }

  .unit-table tr {
    display: block;
    padding: 0.7rem 0;
    border-bottom: 1px solid rgba(21, 36, 31, 0.08);
  }

  .unit-table thead {
    display: none;
  }

  .unit-table th {
    color: #5a6d66;
    font-size: 0.82rem;
    padding-bottom: 0.2rem;
  }

  .hub-card {
    min-height: 112px;
    padding: 1rem;
  }

  .hub-card-icon {
    width: 2.35rem;
    height: 2.35rem;
  }

  .hub-title {
    font-size: 1.2rem;
  }

  .home-banner {
    padding-left: 1rem;
    padding-right: 1rem;
  }

  .home-stats {
    grid-template-columns: repeat(3, 1fr);
  }

  .fits {
    gap: 0.5rem;
  }

  .fit {
    min-height: 64px;
  }

  .result-box {
    font-size: 0.9rem;
  }

  .foot {
    font-size: 0.8rem;
    padding-bottom: 0.5rem;
  }

  .site-footer-meta {
    width: 100%;
  }

  /* ── Homepage H5 ── */
  .page-home {
    width: min(100%, calc(100% - 1.2rem));
    padding-top: 0.25rem;
  }

  .home-banner {
    width: 100vw;
    margin-left: calc(50% - 50vw);
    margin-bottom: 1.5rem;
    padding: clamp(2rem, 8vw, 2.75rem) 1rem clamp(2rem, 6vw, 2.5rem);
  }

  .home-banner-inner {
    width: min(100%, calc(100% - 0.5rem));
  }

  .home-badge {
    font-size: 0.72rem;
    margin-bottom: 0.75rem;
  }

  .home-title {
    font-size: clamp(1.85rem, 8.5vw, 2.6rem);
    max-width: none;
    margin-bottom: 0.65rem;
  }

  .home-lede {
    font-size: 0.92rem;
    line-height: 1.6;
    margin-bottom: 1.25rem;
  }

  .home-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.45rem;
    margin-bottom: 1.25rem;
  }

  .home-stat {
    min-width: 0;
    padding: 0.65rem 0.5rem;
    text-align: center;
    border-radius: 14px;
  }

  .home-stat strong {
    font-size: 1.25rem;
  }

  .home-stat span {
    font-size: 0.68rem;
  }

  .home-quick-label {
    font-size: 0.75rem;
  }

  .home-quick-links {
    gap: 0.4rem;
  }

  .home-quick-link {
    min-height: 36px;
    font-size: 0.8rem;
    padding: 0.4rem 0.75rem;
  }

  .hub-head {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.2rem;
    margin-bottom: 0.75rem;
  }

  .hub-grid {
    grid-template-columns: 1fr;
    gap: 0.65rem;
  }

  .hub-card {
    min-height: 96px;
    padding: 0.9rem;
    border-radius: 14px;
    -webkit-tap-highlight-color: transparent;
  }

  .hub-card:active {
    transform: scale(0.985);
  }

  .hub-card-arrow {
    display: none;
  }

  /* ── Footer H5 accordion ── */
  .site-footer {
    margin-top: 1.5rem;
    padding: 2rem 1rem calc(1.25rem + env(safe-area-inset-bottom, 0px));
  }

  .site-footer-inner {
    width: min(100%, calc(100% - 0.5rem));
  }

  .site-footer-top {
    grid-template-columns: 1fr;
    gap: 0;
    padding-bottom: 0.5rem;
    border-bottom: 0;
  }

  .site-footer-brand {
    padding-bottom: 1.25rem;
    margin-bottom: 0.25rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  }

  .site-footer-desc {
    font-size: 0.84rem;
  }

  .site-footer-col {
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  }

  .site-footer-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 48px;
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
  }

  .site-footer-heading::after {
    content: "+";
    font-size: 1.1rem;
    font-weight: 400;
    color: rgba(244, 255, 252, 0.45);
    transition: transform 0.2s ease;
  }

  .site-footer-col.is-open .site-footer-heading::after {
    content: "−";
  }

  .site-footer-links {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.28s cubic-bezier(0.22, 1, 0.36, 1);
  }

  .site-footer-col.is-open .site-footer-links {
    max-height: 480px;
    padding-bottom: 0.85rem;
  }

  .site-footer-links a {
    display: block;
    min-height: 40px;
    line-height: 40px;
    font-size: 0.88rem;
  }

  .site-footer-bottom {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
    flex-direction: column;
    align-items: flex-start;
    gap: 0.65rem;
  }

  .site-footer-copy {
    font-size: 0.78rem;
    line-height: 1.5;
  }

  .site-footer-meta {
    gap: 0.5rem 0.85rem;
  }

  .site-footer-meta a {
    min-height: 36px;
    display: inline-flex;
    align-items: center;
  }

  .site-footer-note {
    border-right: 0;
    padding-right: 0;
    width: 100%;
    font-size: 0.78rem;
    line-height: 1.45;
  }

  /* ── H5 bottom tab bar ── */
  body.has-h5-tabbar {
    padding-bottom: calc(58px + env(safe-area-inset-bottom, 0px));
  }

  .h5-tabbar {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 55;
    min-height: calc(54px + env(safe-area-inset-bottom, 0px));
    padding: 0.35rem 0.25rem env(safe-area-inset-bottom, 0px);
    border-top: 1px solid rgba(21, 36, 31, 0.1);
    background: rgba(247, 250, 248, 0.94);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    box-shadow: 0 -8px 24px rgba(21, 36, 31, 0.08);
  }

  .h5-tabbar-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.15rem;
    min-height: 48px;
    padding: 0.2rem 0.15rem;
    text-decoration: none;
    color: #5a6d66;
    border-radius: 10px;
    transition: color 0.15s ease, background 0.15s ease;
    -webkit-tap-highlight-color: transparent;
  }

  .h5-tabbar-item.is-active {
    color: #0a544c;
    background: rgba(13, 110, 99, 0.1);
  }

  .h5-tabbar-item:active {
    transform: scale(0.96);
  }

  .h5-tabbar-icon {
    font-size: 1.05rem;
    line-height: 1;
  }

  .h5-tabbar-label {
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.02em;
  }

  /* ── Back to top FAB ── */
  .h5-fab {
    display: grid;
    place-items: center;
    position: fixed;
    right: 1rem;
    bottom: calc(68px + env(safe-area-inset-bottom, 0px));
    z-index: 54;
    width: 44px;
    height: 44px;
    border: 1px solid rgba(13, 110, 99, 0.22);
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.92);
    color: #0a544c;
    font-size: 1.1rem;
    font-weight: 700;
    box-shadow: 0 8px 24px rgba(21, 36, 31, 0.14);
    cursor: pointer;
    transition: transform 0.2s ease, opacity 0.2s ease;
    -webkit-tap-highlight-color: transparent;
  }

  .h5-fab:active {
    transform: scale(0.92);
  }

  .support-widget {
    right: 0.85rem;
    bottom: calc(68px + env(safe-area-inset-bottom, 0px));
  }

  .support-panel {
    right: 0;
    left: auto;
    width: min(320px, calc(100vw - 1.7rem));
    max-height: min(70vh, 520px);
    overflow: auto;
  }

  .support-fab {
    min-height: 46px;
    padding: 0.5rem 0.85rem 0.5rem 0.72rem;
  }

  .support-fab-label {
    font-size: 0.82rem;
  }
}

/* Desktop: hide H5-only chrome */
@media (min-width: 861px) {
  .h5-tabbar,
  .h5-fab {
    display: none !important;
  }

  .site-footer-col .site-footer-links {
    max-height: none !important;
    overflow: visible;
    padding-bottom: 0 !important;
  }

  .site-footer-heading::after {
    display: none;
  }

  .site-footer-heading {
    cursor: default;
  }
}

/* Ultra small phones */
@media (max-width: 380px) {
  .sizes {
    grid-template-columns: repeat(2, 1fr);
  }

  .site-logo-mark {
    display: none;
  }
}

/* Landscape phones */
@media (max-width: 900px) and (orientation: landscape) {
  .site-nav {
    max-height: 70vh;
  }

  .brand {
    font-size: 2.1rem;
  }
}
