/* =========================================================
 * 黏土调色器 — 样式
 * 气质：手作笔记。纸感、圆角、留白多、字大。
 * 铁律：界面自己不能抢戏——整个 App 都在展示颜色，底色必须安静。
 * 强制浅色：颜色判断需要一致的观察环境，不给深色模式。
 * ========================================================= */

:root {
  --paper:  #FAF7F2;
  --card:   #FFFFFF;
  --ink:    #2E2A26;
  --dim:    #8B8178;
  --line:   #E8E0D5;
  --accent: #E9B949;
  --good:   #5A9367;
  --ok:     #7A9A5B;
  --warn:   #D98E3C;
  --bad:    #C7513F;
  --r:      16px;
  --tabh:   62px;
  color-scheme: light;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei",
               "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 17px;
  line-height: 1.55;
  overscroll-behavior-y: contain;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  padding: 0 20px calc(var(--tabh) + env(safe-area-inset-bottom) + 24px);
  min-height: 100vh;
}

.hidden { display: none !important; }
.dim { color: var(--dim); }

h1 { font-size: 26px; font-weight: 700; margin: 0; letter-spacing: -.02em; }
h2 { font-size: 19px; font-weight: 700; margin: 0 0 14px; }

.hd { padding: calc(env(safe-area-inset-top) + 22px) 0 18px; }
.hd-row { display: flex; align-items: center; gap: 12px; }
.hd-row h1 { flex: 1; }

/* ---------- 横幅 ---------- */
.banner {
  display: flex; gap: 10px; align-items: flex-start;
  background: #FFF6DE; border: 1px solid #F0DFA8;
  border-radius: 14px; padding: 12px 14px;
  margin-top: calc(env(safe-area-inset-top) + 12px);
  font-size: 14px; line-height: 1.5;
}
.banner-txt { flex: 1; }
.banner-x {
  border: 0; background: transparent; color: var(--dim);
  font-size: 22px; line-height: 1; padding: 0 2px; cursor: pointer;
}

