:root {
  --ink: #14213D; --sub: #4A5468; --muted: #5B6577; --line: #E3E7EE; --line2: #C9D0DB;
  --bg: #F4F6F9; --card: #FFFFFF; --accent: #2457C5; --accent-ink: #1E46A0; --accent-bg: #E8EEFB;
  --dot: #C2410C; --danger: #B42318; --off: #8A94A6;
}
@media (prefers-color-scheme: dark) {
  :root {
    --ink: #E8ECF3; --sub: #B7C0CF; --muted: #A3ADBD; --line: #2A3448; --line2: #3A465E;
    --bg: #0F1522; --card: #182033; --accent: #6E9BFF; --accent-ink: #9DBBFF; --accent-bg: #22314F;
    --dot: #FF8A4C; --danger: #FF8A80; --off: #5E6A80;
  }
}
* { box-sizing: border-box; }
/* hidden 属性は .btn などの display 指定より優先する */
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", system-ui, sans-serif; font-size: 15px; line-height: 1.6; -webkit-text-size-adjust: 100%; }
a { color: var(--accent); text-decoration: none; }
.app { max-width: 720px; margin: 0 auto; min-height: 100vh; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; gap: 4px; padding: calc(env(safe-area-inset-top) + 10px) 16px 10px; background: var(--card); border-bottom: 1px solid var(--line); }
.topbar h1 { margin: 0; font-size: 20px; }
.iconbtn { width: 44px; height: 44px; margin-left: -10px; display: flex; align-items: center; justify-content: center; color: var(--ink); }
.content { flex: 1; padding: 16px 16px 110px; display: flex; flex-direction: column; gap: 12px; }
.flash { margin: 12px 16px 0; padding: 10px 14px; border-radius: 12px; background: var(--accent-bg); color: var(--accent-ink); font-size: 14px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.stack.tight { gap: 2px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row.end { justify-content: flex-end; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.grid2 > * { min-width: 0; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.strong { font-weight: 700; }
.error { color: var(--danger); margin: 0; }
.hint { margin: 0; font-size: 12px; color: var(--sub); }
.empty { color: var(--sub); }
.label { font-size: 13px; font-weight: 700; margin: 0; }
.section { font-size: 13px; color: var(--muted); margin: 10px 0 0; }
.kwname { margin: 0; font-size: 16px; }
.url { color: var(--muted); word-break: break-all; }
.nowrap { white-space: nowrap; }

input, select, textarea { width: 100%; min-height: 44px; padding: 10px 12px; border: 1px solid var(--line2); border-radius: 12px; background: var(--card); color: var(--ink); font: inherit; font-size: 16px; }
textarea { resize: vertical; }
input[type="checkbox"], input[type="radio"] { accent-color: var(--accent); }
/* iOS Safari：選択欄の独自の見た目をやめて入力欄と揃える */
select { -webkit-appearance: none; appearance: none; padding-right: 40px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238A94A6' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; background-size: 18px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.check input { width: 20px; min-height: 20px; height: 20px; margin: 0; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 46px; padding: 0 16px; border-radius: 12px; border: 1px solid var(--accent); background: var(--card); color: var(--accent); font: inherit; font-weight: 700; cursor: pointer; }
.btn.primary { background: var(--accent); color: #FFFFFF; }
@media (prefers-color-scheme: dark) { .btn.primary { color: #0F1522; } }
.btn:disabled { opacity: .5; }
.btn.danger { border-color: var(--danger); color: var(--danger); }
.pill { flex: none; white-space: nowrap; min-height: 36px; padding: 0 12px; border-radius: 18px; border: 1px solid var(--accent); background: transparent; color: var(--accent); font: inherit; font-size: 13px; cursor: pointer; display: inline-flex; align-items: center; }
.pill.on { background: var(--accent); color: var(--card); }
.pill.danger { border-color: var(--danger); color: var(--danger); }

.search { display: flex; align-items: center; gap: 8px; padding: 0 12px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; color: var(--muted); }
.search input { border: 0; padding-left: 0; }
.search input:focus { outline: none; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; }
.chip { flex: none; display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 14px; border-radius: 18px; border: 1px solid var(--line2); background: var(--card); color: var(--ink); font-size: 13px; font-weight: 500; }
.chiptext { max-width: 12em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip.on { background: var(--ink); border-color: var(--ink); color: var(--card); }
.badge { font-size: 11px; padding: 0 6px; border-radius: 9px; background: var(--dot); color: #FFFFFF; }

.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.article { display: flex; flex-direction: column; gap: 6px; padding: 14px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; color: var(--ink); }
.article.read .title { color: var(--sub); font-weight: 500; }
.article.compact { padding: 12px; }
.meta { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; font-size: 12px; color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 4px; background: var(--dot); }
.tag { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-left: auto; padding: 2px 8px; border-radius: 6px; background: var(--accent-bg); color: var(--accent-ink); font-weight: 500; }
article .meta .tag { margin-left: 0; }
.item { position: relative; }
.item .article { padding-right: 52px; }
.saveform { position: absolute; top: 4px; right: 4px; }
.savebtn { width: 44px; height: 44px; display: flex; align-items: center; justify-content: center; border: 0; border-radius: 12px; background: transparent; color: var(--muted); cursor: pointer; }
.savebtn.on { color: var(--accent); }
.savebtn.on svg { fill: currentColor; }
.savebtn:focus-visible { outline: 2px solid var(--accent); }
.title { font-size: 15px; font-weight: 700; line-height: 1.5; }
.snippet { font-size: 13px; color: var(--sub); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.headline { margin: 0; font-size: 21px; line-height: 1.5; }
.body { margin: 0; color: var(--sub); line-height: 1.8; }

details summary { cursor: pointer; font-weight: 700; font-size: 14px; min-height: 32px; }
.kw { padding: 10px 14px; gap: 6px; }
.kwhead { flex-wrap: nowrap; }
.kwhead > div { min-width: 0; }
.kwhead .kwname { overflow-wrap: anywhere; }
.kwhead .check { flex: none; white-space: nowrap; min-height: 44px; font-size: 13px; }
.kwmore summary { font-size: 13px; font-weight: 500; color: var(--muted); line-height: 32px; }
.kwmore[open] summary { margin-bottom: 8px; }
.warn { color: var(--danger); font-weight: 700; }
.feeds { list-style: none; padding: 0; margin: 8px 0; display: flex; flex-direction: column; gap: 10px; }
.feeds li { display: flex; gap: 8px; justify-content: space-between; align-items: flex-start; padding-bottom: 10px; border-bottom: 1px solid var(--line); }
.sub { padding-top: 14px; margin-top: 14px; border-top: 1px solid var(--line); }

.switch { position: relative; width: 52px; height: 32px; flex: none; }
.switch input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: 16px; background: var(--off); transition: background .15s; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 13px; background: #FFFFFF; transition: left .15s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { left: 23px; }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
.fieldset legend { padding: 0; margin-bottom: 6px; }
.segment { padding: 4px; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; background: var(--line); border-radius: 12px; }
.segment label { position: relative; }
.segment input { position: absolute; opacity: 0; inset: 0; margin: 0; min-height: 0; cursor: pointer; }
.segment span { display: flex; align-items: center; justify-content: center; min-height: 38px; border-radius: 9px; font-size: 13px; font-weight: 700; color: var(--sub); }
.segment input:checked + span { background: var(--card); color: var(--ink); }
.segment input:focus-visible + span { outline: 2px solid var(--accent); }

.tabbar { position: fixed; bottom: 0; left: 0; right: 0; z-index: 2; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); max-width: 720px; margin: 0 auto; padding: 6px 4px calc(env(safe-area-inset-bottom) + 6px); background: var(--card); border-top: 1px solid var(--line); }
.tabbar a { display: flex; flex-direction: column; align-items: center; gap: 2px; min-height: 48px; padding-top: 4px; font-size: 11px; color: var(--muted); }
.tabbar a.on { color: var(--accent); font-weight: 700; }
