/* ===== 共通トークン ===== */
:root {
  --bg: #f3f4f6;
  --card: #ffffff;
  --text: #1f2330;
  --muted: #6b7280;
  --border: #e5e7eb;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --accent-soft: #eef2ff;
  --accent-soft-border: #dbe3ff;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.1);
  --shadow-hover: 0 6px 16px rgba(16, 24, 40, 0.12);
  --code-bg: #f6f8fa;
}
:root[data-theme="dark"] {
  --bg: #0e131a;
  --card: #171e27;
  --text: #e6e8eb;
  --muted: #94a3b8;
  --border: #2a3340;
  --accent: #3b82f6;
  --accent-dark: #bfdbfe;
  --accent-soft: #1e293b;
  --accent-soft-border: #334155;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
  --shadow-hover: 0 8px 20px rgba(0, 0, 0, 0.6);
  --code-bg: #0f151d;
}
:root[data-theme="dark"] .search input,
:root[data-theme="dark"] .toolbar select,
:root[data-theme="dark"] .chip,
:root[data-theme="dark"] .cal-nav,
:root[data-theme="dark"] .src-toggle,
:root[data-theme="dark"] .cal-selected .clear { background: var(--card); color: var(--text); }
:root[data-theme="dark"] .toolbar { background: rgba(14, 19, 26, 0.92); }
:root[data-theme="dark"] .empty,
:root[data-theme="dark"] .error { background: var(--card); }
:root[data-theme="dark"] .today {
  background: linear-gradient(135deg, #2a2010 0%, #3a2c12 100%); border-color: #7c5316;
}
:root[data-theme="dark"] .up-card,
:root[data-theme="dark"] .act,
:root[data-theme="dark"] .nav-card { background: var(--card); }
:root[data-theme="dark"] .card .summary { color: #cbd5e1; }

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Kaku Gothic ProN", "Noto Sans JP", Meiryo, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}
a { color: inherit; }

/* ===== ヘッダー ===== */
header.site {
  background: linear-gradient(135deg, #2563eb 0%, #1e3a8a 100%);
  color: #fff;
  padding: 12px 16px;
}
header.site .inner {
  max-width: 920px; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
header.site h1 { margin: 0; font-size: 1.35rem; letter-spacing: 0.02em; }
header.site h1 .pin { margin-right: 6px; }
header.site h1 a { text-decoration: none; }
header.site .sub { font-size: 0.72rem; opacity: 0.85; display: block; font-weight: 400; letter-spacing: 0; }
.header-actions { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }
.header-btn {
  width: 38px; height: 38px; border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  background: rgba(255, 255, 255, 0.12);
  color: #fff; cursor: pointer; font-size: 1.1rem; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
  text-decoration: none;
}
.header-btn:hover { background: rgba(255, 255, 255, 0.22); }
.header-btn svg { width: 20px; height: 20px; fill: currentColor; display: block; }

/* ===== スティッキー操作バー ===== */
.toolbar {
  position: sticky; top: 0; z-index: 10;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.toolbar .inner {
  max-width: 920px; margin: 0 auto; padding: 10px 16px;
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
}
.search { flex: 1 1 220px; position: relative; min-width: 160px; }
.search input {
  width: 100%; padding: 9px 12px 9px 34px;
  border: 1px solid var(--border); border-radius: 999px;
  font-size: 0.9rem; background: #fff; color: var(--text);
}
.search input:focus { outline: 2px solid var(--accent); border-color: var(--accent); }
.search .icon {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  color: var(--muted); font-size: 0.95rem; pointer-events: none;
}
.toolbar select {
  padding: 9px 10px; border: 1px solid var(--border); border-radius: 8px;
  background: #fff; font-size: 0.88rem; color: var(--text);
}
.src-toggle {
  padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px;
  background: #fff; font-size: 0.88rem; color: var(--text);
  cursor: pointer; white-space: nowrap; transition: all 0.15s;
}
.src-toggle:hover { border-color: var(--accent); }
.src-toggle[aria-expanded="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.src-toggle.active { border-color: var(--accent); color: var(--accent); font-weight: 700; }
.src-toggle.active[aria-expanded="true"] { color: #fff; }

/* ===== チップ ===== */
.chips {
  max-width: 920px; margin: 14px auto 0; padding: 0 16px;
  display: flex; flex-wrap: wrap; gap: 8px;
}
#tag-chips { display: none; }
#tag-chips.show { display: flex; }
.chip {
  border: 1px solid var(--border); background: #fff; color: var(--text);
  padding: 5px 12px; border-radius: 999px; font-size: 0.8rem; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px; transition: all 0.15s;
}
.chip:hover { border-color: var(--accent); }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip .dot { width: 8px; height: 8px; border-radius: 50%; }
.chip .n { opacity: 0.7; font-size: 0.72rem; }

main { max-width: 920px; margin: 0 auto; padding: 14px 16px 40px; }
.count { font-size: 0.8rem; color: var(--muted); margin: 14px 2px 12px; }

/* ===== 上部2カラム: 左=カレンダー / 右=今日の記録＋最近の記録 ===== */
.top-layout {
  max-width: 920px; margin: 14px auto 0; padding: 0 16px;
  display: flex; gap: 14px; align-items: flex-start;
}
.top-layout .col-cal { flex: 1 1 0; min-width: 0; }
.top-layout .col-info { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; gap: 14px; }
.top-layout .cal-wrap,
.top-layout .hero,
.top-layout .recent-wrap { max-width: none; margin: 0; padding: 0; }
/* 狭い画面では縦積み。align-items は stretch に戻す —— column 方向のまま
   flex-start だと各カラムが内容幅（横スクロールレールの全長）まで広がり、
   ページ全体が横にはみ出す。 */
@media (max-width: 720px) {
  .top-layout { flex-direction: column; gap: 12px; align-items: stretch; }
}

/* ===== 今日の記録バナー ===== */
.hero { max-width: 920px; margin: 14px auto 0; padding: 0 16px; }
.today {
  display: flex; align-items: center; gap: 14px; width: 100%;
  background: linear-gradient(135deg, #fff7ed 0%, #ffedd5 100%);
  border: 1px solid #fed7aa; border-radius: 14px;
  padding: 12px 16px; cursor: pointer; text-align: left;
  transition: box-shadow 0.18s, transform 0.18s;
}
.today:hover { box-shadow: var(--shadow-hover); transform: translateY(-1px); }
.today[aria-pressed="true"] { outline: 2px solid #f97316; }
.today .cal { font-size: 2rem; line-height: 1; }
.today .lbl { font-size: 0.8rem; color: #9a3412; font-weight: 700; }
.today .big { font-size: 1.7rem; font-weight: 800; color: #c2410c; }
.today .unit { font-size: 0.9rem; color: #c2410c; font-weight: 700; }
.today .sub { font-size: 0.72rem; color: #9a3412; opacity: 0.85; }
.today .go { margin-left: auto; font-size: 0.8rem; color: #c2410c; font-weight: 700; white-space: nowrap; }
@media (max-width: 520px) {
  .today .go { display: none; }
  .today .big { font-size: 1.4rem; }
}

/* ===== カレンダー ===== */
.cal-wrap { max-width: 920px; margin: 14px auto 0; padding: 0 16px; }
.cal {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 14px; box-shadow: var(--shadow); padding: 10px 14px 12px;
}
.cal-head { display: flex; align-items: center; justify-content: center; gap: 14px; margin-bottom: 6px; }
.cal-head .title { font-size: 0.98rem; font-weight: 800; min-width: 8.5em; text-align: center; }
.cal-nav {
  width: 28px; height: 28px; border-radius: 8px;
  border: 1px solid var(--border); background: #fff; color: var(--text);
  cursor: pointer; font-size: 1.05rem; line-height: 1;
}
.cal-nav:hover { border-color: var(--accent); color: var(--accent); }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; }
.cal-dow { text-align: center; font-size: 0.7rem; font-weight: 700; color: var(--muted); padding: 1px 0; }
.cal-dow.sun { color: #dc2626; }
.cal-dow.sat { color: #2563eb; }
.cal-cell { height: 26px; }
.cal-day {
  width: 100%; height: 100%;
  border: 1px solid transparent; border-radius: 8px;
  background: transparent; color: var(--text);
  display: flex; align-items: center; justify-content: center;
  cursor: default; position: relative; font: inherit; padding: 0;
}
.cal-day .d { font-size: 0.9rem; }
.cal-day.sun .d { color: #dc2626; }
.cal-day.sat .d { color: #2563eb; }
.cal-day.today { border-color: #f97316; }
.cal-day.has {
  cursor: pointer;
  background: var(--accent-soft); border-color: var(--accent-soft-border); color: var(--accent-dark);
}
.cal-day.has .d { color: var(--accent-dark); font-weight: 800; }
.cal-day.has:hover { background: #e0e7ff; border-color: var(--accent); }
:root[data-theme="dark"] .cal-day.has:hover { background: #283549; }
.cal-day .cnt {
  position: absolute; top: 1px; right: 2px;
  font-size: 0.55rem; font-weight: 800; line-height: 1;
  background: var(--accent); color: #fff;
  border-radius: 999px; padding: 1px 4px; min-width: 12px; text-align: center;
}
.cal-day.sel { background: var(--accent); border-color: var(--accent); }
.cal-day.sel .d, .cal-day.sel .cnt { color: #fff; }
.cal-day.sel .cnt { background: rgba(255,255,255,0.28); }
.cal-selected {
  margin-top: 8px; display: none; align-items: center; gap: 10px; flex-wrap: wrap;
  font-size: 0.85rem; color: var(--accent-dark);
}
.cal-selected.show { display: flex; }
.cal-selected .clear {
  border: 1px solid var(--border); background: #fff; color: var(--muted);
  border-radius: 999px; padding: 3px 12px; cursor: pointer; font-size: 0.78rem;
}
.cal-selected .clear:hover { border-color: var(--accent); color: var(--accent); }
.cal-hint { margin-top: 6px; font-size: 0.68rem; color: var(--muted); text-align: center; }
@media (max-width: 520px) {
  .cal { padding: 10px 10px 12px; }
  .cal-day .d { font-size: 0.8rem; }
}

/* ===== カード ===== */
.cards { display: grid; gap: 12px; }
.card {
  background: var(--card); border-radius: 12px; border: 1px solid var(--border);
  box-shadow: var(--shadow); display: flex; gap: 14px; padding: 14px;
  transition: box-shadow 0.18s, transform 0.18s;
}
.card:hover { box-shadow: var(--shadow-hover); transform: translateY(-2px); }
.card .left { flex: 0 0 84px; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.datechip {
  width: 100%; border-radius: 10px;
  background: var(--accent-soft); color: var(--accent-dark);
  text-align: center; padding: 6px 2px 5px; line-height: 1.1;
  border: 1px solid var(--accent-soft-border);
}
.datechip .label { font-size: 0.6rem; font-weight: 700; letter-spacing: 0.08em; opacity: 0.8; }
.datechip .day { font-size: 1.25rem; font-weight: 800; }
.datechip .year { font-size: 0.62rem; opacity: 0.75; }
.thumb-wrap {
  width: 84px; height: 84px; border-radius: 10px;
  background: var(--c, #94a3b8);
  display: flex; align-items: center; justify-content: center; flex: 0 0 auto;
}
.thumb-letter { color: #fff; font-weight: 800; font-size: 2rem; user-select: none; line-height: 1; }

.card .body { flex: 1 1 auto; min-width: 0; }
.card .meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 5px; }
.badge {
  font-size: 0.7rem; font-weight: 700; padding: 2px 9px; border-radius: 999px;
  white-space: nowrap; color: #fff;
}
.badge.new { background: #ef4444; color: #fff; }
.badge.read {
  background: transparent; color: var(--muted);
  border: 1px solid var(--border); font-weight: 600;
}
.card h2 { margin: 0 0 3px; font-size: 1.04rem; line-height: 1.45; }
.card h2 a { color: var(--text); text-decoration: none; }
.card h2 a:hover { color: var(--accent); text-decoration: underline; }
.card .summary {
  margin: 0; font-size: 0.86rem; color: #374151;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.card .actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.act {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 0.72rem; color: var(--muted); text-decoration: none;
  border: 1px solid var(--border); border-radius: 999px;
  padding: 3px 10px; background: #fff; transition: all 0.15s; white-space: nowrap;
}
.act:hover { border-color: var(--accent); color: var(--accent); }
.act.primary { color: var(--accent); border-color: var(--accent-soft-border); background: var(--accent-soft); font-weight: 700; }

.empty, .error {
  text-align: center; color: var(--muted); padding: 48px 16px;
  background: #fff; border-radius: 12px; border: 1px dashed var(--border);
}
.error { color: #b91c1c; border-color: #fecaca; }

@media (max-width: 520px) {
  .card { gap: 10px; padding: 12px; }
  .card .left { flex-basis: 68px; }
  .thumb-wrap { width: 68px; height: 68px; }
  .thumb-letter { font-size: 1.6rem; }
  .datechip .day { font-size: 1.05rem; }
  .card h2 { font-size: 1rem; }
}

/* ===== 最近の記録（横スクロール） ===== */
.recent-wrap { max-width: 920px; margin: 16px auto 0; padding: 0 16px; }
.up-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 8px; }
.up-head .t { font-size: 1rem; font-weight: 800; }
.up-head .s { font-size: 0.72rem; color: var(--muted); }
.up-rail {
  display: flex; gap: 10px; overflow-x: auto; padding-bottom: 6px;
  scroll-snap-type: x mandatory; -webkit-overflow-scrolling: touch;
}
.up-card {
  scroll-snap-align: start; flex: 0 0 200px; max-width: 200px;
  background: var(--card); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: var(--shadow);
  padding: 12px; text-decoration: none; color: var(--text);
  display: flex; flex-direction: column; gap: 6px;
  transition: box-shadow 0.18s, transform 0.18s;
}
.up-card:hover { box-shadow: var(--shadow-hover); transform: translateY(-2px); }
.up-date {
  align-self: flex-start;
  background: var(--accent-soft); color: var(--accent-dark); border: 1px solid var(--accent-soft-border);
  border-radius: 8px; padding: 3px 9px; font-weight: 800; font-size: 0.82rem;
}
.up-card .up-title {
  font-size: 0.84rem; font-weight: 700; line-height: 1.4;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.up-card .up-tag { font-size: 0.7rem; color: var(--muted); }
.up-rail::-webkit-scrollbar { height: 6px; }
.up-rail::-webkit-scrollbar-thumb { background: var(--border); border-radius: 999px; }

/* 上に戻るボタン */
#toTop {
  position: fixed; right: 18px; bottom: 18px;
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--accent); color: #fff; border: none;
  box-shadow: var(--shadow-hover); cursor: pointer;
  font-size: 1.1rem; display: none; z-index: 20;
}
#toTop.show { display: block; }

footer {
  max-width: 920px; margin: 8px auto 40px; padding: 0 16px;
  font-size: 0.74rem; color: var(--muted); text-align: center;
}
footer .updated { margin-bottom: 6px; font-weight: 700; }

/* ===== 個別ページ ===== */
.crumb {
  max-width: 760px; margin: 14px auto 0; padding: 0 16px;
  font-size: 0.76rem; color: var(--muted);
}
.crumb a { color: var(--accent); text-decoration: none; }
.crumb a:hover { text-decoration: underline; }

article.entry {
  max-width: 760px; margin: 10px auto 0; padding: 0 16px;
}
.entry-head {
  background: var(--card); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: var(--shadow); padding: 18px 20px;
}
.entry-head h1 { margin: 8px 0 6px; font-size: 1.5rem; line-height: 1.4; }
.entry-head .meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.entry-head .lead { margin: 8px 0 0; font-size: 0.9rem; color: var(--muted); }
.entry-head .stamp { font-size: 0.76rem; color: var(--muted); margin-top: 10px; }

.prose {
  background: var(--card); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: var(--shadow); padding: 20px 22px; margin-top: 14px;
  font-size: 0.94rem;
}
.prose > :first-child { margin-top: 0; }
.prose > :last-child { margin-bottom: 0; }
.prose h2 {
  font-size: 1.12rem; margin: 26px 0 10px; padding-bottom: 6px;
  border-bottom: 2px solid var(--accent-soft-border);
}
.prose h3 { font-size: 1rem; margin: 20px 0 8px; }
.prose p { margin: 0 0 12px; }
.prose ul, .prose ol { margin: 0 0 12px; padding-left: 1.4em; }
.prose li { margin-bottom: 4px; }
.prose a { color: var(--accent); text-decoration: none; }
.prose a:hover { text-decoration: underline; }
.prose blockquote {
  margin: 0 0 12px; padding: 8px 14px;
  border-left: 3px solid var(--accent-soft-border);
  background: var(--accent-soft); border-radius: 0 8px 8px 0;
  color: var(--muted);
}
.prose blockquote p:last-child { margin-bottom: 0; }
.prose code {
  background: var(--code-bg); border: 1px solid var(--border);
  border-radius: 5px; padding: 1px 5px; font-size: 0.86em;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.prose pre {
  background: var(--code-bg); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px 14px; overflow-x: auto; margin: 0 0 12px;
}
.prose pre code { background: none; border: none; padding: 0; font-size: 0.84rem; }
.prose table { border-collapse: collapse; width: 100%; margin: 0 0 12px; font-size: 0.86rem; }
.prose th, .prose td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.prose th { background: var(--accent-soft); color: var(--accent-dark); }
.prose img { max-width: 100%; height: auto; border-radius: 8px; }
.prose hr { border: none; border-top: 1px solid var(--border); margin: 20px 0; }
.prose .table-scroll { overflow-x: auto; }

.entry-tail { max-width: 760px; margin: 14px auto 40px; padding: 0 16px; }
.sources {
  background: var(--card); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: var(--shadow); padding: 14px 18px; margin-bottom: 14px;
}
.sources h2 { margin: 0 0 8px; font-size: 0.9rem; }
.sources ul { margin: 0; padding-left: 1.2em; font-size: 0.84rem; }
.sources li { margin-bottom: 4px; }
.sources a { color: var(--accent); text-decoration: none; word-break: break-all; }
.sources a:hover { text-decoration: underline; }

.entry-nav { display: flex; gap: 10px; }
.nav-card {
  flex: 1 1 0; min-width: 0;
  background: #fff; border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow); padding: 10px 14px;
  text-decoration: none; color: var(--text);
  transition: box-shadow 0.18s, transform 0.18s;
}
.nav-card:hover { box-shadow: var(--shadow-hover); transform: translateY(-2px); }
.nav-card .dir { font-size: 0.7rem; color: var(--muted); font-weight: 700; }
.nav-card .t {
  font-size: 0.84rem; font-weight: 700; line-height: 1.4;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.nav-card.next { text-align: right; }
@media (max-width: 520px) { .entry-nav { flex-direction: column; } .nav-card.next { text-align: left; } }
