:root {
  --bg: #f1f4f4;
  --card: #ffffff;
  --ink: #1b2628;
  --soft: #5d6b6d;
  --line: #d9e2e2;
  --accent: #2e7d87;
  --accent-ink: #216570;
  --good: #2f7d4e;
  --good-bg: #e5f1ea;
  --warn: #b0432a;
  --warn-bg: #f7e6e0;
  --mid: #b5852f;
  --mid-bg: #f5ecd8;
  --pick-bg: #e7f1f2;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20,36,38,.06), 0 8px 24px rgba(20,36,38,.08);
}

* { 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, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}
.wrap { max-width: 700px; margin: 0 auto; padding: 0 16px; }

.top { padding: 34px 0 10px; }
.top h1 { font-size: 30px; margin: 0 0 6px; letter-spacing: -.02em; display: flex; align-items: center; gap: 10px; }
.logo {
  display: inline-block; width: 30px; height: 30px; border-radius: 7px;
  background: var(--accent); position: relative; overflow: hidden;
}
.logo::before { content: ""; position: absolute; left: 6px; top: 6px; bottom: 6px; width: 4px; border-radius: 2px; background: #fff; }
.logo::after { content: ""; position: absolute; left: 13px; top: 6px; bottom: 6px; width: 4px; border-radius: 2px; background: rgba(255,255,255,.6); box-shadow: 7px 0 0 rgba(255,255,255,.4); }
.tag { margin: 0; color: var(--soft); max-width: 60ch; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 18px 18px; box-shadow: var(--shadow); margin-top: 20px; }

.group { border: 0; padding: 12px 0; margin: 0; border-top: 1px solid var(--line); }
.group:first-of-type { border-top: 0; }
.group legend { font-size: 13px; font-weight: 700; color: var(--accent-ink); text-transform: uppercase; letter-spacing: .05em; padding: 0; }

.field-row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; margin-top: 10px; }
.field { display: flex; flex-direction: column; gap: 5px; flex: 1 1 120px; }
.field.narrow { flex: 0 1 130px; }
.field.wide { flex: 1 1 100%; }
.field span { font-size: 13px; color: var(--soft); font-weight: 600; }
.field input, .field select {
  font: inherit; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink);
  min-width: 0; width: 100%;
}
.field input:disabled { background: #eef2f2; color: var(--soft); }
.field input:focus, .field select:focus { outline: 3px solid var(--accent); outline-offset: 1px; }
.hint { margin: 10px 0 0; font-size: 13px; color: var(--soft); }

.out { margin-top: 16px; }
.result { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); margin-bottom: 14px; }
.result h3 { margin: 0 0 12px; font-size: 14px; color: var(--soft); font-weight: 700; letter-spacing: .01em; }

