:root {
  --bg: #f6efe6;
  --surface: #fffaf3;
  --surface-2: #efe5d8;
  --ink: #2a211b;
  --ink-2: #6b5d52;
  --line: #ddcfbf;
  --accent: #b5542c;      /* terracotta */
  --accent-ink: #fff;
  --accent-soft: #f3d9c9;
  --clay: #c98a63;
  --clay-wet: #8a6a55;
  --good: #3f7a4f;
  --radius: 14px;
  --tabbar: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1d1916;
    --surface: #27211d;
    --surface-2: #322a24;
    --ink: #f3e9de;
    --ink-2: #b6a596;
    --line: #463b33;
    --accent: #e27a4b;
    --accent-ink: #1d1916;
    --accent-soft: #4a2f22;
    --clay: #d79a72;
    --clay-wet: #b49580;
    --good: #7cc08d;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  padding-bottom: calc(var(--tabbar) + env(safe-area-inset-bottom) + 24px);
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; }

/* ---------- header & tabs ---------- */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.top h1 { font-size: 28px; margin: 0; letter-spacing: -0.02em; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 22px; border: 0;
  background: var(--surface-2); display: grid; place-items: center; cursor: pointer;
}

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tabbar) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--line);
}
.tabs button {
  border: 0; background: none; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 2px;
  color: var(--ink-2); font-size: 12px; font-weight: 600; cursor: pointer;
}
.tabs svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabs button.on { color: var(--accent); }

main { padding: 4px 16px 0; max-width: 640px; margin: 0 auto; }

/* ---------- cards & layout ---------- */
.card {
  background: var(--surface); border-radius: var(--radius);
  padding: 14px; margin: 0 0 14px; border: 1px solid var(--line);
}
.card h2 { font-size: 15px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-2); margin: 0 0 10px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.muted { color: var(--ink-2); font-size: 14px; }
.small { font-size: 13px; }

/* hero result */
.hero { background: var(--accent); color: var(--accent-ink); border: 0; }
.hero .big { font-size: 44px; font-weight: 800; letter-spacing: -0.02em; line-height: 1.05; }
.hero .big.long { font-size: 32px; }
.hero .sub { opacity: .9; font-size: 15px; margin-top: 4px; }
.hero .label { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; opacity: .85; font-weight: 700; }
.hero .row { display: flex; gap: 18px; flex-wrap: wrap; margin-top: 12px; }
.hero .row div { min-width: 0; }
.hero .row b { display: block; font-size: 22px; }
.hero .row span { font-size: 13px; opacity: .85; }

/* stats */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; min-width: 0; }
.stat .k { font-size: 12px; color: var(--ink-2); text-transform: uppercase; letter-spacing: .05em; font-weight: 700; }
.stat .v { font-size: 20px; font-weight: 700; overflow-wrap: anywhere; }
.stat .h { font-size: 13px; color: var(--ink-2); }

/* ---------- segmented & chips ---------- */
.seg { display: flex; background: var(--surface-2); border-radius: 12px; padding: 3px; margin-bottom: 12px; }
.seg button {
  flex: 1; border: 0; background: none; padding: 10px 6px; border-radius: 10px;
  font-weight: 600; font-size: 15px; cursor: pointer; min-height: 44px;
}
.seg button.on { background: var(--surface); box-shadow: 0 1px 3px rgba(0,0,0,.12); }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 12px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--line); background: var(--surface);
  border-radius: 999px; padding: 9px 14px; font-weight: 600; font-size: 15px; cursor: pointer; min-height: 44px;
  display: inline-flex; align-items: center; gap: 6px;
}
.chip.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.chip .x { opacity: .6; padding-left: 4px; }

/* ---------- fields ---------- */
.field { margin-bottom: 12px; min-width: 0; }
.field:last-child { margin-bottom: 0; }
.field > label { display: block; font-size: 14px; font-weight: 600; color: var(--ink-2); margin-bottom: 5px; }
.ctrl {
  display: flex; align-items: stretch; background: var(--surface-2);
  border-radius: 12px; overflow: hidden; border: 1px solid transparent;
}
.ctrl:focus-within { border-color: var(--accent); }
.ctrl input {
  flex: 1; min-width: 0; border: 0; background: none; color: var(--ink);
  font: inherit; font-size: 20px; font-weight: 700; padding: 10px 4px 10px 10px; text-align: right;
}
.ctrl input:focus { outline: none; }
.ctrl .unit { align-self: center; padding: 0 8px 0 4px; color: var(--ink-2); font-size: 15px; font-weight: 600; min-width: 22px; }
.ctrl .step {
  width: 46px; flex: none; border: 0; background: none; font-size: 24px; font-weight: 500;
  color: var(--accent); cursor: pointer; touch-action: manipulation;
}
.ctrl .step:active { background: var(--accent-soft); }
/* two-up fields on a phone: slimmer steppers so the number fits */
.grid2 .ctrl .step { width: 34px; font-size: 22px; }
.grid2 .ctrl input { font-size: 18px; padding-left: 2px; }
.grid2 .ctrl .unit { padding: 0 2px 0 3px; font-size: 14px; }
.field small { display: block; color: var(--ink-2); font-size: 13px; margin-top: 4px; }

