:root {
  --paper: #f4eedf; --page: #fffaf0; --ink: #2a2620; --sub: #6f6656; --rule: #e3d9c2; --line: #d6cab0;
  --shu: #c8432b; --shu-bg: #fbe6df; --kin: #b9791a; --kin-bg: #f8ecd2; --ai: #2f6f6a; --ai-bg: #e2efe9; --none: #9a907c;
  --mincho: "Hiragino Mincho ProN", "Yu Mincho", "YuMincho", "Noto Serif JP", serif;
  --sans: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", "Meiryo", sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --paper: #1d1b17; --page: #27241e; --ink: #efe7d6; --sub: #b0a58f; --rule: #37322a; --line: #4a4337;
    --shu: #f07a5f; --shu-bg: #3d241d; --kin: #e3ad55; --kin-bg: #3a2e18; --ai: #7cc4b8; --ai-bg: #1d3330; --none: #8f8676; }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--paper); color: var(--ink); font-family: var(--sans); line-height: 1.6; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--ai); outline-offset: 2px; }
.vh { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

.book { max-width: 560px; margin: 0 auto; padding: calc(18px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right)) calc(96px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left)); }
.cover { border-bottom: 2px solid var(--ink); padding-bottom: 12px; margin-bottom: 18px; }
.title { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; }
h1 { margin: 0; font-family: var(--mincho); font-size: 28px; letter-spacing: .04em; font-weight: 700; }
.cho { display: inline-block; margin-left: 4px; padding: 0 6px; border: 2px solid var(--shu); color: var(--shu); border-radius: 4px; font-size: .8em; transform: rotate(-4deg); line-height: 1.25; }
.today { margin: 0; color: var(--sub); font-size: 13px; }
.lead { margin: 6px 0 0; font-size: 15px; }
.lead span { display: inline-block; }
.tally { margin: 10px 0 0; font-size: 13px; color: var(--sub); letter-spacing: .02em; }

.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.card { position: relative; display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 4px 10px; background: var(--page); border: 1px solid var(--line); border-left: 6px solid var(--none); border-radius: 4px 10px 10px 4px; padding: 10px 10px 10px 4px;
  transition: transform .25s ease; }
.card.s-over { border-left-color: var(--shu); }
.card.s-soon { border-left-color: var(--kin); }
.card.s-ok { border-left-color: var(--ai); }
.card-open { all: unset; cursor: pointer; display: grid; gap: 1px; padding: 2px 8px; border-radius: 6px; min-width: 0; }
.card-open:focus-visible { outline: 3px solid var(--ai); }
.nm { font-weight: 700; font-size: 16px; overflow-wrap: anywhere; }
.stt { font-family: var(--mincho); font-weight: 700; font-size: 17px; }
.s-over .stt { color: var(--shu); } .s-soon .stt { color: var(--kin); } .s-ok .stt { color: var(--ai); } .s-none .stt { color: var(--none); font-size: 14px; }
.meta { font-size: 12px; color: var(--sub); }
.gauge { display: block; height: 4px; background: var(--rule); border-radius: 2px; overflow: hidden; margin-top: 5px; }
.gauge i { display: block; height: 100%; background: var(--none); border-radius: 2px; }
.s-over .gauge i { background: var(--shu); } .s-soon .gauge i { background: var(--kin); } .s-ok .gauge i { background: var(--ai); }
.done { min-height: 48px; min-width: 96px; padding: 6px 12px; border: 2px solid var(--ink); background: var(--page); border-radius: 10px; font-weight: 700; font-size: 14px; cursor: pointer; box-shadow: 0 3px 0 var(--ink); }
.done:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
.done.is-done { border-color: var(--line); color: var(--sub); box-shadow: none; cursor: default; }
.past { grid-column: 1 / -1; justify-self: start; margin: -4px 0 -6px 8px; padding: 6px 0; font-size: 13px; }
.stamp { position: absolute; right: 2px; top: -10px; width: 40px; height: 40px; display: grid; place-items: center; border: 3px solid var(--shu); color: var(--shu); border-radius: 50%; font-family: var(--mincho); font-weight: 700; font-size: 19px; background: var(--page); transform: rotate(-12deg); opacity: .9; pointer-events: none; }
.card.pressed .done { background: var(--shu); color: #fff; border-color: var(--shu); }
@media (prefers-reduced-motion: no-preference) {
  .card.pressed { transform: scale(.985); }
  .stamp { animation: hanko .45s cubic-bezier(.2, 1.6, .4, 1) both; }
  @keyframes hanko { from { transform: rotate(-12deg) scale(1.8); opacity: 0; } to { transform: rotate(-12deg) scale(1); opacity: .9; } }
}

.add-open { width: 100%; margin-top: 14px; min-height: 52px; border: 2px dashed var(--line); background: transparent; border-radius: 10px; font-weight: 700; color: var(--sub); cursor: pointer; }
.add { margin-top: 20px; background: var(--page); border: 1px solid var(--line); border-radius: 12px; padding: 16px; }
.empty .add { margin-top: 0; border: 2px solid var(--ink); box-shadow: 4px 4px 0 var(--line); }
.sec { margin: 0 0 4px; font-family: var(--mincho); font-size: 18px; text-wrap: balance; }
.sec2 { margin: 18px 0 8px; font-size: 14px; color: var(--sub); }
.hint { margin: 0 0 10px; font-size: 13px; color: var(--sub); }
.presets { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: grid; text-align: left; min-height: 48px; padding: 6px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--paper); cursor: pointer; line-height: 1.35; }
.chip small { color: var(--sub); font-size: 11px; }
.chip[aria-pressed="true"] { border: 2px solid var(--shu); background: var(--shu-bg); padding: 5px 11px; }
.chip[aria-pressed="true"] span::before { content: "✓ "; color: var(--shu); font-weight: 700; }
.add-row { display: flex; align-items: center; gap: 12px; margin-top: 12px; }
.pcount { font-size: 13px; color: var(--sub); }
.btn { min-height: 46px; padding: 8px 18px; border: 2px solid var(--ink); background: var(--page); border-radius: 10px; font-weight: 700; cursor: pointer; white-space: nowrap; }
.btn.ink { background: var(--ink); color: var(--page); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.ghost { border-width: 1px; border-color: var(--line); font-weight: 400; font-size: 14px; }
.custom { display: grid; grid-template-columns: 1fr; gap: 10px; }
.f-name { display: grid; gap: 4px; font-size: 13px; color: var(--sub); }
.f-every { display: grid; gap: 4px; font-size: 13px; color: var(--sub); }
.f-name input, .every input, .every select, .d-other input { min-height: 46px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--paper); font-size: 16px; color: var(--ink); }
.every { display: flex; align-items: center; gap: 8px; color: var(--ink); font-size: 15px; }
.every input { width: 72px; text-align: center; }
.custom .btn { justify-self: start; }
.ferr { margin: 4px 0 0; color: var(--shu); font-size: 13px; min-height: 0; }
.ferr:empty { display: none; }
.link { background: none; border: 0; padding: 10px 0; color: var(--ai); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; font-size: 14px; min-height: 44px; }
.link.danger { color: var(--shu); }

