:root {
  --bg: #f3f1ec;
  --panel: #fbfaf7;
  --ink: #24231f;
  --muted: #77736a;
  --line: #dedbd3;
  --accent: #294d3f;
  --accent-soft: #e3ebe7;
  --radius: 16px;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: Inter, ui-sans-serif, system-ui, -apple-system, sans-serif; }
button, input { font: inherit; }
button { cursor: pointer; }
.topbar { height: 68px; padding: 0 22px; display: flex; align-items: center; gap: 14px; border-bottom: 1px solid var(--line); background: var(--panel); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; min-width: 230px; }
.brand-mark { width: 32px; height: 32px; display: grid; place-items: center; color: white; background: var(--accent); border-radius: 10px; }
.project-name { flex: 1; color: var(--muted); text-align: center; }
.button { border: 1px solid var(--line); border-radius: 10px; padding: 9px 14px; background: var(--panel); color: var(--ink); font-weight: 650; }
.button.primary { background: var(--accent); border-color: var(--accent); color: white; }
.workspace { display: grid; grid-template-columns: 310px minmax(0, 1fr); min-height: calc(100vh - 68px); }
.sidebar { background: var(--panel); border-right: 1px solid var(--line); padding: 22px; overflow-y: auto; }
.sidebar section + section { border-top: 1px solid var(--line); margin-top: 22px; padding-top: 22px; }
.eyebrow { margin: 0 0 12px; color: var(--muted); font-size: 12px; font-weight: 750; text-transform: uppercase; letter-spacing: .09em; }
.layout-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.layout-card { border: 1px solid var(--line); border-radius: 12px; background: transparent; padding: 8px; text-align: left; color: var(--muted); }
.layout-card img { width: 100%; aspect-ratio: 16/9; display: block; object-fit: cover; border-radius: 7px; margin-bottom: 7px; }
.layout-card.active { border-color: var(--accent); background: var(--accent-soft); color: var(--ink); box-shadow: 0 0 0 1px var(--accent); }
.segmented { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--bg); padding: 3px; border-radius: 11px; }
.segmented button { border: 0; background: transparent; padding: 8px 5px; border-radius: 8px; color: var(--muted); font-size: 12px; }
.segmented button.active { background: var(--panel); color: var(--ink); box-shadow: 0 1px 5px #00000018; }
.section-heading { display: flex; justify-content: space-between; align-items: baseline; }
.text-button { border: 0; background: none; color: var(--accent); font-weight: 700; }
.material-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.material-card { position: relative; border: 1px solid transparent; border-radius: 12px; padding: 6px; background: transparent; text-align: left; }
.material-card.active { border-color: var(--accent); background: var(--accent-soft); }
.material-select { display: block; width: 100%; padding: 0; border: 0; background: transparent; color: inherit; text-align: left; }
.material-delete { position: absolute; top: 9px; right: 9px; width: 25px; height: 25px; padding: 0; border: 1px solid #ffffffaa; border-radius: 50%; background: #25231fd9; color: white; font-size: 18px; line-height: 21px; opacity: 0; transition: opacity .15s, transform .15s; }
.material-card:hover .material-delete, .material-delete:focus-visible { opacity: 1; }
.material-delete:hover { transform: scale(1.06); }
.swatch { height: 60px; border-radius: 8px; background-size: cover; background-position: center; box-shadow: inset 0 0 0 1px #00000012; }
.material-card strong { display: block; margin-top: 6px; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.material-card small { color: var(--muted); font-size: 10px; }
.stage { min-width: 0; padding: 22px 28px 20px; display: flex; flex-direction: column; }
.stage-toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.stage-toolbar strong { display: block; }
.stage-toolbar span { display: block; color: var(--muted); margin-top: 3px; font-size: 13px; }
.icon-button { border: 1px solid var(--line); border-radius: 10px; background: var(--panel); padding: 8px 12px; color: var(--muted); }
.icon-button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }
.canvas-shell { position: relative; flex: 1; min-height: 460px; display: grid; place-items: center; background: #dedbd4; border-radius: var(--radius); overflow: hidden; box-shadow: 0 14px 35px #4e483c1c; }
canvas { display: block; width: 100%; height: 100%; object-fit: contain; }
.loading { position: absolute; background: #ffffffd9; padding: 10px 14px; border-radius: 10px; }
.hint { color: var(--muted); text-align: center; font-size: 12px; padding-top: 12px; }
dialog { border: 0; border-radius: 16px; padding: 0; box-shadow: 0 25px 80px #0004; }
dialog::backdrop { background: #15171288; backdrop-filter: blur(3px); }
dialog form { min-width: min(420px, calc(100vw - 32px)); padding: 24px; }
dialog h2 { margin: 0 0 20px; }
dialog label { display: block; color: var(--muted); font-size: 13px; margin-top: 14px; }
dialog input { width: 100%; padding: 10px 11px; margin-top: 6px; border: 1px solid var(--line); border-radius: 9px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 22px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; background: var(--ink); color: white; padding: 10px 14px; border-radius: 10px; pointer-events: none; transition: .2s; }
.toast.show { transform: translate(-50%, 0); opacity: 1; }
@media (max-width: 820px) {
  .topbar { height: auto; min-height: 62px; padding: 12px 14px; }
  .brand { min-width: 0; margin-right: auto; }
  .project-name, #saveProject { display: none; }
  .workspace { grid-template-columns: 1fr; }
  .stage { order: 1; padding: 14px; }
  .sidebar { order: 2; border-right: 0; border-top: 1px solid var(--line); padding: 16px; }
  .canvas-shell { min-height: 280px; aspect-ratio: 16/10; }
  .layout-grid { grid-template-columns: repeat(4, 1fr); }
  .layout-card span { display: none; }
  .material-grid { grid-template-columns: repeat(4, 1fr); }
  .material-delete { opacity: 1; }
}
@media (max-width: 520px) {
  .brand > span:last-child { display: none; }
  .button { padding: 8px 10px; }
  .stage-toolbar { align-items: flex-end; }
  .icon-button { font-size: 12px; }
  .canvas-shell { min-height: 220px; }
  .layout-grid, .material-grid { grid-template-columns: repeat(2, 1fr); }
}
