/* Kamifold Paper Model Studio — tactile stationery & drafting-mat aesthetic */

@font-face {
  font-family: 'Source Serif 4';
  src: url('/fonts/source-serif-4-latin-wght-normal.woff2') format('woff2');
  font-weight: 300 700;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'Courier Prime';
  src: url('/fonts/courier-prime-latin-400-normal.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'Courier Prime';
  src: url('/fonts/courier-prime-latin-700-normal.woff2') format('woff2');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

:root {
  --mat-bg: #acc2c0;
  --paper: #f7f4ec;
  --paper-elevated: #fbf9f3;
  --paper-soft: #efeae0;
  --ink: #1c1f1d;
  --ink-muted: #5d615c;
  --ink-faint: #898b83;
  --border: rgba(28, 34, 31, 0.13);
  --border-strong: rgba(28, 34, 31, 0.24);
  --accent: #e05a2b;
  --accent-hover: #c94b20;
  --cta-bg: #1c2622;
  --cta-hover: #293832;
  --sage-ok: #3a7558;
  --sage-ok-bg: rgba(58, 117, 88, 0.11);
  --amber-warn: #b56c24;
  --amber-warn-bg: rgba(181, 108, 36, 0.12);
  --shadow-card: 0 14px 36px rgba(24, 38, 37, 0.14), 0 2px 6px rgba(24, 38, 37, 0.08);
  --shadow-pill: 0 4px 14px rgba(24, 38, 37, 0.10);
  --font-serif: 'Source Serif 4', Georgia, serif;
  --font-mono: 'Courier Prime', ui-monospace, SFMono-Regular, Menlo, monospace;
  --font-sans: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--mat-bg);
  color: var(--ink);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
}

.is-hidden { display: none !important; }

.noscript-fallback {
  max-width: 680px;
  margin: 3rem auto;
  padding: 2rem;
  background: var(--paper-elevated);
  border-radius: 12px;
  border: 1px solid var(--border);
  font-family: var(--font-serif);
  line-height: 1.6;
}

/* Full-bleed WebGL Stage */
.studio-stage {
  position: fixed;
  inset: 0;
  z-index: 1;
}

#studio-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: none;
}

#studio-canvas:active { cursor: grabbing; }

.drop-overlay {
  position: absolute;
  inset: 16px;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(172, 194, 192, 0.84);
  backdrop-filter: blur(6px);
  border: 2.5px dashed var(--accent);
  border-radius: 18px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
}

.drop-overlay.is-active {
  opacity: 1;
  pointer-events: auto;
}

.drop-overlay-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 28px 36px;
  background: var(--paper-elevated);
  border-radius: 14px;
  box-shadow: var(--shadow-card);
  text-align: center;
}

.drop-icon { font-size: 28px; color: var(--accent); }
.drop-overlay-box strong { font-family: var(--font-serif); font-size: 20px; }
.drop-overlay-box span { font-size: 13px; color: var(--ink-muted); }

/* Minimal Top Bar */
.hud-top {
  position: fixed;
  top: 14px;
  left: 16px;
  right: 16px;
  z-index: 15;
  display: flex;
  align-items: center;
  justify-content: space-between;
  pointer-events: none;
}

.hud-top-left, .hud-top-right {
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: auto;
}

.brand-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 11px 5px 7px;
  background: rgba(247, 244, 236, 0.88);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: 9px;
  cursor: pointer;
  color: var(--ink);
  box-shadow: var(--shadow-pill);
  transition: background 0.15s ease, transform 0.12s ease;
}

.brand-pill:hover { background: var(--paper-elevated); }
.brand-square { display: inline-flex; align-items: center; }
.brand-name {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 14px;
  letter-spacing: -0.02em;
}

.blog-back-pill {
  padding: 6px 10px;
  background: rgba(247, 244, 236, 0.72);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: 9px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--ink-muted);
  text-decoration: none;
  transition: background 0.15s ease, color 0.15s ease;
}
.blog-back-pill:hover { background: var(--paper-elevated); color: var(--ink); }