.move { margin-top: 28px; padding-top: 16px; border-top: 1px solid var(--line); }
.move .sec { font-size: 15px; }
.move-row { display: flex; flex-wrap: wrap; gap: 8px; }
.file { position: relative; display: inline-flex; align-items: center; }
.file input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; }
.file:focus-within { outline: 3px solid var(--ai); outline-offset: 2px; }
.foot { margin-top: 28px; font-size: 12px; color: var(--sub); text-align: center; }
.foot p { margin: 2px 0; }
.foot a { color: inherit; display: inline-block; padding: 8px; }

.sheet { width: min(520px, calc(100vw - 24px)); max-height: calc(100dvh - 40px); border: 2px solid var(--ink); border-radius: 14px; background: var(--page); color: var(--ink); padding: 18px 16px 12px; box-shadow: 6px 6px 0 rgba(0, 0, 0, .18); }
.sheet::backdrop { background: rgba(30, 24, 16, .45); }
.sheet h2 { margin: 0 36px 2px 0; font-family: var(--mincho); font-size: 22px; overflow-wrap: anywhere; }
.sheet-close { position: absolute; right: 8px; top: 8px; margin: 0; }
.x { width: 44px; height: 44px; border: 0; background: none; font-size: 24px; cursor: pointer; color: var(--sub); }
.d-status { margin: 0 0 14px; font-weight: 700; }
.d-status.s-over { color: var(--shu); } .d-status.s-soon { color: var(--kin); } .d-status.s-ok { color: var(--ai); } .d-status.s-none { color: var(--sub); font-weight: 400; }
.d-other label { font-size: 13px; color: var(--sub); }
.row { display: flex; gap: 8px; margin-top: 4px; }
.row input { flex: 1; min-width: 0; }
.hist { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--rule); max-height: 220px; overflow-y: auto; }
.hist li { display: flex; align-items: center; gap: 10px; border-bottom: 1px solid var(--rule); min-height: 44px; }
.hist .hd { font-weight: 700; flex: 1; }
.hist .gap { font-size: 12px; color: var(--sub); }
.hist .none { color: var(--sub); font-size: 13px; padding: 8px 0; }
.rm { width: 44px; height: 44px; border: 0; background: none; color: var(--sub); font-size: 18px; cursor: pointer; }
.d-edit { margin-top: 14px; }
.d-edit summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; color: var(--ai); font-size: 14px; }
.d-edit form { display: grid; gap: 10px; padding: 4px 0 8px; }
.d-edit .btn { justify-self: start; }

.toast { position: fixed; inset: auto auto calc(16px + env(safe-area-inset-bottom)) 50%; margin: 0; border: 0; overflow: visible; transform: translate(-50%, 0); width: min(520px, calc(100% - 24px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px))); display: none; align-items: center; gap: 10px; padding: 12px 14px; background: var(--ink); color: var(--page); border-radius: 12px; font-size: 14px; z-index: 10; }
.toast.on { display: flex; }
@media (prefers-reduced-motion: no-preference) { .toast.on { animation: up .22s ease-out; } @keyframes up { from { transform: translate(-50%, 30%); opacity: 0; } } }
.toast span { flex: 1; }
.toast button { min-height: 40px; padding: 4px 12px; border: 1px solid currentColor; border-radius: 8px; background: none; color: inherit; font-weight: 700; cursor: pointer; white-space: nowrap; }
@media (min-width: 720px) { .book { padding-top: 40px; } h1 { font-size: 34px; } }
.s-none .gauge { visibility: hidden; height: 0; margin: 0; }

/* iPhone (WebKit) keeps a fieldset at least as wide as its content; let it shrink so nothing overflows narrow screens */
fieldset{min-width:0;min-inline-size:0}
input,select,textarea{max-width:100%}
