/* センサー：流し読みのための、静かな画面 */
:root {
  --bg: #ffffff;
  --surface: #f6f7f8;
  --line: #e6e8eb;
  --text: #15181c;
  --muted: #5f6b76;
  --faint: #8a94a0;
  --accent: #1f6feb;
  --heart: #d9304f;
  --save: #b07a06;
  --warn-bg: #fff6e0;
  --warn-text: #7a5600;
  --ok: #1d8a53;
  --error: #c62f3b;
  --radius: 10px;
  --nav-h: 56px;
  --font: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", "Meiryo", sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #101214;
    --surface: #1a1d21;
    --line: #2a2e34;
    --text: #e8eaed;
    --muted: #a0a9b3;
    --faint: #737d88;
    --accent: #5b9dff;
    --heart: #ff6b85;
    --save: #e0b13e;
    --warn-bg: #33290f;
    --warn-text: #e9c766;
    --ok: #4cc488;
    --error: #ff7b86;
  }
}
:root[data-theme="dark"] {
  --bg: #101214;
  --surface: #1a1d21;
  --line: #2a2e34;
  --text: #e8eaed;
  --muted: #a0a9b3;
  --faint: #737d88;
  --accent: #5b9dff;
  --heart: #ff6b85;
  --save: #e0b13e;
  --warn-bg: #33290f;
  --warn-text: #e9c766;
  --ok: #4cc488;
  --error: #ff7b86;
}

* { 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.65;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
main:focus { outline: none; }

/* 全体の配置 */
.layout { min-height: 100dvh; }
.main {
  max-width: 640px;
  margin: 0 auto;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 24px);
}
.nav {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 20;
  display: flex;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--bg);
  border-top: 1px solid var(--line);
}
.brand { display: none; }
.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  color: var(--faint);
  text-decoration: none;
  font-size: 10.5px;
}
.nav-item svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.nav-item.active { color: var(--text); }
.nav-item.active svg { stroke-width: 2.1; }

/* PC では左に縦の並び */
@media (min-width: 880px) {
  .layout { display: grid; grid-template-columns: 200px minmax(0, 640px); justify-content: center; gap: 0; }
  .nav {
    position: sticky;
    top: 0;
    inset: auto;
    height: 100dvh;
    flex-direction: column;
    gap: 2px;
    padding: 18px 12px;
    border-top: 0;
    border-right: 1px solid var(--line);
  }
  .brand { display: block; font-weight: 700; font-size: 17px; padding: 0 10px 14px; letter-spacing: .04em; }
  .nav-item {
    flex: 0 0 auto;
    flex-direction: row;
    justify-content: flex-start;
    gap: 12px;
    padding: 9px 10px;
    border-radius: var(--radius);
    font-size: 14.5px;
    color: var(--muted);
  }
  .nav-item:hover { background: var(--surface); }
  .main { margin: 0; width: 100%; border-right: 1px solid var(--line); padding-bottom: 48px; min-height: 100dvh; }
}

/* 上の帯 */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}
.topbar-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 16px; min-height: 46px; }
.page-title { font-size: 17px; font-weight: 700; margin: 0; }
.date-nav { display: flex; align-items: center; gap: 2px; }
.date-nav .date { font-weight: 700; font-size: 16px; padding: 0 4px; white-space: nowrap; }
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  height: 32px;
  border-radius: 8px;
  color: var(--muted);
}
.icon-btn:hover:not(:disabled) { background: var(--surface); }
.icon-btn:disabled { color: var(--line); cursor: default; }
.icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.tabs { display: flex; }
.tab {
  flex: 1;
  padding: 9px 4px 10px;
  color: var(--muted);
  font-weight: 600;
  font-size: 14.5px;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab.active { color: var(--text); border-bottom-color: var(--text); }
.tab .count { font-weight: 500; font-size: 12.5px; color: var(--faint); margin-left: 4px; }

/* お知らせ */
.notice {
  margin: 12px 16px 0;
  padding: 9px 12px;
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--muted);
  font-size: 13.5px;
}
.notice.warn { background: var(--warn-bg); color: var(--warn-text); }