.engine-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px;
  background: rgba(247, 244, 236, 0.88);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--ink-muted);
  cursor: pointer;
  box-shadow: var(--shadow-pill);
  transition: background 0.15s ease, color 0.15s ease;
}
.engine-pill:hover { background: var(--paper-elevated); color: var(--ink); }

.engine-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #6f9482;
}
.engine-dot.is-ai { background: var(--accent); }

/* Floating Left Stationery Card */
.left-card {
  position: fixed;
  top: 56px;
  left: 16px;
  bottom: 16px;
  width: 344px;
  max-height: calc(100vh - 72px);
  z-index: 12;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-card);
  overflow: hidden;
}

.mobile-sheet-grab { display: none; }

.card-view {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 20px 18px 16px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(28,34,31,0.18) transparent;
}

#view-inspector {
  padding: 0;
  overflow: hidden;
}

.create-heading {
  margin: 0 0 14px;
  font-family: var(--font-serif);
  font-size: 25px;
  font-weight: 400;
  line-height: 1.18;
  letter-spacing: -0.015em;
  color: var(--ink);
}

/* Photo Preview Box (matching kami demo with 4 bottom-left color swatches + Remove pill) */
.photo-preview-box {
  position: relative;
  width: 100%;
  height: 138px;
  margin-bottom: 10px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: #dfd8ca;
}

.photo-preview-box img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.photo-swatches {
  position: absolute;
  left: 8px;
  bottom: 8px;
  display: flex;
  gap: 4px;
  padding: 3px;
  background: rgba(251, 249, 243, 0.85);
  backdrop-filter: blur(4px);
  border-radius: 6px;
}

.photo-swatch-dot {
  width: 13px;
  height: 13px;
  border-radius: 3px;
  border: 1px solid rgba(0, 0, 0, 0.16);
}

.photo-remove-btn {
  position: absolute;
  right: 8px;
  bottom: 8px;
  padding: 4px 10px;
  background: rgba(28, 34, 31, 0.78);
  color: #fbf9f3;
  border: none;
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 11px;
  cursor: pointer;
}
.photo-remove-btn:hover { background: var(--ink); }

/* Input Shell */
.input-shell {
  background: var(--paper-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 14px;
  transition: border-color 0.15s ease;
}
.input-shell:focus-within { border-color: var(--border-strong); }

#prompt-input {
  width: 100%;
  padding: 11px 12px 8px;
  border: none;
  background: transparent;
  resize: none;
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.48;
  color: var(--ink);
  outline: none;
}
#prompt-input::placeholder { color: var(--ink-faint); }

.photo-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 11px;
  border-top: 1px dashed rgba(28, 34, 31, 0.11);
  background: rgba(239, 234, 224, 0.42);
}

.photo-upload-trigger {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  color: var(--ink);
  cursor: pointer;
}
.photo-upload-trigger:hover { color: var(--accent); }
.photo-upload-trigger input { display: none; }

.photo-bar-hint {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-faint);
}

.photo-project-toggle {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 11px;
  border-top: 1px solid rgba(28, 34, 31, 0.08);
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-muted);
  cursor: pointer;
}
.photo-project-toggle input { accent-color: var(--accent); }

/* Detail Segmented Control */
.field-group { margin-bottom: 14px; }
.field-label {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.02em;
  color: var(--ink-muted);
  margin-bottom: 6px;
}

.detail-segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 3px;
  background: var(--paper-soft);
  border: 1px solid var(--border);
  border-radius: 9px;
}

.seg-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 7px 4px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--ink-muted);
  cursor: pointer;
  transition: all 0.15s ease;
}
.seg-btn:hover { color: var(--ink); }
.seg-btn.is-active {
  background: var(--paper-elevated);
  border-color: var(--border);
  color: var(--ink);
  font-weight: 700;
  box-shadow: 0 1px 3px rgba(24, 38, 37, 0.08);
}
.seg-dots { font-size: 11px; color: var(--ink-faint); letter-spacing: -1px; }
.seg-btn.is-active .seg-dots { color: var(--accent); }

/* Primary CTA Row */
.cta-row {
  display: flex;
  gap: 7px;
  margin-bottom: 8px;
}

