:root {
  --ink: #152422;
  --muted: #6c7976;
  --line: #dbe5e2;
  --surface: #ffffff;
  --canvas: #f3f7f5;
  --accent: #0d8b82;
  --accent-deep: #08736b;
  --accent-soft: #e3f4f0;
  --shadow: 0 16px 40px rgba(25, 63, 58, .08);
  font-family: "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
  color: var(--ink);
  background: #f7faf9;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; }
button, input, select { font: inherit; }
button { cursor: pointer; }

.topbar { height: 74px; padding: 0 max(24px, calc((100vw - 1440px) / 2)); display: flex; align-items: center; justify-content: space-between; background: rgba(255,255,255,.92); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; backdrop-filter: blur(12px); }
.brand { display: flex; align-items: center; gap: 11px; color: var(--ink); text-decoration: none; }
.brand strong { display: block; font-size: 18px; letter-spacing: 0; line-height: 1; }
.brand small { display: block; margin-top: 4px; color: var(--muted); font-size: 9px; letter-spacing: .13em; }
.brand-mark { width: 31px; height: 31px; display: grid; grid-template-columns: repeat(2, 1fr); gap: 3px; padding: 3px; border: 2px solid var(--accent); border-radius: 5px; }
.brand-mark i { border-radius: 1px; background: var(--accent); }
.top-actions, .export-actions { display: flex; gap: 9px; align-items: center; }
.button { min-height: 38px; padding: 0 14px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--ink); font-size: 14px; font-weight: 650; white-space: nowrap; transition: transform .18s ease, border-color .18s ease, background .18s ease; }
.button:hover { border-color: var(--accent); }
.button:active { transform: translateY(1px); }
.button-primary { border-color: var(--accent); color: #fff; background: var(--accent); }
.button-primary:hover { background: var(--accent-deep); }
.button-soft { background: #f7fbfa; color: var(--accent-deep); }

main { max-width: 1440px; margin: 0 auto; padding: 28px 28px 52px; }
.intro { display: flex; justify-content: space-between; align-items: end; gap: 40px; margin: 0 0 23px; }
.intro h1 { max-width: 610px; margin: 4px 0 0; font-size: clamp(28px, 3.4vw, 44px); line-height: 1.16; letter-spacing: 0; }
.intro > p { max-width: 340px; margin: 0 0 5px; color: var(--muted); line-height: 1.7; font-size: 14px; }
.kicker, .panel-eyebrow { margin: 0; color: var(--accent-deep); font-size: 11px; font-weight: 700; letter-spacing: .08em; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); }
.workspace { display: grid; grid-template-columns: minmax(0, 1fr) 32px minmax(0, 1.18fr); align-items: stretch; }
.source-panel, .result-panel { min-height: 524px; padding: 20px; }
.workspace-divider { display: flex; align-items: center; justify-content: center; background: linear-gradient(var(--accent), var(--accent)) center/1px 100% no-repeat; }
.workspace-divider span { width: 32px; height: 32px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 50%; background: #fff; color: var(--accent); font-weight: 700; }
.panel-heading { min-height: 49px; display: flex; align-items: start; justify-content: space-between; gap: 14px; }
h2 { margin: 4px 0 0; font-size: 18px; line-height: 1.2; letter-spacing: 0; }
.file-type { margin-top: 6px; color: var(--muted); font-size: 11px; white-space: nowrap; }
.upload-zone { position: relative; height: 395px; display: grid; place-items: center; overflow: hidden; border: 1px dashed #b7ceca; background-color: #f7faf9; background-image: linear-gradient(45deg, #edf3f1 25%, transparent 25%), linear-gradient(-45deg, #edf3f1 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #edf3f1 75%), linear-gradient(-45deg, transparent 75%, #edf3f1 75%); background-size: 22px 22px; background-position: 0 0, 0 11px, 11px -11px, -11px 0; cursor: pointer; }
.upload-zone.is-dragging { outline: 3px solid rgba(13,139,130,.25); border-color: var(--accent); }
.upload-zone img { position: absolute; width: 100%; height: 100%; object-fit: contain; display: none; background: #eef5f3; transition: transform .2s ease; }
.upload-zone.has-image img { display: block; }
.upload-zone.has-image .upload-copy { display: none; }
.upload-copy { display: flex; flex-direction: column; align-items: center; gap: 7px; color: var(--muted); font-size: 13px; text-align: center; }
.upload-copy strong { color: var(--accent-deep); font-size: 16px; }
.upload-icon { width: 43px; height: 43px; display: grid; place-items: center; border: 1px solid #a7cfca; color: var(--accent); font-size: 31px; line-height: 1; }
.zoom-row { display: grid; grid-template-columns: 75px 1fr 42px; align-items: center; gap: 9px; margin-top: 16px; color: var(--muted); font-size: 12px; }
input[type="range"] { appearance: none; width: 100%; height: 6px; border-radius: 20px; background: #d9e4e1; outline: none; accent-color: var(--accent); }
input[type="range"]::-webkit-slider-thumb { appearance: none; width: 16px; height: 16px; border: 2px solid #fff; border-radius: 50%; background: var(--accent); box-shadow: 0 1px 4px rgba(0,0,0,.18); }
.result-heading { align-items: start; }
.view-toggle { display: flex; padding: 3px; border: 1px solid var(--line); border-radius: 6px; background: #f6f9f8; }
.view-toggle button { padding: 5px 10px; border: 0; border-radius: 4px; color: var(--muted); background: transparent; font-size: 12px; font-weight: 650; }
.view-toggle button.is-active { color: var(--accent-deep); background: #fff; box-shadow: 0 1px 4px rgba(25,63,58,.1); }
.canvas-wrap { position: relative; height: 395px; display: flex; align-items: flex-start; justify-content: flex-start; overflow: auto; border: 1px solid var(--line); background: #f8fbfa; }
canvas { display: block; image-rendering: pixelated; }
.canvas-wrap::-webkit-scrollbar { width: 9px; height: 9px; }
.canvas-wrap::-webkit-scrollbar-thumb { border: 2px solid #f8fbfa; border-radius: 20px; background: #a8c3bd; }
.canvas-wrap::-webkit-scrollbar-corner { background: #f8fbfa; }
.canvas-empty { position: absolute; color: #96a5a2; font-size: 14px; pointer-events: none; }
.result-meta { display: flex; justify-content: space-between; gap: 10px; margin-top: 16px; color: var(--muted); font-size: 12px; }
.result-meta #beadVisualInfo { color: var(--accent-deep); font-weight: 700; }

.settings { display: grid; grid-template-columns: 180px 1fr; gap: 24px; padding: 22px; margin-top: 24px; }
.settings-grid { display: grid; grid-template-columns: 1.35fr repeat(3, 1fr) 1.75fr; gap: 17px; align-items: end; }
.control { display: grid; gap: 9px; color: var(--muted); font-size: 12px; }
.control b { color: var(--accent-deep); font-size: 14px; }
.control select { height: 38px; width: 100%; padding: 0 9px; border: 1px solid var(--line); border-radius: 5px; color: var(--ink); background: #fff; font-size: 13px; }
.number-row { display: flex; align-items: center; gap: 9px; }
.step-button { width: 30px; height: 30px; border: 1px solid var(--line); border-radius: 4px; background: #fff; color: var(--accent-deep); font-size: 18px; line-height: 1; }
.switches { display: grid; grid-template-columns: repeat(3, max-content); gap: 15px; min-height: 38px; align-items: center; }
.switch { display: flex; gap: 6px; align-items: center; color: var(--muted); font-size: 12px; white-space: nowrap; }
.switch input { position: absolute; opacity: 0; }
.switch span { width: 30px; height: 17px; border-radius: 99px; background: #cbd8d5; position: relative; transition: background .2s ease; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 11px; height: 11px; border-radius: 50%; background: #fff; transition: transform .2s ease; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(13px); }

.inventory { margin-top: 38px; }
.inventory-heading { display: flex; align-items: end; justify-content: space-between; gap: 20px; }
.inventory-heading h2 { font-size: 25px; }
.inventory-heading p:not(.panel-eyebrow) { margin: 6px 0 0; color: var(--muted); font-size: 14px; }
.inventory-summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; margin-top: 18px; border: 1px solid var(--line); background: var(--line); }
.inventory-summary div { padding: 14px 17px; background: #fff; }
.inventory-summary span { display: block; color: var(--muted); font-size: 12px; }
.inventory-summary strong { display: block; margin-top: 5px; font-size: 16px; }
.color-list { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-top: 14px; }
.color-item { display: grid; grid-template-columns: 38px 1fr auto; align-items: center; gap: 10px; padding: 10px; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.color-swatch { width: 38px; height: 38px; border: 1px solid rgba(0,0,0,.11); border-radius: 4px; }
.color-item strong { display: block; font-size: 14px; }
.color-item small { display: block; margin-top: 2px; color: var(--muted); font-size: 11px; }
.color-item b { font-size: 14px; }
.required-section, .palette-section { margin-top: 26px; }
.palette-section { padding-top: 21px; border-top: 1px solid var(--line); }
.list-heading { display: flex; align-items: end; justify-content: space-between; gap: 18px; }
.list-heading h3 { margin: 0; font-size: 16px; }
.list-heading h3 span { margin-left: 5px; color: var(--accent-deep); font-size: 13px; }
.list-heading p { margin: 5px 0 0; color: var(--muted); font-size: 12px; }
.palette-search { display: flex; align-items: center; gap: 7px; min-width: 250px; height: 36px; padding: 0 9px; border: 1px solid var(--line); border-radius: 5px; background: #fff; color: var(--muted); }
.palette-search input { width: 100%; border: 0; outline: 0; color: var(--ink); font-size: 13px; }
.all-colors { display: grid; grid-template-columns: repeat(11, minmax(0, 1fr)); gap: 8px; max-height: 420px; margin-top: 14px; padding: 2px; overflow: auto; }
.palette-item { min-height: 106px; display: grid; justify-items: center; align-content: center; gap: 6px; padding: 7px 4px; border: 1px solid var(--line); border-radius: 5px; background: #fff; color: var(--muted); font-size: 11px; text-align: center; }
.palette-item.is-used { border: 2px solid var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); color: var(--accent-deep); }
.palette-item b { color: var(--ink); font-size: 12px; }
.bead-swatch { width: 31px; height: 31px; border: 1px solid rgba(0,0,0,.1); border-radius: 50%; background: var(--swatch); box-shadow: inset 4px 4px 5px rgba(255,255,255,.42), inset -3px -3px 4px rgba(0,0,0,.15); }
.bead-swatch::after { content: ""; display: block; width: 12px; height: 12px; margin: 8px; border-radius: 50%; background: rgba(31,50,47,.22); box-shadow: inset 1px 1px 2px rgba(0,0,0,.2); }
footer { padding: 20px 24px; border-top: 1px solid var(--line); color: var(--muted); background: #fff; text-align: center; font-size: 12px; }
.toast { position: fixed; right: 22px; bottom: 22px; z-index: 10; padding: 10px 14px; border-radius: 5px; color: #fff; background: #1d3935; font-size: 13px; opacity: 0; pointer-events: none; transform: translateY(10px); transition: opacity .2s ease, transform .2s ease; }
.toast.is-visible { opacity: 1; transform: translateY(0); }

@media (max-width: 1080px) {
  .settings { grid-template-columns: 1fr; }
  .settings-grid { grid-template-columns: 1.4fr repeat(3, 1fr); }
  .switches { grid-column: 1 / -1; }
}
@media (max-width: 820px) {
  .topbar { padding: 0 16px; }
  .button { padding: 0 10px; }
  .top-actions .button-soft { display: none; }
  main { padding: 22px 16px 40px; }
  .intro { display: block; }
  .intro > p { margin-top: 12px; }
  .workspace { grid-template-columns: 1fr; }
  .workspace-divider { height: 32px; background: linear-gradient(90deg, var(--accent), var(--accent)) center/100% 1px no-repeat; }
  .workspace-divider span { transform: rotate(90deg); }
  .source-panel, .result-panel { min-height: 0; }
  .upload-zone, .canvas-wrap { height: min(68vw, 370px); }
  .settings-grid { grid-template-columns: repeat(2, 1fr); }
  .control-wide, .switches { grid-column: 1 / -1; }
  .color-list { grid-template-columns: repeat(2, 1fr); }
  .all-colors { grid-template-columns: repeat(7, minmax(0, 1fr)); }
}
@media (max-width: 540px) {
  .brand small { display: none; }
  .top-actions .button-secondary:first-child span { display: none; }
  .top-actions .button-secondary { font-size: 12px; padding: 0 8px; }
  .source-panel, .result-panel, .settings { padding: 15px; }
  .settings-grid { grid-template-columns: 1fr; }
  .control-wide, .switches { grid-column: auto; }
  .switches { grid-template-columns: 1fr 1fr; gap: 10px; }
  .inventory-heading { display: block; }
  .export-actions { margin-top: 15px; }
  .inventory-summary { grid-template-columns: 1fr; }
  .color-list { grid-template-columns: 1fr; }
  .list-heading { align-items: start; flex-direction: column; }
  .palette-search { width: 100%; min-width: 0; }
  .all-colors { grid-template-columns: repeat(4, minmax(0, 1fr)); max-height: 360px; }
}