/* ---------- 目标色块 ---------- */
.swatch-wrap { position: relative; }
.swatch-big {
  width: 100%; aspect-ratio: 4/3;
  border-radius: 20px;
  border: 1px solid rgba(0,0,0,.07);
  box-shadow: 0 2px 14px rgba(60,45,25,.07);
  background: #E8B4B8;
  transition: background .18s ease;
}
.hex-input {
  position: absolute; left: 12px; bottom: 12px;
  width: 118px;
  background: rgba(255,255,255,.9);
  border: 1px solid rgba(0,0,0,.06);
  border-radius: 10px;
  padding: 7px 10px;
  font: 600 15px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--ink);
  letter-spacing: .04em;
  backdrop-filter: blur(6px);
}
.hex-input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---------- 取色按钮行 ---------- */
.pick-row { display: flex; gap: 10px; margin: 16px 0 4px; }
.pick-btn {
  flex: 1; border: 1px solid var(--line); background: var(--card);
  border-radius: 14px; padding: 13px 4px;
  font-size: 15px; font-weight: 600; color: var(--ink);
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  cursor: pointer;
}
.pick-btn:active { background: #F3EEE6; }
.ico { font-size: 21px; line-height: 1; }

/* ---------- 总量 ---------- */
.total-row {
  display: flex; align-items: center; gap: 12px;
  margin: 22px 0 18px;
  font-size: 16px;
}
.total-box {
  display: flex; align-items: center;
  border: 1px solid var(--line); background: var(--card);
  border-radius: 12px; overflow: hidden;
}
.total-box input {
  width: 74px; border: 0; text-align: center;
  font: 700 19px/1 inherit; color: var(--ink);
  padding: 11px 0; background: transparent;
  -moz-appearance: textfield;
}
.total-box input::-webkit-outer-spin-button,
.total-box input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.step {
  border: 0; background: transparent; color: var(--dim);
  font-size: 21px; width: 40px; height: 44px; cursor: pointer;
}
.step:active { background: #F3EEE6; }
.unit { color: var(--dim); }

/* ---------- 主按钮 ---------- */
.primary {
  width: 100%; border: 0; border-radius: 15px;
  background: var(--ink); color: #FFF9EC;
  font-size: 18px; font-weight: 700; letter-spacing: .12em;
  padding: 17px; cursor: pointer;
}
.primary:active { transform: translateY(1px); }
.primary.small { width: auto; padding: 12px 22px; font-size: 16px; letter-spacing: .02em; }
.ghost {
  border: 0; background: transparent; color: var(--dim);
  font-size: 16px; padding: 8px 4px; cursor: pointer;
}
.ghost.strong { color: var(--ink); font-weight: 700; }
.back {
  border: 1px solid var(--line); background: var(--card);
  width: 38px; height: 38px; border-radius: 12px;
  font-size: 19px; color: var(--ink); cursor: pointer;
}

.hint-foot { font-size: 13px; color: var(--dim); text-align: center; margin: 14px 0 0; }

/* ---------- 对比条 ---------- */
.compare {
  display: flex; align-items: center; gap: 14px;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--r); padding: 14px; margin-bottom: 14px;
}
.cmp { text-align: center; }
.cmp-sw {
  width: 62px; height: 62px; border-radius: 13px;
  border: 1px solid rgba(0,0,0,.08); margin-bottom: 5px;
}
.cmp span { font-size: 12px; color: var(--dim); }
.cmp-de { flex: 1; text-align: right; }
.cmp-de b { display: block; font-size: 25px; font-weight: 700; line-height: 1.1; }
.cmp-de span { font-size: 13px; color: var(--dim); }
.cmp-de.good b { color: var(--good); }
.cmp-de.ok   b { color: var(--ok); }
.cmp-de.warn b { color: var(--warn); }
.cmp-de.bad  b { color: var(--bad); }

/* ---------- 提醒框 ---------- */
.alert {
  border-radius: 14px; padding: 13px 15px; margin-bottom: 14px;
  font-size: 14.5px; line-height: 1.55;
}
.alert > b:first-child { display: block; margin-bottom: 3px; }
.alert.warn { background: #FFF3E2; border: 1px solid #F2D9AF; }
.alert.bad  { background: #FDECE9; border: 1px solid #F2C9C1; }
.alert .act {
  display: inline-block; margin-top: 8px;
  background: var(--ink); color: #FFF9EC; border: 0;
  border-radius: 10px; padding: 8px 14px; font-size: 14px; font-weight: 600;
  cursor: pointer;
}

/* ---------- 配方卡 ---------- */
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--r); padding: 6px 16px 16px;
}
.card-tag {
  font-size: 12.5px; color: var(--dim);
  padding: 10px 0 8px; border-bottom: 1px dashed var(--line);
}
.card-tag b { color: var(--ink); }

.part {
  display: flex; align-items: center; gap: 13px;
  padding: 15px 0; border-bottom: 1px solid #F2ECE2;
  cursor: pointer; user-select: none;
}
.part:last-child { border-bottom: 0; }
.chk {
  width: 30px; height: 30px; border-radius: 9px;
  border: 2px solid var(--line); flex: none;
  display: flex; align-items: center; justify-content: center;
  font-size: 17px; color: transparent; transition: .12s;
}
.part.done .chk { background: var(--ink); border-color: var(--ink); color: #FFF9EC; }
.part.done .p-name, .part.done .p-g { opacity: .4; text-decoration: line-through; }
/* 白色黏土在纸底上会消失，边框必须够重才看得见是哪一管 */
.p-dot {
  width: 26px; height: 26px; border-radius: 8px; flex: none;
  border: 1px solid rgba(0,0,0,.22);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.5);
}
.p-name { flex: 1; font-size: 17px; font-weight: 600; }
.p-g { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.p-g em { font-size: 14px; font-weight: 600; font-style: normal; color: var(--dim); margin-left: 2px; }
.part.black-warn { background: #FFFBF0; margin: 0 -16px; padding-left: 16px; padding-right: 16px; }
.p-tip { font-size: 12px; color: var(--warn); display: block; font-weight: 500; }

/* ---------- 预混 ---------- */
.premix {
  background: #F4F6F3; border: 1px solid #DCE3D8;
  border-radius: 14px; padding: 14px 15px; margin-top: 12px;
  font-size: 14.5px; line-height: 1.6;
}
.premix > b:first-child { display: block; margin-bottom: 5px; }
.premix li b { font-variant-numeric: tabular-nums; }
.premix ol { margin: 8px 0 0; padding-left: 20px; }
.premix li { margin-bottom: 4px; }

/* ---------- 总量滑块 ---------- */
.total-slider {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--r); padding: 14px 16px 6px; margin: 14px 0;
}
.ts-head { display: flex; justify-content: space-between; align-items: baseline; font-size: 15px; }
.ts-head b { font-size: 19px; font-variant-numeric: tabular-nums; }
input[type=range] {
  width: 100%; margin: 10px 0 4px; -webkit-appearance: none; background: transparent;
}
input[type=range]::-webkit-slider-runnable-track {
  height: 5px; border-radius: 3px; background: var(--line);
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 27px; height: 27px; border-radius: 50%;
  background: var(--ink); margin-top: -11px; border: 3px solid var(--card);
  box-shadow: 0 1px 5px rgba(0,0,0,.2);
}
input[type=range]::-moz-range-track { height: 5px; border-radius: 3px; background: var(--line); }
input[type=range]::-moz-range-thumb {
  width: 22px; height: 22px; border-radius: 50%; background: var(--ink); border: 3px solid var(--card);
}

/* ---------- 备选 ---------- */
.alts { margin-top: 18px; }
.alts summary {
  cursor: pointer; font-size: 15px; color: var(--dim);
  padding: 12px 0; list-style: none;
}
.alts summary::-webkit-details-marker { display: none; }
.alts summary::before { content: '▾ '; }
.alts[open] summary::before { content: '▴ '; }
.alt-item {
  background: var(--card); border: 1px solid var(--line);
  border-radius: 13px; padding: 13px 15px; margin-bottom: 10px;
  display: flex; align-items: center; gap: 12px; cursor: pointer;
}
.alt-sw { width: 38px; height: 38px; border-radius: 10px; border: 1px solid rgba(0,0,0,.08); flex: none; }
.alt-body { flex: 1; min-width: 0; }
.alt-parts { font-size: 14.5px; font-weight: 600; }
.alt-meta { font-size: 12.5px; color: var(--dim); }
.alt-use { font-size: 13px; color: var(--dim); }

/* ---------- 配方本 ---------- */
.book-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 13px; }
.book-item { cursor: pointer; }
.book-sw {
  width: 100%; aspect-ratio: 1;
  border-radius: 15px; border: 1px solid rgba(0,0,0,.08);
  box-shadow: 0 1px 8px rgba(60,45,25,.06);
}
.book-name {
  font-size: 15px; font-weight: 600; margin-top: 8px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.book-meta { font-size: 12px; color: var(--dim); }
.empty { text-align: center; color: var(--dim); margin-top: 60px; line-height: 1.9; }

/* ---------- tab ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  height: calc(var(--tabh) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: flex; background: rgba(250,247,242,.94);
  backdrop-filter: blur(12px); border-top: 1px solid var(--line);
}
.tab {
  flex: 1; border: 0; background: transparent; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; font-size: 11.5px; color: var(--dim); font-weight: 600;
}
.tab span { font-size: 21px; line-height: 1; filter: grayscale(1); opacity: .55; }
.tab.active { color: var(--ink); }
.tab.active span { filter: none; opacity: 1; }

/* ---------- 弹层 ---------- */
.modal {
  position: fixed; inset: 0; z-index: 60;
  background: var(--paper);
  display: flex; flex-direction: column;
}
.modal.center {
  background: rgba(40,34,28,.42);
  align-items: center; justify-content: center; padding: 24px;
}
.modal-hd {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 12px) 18px 12px;
  font-size: 15px; color: var(--dim); border-bottom: 1px solid var(--line);
}
.canvas-wrap {
  flex: 1; position: relative; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  background: #2A2622; touch-action: none;
}
#picCanvas { max-width: 100%; max-height: 100%; display: block; touch-action: none; }
.loupe {
  position: absolute; width: 120px; height: 120px; border-radius: 50%;
  border: 3px solid #fff; box-shadow: 0 3px 14px rgba(0,0,0,.4);
  overflow: hidden; pointer-events: none; display: none;
}
.pick-foot, .wheel-foot {
  display: flex; align-items: center; gap: 13px;
  padding: 14px 18px calc(env(safe-area-inset-bottom) + 14px);
  border-top: 1px solid var(--line); background: var(--card);
}
.pick-sw { width: 50px; height: 50px; border-radius: 13px; border: 1px solid rgba(0,0,0,.1); flex: none; }
.pick-info { flex: 1; min-width: 0; }
.pick-info b { display: block; font: 700 17px/1.3 ui-monospace, Menlo, monospace; }
.pick-info span { font-size: 12px; }
.ring-size { display: flex; align-items: center; gap: 2px; font-size: 12px; color: var(--dim); }

.wheel-wrap {
  flex: 1; display: flex; align-items: center; justify-content: center;
  touch-action: none; padding: 20px;
}
#wheelCanvas { touch-action: none; max-width: 100%; }
.light-row {
  display: flex; align-items: center; gap: 14px;
  padding: 4px 22px calc(env(safe-area-inset-bottom) + 18px);
  background: var(--card); font-size: 13px; color: var(--dim);
}
.light-row input { margin: 0; }

/* ---------- sheet ---------- */
.sheet {
  background: var(--card); border-radius: 20px; padding: 22px;
  width: 100%; max-width: 400px; max-height: 82vh; overflow-y: auto;
}
.name-row { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.name-input {
  flex: 1; border: 0; border-bottom: 2px solid var(--line);
  font-size: 19px; padding: 9px 2px; background: transparent; color: var(--ink);
}
.name-input:focus { outline: 0; border-bottom-color: var(--accent); }
.sheet-btns { display: flex; justify-content: flex-end; align-items: center; gap: 8px; }

.d-head { display: flex; gap: 14px; align-items: center; margin-bottom: 16px; }
.d-sw { width: 66px; height: 66px; border-radius: 15px; border: 1px solid rgba(0,0,0,.08); flex: none; }
.d-name { font-size: 21px; font-weight: 700; }
.d-meta { font-size: 13px; color: var(--dim); }
.d-list { border-top: 1px solid var(--line); margin-bottom: 16px; }
.d-row {
  display: flex; align-items: center; gap: 11px;
  padding: 11px 0; border-bottom: 1px solid #F2ECE2;
}
.d-row .p-dot { width: 22px; height: 22px; }
.d-row .p-name { font-size: 15.5px; }
.d-row .p-g { font-size: 18px; }
.d-del { color: var(--bad); }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabh) + 28px);
  transform: translateX(-50%); z-index: 90;
  background: rgba(46,42,38,.94); color: #FFF9EC;
  padding: 11px 20px; border-radius: 12px; font-size: 15px;
  max-width: 84vw; text-align: center;
}
