:root {
  --bg: #f6f1ea;
  --card: #ffffff;
  --text: #2b1d14;
  --muted: #7d6a5c;
  --line: #e7ddd2;
  --accent: #8a4b2a;
  --accent-text: #fff;
  --soft: #f1e7dc;
  --danger: #b3261e;
  --chip-l: 92%;
  --chip-on-l: 42%;
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17110d;
    --card: #221a14;
    --text: #efe6dc;
    --muted: #a8968a;
    --line: #3a2e25;
    --accent: #d08a5b;
    --accent-text: #1a120c;
    --soft: #2d231b;
    --danger: #ff8a80;
    --chip-l: 22%;
    --chip-on-l: 58%;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
a { color: inherit; }
h1 { font-size: 22px; margin: 0 0 4px; line-height: 1.2; }
h2 { font-size: 15px; margin: 18px 0 10px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
section > h2:first-child { margin-top: 0; }
h3 { font-size: 13px; margin: 14px 0 6px; color: var(--muted); font-weight: 600; }
.muted { color: var(--muted); font-weight: normal; text-transform: none; letter-spacing: 0; }
.small { font-size: 13px; }

.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; gap: 8px; align-items: center; font-weight: 700; text-decoration: none; font-size: 17px; }
.link { color: var(--accent); text-decoration: none; font-weight: 600; }
.back { display: inline-block; margin: 2px 0 10px; }

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

.card {
  display: block;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  text-decoration: none;
}
.empty { text-align: center; color: var(--muted); padding: 32px 16px; }
.row { display: flex; align-items: center; gap: 8px; }
.between { justify-content: space-between; }
.stack > * { margin-bottom: 12px; }

/* list */
.toolbar { margin-bottom: 12px; }
input, textarea {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--soft);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 12px;
  outline: none;
}
input:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
.brew .bean { font-size: 17px; }
.meta { color: var(--muted); font-size: 13px; margin-top: 2px; }
.params { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 14px; margin-top: 8px; font-variant-numeric: tabular-nums; }
.brew .chips { margin-top: 10px; }
.score {
  min-width: 32px; height: 32px; border-radius: 16px; display: grid; place-items: center;
  background: var(--accent); color: var(--accent-text); font-weight: 700;
}
.fab {
  position: fixed; right: 16px; bottom: calc(20px + env(safe-area-inset-bottom));
  background: var(--accent); color: var(--accent-text);
  padding: 14px 20px; border-radius: 28px; font-weight: 700; text-decoration: none;
  box-shadow: 0 6px 20px rgb(0 0 0 / .25);
}

/* chips */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  --h: 30;
  font: inherit; font-size: 14px;
  border: 1px solid hsl(var(--h) 45% calc(var(--chip-l) - 10%));
  background: hsl(var(--h) 55% var(--chip-l));
  color: var(--text);
  border-radius: 999px;
  padding: 6px 12px;
  line-height: 1.2;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.chip.custom { --h: 30; background: var(--soft); border-color: var(--line); }
.chip.on { background: hsl(var(--h) 50% var(--chip-on-l)); border-color: transparent; color: #fff; font-weight: 600; }
.chip.custom.on { background: var(--accent); color: var(--accent-text); }
.chip.cat { font-weight: 600; }
.chip.cat.open { outline: 2px solid hsl(var(--h) 50% var(--chip-on-l)); }
.chip.lvl0, .chip.lvl1 { font-weight: 700; }
.chip.add { background: transparent; border-style: dashed; border-color: var(--accent); color: var(--accent); }
span.chip { cursor: default; }
.selected { min-height: 34px; margin-bottom: 10px; align-items: center; }
#fq { margin-bottom: 4px; }
.wheel { margin-top: 10px; padding: 10px; border-radius: 12px; background: hsl(var(--h) 40% var(--chip-l) / .35); }
.wheel .sub { padding-top: 8px; margin-top: 8px; border-top: 1px solid var(--line); }

/* form */
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.field small { display: block; color: var(--muted); font-size: 12px; margin-top: 4px; text-align: center; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.grid3 .field > span { text-align: center; }
.stepper { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--soft); }
.stepper input {
  border: 0; border-radius: 0; text-align: center; padding: 11px 0; min-width: 0;
  font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; background: transparent; -moz-appearance: textfield;
}
.stepper input::-webkit-inner-spin-button, .stepper input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.stepper button { border: 0; background: transparent; color: var(--accent); font-size: 20px; width: 30px; flex: none; cursor: pointer; }
.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--soft); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.seg button { font: inherit; border: 0; background: transparent; color: var(--text); padding: 9px; border-radius: 8px; cursor: pointer; }
.seg button[aria-checked="true"] { background: var(--card); font-weight: 700; box-shadow: 0 1px 3px rgb(0 0 0 / .15); color: var(--accent); }

.scale { padding: 10px 0; border-bottom: 1px solid var(--line); }
.scale:last-child { border-bottom: 0; }
.scale .lbl { font-weight: 600; }
.scale .lbl small { font-size: 12px; margin-left: 4px; }
.scale output { font-weight: 700; font-size: 18px; min-width: 20px; text-align: right; color: var(--accent); }
.dots { display: grid; grid-template-columns: repeat(9, 1fr); gap: 4px; margin-top: 6px; }
.dots button {
  font: inherit; font-size: 14px; height: 40px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--line); background: var(--soft); color: var(--muted);
  -webkit-tap-highlight-color: transparent;
}
.dots button.f { background: color-mix(in srgb, var(--accent) 35%, var(--soft)); color: var(--text); border-color: transparent; }
.dots button[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); font-weight: 700; }
.ends small { color: var(--muted); font-size: 11px; }

.savebar {
  position: sticky; bottom: 0; padding: 12px 0 calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(transparent, var(--bg) 30%);
}

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
  padding: 12px 18px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--card); color: var(--text);
}
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.btn.danger { color: var(--danger); }
.btn.wide { width: 100%; padding: 15px; font-size: 17px; }
.btn:disabled { opacity: .6; }
.actions { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 8px; }

/* detail */
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 14px; }
.tiles div { background: var(--soft); border-radius: 10px; padding: 10px 6px; text-align: center; }
.tiles small { display: block; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; }
.tiles b { font-size: 18px; font-variant-numeric: tabular-nums; text-transform: capitalize; }
.tiles b span { font-size: 12px; font-weight: 500; text-transform: none; }
.sro { display: grid; grid-template-columns: 90px 1fr 18px; align-items: center; gap: 10px; padding: 5px 0; font-size: 14px; }
.sro b { text-align: right; }
.bar { display: grid; grid-template-columns: repeat(9, 1fr); gap: 3px; }
.bar i { height: 8px; border-radius: 4px; background: var(--soft); }
.bar i.f { background: var(--accent); }
.notes { white-space: pre-wrap; margin: 0; }

/* pin */
.pin { max-width: 340px; margin: 40px auto; text-align: center; display: grid; gap: 12px; }
.pin input { text-align: center; font-size: 28px; letter-spacing: .5em; padding: 12px; font-variant-numeric: tabular-nums; }
.error { color: var(--danger); min-height: 1.4em; margin: 0; font-size: 14px; }

#toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: .2s; max-width: calc(100% - 32px);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 380px) {
  .tiles { grid-template-columns: repeat(2, 1fr); }
  .stepper button { width: 24px; }
}