/* ニュースカード */
.card { padding: 13px 16px 7px; border-bottom: 1px solid var(--line); }
.card.dismissed { opacity: .45; }
.meta { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 6px; font-size: 12.5px; color: var(--muted); }
.meta .cat { font-weight: 600; }
.meta .sep { color: var(--faint); }
.chip {
  font-size: 11px;
  line-height: 1.5;
  padding: 0 6px;
  border-radius: 4px;
  background: var(--surface);
  color: var(--muted);
}
.chip.warn { background: var(--warn-bg); color: var(--warn-text); }
.title { margin: 3px 0 4px; font-size: 16.5px; line-height: 1.45; font-weight: 700; letter-spacing: .005em; }
.title a { text-decoration: none; }
.title a:hover { text-decoration: underline; }
.summary {
  display: block;
  width: 100%;
  text-align: left;
  color: var(--text);
  opacity: .9;
  font-size: 14.5px;
  line-height: 1.7;
  cursor: pointer;
  margin: 0;
}
.reason { margin: 5px 0 0; font-size: 12.5px; color: var(--faint); }
.actions { display: flex; align-items: center; gap: 2px; margin: 4px -8px 0; }
.action {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 36px;
  padding: 0 8px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 12.5px;
  text-decoration: none;
  white-space: nowrap;
}
.action:hover { background: var(--surface); }
.action svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.action.heart.on { color: var(--heart); }
.action.heart.on svg { fill: currentColor; }
.action.save.on { color: var(--save); }
.action.save.on svg { fill: currentColor; }
.spacer { flex: 1; }
.action.quiet { color: var(--faint); font-size: 12px; padding: 0 6px; }

/* セクション見出し */
.section-head { padding: 16px 16px 4px; font-size: 13px; font-weight: 700; color: var(--muted); border-bottom: 1px solid var(--line); }
.section-head small { font-weight: 400; color: var(--faint); margin-left: 6px; }

/* 読み終わり */
.finish { padding: 26px 16px 32px; text-align: center; color: var(--muted); font-size: 14px; }
.finish strong { display: block; color: var(--text); font-size: 15px; margin-bottom: 4px; }
.finish button { color: var(--accent); margin-top: 8px; }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }

/* 詳細シート */
.sheet-backdrop { position: fixed; inset: 0; z-index: 30; background: rgb(0 0 0 / .38); }
.sheet {
  position: fixed;
  z-index: 31;
  inset: auto 0 0 0;
  max-height: 88dvh;
  overflow-y: auto;
  background: var(--bg);
  border-radius: 14px 14px 0 0;
  padding: 16px 16px calc(20px + env(safe-area-inset-bottom));
}
@media (min-width: 640px) {
  .sheet { inset: 8dvh auto auto 50%; transform: translateX(-50%); width: 560px; max-height: 84dvh; border-radius: 14px; }
}
.sheet h2 { font-size: 17px; line-height: 1.45; margin: 4px 0 8px; }
.sheet h3 { font-size: 13px; color: var(--muted); margin: 18px 0 6px; }
.sheet .close { position: absolute; top: 8px; right: 8px; }
.sheet .original { color: var(--muted); font-size: 13.5px; }
.source-list { list-style: none; margin: 0; padding: 0; }
.source-list li { padding: 7px 0; border-top: 1px solid var(--line); font-size: 13.5px; }
.source-list li:first-child { border-top: 0; }
.source-list a { text-decoration: none; }
.source-list a:hover { text-decoration: underline; }
.source-list .pub { display: block; color: var(--muted); font-size: 12px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 13px;
  border-radius: 9px;
  background: var(--surface);
  border: 1px solid var(--line);
  font-size: 13.5px;
  font-weight: 600;
  text-decoration: none;
}
.btn:hover:not(:disabled) { border-color: var(--faint); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--text); color: var(--bg); border-color: var(--text); }
.notes { margin: 8px 0 0; padding: 8px 11px; border-radius: 8px; background: var(--warn-bg); color: var(--warn-text); font-size: 13px; }
.notes ul { margin: 3px 0 0; padding-left: 18px; }
.score-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 2px 14px; font-size: 12.5px; color: var(--muted); }
.score-grid div { display: flex; justify-content: space-between; }

