:root {
  --paper: #f3f2ee;
  --surface: #fbfbf8;
  --white: #ffffff;
  --ink: #20211e;
  --muted: #686a64;
  --quiet: #96988f;
  --line: #d9d9d2;
  --line-strong: #c3c4bc;
  --accent: #e65f20;
  --accent-hover: #c94d13;
  --accent-pale: #fff0e8;
  --success: #2f7d50;
  --radius: 10px;
  --shadow: 0 18px 55px rgba(36, 36, 30, 0.09);
  font-family: "Avenir Next", Avenir, "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
  background: var(--paper);
  font-synthesis: none;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; }
body { margin: 0; min-width: 320px; background: var(--paper); }
button, input, select { font: inherit; }
button, label, select, input[type="range"], input[type="checkbox"] { touch-action: manipulation; }
button { color: inherit; }
button:focus-visible, input:focus-visible, select:focus-visible, [tabindex]:focus-visible {
  outline: 3px solid rgba(230, 95, 32, .3);
  outline-offset: 2px;
}

.topbar {
  height: 66px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 clamp(20px, 4vw, 64px);
  background: rgba(251,251,248,.92);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(12px);
}
.brand { display: inline-flex; align-items: center; gap: 11px; color: var(--ink); text-decoration: none; font-weight: 700; letter-spacing: -.02em; }
.brand-mark { width: 24px; height: 24px; border: 2px solid var(--ink); display: grid; place-items: center; transform: rotate(-3deg); }
.brand-mark span { width: 9px; height: 9px; background: var(--accent); border-radius: 50%; }
.privacy-note { display: flex; align-items: center; gap: 9px; color: var(--muted); font-size: 13px; font-weight: 500; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--success); box-shadow: 0 0 0 4px rgba(47,125,80,.1); }

.app-shell { width: min(1180px, calc(100% - 40px)); margin: 0 auto; padding: 58px 0 42px; }
.intro { display: grid; grid-template-columns: 1fr 420px; align-items: end; gap: 32px; margin-bottom: 40px; }
.intro .eyebrow { grid-column: 1 / -1; margin: 0 0 -15px; color: var(--accent); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; font-weight: 700; letter-spacing: .14em; }
.intro h1 { margin: 0; font-size: clamp(38px, 5vw, 64px); line-height: .98; letter-spacing: -.055em; font-weight: 650; text-wrap: balance; }
.intro > p:last-child { margin: 0 0 3px; color: var(--muted); font-size: 16px; line-height: 1.55; max-width: 45ch; text-wrap: pretty; }

