/* 画面の骨組み：上のバー・メニュー（PC は左の列、スマホは左から出る）・アカウント・ドック・本文
   PC とスマホの切り替えは 960px */
@layer layout {

  /* ---- 上のバー */
  .topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 6px;
    height: var(--topbar-h);
    padding: 0 8px;
    background: color-mix(in srgb, var(--surface) 84%, transparent);
    -webkit-backdrop-filter: saturate(1.6) blur(14px);
    backdrop-filter: saturate(1.6) blur(14px);
    border-bottom: 1px solid var(--border);
  }
  .topbar-site {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    flex: 1;
    color: var(--text);
    font-weight: 700;
    text-decoration: none;
  }
  .topbar-site span { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
  .topbar-spacer { flex: 1; }
  .topbar-view { display: none; } /* PC だけ（スマホは引き出しの右上のアイコン）。公開ページを確かめる動線は多い */

  /* ---- アカウント（右上）：<details> で開く。JS があれば外を押すと閉じる */
  .acct { position: relative; flex: none; }
  .acct > summary { list-style: none; cursor: pointer; width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; }
  .acct > summary::-webkit-details-marker { display: none; }
  .acct > summary .avatar { width: 34px; height: 34px; transition: box-shadow .15s; }
  .acct > summary:hover .avatar, .acct[open] > summary .avatar { box-shadow: 0 0 0 3px var(--accent-soft); }
  .acct-menu {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    z-index: 30;
    width: 264px;
    padding: 6px;
    border-radius: 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-l);
    transform-origin: top right;
    animation: kwe-pop .2s var(--ease) both;
  }
  .acct-head { display: flex; gap: 12px; align-items: center; padding: 10px 10px 14px; margin-bottom: 4px; border-bottom: 1px solid var(--border); }
  .acct-head b { display: block; line-height: 1.3; }
  .acct-head small { color: var(--muted); }
  .acct-menu form { margin: 0; }
  .menu-sep { height: 1px; background: var(--border); margin: 4px 6px; }

  /* ---- メニューの項目（左の列・引き出し・アカウントで共通） */
  .nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    min-height: 44px;
    padding: 0 12px;
    border: 0;
    border-radius: 12px;
    background: none;
    color: var(--text);
    font: inherit;
    font-size: 15px;
    font-weight: 500;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
    transition: background .15s, color .15s;
  }
  .nav-item:hover { background: var(--surface-2); }
  .nav-label { min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; } /* 長い種類の名前は「…」（2行にしない） */
  .nav-item svg.i { color: var(--muted); width: 20px; height: 20px; }
  .nav-item.is-active { background: var(--accent-soft); color: var(--accent); font-weight: 700; }
  .nav-item.is-active svg.i { color: var(--accent); }
  .nav-item.is-danger, .nav-item.is-danger svg.i { color: var(--danger); }
  .nav-count { margin-left: auto; font-size: 12px; color: var(--faint); font-variant-numeric: tabular-nums; }
  .nav-group { margin: 14px 12px 4px; font-size: 11.5px; font-weight: 700; color: var(--faint); letter-spacing: .06em; }

  /* ---- メニュー（スマホ：左から出る引き出し） */
  .nav {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 50;
    width: min(86vw, 320px);
    display: flex;
    flex-direction: column;
    background: var(--surface);
    box-shadow: var(--shadow-l);
    transform: translateX(-102%);
    transition: transform .32s var(--ease);
    visibility: hidden;
  }
  .nav.is-open { transform: none; visibility: visible; }
  .nav-head { display: flex; align-items: center; gap: 4px; min-height: 64px; padding: 0 8px 0 16px; border-bottom: 1px solid var(--border); }
  .nav-site { display: flex; align-items: center; gap: 10px; min-width: 0; color: var(--text); font-weight: 700; }
  .nav-site span { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
  .nav-ext { flex: none; width: 32px; height: 32px; border-radius: 8px; display: grid; place-items: center; color: var(--faint); transition: color .15s, background .15s; }
  .nav-ext:hover { color: var(--accent); background: var(--accent-soft); }
  .nav-ext svg.i { width: 17px; height: 17px; }
  .nav-close { margin-left: auto; }
  .nav-body { flex: 1; overflow: auto; padding: 8px; }
  .nav-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 14px 18px; border-top: 1px solid var(--border); }
  .nav-foot img { height: 20px; width: auto; display: block; }
  .nav-foot small { color: var(--faint); font-size: 12px; }
  /* メンテナンス中の札（忘れないように。管理者はタップで「設定 → メンテナンス」へ） */
  .nav-maint { text-decoration: none; white-space: nowrap; }
  .nav-scrim { position: fixed; inset: 0; z-index: 45; background: var(--scrim); opacity: 0; pointer-events: none; transition: opacity .25s; }
  .nav-scrim.is-open { opacity: 1; pointer-events: auto; }

  /* ---- 本文 */
  .content {
    width: 100%;
    max-width: var(--content-w);
    margin: 0 auto;
    padding: 20px 16px 48px;
    animation: kwe-enter .35s var(--ease) backwards; /* 終わったら何も残さない（残すと中の固定表示の基準がずれる） */
  }
  .content-narrow { max-width: 640px; }
  .has-dock .content { padding-bottom: 120px; }

  /* ---- ドック（ホームだけ。スマホの画面下） */
  .dock {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: calc(12px + env(safe-area-inset-bottom));
    z-index: 30;
    display: flex;
    align-items: center;
    height: 64px;
    padding: 0 6px;
    border-radius: 22px;
    background: color-mix(in srgb, var(--surface) 86%, transparent);
    -webkit-backdrop-filter: saturate(1.6) blur(16px);
    backdrop-filter: saturate(1.6) blur(16px);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-l);
    transition: transform .3s var(--ease), opacity .3s;
  }
  .dock.is-hidden { transform: translateY(130%); opacity: 0; }
  .dock-item {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 6px 0;
    color: var(--muted);
    font-size: 10.5px;
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: color .2s;
  }
  .dock-item span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
  .dock-item:hover { color: var(--text); }
  .dock-item.is-add { flex-grow: 1.5; color: var(--accent); letter-spacing: -.02em; }
  .dock-item.is-add svg.i { width: 26px; height: 26px; padding: 3px; margin-bottom: -2px; border-radius: 9px; background: var(--accent); color: var(--on-accent); stroke-width: 2.2; }
  .dock-preview { position: relative; height: 90px; margin-bottom: 20px; border-radius: var(--radius); background: var(--surface-2); border: 1px dashed var(--border); overflow: hidden; }
  .dock-preview .dock { position: absolute; }

  /* ---- ログイン画面など（メニューのない画面） */
  .bare {
    display: grid;
    place-items: center;
    padding: 24px 16px;
    background:
      radial-gradient(60% 40% at 15% 10%, rgba(233, 95, 95, .13), transparent 70%),
      radial-gradient(50% 40% at 90% 15%, rgba(155, 89, 182, .13), transparent 70%),
      radial-gradient(60% 50% at 80% 95%, rgba(52, 152, 219, .13), transparent 70%),
      radial-gradient(50% 40% at 10% 90%, rgba(46, 204, 113, .11), transparent 70%),
      var(--bg);
  }
  .bare-card {
    width: 100%;
    max-width: 400px;
    padding: 28px 22px 22px;
    border-radius: 22px;
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-l);
    animation: kwe-enter .5s var(--ease) both;
  }
  .bare-site { display: flex; align-items: center; gap: 10px; margin: 0 0 22px; font-weight: 700; }
  .bare-card .btn-primary { min-height: 50px; }
  .bare-card .card { padding: 0; border: 0; box-shadow: none; background: none; }
  .bare-card .passkey-btn { min-height: 50px; }
  .login-or { display: flex; align-items: center; gap: 12px; margin: 18px 0; color: var(--muted); font-size: 13px; }
  .login-or::before, .login-or::after { content: ''; flex: 1; border-top: 1px solid var(--border); }
  .bare-title { margin: 0 0 4px; font-size: 20px; }
  .bare-title + .hint { margin: 0 0 18px; }
  .bare-links { margin: 14px 0 0; display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 18px; font-size: 14px; }
  .bare-links a { color: var(--muted); white-space: nowrap; }
  .bare-brand { display: flex; justify-content: center; margin-top: 22px; }
  .bare-brand img { height: 34px; width: auto; }

  /* ========== PC（960px 以上）：メニューは左の列に常に出す。ドックは出さない */
  @media (min-width: 960px) {
    .nav {
      width: var(--side-w);
      transform: none;
      visibility: visible;
      box-shadow: none;
      border-right: 1px solid var(--border);
      transition: none;
    }
    .nav-close, .nav-scrim, .menu-btn, .topbar-site, .dock { display: none !important; }
    .app-main { margin-left: var(--side-w); }
    .topbar { justify-content: flex-end; gap: 10px; padding: 0 20px; background: transparent; border-bottom: 0; -webkit-backdrop-filter: none; backdrop-filter: none; position: static; }
    .topbar-view { display: inline-flex; color: var(--muted); }
    .topbar-view:hover { color: var(--accent); }
    .content { padding: 4px 32px 60px; }
    .has-dock .content { padding-bottom: 60px; }
    .page-title { font-size: 28px; }
  }
  @media (min-width: 1280px) {
    .content { padding-top: 12px; }
  }
}
