:root {
  --bg: #f3f4f6;
  --card: #ffffff;
  --ink: #111827;
  --muted: #6b7280;
  --line: #d1d5db;
  --accent: #0f172a;
  --danger: #b91c1c;
  --radius: 18px;
  --shadow: 0 10px 30px rgba(15,23,42,.08);
}
* { box-sizing: border-box; }
html { background: var(--bg); }
body { margin: 0; color: var(--ink); background: var(--bg); font-family: system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif; }
body.editor-open { overflow: hidden; overscroll-behavior: none; }
button,input,select { font: inherit; }
button,.button-like { min-height: 46px; border: 1px solid var(--line); border-radius: 12px; background: #fff; color: var(--ink); padding: 10px 14px; font-weight: 700; cursor: pointer; touch-action: manipulation; }
button:active,.button-like:active { transform: translateY(1px); }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
button.danger { color: var(--danger); border-color: #fecaca; background: #fff7f7; }
button.ghost { background: transparent; }
.hidden { display: none !important; }
.app-header { max-width: 1200px; margin: 0 auto; padding: 18px 16px 8px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.app-header h1 { margin: 0; font-size: clamp(1.35rem,4vw,2rem); }
.app-header p { margin: 5px 0 0; color: var(--muted); font-size: .92rem; }
.app-shell { max-width: 1200px; margin: 0 auto; padding: 8px 12px 32px; }
.preview-sticky { position: sticky; top: 0; z-index: 30; background: rgba(243,244,246,.95); backdrop-filter: blur(10px); padding: 8px 0 10px; }
.preview-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 7px; }
.chip-row,.toolbar-actions,.button-row { display: flex; align-items: center; gap: 8px; }
.chip-row { flex-wrap: wrap; }
.toolbar-actions { flex-shrink: 0; }
.button-row.wrap { flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; min-height: 34px; padding: 5px 10px; border: 1px solid var(--line); background: #fff; border-radius: 999px; font-size: .85rem; font-weight: 800; }
.icon-btn { min-width: 44px; padding: 9px; font-size: 1.2rem; }
.fullscreen-btn { min-height: 44px; padding: 8px 12px; background: var(--accent); color: #fff; border-color: var(--accent); white-space: nowrap; }
.toggle { display: inline-flex; align-items: center; gap: 8px; min-height: 42px; padding: 7px 10px; border: 1px solid var(--line); border-radius: 12px; background: #fff; font-weight: 700; }
.toggle.compact { min-height: 34px; padding: 4px 8px; font-size: .83rem; }
.toggle input { width: 20px; height: 20px; }
.canvas-stage { position: relative; width: 100%; border-radius: 14px; overflow: hidden; background: #111827; box-shadow: var(--shadow); border: 1px solid #111827; line-height: 0; }
#headerCanvas { display: block; width: 100%; height: auto; aspect-ratio: 3/1; touch-action: none; cursor: default; }
.gesture-hint { display: none; position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); z-index: 2; padding: 8px 12px; border-radius: 999px; background: rgba(15,23,42,.82); color: #fff; font-size: .78rem; font-weight: 800; line-height: 1.2; white-space: nowrap; pointer-events: none; }
.preview-note { margin: 6px 2px 0; color: var(--muted); font-size: .78rem; }
.autosave-status { margin: 0; min-height: 1.3em; font-variant-numeric: tabular-nums; }
.autosave-status[data-state="saving"] { color: #1d4ed8; }
.autosave-status[data-state="saved"] { color: #166534; }
.autosave-status[data-state="error"] { color: var(--danger); font-weight: 700; }
.control-stack { display: grid; gap: 12px; margin-top: 12px; }
.panel,.export-card { border: 1px solid var(--line); background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: clip; }
.panel summary { cursor: pointer; list-style: none; padding: 17px 18px; font-weight: 900; user-select: none; }
.panel summary::-webkit-details-marker { display:none; }
.panel summary::after { content: "＋"; float: right; color: var(--muted); }
.panel[open] summary::after { content: "−"; }
.panel-body { border-top: 1px solid #eef0f2; padding: 16px; display: grid; gap: 14px; }
.file-drop { border: 2px dashed #cbd5e1; border-radius: 16px; background: #f8fafc; min-height: 110px; display: grid; place-content: center; text-align: center; cursor: pointer; padding: 16px; }
.file-drop.small { min-height: 90px; }
.file-drop input,.button-like input { display: none; }
.file-drop strong { font-size: 1rem; }
.file-drop span,.hint { color: var(--muted); font-size: .86rem; }
.range-grid { display: grid; gap: 13px; }
.range-grid label { display: grid; grid-template-columns: 90px 1fr; gap: 8px 12px; align-items: center; font-weight: 700; }
.range-grid output { justify-self: end; color: var(--muted); font-variant-numeric: tabular-nums; font-size: .86rem; }
.range-grid input[type=range] { grid-column: 1 / -1; width: 100%; min-height: 32px; }
.input-grid { display: grid; gap: 12px; }
.input-grid.two { grid-template-columns: repeat(2,minmax(0,1fr)); }
.input-grid label { display:grid; gap:6px; font-weight:700; }
.input-grid input,.input-grid select { width: 100%; min-height: 46px; border:1px solid var(--line); border-radius:12px; padding:10px 12px; background:#fff; }
.input-grid input[type=color] { padding:4px; }
.empty-state { margin: 0; color: var(--muted); }
.selection-title-row { display:flex; align-items:center; justify-content:space-between; gap:10px; }
.tag { font-size:.75rem; color:var(--muted); border:1px solid var(--line); border-radius:999px; padding:4px 8px; }
.layer-list { display:grid; gap:8px; }
.layer-item { display:grid; grid-template-columns: 1fr auto; gap:8px; align-items:center; border:1px solid var(--line); border-radius:12px; padding:9px; background:#fff; }
.layer-item.selected { outline:3px solid rgba(15,23,42,.16); border-color:#64748b; }
.layer-main { display:flex; gap:10px; align-items:center; min-width:0; cursor:pointer; }
.layer-thumb { width:44px; height:44px; border-radius:9px; border:1px solid var(--line); background:#f8fafc; object-fit:contain; }
.layer-icon { width:44px; height:44px; border-radius:9px; display:grid; place-items:center; background:#f8fafc; border:1px solid var(--line); font-weight:900; }
.layer-text { min-width:0; }
.layer-text strong,.layer-text span { display:block; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.layer-text span { color:var(--muted); font-size:.78rem; margin-top:3px; }
.layer-mini-actions { display:flex; gap:4px; }
.layer-mini-actions button { min-width:40px; min-height:40px; padding:7px; }
.export-card { padding:18px; display:flex; justify-content:space-between; gap:14px; align-items:center; }
.export-card h2 { margin:0 0 4px; }
.export-card p { margin:0; color:var(--muted); }
.export-buttons { flex-wrap:wrap; justify-content:flex-end; }
.button-like { display:inline-flex; align-items:center; justify-content:center; }
dialog { border:0; padding:0; background:transparent; width:min(720px,94vw); }
dialog::backdrop { background:rgba(15,23,42,.52); backdrop-filter:blur(4px); }
.dialog-card { background:#fff; border-radius:20px; overflow:hidden; box-shadow:0 24px 70px rgba(0,0,0,.25); }
.dialog-header,.dialog-footer { padding:15px; display:flex; align-items:center; justify-content:space-between; gap:12px; }
.dialog-header { border-bottom:1px solid var(--line); }
.dialog-header h2 { margin:0; }
.dialog-header p { margin:3px 0 0; color:var(--muted); font-size:.84rem; }
.dialog-footer { border-top:1px solid var(--line); justify-content:flex-end; }
.asset-library-grid { padding:15px; display:grid; grid-template-columns:repeat(3,minmax(0,1fr)); gap:10px; max-height:60vh; overflow:auto; }
.asset-card { border:1px solid var(--line); border-radius:14px; padding:9px; display:grid; gap:8px; background:#f8fafc; }
.asset-card img { width:100%; aspect-ratio:1; object-fit:contain; background:white; border-radius:9px; border:1px solid #e5e7eb; }
.asset-card strong { overflow:hidden; text-overflow:ellipsis; white-space:nowrap; font-size:.82rem; }
.asset-card .button-row { gap:5px; }
.asset-card button { min-height:40px; padding:7px 9px; flex:1; }
.toast { position:fixed; left:50%; bottom:calc(18px + env(safe-area-inset-bottom)); transform:translateX(-50%) translateY(20px); opacity:0; pointer-events:none; background:#111827; color:#fff; padding:11px 16px; border-radius:999px; font-weight:800; z-index:100; transition:.2s ease; box-shadow:0 8px 30px rgba(0,0,0,.25); }
.toast.show { opacity:1; transform:translateX(-50%) translateY(0); }

/* v0.4 fullscreen editor */
.preview-sticky.edit-fullscreen {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  max-width: none;
  padding: calc(8px + env(safe-area-inset-top)) 8px calc(8px + env(safe-area-inset-bottom));
  background: #0f172a;
  backdrop-filter: none;
}
.preview-sticky.edit-fullscreen .preview-toolbar { flex: 0 0 auto; margin: 0 0 8px; }
.preview-sticky.edit-fullscreen .canvas-stage { flex: 1 1 auto; min-height: 0; display: flex; align-items: center; justify-content: center; border: 0; border-radius: 10px; box-shadow: none; background: #020617; }
.preview-sticky.edit-fullscreen #headerCanvas { width: min(100%, calc((100vh - 130px) * 3)); max-width: none; height: auto; flex: 0 0 auto; box-shadow: 0 10px 40px rgba(0,0,0,.45); }
.preview-sticky.edit-fullscreen .preview-note { flex: 0 0 auto; margin: 7px 0 0; color: #cbd5e1; text-align: center; }
.preview-sticky.edit-fullscreen .gesture-hint { display: block; }
.preview-sticky.edit-fullscreen .fullscreen-btn { background: #fff; color: #0f172a; border-color: #fff; }
@media (min-width: 900px) {
  .app-shell { display:grid; grid-template-columns:minmax(0,1.25fr) minmax(340px,.75fr); gap:16px; align-items:start; }
  .preview-sticky { top:8px; padding-top:0; }
  .control-stack { margin-top:0; }
}
@media (max-width: 600px) {
  .app-header { padding-top:12px; }
  .preview-toolbar { align-items:stretch; flex-direction:column; }
  .toolbar-actions { justify-content:flex-end; }
  .toolbar-actions .ghost { display:none; }
  .input-grid.two { grid-template-columns:1fr 1fr; }
  .export-card { align-items:stretch; flex-direction:column; }
  .export-buttons button { flex:1; }
  .asset-library-grid { grid-template-columns:repeat(2,minmax(0,1fr)); }
  .range-grid label { grid-template-columns:76px 1fr; }
}

@media (orientation: landscape) and (max-height: 520px) {
  .preview-sticky.edit-fullscreen { padding-top: calc(4px + env(safe-area-inset-top)); padding-bottom: calc(4px + env(safe-area-inset-bottom)); }
  .preview-sticky.edit-fullscreen .preview-toolbar { margin-bottom: 4px; }
  .preview-sticky.edit-fullscreen .preview-note { display: none; }
  .preview-sticky.edit-fullscreen #headerCanvas { width: min(100%, calc((100vh - 68px) * 3)); }
}

/* v0.2 font controls */
.font-label { grid-column: 1 / -1; }
.font-label select { width: 100%; }
.font-sample { margin-top: 14px; min-height: 64px; display:flex; align-items:center; justify-content:center; padding:12px 14px; border:1px dashed var(--line); border-radius:12px; background:#f8fafc; text-align:center; font-size:1.35rem; overflow-wrap:anywhere; }
.font-hint { margin-top:8px; }
@media (min-width: 680px) { .font-label { grid-column: auto; } }


/* v0.3 fine adjust buttons */
.range-stepper {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 48px minmax(0,1fr) 48px;
  gap: 8px;
  align-items: center;
}
.range-stepper input[type=range] {
  grid-column: auto;
  min-width: 0;
}
.step-btn {
  min-height: 42px;
  min-width: 42px;
  padding: 0;
  font-size: 1.35rem;
  line-height: 1;
  border-radius: 12px;
  font-weight: 900;
}
.step-btn:active {
  transform: translateY(1px) scale(.98);
}
