/* ===================- タブレット用（768px以上）======================== */
@media screen and (min-width: 768px) {
  :root {
    --gap: 8px;
    --topbar-height: 55px;
    --subnav-height: 44px;
    --header-height: var(--topbar-height);
    --sidebar-width: 320px;
  }

  h1 {
    font-size: 28px;
  }

  /* タブレット以上では従来の検索フォームとテキストボタンを表示 */
  .topbar-center {
    display: flex;
  }
  .topbar-nav {
    display: flex;
  }
  /* アイコン系は非表示 */
  .topbar-icon-btn {
    display: none;
  }
  .mobile-search-overlay {
    display: none;
  }

  /* サイドバーの横幅調整 */
  .sidebar {
    width: var(--sidebar-width);
  }

  /* フッターの「カテゴリー」を中央に表示 */
  .footer-categories h3 {
    text-align: center;
  }
  /* フッターに３×３グリッドリンク表示 */
  .footer-category-links {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 12px 120px;
    max-width: 500px;
    margin: 0 auto;
  }
  .footer-category-item a {
    border-bottom: none;
    padding: 2px 0;
  }
}

/* ======================= PC用（1024px以上）======================== */
@media screen and (min-width: 1024px) {
  :root {
    --gap: 12px;
    --topbar-height: 60px;
    --mega-nav-height: 56px;
    --subnav-height: 56px;
    --header-height: calc(var(--topbar-height) + var(--mega-nav-height));
    --sidebar-width: 250px;
    --sidebar-rail-width: 60px;
  }
  h1 {
    font-size: 32px;
  }
  .breadcrumbs {
    font-size: 14px;
    padding: 8px var(--gap);
  }

  /* マイページボタンは、PCでは非表示 */
  .topbar-nav-btn-mypage {
    display: none;
  }

  /* ヘッダーに「ようこそ〇〇さん」を表示 */
  .topbar-welcome {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #000000;
    font-size: 14px;
    font-weight: 400;
    padding: 6px 12px;
  }
  .topbar-welcome strong {
    font-weight: 700;
  }

  /* ハンバーガーメニューを非表示 */
  .mobile-sidebar-toggle {
    display: none;
  }

  /* PC専用：ページTOPへ（ヘッダーが閉じた時だけ表示） */
  .page-top-btn {
    display: inline-flex;
  }
  html.header-collapsed .page-top-btn {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateY(0) scale(1);
    transition-delay: 0s;
  }

  /* PC専用のメガナビを表示 */
  .mega-nav {
    display: table;
    width: 100%;
    height: var(--mega-nav-height);
    table-layout: fixed;
    border-top: 1px solid #d6d3d1;
    border-bottom: 1px solid #d6d3d1;
    border-collapse: collapse;
    overflow: visible;
  }
  .mega-nav__item {
    display: table-cell;
    text-align: center;
    vertical-align: middle;
    text-decoration: none;
    color: #000000;
    transition:
      background-color 0.2s ease,
      color 0.2s ease,
      transform 0.18s ease,
      box-shadow 0.18s ease;
    cursor: pointer;
    padding: 14px 0;
    border-right: 1px solid #d6d3d1;
    width: 25%;
    font-size: 16px;
    position: relative;
    will-change: transform;
  }
  .mega-nav__item:last-child {
    border-right: none;
  }
  .mega-nav__item:hover {
    transform: translateY(-2px) scale(1.03);
    z-index: 2;
    box-shadow: 0 10px 22px rgba(17, 24, 39, 0.18);
  }
  .mega-nav__item:focus-visible {
    transform: translateY(-2px) scale(1.03);
    z-index: 2;
    box-shadow: 0 10px 22px rgba(17, 24, 39, 0.18);
    outline: 2px solid var(--focus-ring, rgba(74, 124, 89, 0.45));
    outline-offset: -2px;
  }
  .mega-nav__item:active {
    transform: translateY(-1px) scale(1.01);
    box-shadow: 0 6px 16px rgba(17, 24, 39, 0.16);
  }
  /* アクティブ状態のスタイル */
  .mega-nav__item.active {
    position: relative;
  }
  .mega-nav__item.active:hover {
    transform: translateY(-2px) scale(1.03);
    z-index: 2;
    box-shadow: 0 10px 22px rgba(17, 24, 39, 0.22);
  }

  /* PC用のサブナビ：横スクロール無しで常に等分 */
  .subnav-cats {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 1fr;
    overflow-x: hidden;
  }
  .subnav-cats .subnav-item {
    min-width: 0;
    flex-shrink: 1;
  }
  .subnav-item {
    font-size: 16px;
  }

  /* PCは等分グリッドなので、暖簾の裾を少し控えめに（横一列感を保つ） */
  .subnav-item::after {
    opacity: 0.45;
  }

  /* サイドバー(固定表示) */
  .sidebar {
    left: 0;
    width: var(--sidebar-width);
    right: auto;
    transition:
      transform 260ms ease,
      top 220ms ease,
      height 220ms ease;
    will-change: transform;
    position: fixed;
    overflow-x: visible;
  }
  .sidebar-search {
    display: none;
  }
  .sidebar-welcome {
    display: none;
  }

  /* 配色の右側に閉じるボタン */
  .sidebar-top-row {
    display: flex;
    align-items: center;
    gap: 8px;
  }
  .sidebar-top-row .theme-switcher {
    flex: 1 1 auto;
    min-width: 0;
  }
  .sidebar-collapse-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: 10px;
    border: 1px solid var(--sidebar-border, #e5e7eb);
    background: var(--surface-1, #ffffff);
    color: var(--sidebar-fg, #111827);
    cursor: pointer;
    flex: 0 0 auto;
    transition:
      background-color 0.18s ease,
      color 0.18s ease,
      border-color 0.18s ease,
      box-shadow 0.18s ease,
      transform 0.18s ease;
  }
  .sidebar-collapse-btn:hover {
    background: var(--nav-hover-overlay, rgba(138, 90, 43, 0.18));
    color: var(--nav-hover-fg, var(--sidebar-fg, #111827));
  }
  .sidebar-collapse-btn:active {
    background: var(--nav-hover-overlay, rgba(138, 90, 43, 0.22));
    transform: translateY(1px);
  }
  .sidebar-collapse-btn:focus-visible {
    outline: 2px solid var(--focus-ring, rgba(138, 90, 43, 0.55));
    outline-offset: 2px;
  }

  /* 非表示中の再表示ボタン（画面左側） */
  .sidebar-rail {
    position: absolute;
    top: 0;
    right: 0;
    width: var(--sidebar-rail-width);
    height: 100%;
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 10px 6px;
    pointer-events: auto;
    border-right: 1px solid #e5e7eb;
    overflow-y: auto;
    scrollbar-width: none;
  }
  .sidebar-expand-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
    border-radius: 12px;
    border: 1px solid var(--sidebar-border, #e5e7eb);
    background: var(--surface-1, #ffffff);
    color: var(--sidebar-fg, #111827);
    cursor: pointer;
    box-shadow: 0 6px 18px rgba(17, 24, 39, 0.18);
    transition:
      background-color 0.18s ease,
      color 0.18s ease,
      border-color 0.18s ease;
  }
  .sidebar-expand-btn:hover {
    background: var(--nav-hover-overlay, rgba(138, 90, 43, 0.18));
    color: var(--nav-hover-fg, var(--sidebar-fg, #111827));
  }
  .sidebar-expand-btn:focus-visible {
    outline: 2px solid var(--focus-ring, rgba(138, 90, 43, 0.55));
    outline-offset: 2px;
  }

  /* メインコンテンツにサイドバー分のマージン */
  #content {
    margin-left: var(--sidebar-width);
    transition: margin-left 260ms ease;
  }

  /* フッターにサイドバー分のマージン */
  .site-footer {
    margin-left: var(--sidebar-width);
    transition: margin-left 260ms ease;
  }
  /* フッターの３×３グリッドリンクをPC用に微調整 */
  .footer-category-links {
    gap: 12px 180px;
    max-width: 600px;
  }

  .sidebar-rail-nav {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    width: 100%;
  }
  .sidebar-rail-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    width: 100%;
    padding: 8px 4px;
    border-radius: 10px;
    text-decoration: none;
    color: var(--sidebar-fg, #111827);
    transition:
      background-color 0.18s ease,
      color 0.18s ease;
  }
  .sidebar-rail-item:hover {
    background: var(--nav-hover-overlay, rgba(138, 90, 43, 0.18));
    color: var(--nav-hover-fg, var(--sidebar-fg, #111827));
    scale: 1.1;
  }
  .sidebar-rail-item.active {
    background: var(--nav-hover-overlay, rgba(138, 90, 43, 0.22));
    color: var(--nav-hover-fg, var(--sidebar-fg, #111827));
  }
  .sidebar-rail-item:focus-visible {
    background: var(--nav-hover-overlay, rgba(138, 90, 43, 0.18));
    color: var(--nav-hover-fg, var(--sidebar-fg, #111827));
    outline: 2px solid var(--focus-ring, rgba(138, 90, 43, 0.55));
    outline-offset: 2px;
  }
  .sidebar-rail-icon {
    font-size: 24px;
    line-height: 1;
    color: inherit;
  }
  .sidebar-rail-label {
    display: block;
    max-width: 100%;
    font-size: 10px;
    font-weight: 700;
    line-height: 1.1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: inherit;
  }

  /* ========== サイドバー非表示状態 ========== */
  html.sidebar-collapsed .sidebar {
    transform: translateX(calc(-1 * (var(--sidebar-width) - var(--sidebar-rail-width))));
  }
  html.sidebar-collapsed #content {
    margin-left: var(--sidebar-rail-width);
  }
  html.sidebar-collapsed .site-footer {
    margin-left: var(--sidebar-rail-width);
  }
  /* 畳んだ時はレールだけ表示（中身は隠す） */
  html.sidebar-collapsed .sidebar .sidebar-content {
    display: none;
  }
  html.sidebar-collapsed .sidebar .sidebar-rail {
    display: flex;
  }
}
