/* Base + layout. Mobile First。全値はtokens.cssのトークンを参照する。 */

*, *::before, *::after { box-sizing: border-box; }

/* スクロールバー領域を常に確保（タブ切替で内容量が変わっても横ズレしない） */
html { -webkit-text-size-adjust: 100%; scrollbar-gutter: stable; }

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--fs-body);
  line-height: var(--lh-body);
  color: var(--text);
  background: var(--bg);
  /* ページ全体の横スクロールを禁止（Spec 04 §5）。原因は各要素で断つのが原則で、
     これは最後の保険。overflow-x:hidden はoverflow-yをautoに変えbodyをスクロール容器化して
     PCで縦スクロールが効かなくなるため、スクロール容器を作らない clip を使う。 */
  overflow-x: clip;
}

img { max-width: 100%; height: auto; display: block; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* 長い英数字（AI名・型番・URL）で親を押し広げない（Spec 04 §148） */
h1, h2, h3, p, li, a, span { overflow-wrap: anywhere; }

/* ---- Header ---- */
.site-header {
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: 0 var(--sp-4);
  background: var(--surface);
  border-bottom: var(--border-w) solid var(--border);
}
.site-header .brand {
  font-size: var(--fs-lg);
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.01em;
}
.site-header .brand:hover { text-decoration: none; }
.header-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: var(--tap-min);
  min-height: var(--tap-min);
  color: var(--text-muted);
  background: none;
  border: 0;
  cursor: pointer;
}

/* ---- Layout container ---- */
.wrap {
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  padding-inline: var(--sp-4);
}

main {
  /* 下部ナビ廃止に伴い、最下部の余白のみ確保 */
  padding-bottom: calc(env(safe-area-inset-bottom, 0px) + var(--sp-5));
}

/* スクリーンリーダー専用（見た目には出さない） */
.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  overflow: hidden;
  white-space: nowrap;
}

/* ---- Hero（ブランド。巨大Heroにしない） ---- */
.hero { margin-top: var(--sp-5); }
.hero-title { margin: 0 0 var(--sp-3); line-height: 0; }
.hero-img {
  width: 100%; max-width: 440px; height: auto;
  border-radius: var(--radius);
}
.hero-sub {
  margin: 0; font-size: var(--fs-body); line-height: var(--lh-body);
  color: var(--text-muted);
}
/* 月間利用者数トップ10（スマホ5×2、PC10列。順位順） */
.hero-ais-label {
  margin: 0 0 var(--sp-3); font-size: var(--fs-body); line-height: var(--lh-body);
  color: var(--text-muted);
}
.hero-ais {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: var(--sp-3) var(--sp-2);
  margin: 0;
}
.hero-ai {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  min-width: 0; text-decoration: none; color: var(--text-muted);
}
.hero-ai .logo { width: 44px; height: 44px; }
.hero-ai-name {
  font-size: var(--fs-sm); line-height: 1.2; text-align: center;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%;
}
.hero-ai:hover { text-decoration: none; outline: var(--border-w) solid var(--accent); outline-offset: var(--sp-2); border-radius: var(--radius); }
.hero-ai:hover .hero-ai-name { color: var(--text); }

/* ---- Section ---- */
.section { margin-top: var(--sp-6); }
.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: var(--sp-3);
}
.section-head h2 {
  margin: 0;
  font-size: var(--fs-lg);
  line-height: var(--lh-tight);
}
.section-head .more { font-size: var(--fs-sm); }

/* ---- 用途から探す（カテゴリGrid：2列、横スクロールにしない） ---- */
.cat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--sp-2);
}
.cat-card {
  display: flex;
  align-items: center;
  min-height: var(--tap-min);
  padding: var(--sp-3);
  background: var(--surface);
  border: var(--border-w) solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: var(--fs-body);
  font-weight: 600;
}
.cat-card:hover { text-decoration: none; border-color: var(--accent); }

/* ---- 姉妹サイトへの相互リンク ---- */
.cross-link {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: var(--sp-1);
  padding: var(--sp-3) var(--sp-4);
  background: var(--surface);
  border: var(--border-w) solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
}
.cross-link:hover { text-decoration: none; border-color: var(--accent); }
.cross-link-title { font-size: var(--fs-lg); font-weight: 700; }
.cross-link-sub { font-size: var(--fs-sm); color: var(--text-muted); }

