:root {
  --navy: #12365e;
  --blue: #1467a8;
  --light-blue: #eaf3fa;
  --ink: #1d2b3a;
  --muted: #6a7c8d;
  --line: #d9e3ea;
  --bg: #f5f8fa;
  --danger: #a33b3b;
  --brand-primary: #1467a8;
  --brand-secondary: #eaf3fa;
  --brand-accent: #ff8b42;
}

* { box-sizing: border-box; }
html { color-scheme: light; }
body { margin: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans JP", sans-serif; background: var(--bg); color: var(--ink); }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.topbar { height: 78px; background: #fff; border-bottom: 1px solid var(--line); padding: 0 28px; display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 100; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; background: linear-gradient(135deg, var(--navy), var(--blue)); color: #fff; font-weight: 900; }
.brand strong, .brand small { display: block; }
.brand strong { font-size: 18px; }
.brand small { color: var(--muted); margin-top: 2px; }
.header-actions { display: flex; align-items: center; gap: 10px; }
.ghost-btn { min-height: 38px; padding: 0 14px; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--navy); font-weight: 800; }
.status-badge { padding: 7px 11px; border-radius: 999px; font-size: 12px; font-weight: 800; background: #eef2f5; color: #536477; }
.status-badge.api { background: #e8f6ee; color: #24633d; }
.status-badge.demo { background: #fff3df; color: #8a5714; }

.wizard-shell { width: min(1040px, calc(100% - 30px)); margin: 30px auto 60px; }
.progress-wrap { margin-bottom: 14px; }
.progress-label { display: flex; justify-content: space-between; color: var(--muted); font-size: 13px; font-weight: 800; }
.progress-track { height: 8px; background: #dfe7ed; border-radius: 999px; overflow: hidden; margin-top: 8px; }
.progress-bar { height: 100%; width: 16.67%; background: linear-gradient(90deg, var(--navy), var(--blue)); transition: width .2s ease; }
.wizard-card { background: #fff; border: 1px solid var(--line); border-radius: 24px; padding: 38px; box-shadow: 0 15px 45px rgba(25, 55, 82, .08); }
.step { display: none; min-height: 500px; }
.step.active { display: block; }
.step-icon { width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; background: var(--light-blue); color: var(--blue); font-weight: 900; }
.step h1 { font-size: clamp(26px, 3.2vw, 38px); margin: 18px 0 8px; letter-spacing: -.03em; }
.help { margin: 0 0 28px; color: var(--muted); font-size: 16px; }
.product-grid, .chip-grid, .style-grid { display: grid; gap: 12px; }
.product-grid { grid-template-columns: repeat(3, 1fr); }
.select-card, .choice-chip, .style-card { border: 2px solid var(--line); background: #fff; border-radius: 14px; color: var(--ink); transition: .15s ease; }
.select-card { min-height: 76px; padding: 16px; font-size: 18px; font-weight: 700; }
.select-card:hover, .choice-chip:hover, .style-card:hover { border-color: #8db6d6; transform: translateY(-1px); }
.select-card.selected, .choice-chip.selected, .style-card.selected { border-color: var(--blue); background: var(--light-blue); color: var(--navy); }
.chip-grid { grid-template-columns: repeat(4, 1fr); }
.choice-chip { min-height: 66px; padding: 12px; font-size: 16px; font-weight: 700; }
.field-label { display: block; margin: 24px 0 8px; font-size: 14px; font-weight: 800; color: var(--navy); }
.big-input { width: 100%; border: 2px solid var(--line); border-radius: 13px; min-height: 54px; padding: 13px 15px; font-size: 18px; outline: none; background: #fff; }
.big-input:focus, .tool-textarea:focus, .small-input:focus, .hex-input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(30, 111, 184, .12); }
.textarea { min-height: 100px; resize: vertical; }
.select-input { appearance: auto; }

.upload-box { min-height: 245px; border: 3px dashed #aac2d5; border-radius: 20px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; background: #f9fcfe; color: var(--navy); transition: .15s ease; }
.upload-box:hover, .upload-box.dragover { background: var(--light-blue); border-color: var(--blue); }
.upload-icon { width: 60px; height: 60px; border-radius: 50%; background: #fff; border: 1px solid var(--line); display: grid; place-items: center; font-size: 34px; }
.upload-box strong { font-size: 20px; }
.upload-box span { color: var(--muted); }
.reference-preview { margin-top: 16px; display: flex; align-items: center; gap: 16px; }
.reference-preview img { width: 130px; height: 90px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); }

.brand-layout { display: grid; grid-template-columns: 1.1fr .9fr; gap: 24px; align-items: start; }
.logo-upload { display: block; }
.logo-preview-box { min-height: 110px; border: 2px dashed #b9cbd8; border-radius: 14px; display: grid; place-items: center; padding: 14px; background: #fafcfd; color: var(--muted); overflow: hidden; }
.logo-preview-box img { max-width: 220px; max-height: 74px; object-fit: contain; }
.logo-upload small { display: block; color: var(--muted); margin-top: 6px; }
.logo-actions { margin-top: 8px; }
.color-settings { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-top: 24px; }
.color-field { border: 1px solid var(--line); border-radius: 14px; padding: 14px; background: #fbfdfe; }
.color-field > label { display: block; font-size: 13px; font-weight: 800; margin-bottom: 9px; color: var(--navy); }
.color-row { display: grid; grid-template-columns: 48px 1fr; gap: 8px; align-items: center; }
.color-row input[type="color"] { width: 48px; height: 44px; border: 0; padding: 0; background: transparent; }
.hex-input { width: 100%; min-height: 42px; border: 1px solid var(--line); border-radius: 10px; padding: 0 10px; text-transform: uppercase; outline: none; }
.quick-palettes { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 16px; color: var(--muted); font-size: 13px; }
.palette-btn { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 8px 11px; display: inline-flex; align-items: center; gap: 7px; color: var(--ink); }
.palette-btn i { width: 15px; height: 15px; border-radius: 50%; background: var(--c); box-shadow: inset 0 0 0 1px rgba(0,0,0,.08); }
.advanced-settings { margin-top: 20px; border: 1px solid var(--line); border-radius: 14px; background: #fbfdfe; }
.advanced-settings summary { padding: 14px 16px; cursor: pointer; color: var(--navy); font-weight: 800; }
.advanced-grid { padding: 0 16px 16px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.advanced-grid label { font-size: 13px; color: var(--muted); }
.small-select, .small-input { margin-top: 6px; width: 100%; min-height: 42px; border: 1px solid var(--line); border-radius: 9px; padding: 0 10px; background: #fff; outline: none; }
.brand-save-row { display: flex; align-items: center; gap: 12px; margin-top: 18px; }
.brand-save-row span { color: var(--muted); font-size: 13px; }

.style-grid { grid-template-columns: repeat(2, 1fr); }
.style-card { padding: 18px; text-align: left; min-height: 88px; }
.style-card b, .style-card span { display: block; }
.style-card b { font-size: 18px; margin-bottom: 4px; }
.style-card span { color: var(--muted); font-size: 14px; }
.style-card.selected span { color: #456985; }

.wizard-actions { display: flex; gap: 12px; justify-content: space-between; align-items: center; border-top: 1px solid var(--line); padding-top: 24px; margin-top: 18px; }
.primary-btn, .secondary-btn, .text-btn, .mini-btn { border-radius: 11px; border: 0; font-weight: 800; }
.primary-btn, .secondary-btn { min-height: 52px; padding: 0 24px; font-size: 17px; }
.primary-btn { background: var(--navy); color: #fff; }
.primary-btn:hover { background: #0a2444; }
.primary-btn.generate { margin-left: auto; min-width: 260px; background: linear-gradient(135deg, var(--navy), var(--blue)); }
.secondary-btn { background: #edf3f7; color: var(--navy); border: 1px solid #cddae4; }
.secondary-btn:disabled { opacity: .45; cursor: not-allowed; }
.full { width: 100%; }
.text-btn { background: transparent; color: var(--muted); text-decoration: underline; padding: 8px; }
.mini-btn { min-height: 38px; padding: 0 12px; background: #edf3f7; color: var(--navy); border: 1px solid #cddae4; }
.mini-btn.danger { color: var(--danger); }
.file-btn { display: flex; align-items: center; justify-content: center; cursor: pointer; }

.loading-view { min-height: calc(100vh - 78px); display: flex; flex-direction: column; align-items: center; justify-content: center; }
.spinner { width: 64px; height: 64px; border: 7px solid #dce8f1; border-top-color: var(--blue); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-view h2 { margin: 20px 0 7px; font-size: 26px; }
.loading-view p { color: var(--muted); }

.editor-view { display: grid; grid-template-columns: 320px 1fr; min-height: calc(100vh - 78px); }
.editor-toolbar { background: #fff; border-right: 1px solid var(--line); padding: 24px 20px; position: sticky; top: 78px; height: calc(100vh - 78px); overflow: auto; }
.toolbar-section { padding-bottom: 22px; margin-bottom: 22px; border-bottom: 1px solid var(--line); }
.toolbar-section h3, .toolbar-section h4 { margin: 0 0 7px; }
.toolbar-section h3 { font-size: 20px; }
.toolbar-section h4 { font-size: 16px; color: var(--navy); }
.toolbar-section p { margin: 0; color: var(--muted); line-height: 1.6; font-size: 14px; }
.tool-textarea { width: 100%; border: 2px solid var(--line); border-radius: 11px; padding: 10px; resize: vertical; outline: none; }
.inline-buttons { display: flex; gap: 8px; }
.compact-label { display: block; font-size: 12px; font-weight: 800; color: var(--muted); margin: 12px 0 5px; }
.color-row.compact { grid-template-columns: 42px 1fr; }
.color-row.compact input[type="color"] { width: 42px; height: 40px; }
.tiny { margin-top: 8px !important; font-size: 12px !important; }
.export-buttons { display: grid; gap: 10px; border-bottom: 0; }

.canvas-area { padding: 28px; overflow: auto; background: #e9eef3; }
.canvas-topline { width: min(794px, 100%); margin: 0 auto 14px; display: flex; justify-content: space-between; color: #586878; font-size: 13px; }
.canvas-topline strong { color: var(--navy); font-size: 16px; margin-right: 8px; }
#modeLabel { padding: 4px 8px; background: white; border-radius: 99px; }

.flyer { --flyer-primary: var(--brand-primary); --flyer-secondary: var(--brand-secondary); --flyer-accent: var(--brand-accent); width: 794px; height: 1123px; margin: 0 auto 60px; background: #fff; position: relative; overflow: hidden; box-shadow: 0 12px 45px rgba(20, 42, 66, .18); color: #1d2b3a; }
.flyer [contenteditable="true"] { outline: none; border-radius: 4px; }
.flyer [contenteditable="true"]:hover { box-shadow: inset 0 0 0 1px rgba(30,111,184,.45); }
.flyer [contenteditable="true"]:focus { box-shadow: inset 0 0 0 2px #3f95d4; background: rgba(255,255,255,.08); }
.flyer-top-accent { height: 10px; background: var(--flyer-primary); }
.flyer-header { height: 76px; display: flex; justify-content: space-between; align-items: center; padding: 0 48px; }
.flyer-header.logo-right { flex-direction: row-reverse; }
.flyer-brand-wrap { min-width: 140px; display: flex; align-items: center; }
.flyer-logo { max-width: 210px; max-height: 48px; object-fit: contain; }
.flyer-brand { font-size: 24px; font-weight: 900; letter-spacing: .12em; color: var(--flyer-primary); }
.flyer-target { color: #53697e; font-size: 14px; font-weight: 700; }
.hero-wrap { height: 455px; position: relative; overflow: hidden; background: #173c60; }
.hero-image { width: 100%; height: 100%; object-fit: cover; display: block; }
.hero-overlay { position: absolute; inset: 0; background: linear-gradient(90deg, rgba(7,34,61,.88) 0%, rgba(7,34,61,.56) 52%, rgba(7,34,61,.08) 100%); }
.hero-copy { position: absolute; left: 52px; top: 75px; width: 590px; color: white; }
.product-label { display: inline-block; border: 1px solid rgba(255,255,255,.6); border-radius: 99px; padding: 7px 13px; font-size: 13px; font-weight: 800; letter-spacing: .08em; }
.hero-copy h1 { font-size: 48px; line-height: 1.17; letter-spacing: -.04em; margin: 23px 0 14px; max-width: 590px; }
.hero-copy p { margin: 0; font-size: 22px; line-height: 1.5; font-weight: 600; max-width: 520px; }
.flyer-content { padding: 44px 52px 28px; }
.lead { font-size: 20px; line-height: 1.7; font-weight: 700; margin: 0 0 30px; color: #2b3c4e; }
.benefit-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.benefit-card { min-height: 138px; padding: 22px 18px; background: var(--flyer-secondary); border-radius: 12px; border-top: 4px solid var(--flyer-primary); }
.benefit-card span { display: block; color: var(--flyer-primary); font-size: 12px; font-weight: 900; letter-spacing: .09em; }
.benefit-card p { font-size: 17px; line-height: 1.5; font-weight: 800; margin: 12px 0 0; }
.cta-box { margin-top: 28px; background: var(--flyer-primary); color: #fff; border-radius: 12px; min-height: 112px; display: flex; align-items: center; justify-content: space-between; padding: 22px 24px; border-left: 8px solid var(--flyer-accent); }
.cta-box small { display: block; opacity: .72; letter-spacing: .13em; font-weight: 800; }
.cta-box p { margin: 7px 0 0; font-size: 17px; font-weight: 800; }
.qr-placeholder { width: 68px; height: 68px; background: white; color: var(--flyer-primary); display: grid; place-items: center; font-weight: 900; border-radius: 4px; }
.flyer-footer { position: absolute; bottom: 0; left: 0; right: 0; height: 48px; display: flex; align-items: center; justify-content: space-between; padding: 0 52px; border-top: 1px solid #dce4eb; color: #647385; font-size: 12px; }

.flyer.theme-simple .hero-overlay { background: linear-gradient(90deg, rgba(255,255,255,.96), rgba(255,255,255,.62), rgba(255,255,255,.08)); }
.flyer.theme-simple .hero-copy { color: #1d2b3a; }
.flyer.theme-simple .product-label { border-color: rgba(29,43,58,.4); }
.flyer.theme-modern .hero-wrap { background: #111827; }
.flyer.theme-modern .hero-overlay { background: linear-gradient(100deg, rgba(10,16,30,.88), rgba(10,16,30,.18)); }
.flyer.theme-friendly .hero-overlay { background: linear-gradient(90deg, rgba(28,73,66,.84), rgba(28,73,66,.42), rgba(28,73,66,.06)); }

.modal-backdrop { position: fixed; inset: 0; background: rgba(13,28,42,.55); z-index: 500; display: grid; place-items: center; padding: 20px; }
.modal-card { width: min(680px, 100%); max-height: min(760px, calc(100vh - 40px)); overflow: auto; background: #fff; border-radius: 20px; box-shadow: 0 24px 80px rgba(0,0,0,.25); }
.modal-head { padding: 22px 24px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 15px; align-items: flex-start; }
.modal-head h2 { margin: 0 0 4px; }
.modal-head p { margin: 0; color: var(--muted); }
.icon-btn { width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line); background: #fff; font-size: 24px; }
.modal-body { padding: 22px 24px; }
.modal-actions { padding: 18px 24px 24px; display: flex; justify-content: flex-end; }
.saved-brand-list { margin-top: 20px; display: grid; gap: 9px; }
.saved-brand-item { border: 1px solid var(--line); border-radius: 12px; padding: 12px; display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center; }
.saved-brand-main { display: flex; align-items: center; gap: 10px; min-width: 0; }
.saved-brand-swatches { display: flex; }
.saved-brand-swatches i { width: 18px; height: 18px; border-radius: 50%; margin-left: -4px; border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.06); }
.saved-brand-actions { display: flex; gap: 6px; }

.toast { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); background: #12263a; color: white; padding: 12px 18px; border-radius: 999px; z-index: 800; box-shadow: 0 8px 24px rgba(0,0,0,.2); }

@media (max-width: 1050px) {
  .editor-view { grid-template-columns: 1fr; }
  .editor-toolbar { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--line); display: grid; grid-template-columns: repeat(2, 1fr); gap: 18px; }
  .toolbar-section { margin: 0; }
  .canvas-area { overflow-x: auto; }
}

@media (max-width: 760px) {
  .topbar { height: auto; min-height: 70px; padding: 10px 14px; gap: 10px; }
  .brand small, .ghost-btn { display: none; }
  .wizard-card { padding: 24px 18px; border-radius: 17px; }
  .step { min-height: 500px; }
  .product-grid, .chip-grid, .style-grid, .color-settings, .advanced-grid, .brand-layout { grid-template-columns: 1fr; }
  .product-grid, .chip-grid { grid-template-columns: 1fr 1fr; }
  .select-card, .choice-chip { font-size: 15px; }
  .wizard-actions { gap: 8px; }
  .primary-btn, .secondary-btn { padding: 0 15px; }
  .primary-btn.generate { min-width: 0; width: 100%; }
  .editor-toolbar { grid-template-columns: 1fr; }
  .brand-save-row { align-items: stretch; flex-direction: column; }
}

@media print {
  body { background: white; }
  .topbar, .editor-toolbar, .canvas-topline { display: none !important; }
  .editor-view { display: block !important; }
  .canvas-area { padding: 0 !important; background: white !important; overflow: visible !important; }
  .flyer { width: 210mm; height: 297mm; box-shadow: none; margin: 0; }
  @page { size: A4; margin: 0; }
}
