/* img2threejs — theme-aware UI. Dark is the primary look (3D viewport apps
 * read better dark); light stays fully supported. */

:root[data-theme="light"] {
  --bg: #eef0f6; --bg2: #ffffff; --card: #ffffff; --line: #d9dce6;
  --text: #191b22; --muted: #5c6270; --accent: #3b6ef6; --accent-soft: #e3ebff;
  --ok: #178a4c; --warn-bg: #fff6e0; --warn-text: #7a5a10; --warn-line: #e8d49a;
  --code-bg: #f4f5fa; --shadow: 0 10px 30px rgba(25, 30, 50, 0.08);
}
:root[data-theme="dark"] {
  --bg: #101117; --bg2: #15161e; --card: #1a1c26; --line: #2a2d3c;
  --text: #e8eaf2; --muted: #9aa0b4; --accent: #7aa2ff; --accent-soft: #223154;
  --ok: #4cc98a; --warn-bg: #33290f; --warn-text: #ecd489; --warn-line: #57491c;
  --code-bg: #12131b; --shadow: 0 12px 34px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.55 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.tiny { font-size: 12.5px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* header */
.hdr {
  position: sticky; top: 0; z-index: 20; backdrop-filter: blur(10px);
  background: color-mix(in srgb, var(--bg2) 82%, transparent);
  border-bottom: 1px solid var(--line);
}
.hdr-inner {
  max-width: 1340px; margin: 0 auto; padding: 10px 20px;
  display: flex; align-items: center; gap: 16px;
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 17px; color: var(--text); }
.brand:hover { text-decoration: none; }
.hdr-actions { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.hdr-link { color: var(--muted); font-size: 13.5px; }
.hdr-link.accent { color: var(--accent); font-weight: 600; }
.hdr-credits { display: inline-flex; align-items: center; gap: 8px; font-size: 13.5px; color: var(--muted); }

/* buttons */
.btn {
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  border-radius: 9px; padding: 7px 14px; font-size: 14px; cursor: pointer;
  transition: transform 0.06s ease, background 0.12s ease, border-color 0.12s ease;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 10px; font-size: 12.5px; border-radius: 7px; }
.btn.big { width: 100%; padding: 12px; font-size: 15.5px; border-radius: 11px; }
.btn.icon { padding: 6px 10px; font-size: 15px; }

/* layout */
.main { max-width: 1340px; margin: 0 auto; padding: 26px 20px 60px; }
.hero { text-align: center; margin: 14px auto 30px; max-width: 760px; }
.hero h1 {
  font-size: clamp(24px, 3.4vw, 34px); line-height: 1.2; margin: 0 0 10px;
  background: linear-gradient(100deg, var(--text), var(--accent));
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}
.hero p { color: var(--muted); margin: 0; font-size: 15.5px; }
.layout { display: grid; grid-template-columns: 380px 1fr; gap: 20px; align-items: start; }
@media (max-width: 980px) { .layout { grid-template-columns: 1fr; } }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 18px; margin-bottom: 16px; box-shadow: var(--shadow);
}
.card h3 { margin: 0 0 12px; font-size: 15px; letter-spacing: 0.01em; }
.card h4 { margin: 14px 0 6px; font-size: 13.5px; }
.lbl { display: block; font-size: 12.5px; color: var(--muted); margin: 12px 0 4px; }
input[type="text"], input[type="search"], textarea, select {
  width: 100%; background: var(--bg2); color: var(--text);
  border: 1px solid var(--line); border-radius: 9px; padding: 9px 11px; font: inherit;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); }
textarea { resize: vertical; }

/* dropzone */
.dropzone {
  border: 1.5px dashed var(--line); border-radius: 12px; min-height: 130px;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease; position: relative; overflow: hidden;
}
.dropzone.over, .dropzone:hover { border-color: var(--accent); background: var(--accent-soft); }
.drop-hint { text-align: center; color: var(--muted); padding: 18px; }
.drop-hint strong { display: block; color: var(--text); margin-bottom: 3px; }
.drop-hint span { font-size: 12.5px; }
.ref-preview { width: 100%; position: relative; }
.ref-preview img { display: block; width: 100%; max-height: 260px; object-fit: contain; background: var(--bg2); }
.ref-preview .btn { position: absolute; top: 8px; right: 8px; }

/* prescan */
.prescan { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 4px; }
.prescan-row { display: flex; gap: 14px; align-items: center; }
.palette { display: flex; flex-wrap: wrap; gap: 7px; flex: 1; }
.swatch {
  width: 30px; height: 30px; border-radius: 8px; border: 1px solid var(--line);
  cursor: pointer; padding: 0;
}
.swatch:hover { transform: scale(1.12); }
#sil-canvas { background: var(--bg2); border: 1px solid var(--line); border-radius: 9px; }

/* status / progress */
.status { margin-top: 14px; border: 1px solid var(--line); border-radius: 11px; padding: 12px 14px; background: var(--bg2); }
.status-head { display: flex; align-items: center; gap: 9px; font-weight: 600; font-size: 14px; }
.status-timer { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; font-weight: 400; }
.spinner {
  width: 13px; height: 13px; border-radius: 50%;
  border: 2px solid var(--accent); border-top-color: transparent;
  animation: spin 0.8s linear infinite; flex: none;
}
.spinner.stopped { animation: none; border-top-color: var(--accent); }
@keyframes spin { to { transform: rotate(360deg); } }
.steps { list-style: none; margin: 10px 0 0; padding: 0; }
.step { display: flex; align-items: center; gap: 8px; padding: 3.5px 0; color: var(--muted); font-size: 13px; }
.step .mark { visibility: hidden; color: var(--ok); font-weight: 700; }
.step.done .mark { visibility: visible; }
.step.done { color: var(--text); }
.step.active { color: var(--accent); }
.step-time { margin-left: auto; font-variant-numeric: tabular-nums; font-size: 12px; }
.status-note { margin-top: 8px; font-size: 12.5px; color: var(--muted); }

