:root {
  --bg: #f7f3ed;
  --panel: #fffaf4;
  --panel-strong: #fff7ef;
  --ink: #2e2a28;
  --muted: #6e6762;
  --line: #d7d0c6;
  --line-strong: #49433f;
  --orange: #fb8600;
  --orange-deep: #e16f00;
  --gold: #f4ba16;
  --teal: #2bb6ac;
  --teal-deep: #18948b;
  --shadow: 0 20px 60px rgba(46, 42, 40, 0.08);
  --font-brand: "Nunito", "Avenir Next", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

.hidden {
  display: none !important;
}

body {
  margin: 0;
  font-family: var(--font-brand);
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(251, 134, 0, 0.09), transparent 30%),
    radial-gradient(circle at top right, rgba(43, 182, 172, 0.12), transparent 34%),
    linear-gradient(180deg, #fbf8f2 0%, var(--bg) 100%);
}

.app {
  max-width: 1180px;
  margin: 0 auto;
  padding: 28px 24px 40px;
  display: grid;
  gap: 18px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 22px;
}

.brand-header {
  display: grid;
  justify-items: start;
  gap: 6px;
  background: linear-gradient(135deg, #fffaf2 0%, #fff6ea 52%, #eefaf8 100%);
  overflow: hidden;
  text-align: left;
  padding-top: 14px;
  padding-bottom: 14px;
}

.brand-logo-frame {
  width: min(100%, 620px);
  height: clamp(96px, 14vw, 132px);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: flex-start;
}

.brand-logo {
  width: min(100%, 680px);
  display: block;
  max-width: none;
  margin-top: -72px;
  margin-bottom: -88px;
  margin-left: -8px;
  image-rendering: auto;
}

.section-kicker,
.overlay-eyebrow {
  margin: 0;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--teal-deep);
}

.panel-heading h2,
.preview-header h2,
.preview-header h3,
.preview-panel h3,
.plan-preview-block h4 {
  margin: 0;
  font-family: var(--font-brand);
}

.brand-subtitle {
  margin: 0;
  max-width: 58ch;
  color: var(--muted);
  font-size: 0.96rem;
  font-weight: 700;
}

.status-banner {
  position: sticky;
  top: 12px;
  z-index: 20;
  border: 1px solid #d0c4b8;
  border-radius: 16px;
  background: rgba(255, 249, 240, 0.96);
  color: #473f39;
  padding: 12px 16px;
  backdrop-filter: blur(10px);
  box-shadow: 0 16px 30px rgba(46, 42, 40, 0.08);
}

.status-banner.error {
  border-color: #d8938a;
  background: rgba(255, 241, 239, 0.98);
  color: #7a221a;
}

.status-banner.success {
  border-color: rgba(43, 182, 172, 0.4);
  background: rgba(238, 250, 248, 0.98);
  color: #145f58;
}

.panel-heading {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 16px;
  margin-bottom: 18px;
}

.home-panel {
  display: grid;
  gap: 18px;
}

.home-panel-header {
  display: flex;
  justify-content: flex-start;
  align-items: end;
  gap: 16px;
}

.home-panel-header h1 {
  margin: 0;
  font-size: clamp(2.2rem, 5vw, 3.25rem);
  line-height: 1;
}

.home-panel-header p {
  margin: 8px 0 0;
}

.home-gallery {
  display: grid;
  gap: 18px;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
}

.home-gallery-empty {
  margin: 0;
}

.home-card {
  display: grid;
  gap: 10px;
  align-content: start;
  padding: 14px;
  border: 1px solid rgba(73, 67, 63, 0.12);
  border-radius: 26px;
  background: linear-gradient(180deg, rgba(255,255,255,0.96), rgba(255,249,242,0.94));
  box-shadow: 0 14px 36px rgba(61, 52, 46, 0.08);
  min-height: 220px;
  text-align: left;
}

.home-card:hover {
  transform: translateY(-2px);
}

.home-card-thumb {
  width: 100%;
  aspect-ratio: 4 / 5;
  object-fit: cover;
  border-radius: 20px;
  border: 1px solid rgba(73, 67, 63, 0.12);
  background: #f7f2eb;
}

.home-card-name {
  display: block;
  font-weight: 800;
  word-break: break-word;
}

.home-card-upload {
  place-items: center;
  justify-items: center;
  border-style: dashed;
  background: linear-gradient(180deg, rgba(255,250,244,0.98), rgba(242,250,248,0.92));
  text-align: center;
}

.home-card-plus {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 72px;
  height: 72px;
  border-radius: 24px;
  background: rgba(255,255,255,0.92);
  font-size: 2rem;
  font-weight: 900;
  color: var(--orange-deep);
  box-shadow: inset 0 0 0 1px rgba(73, 67, 63, 0.1);
}

.section-intro {
  margin: 6px 0 0;
}

.controls-panel {
  display: grid;
  gap: 14px;
}

.controls {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  align-items: start;
}

.setup-advanced {
  border: 1px solid rgba(73, 67, 63, 0.14);
  border-radius: 18px;
  background: #fffdfa;
  padding: 2px 0;
}

.setup-advanced summary {
  cursor: pointer;
  list-style: none;
  padding: 14px 16px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: linear-gradient(180deg, rgba(255,250,244,0.98), rgba(255,245,236,0.98));
}

.setup-advanced summary::-webkit-details-marker {
  display: none;
}

.setup-advanced summary::after {
  content: "▾";
  color: var(--orange-deep);
  font-size: 1rem;
  transition: transform 120ms ease;
}

.setup-advanced[open] summary::after {
  transform: rotate(180deg);
}

.setup-advanced-grid {
  padding: 0 16px 14px;
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.label-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.size-crop-control {
  padding: 14px;
  border: 1px solid rgba(73, 67, 63, 0.12);
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(255, 251, 246, 0.98), rgba(255, 255, 255, 0.94));
}

.dimensions-hidden-select {
  display: none;
}

.size-crop-summary {
  display: grid;
  gap: 6px;
  padding: 12px 14px;
  border: 1px solid rgba(73, 67, 63, 0.1);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.82);
}

