/* ============================================================
   Noosphere Timeline — ダークテーマ
   配色は地形図ビュー（app/web/index.html）の :root を踏襲する。
   フォントはシステムフォントのみ（Webフォント禁止＝速度優先）。
   ============================================================ */

:root {
  --bg-primary: #0a0e1a;
  --bg-secondary: #111827;
  --bg-card: rgba(17, 24, 39, 0.8);
  --bg-raised: #1a2234;
  --text-primary: #e5e7eb;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;
  --border: rgba(255, 255, 255, 0.06);
  --accent: #6366f1;
  --accent-soft: rgba(99, 102, 241, 0.12);
  --accent-text: #a5b4fc;

  /* ソース別カラー（地形図ビューと統一） */
  --color-x: #a78bfa;
  --color-chrome: #60a5fa;
  --color-clippings: #34d399;
  --color-youtube: #f87171;
  --color-other: #9ca3af;

  --tabbar-h: calc(56px + env(safe-area-inset-bottom, 0px));
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans",
               "Yu Gothic UI", "Noto Sans JP", sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  height: 100%;
  overflow: hidden;
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

[hidden] { display: none !important; }

button {
  font-family: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

a { -webkit-tap-highlight-color: transparent; }

/* ---- ビュー（タブごとに独立スクロール・位置を保持） ---- */
.view {
  position: fixed;
  top: 0; left: 0; right: 0;
  bottom: var(--tabbar-h);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch; /* 慣性スクロール */
  overscroll-behavior-y: contain;
  display: none;
}
.view.active { display: block; }

.view-head {
  position: sticky;
  top: 0;
  z-index: 6;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 16px 10px;
  background: linear-gradient(180deg, rgba(10, 14, 26, 0.97), rgba(10, 14, 26, 0.88));
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-bottom: 1px solid var(--border);
}
.view-head h1 { font-size: 20px; font-weight: 700; letter-spacing: 0.01em; }
.view-sub { font-size: 12.5px; color: var(--text-muted); margin-top: 2px; }

.view-body {
  max-width: 640px;
  margin: 0 auto;
  padding: 12px 12px 32px;
}

.section-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-secondary);
  letter-spacing: 0.05em;
  padding: 14px 4px 8px;
}

.month-heading {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-secondary);
  letter-spacing: 0.05em;
  padding: 16px 4px 2px;
}

.status-row {
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  padding: 20px 8px;
}

.retry-btn {
  min-height: 44px;
  padding: 6px 18px;
  margin-left: 6px;
  border: 1px solid rgba(99, 102, 241, 0.35);
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-text);
  font-size: 13px;
  font-weight: 600;
}

/* ---- カード共通 ---- */
.card-list { display: flex; flex-direction: column; gap: 10px; }

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px;
  content-visibility: auto;
  contain-intrinsic-size: auto 140px;
}

article.card { cursor: pointer; }
article.card:active { background: var(--bg-raised); }

/* AI 1行要約（あれば原文より上に強調表示） */
.ai-summary {
  display: flex;
  gap: 7px;
  align-items: flex-start;
  background: var(--accent-soft);
  border: 1px solid rgba(99, 102, 241, 0.25);
  color: #c7d2fe;
  border-radius: 10px;
  padding: 7px 10px;
  font-size: 13.5px;
  line-height: 1.5;
  margin-bottom: 8px;
}
.ai-mark { color: #818cf8; flex: 0 0 auto; }

.tag-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.tag {
  font-size: 11.5px;
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(99, 102, 241, 0.1);
  border: 1px solid rgba(99, 102, 241, 0.2);
  color: var(--accent-text);
  white-space: nowrap;
}
/* ユーザー定義ラベル（config/labels.json）: AIタグと色で区別する */
.tag.tag-label {
  background: rgba(251, 191, 36, 0.12);
  border-color: rgba(251, 191, 36, 0.3);
  color: #fbbf24;
}

/* ---- ツイートカード（自前HTML/CSS） ---- */
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }

.avatar {
  position: relative;
  width: 40px; height: 40px;
  flex: 0 0 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  font-weight: 700;
  color: #e5e7eb;
  background: #374151;
  overflow: hidden;
  user-select: none;
}
.avatar img {
  position: absolute;
  inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
}

