:root {
  color-scheme: light;
  --ink: #26312e;
  --muted: #7a8681;
  --line: #e2e8e5;
  --surface: #ffffff;
  --page: #f4f6f5;
  --stage: #dfe6e2;
  --accent: #176d62;
  --accent-strong: #0d5b51;
  --accent-soft: #e5f2ef;
  --coral: #e77b61;
  --gold: #c49236;
  --danger: #b94d46;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { width: 100%; min-width: 320px; height: 100%; margin: 0; }
body { overflow: hidden; background: var(--page); color: var(--ink); }
button, input, select { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid #5b9d90; outline-offset: 2px; }
button:disabled { cursor: not-allowed; opacity: .44; }

.app-shell { display: flex; flex-direction: column; width: 100%; height: 100dvh; min-height: 520px; }
.standalone .app-shell { padding-top: max(env(safe-area-inset-top), 8px); }
.app-shell, .app-shell * { -webkit-tap-highlight-color: transparent; -webkit-touch-callout: none; }
.app-shell button, .app-shell a, .app-shell select { touch-action: manipulation; }
.app-shell input { -webkit-user-select: text; user-select: text; }
.topbar { z-index: 5; display: flex; align-items: center; justify-content: space-between; height: 64px; flex: 0 0 64px; padding: 0 22px; background: var(--surface); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 11px; min-width: 165px; }
.brand-mark { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 7px; background: var(--accent); color: white; font-family: Georgia, serif; font-size: 20px; font-weight: 700; }
.brand-copy { display: grid; gap: 2px; }
.brand-copy strong { font-size: 15px; font-weight: 650; }
.brand-copy span { color: var(--muted); font-size: 10px; }
.top-actions { display: flex; align-items: center; gap: 9px; }
.button, .icon-button, .text-button, .rail-tool, .template-card, .category-tab { border: 0; cursor: pointer; }
.button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 38px; padding: 0 14px; border-radius: 5px; font-size: 12px; font-weight: 600; white-space: nowrap; transition: background .15s ease, color .15s ease, border-color .15s ease; }
.button svg, .icon-button svg, .rail-icon svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.button-primary { background: var(--accent); color: #fff; }
.button-primary:hover:not(:disabled) { background: var(--accent-strong); }
.button-secondary { border: 1px solid var(--line); background: #fff; color: var(--ink); }
.button-secondary:hover:not(:disabled) { border-color: #b7ccc5; background: #f8fbf9; }
.button-small { min-height: 34px; padding: 0 11px; font-size: 11px; }
.icon-button { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 5px; background: transparent; color: #596660; }
.icon-button:hover:not(:disabled) { background: #edf2ef; color: var(--ink); }
.icon-button svg { width: 19px; height: 19px; }
.text-button { padding: 5px 7px; background: transparent; color: var(--accent); font-size: 11px; font-weight: 600; }
.text-button:hover:not(:disabled) { background: var(--accent-soft); border-radius: 4px; }
.text-button.destructive { color: var(--danger); }
.text-button.destructive:hover:not(:disabled) { background: #faecea; }

.workspace { display: grid; grid-template-columns: 66px minmax(0, 1fr) 348px; flex: 1 1 auto; min-height: 0; }
.toolrail { display: flex; flex-direction: column; align-items: center; gap: 5px; padding: 15px 7px; background: #fbfcfb; border-right: 1px solid var(--line); }
.rail-heading { margin: 0 0 6px; color: #9aa49f; font-size: 9px; font-weight: 650; letter-spacing: .08em; }
.rail-tool { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 5px; width: 50px; height: 54px; border-radius: 5px; background: transparent; color: #6e7a75; font-size: 9px; }
.rail-tool:hover { background: #f0f4f2; }
.rail-tool.is-active { background: var(--accent-soft); color: var(--accent-strong); }
.rail-icon { display: grid; place-items: center; width: 23px; height: 23px; font-family: Georgia, serif; font-size: 18px; font-weight: 700; }
.rail-icon svg { width: 20px; height: 20px; }
.stamp-icon { font-size: 22px; }
.floral-icon { color: var(--coral); }
.rail-rule { width: 28px; height: 1px; margin: 5px 0; background: var(--line); }

.canvas-column { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: #edf1ef; }
.canvas-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 48px; padding: 0 17px; border-bottom: 1px solid var(--line); background: #f8faf9; }
.photo-count { display: inline-flex; align-items: center; gap: 8px; color: #738079; font-size: 11px; white-space: nowrap; }
.local-dot { width: 6px; height: 6px; border-radius: 50%; background: #65a38e; }
.batch-tools { display: flex; align-items: center; justify-content: flex-end; gap: 6px; }
.segmented { display: inline-flex; align-items: center; padding: 2px; border: 1px solid var(--line); border-radius: 5px; background: #f1f4f2; }
.segmented button { min-width: 43px; height: 27px; padding: 0 10px; border: 0; border-radius: 3px; background: transparent; color: #75817b; font-size: 10px; cursor: pointer; }
.segmented button.is-active { background: #fff; color: var(--accent-strong); box-shadow: 0 1px 2px #26312e14; font-weight: 650; }
.mobile-import-actions { display: none; }
.stage-wrap { display: flex; flex: 1 1 auto; flex-direction: column; min-height: 0; padding: 19px 23px 0; }
.stage { position: relative; display: flex; flex: 1 1 auto; align-items: center; justify-content: center; min-height: 160px; overflow: hidden; border: 1px solid #d2dad6; border-radius: 5px; background-color: var(--stage); background-image: linear-gradient(45deg,#d6dfda 25%,transparent 25%),linear-gradient(-45deg,#d6dfda 25%,transparent 25%),linear-gradient(45deg,transparent 75%,#d6dfda 75%),linear-gradient(-45deg,transparent 75%,#d6dfda 75%); background-size: 18px 18px; background-position: 0 0,0 9px,9px -9px,-9px 0; }
#previewCanvas { display: block; width: 100%; height: 100%; touch-action: none; cursor: crosshair; }
.video-source { position: absolute; z-index: -1; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.empty-state { position: absolute; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 13px; inset: 0; pointer-events: none; }
.empty-frame { display: grid; place-items: center; width: 55px; height: 48px; color: #8f9e96; }
.empty-frame svg { width: 50px; height: 50px; fill: none; stroke: currentColor; stroke-width: 1.25; stroke-linecap: round; stroke-linejoin: round; }
.empty-state .button { pointer-events: auto; }
.empty-caption { color: #738079; font-size: 10px; }
.stage-badge { position: absolute; right: 10px; top: 10px; padding: 5px 8px; border-radius: 3px; background: #26312ecf; color: #fff; font-size: 9px; }
.video-controls { display: flex; align-items: center; gap: 8px; height: 40px; flex: 0 0 40px; padding: 0 8px; background: #f8faf9; border-bottom: 1px solid var(--line); }
.video-controls input[type="range"] { flex: 1; }
.video-controls span { min-width: 32px; color: var(--muted); font-size: 10px; font-variant-numeric: tabular-nums; }
.filmstrip { display: flex; flex: 0 0 auto; align-items: center; gap: 7px; min-height: 78px; overflow-x: auto; padding: 10px 1px 12px; scrollbar-width: thin; }
.filmstrip[hidden] { display: none; }
.film-item { position: relative; flex: 0 0 54px; width: 54px; height: 54px; padding: 0; overflow: hidden; border: 1px solid transparent; border-radius: 4px; background: #d9e0dc; cursor: pointer; }
.film-item img { width: 100%; height: 100%; object-fit: cover; }
.film-item.is-selected { border: 2px solid var(--accent); }
.film-item.has-override::after { position: absolute; top: 3px; right: 3px; width: 6px; height: 6px; border-radius: 50%; background: var(--coral); content: ""; }
.film-index { position: absolute; bottom: 2px; left: 3px; padding: 1px 3px; border-radius: 2px; background: #17201dcc; color: white; font-size: 8px; }

.inspector { min-width: 0; min-height: 0; overflow: hidden; background: var(--surface); border-left: 1px solid var(--line); }
.inspector-scroll { height: 100%; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; }
.panel-section { padding: 17px 17px 18px; border-bottom: 1px solid var(--line); }
.section-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 10px; margin-bottom: 13px; }
.section-heading h1, .section-heading h2, .export-dialog-heading h2 { margin: 2px 0 0; font-size: 16px; line-height: 1.15; font-weight: 650; }
.section-heading h2, .export-dialog-heading h2 { font-size: 14px; }
.section-kicker { color: #8a9690; font-size: 9px; font-weight: 700; }
.template-count { color: #9aa49f; font-size: 10px; }
.category-tabs { display: flex; gap: 13px; overflow-x: auto; margin: 0 -2px 12px; scrollbar-width: none; }
.category-tabs::-webkit-scrollbar { display: none; }
.category-tab { position: relative; flex: 0 0 auto; padding: 3px 1px 7px; background: transparent; color: #7e8984; font-size: 10px; white-space: nowrap; }
.category-tab.is-active { color: var(--accent-strong); font-weight: 650; }
.category-tab.is-active::after { position: absolute; right: 0; bottom: 0; left: 0; height: 2px; background: var(--accent); content: ""; }
.template-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 7px; }
.template-card { display: flex; min-width: 0; flex-direction: column; align-items: stretch; justify-content: center; gap: 5px; height: 57px; padding: 5px 4px; border: 1px solid #e5eae7; border-radius: 4px; background: #fafcfb; }
.template-card:hover { border-color: #a9c6bd; background: #f4f9f7; }
.template-sample { display: grid; place-items: center; height: 26px; overflow: hidden; color: var(--sample-color); font-size: 11px; font-weight: 700; text-shadow: 0 1px 2px #26312e35; }
.template-label { overflow: hidden; color: #6e7974; font-size: 9px; text-overflow: ellipsis; white-space: nowrap; }
.compact-heading { margin-bottom: 12px; }
.field-label { color: #79847f; font-size: 10px; }
.text-input, .select-input { width: 100%; height: 35px; padding: 0 10px; border: 1px solid #dfe6e2; border-radius: 4px; background: #fff; color: var(--ink); font-size: 11px; }
.text-input:focus, .select-input:focus { border-color: #7ca99d; outline: none; }
.field-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 13px; }
.font-row .field-label { flex: 0 0 auto; }
.font-row .select-input { width: 150px; height: 31px; padding: 0 8px; }
.color-controls { display: flex; align-items: center; gap: 12px; }
.swatches { display: flex; align-items: center; gap: 8px; }
.swatch { position: relative; width: 20px; height: 20px; padding: 0; border: 1px solid #d4dcd7; border-radius: 50%; cursor: pointer; }
.swatch.is-active::after { position: absolute; inset: -4px; border: 1.5px solid var(--accent); border-radius: 50%; content: ""; }
.swatch[data-color="#ffffff"] { box-shadow: inset 0 0 0 1px #fff; }
.color-picker-wrap { position: relative; display: block; width: 23px; height: 23px; overflow: hidden; border: 1px solid #d4dcd7; border-radius: 50%; background: conic-gradient(#ee7065,#ead35c,#69bd81,#55a9ce,#ae83c2,#ee7065); cursor: pointer; }
.color-picker-wrap input { position: absolute; inset: -7px; width: 38px; height: 38px; opacity: .01; cursor: pointer; }
.eyedropper-mark { position: absolute; inset: 6px; border: 1.5px solid #fff; border-radius: 50%; pointer-events: none; }
.slider-list { display: grid; gap: 10px; margin-top: 16px; }
.slider-row { display: grid; grid-template-columns: 53px minmax(0, 1fr) 38px; align-items: center; gap: 9px; color: #6f7b75; font-size: 10px; }
.slider-row output { color: #818c86; text-align: right; font-size: 9px; font-variant-numeric: tabular-nums; }
input[type="range"] { width: 100%; height: 18px; margin: 0; accent-color: var(--accent); }
.outline-row { justify-content: flex-start; margin-top: 14px; }
.small-color { width: 21px; height: 21px; background: #303734; }
.small-color input { width: 36px; height: 36px; }
.outline-mark { position: absolute; inset: 5px; border: 1.5px solid #fff; border-radius: 50%; pointer-events: none; }
.logo-actions, .default-logo-actions { display: flex; align-items: center; gap: 6px; }
.default-logo-actions { gap: 14px; margin-top: 12px; padding-top: 9px; border-top: 1px solid #edf0ee; }

.mobile-actionbar { display: none; }
.install-prompt { z-index: 7; display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 42px; padding: 5px 16px; border-bottom: 1px solid #dfe8e4; background: #f5fbf8; color: #47645a; font-size: 11px; }
.update-prompt { position: fixed; z-index: 26; right: 16px; bottom: 16px; left: 16px; display: flex; align-items: center; justify-content: space-between; gap: 12px; width: min(420px, calc(100% - 32px)); margin: 0 auto; padding: 10px 12px; border: 1px solid #d8e4df; border-radius: 6px; background: #fff; box-shadow: 0 8px 28px #26312e1c; color: var(--ink); font-size: 11px; }
.toast { position: fixed; z-index: 30; bottom: 22px; left: 50%; max-width: calc(100% - 32px); padding: 11px 15px; transform: translateX(-50%); border: 1px solid #d7e2dd; border-radius: 5px; background: #fff; color: var(--ink); box-shadow: 0 8px 24px #26312e17; font-size: 12px; }
.toast[hidden], .export-overlay[hidden] { display: none; }
.export-overlay { position: fixed; z-index: 25; display: grid; place-items: center; inset: 0; padding: 18px; background: #17201e7a; }
.export-dialog { display: flex; width: min(430px, 100%); max-height: min(82dvh, 700px); flex-direction: column; padding: 20px; overflow: hidden; border-radius: 7px; background: #fff; box-shadow: 0 18px 60px #0b161244; }
.export-dialog-heading { display: flex; align-items: center; justify-content: space-between; padding-bottom: 13px; border-bottom: 1px solid var(--line); }
.export-status { margin: 13px 0 9px; color: #75817b; font-size: 11px; }
.progress-track { height: 4px; overflow: hidden; border-radius: 5px; background: #e9efec; }
.progress-track span { display: block; width: 0; height: 100%; background: var(--accent); transition: width .15s ease; }
.export-results { display: grid; gap: 7px; min-height: 0; overflow-y: auto; padding: 13px 0; }
.result-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 42px; padding: 6px 9px; border: 1px solid #e7ece9; border-radius: 4px; }
.result-name { min-width: 0; overflow: hidden; color: #58645e; font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.result-row a { flex: 0 0 auto; padding: 6px 8px; border-radius: 3px; background: var(--accent-soft); color: var(--accent-strong); font-size: 10px; font-weight: 600; text-decoration: none; }
.share-button { width: 100%; margin-top: 3px; }

@media (min-width: 1500px) {
  .workspace { grid-template-columns: 72px minmax(0, 1fr) 374px; }
  .stage-wrap { padding: 24px 32px 0; }
  .panel-section { padding-right: 20px; padding-left: 20px; }
}

@media (max-width: 850px) {
  .app-shell { min-height: 0; }
  .topbar { height: 56px; flex-basis: 56px; padding: 0 12px; }
  .brand { min-width: 0; gap: 8px; }
  .brand-mark { width: 30px; height: 30px; font-size: 18px; }
  .brand-copy strong { font-size: 13px; }
  .brand-copy span { display: none; }
  .top-actions { gap: 3px; }
  .top-actions .icon-button { width: 34px; height: 34px; }
  .top-actions .import-trigger { display: none; }
  .top-actions .video-trigger { display: none; }
  .top-actions .export-trigger { display: none; }
  .workspace { display: flex; flex-direction: column; min-height: 0; }
  .toolrail { display: none; }
  .canvas-column { flex: 0 0 auto; min-height: 0; }
  .canvas-toolbar { min-height: 38px; height: 38px; padding: 0 12px; }
  .batch-tools { gap: 3px; }
  .batch-tools .text-button { font-size: 9px; }
  .segmented { padding: 1px; }
  .segmented button { min-width: 39px; height: 24px; font-size: 9px; }
  .mobile-import-actions { display: flex; align-items: center; gap: 0; }
  .mobile-import-actions .icon-button { width: 32px; height: 32px; }
  .stage-wrap { height: min(43dvh, 390px); min-height: 235px; padding: 8px 10px 0; }
  .stage { min-height: 0; }
  .empty-frame { width: 42px; height: 40px; }
  .empty-frame svg { width: 41px; height: 41px; }
  .empty-state { gap: 9px; }
  .empty-caption { font-size: 9px; }
  .filmstrip { min-height: 62px; gap: 6px; padding: 6px 0 7px; }
  .film-item { flex-basis: 46px; width: 46px; height: 46px; }
  .video-controls { height: 35px; flex-basis: 35px; }
  .inspector { flex: 1 1 auto; min-height: 0; overflow: hidden; border-top: 1px solid var(--line); border-left: 0; }
  .inspector-scroll { padding-bottom: 9px; }
  .panel-section { padding: 12px 14px 13px; }
  .section-heading { margin-bottom: 9px; }
  .section-heading h1 { font-size: 14px; }
  .section-heading h2 { font-size: 13px; }
  .category-tabs { gap: 16px; margin-bottom: 9px; }
  .template-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
  .template-card { height: 48px; gap: 3px; }
  .template-sample { height: 21px; font-size: 10px; }
  .template-label { font-size: 8px; }
  .settings-section .compact-heading { margin-bottom: 9px; }
  .text-input { height: 33px; }
  .field-row { margin-top: 9px; }
  .slider-list { gap: 6px; margin-top: 10px; }
  .slider-row { grid-template-columns: 48px minmax(0, 1fr) 36px; gap: 6px; }
  .outline-row { margin-top: 9px; }
  .logo-section { padding-bottom: 20px; }
  .mobile-actionbar { z-index: 6; display: flex; flex: 0 0 auto; min-height: 60px; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 14px max(env(safe-area-inset-bottom), 8px); border-top: 1px solid var(--line); background: #fff; }
  .mobile-actionbar > span { color: #78847e; font-size: 10px; }
  .mobile-actionbar .button { min-width: 140px; min-height: 40px; }
  .toast { bottom: calc(68px + max(env(safe-area-inset-bottom), 8px)); }
  .update-prompt { bottom: calc(72px + max(env(safe-area-inset-bottom), 8px)); }
}

@media (max-width: 390px) {
  .stage-wrap { height: 38dvh; min-height: 205px; }
  .template-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; }
  .template-card { padding-right: 2px; padding-left: 2px; }
  .swatches { gap: 6px; }
  .swatch { width: 18px; height: 18px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
