:root {
  --bg: #f6f2ea;
  --card: #fffaf1;
  --ink: #26342f;
  --muted: #65746c;
  --line: #dfd5c6;
  --green: #385f4f;
  --green-2: #e8f2ec;
  --gold: #f5e7bf;
  --red: #8b2f2f;
  --red-bg: #f8e6e6;
  --shadow: 0 12px 30px rgba(33, 42, 38, 0.12);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: radial-gradient(circle at top, #fffaf1 0, var(--bg) 45%, #efe7d8 100%);
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
}

html { scroll-behavior: smooth; }

.app-header, footer, .layout { width: min(1100px, calc(100% - 28px)); margin: 0 auto; }
.app-header {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  padding: 28px 0 16px;
  align-items: flex-start;
}
.header-actions, .button-row, .results-header { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.header-actions { justify-content: flex-end; align-items: stretch; }
h1 { margin: 2px 0 6px; font-size: clamp(2rem, 6vw, 4.5rem); line-height: .95; letter-spacing: -0.05em; }
h2, h3 { margin: 0 0 10px; }
p { line-height: 1.5; }
.subtitle { max-width: 760px; color: var(--muted); margin: 0; font-size: 1.05rem; }
.eyebrow { text-transform: uppercase; letter-spacing: .12em; color: var(--green); font-weight: 700; margin: 0; font-size: .78rem; }
.layout { display: grid; gap: 16px; padding-bottom: 30px; }
.card, .notice {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: var(--shadow);
}
.card { overflow: hidden; }
.notice { padding: 18px; }
.notice.soft { background: var(--green-2); box-shadow: none; }
.notice.warm { background: #fff4d5; }
.notice.danger { background: var(--red-bg); color: var(--red); box-shadow: none; }
summary {
  cursor: pointer;
  list-style: none;
  padding: 18px 20px;
  font-size: 1.05rem;
  font-weight: 800;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--line);
}
summary::-webkit-details-marker { display: none; }
details:not([open]) summary { border-bottom: 0; }
details > :not(summary) { margin-left: 20px; margin-right: 20px; }
details > :last-child { margin-bottom: 20px; }
.status { font-size: .75rem; border-radius: 999px; padding: 5px 9px; background: #eee0c8; color: #6d5524; white-space: nowrap; }
.status.ok { background: var(--green-2); color: var(--green); }
.grid { display: grid; gap: 14px; margin-top: 18px; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
label { display: grid; gap: 7px; font-weight: 700; color: #33433d; }
input, select {
  width: 100%;
  border: 1px solid #cabda9;
  border-radius: 14px;
  padding: 12px 13px;
  font-size: 1rem;
  background: #fffdfa;
  color: var(--ink);
  font-weight: 400;
}
input::placeholder { color: #9f9586; opacity: .72; font-weight: 400; }
input:focus::placeholder { opacity: .45; }
.field-help { color: var(--muted); font-size: .84rem; font-weight: 400; line-height: 1.35; margin-top: -2px; }
input:focus, select:focus { outline: 3px solid rgba(56, 95, 79, .18); border-color: var(--green); }
button {
  border: 0;
  border-radius: 999px;
  padding: 12px 16px;
  min-height: 44px;
  font-size: .95rem;
  font-weight: 800;
  background: var(--green);
  color: white;
  cursor: pointer;
  box-shadow: 0 8px 18px rgba(56, 95, 79, .22);
}
button.secondary { background: #fffaf1; color: var(--green); border: 1px solid var(--green); box-shadow: none; }
button.ghost { background: transparent; color: var(--green); border: 1px dashed var(--green); box-shadow: none; }
button:hover { transform: translateY(-1px); }
.small, .tip, footer { color: var(--muted); font-size: .92rem; }
.tip { background: #f8efe0; padding: 12px 14px; border-radius: 16px; }
.hidden { display: none !important; }
.results-card { padding: 20px; }
.results-header { justify-content: space-between; margin-bottom: 12px; }
.results { display: grid; gap: 12px; }
.result-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.result-box { background: #fffdfa; border: 1px solid var(--line); border-radius: 18px; padding: 14px; }
.result-box .label { color: var(--muted); font-size: .82rem; margin-bottom: 7px; }
.result-box .value { font-size: 1.35rem; font-weight: 400; }
.result-box .negative { color: var(--red); }
.steps { background: var(--green-2); border-radius: 18px; padding: 15px; }
.steps ol { margin: 0; padding-left: 22px; }
.steps li { margin: 8px 0; }
.explain { background: #fff4d5; border-radius: 18px; padding: 15px; }
pre { overflow-x: auto; background: #26342f; color: #fffaf1; padding: 14px; border-radius: 16px; }
code { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }
footer { padding: 10px 0 30px; }
.sources { font-size: .82rem; }
@media (max-width: 820px) {
  .app-header { flex-direction: column; padding-top: 18px; }
  .header-actions, .results-header, .button-row { width: 100%; }
  .header-actions button, .results-header button, .button-row button { flex: 1 1 160px; }
  .grid.two, .result-grid { grid-template-columns: 1fr; }
  details > :not(summary) { margin-left: 14px; margin-right: 14px; }
}

@media (max-width: 560px) {
  .app-header, footer, .layout { width: min(100% - 16px, 1100px); }
  h1 { font-size: clamp(2rem, 15vw, 3.2rem); }
  .subtitle { font-size: .98rem; }
  .notice, .results-card { padding: 14px; }
  summary { padding: 15px 14px; font-size: 1rem; align-items: flex-start; }
  .status { font-size: .7rem; }
  input, select { font-size: 16px; padding: 13px 12px; }
  .header-actions button, .results-header button, .button-row button { flex: 1 1 100%; width: 100%; }
  .math-line { display: block; }
  .math-line span:last-child { display: block; margin-top: 3px; }
  pre { font-size: .82rem; }
}

@media (max-width: 380px) {
  .app-header, footer, .layout { width: min(100% - 10px, 1100px); }
  .card, .notice { border-radius: 16px; }
}

/* Missing required amount helper */
input.missing-required, select.missing-required {
  border-color: var(--red) !important;
  background: #fff4f4;
  box-shadow: 0 0 0 4px rgba(139, 47, 47, .15);
}
label.has-missing {
  color: var(--red);
}
.missing-jump-note {
  font-weight: 700;
}

.mini-list { margin: 8px 0 0 18px; padding: 0; color: var(--ink); }
.mini-list li { margin: 6px 0; }


.simple-total {
  background: #fffdfa;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
  margin: 12px 0;
}
.simple-total h4 { margin: 0 0 8px; font-size: 1rem; }
.math-line {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border-top: 1px solid var(--line);
  padding: 9px 0;
}
.math-line.total {
  font-size: 1.08rem;
  color: var(--green);
}
.plain-warning {
  background: #fffdfa;
  border-left: 5px solid var(--green);
  border-radius: 12px;
  padding: 12px;
}

@media print {
  body { background: white; }
  .app-header, footer, details.card, #missingBox, #installHelpSection, #calculateBtn, #printBtn, #saveBtn, #shareBtn { display: none !important; }
  .layout { width: 100%; padding: 0; }
  .results-card { box-shadow: none; border: 0; padding: 0; }
  .results-header { display: block; }
  .results-header .eyebrow { display: none; }
  .results { display: block; }
  .result-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .explain, .steps, .simple-total { break-inside: avoid; }
}

.sub-label {
  display: block;
  color: var(--muted);
  font-weight: 400;
  font-size: .86rem;
  margin-top: 2px;
}
.next-steps ol {
  margin: 0;
  padding-left: 22px;
}
.next-steps li { margin: 8px 0; }
@media print {
  .next-steps { break-inside: avoid; }
}
