:root {
  --bg: #f3f4f6;
  --card: #ffffff;
  --text: #1b1d21;
  --sub: #6b7079;
  --line: #e4e6ea;
  --read: #9aa0a8;
  --accent: #e0452b;
  --shadow: 0 1px 2px rgba(0,0,0,.06);
  --reader-size: 18px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #101114; --card: #1a1c20; --text: #e8e9ec; --sub: #9a9fa8;
    --line: #2a2d33; --read: #6c717a; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #101114; --card: #1a1c20; --text: #e8e9ec; --sub: #9a9fa8;
  --line: #2a2d33; --read: #6c717a; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; overscroll-behavior-y: contain; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", Meiryo, sans-serif;
  font-size: 16px; line-height: 1.5;
}
a { color: inherit; }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---- ログイン ---- */
body.auth { display: flex; justify-content: center; padding: 48px 16px; }
.auth-box {
  width: 100%; max-width: 380px; background: var(--card); border-radius: 14px;
  padding: 28px 24px; box-shadow: 0 2px 12px rgba(0,0,0,.08);
}
.auth-logo { margin: 0 0 8px; font-size: 26px; color: var(--accent); letter-spacing: .02em; }
.auth-h2 { font-size: 17px; margin: 8px 0; }
.auth-lead { color: var(--sub); margin: 0 0 18px; font-size: 14px; }
.auth-steps { padding-left: 20px; font-size: 14px; color: var(--sub); }
.auth-steps li { margin-bottom: 6px; }
.auth-qr { display: block; margin: 12px auto; background: #fff; border-radius: 8px; }
.auth-secret { font-size: 13px; color: var(--sub); margin-bottom: 14px; }
.auth-secret code { display: block; word-break: break-all; font-size: 15px; color: var(--text); padding: 6px 0; }
.auth-error { background: #fde8e4; color: #a32513; border-radius: 8px; padding: 10px 12px; font-size: 14px; }
.auth-back { text-align: center; font-size: 13px; margin: 16px 0 0; }
.auth-back a { color: var(--sub); }
.auth label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 14px; }
.auth input {
  display: block; width: 100%; margin-top: 6px; padding: 12px; font-size: 17px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--text);
}
.auth input:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.btn-primary {
  width: 100%; padding: 12px; font-size: 16px; font-weight: 700; color: #fff;
  background: var(--accent); border: 0; border-radius: 8px; cursor: pointer; margin-top: 4px;
}

/* ---- 上の帯 ---- */
.topbar {
  position: sticky; top: 0; z-index: 10; background: var(--card);
  border-bottom: 1px solid var(--line); padding-top: env(safe-area-inset-top);
}
.topbar-row {
  display: flex; align-items: center; gap: 6px; max-width: 760px; margin: 0 auto;
  padding: 8px 12px 4px; position: relative;
}
.logo { font-weight: 800; font-size: 20px; color: var(--accent); text-decoration: none; white-space: nowrap; margin-right: 4px; }
.search { flex: 1; min-width: 0; }
.search input {
  width: 100%; padding: 7px 12px; border-radius: 18px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); font-size: 15px;
}
.icon-btn {
  background: none; border: 0; padding: 6px; border-radius: 8px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; min-width: 36px; min-height: 36px;
  color: var(--sub); font-weight: 700; font-size: 14px;
}
.icon-btn:hover { background: var(--bg); }
.icon-btn.spin svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.icon-btn[aria-pressed="true"] { color: var(--accent); }
.icon-btn[aria-pressed="true"] path { fill: currentColor; }