.opt { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.opt.pick { border-color: var(--accent); background: var(--pick-bg); box-shadow: inset 0 0 0 1px var(--accent); }
.opt-h { font-size: 15px; font-weight: 800; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.tagpill { display: inline-block; font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 999px; color: var(--accent-ink); background: var(--pick-bg); }
.tagpill.good { color: var(--good); background: var(--good-bg); }
.tagpill.warn { color: var(--warn); background: var(--warn-bg); }

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(80px, 1fr)); gap: 10px; margin-top: 12px; }
.cell { text-align: center; background: #eaf0f0; border: 1px solid var(--line); border-radius: 10px; padding: 11px 6px; }
.cell.big { background: var(--accent); border-color: var(--accent); }
.cell.big .k, .cell.big .v { color: #fff; }
.cell .k { display: block; font-size: 11px; color: var(--soft); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.cell .v { display: block; font-size: 22px; font-weight: 800; margin-top: 3px; }
.cell .u { font-size: 13px; font-weight: 700; }
.opt-sub { margin: 10px 0 0; font-size: 13px; color: var(--soft); }

/* the waste bar: how much of what you buy ends up as offcut */
.fill { margin-top: 12px; }
.fill-track { height: 12px; border-radius: 999px; background: #e6edec; border: 1px solid var(--line); overflow: hidden; }
.waste-bar { height: 100%; background: var(--good); border-radius: 999px; transition: width .25s ease; }
.waste-bar.mid { background: var(--mid); }
.waste-bar.high { background: var(--warn); }
.fill-label { margin: 6px 0 0; font-size: 13px; color: var(--soft); }

.advice { margin: 0; padding-left: 18px; }
.advice li { font-size: 14px; color: var(--soft); margin-bottom: 7px; }
.advice li:last-child { margin-bottom: 0; }

.bad { border-color: #e7cdbb; }
.bad h3 { color: var(--warn); }
.msg { margin: 0; font-size: 14px; color: var(--soft); }

.actions { display: flex; align-items: center; gap: 12px; margin: 6px 0 8px; }
.ghost {
  appearance: none; border: 1px solid var(--line); background: #fff; color: var(--ink);
  padding: 9px 14px; border-radius: 10px; font: inherit; font-weight: 600; cursor: pointer;
}
.ghost:hover { border-color: var(--accent); }
.ghost:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.share-done { color: var(--good); font-size: 14px; font-weight: 600; }

.note { margin: 20px 0 10px; padding: 16px 18px; background: #e6edec; border: 1px solid var(--line); border-radius: var(--radius); }
.note h2 { margin: 0 0 6px; font-size: 15px; }
.note p { margin: 0; color: var(--soft); font-size: 14px; }

.foot { padding: 20px 16px 120px; color: var(--soft); font-size: 13px; }
.foot a { color: var(--accent-ink); }

/* ---- Sweep the smoothing brush ---- */
.sweep-dock { position: fixed; right: 16px; bottom: 16px; z-index: 50; display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
.sweep-dock.tucked .sweep-bubble, .sweep-dock.tucked .sweep { display: none; }
.sweep-hide {
  align-self: flex-end; appearance: none; border: 1px solid var(--line); background: #fff; color: var(--soft);
  font: inherit; font-size: 12px; padding: 3px 9px; border-radius: 999px; cursor: pointer;
}
.sweep-dock.tucked .sweep-hide::after { content: "Sweep"; }
.sweep-dock.tucked .sweep-hide { font-size: 13px; }
.sweep-bubble:empty { display: none; }
.sweep-bubble {
  max-width: 244px; background: var(--ink); color: #fff; padding: 10px 13px; border-radius: 13px 13px 3px 13px;
  font-size: 13.5px; line-height: 1.4; box-shadow: var(--shadow);
}
.sweep-bubble.pop { animation: pop .18s ease-out; }
@keyframes pop { from { transform: scale(.9); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.sweep { appearance: none; border: 0; background: transparent; cursor: pointer; padding: 4px; }
.sweep-body { display: block; width: 56px; height: 60px; position: relative; }
/* flat brush bristles across the top */
.sweep-bristles {
  position: absolute; left: 4px; right: 4px; top: 0; height: 15px; border-radius: 3px 3px 1px 1px;
  background: repeating-linear-gradient(90deg, #c9b48a 0 3px, #b89e6d 3px 6px);
}
/* the metal band under the bristles */
.sweep-ferrule {
  position: absolute; left: 4px; right: 4px; top: 15px; height: 7px;
  background: linear-gradient(#c7d0d1, #9aa8a9); border-radius: 2px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.5);
}
/* the handle block, which carries the face */
.sweep-handle {
  position: absolute; left: 7px; right: 7px; top: 21px; bottom: 0; border-radius: 4px 4px 7px 7px;
  background: linear-gradient(var(--accent), var(--accent-ink));
  box-shadow: var(--shadow), inset 0 0 0 2px rgba(255,255,255,.12);
}
.sweep-face { position: absolute; left: 8px; right: 8px; top: 8px; height: 22px; }
.sweep-eye { position: absolute; top: 0; width: 9px; height: 9px; border-radius: 50%; background: #fff; }
.sweep-eye.l { left: 6px; } .sweep-eye.r { right: 6px; }
.sweep-eye::after { content: ""; position: absolute; left: 2.5px; top: 2.5px; width: 4px; height: 4px; border-radius: 50%; background: var(--ink); }
.sweep-mouth { position: absolute; left: 50%; transform: translateX(-50%); bottom: -1px; width: 16px; height: 7px; border-radius: 0 0 10px 10px; background: #fff; }

.sweep[data-mood="happy"] .sweep-mouth { height: 9px; width: 20px; }
.sweep[data-mood="happy"] { animation: hop .5s ease; }
.sweep[data-mood="think"] .sweep-mouth { width: 9px; height: 3px; border-radius: 3px; bottom: 1px; }
.sweep[data-mood="warn"] .sweep-handle { background: linear-gradient(#c4653f, #a84f30); }
.sweep[data-mood="warn"] .sweep-mouth { width: 11px; height: 4px; border-radius: 10px 10px 0 0; bottom: -2px; }
.sweep[data-mood="calm"] .sweep-eye::after { top: 3.5px; height: 2px; border-radius: 2px; }
@keyframes hop { 0%,100% { transform: translateY(0); } 30% { transform: translateY(-9px); } 55% { transform: translateY(0); } 70% { transform: translateY(-4px); } }

.bub { position: fixed; pointer-events: none; width: 9px; height: 9px; border-radius: 50%; background: rgba(46,125,135,.55); border: 1px solid rgba(255,255,255,.6); z-index: 49; animation: rise 1.1s ease-out forwards; }
@keyframes rise { from { opacity: 1; transform: translate(0,0) scale(1); } to { opacity: 0; transform: translate(var(--dx), var(--dy)) scale(.4); } }

@media (prefers-reduced-motion: reduce) {
  .sweep[data-mood="happy"], .sweep-bubble.pop { animation: none; }
  .bub { display: none; }
  .waste-bar { transition: none; }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1516; --card: #182021; --ink: #e6eeee; --soft: #9fb0b1; --line: #263031;
    --warn-bg: #2e1b14; --good-bg: #16261d; --mid-bg: #2a2314; --accent-ink: #5aa9b4; --pick-bg: #16262a;
  }
  .cell { background: #202a2b; }
  .cell.big { background: var(--accent); }
  .note { background: #182021; }
  .opt { border-color: #263031; }
  .fill-track { background: #202a2b; }
  .field input:disabled { background: #141b1c; }
}