/* examples */
.examples { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.example-card {
  border: 1px solid var(--line); border-radius: 11px; background: var(--bg2);
  padding: 0 0 8px; cursor: pointer; text-align: center; overflow: hidden;
  color: var(--text); font: inherit; font-size: 13.5px; font-weight: 600;
}
.example-card:hover { border-color: var(--accent); }
.example-card img { width: 100%; height: 96px; object-fit: cover; display: block; margin-bottom: 7px; }
.example-card small { display: block; color: var(--muted); font-weight: 400; font-size: 11.5px; }

/* viewer */
.viewer-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  overflow: hidden; box-shadow: var(--shadow); margin-bottom: 16px;
}
.viewer-toolbar {
  display: flex; gap: 6px; padding: 9px 12px; border-bottom: 1px solid var(--line);
  background: var(--bg2); flex-wrap: wrap;
}
.tb {
  border: 1px solid var(--line); background: transparent; color: var(--muted);
  font-size: 12.5px; border-radius: 8px; padding: 4px 11px; cursor: pointer;
}
.tb:hover { color: var(--text); border-color: var(--accent); }
.tb.on { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.tb-spacer { flex: 1; }
.viewer-split { display: flex; min-height: 470px; }
.side-ref {
  width: 38%; min-width: 200px; border-right: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center; background: var(--bg2); padding: 10px;
}
.side-ref img { max-width: 100%; max-height: 450px; object-fit: contain; border-radius: 8px; }
.canvas-host { flex: 1; position: relative; min-height: 470px; }
.canvas-host canvas { display: block; width: 100% !important; height: 100% !important; position: absolute; inset: 0; }
.viewer-empty {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center;
  color: var(--muted); padding: 30px; z-index: 2; pointer-events: none;
}
.viewer-empty p { margin: 4px 0; max-width: 420px; }

/* result card */
.result-head { display: flex; align-items: baseline; gap: 12px; }
.result-head h2 { margin: 0 0 2px; font-size: 20px; text-transform: capitalize; }
.banner {
  border-radius: 10px; padding: 10px 14px; margin-bottom: 14px; font-size: 13.5px;
  display: flex; gap: 12px; align-items: center; justify-content: space-between;
}
.banner.warn { background: var(--warn-bg); color: var(--warn-text); border: 1px solid var(--warn-line); }
.banner a { font-weight: 600; white-space: nowrap; }

.tabbar { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: 14px 0 0; flex-wrap: wrap; }
.tab {
  border: none; background: transparent; color: var(--muted); font: inherit; font-size: 13.5px;
  padding: 8px 14px; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab:hover { color: var(--text); }
.tab.sel { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.tabpanel { padding: 16px 2px 4px; }
.panel-actions { display: flex; gap: 8px; margin-bottom: 10px; }

.codeblock {
  background: var(--code-bg); border: 1px solid var(--line); border-radius: 10px;
  padding: 14px; overflow-y: auto; max-height: 480px; font: 12.5px/1.55 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  white-space: pre-wrap; overflow-wrap: anywhere; margin: 0;
}

/* parts */
.parts { display: flex; flex-direction: column; gap: 4px; max-height: 420px; overflow: auto; }
.part-row {
  display: flex; align-items: center; gap: 10px; padding: 7px 10px;
  border: 1px solid transparent; border-radius: 8px; background: transparent;
  color: var(--text); font: inherit; font-size: 13.5px; cursor: pointer; text-align: left;
}
.part-row:hover { background: var(--bg2); }
.part-row.sel { border-color: var(--accent); background: var(--accent-soft); }
.part-row.all { color: var(--muted); font-size: 12.5px; }
.part-row .dot { width: 14px; height: 14px; border-radius: 5px; border: 1px solid var(--line); flex: none; }
.part-row .dot.pivot { border-style: dashed; background: transparent !important; }
.part-row .pname { font-weight: 600; }
.part-row .pkind { margin-left: auto; color: var(--muted); font-size: 12px; }

/* report */
.report h4 { margin: 16px 0 6px; font-size: 13.5px; }
.report h4:first-child { margin-top: 0; }
.report ul { margin: 4px 0; padding-left: 20px; font-size: 13.5px; }
.report li { margin: 3px 0; }
.report p { margin: 4px 0; font-size: 13px; }

/* history */
.history { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.hist-row {
  display: flex; align-items: center; gap: 12px; border: 1px solid var(--line);
  border-radius: 10px; padding: 9px 12px; background: var(--bg2);
}
.hist-thumb { width: 46px; height: 46px; object-fit: cover; border-radius: 8px; flex: none; }
.hist-body { flex: 1; min-width: 0; }
.hist-title { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-transform: capitalize; }
.hist-meta { color: var(--muted); font-size: 12px; }

/* footer */
.ftr {
  border-top: 1px solid var(--line); padding: 22px 20px 34px; text-align: center;
  color: var(--muted); font-size: 13px;
}
.ftr p { max-width: 720px; margin: 4px auto; }