/* ---- Article Card（左サムネ + 右テキスト。placeholder） ---- */
.card {
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: var(--sp-3);
  padding: var(--sp-3) 0;
  border-bottom: var(--border-w) solid var(--border);
  color: var(--text);
}
.card[hidden] { display: none; }
.card:hover { text-decoration: none; outline: var(--border-w) solid var(--accent); outline-offset: var(--sp-2); border-radius: var(--radius); }
.card .thumb {
  width: 96px;
  aspect-ratio: 4 / 3;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: var(--border-w) solid var(--border);
}
.card .meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  font-size: var(--fs-sm);
  color: var(--text-muted);
  margin-bottom: var(--sp-1);
}
.card .card-title {
  margin: 0;
  font-size: var(--fs-body);
  line-height: var(--lh-tight);
  /* 2行まででClamp */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Badge（数を絞る。原色で煽らない） */
.badge {
  display: inline-block;
  padding: 1px var(--sp-2);
  border-radius: var(--radius-sm);
  border: var(--border-w) solid var(--border);
  font-size: var(--fs-sm);
  color: var(--text-muted);
}
.badge.breaking { color: var(--danger); border-color: var(--danger); }
.badge.mine-pill { color: var(--accent-ink); background: var(--accent); border-color: var(--accent); }

/* My AI のAI記事を新着で静かに強調（左アクセント＋淡い下地） */
.card.is-mine {
  border-left: 3px solid var(--accent);
  border-bottom-color: transparent;
  padding: var(--sp-3);
  background: var(--surface-2);
  border-radius: var(--radius-sm);
}

/* placeholder注記 */
.placeholder-note {
  margin: var(--sp-2) 0 0;
  font-size: var(--fs-sm);
  color: var(--text-muted);
}

/* ---- Logo（画像 or 頭文字フォールバック。per-brand色はハードコードしない §96） ---- */
.logo {
  width: 40px; height: 40px;
  border-radius: var(--radius-sm);
  object-fit: contain;
  background: var(--surface);
  border: var(--border-w) solid var(--border);
  flex: 0 0 auto;
}
img.logo { background: var(--logo-plate); padding: 3px; box-sizing: border-box; }
/* 白抜きロゴは白下地だと消えるので暗い下地にする（logo_bg:dark） */
img.logo.logo-on-dark { background: var(--logo-plate-dark); }
.logo-fallback {
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: var(--fs-lg);
  color: var(--text-muted);
  background: var(--surface-2);
}
.card .thumb-wrap {
  width: 96px; aspect-ratio: 4 / 3;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: var(--border-w) solid var(--border);
}
.card .thumb-wrap .logo { width: 48px; height: 48px; border: 0; }
.card .thumb-wrap img.logo { background: var(--logo-plate); padding: 6px; }
.card .thumb-wrap img.logo.logo-on-dark { background: var(--logo-plate-dark); }
.card .thumb-wrap .logo-fallback { background: none; }

.empty { color: var(--text-muted); padding: var(--sp-4) 0; }

/* カテゴリ件数 */
.cat-card { justify-content: space-between; }
.cat-count { color: var(--text-muted); font-weight: 400; font-size: var(--fs-sm); }

/* ---- AI一覧（Category detail） ---- */
.ai-list { display: flex; flex-direction: column; }
.ai-item {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-3) 0;
  border-bottom: var(--border-w) solid var(--border);
  color: var(--text); min-height: var(--tap-min);
}
.ai-item:hover { text-decoration: none; outline: var(--border-w) solid var(--accent); outline-offset: var(--sp-2); border-radius: var(--radius); }
.ai-item-body { display: flex; flex-direction: column; }
.ai-name { font-weight: 600; }
.ai-sub { font-size: var(--fs-sm); color: var(--text-muted); }

