:root {
  color-scheme: light dark;
  --bg: #f6f3ec; --card: #fffdf8; --ink: #24302b; --sub: #65706a; --line: #ddd7c9;
  --accent: #1f4d3f; --on-accent: #fff; --star: #a8541f; --danger: #b3261e;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171a18; --card: #222724; --ink: #ecebe4; --sub: #a3ada7; --line: #39413c;
    --accent: #8fcdb5; --on-accent: #10241d; --star: #f0a56f; --danger: #ff8a80;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.5 -apple-system, "Hiragino Sans", sans-serif;
  -webkit-text-size-adjust: 100%;
}
/* 16px未満だとiPhoneが入力時に拡大する */
button, input, textarea { font: inherit; color: inherit; }
button, label { touch-action: manipulation; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

header, main, dialog {
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
}
header {
  position: sticky; top: 0; z-index: 1; background: var(--bg);
  padding-top: calc(8px + env(safe-area-inset-top)); padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}
main { max-width: 720px; margin: auto; padding-top: 12px; padding-bottom: calc(104px + env(safe-area-inset-bottom)); }
.bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 44px; }
h1 { font-size: 24px; margin: 0; }
h2 { font-size: 17px; margin: 0; }
.plain { border: 0; background: none; color: var(--accent); min-height: 44px; padding: 0 4px; }
.strong { font-weight: 700; }

input:not([type=radio], [type=file]), textarea {
  width: 100%; min-width: 0; min-height: 44px; padding: 9px 12px; border: 1px solid var(--line);
  border-radius: 10px; background: var(--card); -webkit-appearance: none; appearance: none;
}
textarea { resize: vertical; }
.tabs { display: flex; gap: 4px; margin-top: 8px; }
.tabs button {
  flex: 1; min-height: 44px; padding: 0 2px; border: 0; border-radius: 10px;
  background: none; color: var(--sub); font-size: 14px; white-space: nowrap;
}
.tabs button[aria-pressed=true] { background: var(--accent); color: var(--on-accent); font-weight: 700; }

ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.book {
  width: 100%; text-align: left; padding: 14px 16px; border: 1px solid var(--line);
  border-radius: 14px; background: var(--card); display: grid; gap: 2px; overflow-wrap: anywhere;
}
.book b { font-size: 17px; line-height: 1.4; }
.sub { color: var(--sub); font-size: 14px; margin: 0; }
.stars { color: var(--star); }
.empty { text-align: center; color: var(--sub); padding: 56px 16px; }
.add {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(16px + env(safe-area-inset-bottom));
  min-height: 52px; padding: 0 28px; border: 0; border-radius: 26px; font-weight: 700;
  background: var(--accent); color: var(--on-accent); box-shadow: 0 4px 14px #0004;
}
.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(84px + env(safe-area-inset-bottom)); margin: auto;
  width: fit-content; padding: 10px 18px; border-radius: 12px; background: var(--ink); color: var(--bg);
}

dialog {
  width: 100%; max-width: 720px; height: 100%; height: 100dvh; max-height: none; margin: 0 auto; border: 0;
  background: var(--bg); color: var(--ink); overflow-y: auto; overscroll-behavior: contain;
  padding-top: 0; padding-bottom: calc(24px + env(safe-area-inset-bottom));
}
dialog .bar {
  position: sticky; top: 0; z-index: 1; background: var(--bg);
  padding-top: calc(8px + env(safe-area-inset-top)); padding-bottom: 8px;
}
form { display: grid; gap: 16px; }
form > label, .dates label { display: grid; gap: 4px; font-size: 14px; color: var(--sub); }
label input, label textarea { font-size: 16px; color: var(--ink); }
.dates { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.dates label { min-width: 0; }
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
legend { font-size: 14px; color: var(--sub); padding: 0 0 4px; }
.segments { display: flex; border: 1px solid var(--line); border-radius: 10px; background: var(--card); overflow: hidden; }
.segments label { flex: 1; min-height: 44px; display: grid; place-items: center; position: relative; }
.segments input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; }
.segments label:has(:checked) { background: var(--accent); color: var(--on-accent); font-weight: 700; }
.segments label:has(:focus-visible) { outline: 2px solid var(--star); outline-offset: -3px; border-radius: 10px; }
.danger { min-height: 48px; border: 1px solid var(--line); border-radius: 10px; background: none; color: var(--danger); }
.error { color: var(--danger); margin: 0; }
.block {
  display: grid; place-items: center; position: relative; width: 100%; min-height: 50px; margin: 16px 0;
  border: 1px solid var(--accent); border-radius: 12px; background: var(--accent); color: var(--on-accent); font-weight: 700;
}
.block.secondary { background: none; color: var(--accent); }
.block input { position: absolute; inset: 0; opacity: 0; width: 100%; }