.cta-primary {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 14px;
  background: var(--cta-bg);
  color: #fbf9f3;
  border: none;
  border-radius: 9px;
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}
.cta-primary:hover { background: var(--cta-hover); }
.cta-primary:active { transform: translateY(1px); }
.cta-primary.compact { flex: 0 0 auto; padding: 9px 14px; font-size: 12px; }

.cta-dice {
  width: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--paper-elevated);
  border: 1px solid var(--border);
  border-radius: 9px;
  color: var(--ink-muted);
  cursor: pointer;
}
.cta-dice:hover { border-color: var(--border-strong); color: var(--ink); }

.key-note {
  margin: 0 0 16px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-faint);
  line-height: 1.45;
}
.key-note.compact { margin: 7px 0 0; }

.inline-link {
  padding: 0;
  background: none;
  border: none;
  color: var(--ink-muted);
  font-family: inherit;
  font-size: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}
.inline-link:hover { color: var(--accent); }

/* Example Cards Row */
.examples-block { margin-top: auto; padding-top: 8px; border-top: 1px solid rgba(28, 34, 31, 0.08); }

.examples-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
}

.example-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 6px 8px;
  background: var(--paper-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  text-align: center;
  transition: border-color 0.15s ease, transform 0.12s ease, box-shadow 0.15s ease;
}
.example-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 5px 14px rgba(24, 38, 37, 0.09);
}

.example-thumb {
  width: 100%;
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 4px;
}
.example-thumb svg { width: 100%; height: 100%; }

.example-title {
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-weight: 700;
  color: var(--ink);
  line-height: 1.25;
}
.example-sub {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--ink-faint);
  margin-top: 1px;
}

/* VIEW 2: BUILDING PROGRESS */
.build-status-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.build-pulse-square {
  width: 16px;
  height: 16px;
  border-radius: 3px;
  background: var(--accent);
  flex-shrink: 0;
  animation: pulseSquare 1.1s ease-in-out infinite;
}

@keyframes pulseSquare {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.45; transform: scale(0.84); }
}

.build-status-text {
  flex: 1;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}
.build-status-text strong { font-family: var(--font-mono); font-size: 13px; }
.build-timer { font-family: var(--font-mono); font-size: 11px; color: var(--ink-faint); }

.build-progress-track {
  height: 3px;
  background: var(--paper-soft);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 16px;
}
.build-progress-fill {
  height: 100%;
  width: 12%;
  background: var(--accent);
  transition: width 0.25s ease;
}

.build-model-title {
  margin: 0 0 12px;
  font-family: var(--font-serif);
  font-size: 24px;
  font-weight: 400;
}

.build-source-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 9px;
  background: var(--paper-elevated);
  border: 1px solid var(--border);
  border-radius: 9px;
  margin-bottom: 14px;
}
.build-source-chip img {
  width: 40px;
  height: 32px;
  border-radius: 5px;
  object-fit: cover;
}
.build-source-chip span { font-family: var(--font-mono); font-size: 11.5px; color: var(--ink-muted); }

.build-parts-stream {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
  overflow-y: auto;
}

.build-stream-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 6px 8px;
  background: var(--paper-elevated);
  border: 1px solid rgba(28, 34, 31, 0.08);
  border-radius: 7px;
  font-family: var(--font-mono);
  font-size: 12px;
  animation: fadeSlideUp 0.22s ease both;
}

@keyframes fadeSlideUp {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.cancel-link {
  margin-top: 12px;
  align-self: flex-start;
  padding: 4px 0;
  background: none;
  border: none;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-faint);
  cursor: pointer;
}
.cancel-link:hover { color: var(--ink); text-decoration: underline; }

/* VIEW 3: INSPECTOR */
.inspector-top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid rgba(28, 34, 31, 0.09);
  background: var(--paper);
}

.text-action-btn {
  padding: 0;
  background: none;
  border: none;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-muted);
  cursor: pointer;
}
.text-action-btn:hover { color: var(--ink); }

.copy-link-btn {
  padding: 4px 9px;
  background: var(--paper-elevated);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-muted);
  cursor: pointer;
}
.copy-link-btn:hover { border-color: var(--border-strong); color: var(--ink); }

.inspector-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 14px 16px 18px;
  scrollbar-width: thin;
  scrollbar-color: rgba(28,34,31,0.18) transparent;
}