.card-names { min-width: 0; flex: 1; display: flex; flex-direction: column; }
.author-name {
  font-weight: 700;
  font-size: 14.5px;
  line-height: 1.35;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.author-id {
  font-size: 12.5px;
  color: var(--text-muted);
  line-height: 1.35;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.card-date { font-size: 12px; color: var(--text-muted); flex: 0 0 auto; align-self: flex-start; }

.card-body {
  font-size: 15px;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
}
.clamp {
  display: -webkit-box;
  -webkit-line-clamp: 6; /* 本文は6行でクランプ */
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card.expanded .clamp {
  display: block;
  -webkit-line-clamp: none;
  overflow: visible;
}

.more-hint {
  display: none;
  color: var(--accent-text);
  font-size: 13px;
  font-weight: 600;
  margin-top: 6px;
}
.card.is-clamped:not(.expanded) .more-hint { display: block; }

/* 展開部（「Xで開く」リンクは展開部の最下部のみ） */
.card-detail { display: none; }
.card.expanded .card-detail {
  display: flex;
  justify-content: flex-end;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}
.open-link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 6px 18px;
  border-radius: 999px;
  background: var(--accent-soft);
  border: 1px solid rgba(99, 102, 241, 0.3);
  color: var(--accent-text);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 600;
}

/* ---- リンクカード（Chrome / YouTube / メモ / その他） ---- */
a.card-link {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  text-decoration: none;
  color: inherit;
}
a.card-link:active { background: var(--bg-raised); }

.site-icon {
  width: 40px; height: 40px;
  flex: 0 0 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-secondary);
  user-select: none;
}
.card[data-source="x"] .site-icon { color: var(--color-x); background: rgba(167, 139, 250, 0.12); }
.card[data-source="chrome"] .site-icon { color: var(--color-chrome); background: rgba(96, 165, 250, 0.12); }
.card[data-source="youtube"] .site-icon { color: var(--color-youtube); background: rgba(248, 113, 113, 0.12); }
.card[data-source="clippings"] .site-icon { color: var(--color-clippings); background: rgba(52, 211, 153, 0.12); }
.card[data-source="other"] .site-icon { color: var(--color-other); background: rgba(156, 163, 175, 0.1); }

.card-link-main { min-width: 0; flex: 1; }
.link-title {
  font-size: 14.5px;
  font-weight: 600;
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}
.link-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ---- 今日: ダイジェストカード ---- */
.digest-card { border-left: 3px solid var(--accent); cursor: default; }
.digest-title { font-size: 15px; font-weight: 700; margin-bottom: 6px; }
.digest-summary { font-size: 13.5px; color: var(--text-secondary); }

/* ---- タイムライン: ソースフィルタチップ ---- */
.chip-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 10px 0 2px;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.chip-row::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto;
  min-height: 44px; /* タップ領域44px以上 */
  padding: 6px 16px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 600;
}
.chip.active {
  background: var(--accent-soft);
  border-color: rgba(99, 102, 241, 0.45);
  color: var(--accent-text);
}

#timeline-sentinel { height: 2px; }

/* ---- トピック ---- */
a.topic-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 56px;
  padding: 12px 14px;
  margin-bottom: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  color: inherit;
  text-decoration: none;
}
a.topic-row:active { background: var(--bg-raised); }
.topic-label {
  flex: 1; min-width: 0;
  font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topic-count { font-size: 12.5px; color: var(--text-muted); flex: 0 0 auto; }
.topic-chevron { color: var(--text-muted); font-size: 18px; flex: 0 0 auto; }

.empty-state { text-align: center; padding: 64px 20px; color: var(--text-muted); }
.empty-icon { font-size: 36px; opacity: 0.7; margin-bottom: 14px; }
.empty-title { font-size: 15px; font-weight: 700; color: var(--text-secondary); margin-bottom: 6px; }
.empty-text { font-size: 13px; }

.back-btn {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 4px 6px;
  background: none;
  border: none;
  color: var(--accent-text);
  font-size: 14.5px;
  font-weight: 600;
}
.topic-title { font-size: 19px; font-weight: 700; padding: 2px 4px 0; }
.topic-desc { color: var(--text-secondary); font-size: 14px; padding: 6px 4px 4px; }
.topic-meta { color: var(--text-muted); font-size: 12.5px; padding: 0 4px 12px; }

.related-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-muted);
}
.src-badge {
  font-size: 10.5px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 6px;
  background: rgba(251, 191, 36, 0.12);
  color: #fbbf24;
}
.src-badge[data-src="gnews"] { background: rgba(96, 165, 250, 0.12); color: var(--color-chrome); }
.related-why { font-size: 12.5px; color: var(--text-muted); margin-top: 6px; }

