:root {
  --bg: #f5f4f0;
  --card: #ffffff;
  --text: #24303f;
  --muted: #5d6878;
  --line: #e1e3e8;
  --accent: #4e6e9e;
  --accent-soft: #e3ecf7;
  --on-accent: #ffffff;
  --danger: #b23a3a;
  --warn-bg: #fbf0e1;
  --warn-text: #7a5212;
  --verse-bg: #ece8f6;
  --verse-ink: #6a5ba8;

  /* body map */
  --body: #d9dce1;
  --body-line: #b7bdc6;
  --zone: #a9c8e8;
  --keepout: #ffffff;
  --dot-now: #2c3e78;
  --dot-prev: #c9782c;

  --radius: 14px;
  --tabbar-h: 64px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101318;
    --card: #1a1e25;
    --text: #e4e9f1;
    --muted: #9aa5b5;
    --line: #2a303a;
    --accent: #9db8e6;
    --accent-soft: #1f2a3a;
    --on-accent: #101318;
    --danger: #ff7a6b;
    --warn-bg: #3a2e1c;
    --warn-text: #f3cf95;
    --verse-bg: #252236;
    --verse-ink: #c5bbf0;

    --body: #3b414b;
    --body-line: #555d69;
    --zone: #3a5e86;
    --keepout: #1a1e25;
    --dot-now: #eef2ff;
    --dot-prev: #f2a65a;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

#app {
  max-width: 640px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 12px) 16px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 24px);
}

body.no-tabs #app { padding-bottom: calc(env(safe-area-inset-bottom) + 32px); }
body.no-tabs .tabbar { display: none; }

h1 { font-size: 28px; line-height: 1.15; margin: 8px 0 16px; letter-spacing: -0.01em; }
h2 { font-size: 17px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 16px 0 6px; color: var(--muted); font-weight: 600; }
p { margin: 0 0 8px; }

a { color: var(--accent); }

.muted { color: var(--muted); }
.small { font-size: 14px; }
.center { text-align: center; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  margin: 0 0 14px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.card.warn { background: var(--warn-bg); color: var(--warn-text); }
.card.warn a { color: inherit; font-weight: 600; }

/* ---------- buttons ---------- */

button { font: inherit; color: inherit; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 10px 16px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}

.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.danger { color: var(--danger); }
.btn.block { display: flex; width: 100%; }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: 14px; }

.link-btn {
  background: none;
  border: 0;
  padding: 10px 4px;
  color: var(--accent);
  font-weight: 600;
  cursor: pointer;
  min-height: 44px;
}

.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-row > .btn { flex: 1 1 auto; }

/* ---------- sheet header ---------- */

.sheet-head {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  margin: calc(-12px - env(safe-area-inset-top)) -16px 12px;
  padding: calc(env(safe-area-inset-top) + 4px) 12px 4px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.sheet-head h1 { font-size: 17px; margin: 0; text-align: center; }
.sheet-head > :first-child { justify-self: start; }
.sheet-head > :last-child { justify-self: end; }

/* ---------- forms ---------- */

.field { display: block; margin: 0 0 12px; min-width: 0; }
.field:last-child { margin-bottom: 0; }
.field > .label, .field > label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  margin: 0 0 4px;
}

input[type="text"], input[type="date"], input[type="time"], input[type="number"],
input:not([type]), textarea, select {
  width: 100%;
  min-height: 44px;
  font: inherit;
  font-size: 16px; /* prevents iOS zoom */
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  -webkit-appearance: none;
  appearance: none;
}

input[type="date"], input[type="time"] { display: block; min-width: 0; }
input::-webkit-date-and-time-value { text-align: left; }

textarea { min-height: 76px; resize: vertical; }

input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row2 > .field { margin-bottom: 12px; }

