:root {
  --bg: #f5f4f0;
  --card: #ffffff;
  --text: #1c1d21;
  --sub: #62656d;
  --faint: #8d9098;
  --line: #e6e4de;
  --chip: #ecebe6;
  --chip-on: #1c1d21;
  --chip-on-text: #ffffff;
  --link-bg: #f2f1ec;
  --shadow: 0 1px 2px rgba(20, 20, 30, 0.04), 0 2px 10px rgba(20, 20, 30, 0.04);

  /* キャラクター */
  --K: #2563eb;
  --V: #059669;
  --R: #d97706;
  --U: #db2777;
  /* カテゴリ */
  --c-ai: #6d4ee6;
  --c-world: #475569;
  --c-foryou: #0891b2;

  --radius: 18px;
  --font: system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", "Noto Sans CJK JP", "Yu Gothic UI", sans-serif;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #0f1013;
  --card: #18191d;
  --text: #ececee;
  --sub: #a5a8b0;
  --faint: #7b7f88;
  --line: #2a2c31;
  --chip: #23252a;
  --chip-on: #ececee;
  --chip-on-text: #111216;
  --link-bg: #212328;
  --shadow: none;

  --K: #6b9bff;
  --V: #34c79a;
  --R: #f0a640;
  --U: #f06aa6;
  --c-ai: #9f8cff;
  --c-world: #a3b0c2;
  --c-foryou: #38c3dd;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.7;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
a { color: inherit; }

/* ---------- 上の帯 ---------- */
.top {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(14px);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}
.bar, .datebar, .filters, .feed { max-width: 620px; margin: 0 auto; }
.bar { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px 2px 16px; }
.brand { margin: 0; font-size: 20px; font-weight: 800; letter-spacing: -0.02em; display: flex; align-items: center; gap: 8px; }
.brand-dot { width: 11px; height: 11px; border-radius: 50%; background: var(--text); box-shadow: 9px -7px 0 -3px var(--c-ai); margin-right: 6px; }
.bar-actions { display: flex; gap: 2px; }
.icon-btn { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; color: var(--sub); }
.icon-btn:active { background: var(--chip); }
.i-sun { display: none; }
:root[data-theme="dark"] .i-sun { display: block; }
:root[data-theme="dark"] .i-moon { display: none; }

.datebar { display: flex; align-items: center; justify-content: space-between; padding: 0 8px; }
.nav-btn { width: 44px; height: 40px; display: grid; place-items: center; color: var(--sub); border-radius: 12px; }
.nav-btn:disabled { opacity: 0.25; cursor: default; }
.nav-btn:not(:disabled):active { background: var(--chip); }
.date-btn { display: flex; align-items: center; gap: 2px; font-weight: 700; font-size: 16px; padding: 6px 10px; border-radius: 12px; }
.date-btn svg { width: 18px; height: 18px; color: var(--faint); }
.date-btn:active { background: var(--chip); }

.filters { display: flex; gap: 8px; padding: 6px 16px 12px; overflow-x: auto; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.filters button {
  flex: none; padding: 6px 14px; border-radius: 999px; background: var(--chip);
  font-size: 14px; font-weight: 600; color: var(--sub); white-space: nowrap;
}
.filters button .n { font-weight: 500; opacity: 0.6; margin-left: 4px; font-size: 12px; }
.filters button.on { background: var(--chip-on); color: var(--chip-on-text); }

/* ---------- タイムライン ---------- */
.feed { padding: 14px 12px calc(40px + env(safe-area-inset-bottom)); }
.day-head { padding: 4px 6px 12px; }
.day-head .count { color: var(--sub); font-size: 13px; }
.day-note { margin: 6px 0 0; font-size: 13.5px; color: var(--sub); }

.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  border: 1px solid var(--line); margin-bottom: 14px; overflow: hidden;
}
.topic { padding: 16px 16px 14px; }
.tags { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.cat { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 700; letter-spacing: 0.02em; color: var(--cat); }
.cat::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--cat); }
.cat-ai { --cat: var(--c-ai); }
.cat-world { --cat: var(--c-world); }
.cat-foryou { --cat: var(--c-foryou); }
.badge { font-size: 11px; font-weight: 700; padding: 1px 8px; border-radius: 999px; border: 1px solid var(--line); color: var(--sub); }
.headline { margin: 0 0 6px; font-size: 18px; line-height: 1.5; font-weight: 800; letter-spacing: -0.01em; }
.summary { margin: 0; color: var(--text); opacity: 0.88; font-size: 15px; }
.sources { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.src {
  display: inline-flex; align-items: center; gap: 4px; max-width: 100%;
  font-size: 12.5px; font-weight: 600; color: var(--sub); text-decoration: none;
  background: var(--link-bg); padding: 4px 10px; border-radius: 999px;
}
.src svg { width: 13px; height: 13px; flex: none; }
.src span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.src:active { opacity: 0.7; }

/* 会話 */
.thread { border-top: 1px solid var(--line); padding: 12px 16px 6px; }
.post { display: grid; grid-template-columns: 34px 1fr; gap: 10px; position: relative; padding-bottom: 12px; }
.post:not(:last-child)::before {
  content: ""; position: absolute; left: 16px; top: 38px; bottom: 2px; width: 2px; background: var(--line); border-radius: 2px;
}
.av {
  width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center;
  font-weight: 800; font-size: 15px; color: #fff; background: var(--who);
}
:root[data-theme="dark"] .av { color: #111216; }
.who-K { --who: var(--K); }
.who-V { --who: var(--V); }
.who-R { --who: var(--R); }
.who-U { --who: var(--U); }
.meta { display: flex; align-items: baseline; gap: 6px; line-height: 1.4; }
.meta b { font-size: 14px; }
.meta .role { font-size: 12px; color: var(--faint); }
.op { font-size: 10.5px; font-weight: 700; padding: 0 6px; border-radius: 6px; color: var(--who); border: 1px solid color-mix(in srgb, var(--who) 40%, transparent); line-height: 1.6; }
.post p { margin: 2px 0 0; font-size: 14.5px; line-height: 1.7; }

/* Claudeに聞く */
.ask-row { display: flex; justify-content: flex-end; padding: 0 12px 12px; }
.ask {
  display: inline-flex; align-items: center; gap: 6px; text-decoration: none;
  font-size: 13px; font-weight: 700; color: var(--sub);
  padding: 7px 14px; border-radius: 999px; border: 1px solid var(--line);
}
.ask svg { width: 17px; height: 17px; }
.ask:active { background: var(--chip); }

/* 状態の表示（未着・失敗・空） */
.notice { text-align: center; padding: 48px 20px; color: var(--sub); }
.notice .big { font-size: 15px; font-weight: 700; color: var(--text); margin: 0 0 6px; }
.notice p { margin: 0; font-size: 13.5px; }
.notice button { margin-top: 16px; font-size: 13.5px; font-weight: 700; padding: 8px 16px; border-radius: 999px; background: var(--chip); color: var(--text); }
.soft-fail { font-size: 12.5px; color: var(--faint); text-align: center; margin: 2px 0 14px; }
.skeleton { height: 210px; border-radius: var(--radius); background: var(--card); border: 1px solid var(--line); margin-bottom: 14px; opacity: 0.6; }

.foot { text-align: center; color: var(--faint); font-size: 12px; padding: 10px 0 0; }

/* ---------- 下から出るシート ---------- */
.sheet-wrap { position: fixed; inset: 0; z-index: 30; display: flex; align-items: flex-end; justify-content: center; }
.sheet-wrap[hidden] { display: none; }
.sheet-bg { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.35); animation: fade 0.15s ease; }
.sheet {
  position: relative; width: 100%; max-width: 620px; max-height: 78vh; overflow-y: auto;
  background: var(--card); border-radius: 22px 22px 0 0; padding: 6px 16px calc(20px + env(safe-area-inset-bottom));
  animation: up 0.2s ease;
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; background: var(--card); padding: 8px 0; }
.sheet-head h2 { margin: 0; font-size: 16px; }
.date-list .month { font-size: 12px; font-weight: 700; color: var(--faint); margin: 12px 4px 4px; }
.date-row { display: flex; justify-content: space-between; align-items: center; width: 100%; padding: 11px 12px; border-radius: 12px; text-align: left; }
.date-row:active, .date-row.on { background: var(--chip); }
.date-row .d { font-weight: 600; }
.date-row .s { font-size: 12.5px; color: var(--faint); }
.cast { display: grid; gap: 12px; margin-top: 6px; }
.cast-item { display: grid; grid-template-columns: 34px 1fr; gap: 12px; align-items: start; }
.cast-item b { display: block; font-size: 14.5px; }
.cast-item span { font-size: 13.5px; color: var(--sub); }
.cast-note { font-size: 12.5px; color: var(--faint); margin: 16px 0 0; line-height: 1.7; }

@keyframes up { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

@media (min-width: 700px) {
  .feed { padding-top: 20px; }
  .headline { font-size: 19px; }
}