.size-crop-summary strong,
.size-crop-summary p {
  margin: 0;
}

.size-crop-actions {
  display: grid;
  gap: 8px;
}

label,
.static-control {
  display: grid;
  gap: 8px;
  font-weight: 700;
}

input,
select,
button {
  font: inherit;
  border-radius: 14px;
}

input,
select {
  width: 100%;
  padding: 12px 13px;
  border: 1px solid #c8c0b5;
  background: #fffefb;
  color: var(--ink);
}

input[type="file"] {
  padding: 10px 12px;
  background: #fffdf8;
}

.file-input-native {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.file-input-shell {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  padding: 8px 10px;
  border: 1px solid #c8c0b5;
  border-radius: 14px;
  background: #fffefb;
}

.file-input-shell .mini-btn {
  flex: 0 0 auto;
}

.image-controls-preview {
  display: grid;
  gap: 10px;
  margin-bottom: 10px;
}

.image-controls-preview canvas {
  width: min(100%, 360px);
  max-width: 100%;
  border: 1px solid rgba(49, 45, 43, 0.24);
  border-radius: 14px;
  background: #fff;
}

.file-input-name {
  min-width: 0;
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.helper-text {
  font-weight: 500;
  color: var(--muted);
  line-height: 1.45;
}

.aspect-ratio-warning {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 12px 14px;
  border: 1px solid rgba(251, 134, 0, 0.34);
  border-radius: 14px;
  background: rgba(251, 134, 0, 0.08);
  color: #70410d;
}

.aspect-ratio-warning-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  background: var(--orange);
  color: #fff;
  font-weight: 900;
  line-height: 1;
  flex: 0 0 auto;
}

.aspect-ratio-warning-copy {
  display: grid;
  gap: 8px;
}

.aspect-ratio-warning-copy p {
  margin: 0;
}

.crop-surface-active {
  cursor: crosshair;
}

.crop-surface-active.crop-surface-moving {
  cursor: move;
}

.section-note {
  margin: 0;
}

.static-control-value {
  display: block;
  padding: 12px 13px;
  border: 1px solid #c8c0b5;
  border-radius: 14px;
  background: #fffefb;
  color: var(--ink);
  font-weight: 700;
}

.control-actions,
.adjust-actions,
.palette-presets,
.instructions-actions,
.customize-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.export-pair {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

button {
  border: 1px solid transparent;
  background: linear-gradient(135deg, var(--orange) 0%, var(--orange-deep) 100%);
  color: #fff;
  cursor: pointer;
  font-family: var(--font-brand);
  font-weight: 900;
  letter-spacing: -0.02em;
  padding: 12px 16px;
  box-shadow: 0 12px 24px rgba(251, 134, 0, 0.2);
  transition: transform 120ms ease, filter 120ms ease, box-shadow 120ms ease;
}

.primary-action-wrap {
  width: 100%;
}

.primary-generate-btn {
  width: 100%;
  min-height: 60px;
  font-size: 1.12rem;
  padding-inline: 24px;
}

.gleam-btn {
  position: relative;
  overflow: hidden;
}

.gleam-btn::after {
  content: "";
  position: absolute;
  top: -18%;
  left: -34%;
  width: 32%;
  height: 140%;
  transform: rotate(18deg);
  background: linear-gradient(90deg, rgba(255,255,255,0) 0%, rgba(255,255,255,0.18) 45%, rgba(255,255,255,0.62) 50%, rgba(255,255,255,0.18) 55%, rgba(255,255,255,0) 100%);
  pointer-events: none;
  opacity: 0;
}

.gleam-btn.gleam-active::after {
  opacity: 1;
  animation: gleamSweep 3.4s linear infinite;
}

@keyframes gleamSweep {
  0% { left: -34%; }
  100% { left: 132%; }
}

button:hover:not(:disabled) {
  transform: translateY(-1px);
  filter: brightness(0.98);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
  box-shadow: none;
}

button.mini-btn,
.mini-btn-link {
  background: linear-gradient(135deg, rgba(43, 182, 172, 0.12), rgba(43, 182, 172, 0.2));
  color: var(--ink);
  border-color: rgba(24, 148, 139, 0.18);
  box-shadow: none;
  padding: 9px 13px;
  font-weight: 800;
}

button.mini-btn:hover:not(:disabled),
.mini-btn-link:hover {
  background: linear-gradient(135deg, rgba(43, 182, 172, 0.18), rgba(43, 182, 172, 0.26));
}

.info-btn {
  width: 24px;
  height: 24px;
  min-width: 24px;
  padding: 0;
  border-radius: 999px;
  border: 1px solid rgba(24, 148, 139, 0.28);
  background: rgba(43, 182, 172, 0.12);
  color: var(--teal-deep);
  box-shadow: none;
  font-size: 0.82rem;
  font-weight: 900;
}

.inline-info-control {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.info-popover {
  margin-top: 8px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid rgba(24, 148, 139, 0.16);
  background: rgba(238, 250, 248, 0.92);
  color: #235853;
  font-size: 0.94rem;
  font-weight: 700;
  line-height: 1.45;
}

.floating-popover {
  position: fixed;
  z-index: 70;
  width: min(320px, calc(100vw - 24px));
  margin-top: 0;
  box-shadow: 0 16px 36px rgba(46, 42, 40, 0.14);
}

.floating-popover::after {
  content: "";
  position: absolute;
  left: var(--popover-arrow-left, 26px);
  bottom: -8px;
  width: 14px;
  height: 14px;
  transform: rotate(45deg);
  background: rgba(238, 250, 248, 0.98);
  border-right: 1px solid rgba(24, 148, 139, 0.16);
  border-bottom: 1px solid rgba(24, 148, 139, 0.16);
}

.preview-section,
.preview-step-content,
#summaryStepContent,
#exportStepContent {
  display: grid;
  gap: 18px;
}

.step-empty-state {
  padding: 18px;
  border: 1px dashed rgba(73, 67, 63, 0.22);
  border-radius: 20px;
  background: linear-gradient(180deg, rgba(255, 250, 244, 0.88), rgba(255, 255, 255, 0.92));
}

.step-empty-state h3 {
  margin: 0 0 8px;
  font-size: 1.05rem;
}

.step-empty-state p {
  margin: 0;
}

.enhance-panel,
.image-settings-panel {
  display: grid;
  gap: 14px;
  padding: 16px 18px;
  border: 1px solid rgba(43, 182, 172, 0.18);
  border-radius: 20px;
  background: linear-gradient(180deg, rgba(255,255,255,0.94), rgba(238,250,248,0.92));
}

.enhance-copy h3,
.export-option-title {
  margin: 0;
}

.image-controls-preview h4 {
  margin: 0;
  font-size: 1rem;
}

.enhance-copy p {
  margin: 6px 0 0;
}

.enhance-actions,
.preview-quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.preview-quick-actions {
  margin-top: -4px;
}

.image-settings-layout,
.image-settings-controls,
.image-settings-tools,
.image-slider-grid,
.interactive-customization-panel {
  display: grid;
  gap: 14px;
}

.image-settings-launcher {
  display: grid;
  gap: 10px;
}

.image-settings-launcher p {
  margin: 0;
}

.setup-editor-layout {
  display: grid;
  gap: 16px;
  grid-template-columns: 1fr;
  align-items: start;
}

.setup-image-preview {
  display: grid;
  gap: 10px;
  min-width: 0;
  justify-items: center;
  padding-top: 4px;
}

.setup-image-preview h4 {
  margin: 0;
  font-size: 1rem;
  width: min(100%, 320px);
}

#setupPreviewCanvas {
  width: min(100%, 320px);
  max-width: 100%;
  display: block;
  height: auto;
  border: 1px solid rgba(49, 45, 43, 0.24);
  border-radius: 18px;
  background: #fff;
}

.setup-image-preview .helper-text {
  width: min(100%, 320px);
  margin: 0;
}

.image-editor-modal {
  width: min(1180px, 96vw);
}

.image-editor-tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(140px, auto)) 1fr 72px 72px;
  gap: 0;
  align-items: end;
  border-bottom: 1px solid rgba(73, 67, 63, 0.14);
  margin-top: 8px;
}