.source-pill-row {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 10px;
}
.source-pill-row img {
  width: 34px;
  height: 28px;
  border-radius: 5px;
  object-fit: cover;
  border: 1px solid var(--border);
}
.source-pill-row span {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--ink-muted);
}

.model-title {
  margin: 0 0 4px;
  font-family: var(--font-serif);
  font-size: 27px;
  font-weight: 400;
  line-height: 1.15;
  letter-spacing: -0.015em;
}

.model-stats {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--ink-muted);
  margin-bottom: 9px;
}

.stability-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 9px;
  border-radius: 999px;
  background: var(--sage-ok-bg);
  color: var(--sage-ok);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  margin-bottom: 14px;
}
.stability-badge.is-warn {
  background: var(--amber-warn-bg);
  color: var(--amber-warn);
}
.stability-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

/* Edit Bar */
.edit-block {
  padding: 11px;
  background: var(--paper-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 14px;
}

.edit-input-row {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}

#edit-input {
  flex: 1;
  min-width: 0;
  padding: 7px 9px;
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: 7px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink);
  outline: none;
}
#edit-input:focus { border-color: var(--border-strong); }

.edit-submit-btn {
  width: 32px;
  flex-shrink: 0;
  background: var(--cta-bg);
  color: #fbf9f3;
  border: none;
  border-radius: 7px;
  font-family: var(--font-mono);
  font-size: 14px;
  cursor: pointer;
}
.edit-submit-btn:hover { background: var(--cta-hover); }

.quick-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.quick-pill {
  padding: 4px 8px;
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--ink-muted);
  cursor: pointer;
  transition: all 0.12s ease;
}
.quick-pill:hover {
  border-color: var(--accent);
  color: var(--ink);
  background: #fff;
}

/* Tabs */
.inspector-tabs {
  display: flex;
  gap: 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 10px;
}

.tab-btn {
  padding: 6px 2px 8px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-faint);
  cursor: pointer;
  margin-bottom: -1px;
}
.tab-btn:hover { color: var(--ink); }
.tab-btn.is-active {
  color: var(--ink);
  font-weight: 700;
  border-bottom-color: var(--accent);
}

/* Parts List */
.parts-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.part-row {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 9px;
  background: var(--paper-elevated);
  border: 1px solid rgba(28, 34, 31, 0.08);
  border-radius: 8px;
  cursor: pointer;
  transition: border-color 0.12s ease, background 0.12s ease;
}
.part-row:hover, .part-row.is-active {
  border-color: var(--accent);
  background: #ffffff;
}
.part-row.is-hidden-part { opacity: 0.45; }

.part-badge {
  width: 22px;
  height: 22px;
  border-radius: 5px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.32);
  flex-shrink: 0;
  border: 1px solid rgba(0, 0, 0, 0.14);
}

.part-row-name {
  flex: 1;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.part-row-shape {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--ink-faint);
  text-transform: capitalize;
}

.part-eye-btn {
  padding: 2px 4px;
  background: none;
  border: none;
  color: var(--ink-faint);
  cursor: pointer;
  font-size: 12px;
}
.part-eye-btn:hover { color: var(--ink); }

/* Inline Steps List */
.steps-inline-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.step-inline-item {
  padding: 9px 10px;
  background: var(--paper-elevated);
  border: 1px solid rgba(28, 34, 31, 0.09);
  border-radius: 8px;
  cursor: pointer;
}
.step-inline-item:hover { border-color: var(--accent); }
.step-inline-head {
  display: flex;
  align-items: center;
  gap: 7px;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 4px;
}
.step-inline-num {
  padding: 1px 5px;
  background: var(--paper-soft);
  border-radius: 4px;
  font-size: 10.5px;
  color: var(--ink-muted);
}
.step-inline-desc {
  margin: 0;
  font-size: 12px;
  line-height: 1.45;
  color: var(--ink-muted);
}

/* Sticky Inspector Footer */
.inspector-footer {
  display: flex;
  gap: 7px;
  padding: 12px 16px;
  border-top: 1px solid rgba(28, 34, 31, 0.1);
  background: var(--paper);
}

