:root {
  --bg: #0e1015;
  --card: #171a21;
  --card-2: #1d212a;
  --line: rgba(255, 255, 255, .08);
  --text: #eef0f5;
  --muted: #969cab;
  --accent: #ff6b57;
  --accent-2: #ff9a6b;
  --mint: #4fd6a8;
  --radius: 18px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background:
    radial-gradient(900px 420px at 88% -8%, rgba(255, 107, 87, .12), transparent 70%),
    radial-gradient(700px 400px at -10% 28%, rgba(79, 214, 168, .07), transparent 70%),
    var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Noto Sans SC", "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
}
button, input, select { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.app { max-width: 720px; margin: 0 auto; padding: 0 14px calc(94px + var(--safe-bottom)); }

/* 顶部 */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 4px 12px;
  background: linear-gradient(180deg, rgba(14, 16, 21, .96), rgba(14, 16, 21, .72));
  backdrop-filter: blur(14px);
}
.brand { display: flex; align-items: center; gap: 11px; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 12px; flex: none;
  background: linear-gradient(145deg, #262b36, #171a21);
  border: 1px solid var(--line);
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 3px;
  padding: 8px; box-shadow: 0 6px 18px rgba(0, 0, 0, .28);
}
.brand-mark i { border-radius: 50%; box-shadow: inset 0 -2px 3px rgba(0, 0, 0, .25); }
.brand-mark i:nth-child(1) { background: #ff6b57; }
.brand-mark i:nth-child(2) { background: #ffd166; }
.brand-mark i:nth-child(3) { background: #4fd6a8; }
.brand-mark i:nth-child(4) { background: #7c8cff; }
.brand-text h1 { margin: 0; font-size: 17px; letter-spacing: .3px; font-weight: 700; }
.brand-text p { margin: 1px 0 0; font-size: 11px; color: var(--muted); letter-spacing: .2px; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 11px; border: 1px solid var(--line);
  background: rgba(255, 255, 255, .04); color: var(--muted);
  font-size: 15px; font-weight: 700; display: grid; place-items: center;
}
.icon-btn:active { transform: scale(.94); }

/* 卡片 */
.card {
  background: linear-gradient(160deg, var(--card-2), var(--card) 62%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 17px 16px;
  margin-bottom: 13px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, .16);
}
.section-title { display: flex; align-items: center; gap: 9px; margin-bottom: 14px; }
.section-title h2 { margin: 0; font-size: 14px; font-weight: 650; letter-spacing: .3px; }
.step {
  width: 21px; height: 21px; border-radius: 7px; flex: none;
  display: grid; place-items: center; font-size: 11px; font-weight: 800;
  color: #1a1210; background: linear-gradient(145deg, var(--accent-2), var(--accent));
}
.badge {
  margin-left: auto; font-size: 11px; color: var(--muted);
  padding: 3px 9px; border-radius: 999px; background: rgba(255, 255, 255, .05);
  border: 1px solid var(--line); white-space: nowrap;
}
.badge.ready { color: var(--mint); border-color: rgba(79, 214, 168, .25); background: rgba(79, 214, 168, .09); }

/* 上传 */
.dropzone {
  display: flex; align-items: center; gap: 13px;
  padding: 17px 15px; border-radius: 14px; cursor: pointer;
  border: 1.5px dashed rgba(255, 255, 255, .18);
  background: rgba(255, 255, 255, .025);
  transition: border-color .18s, background .18s;
}
.dropzone:hover, .dropzone.dragover { border-color: var(--accent); background: rgba(255, 107, 87, .06); }
.dz-icon {
  width: 42px; height: 42px; flex: none; border-radius: 13px; display: grid; place-items: center;
  background: linear-gradient(145deg, rgba(255, 107, 87, .2), rgba(255, 154, 107, .08));
  color: var(--accent-2);
}
.dz-icon svg { width: 23px; height: 23px; }
.dz-text { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.dz-text b { font-size: 13px; font-weight: 600; }
.dz-text small, .hint, .tip { color: var(--muted); font-size: 11px; }
.source-row {
  display: flex; align-items: center; gap: 11px; margin-top: 11px;
  padding: 8px; border-radius: 12px; background: rgba(255, 255, 255, .035);
  border: 1px solid var(--line);
}
.source-row img { width: 46px; height: 46px; border-radius: 9px; object-fit: cover; background: #222; }
.source-meta { min-width: 0; flex: 1; display: flex; flex-direction: column; }
.source-meta b { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.source-meta small { color: var(--muted); font-size: 11px; }
.text-btn, .inline-btn {
  border: 0; background: transparent; color: var(--accent-2); font-size: 12px; padding: 5px;
}
.inline-btn { margin-top: 9px; padding: 6px 0; }
.inline-btn:disabled { color: #5b6070; cursor: default; }

/* 表单 */
.field { margin-bottom: 14px; min-width: 0; }
.field:last-child { margin-bottom: 0; }
.field-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.field label { display: block; font-size: 12px; color: #cdd2de; margin-bottom: 7px; }
.field-head label { margin: 0; }
.value { font-size: 12px; font-weight: 700; color: var(--accent-2); }
.range { width: 100%; height: 20px; margin: 0; appearance: none; background: transparent; }
.range::-webkit-slider-runnable-track { height: 5px; border-radius: 99px; background: linear-gradient(90deg, var(--accent), #3b404e); }
.range::-webkit-slider-thumb {
  appearance: none; width: 18px; height: 18px; border-radius: 50%; margin-top: -6.5px;
  background: #fff; border: 4px solid var(--accent); box-shadow: 0 2px 8px rgba(0, 0, 0, .35);
}
.range::-moz-range-track { height: 5px; border-radius: 99px; background: #3b404e; }
.range::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: #fff; border: 4px solid var(--accent); }
.presets { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.presets button {
  min-width: 42px; padding: 5px 8px; border-radius: 8px; font-size: 11px;
  border: 1px solid var(--line); background: rgba(255, 255, 255, .035); color: var(--muted);
}
.presets button.active { color: #fff; border-color: rgba(255, 107, 87, .55); background: rgba(255, 107, 87, .15); }
.hint { margin: 8px 0 0; }
.hint b { color: #d7dbe5; font-weight: 600; }
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }
select, .text-input {
  width: 100%; height: 38px; padding: 0 10px; color: var(--text);
  background: rgba(255, 255, 255, .045); border: 1px solid var(--line);
  border-radius: 10px; outline: none; appearance: none;
}
select { background-image: linear-gradient(45deg, transparent 50%, #8e94a4 50%), linear-gradient(135deg, #8e94a4 50%, transparent 50%); background-position: calc(100% - 15px) 16px, calc(100% - 10px) 16px; background-size: 5px 5px; background-repeat: no-repeat; }
select option { background: #1b1e26; }
.text-input::placeholder { color: #6e7484; }
.text-input:focus, select:focus { border-color: rgba(255, 107, 87, .55); }
.switches { border-top: 1px solid var(--line); padding-top: 6px; margin-top: 4px; }
.switch-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 9px 0; font-size: 12px; color: #d5d9e3; cursor: pointer;
}
.switch-row input { position: absolute; opacity: 0; pointer-events: none; }
.switch {
  width: 38px; height: 22px; border-radius: 99px; flex: none; position: relative;
  background: #343945; transition: background .2s;
}
.switch::after {
  content: ''; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px;
  border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 1px 4px rgba(0, 0, 0, .4);
}
.switch-row input:checked + .switch { background: var(--accent); }
.switch-row input:checked + .switch::after { transform: translateX(16px); }
.tip { margin: 6px 0 0; line-height: 1.6; }

/* 图纸 */
.paper-wrap {
  background: #f5f5f3; border-radius: 12px; padding: 10px; min-height: 170px;
  display: flex; align-items: center; justify-content: center; overflow-x: auto;
  box-shadow: inset 0 2px 12px rgba(0, 0, 0, .25);
}
#patternCanvas { display: block; max-width: none; height: auto; background: #fff; box-shadow: 0 4px 18px rgba(0, 0, 0, .18); }
.empty-state { display: flex; flex-direction: column; align-items: center; gap: 6px; color: #8b9099; padding: 26px 10px; text-align: center; }
.empty-state b { color: #646a75; font-size: 13px; }
.empty-state small { font-size: 11px; }
.empty-beads { display: grid; grid-template-columns: repeat(3, 10px); gap: 4px; margin-bottom: 6px; }
.empty-beads i { width: 10px; height: 10px; border-radius: 50%; background: #d5d7da; }
.empty-beads i:nth-child(2), .empty-beads i:nth-child(6) { background: #e9b3a8; }
.empty-beads i:nth-child(5) { background: #a8d8c0; }
.result-actions { display: flex; gap: 14px; justify-content: center; margin: 12px 0; }
.result-actions .inline-btn { margin: 0; }
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.stat-grid div { padding: 10px 4px; text-align: center; background: rgba(255, 255, 255, .025); }
.stat-grid div + div { border-left: 1px solid var(--line); }
.stat-grid span { display: block; font-size: 10px; color: var(--muted); margin-bottom: 2px; }
.stat-grid b { font-size: 14px; font-weight: 700; }
.footer-note { text-align: center; color: #666c7a; font-size: 10px; line-height: 1.7; margin: 18px 8px 4px; }

/* 底部操作 */
.bottom-bar {
  position: fixed; z-index: 25; left: 0; right: 0; bottom: 0;
  max-width: 720px; margin: 0 auto;
  display: flex; gap: 10px; padding: 11px 14px calc(11px + var(--safe-bottom));
  background: linear-gradient(180deg, rgba(14, 16, 21, .86), rgba(14, 16, 21, .98));
  border-top: 1px solid var(--line); backdrop-filter: blur(14px);
}
.btn {
  flex: 1; height: 44px; border-radius: 12px; border: 0; font-size: 13px; font-weight: 650;
  letter-spacing: .3px; transition: transform .12s, opacity .12s;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .42; cursor: default; transform: none; }
.btn-secondary { background: rgba(255, 255, 255, .08); color: #e5e8ef; border: 1px solid var(--line); }
.btn-primary { background: linear-gradient(135deg, var(--accent-2), var(--accent)); color: #fff; box-shadow: 0 8px 22px rgba(255, 107, 87, .22); }

/* 弹层 */
.modal { position: fixed; inset: 0; z-index: 50; background: #0b0d11; display: flex; flex-direction: column; }
.modal-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(12px + env(safe-area-inset-top, 0px)) 14px 12px;
  border-bottom: 1px solid var(--line); background: #11141a;
}
.modal-bar b { font-size: 13px; }
.modal-bar button { border: 0; background: transparent; color: var(--muted); font-size: 18px; padding: 4px 8px; }
.modal-tools { display: flex; align-items: center; gap: 9px; }
.modal-tools span { font-size: 11px; color: var(--muted); min-width: 40px; text-align: center; }
.modal-body { flex: 1; overflow: auto; padding: 18px; -webkit-overflow-scrolling: touch; }
.modal-body canvas { display: block; margin: 0 auto; background: #fff; transform-origin: top center; }
.help-body { color: #c8cdd8; font-size: 13px; line-height: 1.9; }
.help-body ol { padding-left: 20px; margin: 0 0 14px; }
.help-body b { color: #fff; }
.help-body p { color: var(--muted); font-size: 12px; }

.sheet { position: fixed; inset: 0; z-index: 55; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .62); }
.sheet-panel {
  position: absolute; left: 0; right: 0; bottom: 0; max-width: 720px; margin: 0 auto;
  max-height: 76vh; display: flex; flex-direction: column;
  background: #171a21; border-radius: 20px 20px 0 0; border-top: 1px solid var(--line);
  padding-bottom: var(--safe-bottom);
}
.sheet-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 16px 10px; }
.sheet-head b { display: block; font-size: 15px; }
.sheet-head small { display: block; color: var(--muted); font-size: 11px; margin-top: 2px; }
.check-line { display: flex; align-items: center; gap: 8px; padding: 0 16px 10px; color: #c3c8d4; font-size: 12px; }
.check-line input { accent-color: var(--accent); }
.sheet-tabs { display: flex; gap: 6px; padding: 0 16px 10px; }
.sheet-tabs button { padding: 6px 13px; border-radius: 9px; font-size: 12px; border: 1px solid var(--line); background: rgba(255, 255, 255, .04); color: var(--muted); }
.sheet-tabs button.active { color: #fff; background: rgba(255, 107, 87, .16); border-color: rgba(255, 107, 87, .5); }
.palette-grid { overflow: auto; padding: 4px 16px 12px; display: grid; grid-template-columns: repeat(auto-fill, minmax(62px, 1fr)); gap: 7px; }
.swatch-btn {
  border: 1px solid var(--line); background: rgba(255, 255, 255, .04); border-radius: 10px;
  padding: 7px 3px 6px; display: flex; flex-direction: column; align-items: center; gap: 5px; color: #d7dbe5; font-size: 11px;
}
.swatch-btn i { width: 26px; height: 26px; border-radius: 8px; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .2); }
.swatch-btn small { color: var(--muted); font-size: 9px; }
.sheet-foot { padding: 10px 16px 14px; border-top: 1px solid var(--line); }
.sheet-foot .btn { width: 100%; }

.toast {
  position: fixed; z-index: 90; left: 50%; bottom: calc(90px + var(--safe-bottom)); transform: translate(-50%, 12px);
  background: rgba(30, 34, 43, .97); border: 1px solid var(--line); color: #fff;
  padding: 9px 16px; border-radius: 11px; font-size: 12px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .35); max-width: 86vw; text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 600px) {
  .app { padding-left: 20px; padding-right: 20px; }
  .card { padding: 20px; }
}
@media (max-width: 360px) {
  .field-row { flex-direction: column; gap: 0; }
  .result-actions { gap: 8px; }
}