.times { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.times > .field { margin-bottom: 0; }
@media (max-width: 480px) { .times { grid-template-columns: 1fr; gap: 12px; } }

.with-btn { display: flex; gap: 6px; }
.with-btn input { flex: 1; min-width: 0; }
.with-btn .btn { padding: 8px 10px; font-size: 14px; }

.seg {
  display: flex;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 3px;
  gap: 3px;
}
.seg label, .seg button {
  flex: 1;
  text-align: center;
  padding: 8px 6px;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  border: 0;
  background: none;
  min-height: 38px;
}
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label:has(input:checked), .seg button[aria-pressed="true"] {
  background: var(--card);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
}

.hint { font-size: 14px; color: var(--muted); margin: 4px 0 0; }

.vial {
  display: grid;
  grid-template-columns: 1fr 1fr 40px;
  gap: 8px;
  align-items: end;
  margin-bottom: 10px;
}
.vial .remove {
  width: 40px; height: 44px;
  border: 0; background: none; color: var(--muted);
  font-size: 22px; cursor: pointer;
}

/* ---------- body map ---------- */

.map-wrap { position: relative; margin: 8px 0 4px; }
.map-sides {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 0 2px 4px;
}
.bodymap {
  display: block;
  width: 100%;
  max-height: 62vh;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
.bodymap.tappable { cursor: crosshair; }
.bodymap .body * { fill: var(--body); stroke: var(--body-line); stroke-width: 0.6; }
.bodymap .zone { fill: var(--zone); }
.bodymap .keepout { fill: var(--keepout); }
.bodymap .navel { fill: var(--body-line); }
.bodymap .face { fill: none; stroke: var(--body-line); stroke-width: 0.8; stroke-linecap: round; }
.bodymap .dot-now { fill: var(--dot-now); stroke: #fff; }
.bodymap .dot-prev { fill: var(--dot-prev); fill-opacity: 0.25; stroke: var(--dot-prev); }
.bodymap .dot-hist { fill: var(--dot-prev); stroke: #fff; }
.bodymap .dot-label { fill: #fff; font-weight: 700; text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.bodymap .dot-label.prev { fill: var(--dot-prev); }

@media (prefers-color-scheme: dark) {
  .bodymap .dot-now { stroke: #101318; }
  .bodymap .dot-label { fill: #1a2340; }
  .bodymap .dot-hist { stroke: #101318; }
}

.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 13px; color: var(--muted); margin: 6px 0 0; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.sw { width: 12px; height: 12px; border-radius: 50%; display: inline-block; flex: none; }
.sw.now { background: var(--dot-now); }
.sw.prev { background: color-mix(in srgb, var(--dot-prev) 25%, transparent); border: 2px solid var(--dot-prev); }
.sw.hist { background: var(--dot-prev); }

.site-summary { font-size: 14px; margin-top: 10px; }
.site-summary ol { margin: 4px 0 0; padding-left: 20px; }

/* ---------- weekly verse ---------- */

.verse { background: var(--verse-bg); margin: 0 0 14px; }
.verse-week { font-size: 12px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--verse-ink); margin-bottom: 6px; }
.verse blockquote { margin: 0; font-family: "Iowan Old Style", "Palatino Linotype", Georgia, serif; font-size: 18px; line-height: 1.5; }
.verse .lord { font-variant: small-caps; }
.verse figcaption { margin-top: 8px; font-size: 14px; font-weight: 600; color: var(--muted); }
.verse figcaption span { font-weight: 500; font-size: 12px; opacity: 0.8; }
.verse.compact blockquote { font-size: 16px; }
.verse-note { margin: 4px 0 0; font-family: "Iowan Old Style", "Palatino Linotype", Georgia, serif; font-style: italic; font-size: 14px; line-height: 1.45; color: var(--verse-ink); }
.verse-note span { font-family: -apple-system, BlinkMacSystemFont, sans-serif; font-style: normal; font-weight: 600; font-size: 12px; white-space: nowrap; }

/* ---------- log list ---------- */

.due { display: flex; gap: 14px; align-items: center; }
.due .big { font-size: 20px; font-weight: 700; line-height: 1.2; }
.due .badge {
  flex: none;
  width: 52px; height: 52px;
  border-radius: 14px;
  display: grid; place-items: center;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 800;
  font-size: 20px;
  line-height: 1;
  text-align: center;
}
.due .badge small { display: block; font-size: 10px; font-weight: 700; text-transform: uppercase; }
.due.overdue .badge { background: var(--warn-bg); color: var(--warn-text); }

.list { list-style: none; margin: 0; padding: 0; }
.list-month { font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; margin: 18px 4px 6px; }

.entry {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--card);
  text-decoration: none;
  color: inherit;
  border-bottom: 1px solid var(--line);
}
.list li:first-child .entry { border-radius: var(--radius) var(--radius) 0 0; }
.list li:last-child .entry { border-radius: 0 0 var(--radius) var(--radius); border-bottom: 0; }
.list li:only-child .entry { border-radius: var(--radius); }
.entry .date { flex: none; width: 44px; text-align: center; line-height: 1.1; }
.entry .date b { display: block; font-size: 22px; }
.entry .date small { font-size: 11px; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.entry .info { flex: 1; min-width: 0; }
.entry .info .t { font-weight: 600; }
.entry .info .s { font-size: 14px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.entry .flags { flex: none; display: flex; gap: 4px; }
.flag { font-size: 11px; font-weight: 700; padding: 2px 6px; border-radius: 6px; background: var(--warn-bg); color: var(--warn-text); }
.flag.q { background: var(--accent-soft); color: var(--accent); }
.chev { color: var(--muted); flex: none; }

.empty { text-align: center; padding: 32px 16px; }
.empty svg { width: 64px; height: 64px; color: var(--accent); margin-bottom: 8px; }

/* ---------- detail ---------- */

dl.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 0; }
dl.kv dt { color: var(--muted); font-size: 14px; }
dl.kv dd { margin: 0; font-weight: 600; }
.note-block { white-space: pre-wrap; margin: 0; }

/* ---------- settings list ---------- */

.menu { list-style: none; margin: 0; padding: 0; }
.menu li + li { border-top: 1px solid var(--line); }
.menu button, .menu a, .menu label.menu-item {
  display: flex; width: 100%; align-items: center; justify-content: space-between;
  min-height: 48px; padding: 10px 0; border: 0; background: none;
  font: inherit; color: var(--text); text-align: left; text-decoration: none; cursor: pointer;
}
.menu .danger { color: var(--danger); }
.menu small { color: var(--muted); font-size: 13px; }

/* ---------- report ---------- */

.report table { width: 100%; border-collapse: collapse; font-size: 13px; }
.report th, .report td { border-bottom: 1px solid var(--line); padding: 6px 6px; text-align: left; vertical-align: top; }
.report th { font-size: 12px; color: var(--muted); }
.report .scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.report td.notes { min-width: 180px; white-space: pre-wrap; }

/* ---------- tab bar ---------- */

.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 10;
  display: flex;
  justify-content: space-around;
  padding: 6px 8px calc(env(safe-area-inset-bottom) + 6px);
  background: color-mix(in srgb, var(--card) 92%, transparent);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
}
.tabbar a {
  flex: 1;
  max-width: 120px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 4px 0;
  color: var(--muted);
  text-decoration: none;
  font-size: 11px;
  font-weight: 600;
}
.tabbar svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabbar svg .fill { fill: currentColor; stroke: none; }
.tabbar a[aria-current="page"] { color: var(--accent); }
.tabbar .tab-add svg { background: var(--accent); color: var(--on-accent); border-radius: 50%; padding: 3px; stroke-width: 2.4; }

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
  transform: translateX(-50%);
  z-index: 20;
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 12px;
  background: var(--text);
  color: var(--bg);
  font-size: 15px;
  font-weight: 600;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
}

@media (max-width: 360px) {
  .row2 { grid-template-columns: 1fr; gap: 0; }
}

/* ---------- print ---------- */

@media print {
  :root { --bg: #fff; --card: #fff; --text: #000; --muted: #444; --line: #bbb; }
  body { background: #fff; }
  .no-print, .tabbar, .toast, .sheet-head { display: none !important; }
  #app { max-width: none; padding: 0; }
  .card { box-shadow: none; padding: 0; }
  .report .scroll { overflow: visible; }
  .report table { font-size: 10px; }
}