.text-input {
  width: 100%; border: 1px solid var(--line); background: var(--surface-2); color: var(--ink);
  border-radius: 12px; padding: 12px; font: inherit; font-size: 17px;
}

.btn {
  border: 0; border-radius: 12px; padding: 12px 16px; min-height: 46px; font-weight: 700;
  background: var(--accent); color: var(--accent-ink); cursor: pointer;
}
.btn.ghost { background: var(--surface-2); color: var(--ink); }
.btn.danger { background: none; color: #c0392b; padding-left: 0; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 10px; }

details.card > summary { cursor: pointer; font-weight: 700; list-style: none; display: flex; justify-content: space-between; align-items: center; min-height: 28px; }
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary::after { content: "＋"; color: var(--ink-2); }
details.card[open] > summary::after { content: "−"; }
details.card[open] > summary { margin-bottom: 12px; }

/* ---------- pot drawings ---------- */
.pot-svg { width: 100%; display: block; }
.pot-svg .grid line { stroke: var(--line); stroke-width: .5; vector-effect: non-scaling-stroke; }
.pot-svg .grid text { fill: var(--ink-2); font-size: 11px; }
.pot-svg .fired { fill: var(--clay); }
.pot-svg .wet { fill: none; stroke: var(--clay-wet); stroke-dasharray: 4 3; stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.pot-svg .extra { fill: none; stroke: var(--clay); stroke-linecap: round; }
.pot-svg .axis { stroke: var(--ink-2); stroke-dasharray: 2 4; stroke-width: 1; vector-effect: non-scaling-stroke; opacity: .5; }
.pot-svg .knob { fill: var(--surface); stroke: var(--accent); stroke-width: 3; vector-effect: non-scaling-stroke; cursor: grab; }
.pot-svg .knob.sel { fill: var(--accent); }
.btn:disabled { opacity: .4; cursor: default; }
.pot-svg .knob-hit { fill: transparent; cursor: grab; }
.design-wrap { touch-action: none; background: var(--surface); border-radius: var(--radius); border: 1px solid var(--line); margin-bottom: 14px; }
.legend { display: flex; gap: 14px; padding: 0 14px 10px; font-size: 13px; color: var(--ink-2); flex-wrap: wrap; }
.legend i { display: inline-block; width: 18px; height: 0; border-top: 2px dashed var(--clay-wet); vertical-align: middle; margin-right: 4px; }
.legend i.f { border-top: 8px solid var(--clay); height: 0; }

.toggle { display: flex; align-items: center; justify-content: space-between; min-height: 44px; font-weight: 600; }
.toggle input { width: 24px; height: 24px; accent-color: var(--accent); }

/* breakdown table */
table.bd { width: 100%; border-collapse: collapse; font-size: 15px; }
table.bd td { padding: 7px 0; border-bottom: 1px solid var(--line); }
table.bd td:last-child { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
table.bd tr.total td { border-bottom: 0; font-weight: 800; padding-top: 10px; }

/* clay library */
.clay-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.clay-row:last-child { border-bottom: 0; }
.clay-row .name { flex: 1; min-width: 0; }
.clay-row .name b { display: block; overflow-wrap: anywhere; }
.radio { width: 26px; height: 26px; border-radius: 13px; border: 2px solid var(--line); flex: none; background: none; cursor: pointer; }
.radio.on { border-color: var(--accent); box-shadow: inset 0 0 0 5px var(--surface), inset 0 0 0 13px var(--accent); }

/* ---------- settings dialog ---------- */
dialog {
  border: 0; padding: 0; width: 100%; max-width: 640px; max-height: 92vh;
  margin: auto auto 0; border-radius: 20px 20px 0 0; background: var(--bg); color: var(--ink);
}
dialog::backdrop { background: rgba(0,0,0,.4); }
.sheet-head { position: sticky; top: 0; display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; background: var(--bg); z-index: 1; }
.sheet-head h2 { margin: 0; font-size: 22px; }
.sheet-body { padding: 0 16px calc(24px + env(safe-area-inset-bottom)); }

.note { font-size: 14px; color: var(--ink-2); background: var(--surface-2); border-radius: 10px; padding: 10px 12px; margin: 0 0 14px; }
.flag { color: var(--accent); font-weight: 700; }
