:root {
  --bg: #f5f7fa;
  --panel: #ffffff;
  --ink: #1f2a37;
  --muted: #6b7280;
  --line: #e3e8ef;
  --brand: #0f766e;
  --brand-d: #0b5a54;
  --accent: #2563eb;
  --warn: #b45309;
  --shadow: 0 1px 3px rgba(16,24,40,.08), 0 1px 2px rgba(16,24,40,.06);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", "Noto Sans CJK SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
}
a { color: var(--accent); text-decoration: none; }

/* ---------- Header ---------- */
#site-header {
  background: var(--brand);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--shadow);
}
.hdr-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 8px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}
.brand { display: flex; flex-direction: column; line-height: 1.1; color:#fff; }
.brand-name { font-weight: 700; font-size: 18px; }
.brand-tag { font-size: 11px; opacity: .85; }
.hdr-nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1 1 auto; }
.hdr-nav a {
  color: #d7f3ee;
  padding: 5px 9px;
  border-radius: 6px;
  font-size: 13px;
  white-space: nowrap;
}
.hdr-nav a:hover { background: rgba(255,255,255,.14); color:#fff; }
.hdr-nav a.active { background: rgba(255,255,255,.2); color:#fff; font-weight:600; }
.hdr-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.btn-home, .btn-mail {
  background: #fff;
  color: var(--brand-d);
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}
.btn-home:hover, .btn-mail:hover { background: #e6fffb; }
.lang-sel {
  border: 1px solid rgba(255,255,255,.5);
  background: rgba(255,255,255,.12);
  color: #fff;
  padding: 5px 8px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
}
.lang-sel option { color: #111; }

/* ---------- Layout ---------- */
.wrap { max-width: 1180px; margin: 0 auto; padding: 20px 16px 40px; }
.grid { display: grid; grid-template-columns: 320px 1fr; gap: 20px; align-items: start; }
@media (max-width: 860px) { .grid { grid-template-columns: 1fr; } }
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 18px;
  box-shadow: var(--shadow);
}
h1 { font-size: 24px; margin: 4px 0 6px; }
h2 { font-size: 18px; margin: 2px 0 12px; }
.sub { color: var(--muted); margin: 0 0 16px; }

/* ---------- Form ---------- */
.field { margin-bottom: 12px; }
.field label { display:block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.field input, .field select {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line);
  border-radius: 8px; font-size: 14px; background: #fff; color: var(--ink);
}
.field input:focus, .field select:focus { outline: 2px solid var(--brand); border-color: var(--brand); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.btn {
  display: inline-block; border: none; cursor: pointer; border-radius: 8px;
  padding: 10px 14px; font-size: 14px; font-weight: 600;
}
.btn-primary { background: var(--brand); color: #fff; width: 100%; }
.btn-primary:hover { background: var(--brand-d); }
.btn-ghost { background: #eef2f7; color: var(--ink); }
.btn-ghost:hover { background: #e2e8f0; }

/* ---------- Advanced (thickness / allowance) ---------- */
.adv { margin: 4px 0 14px; border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; background: #fbfdff; }
.adv summary { cursor: pointer; font-size: 13px; font-weight: 600; color: var(--brand-d); }
.adv summary:hover { color: var(--brand); }
.adv .dim-note { margin-top: 6px; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 6px; margin: 4px 0 14px; }
.tab-btn {
  flex: 1; padding: 9px 8px; border: 1px solid var(--line); background: #fff; color: var(--muted);
  border-radius: 8px; font-size: 13px; font-weight: 600; cursor: pointer;
}
.tab-btn.active { background: var(--brand); color: #fff; border-color: var(--brand); }

/* ---------- Result ---------- */
.result-head { display:flex; justify-content: space-between; align-items:center; gap: 10px; flex-wrap: wrap; }
.toolbtns { display:flex; gap: 8px; flex-wrap: wrap; }
.svg-box {
  margin-top: 14px; border: 1px dashed var(--line); border-radius: 10px;
  background:
    linear-gradient(45deg,#f0f3f7 25%,transparent 25%,transparent 75%,#f0f3f7 75%) 0 0/18px 18px,
    linear-gradient(45deg,#f0f3f7 25%,transparent 25%,transparent 75%,#f0f3f7 75%) 9px 9px/18px 18px,
    #fff;
  padding: 12px; overflow: auto; text-align:center;
}
.pattern-svg { max-width: 100%; height: auto; display:inline-block; }
.dim-note { font-size: 12px; color: var(--muted); margin-top: 8px; }
.metric { display:inline-block; background:#f1f5f9; border-radius:8px; padding:6px 10px; margin:4px 6px 0 0; font-size:13px; }
.metric b { color: var(--brand-d); }

/* ---------- Companion plates (second plate) ---------- */
.chk { display:flex; align-items:center; gap:8px; margin-top:10px; font-size:13px; color:var(--muted); }
.chk input { width:auto; margin:0; }
.plates { margin-top:16px; border-top:1px dashed var(--line); padding-top:12px; }
.plates-head { font-size:15px; margin:0 0 10px; color:var(--brand-d); }
.plate-card { background:#fbfdff; border:1px solid var(--line); border-radius:10px; padding:12px; margin-bottom:12px; }
.plate-card h4 { margin:0 0 8px; font-size:14px; color:var(--ink); }
.plate-card .metrics { margin-top:10px; }

/* ---------- Home / tools ---------- */
.hero { padding: 26px 22px; }
.tool-grid { display:grid; grid-template-columns: repeat(auto-fill,minmax(220px,1fr)); gap:14px; }
.tool-card {
  display:block; border:1px solid var(--line); border-radius:12px; padding:16px;
  background:#fff; box-shadow: var(--shadow); transition: transform .08s, border-color .12s;
}
.tool-card:hover { transform: translateY(-2px); border-color: var(--brand); }
.tool-card h3 { margin: 0 0 6px; font-size: 16px; }
.tool-card p { margin: 0; color: var(--muted); font-size: 13px; }
.tool-ico { font-size: 22px; margin-bottom: 6px; }

/* ---------- Import drop ---------- */
.drop {
  border: 2px dashed var(--brand); border-radius: 12px; padding: 34px 16px;
  text-align:center; color: var(--muted); background:#f8fbfb; cursor:pointer;
}
.drop.drag { background:#e6fffb; }
.hidden-file { display:none; }

/* ---------- Footer ---------- */
#site-footer { border-top: 1px solid var(--line); background:#fff; }
.ftr-inner { max-width:1180px; margin:0 auto; padding:14px 16px; display:flex; justify-content:space-between; flex-wrap:wrap; gap:8px; color:var(--muted); font-size:13px; }

/* ---------- Print ---------- */
@media print {
  #site-header, #site-footer, .card form, .toolbtns, .no-print { display: none !important; }
  body { background:#fff; }
  .svg-box { border:none; background:#fff; }
  .card { box-shadow:none; border:none; }
}

/* ---------- Header action buttons (theme / unit / project) ---------- */
.hdr-btn {
  border: 1px solid rgba(255,255,255,.5); background: rgba(255,255,255,.12);
  color: #fff; padding: 5px 9px; border-radius: 6px; font-size: 13px; cursor: pointer; white-space: nowrap;
}
.hdr-btn:hover { background: rgba(255,255,255,.24); }

/* ---------- Manufacturing controls (injected into Advanced) ---------- */
.mfg-box { margin-top: 10px; border-top: 1px dashed var(--line); padding-top: 10px; display: grid; gap: 8px; }
.mfg-row { display: grid; grid-template-columns: 1fr 110px; align-items: center; gap: 8px; }
.mfg-row label { font-size: 13px; color: var(--muted); margin: 0; }
.mfg-row input, .mfg-row select { width: 100%; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; font-size: 13px; background: #fff; color: var(--ink); }

/* ---------- Nesting outlines ---------- */
.nest-ta { width: 100%; min-height: 120px; font-family: monospace; font-size: 12px; padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink); resize: vertical; }
.row-btns { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.row-btns .btn { flex: 1 1 auto; }

/* ---------- Dark theme ---------- */
[data-theme="dark"] {
  --bg: #0f1620;
  --panel: #18222e;
  --ink: #e6edf3;
  --muted: #9aa7b4;
  --line: #2a3644;
  --brand: #14b8a6;
  --brand-d: #0d9488;
  --accent: #60a5fa;
  --warn: #f59e0b;
  --shadow: 0 1px 3px rgba(0,0,0,.4), 0 1px 2px rgba(0,0,0,.3);
}
[data-theme="dark"] body { background: var(--bg); }
[data-theme="dark"] .card, [data-theme="dark"] .tool-card, [data-theme="dark"] .plate-card, [data-theme="dark"] .adv,
[data-theme="dark"] #site-footer, [data-theme="dark"] .metric, [data-theme="dark"] .btn-ghost, [data-theme="dark"] .mfg-row input, [data-theme="dark"] .mfg-row select {
  background: var(--panel); color: var(--ink); border-color: var(--line);
}
[data-theme="dark"] .btn-ghost { background: #22303f; color: var(--ink); }
[data-theme="dark"] .btn-ghost:hover { background: #2b3b4d; }
[data-theme="dark"] .tool-card p, [data-theme="dark"] .sub, [data-theme="dark"] .dim-note { color: var(--muted); }
[data-theme="dark"] .svg-box { background: #0b1118; }
[data-theme="dark"] .metric { background: #22303f; }

/* ---- 3D preview panel ---- */
.preview3d-card { margin-top: 18px; }
.preview3d-card .three-canvas {
  width: 100%; height: 340px; display: block;
  border: 1px solid var(--line, #d6dce3); border-radius: 10px;
  background: #eef2f6; cursor: grab; touch-action: none;
}
.preview3d-card .three-canvas:active { cursor: grabbing; }
.preview3d-card .hint { color: var(--muted, #8a93a0); font-size: 12px; margin: 8px 0 0; }
#btn3dSpin.active { background: var(--accent, #0f766e); color: #fff; border-color: transparent; }
[data-theme="dark"] .preview3d-card .three-canvas { background: #0b1118; border-color: var(--line); }

/* ---- Weld seams (3D + 2D linkage) ---- */
.preview3d-card { position: relative; }
.seam-bar { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin: 8px 0 0; }
.seam-toggle { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--muted, #8a93a0); cursor: pointer; }
.seam-legend { display: inline-flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted, #8a93a0); }
.seam-legend .lg { display: inline-flex; align-items: center; gap: 5px; }
.seam-legend .lg i { width: 16px; height: 4px; border-radius: 2px; display: inline-block; }
.seam-label { font-size: 12px; font-weight: 600; color: #b71c1c; margin: 6px 0 0; min-height: 16px; }
[data-theme="dark"] .seam-label { color: #ff8a80; }

.seam-layer { display: none; }
.svg-box.show-seams .seam-layer { display: block; }
.seam-seg { fill: none; stroke-width: 2.6; stroke-linecap: round; vector-effect: non-scaling-stroke; cursor: pointer; pointer-events: stroke; }
.seam-seg[data-kind="long"] { stroke: #e8731a; }
.seam-seg[data-kind="circ"] { stroke: #2673d6; }
.seam-seg[data-kind="inter"] { stroke: #b71c1c; }
.seam-seg.seam-active { stroke: #111; stroke-width: 4.2; }
[data-theme="dark"] .seam-seg.seam-active { stroke: #fff; }

/* ---- Isometric spool builder ---- */
.iso-meta { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.iso-meta .field { flex: 1 1 130px; margin: 0; }
.iso-ta { width: 100%; min-height: 230px; font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 13px; line-height: 1.5; box-sizing: border-box; padding: 10px; border: 1px solid var(--line, #cbd5e1);
  border-radius: 8px; resize: vertical; background: var(--input-bg, #fff); color: var(--text, #1f2937); }
.row-btns { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.row-btns .btn { flex: 1 1 auto; }
.bom-table { width: 100%; border-collapse: collapse; margin-top: 8px; font-size: 13px; }
.bom-table th, .bom-table td { border: 1px solid var(--line, #cbd5e1); padding: 5px 8px; text-align: left; }
.bom-table th { background: var(--muted-bg, #f1f5f9); }
[data-theme="dark"] .iso-ta { background: #0f1a24; border-color: #234; color: #e6edf3; }
[data-theme="dark"] .bom-table th { background: #15212e; }
@media print {
  .no-print, .toolbtns, .adv, .row-btns, header, footer, .iso-meta, .field, #bomWrap .sub { display: none !important; }
  .card { box-shadow: none; border: none; }
}
