/*
  Mobile layout hardening.
  Loaded after the desktop/home styles so small screens always receive
  a self-contained, width-safe layout.
*/

@media (max-width: 820px) {
  html {
    width: 100%;
    max-width: 100%;
    overflow-x: clip;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
  }

  body.home-page {
    width: 100%;
    max-width: 100%;
    overflow-x: clip;
  }

  .home-page .landing-main {
    width: 100%;
    max-width: 100%;
    overflow-x: clip;
  }

  .home-header,
  .home-footer {
    width: 100%;
    max-width: 100%;
  }

  .home-nav {
    width: calc(100% - 2rem);
    min-height: 56px;
    padding: 0.8rem 0;
  }

  /* TOP: desktopの固定高さ・絶対配置・移動量を完全に解除する。 */
  .hero-home {
    width: 100%;
    height: auto;
    min-height: 0;
    margin: 0;
    padding: 2.3rem 1.25rem 0;
    overflow: hidden;
  }

  .hero-copy {
    position: relative;
    top: auto;
    left: auto;
    width: 100%;
    max-width: none;
    min-width: 0;
    padding: 0;
    transform: none;
  }

  .hero-copy h1 {
    width: 100%;
    max-width: 100%;
    margin: 0;
    font-size: clamp(2.25rem, 10.5vw, 2.85rem);
    line-height: 1.22;
    letter-spacing: 0.02em;
  }

  .hero-copy h1 span,
  .hero-copy h1 span:nth-child(2) {
    display: block;
    width: max-content;
    max-width: 100%;
    white-space: nowrap;
    transform: none;
  }

  .hero-copy h1 span:nth-child(2) {
    margin-left: 0.78em;
  }

  .hero-code-image {
    position: relative;
    inset: auto;
    width: calc(100% + 2.5rem);
    max-width: none;
    aspect-ratio: 1045 / 941;
    margin: 2.1rem -1.25rem 0;
    overflow: hidden;
  }

  .hero-code-slices {
    width: 100%;
  }

  /* 各段が画面幅を超えない共通寸法。 */
  .minimal-section {
    width: calc(100% - 2.5rem);
    max-width: 680px;
    min-width: 0;
  }

  .minimal-section h2 {
    max-width: 100%;
    font-size: clamp(1.95rem, 8.4vw, 2.5rem);
  }

  .fixed-two-line-title span {
    display: block;
    max-width: 100%;
    white-space: nowrap;
  }

  /* Serviceは画像と文字を重ねたまま、見出しが切れない寸法にする。 */
  .service-section {
    min-height: clamp(545px, 142vw, 650px);
    padding-top: 2.55rem;
    padding-bottom: 2.65rem;
  }

  .service-section .section-copy {
    width: 100%;
    max-width: none;
    min-width: 0;
  }

  .service-section h2 {
    max-width: 100%;
    margin-left: 0;
    padding: 0.68rem 0.72rem 0.84rem;
    font-size: clamp(1.95rem, 8.5vw, 2.4rem);
    line-height: 1.2;
  }

  .service-section .section-text {
    max-width: 88%;
    margin-left: 0;
    padding: 0.72rem 0.78rem 0.82rem;
    font-size: 0.96rem;
    line-height: 1.92;
  }

  .service-visual {
    top: 7.8rem;
    right: -28%;
    width: 170%;
  }

  .software-grid,
  .software-card,
  .transition-section > div {
    min-width: 0;
    max-width: 100%;
  }

  /* 下部メニューは横スクロールではなく、5項目を画面内に均等配置する。 */
  .home-page .section-nav {
    left: 0.5rem;
    right: 0.5rem;
    bottom: 0.5rem;
    width: auto;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 0.1rem;
    padding: 0.32rem;
    overflow: visible;
    border-radius: 16px;
  }

  .home-page .section-nav a {
    width: 100%;
    min-width: 0;
    height: 38px;
    padding: 0 0.15rem;
    font-size: 0.62rem;
    letter-spacing: 0.01em;
  }

  .home-page .section-nav .menu-en {
    display: none;
  }

  .home-page .section-nav .menu-ja {
    position: static;
    opacity: 1;
    transform: none;
    font-size: 0.62rem;
    letter-spacing: 0.01em;
  }
}

@media (max-width: 420px) {
  .home-nav {
    width: calc(100% - 1.5rem);
  }

  .hero-home {
    padding: 2rem 1rem 0;
  }

  .hero-copy h1 {
    font-size: clamp(2.15rem, 10.2vw, 2.55rem);
  }

  .hero-copy h1 span:nth-child(2) {
    margin-left: 0.68em;
  }

  .hero-code-image {
    width: calc(100% + 2rem);
    margin: 1.9rem -1rem 0;
  }

  .minimal-section {
    width: calc(100% - 2rem);
  }

  .minimal-section h2 {
    font-size: clamp(1.82rem, 8.2vw, 2.15rem);
  }

  .service-section {
    min-height: 540px;
    padding-top: 2.35rem;
  }

  .service-section h2 {
    font-size: clamp(1.82rem, 8.2vw, 2.15rem);
  }

  .service-section .section-text {
    max-width: 92%;
    font-size: 0.92rem;
  }

  .service-visual {
    top: 7.25rem;
    right: -31%;
    width: 174%;
  }

  .home-page .section-nav a,
  .home-page .section-nav .menu-ja {
    font-size: 0.58rem;
  }
}
