.mobile-menu { display: none; }

@media (max-width: 760px), (max-height: 520px) and (pointer: coarse) {
  .mobile-menu {
    --menu-edge: max(12px, env(safe-area-inset-right));
    --menu-top: max(8px, env(safe-area-inset-top));
    display: block;
    position: fixed;
    top: var(--menu-top);
    right: var(--menu-edge);
    z-index: 12;
    color: var(--paper);
  }

  .mobile-menu summary {
    display: flex;
    width: max-content;
    min-height: 48px;
    align-items: center;
    justify-content: center;
    gap: 9px;
    padding: 0 15px;
    border: 1px solid #977985;
    border-radius: 24px;
    background: #211525;
    color: var(--paper);
    font-size: .85rem;
    font-weight: 650;
    line-height: 1.25;
    box-shadow: 0 3px 14px #10081560;
    list-style: none;
    cursor: pointer;
  }
  .mobile-menu summary::-webkit-details-marker { display: none; }
  .mobile-menu summary { -webkit-tap-highlight-color: transparent; }
  /* メニューの外側をおおう幕。summary の一部なので、外をタップするとボタンを押したのと同じ扱いで閉じる。
     iOS Safari はリンクやボタン以外へのタップで click を届けないため、JavaScript の外側判定には頼らない。
     幕が背景のリンクも受け止めるので、閉じると同時にページが移動することもない。 */
  .mobile-menu[open] > summary::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -1;
    background: #0d071880;
    cursor: default;
  }
  .mobile-menu summary:focus-visible,
  .mobile-menu button:focus-visible { outline: 3px solid #ffd284; outline-offset: 2px; }

  .menu-icon { display: grid; flex: none; width: 18px; gap: 4px; }
  .menu-icon i { height: 2px; background: #ffc59d; border-radius: 2px; }
  .mobile-menu[open] .menu-icon i:first-child { transform: translateY(6px) rotate(45deg); }
  .mobile-menu[open] .menu-icon i:nth-child(2) { opacity: 0; }
  .mobile-menu[open] .menu-icon i:last-child { transform: translateY(-6px) rotate(-45deg); }

  .mobile-menu nav {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    width: min(310px, calc(100vw - var(--menu-edge) - 12px));
    max-height: calc(100vh - var(--menu-top) - 70px);
    max-height: calc(100dvh - var(--menu-top) - 70px - env(safe-area-inset-bottom));
    overflow: auto;
    overscroll-behavior: contain;
    padding: 8px;
    border: 1px solid #805e74;
    border-radius: 16px;
    background: #281a2d;
    box-shadow: 0 12px 34px #0d0718aa;
  }
  .mobile-menu nav a, .mobile-menu .menu-dismiss {
    display: flex;
    align-items: center;
    min-height: 48px;
    gap: 12px;
    padding: 8px 14px;
    border-radius: 8px;
    font-size: 1rem;
    line-height: 1.4;
    font-weight: 600;
    text-decoration: none;
    color: var(--paper);
  }
  .mobile-menu nav a::after { content: "›"; margin-left: auto; color: #dfa88d; }
  .mobile-menu nav a[aria-current="page"] { background: #482d41; color: #ffd0aa; }
  .mobile-menu nav a[aria-current="page"]::after {
    content: ""; width: 7px; height: 7px; border-radius: 50%; background: #ffb684;
  }
  .mobile-menu nav a[hreflang] { margin-top: 4px; border-top: 1px solid #63485e; border-radius: 0; }
  .mobile-menu .menu-dismiss {
    width: 100%; justify-content: center; border: 0; background: #38253c; color: #f4d5c4;
    font: inherit; font-size: .875rem; cursor: pointer;
  }
  .mobile-menu .menu-dismiss[hidden] { display: none; }
  .mobile-menu nav a:focus-visible { outline-offset: -3px; }
  .mobile-menu nav a:active, .mobile-menu .menu-dismiss:active { background: #55354b; }

  /* サイト名の帯を画面上部に留め、固定のメニューボタンをその中に収める。
     本文は帯の下を流れるので、ボタンが見出しや行末に重ならない。
     header.masthead と書くのは、後から読み込まれる記事用CSSの右余白指定より優先させるため。 */
  html { scroll-padding-top: 76px; }
  header.masthead {
    position: sticky;
    top: 0;
    z-index: 11;
    width: 100%;
    min-height: 64px;
    align-items: center;
    padding: 8px calc(133px + env(safe-area-inset-right)) 8px max(20px, env(safe-area-inset-left));
    border-bottom: 1px solid #50374d;
    background: var(--ink);
  }
  /* サイト名は語の途中で折り返さない。区切りは空白（Chrome は「・」の後でも区切る。Safari は区切らない）。
     320px幅でも「裏技・攻略まとめサイト」が1行に収まるよう、狭い画面では文字を少し小さくする。
     それでも入りきらない幅では文字単位で折り返す。 */
  .masthead > a:first-child {
    display: flex;
    align-items: center;
    min-height: 48px;
    font-size: clamp(.8rem, 4.4vw, .95rem);
    line-height: 1.35;
    word-break: keep-all;
    overflow-wrap: anywhere;
  }
  /* トップページには帯がないので、ボタンはページと一緒に流す（カテゴリの矢印に重ねない）。
     開いている間だけ画面に固定し、メニューが画面外へ流れないようにする。 */
  .mobile-menu:has(+ .hero) { position: absolute; }
  .mobile-menu[open]:has(+ .hero) { position: fixed; }
  .masthead .language-switch, .category-nav, .home-directory > .guide-language { display: none; }

  .home-directory { padding-block: 16px 26px; }
  .directory { display: grid; gap: 8px; }
  .directory a {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 3px 14px;
    min-height: 64px;
    padding: 12px 14px;
    color: var(--paper);
    border: 1px solid #64495e;
    border-radius: 12px;
    background: linear-gradient(110deg, #312034, #231829);
  }
  .directory span { font-size: 1.13rem; line-height: 1.4; }
  .directory small { grid-column: 1; font-size: .85rem; line-height: 1.5; }
  .directory a::after {
    content: "→";
    display: grid;
    grid-column: 2;
    grid-row: 1 / 3;
    place-items: center;
    align-self: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    color: #ffcea9;
    background: #503448;
    font: 500 1rem/1 system-ui, sans-serif;
  }
  .directory a:active { background: #482d41; border-color: #e6a889; }
}

/* 高さの低い画面（横向きのスマホ、200%拡大のPC）と極端に狭い画面では、帯を留めると読む場所が足りなくなる。
   帯もボタンもページと一緒に流し、開いている間だけボタンを固定する。 */
@media (max-width: 760px) and (max-height: 520px), (max-height: 520px) and (pointer: coarse), (max-width: 299px) {
  html { scroll-padding-top: 0; }
  header.masthead { position: static; }
  .mobile-menu { position: absolute; }
  .mobile-menu[open] { position: fixed; }
}

/* 極端に狭い画面（スマホの200%拡大など）では「メニュー」の文字をたたみ、サイト名の幅を確保する。読み上げ用の名前は残る。 */
@media (max-width: 299px) {
  .mobile-menu summary { width: 48px; justify-content: flex-start; gap: 14px; padding: 0 14px; overflow: hidden; font-size: 0; white-space: nowrap; }
  header.masthead { padding-right: calc(68px + env(safe-area-inset-right)); }
  .masthead > a:first-child { font-size: .8rem; }
}
