:root {
  --paper: #f6f1e7; --card: #fffdf8; --ink: #1f2430; --muted: #5f6672; --line: #e2d9c8;
  --slate: #2f3d4d; --accent: #4a5d73; --amber: #d4894a; --late: #a8492a; --mesh: #c4a574; --mesh-lt: #e8dcc8;
  --ok: #3f7a5a; --week: #b4673f;
  --radius: 14px; --shadow: 0 1px 0 rgba(31,36,48,.04), 0 6px 18px rgba(31,36,48,.06);
  color-scheme: light;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 16px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; color: var(--ink); background: var(--paper); }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
[hidden] { display: none !important; }
.opt { font-weight: 400; color: var(--muted); }

.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; max-width: 920px; margin: 0 auto; padding: 18px 18px 6px; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand h1 { margin: 0; font-size: 1.5rem; letter-spacing: -.01em; font-family: Georgia, "Iowan Old Style", serif; }
.sub { margin: 0; color: var(--muted); font-size: .92rem; }
.top-actions { display: flex; gap: 8px; flex-wrap: wrap; }

main { max-width: 920px; margin: 0 auto; padding: 6px 18px 32px; }
.banner { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 8px 0 12px; padding: 10px 14px; border-radius: 12px; background: #e4e9ef; color: var(--accent); font-size: .93rem; }
.link { background: none; border: 0; padding: 0; min-height: 0; color: var(--accent); text-decoration: underline; font-weight: 600; cursor: pointer; }

.step { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 16px 18px; margin-bottom: 16px; }
.step-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.step-head h2 { margin: 0; font-size: 1.1rem; font-family: Georgia, "Iowan Old Style", serif; }
.step-no { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: var(--accent); color: #fff; font-weight: 700; font-size: .9rem; flex: none; }
.step-aside { margin-left: auto; color: var(--muted); font-size: .86rem; text-align: right; }
.hint { color: var(--muted); font-size: .9rem; margin: 6px 0 4px; min-height: 1.3em; }
.empty { color: var(--muted); font-style: italic; margin: 8px 0; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 12px; }

button { cursor: pointer; border-radius: 10px; border: 1px solid transparent; padding: 9px 14px; min-height: 42px; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid rgba(74,93,115,.35); outline-offset: 2px; }
.primary { background: var(--accent); color: #fff; font-weight: 600; }
.primary:hover { background: #3a4b5e; }
.ghost { background: transparent; border-color: var(--line); }
.ghost:hover { background: #f1eadc; }
.sm { min-height: 34px; min-width: 34px; padding: 4px 9px; font-weight: 700; }
.danger { color: var(--late); }
.amber-btn { background: var(--amber); color: #fff; font-weight: 600; }
.amber-btn:hover { filter: brightness(.95); }

.field { margin: 0 0 12px; }
.field label { display: block; font-weight: 600; font-size: .88rem; margin-bottom: 4px; }
input[type="text"], input[type="date"], input[type="number"], select {
  border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; background: #fffefb; min-height: 40px; width: 100%; min-width: 0;
}
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.cadence-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip { background: #fff; border: 1px solid var(--line); border-radius: 99px; min-height: 32px; padding: 3px 11px; font-size: .85rem; }
.chip:hover { border-color: var(--accent); color: var(--accent); }

.msg { margin: 8px 0 0; font-size: .92rem; color: var(--muted); }
.msg.err { color: var(--late); }

.hero {
  background: linear-gradient(150deg, #fffdf8 0%, #e8edf2 55%, #f7ebe0 100%);
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 20px 18px 18px; margin-bottom: 16px;
}
.hero-kicker { margin: 0 0 4px; font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; font-weight: 700; color: var(--muted); }
.hero-title { margin: 0 0 6px; font-family: Georgia, "Iowan Old Style", serif; font-size: 1.55rem; line-height: 1.25; }
.hero-title .emph { color: var(--accent); }
.hero-title .warn { color: var(--late); }
.hero-title .amber { color: var(--week); }
.hero-sub { margin: 12px 0 0; color: var(--muted); font-size: .92rem; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.hero.empty-hero { background: var(--card); }
.hero.empty-hero .hero-title { color: var(--muted); font-size: 1.25rem; font-weight: 400; }

.shelf {
  position: relative; display: flex; align-items: flex-end; gap: 14px; flex-wrap: nowrap; overflow-x: auto;
  padding: 18px 12px 0; margin-top: 10px; min-height: 40px;
  border-bottom: 10px solid #6a5a48; border-radius: 0 0 4px 4px;
  box-shadow: 0 8px 0 -4px rgba(60,40,20,.18);
  scrollbar-width: thin;
}
.shelf:empty { display: none; }
.filter { flex: none; display: grid; justify-items: center; gap: 6px; width: 108px; }
.cassette {
  position: relative; width: 100%; background: var(--mesh-lt); border: 1px solid var(--mesh); border-radius: 4px;
  box-shadow: inset 0 -6px 0 rgba(0,0,0,.04);
  background-image: repeating-linear-gradient(90deg, transparent, transparent 5px, rgba(74,93,115,.12) 5px, rgba(74,93,115,.12) 6px);
}
.cassette::after {
  content: ""; position: absolute; left: 10px; right: 10px; top: 8px; height: 10px; border-radius: 2px;
  background: rgba(255,253,248,.7); border: 1px solid rgba(196,165,116,.45);
}
.filter.h1 .cassette { height: 52px; }
.filter.h2 .cassette { height: 68px; }
.filter.h3 .cassette { height: 46px; }
.filter.h4 .cassette { height: 60px; }
.tag {
  position: absolute; top: -10px; right: -6px; z-index: 1; padding: 2px 8px; border-radius: 99px; font-size: .72rem; font-weight: 800;
  color: #fff; background: var(--accent); white-space: nowrap; box-shadow: 0 2px 4px rgba(0,0,0,.12);
}
.filter.overdue .cassette { transform: rotate(-2.5deg); transform-origin: bottom left; }
.filter.overdue .tag { background: var(--late); }
.filter.week .tag { background: var(--amber); }
.filter.week .cassette { box-shadow: 0 0 0 3px rgba(212,137,74,.35), inset 0 -6px 0 rgba(0,0,0,.04); }
.filter-name { font-size: .8rem; font-weight: 700; text-align: center; line-height: 1.2; color: var(--slate); margin-bottom: 8px; max-width: 108px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

#shelf-groups { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); align-items: start; }
.group { min-width: 0; }
.group-h { display: flex; align-items: center; gap: 8px; margin: 0 0 8px; font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; font-weight: 800; color: var(--muted); }
.group-h .pip { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); }
.group.overdue .group-h { color: var(--late); }
.group.overdue .pip { background: var(--late); }
.group.week .group-h { color: var(--week); }
.group.week .pip { background: var(--amber); }
.cards { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; grid-template-columns: 1fr; }
.card { border: 1px solid var(--line); border-radius: 12px; background: #fffefb; padding: 12px 14px; display: grid; gap: 8px; align-content: start; }
.card.is-overdue { border-color: #e6bfae; box-shadow: inset 3px 0 0 var(--late); }
.card.is-week { border-color: #ecc9b6; box-shadow: inset 3px 0 0 var(--amber); background: #fffaf5; }
.card-top { display: flex; align-items: flex-start; gap: 10px; }
.card-title { margin: 0; font-size: 1.05rem; font-weight: 700; font-family: Georgia, "Iowan Old Style", serif; flex: 1 1 auto; overflow-wrap: anywhere; }
.card-meta { color: var(--muted); font-size: .88rem; margin: 0; }
.card-notes { font-size: .88rem; margin: 0; padding: 6px 10px; background: #f6f1e7; border-radius: 8px; color: #3a4150; overflow-wrap: anywhere; }
.badge { display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 99px; font-size: .78rem; font-weight: 700; background: #e4e9ef; color: var(--accent); white-space: nowrap; }
.badge.overdue { background: #f6e3da; color: var(--late); }
.badge.week { background: #f9e7dc; color: #a35a34; }
.badge.later { background: #e4e9ef; color: var(--accent); }
.card-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.card-actions button { min-height: 36px; padding: 6px 10px; font-size: .88rem; }

.history { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.history li { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 8px 12px; border: 1px dashed var(--line); border-radius: 10px; background: #fbf8f1; }
.history .a-name { font-weight: 600; color: #4a5160; }
.history .a-meta { color: var(--muted); font-size: .85rem; }
.history .a-actions { margin-left: auto; display: flex; gap: 6px; }
.history button { min-height: 32px; padding: 4px 10px; font-size: .85rem; }

dialog { border: 1px solid var(--line); border-radius: 16px; padding: 0; width: min(520px, calc(100vw - 24px)); background: var(--card); color: var(--ink); box-shadow: 0 20px 60px rgba(0,0,0,.2); }
dialog::backdrop { background: rgba(31,36,48,.35); }
.dlg { padding: 16px; }
.dlg-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.dlg-head h2 { margin: 0; font-size: 1.15rem; font-family: Georgia, "Iowan Old Style", serif; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 10; font-size: .92rem; box-shadow: var(--shadow); max-width: calc(100vw - 32px); }
.foot { color: var(--muted); font-size: .84rem; text-align: center; margin-top: 8px; }

.check-list { display: grid; gap: 6px; margin: 8px 0; }
.check-row { display: flex; align-items: center; gap: 8px; }
.check-row input { width: 18px; height: 18px; accent-color: var(--accent); }

@media (max-width: 640px) {
  .grid2, .cadence-row { grid-template-columns: 1fr; }
  .brand h1 { font-size: 1.3rem; }
  .hero-title { font-size: 1.35rem; }
  .filter { width: 92px; }
  .cards { grid-template-columns: 1fr; }
}
