:root {
  --bg: #f4f6fa;
  --panel: #ffffff;
  --border: #e2e6ee;
  --text: #1b2333;
  --muted: #6b7486;
  --accent: #2f5fd0;
  --accent-dark: #23499f;
  --soft: #eef2ff;
  --ok: #1f9d63;
  --warn: #d97706;
  --err: #c0392b;
  --radius: 12px;
  font-family: "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 14px; }

.topbar {
  height: 68px; background: var(--panel); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; padding: 0 24px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 40px; height: 40px; border-radius: 10px; background: linear-gradient(135deg, #2f5fd0, #6e97f2);
  color: #fff; display: grid; place-items: center; font-weight: 800; letter-spacing: -1px;
}
.brand h1 { margin: 0; font-size: 19px; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.topbar-right { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
.home-btn { white-space: nowrap; }
.home-btn:hover { background: var(--accent); color: #fff; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); }
.status-dot.online { background: var(--ok); }

.layout { display: grid; grid-template-columns: 340px 1fr; gap: 16px; padding: 16px; height: calc(100vh - 68px); }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.controls { overflow-y: auto; padding: 4px 18px 20px; }
.step { padding: 16px 0; border-bottom: 1px solid var(--border); }
.step:last-child { border-bottom: 0; }
.step h2 { margin: 0 0 12px; font-size: 14px; display: flex; align-items: center; gap: 8px; }
.step-no { width: 22px; height: 22px; border-radius: 6px; background: var(--soft); color: var(--accent); display: grid; place-items: center; font-size: 12px; font-weight: 700; }

.dropzone {
  border: 1.5px dashed #c6cede; border-radius: 10px; padding: 18px 10px; text-align: center;
  cursor: pointer; transition: .15s; background: #fafbfe;
}
.dropzone:hover, .dropzone.drag { border-color: var(--accent); background: var(--soft); }
.drop-icon { font-size: 26px; color: var(--accent); line-height: 1; }
.drop-title { font-weight: 600; margin-top: 6px; }
.drop-hint { color: var(--muted); font-size: 11px; margin-top: 4px; }
.file-info { margin-top: 8px; font-size: 12px; color: var(--muted); word-break: break-all; }

/* PA-29-C: long Chinese advice copy used to collapse into an unreadable
   single line (buttons inline + no wrapping). Keep the summary as its own
   paragraph and let the action buttons wrap onto separate lines. */
.advice-box { margin-top: 8px; padding: 10px 11px; border-radius: 8px; background: #fff8e8; border: 1px solid #f2dca8; color: #725018; font-size: 12px; line-height: 1.65; white-space: normal; word-break: break-word; overflow-wrap: anywhere; }
.advice-box > div { margin-bottom: 8px; line-height: 1.65; }
.advice-box button { display: inline-block; margin: 4px 6px 4px 0; border: 1px solid #d9a93f; background: #fff; color: #8a5b00; border-radius: 6px; padding: 5px 9px; cursor: pointer; font-size: 11px; line-height: 1.4; white-space: normal; }
.advice-box .muted { display: block; margin-top: 6px; }

.ratio-row { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.chip { border: 1px solid var(--border); background: #fff; color: var(--muted); border-radius: 6px; padding: 4px 9px; cursor: pointer; font-size: 12px; }
.chip.active { background: var(--soft); border-color: #b9caf5; color: var(--accent); font-weight: 600; }
.crop-stage { position: relative; width: 100%; background: #111827; border-radius: 8px; overflow: hidden; min-height: 80px; line-height: 0; }
.crop-stage img { width: 100%; display: block; user-select: none; visibility: hidden; }
.crop-stage img.ready { visibility: visible; }
.crop-box { position: absolute; border: 2px solid #fff; box-shadow: 0 0 0 9999px rgba(8, 12, 22, .55); cursor: move; }
.handle { position: absolute; width: 12px; height: 12px; background: #fff; border: 2px solid var(--accent); border-radius: 3px; }
.handle.nw { left: -7px; top: -7px; cursor: nwse-resize; }
.handle.ne { right: -7px; top: -7px; cursor: nesw-resize; }
.handle.sw { left: -7px; bottom: -7px; cursor: nesw-resize; }
.handle.se { right: -7px; bottom: -7px; cursor: nwse-resize; }
.crop-actions { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; font-size: 12px; }
.link-btn { border: 0; background: none; color: var(--accent); cursor: pointer; padding: 0; font-size: 12px; }
.muted { color: var(--muted); }

label { display: block; font-size: 12px; color: var(--muted); margin: 10px 0 0; }
input[type=number], select {
  width: 100%; margin-top: 5px; padding: 8px 9px; border: 1px solid var(--border); border-radius: 7px;
  background: #fff; color: var(--text); font-size: 13px;
}
input[type=range] { width: 100%; margin: 8px 0 0; accent-color: var(--accent); }
input[type=checkbox] { accent-color: var(--accent); margin: 0 5px 0 0; vertical-align: -2px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.check-line { display: flex; align-items: center; margin-top: 12px; cursor: pointer; color: var(--text); }
.check-line.small { font-size: 12px; color: var(--muted); margin: 0; }
.value-tag { float: right; color: var(--accent); font-weight: 600; }
/* BF-CORE-UI-03: static portrait-photo hint under the max-colors slider.
   Small secondary text on its own line so it never covers the control. */
.portrait-hint { display: block; margin-top: 6px; color: var(--muted); font-size: 11px; line-height: 1.5; }
.advanced { margin-top: 12px; border-top: 1px dashed var(--border); padding-top: 8px; }
.advanced summary { cursor: pointer; color: var(--accent); font-size: 12px; }

.primary-btn {
  width: 100%; margin-top: 16px; padding: 12px; border: 0; border-radius: 8px; background: var(--accent);
  color: #fff; font-weight: 700; font-size: 14px; cursor: pointer;
}
.primary-btn:hover:not(:disabled) { background: var(--accent-dark); }
.primary-btn:disabled { background: #b9c3d8; cursor: not-allowed; }
.secondary-btn { border: 1px solid var(--accent); background: var(--soft); color: var(--accent); padding: 7px 12px; border-radius: 7px; cursor: pointer; font-weight: 600; }
.progress { margin-top: 10px; color: var(--accent); font-size: 12px; }
.spinner { display: inline-block; width: 11px; height: 11px; border: 2px solid #cbd7f5; border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; vertical-align: -1px; margin-right: 6px; }
@keyframes spin { to { transform: rotate(360deg); } }
.error-box { margin-top: 10px; padding: 9px; background: #fdf0ef; border: 1px solid #f3c6c2; color: var(--err); border-radius: 7px; font-size: 12px; }

.workspace { display: flex; flex-direction: column; min-width: 0; }
.workspace-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.tabs { display: flex; gap: 4px; }
.tab { border: 0; background: none; padding: 8px 14px; border-radius: 7px; cursor: pointer; color: var(--muted); font-size: 13px; }
.tab.active { background: var(--soft); color: var(--accent); font-weight: 700; }
.view-tools { display: flex; align-items: center; gap: 8px; }
.icon-btn { width: 28px; height: 28px; border: 1px solid var(--border); background: #fff; border-radius: 6px; cursor: pointer; color: var(--text); }
.icon-btn.wide { width: auto; padding: 0 9px; font-size: 12px; }
.zoom-value { min-width: 42px; text-align: center; font-size: 12px; color: var(--muted); }

.view-area { flex: 1; min-height: 260px; position: relative; overflow: hidden; background: #f8f9fc; }
.empty-state { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; color: var(--muted); }
.empty-icon { font-size: 46px; color: #c5cee0; }
.empty-state h3 { margin: 8px 0 4px; color: var(--text); }
.empty-state p { margin: 0; max-width: 320px; line-height: 1.6; }
.preview-viewport { position: absolute; inset: 0; overflow: hidden; display: flex; align-items: center; justify-content: center; cursor: grab; }
.preview-viewport:active { cursor: grabbing; }
.preview-viewport img { max-width: none; image-rendering: auto; transform-origin: center center; user-select: none; -webkit-user-drag: none; }
.comparison-image { max-width: 100%; max-height: 100%; object-fit: contain; margin: auto; display: block; }
.materials-view { position: absolute; inset: 0; overflow: auto; padding: 20px; }

.stats-bar { display: flex; gap: 8px; padding: 10px 16px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.stat { flex: 1; min-width: 90px; background: #f8f9fc; border-radius: 8px; padding: 8px 10px; }
.stat-label { display: block; color: var(--muted); font-size: 11px; }
.stat strong { font-size: 16px; }
.edit-bar { border-top: 1px solid var(--border); padding: 10px 16px; background: #fbfcfe; }
.edit-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.edit-row:last-child { margin-bottom: 0; }
.inline { display: inline-flex; align-items: center; gap: 6px; margin: 0; }
.inline input[type=text], .inline input[type=number] { width: auto; margin: 0; padding: 5px 7px; }
.inline select { width: auto; margin: 0; padding: 5px 7px; }
.secondary-btn.danger { color: var(--err); border-color: #e6b6b0; background: #fdf4f3; }
.bead-info { font-size: 12px; color: var(--muted); background: #fff; border: 1px solid var(--border); border-radius: 6px; padding: 6px 9px; }
.bead-info b { color: var(--text); }

.export-bar { display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.export-title { font-weight: 700; }
.export-bar label { margin: 0; display: flex; align-items: center; gap: 6px; }
.export-bar input[type=number] { width: 70px; margin: 0; }
.badge { padding: 4px 8px; border-radius: 6px; font-size: 11px; background: #e8f7ef; color: var(--ok); }
.badge.bad { background: #fdf0ef; color: var(--err); }
.downloads { display: flex; gap: 10px; flex-wrap: wrap; padding: 0 16px 10px; align-items: center; }
.downloads a { color: var(--accent); font-size: 12px; text-decoration: none; border: 1px solid var(--border); border-radius: 6px; padding: 6px 10px; }
.downloads a:hover { background: var(--soft); }
/* PA-29-A: explicit feedback next to the export control so users never
   mistake a successful export for "nothing happened". */
.downloads-note { width: 100%; padding: 6px 0 2px; color: #2e7d32; font-size: 12px; line-height: 1.5; }
.downloads-error { width: 100%; padding: 6px 0 2px; color: var(--err); font-size: 12px; line-height: 1.5; }
.color-panel { border-top: 1px solid var(--border); padding: 10px 16px 14px; max-height: 170px; overflow: auto; }
.color-panel-head { font-weight: 700; margin-bottom: 8px; }
.color-panel-head span { color: var(--muted); font-weight: 400; font-size: 12px; }
.color-list { display: flex; flex-wrap: wrap; gap: 6px; }
.color-item { display: flex; align-items: center; gap: 6px; border: 1px solid var(--border); border-radius: 6px; padding: 4px 7px; font-size: 11px; background: #fff; }
.swatch { width: 16px; height: 16px; border-radius: 4px; border: 1px solid rgba(0,0,0,.15); }
.color-item b { font-weight: 700; }
.color-item span { color: var(--muted); }
.material-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.material-table th, .material-table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.material-table th { color: var(--muted); font-weight: 600; background: #f8f9fc; }

@media (max-width: 960px) {
  .layout { grid-template-columns: 1fr; height: auto; }
  .controls { max-height: none; }
  .view-area { min-height: 420px; }
  .portrait-hint { margin-top: 8px; line-height: 1.6; }
}