.split-print-wrap {
  position: relative;
  flex: 1;
  display: flex;
}

.btn-print-main {
  flex: 1;
  padding: 10px 10px;
  background: var(--cta-bg);
  color: #fbf9f3;
  border: none;
  border-radius: 9px 0 0 9px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
}
.btn-print-main:hover { background: var(--cta-hover); }

.btn-print-caret {
  width: 30px;
  background: #25332d;
  color: #fbf9f3;
  border: none;
  border-left: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 0 9px 9px 0;
  cursor: pointer;
  font-size: 12px;
}
.btn-print-caret:hover { background: #31433c; }

.print-dropdown {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 0;
  right: -70px;
  background: var(--paper-elevated);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  box-shadow: var(--shadow-card);
  padding: 5px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  z-index: 25;
}
.print-dropdown button {
  padding: 8px 10px;
  background: transparent;
  border: none;
  border-radius: 6px;
  text-align: left;
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--ink);
  cursor: pointer;
}
.print-dropdown button:hover { background: var(--paper-soft); }

.btn-preview-modal {
  padding: 10px 13px;
  background: var(--paper-elevated);
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  font-weight: 700;
  color: var(--ink);
  cursor: pointer;
}
.btn-preview-modal:hover { background: #fff; border-color: var(--ink); }

/* Bottom-Right Playback Ruler & View Controls */
.bottom-dock {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 12;
  display: flex;
  align-items: center;
  gap: 10px;
}

.scrub-dock {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 8px 14px 8px 9px;
  background: rgba(247, 244, 236, 0.92);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-pill);
}

.play-circle-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: var(--cta-bg);
  color: #fbf9f3;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}
.play-circle-btn:hover { background: var(--cta-hover); }

.ruler-slider-wrap {
  position: relative;
  width: 224px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.ruler-ticks {
  height: 7px;
  background-image:
    repeating-linear-gradient(
      to right,
      rgba(28, 34, 31, 0.34) 0px,
      rgba(28, 34, 31, 0.34) 1px,
      transparent 1px,
      transparent 9px
    );
  opacity: 0.7;
  pointer-events: none;
}

#fold-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  margin: -5px 0 0;
  background: rgba(28, 34, 31, 0.14);
  border-radius: 999px;
  outline: none;
  cursor: pointer;
}

#fold-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 18px;
  border-radius: 4px;
  background: var(--accent);
  border: 2px solid #fbf9f3;
  box-shadow: 0 2px 6px rgba(24, 34, 31, 0.25);
  cursor: ew-resize;
}

#fold-slider::-moz-range-thumb {
  width: 14px;
  height: 18px;
  border-radius: 4px;
  background: var(--accent);
  border: 2px solid #fbf9f3;
  box-shadow: 0 2px 6px rgba(24, 34, 31, 0.25);
  cursor: ew-resize;
}

.ruler-labels {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 9.5px;
  color: var(--ink-faint);
}

.view-segmented {
  display: flex;
  padding: 4px;
  background: rgba(247, 244, 236, 0.92);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: 11px;
  box-shadow: var(--shadow-pill);
}

.view-seg-btn {
  padding: 7px 12px;
  background: transparent;
  border: none;
  border-radius: 7px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-muted);
  cursor: pointer;
}
.view-seg-btn.is-active {
  background: var(--paper-elevated);
  color: var(--ink);
  font-weight: 700;
  box-shadow: 0 1px 4px rgba(24, 38, 37, 0.11);
}

