:root {
    --ink: #25231f;
    --muted: #7d796f;
    --paper: #fffdf8;
    --canvas: #ebe7df;
    --line: #d8d2c7;
    --accent: #e85d3f;
    --accent-deep: #b83d2b;
    --mint: #cfe7d9;
    --serif: "Noto Serif SC", Georgia, serif;
    --sans: "Manrope", "PingFang SC", sans-serif;
    --mono: "DM Mono", monospace;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--canvas); }
body { margin: 0; color: var(--ink); background: var(--canvas); font-family: var(--sans); font-size: 14px; letter-spacing: 0; }
button, input, select { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
.topbar { height: 70px; padding: 0 4vw; display: flex; align-items: center; justify-content: space-between; background: rgba(255, 253, 248, .86); border-bottom: 1px solid var(--line); }
.brand { display: inline-flex; gap: 10px; align-items: center; color: var(--ink); text-decoration: none; font: 700 13px var(--mono); text-transform: uppercase; }
.brand-mark { display: grid; place-items: center; width: 28px; height: 28px; border: 1px solid var(--ink); border-radius: 50%; font-family: var(--serif); font-size: 16px; }
.topbar-meta { color: var(--muted); font: 12px var(--mono); }
.live-dot { display: inline-block; width: 7px; height: 7px; margin-right: 7px; border-radius: 50%; background: #4d9b6b; box-shadow: 0 0 0 4px rgba(77, 155, 107, .12); }
.app-shell { width: min(1480px, 100%); margin: 0 auto; padding: 74px 5vw 80px; }
.intro { display: flex; align-items: end; justify-content: space-between; gap: 40px; padding-bottom: 58px; }
.eyebrow { margin: 0 0 14px; color: var(--accent-deep); font: 500 11px var(--mono); letter-spacing: .08em; }
.eyebrow span { color: var(--muted); margin-left: 10px; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 20px; font: 900 clamp(42px, 6vw, 82px) / 1.05 var(--serif); letter-spacing: 0; }
h1 em { color: var(--accent); font-style: normal; }
.intro-copy { width: min(500px, 100%); margin: 0; color: var(--muted); font-size: 15px; line-height: 1.8; }
.intro-note { display: flex; gap: 17px; align-items: flex-start; padding-bottom: 9px; min-width: 180px; color: var(--muted); line-height: 1.65; }
.note-line { width: 30px; height: 1px; margin-top: 10px; background: var(--accent); }
.workspace { display: grid; grid-template-columns: 360px minmax(0, 1fr); min-height: 720px; border: 1px solid rgba(37, 35, 31, .62); background: rgba(255, 253, 248, .45); }
.control-panel { padding: 34px; border-right: 1px solid rgba(216, 210, 199, .78); }
.step-block { padding: 0 0 28px; margin-bottom: 28px; border-bottom: 1px solid var(--line); }
.step-label { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.step-label span { color: var(--accent); font: 500 11px var(--mono); }
.step-label strong { font-size: 15px; }
.dropzone { display: flex; min-height: 130px; flex-direction: column; align-items: center; justify-content: center; border: 1px dashed #aaa297; background: rgba(255, 253, 248, .68); transition: border-color .2s, background .2s; }
.dropzone.input-burst { animation: input-burst .72s cubic-bezier(.22, 1.35, .36, 1); }
.dropzone:hover, .dropzone.dragging { border-color: var(--accent); background: #fff8ee; }
.dropzone input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.upload-icon { display: grid; place-items: center; width: 32px; height: 32px; margin-bottom: 10px; border: 1px solid var(--accent); border-radius: 50%; color: var(--accent); font-size: 20px; }
.dropzone strong { font-size: 13px; }
.dropzone small { margin-top: 7px; color: var(--muted); font: 10px var(--mono); }
.photo-strip { display: flex; gap: 8px; overflow-x: auto; margin-top: 14px; padding-bottom: 2px; }
.photo-thumb { position: relative; flex: 0 0 60px; height: 60px; padding: 0; overflow: hidden; border: 1px solid var(--line); background: #ddd; }
.photo-thumb.photo-enter { animation: photo-enter .78s both cubic-bezier(.22, 1.35, .36, 1); animation-delay: var(--photo-delay, 0ms); }
.photo-thumb.active { border: 2px solid var(--accent); }
.photo-thumb img { width: 100%; height: 100%; display: block; object-fit: cover; }
.photo-thumb::after { content: attr(data-index); position: absolute; right: 4px; bottom: 3px; color: white; font: 10px var(--mono); text-shadow: 0 1px 3px #000; }
.group-title { margin: 0 0 9px; color: var(--muted); font: 10px var(--mono); text-transform: uppercase; }
.preset-group + .preset-group { margin-top: 20px; }
.preset-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.preset { display: flex; min-height: 55px; flex-direction: column; align-items: flex-start; justify-content: center; padding: 9px 11px; border: 1px solid var(--line); background: transparent; color: var(--ink); text-align: left; transition: .2s; }
.preset b { font-size: 12px; font-weight: 700; }
.preset small { margin-top: 3px; color: var(--muted); font: 10px var(--mono); }
.preset:hover, .preset.active { border-color: var(--accent); background: var(--accent); color: white; }
.preset:hover small, .preset.active small { color: rgba(255, 255, 255, .8); }
.custom-size { margin-top: 19px; }
.custom-size > label { display: block; margin-bottom: 8px; color: var(--muted); font: 10px var(--mono); }
.number-pair { display: grid; grid-template-columns: 1fr 14px 1fr 65px; align-items: center; gap: 6px; }
input[type="number"], select { width: 100%; height: 37px; padding: 0 9px; border: 1px solid var(--line); border-radius: 0; background: var(--paper); color: var(--ink); outline: none; }
input:focus, select:focus { border-color: var(--accent); }
.number-pair span { color: var(--muted); text-align: center; }
.setting-row { display: grid; grid-template-columns: 1fr 1.5fr; align-items: center; gap: 16px; min-height: 43px; color: var(--muted); font-size: 12px; }
.setting-row label { display: flex; justify-content: space-between; gap: 5px; }
.setting-row output { color: var(--ink); font-family: var(--mono); }
input[type="range"] { width: 100%; accent-color: var(--accent); }
.small-input { width: 70px; justify-self: end; }
.check-row { display: flex; gap: 8px; align-items: center; margin-top: 11px; color: var(--muted); font-size: 12px; }
.check-row input { accent-color: var(--accent); }
.privacy-note { display: flex; gap: 12px; align-items: flex-start; color: var(--muted); font-size: 11px; line-height: 1.6; }
.privacy-note span { color: var(--accent); font-size: 20px; line-height: 1; }
.privacy-note p { margin: 0; }
.preview-panel { min-width: 0; padding: 34px 16px 0 34px; }
.preview-toolbar { display: flex; align-items: end; justify-content: space-between; padding-right: 2px; }
.preview-toolbar .eyebrow { margin-bottom: 8px; }
h2 { margin: 0; font: 600 26px var(--serif); }
.toolbar-actions { display: flex; align-items: center; gap: 15px; color: var(--muted); font: 11px var(--mono); }
.icon-button, .close-button { width: 34px; height: 34px; border: 1px solid var(--line); border-radius: 50%; background: transparent; color: var(--ink); font-size: 19px; }
.preview-stage { display: flex; min-height: 560px; flex-wrap: wrap; gap: 28px; margin-top: 27px; align-items: center; justify-content: center; overflow: auto; padding: 32px; background: #dedad2; background-image: radial-gradient(#c7c1b7 1px, transparent 1px); background-size: 18px 18px; }
.empty-state { color: var(--muted); text-align: center; }
.empty-symbol { display: grid; place-items: center; width: 58px; height: 58px; margin: 0 auto 17px; border: 1px solid #b4ada2; border-radius: 50%; font: 300 32px var(--serif); }
.empty-state strong { display: block; color: var(--ink); font: 600 16px var(--serif); }
.empty-state p { margin: 7px 0 0; font-size: 12px; }
.paper-wrap { display: flex; width: 100%; flex-wrap: wrap; gap: 28px; align-items: center; justify-content: center; transform-origin: center; transition: transform .28s cubic-bezier(.22, 1.2, .36, 1); }
.paper { position: relative; width: 210px; height: 297px; overflow: visible; background: white; box-shadow: 0 15px 30px rgba(60, 55, 48, .2); transform-origin: center; }
.paper.page-enter { animation: page-enter .62s both cubic-bezier(.22, 1.28, .36, 1); animation-delay: var(--page-delay, 0ms); }
.paper.page-exit { animation: page-exit .46s both cubic-bezier(.55, .05, .68, .19); animation-delay: var(--page-delay, 0ms); pointer-events: none; }
.layout-photo { position: absolute; left: calc(var(--photo-x-mm) * var(--preview-scale) * 1px); top: calc(var(--photo-y-mm) * var(--preview-scale) * 1px); width: calc(var(--photo-width-mm) * var(--preview-scale) * 1px); height: calc(var(--photo-height-mm) * var(--preview-scale) * 1px); overflow: visible; background: #eee; outline: 1px solid rgba(48, 43, 37, .1); }
.photo-image-frame { position: absolute; inset: 0; overflow: hidden; }
.layout-photo img { position: absolute; display: block; max-width: none; }
.crop-mark { position: absolute; width: 0; height: 0; pointer-events: none; }
.crop-mark::before, .crop-mark::after { content: ""; position: absolute; z-index: 2; background: rgba(40, 36, 31, .72); }
.crop-mark::before { width: 7px; height: 1px; left: -8px; top: 0; }
.crop-mark::after { width: 1px; height: 7px; left: 0; top: -8px; }
.crop-mark.top-left { top: 0; left: 0; }
.crop-mark.top-right { top: 0; right: 0; left: auto; }
.crop-mark.top-right::before { right: -8px; left: auto; }
.crop-mark.top-right::after { right: 0; left: auto; }
.crop-mark.bottom-left { bottom: 0; left: 0; top: auto; }
.crop-mark.bottom-left::before { top: auto; bottom: 0; }
.crop-mark.bottom-left::after { top: auto; bottom: -8px; }
.crop-mark.bottom-right { top: auto; right: 0; bottom: 0; left: auto; }
.crop-mark.bottom-right::before { right: -8px; bottom: 0; left: auto; }
.crop-mark.bottom-right::after { right: 0; bottom: -8px; top: auto; left: auto; }
.preview-footer { display: flex; justify-content: space-between; align-items: center; min-height: 62px; padding-right: 2px; border-bottom: 1px solid var(--line); }
.legend { display: flex; align-items: center; gap: 8px; color: var(--muted); font: 10px var(--mono); }
.legend-line { display: inline-block; width: 25px; border-top: 1px solid var(--accent); }
.legend-dot { display: inline-block; width: 5px; height: 5px; margin-left: 10px; border-radius: 50%; background: var(--accent); }
.zoom-control { display: flex; gap: 12px; align-items: center; color: var(--muted); font: 10px var(--mono); }
.zoom-control button { width: 25px; height: 25px; padding: 0; border: 1px solid var(--line); background: transparent; color: var(--ink); }
.action-bar { display: flex; align-items: center; gap: 16px; padding: 22px 0; }
.action-bar > div { flex: 1; }
.export-controls { display: flex; align-items: stretch; gap: 8px; flex: 0 0 auto !important; }
.export-controls select { width: 112px; height: 43px; }
.action-bar strong, .action-bar span { display: block; }
.action-bar strong { font-size: 13px; }
.action-bar span { margin-top: 4px; color: var(--muted); font: 10px var(--mono); }
.primary-button, .secondary-button { min-height: 43px; padding: 0 17px; border: 1px solid var(--accent); border-radius: 0; font-size: 12px; font-weight: 700; }
.primary-button { display: inline-flex; gap: 22px; align-items: center; justify-content: center; background: var(--accent); color: white; }
.primary-button:hover { background: var(--accent-deep); }
.secondary-button { background: transparent; color: var(--ink); border-color: var(--line); }
.secondary-button:hover { border-color: var(--ink); }
.crop-modal[hidden] { display: none; }
.crop-modal { position: fixed; z-index: 10; inset: 0; display: grid; place-items: center; padding: 20px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(37, 35, 31, .64); }
.crop-dialog { position: relative; width: min(580px, 100%); padding: 28px; background: var(--paper); box-shadow: 0 25px 80px rgba(0,0,0,.25); }
.modal-head { display: flex; justify-content: space-between; align-items: start; margin-bottom: 20px; }
.modal-head .eyebrow { margin-bottom: 7px; }
.modal-head h2 { font-size: 24px; }
.crop-editor { position: relative; display: grid; min-height: 300px; overflow: hidden; place-items: center; background: #272522; touch-action: none; }
#cropCanvas { display: block; max-width: 100%; }
.crop-frame { position: absolute; width: 43%; aspect-ratio: 1 / 1.4; border: 1px solid white; box-shadow: 0 0 0 999px rgba(0,0,0,.38); pointer-events: none; }
.crop-frame::before, .crop-frame::after { content: ""; position: absolute; inset: 33.33% 0; border-top: 1px solid rgba(255,255,255,.45); border-bottom: 1px solid rgba(255,255,255,.45); }
.crop-frame::after { inset: 0 33.33%; border-top: 0; border-right: 1px solid rgba(255,255,255,.45); border-bottom: 0; border-left: 1px solid rgba(255,255,255,.45); }
.crop-tip { margin: 13px 0 22px; color: var(--muted); font-size: 12px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }
@keyframes input-burst {
    0% { transform: scale(.96); box-shadow: 0 0 0 0 rgba(232, 93, 63, 0); }
    42% { transform: scale(1.035) rotate(-.45deg); box-shadow: 0 0 0 8px rgba(232, 93, 63, .12); }
    72% { transform: scale(.995) rotate(.16deg); box-shadow: 0 0 0 3px rgba(232, 93, 63, .05); }
    100% { transform: scale(1); }
}
@keyframes photo-enter {
    0% { opacity: 0; transform: translateY(22px) scale(.68) rotate(-8deg); }
    58% { opacity: 1; transform: translateY(-5px) scale(1.1) rotate(2deg); }
    78% { transform: translateY(1px) scale(.97) rotate(-.6deg); }
    100% { opacity: 1; transform: translateY(0) scale(1) rotate(0); }
}
@keyframes page-enter {
    0% { opacity: 0; transform: translateY(24px) scale(.88) rotate(-1.5deg); }
    58% { opacity: 1; transform: translateY(-7px) scale(1.025) rotate(.35deg); }
    100% { opacity: 1; transform: translateY(0) scale(1) rotate(0); }
}
@keyframes page-exit {
    0% { opacity: 1; transform: scale(1) rotate(0); }
    100% { opacity: 0; transform: translateY(20px) scale(.88) rotate(1.5deg); }
}
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
@media (max-width: 900px) {
    .app-shell { padding-top: 48px; }
    .intro { padding-bottom: 36px; }
    .workspace { grid-template-columns: 310px minmax(0, 1fr); }
    .control-panel { padding: 28px; }
    .preview-panel { padding-right: 12px; padding-left: 28px; }
}
@media (max-width: 700px) {
    .topbar { height: 58px; padding: 0 18px; }
    .topbar-meta { font-size: 9px; }
    .app-shell { padding: 38px 18px 50px; }
    .intro { display: block; padding-bottom: 35px; }
    h1 { font-size: 47px; }
    .intro-note { margin-top: 25px; }
    .workspace { display: block; border-bottom: 0; }
    .control-panel { padding: 27px 0 5px; border-right: 0; }
    .preview-panel { padding: 25px 0 0; }
    .preview-stage { min-height: 410px; margin-top: 21px; }
    .preview-stage { padding: 22px; }
    .paper-wrap { display: flex; }
    .action-bar { flex-wrap: wrap; }
    .action-bar > div { flex: 1 0 100%; }
    .export-controls { flex: 1 0 100%; }
    .export-controls select { flex: 1; }
    .primary-button { flex: 1; }
    .crop-dialog { padding: 22px 18px; }
}
@media print {
    @page { margin: 0; }
    body { background: white; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    .topbar, .intro, .control-panel, .preview-toolbar, .preview-footer, .action-bar { display: none !important; }
    .app-shell { width: auto; padding: 0; margin: 0; }
    .workspace, .preview-panel, .preview-stage { display: block; width: auto; min-height: 0; padding: 0; margin: 0; border: 0; overflow: visible; background: white; }
    .paper-wrap { display: block; width: auto; height: auto; margin: 0; transform: none !important; transition: none; }
    .paper { width: calc(var(--paper-width-mm) * 1mm) !important; height: calc(var(--paper-height-mm) * 1mm) !important; margin: 0; overflow: hidden; box-shadow: none; break-inside: avoid; page-break-inside: avoid; }
    .paper + .paper { break-before: page; page-break-before: always; }
    .paper.page-exit { display: none !important; }
    .layout-photo { left: calc(var(--photo-x-mm) * 1mm); top: calc(var(--photo-y-mm) * 1mm); width: calc(var(--photo-width-mm) * 1mm); height: calc(var(--photo-height-mm) * 1mm); }
    .layout-photo img { width: calc(var(--image-width-mm) * 1mm) !important; height: calc(var(--image-height-mm) * 1mm) !important; left: calc(var(--image-x-mm) * 1mm) !important; top: calc(var(--image-y-mm) * 1mm) !important; }
    .page-enter, .page-exit { animation: none !important; }
}