.workspace { display: grid; grid-template-columns: 360px minmax(0, 1fr); min-height: 650px; border: 1px solid var(--line-strong); background: var(--surface); box-shadow: var(--shadow); }
.controls { border-right: 1px solid var(--line); background: #f8f8f4; }
.controls-title { height: 66px; display: flex; align-items: center; justify-content: space-between; padding: 0 24px; border-bottom: 1px solid var(--line); }
.controls-title h2 { margin: 0; font-size: 16px; letter-spacing: -.01em; }
.text-button { border: 0; background: transparent; color: var(--muted); font-size: 12px; cursor: pointer; padding: 8px; }
.text-button:hover { color: var(--accent); }
.randomizer-panel { padding: 14px 16px 13px; border-bottom: 1px solid var(--line); background: var(--white); }
.randomize-button { width: 100%; min-height: 58px; display: grid; grid-template-columns: 30px 1fr auto; align-items: center; gap: 11px; padding: 9px 12px; border: 1px solid var(--accent); border-radius: 3px; background: var(--accent-pale); color: var(--ink); text-align: left; cursor: pointer; }
.randomize-button:hover { background: #ffe6d9; }
.randomize-button:active .randomize-icon { transform: rotate(180deg); }
.randomize-button strong, .randomize-button small { display: block; }
.randomize-button strong { margin-bottom: 4px; font-size: 12px; }
.randomize-button small { color: var(--muted); font-size: 9px; }
.randomize-icon { width: 28px; height: 28px; display: grid; place-items: center; border: 1px solid rgba(230,95,32,.35); background: white; color: var(--accent); font-size: 17px; transition: transform .25s ease; }
.randomizer-panel p { display: flex; align-items: center; gap: 7px; margin: 9px 2px 0; color: var(--muted); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 9px; }
.randomizer-panel .status-dot { width: 5px; height: 5px; box-shadow: none; }
.operation { border-bottom: 1px solid var(--line); }
.operation-head { min-height: 82px; display: grid; grid-template-columns: 18px 34px 1fr; align-items: center; gap: 11px; padding: 17px 22px; cursor: pointer; }
.operation-head > input, .inline-check > input { position: absolute; opacity: 0; pointer-events: none; }
.operation-head strong { display: block; font-size: 14px; line-height: 1.2; margin-bottom: 5px; }
.operation-head small { display: block; color: var(--muted); font-size: 11px; line-height: 1.25; }
.check-ui { width: 17px; height: 17px; border: 1px solid var(--line-strong); background: var(--white); display: grid; place-items: center; }
.operation-head input:checked + .check-ui { background: var(--accent); border-color: var(--accent); }
.operation-head input:checked + .check-ui::after { content: ""; width: 7px; height: 4px; border-left: 2px solid white; border-bottom: 2px solid white; transform: translateY(-1px) rotate(-45deg); }
.operation-icon { width: 30px; height: 30px; display: grid; place-items: center; border: 1px solid var(--line); background: var(--white); color: var(--ink); font-family: Georgia, serif; font-size: 13px; }
.line-icon { font-family: inherit; font-size: 18px; }
.operation-body { padding: 0 22px 20px 85px; }
.operation:not(.enabled) .operation-body { opacity: .4; pointer-events: none; }
.operation-body.compact { padding-top: 0; }
.field-label { display: block; color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; margin-bottom: 7px; }
.text-input, select, .color-control { width: 100%; height: 38px; border: 1px solid var(--line-strong); border-radius: 3px; background: var(--white); padding: 0 10px; color: var(--ink); font-size: 12px; }
.text-input { margin-bottom: 14px; }
.text-input:focus, select:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px rgba(230,95,32,.12); }
.field-row { display: grid; grid-template-columns: 1.35fr .9fr; gap: 10px; margin-bottom: 16px; }
.color-control { display: flex; align-items: center; gap: 7px; font-family: ui-monospace, monospace; font-size: 10px; }
.color-control input { width: 20px; height: 20px; padding: 0; border: 0; background: transparent; }
.range-label { display: flex; justify-content: space-between; color: var(--muted); font-size: 11px; margin: 11px 0 3px; }
.range-label output { color: var(--ink); font-family: ui-monospace, monospace; }
input[type="range"] { appearance: none; width: 100%; height: 16px; margin: 0; background: transparent; }
input[type="range"]::-webkit-slider-runnable-track { height: 3px; background: linear-gradient(to right, var(--accent) 0 var(--range-progress, 50%), var(--line) var(--range-progress, 50%) 100%); }
input[type="range"]::-webkit-slider-thumb { appearance: none; width: 13px; height: 13px; margin-top: -5px; border-radius: 50%; border: 2px solid var(--white); background: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.inline-check { display: flex; align-items: center; gap: 8px; margin-top: 11px; color: var(--muted); font-size: 11px; cursor: pointer; }
.small-check { width: 14px; height: 14px; border: 1px solid var(--line-strong); background: white; }
.inline-check input:checked + .small-check { background: var(--accent); box-shadow: inset 0 0 0 3px white; }
.segmented { display: grid; grid-template-columns: 1fr 1fr; border: 1px solid var(--line-strong); padding: 2px; background: var(--white); }
.segmented button { min-height: 33px; border: 0; background: transparent; color: var(--muted); font-size: 10px; cursor: pointer; }
.segmented button.active { color: var(--ink); background: #ecece6; font-weight: 600; }
.frame-row { margin-bottom: 0; }
.export-settings { padding: 20px 22px 24px 67px; border-bottom: 1px solid var(--line); background: #f1f1ec; }
.export-heading { display: grid; grid-template-columns: 34px 1fr; align-items: center; gap: 11px; margin-left: -45px; margin-bottom: 18px; }
.export-heading strong, .export-heading small { display: block; }
.export-heading strong { font-size: 14px; margin-bottom: 4px; }
.export-heading small { color: var(--muted); font-size: 11px; }
.export-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.filename-field { display: block; margin-bottom: 15px; }
.filename-field .text-input { margin-bottom: 6px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.field-help { display: block; color: var(--muted); font-size: 9px; line-height: 1.45; }
.field-help code { color: var(--ink); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.filename-preview { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 14px 0 0; padding-top: 12px; border-top: 1px solid var(--line); font-size: 10px; }
.filename-preview span { color: var(--muted); }
.filename-preview strong { max-width: 190px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 9px; }

.stage { min-width: 0; display: grid; grid-template-rows: 1fr auto auto; background: var(--white); }
.dropzone { margin: 38px; min-height: 470px; display: flex; flex-direction: column; align-items: center; justify-content: center; border: 1px dashed #b8b9b1; background-image: linear-gradient(#f3f3ef 1px, transparent 1px), linear-gradient(90deg, #f3f3ef 1px, transparent 1px); background-size: 24px 24px; cursor: pointer; transition: .2s ease; }
.dropzone:hover, .dropzone.dragover { border-color: var(--accent); background-color: var(--accent-pale); }
.dropzone h2 { margin: 25px 0 5px; font-size: 20px; letter-spacing: -.025em; }
.dropzone p { margin: 0 0 20px; color: var(--muted); font-size: 13px; }
.dropzone small { margin-top: 13px; color: var(--quiet); font-size: 10px; }
.drop-visual { width: 108px; height: 82px; position: relative; }
.photo-sheet { width: 70px; height: 54px; position: absolute; border: 2px solid var(--ink); background: var(--white); }
.photo-sheet.back { top: 3px; left: 9px; transform: rotate(-8deg); opacity: .35; }
.photo-sheet.front { top: 12px; left: 20px; overflow: hidden; }
.photo-sheet.front span { position: absolute; width: 12px; height: 12px; border: 2px solid var(--accent); border-radius: 50%; top: 9px; right: 10px; }
.photo-sheet.front i { position: absolute; width: 57px; height: 34px; left: 4px; bottom: -18px; background: #dcded7; transform: rotate(37deg); }
.plus { position: absolute; right: 0; bottom: 0; width: 30px; height: 30px; display: grid; place-items: center; background: var(--accent); color: white; font-size: 24px; line-height: 1; }
.secondary-button { min-height: 39px; padding: 0 17px; border: 1px solid var(--line-strong); background: var(--white); border-radius: 3px; font-size: 12px; font-weight: 600; cursor: pointer; }
.secondary-button:hover { border-color: var(--ink); }
.secondary-button.small { min-height: 34px; }

.preview-area { min-height: 0; padding: 22px 28px 16px; display: flex; flex-direction: column; overflow: hidden; }
.preview-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 14px; }
.preview-toolbar strong { display: block; max-width: 340px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 13px; }
.preview-toolbar span { display: block; margin-top: 3px; color: var(--muted); font-size: 10px; }
.canvas-wrap { flex: 1; min-height: 360px; display: grid; place-items: center; overflow: hidden; background: #e9e9e4; background-image: linear-gradient(45deg,#deded8 25%,transparent 25%),linear-gradient(-45deg,#deded8 25%,transparent 25%),linear-gradient(45deg,transparent 75%,#deded8 75%),linear-gradient(-45deg,transparent 75%,#deded8 75%); background-size: 18px 18px; background-position: 0 0,0 9px,9px -9px,-9px 0; }
#previewCanvas { display: block; max-width: 100%; max-height: 455px; box-shadow: 0 8px 30px rgba(0,0,0,.15); }
.thumbnail-strip { height: 65px; display: flex; gap: 8px; padding-top: 12px; overflow-x: auto; }
.thumbnail { position: relative; flex: 0 0 52px; height: 52px; border: 2px solid transparent; padding: 0; background: #eee; cursor: pointer; overflow: hidden; }
.thumbnail.active { border-color: var(--accent); }
.thumbnail img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumbnail .remove { position: absolute; right: 1px; top: 1px; width: 17px; height: 17px; border: 0; border-radius: 50%; background: rgba(32,33,30,.85); color: white; font-size: 11px; line-height: 1; cursor: pointer; }

.process-bar { min-height: 82px; display: flex; align-items: center; justify-content: space-between; gap: 24px; padding: 14px 20px 14px 26px; border-top: 1px solid var(--line); background: var(--surface); }
.summary { display: flex; align-items: center; gap: 12px; }
.count { width: 34px; height: 34px; display: grid; place-items: center; border: 1px solid var(--line-strong); background: white; font-family: ui-monospace, monospace; font-size: 13px; }
.summary strong, .summary small { display: block; }
.summary strong { font-size: 12px; }
.summary small { color: var(--muted); margin-top: 4px; font-size: 10px; }
.primary-button { min-height: 48px; display: inline-flex; align-items: center; justify-content: space-between; gap: 36px; padding: 0 17px 0 20px; border: 0; border-radius: 3px; background: var(--accent); color: white; font-size: 12px; font-weight: 700; cursor: pointer; box-shadow: 0 7px 16px rgba(230,95,32,.18); }
.primary-button:hover:not(:disabled) { background: var(--accent-hover); }
.primary-button:disabled { background: #c9c9c3; box-shadow: none; cursor: not-allowed; }
.progress { height: 3px; background: var(--line); overflow: hidden; }
.progress span { display: block; width: 0; height: 100%; background: var(--accent); transition: width .2s; }

.steps { display: grid; grid-template-columns: repeat(3, 1fr); margin: 50px 0 10px; border-top: 1px solid var(--line-strong); }
.steps > div { position: relative; padding: 24px 22px 10px 56px; border-right: 1px solid var(--line); }
.steps > div:last-child { border-right: 0; }
.steps span { position: absolute; left: 0; top: 24px; color: var(--accent); font-family: ui-monospace, monospace; font-size: 11px; }
.steps strong { display: block; font-size: 13px; }
.steps p { margin: 5px 0 0; color: var(--muted); font-size: 11px; }
.toast { position: fixed; left: 50%; bottom: 24px; z-index: 40; transform: translate(-50%, 20px); padding: 12px 16px; background: var(--ink); color: white; border-radius: 3px; font-size: 12px; opacity: 0; pointer-events: none; transition: .2s ease; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 900px) {
  .intro { grid-template-columns: 1fr; }
  .intro .eyebrow { margin-bottom: -10px; }
  .workspace { grid-template-columns: 320px minmax(0, 1fr); }
  .dropzone { margin: 22px; }
}
@media (max-width: 720px) {
  .topbar { height: 58px; }
  .privacy-note { font-size: 0; }
  .app-shell { width: min(100% - 24px, 1180px); padding-top: 34px; }
  .intro { margin-bottom: 28px; }
  .intro h1 { font-size: clamp(36px, 11vw, 52px); }
  .workspace { display: block; }
  .controls { border-right: 0; }
  .operation-body { padding-left: 67px; }
  .export-settings { padding-left: 67px; }
  .stage { min-height: 560px; }
  .dropzone { min-height: 430px; margin: 14px; }
  .process-bar { align-items: stretch; flex-direction: column; }
  .primary-button { width: 100%; }
  .steps { grid-template-columns: 1fr; }
  .steps > div { border-right: 0; border-bottom: 1px solid var(--line); padding-left: 52px; }
  .preview-area { padding: 18px 14px 12px; }
  .canvas-wrap { min-height: 300px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; }
}