/* Full-Screen A4 Print Preview Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(34, 46, 44, 0.72);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
}

.preview-shell {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.preview-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: rgba(26, 36, 33, 0.92);
  color: #f7f4ec;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.preview-meta h2 {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 20px;
  font-weight: 400;
}
.preview-meta span {
  font-family: var(--font-mono);
  font-size: 12px;
  color: rgba(247, 244, 236, 0.68);
}

.preview-actions { display: flex; align-items: center; gap: 10px; }

.btn-print-light {
  padding: 8px 18px;
  background: var(--paper-elevated);
  color: var(--ink);
  border: none;
  border-radius: 8px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
}
.btn-print-light:hover { background: #fff; }

.btn-secondary-light {
  padding: 8px 14px;
  background: transparent;
  color: #f7f4ec;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 8px;
  font-family: var(--font-mono);
  font-size: 12px;
  cursor: pointer;
}
.btn-secondary-light:hover { background: rgba(255, 255, 255, 0.1); }

.btn-close-circle {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  color: #f7f4ec;
  border: none;
  font-size: 15px;
  cursor: pointer;
}
.btn-close-circle:hover { background: rgba(255, 255, 255, 0.22); }
.btn-close-circle.dark { background: var(--paper-soft); color: var(--ink); }

.preview-pages-stage {
  flex: 1;
  overflow: auto;
  padding: 28px 32px 48px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: flex-start;
  gap: 24px;
}

/* Individual A4 Preview Sheets (aspect ratio 210 : 297) */
.a4-page {
  width: min(440px, calc(100vw - 48px));
  aspect-ratio: 210 / 297;
  background: #fbf9f3;
  color: #1c1a17;
  border-radius: 3px;
  box-shadow: 0 18px 44px rgba(10, 18, 16, 0.34);
  position: relative;
  display: flex;
  flex-direction: column;
  padding: 22px 24px 20px;
  overflow: hidden;
  flex-shrink: 0;
}

.a4-cut-sheet { padding: 0; }
.a4-sheet-svg { width: 100%; height: 100%; display: block; }

.a4-page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 10px;
  border-bottom: 1px solid #e4ddd0;
  margin-bottom: 12px;
}

.a4-brand {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
}
.brand-mark-mini {
  width: 11px;
  height: 11px;
  border-radius: 2px;
  background: var(--accent);
  display: inline-block;
}
.a4-head-meta { font-family: var(--font-mono); font-size: 10px; color: #756e62; }
.a4-steps-title { font-family: var(--font-serif); font-size: 16px; }

.cover-title-block h2 {
  margin: 0 0 4px;
  font-family: var(--font-serif);
  font-size: 26px;
  font-weight: 400;
}
.cover-title-block p {
  margin: 0 0 6px;
  font-size: 11px;
  line-height: 1.4;
  color: #5c564c;
}
.cover-stats { font-family: var(--font-mono); font-size: 10px; color: #847c6e; }

.cover-diagram {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px 0;
}

.cover-columns {
  display: grid;
  grid-template-columns: 0.92fr 0.98fr 1.25fr;
  gap: 10px;
  padding-top: 10px;
  border-top: 1px solid #e4ddd0;
  font-size: 8.4px;
  line-height: 1.4;
  color: #464139;
}
.cover-col h4 {
  margin: 0 0 5px;
  font-family: var(--font-mono);
  font-size: 9.2px;
  color: #1c1a17;
}
.cover-col ul { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 3px; }
.legend-list li { display: flex; align-items: center; gap: 5px; }
.leg-line { width: 16px; height: 0; display: inline-block; border-top: 1.5px solid #1c1a17; }
.leg-line.dashed { border-top-style: dashed; }
.leg-swatch.tab { width: 14px; height: 7px; background: #ede7da; border: 1px solid #4f4a42; display: inline-block; }
.leg-badge {
  display: inline-flex; align-items: center; justify-content: center;
  width: 12px; height: 12px; border-radius: 2px;
  background: var(--accent); color: #fff; font-family: var(--font-mono); font-size: 7.5px; font-weight: 700;
}
.cover-parts-grid { display: grid; grid-template-columns: 1fr; gap: 2.5px 6px; }
.cover-parts-grid.is-two-col { grid-template-columns: 1fr 1fr; }
.cover-part-row { display: flex; align-items: center; gap: 4px; min-width: 0; }
.cover-part-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cover-part-badge {
  width: 12px; height: 12px; border-radius: 2px; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  font-family: var(--font-mono); font-size: 7.5px; font-weight: 700; color: #fff;
  border: 0.6px solid rgba(0, 0, 0, 0.16);
}

.steps-grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 10px;
}

.step-card {
  border: 1px solid #e3dcd0;
  border-radius: 6px;
  padding: 8px 9px;
  background: #fdfcf8;
  display: flex;
  flex-direction: column;
}
.step-card-head {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-bottom: 4px;
  font-family: var(--font-mono);
  font-size: 9.5px;
  font-weight: 700;
}
.step-num {
  padding: 1px 4px;
  background: #efeae0;
  border-radius: 3px;
  color: #5c564c;
  font-size: 8.5px;
}
.step-desc {
  margin: 0 0 4px;
  font-size: 8.2px;
  line-height: 1.35;
  color: #5d574d;
}
.step-illus { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; }

.a4-page-foot {
  margin-top: 8px;
  text-align: right;
  font-family: var(--font-mono);
  font-size: 8.5px;
  color: #8c8477;
}

/* BYOK Key Modal */
.key-dialog {
  width: min(460px, calc(100vw - 32px));
  background: var(--paper-elevated);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px 22px;
  box-shadow: var(--shadow-card);
}
.key-dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.key-dialog-head h2 {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 22px;
  font-weight: 400;
}
.key-dialog-desc {
  margin: 0 0 14px;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--ink-muted);
}
.key-form { display: flex; flex-direction: column; gap: 11px; }
.key-field { display: flex; flex-direction: column; gap: 4px; }
.key-field span { font-family: var(--font-mono); font-size: 11.5px; color: var(--ink-muted); }
.key-field input, .key-field select {
  padding: 9px 10px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: #fff;
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--ink);
}
.key-form-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 6px;
}
.btn-ghost-danger {
  background: none;
  border: none;
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: #b5412b;
  cursor: pointer;
}
.btn-ghost-danger:hover { text-decoration: underline; }

