body.viewer { min-height: 100vh; }

.v-top {
  display: flex; align-items: center; gap: 12px; padding: 10px 20px;
  background: var(--surface); border-bottom: 4px solid var(--yellow);
}
.back {
  width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: var(--surface-2); color: var(--text); text-decoration: none; font-size: 20px;
}
.v-thumb { width: 64px; height: 48px; object-fit: contain; background: #fff; border-radius: 8px; flex: none; }
.v-thumb:not([src]) { visibility: hidden; }
.v-title { flex: 1; min-width: 0; }
.v-title h1 { margin: 0; font-size: 19px; line-height: 1.2; }
.v-title p { margin: 0; color: var(--muted); font-size: 13px; }
.v-pct { font-size: 13px; color: var(--muted); text-align: right; }
.v-pct b { display: block; font-size: 20px; color: var(--text); }

.v-layout {
  flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 16px;
  padding: 16px 20px; max-width: 1600px; width: 100%; margin: 0 auto;
}

.stage { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.canvas-box {
  position: relative; flex: 1; min-height: 420px; border-radius: var(--radius); overflow: hidden;
  background: radial-gradient(circle at 50% 35%, #ffffff, #e9e4d8); box-shadow: var(--shadow);
}
.canvas-box canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.loading {
  position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 12px;
  color: #6b665c; text-align: center; padding: 20px;
}
.loading[hidden] { display: none; }
.loading.export { background: rgba(255, 255, 255, .92); z-index: 2; }
#pdfBtn[hidden] { display: none; }
.spinner {
  width: 44px; height: 44px; border-radius: 8px; background: var(--red);
  animation: stack 1s ease-in-out infinite;
}
@keyframes stack { 0%, 100% { transform: translateY(0) rotate(0); } 50% { transform: translateY(-14px) rotate(90deg); } }

.controls {
  display: flex; align-items: center; gap: 8px; background: var(--surface);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 10px 12px;
}
.controls[hidden] { display: none; }
.round {
  width: 38px; height: 38px; border-radius: 50%; border: 0; cursor: pointer; flex: none;
  background: var(--surface-2); color: var(--text); font-size: 15px;
}
.round.big { width: 48px; height: 48px; background: var(--red); color: #fff; font-size: 18px; }
.round:disabled { opacity: .35; cursor: default; }
.step-box { flex: 1; min-width: 0; text-align: center; }
.step-label { font-size: 15px; margin-bottom: 4px; }
.auto-steps { color: var(--muted); font-size: 12px; }
.auto-steps[hidden] { display: none; }
.step-box input { width: 100%; accent-color: var(--red); }

.v-side { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.panel-box { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; }
.panel-box h2 { margin: 0 0 10px; font-size: 16px; display: flex; align-items: center; gap: 8px; }

.step-parts { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; max-height: 300px; overflow: auto; }
.sp { border: 1px solid var(--line); border-radius: 10px; padding: 6px; font-size: 11px; display: flex; flex-direction: column; gap: 3px; position: relative; }
.sp img { width: 100%; aspect-ratio: 1; object-fit: contain; background: #fff; border-radius: 6px; }
.sp img.other-color { filter: grayscale(1); opacity: .75; }
.sp .noimg { width: 100%; aspect-ratio: 1; border-radius: 6px; }
.sp .x { position: absolute; top: 4px; right: 4px; background: var(--text); color: var(--bg); border-radius: 99px; padding: 1px 7px; font-weight: 700; font-size: 12px; }
.sp .n { font-weight: 600; line-height: 1.2; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.sp .c { display: flex; align-items: center; gap: 4px; color: var(--muted); }
.sp .src { color: var(--muted); }
.sp.miss { border-color: var(--red); }
.sp.miss .src { color: var(--red-ink); font-weight: 600; }
.step-parts .none { grid-column: 1 / -1; color: var(--muted); font-size: 13px; }

.chat { display: flex; flex-direction: column; min-height: 320px; flex: 1; }
.ai-tag { font-size: 11px; background: var(--blue); color: #fff; border-radius: 6px; padding: 1px 6px; }
.link-btn { margin-left: auto; border: 0; background: none; color: var(--blue); cursor: pointer; font-size: 12px; font-weight: 500; }
.ai-label { margin: -6px 0 8px; font-size: 11px; color: var(--muted); }
.ai-label:empty { display: none; }
.chat-log { flex: 1; overflow: auto; display: flex; flex-direction: column; gap: 8px; min-height: 140px; max-height: 420px; padding: 2px; }
.msg { padding: 8px 11px; border-radius: 12px; font-size: 14px; line-height: 1.45; max-width: 92%; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.me { align-self: flex-end; background: var(--text); color: var(--bg); border-bottom-right-radius: 4px; }
.msg.bot { align-self: flex-start; background: var(--surface-2); border-bottom-left-radius: 4px; }
.msg.info { align-self: center; background: none; color: var(--muted); font-size: 12px; text-align: center; }
.msg.err { align-self: stretch; background: var(--amber-bg); color: var(--amber-ink); font-size: 13px; }
.msg .tool { display: block; color: var(--muted); font-size: 12px; font-style: italic; margin-bottom: 4px; }
.msg.typing::after { content: '▍'; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 8px; }
.chips button {
  border: 1px solid var(--line); background: var(--surface-2); border-radius: 99px;
  padding: 5px 10px; font-size: 12px; cursor: pointer;
}
.chat-form { display: flex; gap: 6px; }
.chat-form input {
  flex: 1; min-width: 0; padding: 9px 11px; border: 2px solid var(--line); border-radius: 10px;
  background: var(--surface-2); outline: none;
}
.chat-form input:focus { border-color: var(--blue); }
.chat.off .chips, .chat.off .chat-form { opacity: .5; pointer-events: none; }

@media (max-width: 960px) {
  .v-layout { grid-template-columns: 1fr; padding: 12px 16px; }
  .canvas-box { min-height: 58vh; }
  .v-top { padding: 10px 16px; }
  .v-pct { display: none; }
  .round { width: 34px; height: 34px; }
  .round.big { width: 42px; height: 42px; }
}