.menu {
  position: absolute; right: 8px; top: 48px; background: var(--card); border: 1px solid var(--line);
  border-radius: 10px; box-shadow: 0 6px 24px rgba(0,0,0,.15); min-width: 200px; padding: 6px; z-index: 20;
}
.menu-user { padding: 8px 10px; font-size: 13px; color: var(--sub); border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.menu-item {
  display: block; width: 100%; text-align: left; padding: 10px; border: 0; background: none;
  border-radius: 6px; cursor: pointer; text-decoration: none; font-size: 15px;
}
.menu-item:hover { background: var(--bg); }
.menu form { margin: 0; }
.menu-ver { font-size: 11px; color: var(--sub); padding: 6px 10px 2px; }

.tabs {
  display: flex; gap: 2px; overflow-x: auto; max-width: 760px; margin: 0 auto; padding: 0 8px;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: none; padding: 9px 14px 10px; font-size: 15px; font-weight: 700; color: var(--sub);
  text-decoration: none; border-bottom: 3px solid transparent; white-space: nowrap;
}
.tab.active { color: var(--tab-color); border-bottom-color: var(--tab-color); }

/* ---- 一覧 ---- */
.list-view { max-width: 760px; margin: 0 auto; padding: 8px 0 40px; }
.list-head { padding: 8px 16px; font-size: 14px; color: var(--sub); }
.list { background: var(--card); box-shadow: var(--shadow); }
@media (min-width: 780px) { .list { border-radius: 12px; overflow: hidden; } }

.item {
  display: flex; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--line);
  text-decoration: none; color: var(--text); cursor: pointer;
}
.item:hover { background: color-mix(in srgb, var(--bg) 60%, transparent); }
.item-text { flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: space-between; }
.item-title {
  margin: 0; font-size: 16px; font-weight: 700; line-height: 1.45;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.item-meta { margin-top: 6px; font-size: 12px; color: var(--sub); display: flex; gap: 8px; align-items: center; }
.item-meta .saved-mark { color: var(--accent); }
.item-thumb {
  flex: none; width: 104px; height: 78px; border-radius: 6px; object-fit: cover; background: var(--bg);
}
.item.read .item-title { color: var(--read); font-weight: 600; }

/* 先頭の大きな記事 */
.item.hero { flex-direction: column; gap: 10px; padding: 0 0 14px; }
.item.hero .item-thumb { width: 100%; height: auto; aspect-ratio: 16 / 9; border-radius: 0; }
.item.hero .item-text { padding: 0 16px; }
.item.hero .item-title { font-size: 20px; -webkit-line-clamp: 4; }
.item.hero .item-summary {
  font-size: 14px; color: var(--sub); margin: 6px 0 0;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.list-more { padding: 18px; text-align: center; color: var(--sub); font-size: 14px; }
.list-more button {
  padding: 10px 24px; border-radius: 20px; border: 1px solid var(--line); background: var(--card); cursor: pointer;
}
.empty { padding: 48px 16px; text-align: center; color: var(--sub); }

/* ---- 記事を読む画面 ---- */
.reader { position: fixed; inset: 0; z-index: 30; background: var(--card); overflow-y: auto; -webkit-overflow-scrolling: touch; }
.reader-bar {
  position: sticky; top: 0; z-index: 2; display: flex; align-items: center; gap: 2px;
  background: var(--card); border-bottom: 1px solid var(--line);
  padding: calc(4px + env(safe-area-inset-top)) 8px 4px;
}
.reader-bar-src { flex: 1; min-width: 0; font-size: 13px; color: var(--sub); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reader-body { max-width: 720px; margin: 0 auto; padding: 18px 18px 80px; font-size: var(--reader-size); line-height: 1.85; }
.r-cat { font-size: 13px; font-weight: 700; }
.r-title { font-size: 1.4em; line-height: 1.45; margin: 6px 0 10px; }
.r-meta { font-size: 13px; color: var(--sub); margin-bottom: 18px; }
.r-hero { width: 100%; border-radius: 8px; margin-bottom: 18px; }
.r-content p { margin: 0 0 1.1em; }
.r-content h2, .r-content h3, .r-content h4 { font-size: 1.1em; margin: 1.6em 0 .6em; line-height: 1.5; }
.r-content img { max-width: 100%; height: auto; border-radius: 6px; display: block; margin: 1em auto; }
.r-content figure { margin: 1em 0; }
.r-content figcaption { font-size: .8em; color: var(--sub); }
.r-content blockquote { margin: 1em 0; padding-left: 1em; border-left: 3px solid var(--line); color: var(--sub); }
.r-content table { border-collapse: collapse; font-size: .85em; display: block; overflow-x: auto; }
.r-content td, .r-content th { border: 1px solid var(--line); padding: 4px 8px; }
.r-content pre { overflow-x: auto; background: var(--bg); padding: 10px; border-radius: 6px; font-size: .8em; }
.r-note { background: var(--bg); border-radius: 8px; padding: 12px 14px; font-size: 14px; color: var(--sub); margin: 0 0 18px; }
.r-loading { color: var(--sub); padding: 40px 0; text-align: center; }
.r-source {
  display: block; text-align: center; margin: 28px 0 0; padding: 13px; border-radius: 10px;
  background: var(--bg); text-decoration: none; font-weight: 700; font-size: 15px;
}
.r-credit { font-size: 12px; color: var(--sub); text-align: center; margin-top: 10px; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: rgba(30,30,34,.92); color: #fff; padding: 10px 18px; border-radius: 20px; font-size: 14px; z-index: 50;
}
body.reading { overflow: hidden; }

/* ---- 読み上げ ---- */
.speaking { background: color-mix(in srgb, var(--accent) 14%, transparent); border-radius: 4px; }
.tts-bar {
  position: sticky; bottom: 0; z-index: 3; display: flex; align-items: center; gap: 8px;
  max-width: 720px; margin: 0 auto; padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  background: var(--card); border-top: 1px solid var(--line); box-shadow: 0 -4px 16px rgba(0,0,0,.08);
}
.tts-bar { flex-wrap: wrap; }
.tts-label { flex: 1 1 100%; min-width: 0; font-size: 13px; color: var(--sub); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tts-btn {
  flex: none; padding: 8px 12px; border-radius: 18px; border: 1px solid var(--line);
  background: var(--bg); font-size: 14px; font-weight: 700; cursor: pointer;
}
#speakBtn[aria-pressed="true"] { color: var(--accent); }
.tts-main { flex: 1 1 100%; display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.tts-sub { flex: 1 1 100%; display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.tts-big {
  padding: 12px 4px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg);
  font-size: 14px; font-weight: 700; cursor: pointer; white-space: nowrap;
}
.tts-strong { background: var(--accent); border-color: var(--accent); color: #fff; }
.tts-sub .tts-btn { font-size: 13px; padding: 6px 10px; }
.r-next {
  display: block; width: 100%; margin: 20px 0 0; padding: 14px; border-radius: 10px; border: 0;
  background: var(--accent); color: #fff; font-size: 16px; font-weight: 700; cursor: pointer;
}

/* ---- 同じ話題 ---- */
.item-meta .related-mark { color: var(--sub); border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; }
.r-related { margin: 28px 0 0; border-top: 1px solid var(--line); padding-top: 14px; }
.r-related-h { font-size: 15px; margin: 0 0 6px; }
.r-related-item { display: block; padding: 10px 0; border-bottom: 1px solid var(--line); text-decoration: none; }
.r-related-title { display: block; font-size: 15px; font-weight: 700; line-height: 1.5; }
.r-related-meta { display: block; font-size: 12px; color: var(--sub); margin-top: 2px; }

/* ---- 指での操作 ---- */
.ptr {
  display: flex; align-items: flex-end; justify-content: center; overflow: hidden;
  font-size: 13px; color: var(--sub); padding-bottom: 6px; height: 0; max-width: 760px; margin: 0 auto;
}
.list-view.slide-l { animation: slideL .22s ease-out; }
.list-view.slide-r { animation: slideR .22s ease-out; }
@keyframes slideL { from { transform: translateX(40px); opacity: .4; } to { transform: none; opacity: 1; } }
@keyframes slideR { from { transform: translateX(-40px); opacity: .4; } to { transform: none; opacity: 1; } }

/* ---- 下の帯 (スマホ) ---- */
.bottom-nav { display: none; }
.pc-empty { display: none; }
@media (max-width: 779px) {
  .bottom-nav {
    display: grid; grid-template-columns: repeat(4, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 15;
    background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
  }
  .bottom-nav button {
    display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 7px 0 6px;
    background: none; border: 0; color: var(--sub); font-size: 11px; cursor: pointer;
  }
  .bottom-nav button.active { color: var(--accent); font-weight: 700; }
  .list-view { padding-bottom: calc(80px + env(safe-area-inset-bottom)); }
  .menu { position: fixed; top: auto; bottom: calc(64px + env(safe-area-inset-bottom)); right: 8px; }
}

/* ---- PC: 一覧を左、記事を右に並べる ---- */
@media (min-width: 1100px) {
  :root { --pc-side: max(16px, calc(50% - 680px)); --pc-list: 480px; }
  .topbar-row, .tabs { max-width: 1360px; }
  .list-view { max-width: none; width: var(--pc-list); margin: 0 0 0 var(--pc-side); padding-top: 12px; }
  .list { border-radius: 12px; overflow: hidden; }
  .item { cursor: pointer; }
  .item.current { background: color-mix(in srgb, var(--accent) 10%, var(--card)); box-shadow: inset 4px 0 0 var(--accent); }
  .reader, .pc-empty {
    top: calc(var(--topbar-h, 96px) + 12px); bottom: 12px;
    left: calc(var(--pc-side) + var(--pc-list) + 16px); right: var(--pc-side);
    border-radius: 12px; box-shadow: 0 1px 4px rgba(0,0,0,.08); border: 1px solid var(--line);
  }
  .reader { z-index: 5; }
  .reader-body { padding: 24px 32px 80px; }
  body.reading { overflow: auto; }
  body:not(.reading) .pc-empty {
    position: fixed; display: flex; flex-direction: column; gap: 12px; align-items: center; justify-content: center;
    background: var(--card); color: var(--sub); font-size: 15px; text-align: center; line-height: 1.8;
  }
  .pc-empty small { font-size: 12px; }
  .tts-bar { border-radius: 0 0 12px 12px; }
}

/* ---- 指紋・顔でログイン ---- */
.btn-passkey {
  display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%;
  padding: 12px; margin: 0 0 18px; font-size: 16px; font-weight: 700; cursor: pointer;
  border: 2px solid var(--accent); border-radius: 8px; background: var(--card); color: var(--accent);
}
.btn-passkey[disabled] { opacity: .6; }