.image-editor-tab,
.image-editor-tab-ghost {
  min-height: 58px;
  border-radius: 18px 18px 0 0;
  border: 1px solid rgba(73, 67, 63, 0.16);
  border-bottom: none;
  background: rgba(255, 247, 240, 0.92);
}

.image-editor-tab {
  font-weight: 900;
}

.image-editor-tab.active {
  background: #fffaf4;
  box-shadow: 0 -8px 20px rgba(46, 42, 40, 0.06);
}

.image-editor-tab-filler {
  height: 1px;
}

.image-editor-tab-ghost {
  display: block;
  background: rgba(255,255,255,0.72);
}

.image-editor-shell {
  display: grid;
  grid-template-columns: minmax(230px, 290px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.image-editor-sidebar,
.editor-sidebar-panel,
.image-editor-stage,
.editor-stage-panel {
  display: grid;
  gap: 14px;
}

.quick-changes-panel {
  background: linear-gradient(180deg, rgba(255, 250, 244, 0.98), rgba(255, 255, 255, 0.98));
}

.editor-advanced-tools {
  border: 1px solid rgba(73, 67, 63, 0.14);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.9);
  overflow: hidden;
}

.editor-advanced-tools summary {
  cursor: pointer;
  list-style: none;
  padding: 14px 16px;
  font-weight: 800;
  background: linear-gradient(180deg, rgba(255,250,244,0.98), rgba(255,255,255,0.96));
}

.editor-advanced-tools summary::-webkit-details-marker {
  display: none;
}

.editor-advanced-body {
  display: grid;
  gap: 14px;
  padding: 0 16px 16px;
}

.helper-only-tools .image-tool-card {
  background: rgba(255, 255, 255, 0.72);
}

.editor-sidebar-panel h3 {
  font-size: 1.05rem;
}

.image-editor-stage {
  min-width: 0;
}

.editor-stage-panel {
  min-width: 0;
}

.image-settings-layout {
  grid-template-columns: minmax(240px, 320px) minmax(0, 1fr);
  align-items: start;
}

.image-settings-tools {
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
}

.interactive-customization-panel {
  padding: 14px 16px;
  border: 1px solid rgba(251, 134, 0, 0.16);
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(255, 250, 244, 0.98), rgba(255, 255, 255, 0.94));
}