/* Toast */
.toast {
  position: fixed;
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 70;
  padding: 8px 16px;
  background: var(--cta-bg);
  color: #fbf9f3;
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 12px;
  box-shadow: var(--shadow-card);
}

.print-root { display: none; }

/* Responsive Mobile Layout (390px) */
@media (max-width: 860px) {
  .hud-top { top: 10px; left: 10px; right: 10px; }
  .blog-back-pill { display: none; }

  .left-card {
    top: auto;
    left: 10px;
    right: 10px;
    bottom: 70px;
    width: auto;
    max-height: 44vh;
    border-radius: 14px;
    transition: max-height 0.24s ease;
  }
  .left-card.is-collapsed { max-height: 44px; }
  .left-card.is-collapsed .card-view { display: none; }

  .mobile-sheet-grab {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 7px 12px 6px;
    background: var(--paper-soft);
    border: none;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    flex-shrink: 0;
  }
  .grab-bar {
    width: 34px;
    height: 4px;
    border-radius: 4px;
    background: rgba(28, 34, 31, 0.25);
  }
  .grab-label {
    font-family: var(--font-mono);
    font-size: 10.5px;
    color: var(--ink-muted);
  }

  .card-view { padding: 14px 14px 12px; }
  .create-heading { font-size: 20px; margin-bottom: 10px; }

  .bottom-dock {
    left: 10px;
    right: 10px;
    bottom: 10px;
    justify-content: space-between;
    gap: 6px;
  }
  .scrub-dock { flex: 1; min-width: 0; padding: 6px 10px 6px 7px; gap: 8px; }
  .ruler-slider-wrap { width: auto; flex: 1; }
  .view-seg-btn { padding: 6px 8px; font-size: 11px; }
}

/* True 1:1 ISO A4 Print Media Stylesheet */
@media print {
  @page { size: A4 portrait; margin: 0; }
  html, body {
    width: 210mm;
    height: auto;
    overflow: visible !important;
    background: #ffffff !important;
  }
  .studio-stage, .hud-top, .left-card, .bottom-dock, .modal-backdrop, .toast, .noscript-fallback {
    display: none !important;
  }
  .print-root {
    display: block !important;
  }
  .print-root .a4-page {
    width: 210mm !important;
    height: 297mm !important;
    max-width: none !important;
    box-shadow: none !important;
    border-radius: 0 !important;
    page-break-after: always;
    break-after: page;
    padding: 12mm !important;
  }
  .print-root .a4-cut-sheet { padding: 0 !important; }
  .print-root .a4-page:last-child { page-break-after: auto; break-after: auto; }
}
