:root {
  color-scheme: light dark;
  --navy: #071e3d;
  --bg: #f4f6fa;
  --card: #ffffff;
  --text: #1f2937;
  --sub: #5b6675;
  --line: #cbd5e0;
  --pale: #e8eef6;
  --accent: #0f3a73;
  --on-accent: #ffffff;
  --warn: #b45309;
  --danger: #b42318;
  --ok: #17693a;
  --ok-bg: #e3f4e9;
  --warn-bg: #fdf1dc;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1320;
    --card: #152032;
    --text: #e6ebf2;
    --sub: #9aa7b8;
    --line: #2d3b50;
    --pale: #1e2c42;
    --accent: #9cc0f0;
    --on-accent: #071e3d;
    --warn: #f0b35c;
    --danger: #ff8d82;
    --ok: #7fd6a0;
    --ok-bg: #16342a;
    --warn-bg: #3a2c14;
  }
}
:root[data-theme="dark"] {
  --bg: #0b1320;
  --card: #152032;
  --text: #e6ebf2;
  --sub: #9aa7b8;
  --line: #2d3b50;
  --pale: #1e2c42;
  --accent: #9cc0f0;
  --on-accent: #071e3d;
  --warn: #f0b35c;
  --danger: #ff8d82;
  --ok: #7fd6a0;
  --ok-bg: #16342a;
  --warn-bg: #3a2c14;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic", sans-serif;
}
button, input, select, textarea { font: inherit; color: inherit; }

/* ヘッダー */
#top {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 52px;
  padding: calc(env(safe-area-inset-top) + 6px) 16px 6px;
  background: var(--navy);
  color: #fff;
}
#top h1 {
  flex: 1;
  min-width: 0;
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#month {
  flex: none;
  width: auto;
  appearance: none;
  -webkit-appearance: none;
  min-height: 36px;
  padding: 4px 12px;
  border: 1px solid rgba(255, 255, 255, .4);
  border-radius: 8px;
  background: rgba(255, 255, 255, .12);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
}
#month option { color: #111; }
#back {
  min-height: 36px;
  padding: 4px 6px 4px 0;
  border: 0;
  background: none;
  color: #fff;
  font-size: 16px;
  white-space: nowrap;
}
#badge {
  flex: none;
  padding: 2px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .16);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

/* 本文 */
#main {
  max-width: 640px;
  margin: 0 auto;
  padding: 12px 16px calc(env(safe-area-inset-bottom) + 92px);
}
body.detail #main { padding-bottom: calc(env(safe-area-inset-bottom) + 28px); }
.card {
  margin: 0 0 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
}
.card h2 { margin: 0 0 10px; font-size: 16px; font-weight: 700; }
.card h2 small { display: block; margin-top: 1px; color: var(--sub); font-size: 13px; font-weight: 400; }
.note { margin: 0 0 12px; color: var(--sub); font-size: 13px; }
.card .note:last-child { margin-bottom: 0; }

.field { margin: 12px 0 0; }
.field:first-of-type { margin-top: 0; }
h2 + .seg, h2 + .choices { margin-bottom: 12px; }
.field > label, .label { display: block; margin-bottom: 4px; color: var(--sub); font-size: 13px; font-weight: 600; }
input[type="text"], input[type="date"], input[type="time"], input[type="number"], select, textarea {
  display: block;
  width: 100%;
  min-height: 44px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  font-size: 16px; /* 16px未満だとiOSが入力時に拡大するため */
}
input[type="date"], input[type="time"] { appearance: none; -webkit-appearance: none; }
input::-webkit-date-and-time-value { text-align: left; }
textarea { min-height: 72px; padding-right: 54px; resize: none; overflow: hidden; line-height: 1.5; }
input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: transparent;
}
.ta { position: relative; }
.mic {
  position: absolute;
  top: 6px;
  right: 6px;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: var(--pale);
  color: var(--accent);
}
.mic svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.mic.on { background: var(--danger); color: #fff; animation: pulse 1.2s ease-in-out infinite; }
textarea.rec { border-color: var(--danger); }
@keyframes pulse { 50% { opacity: .55; } }
@media (prefers-reduced-motion: reduce) { .mic.on { animation: none; } }
.count { margin-top: 3px; color: var(--sub); font-size: 12px; text-align: right; font-variant-numeric: tabular-nums; }
.count.over { color: var(--warn); font-weight: 600; }

.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.two .field { margin: 0; }
.withbtn { display: flex; gap: 6px; }
.withbtn input { flex: 1; min-width: 0; }
.now {
  flex: none;
  min-width: 44px;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--pale);
  color: var(--accent);
  font-size: 14px;
  font-weight: 600;
}