.interactive-customization-header h4,
.interactive-customization-input span {
  margin: 0;
  font-size: 1rem;
  font-weight: 800;
}

.interactive-customization-header p {
  margin: 6px 0 0;
}

.interactive-customization-input {
  display: grid;
  gap: 8px;
}

.interactive-customization-input textarea {
  width: 100%;
  min-height: 84px;
  padding: 12px 14px;
  border: 1px solid rgba(73, 67, 63, 0.16);
  border-radius: 14px;
  resize: vertical;
  font: inherit;
  background: rgba(255, 255, 255, 0.92);
  color: var(--ink);
}

.interactive-customization-actions,
.interactive-quick-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
}

#customizationSummary {
  margin: 0;
}

.image-tool-card {
  display: grid;
  gap: 8px;
  padding: 12px 14px;
  border: 1px solid rgba(73, 67, 63, 0.12);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.78);
}

.image-tool-card p {
  margin: 0;
}

.image-settings-note {
  margin: 0;
}

.image-slider-grid {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.image-slider-grid label {
  padding: 12px 14px;
  border: 1px solid rgba(73, 67, 63, 0.12);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.78);
}

.image-settings-actions {
  margin-top: 4px;
}

.preview-layout {
  display: grid;
  gap: 18px;
}

.preview-panel {
  min-width: 0;
}

.preview-panel h3,
.plan-preview-block h4 {
  font-size: 1.08rem;
}

.preview-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.lego-plan-panel {
  display: grid;
  gap: 16px;
}

.preview-panel canvas,
canvas {
  width: 100%;
  max-width: 100%;
  display: block;
  height: auto;
  border: 1px solid rgba(49, 45, 43, 0.24);
  border-radius: 18px;
  background: #fff;
}

#originalCanvas,
#planPlaceholderCanvas,
#mosaicCanvas,
#exportSafeCanvas {
  max-width: 100%;
}

.plan-preview-stack {
  display: grid;
  gap: 18px;
}

.plan-preview-block {
  display: grid;
  gap: 10px;
}

.output,
.instructions {
  display: grid;
  gap: 14px;
}

