:root {
  --bg: #f6f3ee;
  --surface: #ffffff;
  --text: #2b2723;
  --muted: #7a726a;
  --line: #e4ddd3;
  --accent: #5b4a8a;
  --accent-soft: #ece8f5;
  --kinichi: #8a5a2b;
  --kinichi-bg: #f6ebdf;
  --nenki: #5b4a8a;
  --nenki-bg: #ece8f5;
  --shotsuki: #4b6b5a;
  --shotsuki-bg: #e5efe9;
  --irei: #3f5f86;
  --irei-bg: #e3ebf5;
  --danger: #b3413a;
  --today-bg: #fff6d9;
  --radius: 12px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1a18;
    --surface: #26231f;
    --text: #ece6de;
    --muted: #a39a90;
    --line: #3a352f;
    --accent: #b3a4e0;
    --accent-soft: #332e44;
    --kinichi: #e4b78a;
    --kinichi-bg: #3b2e22;
    --nenki: #c4b8ec;
    --nenki-bg: #332e44;
    --shotsuki: #9fcbb2;
    --shotsuki-bg: #243229;
    --irei: #9dbbe0;
    --irei-bg: #243040;
    --danger: #f08a82;
    --today-bg: #3a3320;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Hiragino Mincho ProN", "Yu Mincho", "YuMincho", serif;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}

button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }

.container { max-width: 760px; margin: 0 auto; padding: 16px 16px 64px; }

/* ヘッダー */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 16px;
  padding: 10px 16px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.topbar[hidden] { display: none; }
.brand { font-weight: 700; font-size: 1.15rem; color: var(--text); text-decoration: none; letter-spacing: .1em; display: flex; flex-direction: column; line-height: 1.15; white-space: nowrap; }
.brand small { font-size: .58rem; font-weight: normal; letter-spacing: .08em; color: var(--muted); font-style: italic; }
.login-sub { margin: -8px 0 0; color: var(--muted); font-style: italic; letter-spacing: .12em; }
.nav { display: flex; gap: 4px; flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a { padding: 6px 10px; border-radius: 8px; color: var(--muted); text-decoration: none; font-size: .95rem; white-space: nowrap; }
.nav a.active { color: var(--text); background: var(--surface); box-shadow: 0 0 0 1px var(--line); }
.linkbtn { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: .85rem; padding: 6px; }

.demo-banner { background: var(--today-bg); color: var(--text); font-size: .8rem; padding: 6px 16px; text-align: center; }

/* 見出し */
h1 { font-size: 1.5rem; margin: 0; font-weight: 700; }
h2 { font-size: 1.1rem; margin: 32px 0 12px; display: flex; align-items: center; gap: 8px; }
.eyebrow { margin: 0; color: var(--muted); font-size: .85rem; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin: 8px 0 16px; flex-wrap: wrap; }
.count {
  display: inline-block; min-width: 1.6em; padding: 0 6px; border-radius: 99px;
  background: var(--accent-soft); color: var(--accent); font-size: .8rem; text-align: center; font-weight: 600;
}
.date-head { font-size: .95rem; margin: 18px 0 8px; display: flex; gap: 10px; align-items: baseline; }
.date-head .muted { font-size: .8rem; font-weight: normal; }

.muted { color: var(--muted); }
.small { font-size: .8rem; }
.empty { color: var(--muted); padding: 20px; text-align: center; background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); margin: 0; }

/* ボタン */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 9px 16px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); text-decoration: none; cursor: pointer; font-size: .95rem;
  min-height: 42px;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--surface); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--line)); }
.btn:disabled { opacity: .5; cursor: default; }
.actions { display: flex; gap: 10px; margin-top: 28px; flex-wrap: wrap; }

/* カード */
.cards { display: grid; gap: 8px; }
.card {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 14px 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  color: var(--text); text-decoration: none;
  transition: border-color .15s, transform .15s;
}
.card:hover { border-color: var(--accent); }
.card:active { transform: scale(.99); }
.card-main { flex: 1; min-width: 0; }
.card-name { font-size: 1.1rem; font-weight: 700; }
.card-sub { color: var(--muted); font-size: .85rem; }
.homyo { font-weight: normal; color: var(--muted); font-size: .85rem; margin-left: 10px; }