/* ---- 星取り表（matrix・CSS Grid＋横スクロール。ECharts不使用） ---- */
#matrix-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
#matrix-wrap::-webkit-scrollbar { display: none; }
/* 列テンプレート（116px + 日数×40px）は JS が実数で設定する */
.matrix-grid { display: grid; gap: 3px; width: max-content; padding: 8px 2px 4px; }
.matrix-corner, .matrix-day, .matrix-cell {
  display: flex; align-items: center; justify-content: center;
}
.matrix-corner, .matrix-day { font-size: 11px; font-weight: 700; color: var(--text-muted); }
/* トピック列見出しとラベルは横スクロールで固定する */
.matrix-corner, .matrix-label {
  position: sticky; left: 0; z-index: 2; background: var(--bg-primary);
}
.matrix-corner { justify-content: flex-start; }
.matrix-label {
  display: flex; align-items: center; gap: 6px;
  min-height: 40px; padding-right: 6px;
  font-size: 12.5px; font-weight: 600; overflow: hidden;
}
.matrix-label-text {
  flex: 1; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.matrix-total { flex: 0 0 auto; font-size: 11px; color: var(--text-muted); }
.matrix-cell {
  min-height: 40px; border-radius: 8px;
  font-size: 12.5px; font-weight: 700;
  background: rgba(255, 255, 255, 0.03); color: var(--text-secondary);
}
.matrix-cell.matrix-empty { background: transparent; }
.matrix-cell[role="button"] { cursor: pointer; }
.matrix-cell[role="button"]:active { filter: brightness(1.25); }
/* セルの色は max_imp（★の最大値）で濃くする */
.matrix-cell[data-imp="0"] { background: rgba(148, 163, 184, 0.16); }
.matrix-cell[data-imp="1"] { background: rgba(99, 102, 241, 0.22); color: #c7d2fe; }
.matrix-cell[data-imp="2"] { background: rgba(99, 102, 241, 0.45); color: #e0e7ff; }
.matrix-cell[data-imp="3"] { background: var(--accent); color: #fff; }

#matrix-detail { margin-top: 14px; }
.matrix-detail-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: 6px 4px 10px;
}
.matrix-detail-title { font-size: 14px; font-weight: 700; min-width: 0; }
.matrix-close {
  flex: 0 0 auto; min-height: 36px; padding: 4px 14px;
  border-radius: 999px; border: 1px solid var(--border);
  background: var(--bg-secondary); color: var(--text-secondary);
  font-size: 12.5px; font-weight: 600;
}
.matrix-item { cursor: default; }
.imp-badge {
  display: block; font-size: 12px; color: #fbbf24;
  letter-spacing: 1px; margin-bottom: 6px;
}
.matrix-item-summary { font-size: 14px; line-height: 1.5; word-break: break-word; }
.matrix-item-foot {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin-top: 10px;
}

/* ---- 検索 ---- */
.search-bar { padding: 10px 0 4px; }
#search-input {
  width: 100%;
  min-height: 44px;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 16px; /* iOSの自動ズームを防ぐ */
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}
#search-input:focus { border-color: rgba(99, 102, 241, 0.5); }
#search-input::placeholder { color: var(--text-muted); }

.result-card { border-left: 3px solid transparent; }
.result-card[data-source="x"] { border-left-color: var(--color-x); }
.result-card[data-source="chrome"] { border-left-color: var(--color-chrome); }
.result-card[data-source="youtube"] { border-left-color: var(--color-youtube); }
.result-card[data-source="clippings"] { border-left-color: var(--color-clippings); }
.result-card[data-source="other"] { border-left-color: rgba(156, 163, 175, 0.4); }
.result-card.resolving { opacity: 0.55; }

.result-text {
  font-size: 14px;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}
.result-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 6px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.result-note { font-size: 12px; color: var(--color-youtube); margin-top: 6px; }
.result-note:empty { display: none; }

/* ---- Cloudflare Access バナー ---- */
#access-banner {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 16px 10px;
  background: rgba(127, 29, 29, 0.96);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  font-size: 13.5px;
}
#access-banner p { flex: 1; }
#access-reload {
  flex: 0 0 auto;
  min-height: 36px;
  padding: 6px 14px;
  border: none;
  border-radius: 999px;
  background: #fee2e2;
  color: #7f1d1d;
  font-size: 13px;
  font-weight: 700;
}

/* ---- 下部タブバー ---- */
#tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 20;
  height: var(--tabbar-h);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  display: flex;
  background: rgba(10, 14, 26, 0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--border);
}
.tab {
  flex: 1;
  min-height: 44px; /* タップ領域44px以上 */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 10.5px;
  font-weight: 600;
}
.tab svg { width: 23px; height: 23px; }
.tab.active { color: var(--accent-text); }