.export-options {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.export-option {
  display: grid;
  gap: 8px;
  border: 1px solid rgba(73, 67, 63, 0.14);
  border-radius: 18px;
  padding: 14px 16px;
  background: #fffdfa;
}

.export-option-primary {
  border-color: rgba(251, 134, 0, 0.2);
  background: linear-gradient(180deg, rgba(255,250,244,0.98), rgba(255,244,232,0.98));
}

.primary-export-btn {
  min-height: 54px;
}

.export-option-inline {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.summary-metrics {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
}

.summary-insights {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  margin-top: 12px;
}

.insight-pill {
  padding: 12px 14px;
  border-radius: 16px;
  border: 1px solid rgba(73, 67, 63, 0.12);
  background: rgba(255, 255, 255, 0.88);
}

.insight-pill p {
  margin: 0;
}

.insight-label {
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.insight-value {
  margin-top: 6px !important;
  font-size: 1.1rem;
  font-weight: 900;
  color: var(--ink);
}

.metric-card {
  border: 1px solid rgba(43, 182, 172, 0.18);
  border-radius: 18px;
  padding: 14px 16px;
  background: linear-gradient(180deg, rgba(255,255,255,0.92), rgba(255,247,239,0.9));
}

.metric-card p {
  margin: 0;
}

.metric-label {
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--teal-deep);
}

.metric-value {
  margin-top: 6px !important;
  font-size: 1.65rem;
  font-weight: 900;
  letter-spacing: -0.03em;
  color: var(--ink);
}

.metric-value-detail {
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: normal;
  color: var(--muted);
}

.summary-details {
  border: 1px solid rgba(73, 67, 63, 0.14);
  border-radius: 18px;
  background: #fffdfa;
  padding: 2px 0;
}

.piece-counts-dropdown {
  margin-top: 2px;
}

.summary-details summary {
  cursor: pointer;
  list-style: none;
  padding: 14px 16px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: linear-gradient(180deg, rgba(255,250,244,0.98), rgba(255,245,236,0.98));
  border-left: 4px solid rgba(251, 134, 0, 0.26);
}

.summary-details summary::-webkit-details-marker {
  display: none;
}

.summary-details summary::after {
  content: "▾";
  color: var(--orange-deep);
  font-size: 1rem;
  transition: transform 120ms ease;
}

.summary-details[open] summary::after {
  transform: rotate(180deg);
}

.summary-detail-grid {
  padding: 0 16px 14px;
  display: grid;
  gap: 10px;
  min-width: 0;
}

.nested-summary-details {
  margin-top: 4px;
}

.summary-detail-grid p {
  margin: 0;
  color: #48413b;
}

#colorBreakdown {
  display: grid;
  gap: 14px;
}

#buildInstructions {
  margin-top: 4px;
}

.instruction-meta {
  margin: 0 0 8px;
  color: #4e4741;
}

.instruction-legend,
.instruction-card,
.summary-subsection {
  border: 1px solid #ddd6cb;
  border-radius: 18px;
  background: var(--panel-strong);
}

.instruction-legend {
  padding: 12px 14px;
}

.instruction-legend p,
.pickabrick-export-steps li {
  color: #554f49;
}

.instruction-overview-grid,
.instructions-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
}

.instruction-card {
  padding: 12px;
}

.instruction-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.instruction-card h4,
.summary-subsection h3 {
  margin: 0 0 8px;
}

.instruction-range,
.instruction-step,
.instruction-empty {
  color: #6b645c;
  font-size: 0.93rem;
}

.instruction-canvas {
  width: 100%;
  max-width: none;
  border: 1px solid rgba(49, 45, 43, 0.24);
  border-radius: 12px;
  background: #fff;
}

.summary-subsection {
  padding: 14px 16px;
  min-width: 0;
}

.summary-table-wrap {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
}

.summary-table-wrap table {
  min-width: 540px;
  table-layout: fixed;
}

.summary-table-wrap td:last-child {
  overflow-wrap: anywhere;
}

.summary-table-wrap th,
.summary-table-wrap td {
  vertical-align: top;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.summary-breakdown-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.summary-breakdown-pill {
  display: inline-flex;
  align-items: center;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(43, 182, 172, 0.1);
  color: #2f4946;
  font-size: 0.82rem;
  line-height: 1.25;
}

.summary-subsection table,
table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  text-align: left;
  padding: 9px 8px;
  border-bottom: 1px solid rgba(73, 67, 63, 0.1);
}

th {
  color: var(--muted);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.swatch {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 4px;
  margin-right: 8px;
  border: 1px solid rgba(49, 45, 43, 0.45);
  vertical-align: -2px;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(30, 26, 23, 0.32);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}

.modal.hidden {
  display: none;
}

.modal-card {
  background: #fffdfa;
  border-radius: 24px;
  border: 1px solid rgba(73, 67, 63, 0.14);
  width: min(980px, 95vw);
  max-height: 92vh;
  overflow: auto;
  padding: 18px;
  box-shadow: 0 24px 60px rgba(46, 42, 40, 0.16);
}

.pickabrick-export-card {
  width: min(620px, 95vw);
}

.pickabrick-export-steps {
  margin: 10px 0 0 20px;
  padding: 0;
  display: grid;
  gap: 8px;
}

.pickabrick-skipped-panel {
  margin-top: 12px;
  padding: 0.9rem 1rem;
  border: 1px solid rgba(49, 45, 43, 0.16);
  border-radius: 16px;
  background: rgba(251, 134, 0, 0.08);
}

.pickabrick-skipped-panel h3 {
  margin: 0 0 4px;
  font-size: 1rem;
}

.pickabrick-skipped-list {
  margin: 8px 0 0 18px;
  padding: 0;
  display: grid;
  gap: 6px;
}

.pickabrick-export-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px;
}