.badge {
  display: inline-block; font-size: .78rem; padding: 1px 8px; border-radius: 6px; font-weight: 600; margin-bottom: 4px;
  white-space: nowrap;
}
.badge.kinichi { background: var(--kinichi-bg); color: var(--kinichi); }
.badge.nenki { background: var(--nenki-bg); color: var(--nenki); }
.badge.shotsuki { background: var(--shotsuki-bg); color: var(--shotsuki); }

.tag {
  flex: none; font-size: .75rem; padding: 2px 8px; border-radius: 99px;
  border: 1px solid var(--line); color: var(--muted); white-space: nowrap;
}

/* お知らせ */
.notice { display: block; padding: 12px 16px; border-radius: var(--radius); background: var(--accent-soft); color: var(--text); margin: 12px 0; text-decoration: none; }
.notice.link:hover { outline: 1px solid var(--accent); }
.notice.today { background: var(--today-bg); }
.notice.error { background: color-mix(in srgb, var(--danger) 15%, var(--surface)); }
.error-text { color: var(--danger); min-height: 1.2em; margin: 8px 0 0; font-size: .9rem; }

/* 一覧：検索・フィルター */
.search {
  width: 100%; padding: 10px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface);
}
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin: 12px 0 16px; }
.chip {
  padding: 5px 12px; border-radius: 99px; border: 1px solid var(--line); background: var(--surface);
  color: var(--muted); text-decoration: none; font-size: .85rem;
}
.chip-sep { width: 1px; background: var(--line); margin: 2px 2px; }
.chip.active { background: var(--accent); border-color: var(--accent); color: var(--surface); }

/* 詳細 */
.back { display: inline-block; margin: 4px 0 12px; color: var(--muted); text-decoration: none; font-size: .9rem; }
.detail-head { margin-bottom: 12px; }
.detail-head h1 { font-size: 1.8rem; margin-top: 4px; }
.homyo-lg { margin: 4px 0 0; color: var(--muted); }
.status-box {
  display: grid; gap: 6px; padding: 14px 16px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line); margin: 12px 0;
}
.status-box .label { display: inline-block; width: 5.5em; color: var(--muted); font-size: .85rem; }
.summary {
  margin: 0; padding: 14px 16px; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); line-height: 1.9; white-space: pre-wrap;
}
.facts { display: grid; grid-template-columns: 7em 1fr; gap: 8px 12px; margin: 20px 0 0; }
.facts dt { color: var(--muted); font-size: .9rem; }
.facts dd { margin: 0; }
.facts .note { white-space: pre-wrap; }

.plan { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); }
.plan td { padding: 9px 12px; border-top: 1px solid var(--line); font-size: .92rem; white-space: nowrap; }
.plan tr:first-child td { border-top: 0; }
.plan td .badge { margin: 0; }
.plan .rel { text-align: right; color: var(--muted); white-space: nowrap; }
.plan tr.done td { color: var(--muted); }
.plan tr.done .badge { opacity: .5; }
.plan tr.next td { background: var(--accent-soft); }
.plan tr.is-today td { background: var(--today-bg); font-weight: 700; }

/* フォーム */
.form { display: grid; gap: 14px; margin-top: 16px; }
.form label { display: grid; gap: 4px; font-size: .9rem; color: var(--muted); }
.form label em { font-style: normal; font-size: .72rem; color: var(--danger); margin-left: 4px; }
.form input, .form select, .form textarea {
  padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--text);
  width: 100%; min-height: 44px;
}
.form input:focus, .form select:focus, .form textarea:focus, .search:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.form .row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ログイン */
.login { text-align: center; padding: 18vh 0 0; display: grid; gap: 12px; justify-items: center; }
.login-mark { font-size: 3rem; }
.login h1 { letter-spacing: .2em; font-size: 2rem; }

.login-links { margin-top: 24px; font-size: .92rem; }

/* 追悼・慰霊の日 */
.irei-link { margin-top: 28px; border-left: 3px solid var(--irei); background: var(--irei-bg); }
.badge.irei { background: var(--irei-bg); color: var(--irei); }
.card.memorial { border-left: 3px solid var(--irei); }
.memorial-section { margin-top: 12px; padding-top: 4px; border-top: 1px dashed var(--line); }
.h2-link { margin-left: auto; font-size: .85rem; font-weight: normal; text-decoration: none; }
.small-empty { padding: 12px; font-size: .9rem; }
.notice.preset { background: var(--surface); border: 1px solid var(--line); display: grid; gap: 8px; justify-items: start; }
.notice.preset details { font-size: .88rem; color: var(--muted); }
.notice.preset summary { cursor: pointer; }
.notice.preset ul { margin: 6px 0 0; padding-left: 1.2em; }