/* ---- AI詳細 ---- */
.ai-head { display: flex; align-items: center; gap: var(--sp-3); margin-top: var(--sp-5); }
.ai-head .logo { width: 56px; height: 56px; }
.ai-title { margin: 0; font-size: var(--fs-title); line-height: var(--lh-tight); }
.ai-company { margin: 2px 0 0; color: var(--text-muted); }
.chips { display: flex; flex-wrap: wrap; gap: var(--sp-2); margin-top: var(--sp-3); }
.chip {
  font-size: var(--fs-sm); padding: var(--sp-1) var(--sp-3);
  border: var(--border-w) solid var(--border); border-radius: 999px;
  color: var(--text-muted); min-height: 32px; display: inline-flex; align-items: center;
}
.chip:hover { text-decoration: none; border-color: var(--accent); color: var(--accent); }
.ai-actions { display: flex; gap: var(--sp-2); margin-top: var(--sp-4); flex-wrap: wrap; }
.btn-action {
  min-height: var(--tap-min); padding: 0 var(--sp-4);
  border-radius: var(--radius); border: var(--border-w) solid var(--accent);
  background: var(--accent); color: var(--accent-ink); font-weight: 600; cursor: pointer;
}
.btn-action.ghost { background: none; color: var(--accent); }
a.btn-action { display: inline-flex; align-items: center; text-decoration: none; }
.tabs { display: flex; gap: var(--sp-1); border-bottom: var(--border-w) solid var(--border); margin-bottom: var(--sp-4); }
.tab {
  min-height: var(--tap-min); padding: 0 var(--sp-4);
  background: none; border: var(--border-w) solid transparent; border-bottom: none;
  border-radius: var(--radius) var(--radius) 0 0; margin-bottom: calc(-1 * var(--border-w));
  color: var(--text-muted); font-weight: 600; cursor: pointer;
}
/* 選択タブはブラウザのタブのように上辺アクセント＋左右上のフチ、下辺は本文と地続きに見せる */
.tab.is-active {
  color: var(--text); background: var(--surface);
  border-color: var(--border); border-top: 2px solid var(--accent);
  border-bottom: var(--border-w) solid var(--surface);
}
.load-more {
  display: block; text-align: center; width: 100%;
  min-height: var(--tap-min); line-height: var(--tap-min); margin-top: var(--sp-3);
  border: var(--border-w) solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text); font-weight: 600; text-decoration: none;
}
.load-more:hover { text-decoration: none; border-color: var(--accent); }
.btn-action.is-on { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.btn-action.ghost.is-on { background: var(--surface-2); color: var(--text); }

/* ---- 保存ボタン（記事） ---- */
.btn-save {
  margin-top: var(--sp-3); min-height: 36px; padding: 0 var(--sp-3);
  border-radius: var(--radius); border: var(--border-w) solid var(--border);
  background: none; color: var(--text-muted); font-size: var(--fs-sm); font-weight: 600; cursor: pointer;
}
.btn-save.is-on { color: var(--accent); border-color: var(--accent); }
.article-actions { display: flex; gap: var(--sp-2); flex-wrap: wrap; margin-top: var(--sp-3); }
.article-actions .btn-save { margin-top: 0; }

/* ---- 検索入力 ---- */
.search-input {
  width: 100%; min-height: var(--tap-min); padding: 0 var(--sp-3);
  font-size: var(--fs-body); color: var(--text);
  background: var(--surface); border: var(--border-w) solid var(--border); border-radius: var(--radius);
  margin-bottom: var(--sp-4);
}
.search-input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.card-list { display: flex; flex-direction: column; }

/* ---- Home検索窓（用途から探すと最新の間） ---- */
.home-search { position: relative; }
.home-search .search-input { margin-bottom: 0; padding-left: 40px; }
.home-search-ico {
  position: absolute; left: var(--sp-3); top: 50%; transform: translateY(-50%);
  width: 18px; height: 18px; color: var(--text-muted); pointer-events: none;
}
.ai-official { margin-top: var(--sp-4); }
.btn-official { font-weight: 600; }
.official-none { color: var(--text-muted); font-size: var(--fs-sm); }


/* ---- 記事本文（§5.6 軽量フォーマット） ---- */
.article-meta {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2);
  font-size: var(--fs-sm); color: var(--text-muted); margin-top: var(--sp-5);
}
.article-title {
  margin: var(--sp-2) 0 0; font-size: var(--fs-title); line-height: var(--lh-tight);
}
.article-block { margin-top: var(--sp-5); }
.article-block h2 {
  margin: 0 0 var(--sp-2); font-size: var(--fs-lg); line-height: var(--lh-tight);
}
.article-block p { margin: 0; }
.related { border-top: 1px solid var(--border); padding-top: var(--sp-4); }
.related-list { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: var(--sp-2); }
.related-list a { display: block; padding: var(--sp-2) 0; line-height: var(--lh-tight); border-bottom: 1px solid var(--border); }
.related-list li:last-child a { border-bottom: 0; }
.tldr { margin: 0; padding-left: 1.15em; display: flex; flex-direction: column; gap: var(--sp-2); }
.tldr li { line-height: var(--lh-body); }
/* 重要な変更点の蛍光マーカー（==text==）。読みやすさのため薄め。light/dark両対応 */
.hl {
  background: linear-gradient(transparent 55%, var(--hl) 55%);
  color: inherit; padding: 0 1px; border-radius: 1px;
}

/* ---- Tablet / Desktop（コンテンツ基準で拡張。情報構造は変えない） ---- */
@media (min-width: 768px) {
  .cat-grid { grid-template-columns: repeat(3, 1fr); }
  .hero-ais { grid-template-columns: repeat(10, 1fr); }
}

/* ===== LEGAL / STATIC PAGES + FOOTER ===== */
.legal-page { max-width: 720px; margin: 0 auto; padding: 8px 0 40px; }
.legal-page h1 { font-size: var(--fs-lg, 1.6rem); margin: 0 0 20px; color: var(--text); }
.legal-page h2 { font-size: 1.05rem; margin: 28px 0 10px; color: var(--text); }
.legal-page p, .legal-page li { line-height: 1.9; color: var(--text); font-size: .95rem; }
.legal-page ul { padding-left: 1.3em; margin: 8px 0; }
.legal-page li { margin-bottom: 6px; }
.legal-page a { color: var(--accent); text-decoration: underline; }
.legal-page dl { margin: 8px 0; }
.legal-page dt { font-weight: 700; margin-top: 16px; }
.legal-page dd { margin: 4px 0 0; color: var(--text); }
.site-footer-legal { border-top: 1px solid var(--border); margin-top: 48px; padding: 28px 16px 40px; text-align: center; }
.site-footer-legal .footer-nav { display: flex; gap: 18px; flex-wrap: wrap; justify-content: center; margin-bottom: 12px; }
.site-footer-legal .footer-nav a { color: var(--text-muted); text-decoration: none; font-size: .82rem; }
.site-footer-legal .footer-nav a:hover { color: var(--text); }
.site-footer-legal .footer-copy { color: var(--text-muted); font-size: .74rem; margin: 0; }