.pickabrick-guide {
  display: grid;
  gap: 14px;
  margin-top: 14px;
}

.pickabrick-guide-card {
  display: grid;
  gap: 12px;
  padding: 16px;
  border: 1px solid rgba(73, 67, 63, 0.12);
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(255,255,255,0.96), rgba(255,249,242,0.94));
}

.pickabrick-guide-header {
  display: grid;
  gap: 6px;
}

.pickabrick-guide-step {
  display: inline-flex;
  width: fit-content;
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(43, 182, 172, 0.12);
  color: var(--teal-deep);
  font-size: 0.74rem;
  font-weight: 900;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.pickabrick-guide-card h3,
.pickabrick-dropzone-title,
.pickabrick-dropzone-meta {
  margin: 0;
}

.pickabrick-upload-pill-demo {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  min-height: 56px;
  width: fit-content;
  padding: 0 20px;
  border-radius: 999px;
  background: linear-gradient(180deg, #f0f0f0, #e2e2e2);
  color: #1d1d1d;
  font-size: 1.3rem;
  font-weight: 900;
}

.pickabrick-upload-pill-icon {
  font-size: 1.4rem;
  line-height: 1;
}

.pickabrick-dropzone-demo {
  display: grid;
  place-items: center;
  gap: 10px;
  min-height: 220px;
  padding: 22px;
  border: 3px dashed rgba(73, 67, 63, 0.26);
  border-radius: 22px;
  background: #fff;
  text-align: center;
}

.pickabrick-dropzone-icon {
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  border-radius: 999px;
  background: linear-gradient(180deg, #1f73f2, #1556c8);
  color: #fff;
  font-size: 1.5rem;
  font-weight: 900;
}

.pickabrick-dropzone-title {
  font-size: 1.2rem;
  font-weight: 900;
  color: #222;
}

.pickabrick-dropzone-meta {
  color: #706a64;
  font-weight: 700;
}

.mini-btn-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: 14px;
  text-decoration: none;
  transition: transform 120ms ease, filter 120ms ease, box-shadow 120ms ease;
}

.modal-card-wide {
  width: min(1080px, 96vw);
}

.crop-modal-card {
  width: min(1120px, 96vw);
}

.modal-panel {
  margin-top: 12px;
  padding: 14px;
  border: 1px solid #e4ddd3;
  border-radius: 18px;
  background: #fffaf4;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.modal-header h2,
.modal-panel h3 {
  margin: 0;
}

.crop-modal-layout {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.crop-ratio-sidebar {
  display: grid;
  gap: 12px;
}

.crop-ratio-list {
  display: grid;
  gap: 8px;
}

.crop-ratio-btn {
  width: 100%;
  justify-content: flex-start;
  text-align: left;
}

.crop-ratio-btn.active {
  background: linear-gradient(135deg, rgba(43, 182, 172, 0.22), rgba(43, 182, 172, 0.34));
  border-color: rgba(24, 148, 139, 0.36);
}

.crop-preview-stage {
  display: grid;
  gap: 12px;
}

.cropper-shell {
  width: 100%;
  max-width: 100%;
  min-height: clamp(320px, 62vh, 620px);
  aspect-ratio: 1 / 1;
  border: 1px solid rgba(49, 45, 43, 0.24);
  border-radius: 16px;
  background: #fff;
  overflow: hidden;
  position: relative;
}

.cropper-shell.ratio-free {
  aspect-ratio: auto;
}

.cropper-shell img {
  display: block;
  max-width: 100%;
}

.cropper-shell::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(to right, rgba(255, 255, 255, 0.14) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255, 255, 255, 0.14) 1px, transparent 1px);
  background-size: 28px 28px;
  opacity: 0;
  transition: opacity 140ms ease;
}

.cropper-shell.cropper-ready::after {
  opacity: 0.18;
}

.cropper-view-box,
.cropper-face {
  border-radius: 8px;
}

.cropper-view-box {
  box-shadow: 0 0 0 1px rgba(251, 134, 0, 0.68);
  outline: 2px solid rgba(251, 134, 0, 0.24);
}

.cropper-view-box::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(to right, rgba(255, 255, 255, 0.24) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255, 255, 255, 0.24) 1px, transparent 1px);
  background-size: 18px 18px;
}

.cropper-dashed {
  border-color: rgba(255, 255, 255, 0.35);
}

.cropper-line,
.cropper-point {
  background-color: rgba(251, 134, 0, 0.86);
}

.toggle-group {
  display: grid;
  gap: 8px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255,255,255,0.76);
}

.checkbox-row {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
}

.checkbox-row input {
  width: auto;
}