/* 日付ナビ */
.datenav {
  display: grid; gap: 10px; margin: 20px 0 4px; padding: 12px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
}
.datenav-pick { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.datenav-pick input {
  padding: 8px 12px; min-height: 42px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text);
}
.datenav-pick .btn { margin-left: auto; }
.datenav-steps { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.datenav-steps .btn { padding: 8px 4px; font-size: .88rem; white-space: nowrap; }
@media (max-width: 520px) {
  .datenav-steps .btn { font-size: .8rem; }
  .datenav-pick { flex-wrap: nowrap; }
  .datenav-pick input { flex: 1; min-width: 0; }
  .datenav-rel { display: none; }
}

/* ページ送り */
#all { scroll-margin-top: 64px; }
.pager { display: flex; justify-content: center; align-items: center; gap: 4px; flex-wrap: wrap; margin: 20px 0 4px; }
.pager a, .pager span {
  min-width: 40px; min-height: 40px; padding: 0 10px; display: inline-flex; align-items: center; justify-content: center;
  border-radius: 10px; font-size: .92rem; text-decoration: none;
}
.pager a { border: 1px solid var(--line); background: var(--surface); color: var(--text); }
.pager a:hover { border-color: var(--accent); }
.pager .current { background: var(--accent); color: var(--surface); font-weight: 700; }
.pager .disabled { color: var(--line); }
.pager .gap { min-width: 20px; padding: 0; color: var(--muted); }
.pager-summary { text-align: center; color: var(--muted); font-size: .8rem; margin: 4px 0 0; }

/* 資料ページ */
.plan a.badge { text-decoration: none; }
.plan a.badge:hover { outline: 1px solid currentColor; }
.doc { line-height: 1.9; }
.doc h1 { font-size: 1.8rem; }
.doc h2 { font-size: 1.2rem; margin: 0 0 8px; flex-wrap: wrap; }
.doc section, .doc [id] { scroll-margin-top: 72px; }
.doc section { padding: 20px 0; border-top: 1px solid var(--line); }
.doc p { margin: 0 0 10px; }
.doc ul { margin: 0 0 10px; padding-left: 1.3em; }
.doc li { margin-bottom: 4px; }
.lead { color: var(--muted); margin-top: 8px !important; }
.when { font-size: .8rem; font-weight: normal; color: var(--muted); padding: 1px 10px; border: 1px solid var(--line); border-radius: 99px; }
.group-title {
  margin: 36px 0 0 !important; font-size: .85rem; letter-spacing: .15em; color: var(--accent); font-weight: 700;
}
.aside { font-size: .88rem; color: var(--muted); padding: 10px 14px; border-left: 3px solid var(--line); background: var(--surface); border-radius: 0 8px 8px 0; }
.terms { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0 0 12px; }
.terms dt { font-weight: 700; }
.terms dd { margin: 0; }
.toc {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px 20px;
  padding: 16px; margin: 20px 0 8px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
}
.toc a { display: block; font-size: .92rem; text-decoration: none; padding: 2px 0; }
.toc a:hover { text-decoration: underline; }
.toc-head { margin: 0 0 4px !important; font-size: .75rem; color: var(--muted); letter-spacing: .1em; }
.table-wrap { overflow-x: auto; margin: 8px 0 4px; }
.plan.ref th { text-align: left; font-size: .8rem; color: var(--muted); font-weight: normal; padding: 8px 12px; background: var(--bg); }
.footnote { margin-top: 28px !important; }
:target { animation: flash 1.6s ease-out; }
@keyframes flash { from { background: var(--today-bg); } to { background: transparent; } }

@media (max-width: 520px) {
  .terms { grid-template-columns: 1fr; gap: 0; }
  .terms dd { margin-bottom: 8px; }
  .topbar { gap: 8px; padding: 8px 12px; }
  .nav a { padding: 6px 8px; font-size: .88rem; }
  .form .row { grid-template-columns: 1fr; }
  .page-head .btn { width: 100%; }
  .plan td { padding: 8px; font-size: .85rem; white-space: normal; }
}
