:root {
  --paper: #f4f0e6;
  --sheet: #fffdf7;
  --ink: #222c2a;
  --muted: #59635f;
  --line: #cfc9bb;
  --teal: #176b64;
  --teal-soft: #e3f0ec;
  --amber: #8a5b0d;
  --amber-soft: #fbefd5;
  --red: #a32626;
  --red-soft: #fae7e4;
  --focus: #0f5c56;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html {
  scroll-padding-top: 108px;
  background: var(--paper);
  color: var(--ink);
}

body {
  margin: 0;
  min-width: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic UI", sans-serif;
  font-size: 16px;
  line-height: 1.65;
  overflow-wrap: anywhere;
}

button, input, select, textarea { font: inherit; color: inherit; }
button, summary, label, select { cursor: pointer; }
button, input, select { min-height: 44px; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, summary:focus-visible, a:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

a { color: #075f58; text-underline-offset: 3px; }
h1, h2, h3, p { margin-top: 0; }
p { text-wrap: pretty; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.hero {
  width: min(100% - 32px, 760px);
  margin: 0 auto;
  padding: 48px 0 28px;
}

.eyebrow, .kicker, .step {
  color: var(--teal);
  font-size: .75rem;
  font-weight: 800;
  letter-spacing: .14em;
}

.hero h1 {
  margin-bottom: 14px;
  font-family: ui-serif, "Yu Mincho", serif;
  font-size: clamp(2.5rem, 9vw, 4.8rem);
  line-height: 1.08;
  letter-spacing: -.04em;
}

.lead { max-width: 38rem; margin-bottom: 0; color: var(--muted); text-wrap: balance; }

.summary-wrap {
  position: sticky;
  z-index: 10;
  top: 0;
  width: 100%;
  padding: 4px 16px;
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  backdrop-filter: blur(8px);
}

.summary {
  width: min(100%, 760px);
  margin: 0 auto;
  padding: 5px 14px;
  border: 1px solid #387c75;
  border-radius: 12px;
  background: #f8fffc;
  box-shadow: 0 5px 18px rgba(34, 44, 42, .1);
}

.summary__content {
  display: flex;
  align-items: center;
  gap: 8px 14px;
}
.summary__days {
  display: inline-flex;
  flex: none;
  align-items: baseline;
  gap: 3px;
  margin: 0;
  color: #394440;
  font-size: .76rem;
  font-weight: 750;
  line-height: 1;
  white-space: nowrap;
}
.summary__days strong {
  padding: 1px 6px 2px;
  border-radius: 7px;
  background: var(--teal);
  color: #fff;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: clamp(2.125rem, 9vw, 2.5rem);
  font-variant-numeric: tabular-nums;
  letter-spacing: -.07em;
  line-height: 1;
}
.summary__facts { display: flex; min-width: 0; flex-wrap: wrap; gap: 4px 6px; }
.summary__chip {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 8px;
  border: 1px solid #78a19b;
  border-radius: 999px;
  background: var(--teal-soft);
  color: #174f4a;
  font-size: .73rem;
  font-weight: 750;
  line-height: 1.35;
  text-decoration-thickness: 1px;
  white-space: nowrap;
}
.summary__chip--expiry { border-color: #c77777; background: var(--red-soft); color: var(--red); }
.summary__message { margin: 0; font-weight: 750; }
.summary__message .summary__chip { margin-left: 8px; }
.summary__empty-action { display: inline-flex; min-height: 40px; align-items: center; margin-top: 5px; font-size: .76rem; line-height: 1.35; text-decoration: none; }
.summary.is-invalid { border-color: var(--amber); background: var(--amber-soft); }

main { width: min(100% - 32px, 760px); margin: 18px auto 64px; }

.paper, .stock-card, .add-box {
  margin-bottom: 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--sheet);
  box-shadow: 0 2px 0 rgba(78, 67, 45, .06);
}

.paper { padding: 22px; }

.section-head { display: flex; align-items: flex-start; gap: 14px; margin-bottom: 20px; }
.section-head--outside { padding: 20px 4px 0; }
.section-head .step { flex: none; margin: 2px 0 0; }
.section-head h2 { margin: 0 0 3px; font-size: 1.25rem; }
.section-head p:not(.step) { margin: 0; color: var(--muted); font-size: .86rem; }

.household-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.field-group { min-width: 0; padding: 0; border: 0; }
.field-group legend { margin-bottom: 8px; font-size: .84rem; font-weight: 750; }

.stepper { display: flex; align-items: center; gap: 8px; }
.stepper button {
  width: 44px;
  flex: none;
  padding: 0;
  border: 1px solid #78807c;
  border-radius: 50%;
  background: transparent;
  font-size: 1.25rem;
}
.stepper__value { display: flex; align-items: center; gap: 6px; }
.stepper input { width: 72px; border: 1px solid #78807c; border-radius: 8px; background: #fff; text-align: center; }

.segments { display: grid; grid-template-columns: 1fr 1fr; }
.segments label { position: relative; min-width: 0; }
.segments input {
  position: absolute;
  z-index: 2;
  inset: 0;
  width: 100%;
  height: 100%;
  min-height: 0;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}
.segments span {
  position: relative;
  z-index: 1;
  display: grid;
  min-height: 44px;
  place-items: center;
  border: 1px solid #78807c;
  background: #fff;
  font-weight: 750;
}
.segments label:first-child span { border-radius: 9px 0 0 9px; }
.segments label:last-child span { margin-left: -1px; border-radius: 0 9px 9px 0; }
.segments input:checked + span { border-color: var(--teal); background: var(--teal-soft); color: #103f3b; font-weight: 850; }
.segments input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 3px; }

.flags { display: flex; flex-wrap: wrap; gap: 10px 18px; margin-top: 22px; }
.flags label { display: flex; min-height: 44px; align-items: center; gap: 8px; }
.flags input { width: 20px; min-height: 20px; height: 20px; accent-color: var(--teal); }
.hint, .row-note { max-width: 40rem; margin: 4px 0 0; color: var(--muted); font-size: .78rem; }

.stock-card { position: relative; padding: 20px; overflow: hidden; }
.stock-card::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 5px; background: transparent; }
.stock-card.is-bottleneck { border-color: var(--amber); background: #fffaf0; }
.stock-card.is-bottleneck::before { background: var(--amber); }
.stock-card.is-ready { border-color: #5b948e; background: #f4fbf8; }
.stock-card.is-ready::before { background: var(--teal); }
.stock-card.is-ready.is-bottleneck { border-color: var(--amber); background: #fffaf0; }
.stock-card.is-ready.is-bottleneck::before { background: var(--amber); }

.stock-card__title { display: flex; justify-content: space-between; gap: 12px; align-items: start; }
.title-line { display: flex; flex-wrap: wrap; align-items: center; gap: 5px 8px; margin: -4px 0 16px; }
.stock-card__title h3 { margin: 0; font-size: 1.25rem; }
.kicker { margin: 0; font-size: .64rem; }
.rate { flex: none; padding: 4px 9px; border-radius: 999px; background: #e9e5da; color: #394440; font-size: .76rem; font-weight: 700; }
.row-status { padding: 2px 8px; border: 1px solid currentColor; border-radius: 999px; font-size: .7rem; font-weight: 800; line-height: 1.45; white-space: nowrap; }
.row-status.is-bottleneck { background: var(--amber-soft); color: var(--amber); }
.row-status.is-ready { background: var(--teal-soft); color: var(--teal); }

.stock-fields { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.stock-fields > label:first-child { grid-column: span 2; }
.stock-fields label, .custom-grid label { display: grid; min-width: 0; align-content: start; gap: 5px; color: #45504c; font-size: .78rem; font-weight: 700; }
input, select {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  border: 1px solid #727a76;
  border-radius: 8px;
  background: #fff;
  padding: 9px 10px;
}
.input-with-unit { display: grid; grid-template-columns: minmax(0, 12ch) 2em; justify-content: start; align-items: center; gap: 8px; font-size: 1rem; }
.input-with-unit input, .custom-grid input[type="number"] { width: 100%; max-width: 12ch; }
.input-with-unit > span { min-width: 2em; text-align: center; }

.days-line { display: flex; min-height: 34px; align-items: center; justify-content: space-between; gap: 12px; margin-top: 16px; }
.days-line strong { display: inline-flex; align-items: baseline; gap: 3px; font-weight: 800; }
.days-number { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 1.5rem; font-variant-numeric: tabular-nums; }
.days-unit { font-family: system-ui, -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic UI", sans-serif; font-size: .84rem; }
.expiry-badge { padding: 3px 9px; border: 1px solid currentColor; border-radius: 999px; font-size: .75rem; font-weight: 800; }
.expiry-badge.is-expired { background: var(--red-soft); color: var(--red); }
.expiry-badge.is-soon { background: var(--amber-soft); color: var(--amber); }

.tank { position: relative; padding-bottom: 21px; }
.tank progress { display: block; width: 100%; height: 15px; overflow: hidden; border: 1px solid #838984; border-radius: 5px; background: #ddd9ce; }
.tank progress::-webkit-progress-bar { background: #ddd9ce; }
.tank progress::-webkit-progress-value { background: var(--teal); transition: width .3s ease-out; }
.tank progress::-moz-progress-bar { background: var(--teal); transition: width .3s ease-out; }
.stock-card.is-bottleneck progress::-webkit-progress-value { background: var(--amber); }
.stock-card.is-bottleneck progress::-moz-progress-bar { background: var(--amber); }
.mark { position: absolute; top: 17px; color: var(--muted); font-size: .72rem; transform: translateX(-50%); }
.mark.is-target { color: #263d39; font-weight: 850; }
.mark::before { content: ""; position: absolute; bottom: 100%; left: 50%; width: 1px; height: 15px; background: #59635f; }
.mark--zero { left: 0; transform: none; }
.mark--zero::before { left: 0; }
.mark--three { left: 42.857%; }
.mark--seven { right: 0; transform: none; }
.mark--seven::before { right: 0; left: auto; }

.field-error { margin: 7px 0 0; color: var(--amber); font-size: .78rem; font-weight: 750; }
.custom-rows { display: grid; gap: 16px; }
.custom-card { margin-bottom: 0; }
.custom-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.custom-grid .wide { grid-column: span 2; }
.custom-actions { display: flex; justify-content: flex-end; margin-top: 12px; }
.remove-button { min-height: 44px; border: 1px solid #c77777; border-radius: 8px; background: #fffafa; color: var(--red); padding: 7px 14px; }
.custom-help { margin: 8px 0 0; color: var(--amber); font-size: .78rem; font-weight: 700; }

.add-box { margin-top: 16px; padding: 17px 20px; border-style: dashed; }
.add-box > p { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.add-box > p span { color: var(--muted); font-size: .78rem; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { min-height: 44px; padding: 8px 13px; border: 1px solid #55716c; border-radius: 999px; background: #f7fcfa; color: #174f4a; }
.chip:disabled { cursor: not-allowed; opacity: .45; }

.notice { padding: 12px 16px; border: 1px solid var(--amber); border-radius: 10px; background: var(--amber-soft); color: var(--amber); font-weight: 700; }
.shortage-list { display: grid; gap: 0; margin: 0; padding: 0; list-style: none; }
.shortage-list li { display: flex; justify-content: space-between; gap: 16px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.shortage-list li:nth-child(even) { background: #f7f3e9; }
.shortage-list li:last-child { border: 0; }
.shortage-list strong { color: var(--ink); font-weight: 800; text-align: right; }
.shortage-list li.is-bottleneck strong { color: var(--amber); }
.all-ready { color: var(--teal); font-weight: 750; }
.shortage-list + .button { margin-top: 18px; }
.copy-fallback { width: 100%; min-height: 9rem; margin-top: 12px; border: 1px solid #727a76; border-radius: 8px; background: #fff; padding: 10px; line-height: 1.5; resize: vertical; }

.privacy h2 { margin-bottom: 6px; font-size: 1.05rem; }
.privacy p { color: var(--muted); font-size: .86rem; }
.button { min-height: 44px; border: 1px solid var(--teal); border-radius: 9px; background: var(--teal); color: #fff; padding: 9px 16px; font-weight: 750; }
.button--quiet { border: 1px solid #727a76; background: transparent; color: var(--ink); }
.button.is-armed { border-color: var(--amber); background: transparent; color: var(--amber); }

.sources { padding: 0; }
.sources summary { display: flex; align-items: center; gap: 9px; padding: 18px 22px; font-weight: 800; list-style: none; }
.sources summary::-webkit-details-marker { display: none; }
.sources summary::before { content: "▸"; width: 1rem; flex: none; color: var(--teal); transform-origin: center; transition: transform .2s ease; }
.sources[open] summary::before { transform: rotate(90deg); }
.sources__body { padding: 0 22px 20px; color: var(--muted); font-size: .84rem; }
.sources__body ul { padding-left: 1.2rem; }
.sources__body li { margin-bottom: 10px; }

#share { margin-top: 22px; }

@media (max-width: 560px) {
  .hero { padding-top: 34px; }
  main, .hero { width: min(100% - 24px, 760px); }
  .summary-wrap { padding-inline: 12px; }
  .paper, .stock-card { padding: 17px; }
  .household-grid { grid-template-columns: 1fr; }
  .stock-fields { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stock-fields > label:first-child { grid-column: auto; }
  .custom-grid { grid-template-columns: 1fr 1fr; }
  .stock-card__title { align-items: center; }
  .rate { white-space: nowrap; }
}

@media (max-width: 340px) {
  main, .hero { width: min(100% - 16px, 760px); }
  .summary-wrap { padding-inline: 8px; }
  .paper, .stock-card, .add-box { padding: 14px; border-radius: 12px; }
  .stock-fields { grid-template-columns: 1fr; }
  .custom-grid { grid-template-columns: 1fr; }
  .custom-grid .wide { grid-column: auto; }
  .stock-card__title { display: block; }
  .rate { display: inline-block; margin-bottom: 12px; }
  .shortage-list li { display: block; }
  .shortage-list strong { display: block; text-align: left; }
}

@media (max-width: 420px) {
  .summary__content { display: grid; gap: 2px; }
  .summary__days strong { font-size: 2.125rem; }
  .summary__chip { min-height: 22px; padding-block: 1px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