/* 検索 */
.search-form { padding: 12px 16px; display: grid; gap: 8px; border-bottom: 1px solid var(--line); }
.search-form .row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
input[type="search"], input[type="text"], input[type="date"], input[type="password"], select, textarea {
  width: 100%;
  min-height: 40px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--bg);
  font-size: 16px;
}
.field-label { font-size: 12px; color: var(--muted); display: grid; gap: 2px; }
.result-count { padding: 8px 16px; color: var(--muted); font-size: 13px; border-bottom: 1px solid var(--line); }

/* 分段スイッチ */
.segment { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.segment button { padding: 4px 10px; font-size: 12.5px; color: var(--muted); border-left: 1px solid var(--line); }
.segment button:first-child { border-left: 0; }
.segment button.active { background: var(--text); color: var(--bg); }

/* 深掘りの一覧 */
.list-tools { padding: 10px 16px; display: flex; align-items: center; gap: 8px; border-bottom: 1px solid var(--line); }
.list-tools input { flex: 1; min-width: 0; }

/* 設定 */
.settings section { padding: 14px 16px; border-bottom: 1px solid var(--line); }
.settings h2 { font-size: 14.5px; margin: 0 0 8px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 3px 14px; font-size: 13.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.status-ok { color: var(--ok); }
.status-bad { color: var(--error); }
.table-list { list-style: none; margin: 0; padding: 0; }
.table-list > li { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); font-size: 13.5px; }
.table-list > li:first-child { border-top: 0; }
.table-list .sub { display: block; font-size: 12px; color: var(--muted); }
.bar { display: block; height: 3px; margin-top: 4px; background: var(--line); border-radius: 2px; overflow: hidden; max-width: 170px; }
.bar i { display: block; height: 100%; background: var(--muted); }
details.run { border-top: 1px solid var(--line); padding: 8px 0; font-size: 13px; }
details.run:first-of-type { border-top: 0; }
details.run summary { cursor: pointer; display: flex; justify-content: space-between; gap: 8px; }
details.run pre { white-space: pre-wrap; word-break: break-all; font-size: 11.5px; line-height: 1.5; color: var(--muted); max-height: 280px; overflow: auto; background: var(--surface); padding: 8px; border-radius: 8px; }
.switch { position: relative; width: 38px; height: 22px; flex: none; border-radius: 11px; background: var(--line); transition: background .15s; }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgb(0 0 0 / .3); }
.switch.on { background: var(--ok); }
.switch.on::after { transform: translateX(16px); }
.inline-form { display: flex; gap: 8px; margin-top: 10px; }
.inline-form input { flex: 1; min-width: 0; }
.hint { font-size: 12.5px; color: var(--muted); margin: 6px 0 0; }
.hint.flush { margin: 0; }

/* 通知 */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 12px);
  transform: translate(-50%, 8px);
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: calc(100vw - 32px);
  padding: 8px 14px;
  border-radius: 10px;
  background: var(--text);
  color: var(--bg);
  font-size: 13.5px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .15s, transform .15s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.toast button, .toast a { color: inherit; font-weight: 700; text-decoration: underline; white-space: nowrap; }

/* ログイン */
.login-page { display: grid; place-items: center; min-height: 100dvh; padding: 16px; }
.login { width: min(340px, 100%); display: grid; gap: 10px; }
.login h1 { font-size: 20px; margin: 0 0 6px; }
.login label { font-size: 13px; color: var(--muted); }
.login button { min-height: 42px; border-radius: 9px; background: var(--text); color: var(--bg); font-weight: 700; }
.error { color: var(--error); margin: 0; font-size: 13.5px; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