.customize-toolbar {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.pill-list,
.color-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.pill-btn,
.color-btn {
  background: #fff8ee;
  color: var(--ink);
  border: 1px solid #d8d1c7;
  box-shadow: none;
}

.pill-btn {
  padding: 7px 11px;
  border-radius: 999px;
}

.pill-btn.active {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}

.color-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 9px;
  border-radius: 999px;
}

.color-btn.active {
  border-color: var(--teal-deep);
  box-shadow: inset 0 0 0 1px var(--teal-deep);
}

.color-btn .swatch {
  margin-right: 0;
}

#customizeCanvas {
  margin-top: 12px;
  max-width: 100%;
  width: auto;
  image-rendering: pixelated;
}

.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 100;
}

.overlay-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(33, 29, 27, 0.42);
  backdrop-filter: blur(5px);
}

.overlay-card {
  position: relative;
  width: min(440px, calc(100vw - 32px));
  border-radius: 28px;
  border: 1px solid rgba(255,255,255,0.55);
  background: linear-gradient(180deg, rgba(255,250,244,0.98), rgba(255,247,239,0.98));
  padding: 28px 24px;
  text-align: center;
  box-shadow: 0 28px 80px rgba(24, 20, 18, 0.28);
}

.overlay-card h2 {
  margin: 0 0 8px;
  font-size: 1.8rem;
  font-weight: 900;
  letter-spacing: -0.03em;
}

.overlay-card p {
  margin: 0;
  color: var(--muted);
}

.sticky-export-cue {
  position: fixed;
  right: 18px;
  bottom: 16px;
  left: auto;
  transform: none;
  z-index: 60;
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  width: min(calc(100vw - 28px), 360px);
  border-radius: 24px;
  border: 1px solid rgba(251, 134, 0, 0.32);
  background: linear-gradient(135deg, rgba(255, 250, 244, 0.98), rgba(255, 243, 228, 0.98) 48%, rgba(238, 250, 248, 0.96));
  box-shadow: 0 24px 60px rgba(46, 42, 40, 0.16);
  padding: 14px;
  backdrop-filter: blur(10px);
  overflow: hidden;
  animation: stickyExportRise 180ms ease-out;
  transition: opacity 180ms ease, transform 180ms ease, box-shadow 180ms ease;
}

.sticky-export-copy {
  display: grid;
  gap: 4px;
  min-width: 0;
  position: relative;
  z-index: 1;
}

.sticky-export-kicker {
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--teal-deep);
}

.sticky-export-copy strong {
  font-size: 1.02rem;
  line-height: 1.2;
  color: #5f3a09;
}

.sticky-export-helper {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 700;
}

.sticky-export-actions {
  display: grid;
  gap: 8px;
}

.sticky-export-action {
  position: relative;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 52px;
  padding: 0 18px;
  border: 0;
  border-radius: 18px;
  background: linear-gradient(180deg, var(--orange), var(--orange-deep));
  color: #fff;
  font-weight: 900;
  box-shadow: 0 14px 28px rgba(225, 111, 0, 0.28);
  cursor: pointer;
}

.sticky-export-secondary {
  position: relative;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 46px;
  padding: 0 16px;
  border: 1px solid rgba(43, 182, 172, 0.22);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.84);
  color: var(--teal-deep);
  font-weight: 800;
  cursor: pointer;
}

.sticky-export-action:hover {
  transform: translateY(-1px);
  box-shadow: 0 18px 34px rgba(225, 111, 0, 0.32);
}

.sticky-export-secondary:hover {
  transform: translateY(-1px);
  background: rgba(255, 255, 255, 0.96);
}

.sticky-export-action:focus-visible,
.sticky-export-secondary:focus-visible,
.sticky-export-dismiss:focus-visible {
  outline: 3px solid rgba(43, 182, 172, 0.34);
  outline-offset: 2px;
}

.sticky-export-dismiss {
  position: absolute;
  z-index: 1;
  top: 10px;
  right: 10px;
  width: 36px;
  height: 36px;
  border: 1px solid rgba(73, 67, 63, 0.16);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.74);
  color: var(--muted);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
}

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

.loading-dots {
  display: inline-flex;
  gap: 10px;
  margin-bottom: 18px;
}

.loading-dots span {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  display: inline-block;
  animation: bounceDots 1.1s infinite ease-in-out both;
}

.loading-dots span:nth-child(1) { background: var(--orange); animation-delay: -0.3s; }
.loading-dots span:nth-child(2) { background: var(--gold); animation-delay: -0.15s; }
.loading-dots span:nth-child(3) { background: var(--teal); animation-delay: 0s; }
.loading-dots span:nth-child(4) { background: var(--orange); animation-delay: 0.15s; }

.success-card {
  background: linear-gradient(135deg, rgba(255,247,239,0.99), rgba(238,250,248,0.98));
}