/* 選択肢 */
.seg { display: grid; grid-template-columns: repeat(var(--n, 4), 1fr); gap: 6px; }
.seg.n2 { --n: 2; }
.seg.n4 { --n: 4; }
.seg label, .choices label { position: relative; display: block; }
.seg input, .choices input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
}
.seg span {
  display: grid;
  place-items: center;
  min-height: 46px;
  padding: 4px 2px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.25;
  text-align: center;
}
.seg input:checked + span { border-color: var(--accent); background: var(--accent); color: var(--on-accent); }
.seg.danger input[value="あり"]:checked + span { border-color: var(--danger); background: var(--danger); color: #fff; }
.seg input:focus-visible + span, .choices input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.choices { display: grid; gap: 6px; }
.choices span {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 46px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  font-size: 15px;
  font-weight: 600;
}
.choices span::before {
  content: "";
  flex: none;
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border: 2px solid var(--line);
  border-radius: 50%;
  background: var(--card);
  color: var(--on-accent);
  font-size: 13px;
  line-height: 1;
}
.choices.check span::before { border-radius: 5px; }
.choices input:checked + span { border-color: var(--accent); background: var(--pale); }
.choices input:checked + span::before { content: "✓"; border-color: var(--accent); background: var(--accent); }

/* 写真 */
.strip { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.thumb { position: relative; width: 72px; height: 72px; overflow: hidden; border: 1px solid var(--line); border-radius: 8px; background: var(--pale); }
.thumb img { display: block; width: 100%; height: 100%; object-fit: cover; }
.thumb b { position: absolute; left: 3px; bottom: 3px; padding: 0 5px; border-radius: 5px; background: rgba(7, 30, 61, .85); color: #fff; font-size: 11px; font-weight: 600; }
.addphoto {
  display: grid;
  place-items: center;
  width: 72px;
  height: 72px;
  padding: 4px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: none;
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.3;
}
.photo { display: grid; grid-template-columns: 72px 1fr; gap: 10px; padding: 12px 0; border-top: 1px solid var(--line); }
.photo:first-of-type { border-top: 0; padding-top: 0; }
.photo .field { margin: 0 0 8px; }
.photo .textbtn { justify-self: start; }

/* ボタン・リスト */
.primary, .secondary {
  display: block;
  width: 100%;
  min-height: 48px;
  padding: 10px 14px;
  border-radius: 10px;
  font-weight: 700;
}
.primary { border: 0; background: var(--accent); color: var(--on-accent); }
.primary:disabled { opacity: .5; }
.secondary { border: 1px solid var(--line); background: var(--card); color: var(--accent); }
.buttons { display: grid; gap: 8px; margin-top: 12px; }
.textbtn { min-height: 44px; padding: 0 2px; border: 0; background: none; color: var(--danger); font-size: 14px; font-weight: 600; }
.storecard {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  margin: 0 0 8px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  text-align: left;
}
.storecard .main { flex: 1; min-width: 0; }
.storecard strong { display: block; font-size: 16px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.storecard small { display: block; color: var(--sub); font-size: 13px; }
.pill { flex: none; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums; }
.pill.done { background: var(--ok-bg); color: var(--ok); }
.pill.todo { background: var(--warn-bg); color: var(--warn); }
.empty { padding: 28px 12px; color: var(--sub); text-align: center; }

/* 集計表 */
.tally { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
.tally th, .tally td { padding: 7px 3px; border-bottom: 1px solid var(--line); text-align: center; font-weight: 400; }
.tally thead th { color: var(--sub); font-size: 12px; font-weight: 600; }
.tally th:first-child { text-align: left; font-weight: 600; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.stats div { padding: 8px; border-radius: 8px; background: var(--pale); text-align: center; }
.stats b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; }
.stats span { color: var(--sub); font-size: 12px; }
details { margin-top: 6px; font-size: 14px; }
summary { min-height: 32px; padding: 4px 0; color: var(--accent); font-size: 13px; font-weight: 600; }
details ul { margin: 2px 0 0; padding-left: 18px; }
details li { margin: 4px 0; overflow-wrap: anywhere; }
.status { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.status span:first-child { flex: none; }
.status span:last-child { min-width: 0; font-weight: 600; text-align: right; overflow-wrap: anywhere; }
.status .bad { color: var(--warn); }
.alert { margin: 12px 0 0; padding: 10px 12px; border-radius: 8px; background: var(--warn-bg); color: var(--text); font-size: 13px; }
.alert ul { margin: 4px 0 0; padding-left: 18px; }
.result { margin: 12px 0 0; padding: 10px 12px; border-radius: 8px; background: var(--ok-bg); font-size: 14px; overflow-wrap: anywhere; }

/* タブ */
#tabs {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding-bottom: env(safe-area-inset-bottom);
  border-top: 1px solid var(--line);
  background: var(--card);
}
#tabs button {
  display: grid;
  justify-items: center;
  gap: 1px;
  min-height: 52px;
  padding: 6px 0 4px;
  border: 0;
  background: none;
  color: var(--sub);
  font-size: 11px;
  font-weight: 600;
}
#tabs svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
#tabs button[aria-current="page"] { color: var(--accent); }
body.detail #tabs, body.typing #tabs { display: none; }

#toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(env(safe-area-inset-bottom) + 70px);
  z-index: 20;
  max-width: 560px;
  margin: 0 auto;
  padding: 10px 14px;
  border-radius: 10px;
  background: #111827;
  color: #fff;
  font-size: 14px;
  text-align: center;
}
body.typing #toast { top: calc(env(safe-area-inset-top) + 58px); bottom: auto; }