@keyframes bounceDots {
  0%, 80%, 100% { transform: translateY(0) scale(0.88); opacity: 0.55; }
  40% { transform: translateY(-7px) scale(1); opacity: 1; }
}

@media (min-width: 900px) {
  .preview-layout {
    grid-template-columns: minmax(280px, 0.95fr) minmax(380px, 1.35fr);
  }
}

@media (max-width: 1024px) {
  .app {
    padding: 20px 16px 32px;
  }

  .brand-header {
    text-align: center;
    justify-items: center;
  }

  .brand-logo-frame {
    justify-content: center;
  }

  .brand-logo {
    margin-left: 0;
  }
}

@media (max-width: 768px) {
  .app {
    padding: 14px 12px 28px;
  }

  .controls,
  .instruction-overview-grid,
  .instructions-grid,
  .summary-metrics,
  .export-options,
  .image-settings-layout,
  .image-slider-grid,
  .preview-layout,
  .customize-toolbar {
    grid-template-columns: 1fr;
  }

  .control-actions {
    position: sticky;
    bottom: 10px;
    z-index: 8;
    padding: 10px;
    border-radius: 18px;
    background: rgba(247, 243, 237, 0.92);
    backdrop-filter: blur(8px);
  }

  .primary-action-wrap {
    width: 100%;
  }

  .primary-generate-btn {
    width: 100%;
  }

  .preview-header,
  .panel-heading {
    align-items: start;
    flex-direction: column;
  }

  .sticky-export-cue {
    right: 12px;
    left: auto;
    width: min(calc(100vw - 24px), 320px);
    bottom: 12px;
    padding: 14px;
  }

  .sticky-export-action {
    width: 100%;
  }

  .sticky-export-dismiss {
    top: 8px;
    right: 8px;
  }

  .summary-table-wrap {
    overflow: visible;
  }

  .summary-table-wrap table,
  .summary-table-wrap tbody,
  .summary-table-wrap tr,
  .summary-table-wrap td {
    display: block;
    width: 100%;
  }

  .summary-table-wrap table {
    min-width: 0;
    border-collapse: separate;
    border-spacing: 0;
  }

  .summary-table-wrap thead {
    display: none;
  }

  .summary-table-wrap tr {
    margin-bottom: 10px;
    padding: 10px 12px;
    border: 1px solid rgba(73, 67, 63, 0.1);
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.82);
  }

  .summary-table-wrap td {
    display: grid;
    grid-template-columns: minmax(96px, 112px) minmax(0, 1fr);
    gap: 10px;
    align-items: start;
    padding: 6px 0;
    border-bottom: 0;
  }

  .summary-table-wrap td::before {
    content: attr(data-label);
    display: block;
    margin-bottom: 0;
    font-size: 0.74rem;
    font-weight: 900;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
  }

  .summary-table-wrap td > * {
    min-width: 0;
  }

  .summary-breakdown-list {
    justify-content: flex-start;
  }

  .summary-breakdown-pill {
    max-width: 100%;
  }

  .interactive-customization-actions,
  .interactive-quick-grid {
    grid-template-columns: 1fr;
  }

  .home-panel-header {
    flex-direction: column;
    align-items: start;
  }

  .home-gallery {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .image-editor-tabs {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    border-bottom: none;
  }

  .image-editor-tab-filler,
  .image-editor-tab-ghost {
    display: none;
  }

  .image-editor-tab {
    border-bottom: 1px solid rgba(73, 67, 63, 0.16);
    border-radius: 18px;
  }

  .image-editor-shell {
    grid-template-columns: 1fr;
  }

  .crop-modal-layout {
    grid-template-columns: 1fr;
  }

  .crop-ratio-list {
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  }

  .preview-panel canvas,
  .plan-preview-block canvas,
  .cropper-shell,
  .image-controls-preview canvas,
  .instruction-canvas,
  #customizeCanvas {
    width: 100% !important;
    max-width: 100%;
    height: auto !important;
  }

  .preview-panel,
  .plan-preview-block,
  .crop-preview-stage,
  .image-controls-preview {
    min-width: 0;
    overflow: hidden;
  }
}

@media (max-width: 480px) {
  body {
    overflow-x: hidden;
  }

  .panel,
  .modal-card,
  .overlay-card {
    border-radius: 20px;
  }

  button,
  input,
  select {
    min-height: 44px;
  }

  .modal {
    padding: 0;
  }

  .modal-card,
  .modal-card-wide {
    width: 100vw;
    max-height: 100vh;
    border: none;
    border-radius: 0;
  }

  .preview-header .mini-btn,
  .enhance-actions .mini-btn,
  .preview-quick-actions .mini-btn,
  .image-settings-launcher .mini-btn,
  .image-tool-card .mini-btn,
  .image-settings-actions .mini-btn {
    width: 100%;
    justify-content: center;
  }
  .preview-header {
    gap: 10px;
  }
}
