:root {
  --ink: #171715;
  --muted: #74736d;
  --line: #d9d8d0;
  --paper: #f5f4ee;
  --panel: #fbfaf6;
  --accent: #ff5c35;
  --accent-soft: #ffe4dc;
  --shadow: 0 18px 50px rgba(32, 31, 27, .12);
  font-family: Inter, "Segoe UI", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: var(--paper);
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 1080px; min-height: 100vh; overflow: hidden; }
button, input { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.app-shell { height: 100vh; display: grid; grid-template-rows: 66px 1fr; }
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 0 22px; border-bottom: 1px solid var(--line); background: rgba(251,250,246,.94); backdrop-filter: blur(12px); z-index: 10; }
.brand { display: grid; grid-template-columns: 34px auto; grid-template-rows: 22px 14px; column-gap: 10px; color: inherit; text-decoration: none; letter-spacing: .08em; }
.brand > span:nth-child(2) { font-size: 17px; font-weight: 700; }
.brand small { grid-column: 2; color: var(--muted); font: 500 9px/1 "Cascadia Mono", Consolas, monospace; letter-spacing: .14em; }
.brand-mark { grid-row: 1 / 3; width: 34px; height: 34px; display: grid; grid-template: 1fr 1fr / 1fr 1fr; gap: 2px; transform: rotate(45deg) scale(.72); }
.brand-mark i { display: block; background: var(--ink); }
.brand-mark i:nth-child(2), .brand-mark i:nth-child(3) { background: var(--accent); }
.top-actions { display: flex; gap: 8px; align-items: center; }

.button { min-height: 36px; border: 1px solid var(--line); padding: 0 14px; background: var(--panel); font-size: 12px; font-weight: 600; cursor: pointer; transition: transform .15s, border-color .15s, background .15s; }
.button:hover { transform: translateY(-1px); border-color: #aaa89f; }
.button.primary { color: #8b260d; border-color: #ffb19d; background: var(--accent-soft); }
.button.dark { color: #fff; border-color: var(--ink); background: var(--ink); }
.button.danger { color: #a32913; background: #fff1ed; border-color: #f2c7bc; }
.file-button { display: inline-flex; align-items: center; cursor: pointer; }
.file-button input { display: none; }

.workspace { min-height: 0; display: grid; grid-template-columns: 260px minmax(560px, 1fr) 274px; }
.sidebar { min-height: 0; overflow: auto; background: var(--panel); scrollbar-width: thin; }
.left-panel { border-right: 1px solid var(--line); }
.right-panel { border-left: 1px solid var(--line); }
.panel-section { padding: 20px 18px; border-bottom: 1px solid var(--line); }
.section-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; text-transform: uppercase; font: 600 11px/1 "Cascadia Mono", Consolas, monospace; letter-spacing: .11em; }
.section-index { color: #aaa8a0; font-size: 9px; }
.field-grid { display: grid; gap: 12px 10px; }
.two-columns { grid-template-columns: 1fr 1fr; }
.full { grid-column: 1 / -1; }
.field { display: grid; gap: 7px; min-width: 0; color: var(--muted); font-size: 10px; font-weight: 600; letter-spacing: .04em; }
.field-row { display: flex; margin-top: 12px; }
.grow { flex: 1; }
.field input[type="number"], .field input[type="text"] { width: 100%; height: 34px; padding: 0 9px; color: var(--ink); border: 1px solid var(--line); background: #fff; font: 500 12px "Cascadia Mono", Consolas, monospace; }
.input-unit { position: relative; }
.input-unit input { padding-right: 30px !important; }
.input-unit em { position: absolute; right: 9px; top: 50%; transform: translateY(-50%); color: #aaa8a0; font: normal 9px "Cascadia Mono", Consolas, monospace; pointer-events: none; }
.color-control { height: 36px; display: flex; align-items: center; padding: 4px 9px 4px 4px; border: 1px solid var(--line); background: #fff; }
.color-control input { width: 30px; height: 26px; padding: 0; border: 0; background: transparent; cursor: pointer; }
.color-control output { margin-left: 9px; color: var(--ink); font: 500 11px "Cascadia Mono", Consolas, monospace; }
.check-row { display: flex; gap: 8px; align-items: center; margin-top: 12px; color: var(--muted); font-size: 11px; cursor: pointer; }
.check-row input { accent-color: var(--accent); }
.preset-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; margin-top: 14px; }
.preset-row button { height: 28px; border: 1px solid var(--line); background: transparent; color: var(--muted); font: 500 10px "Cascadia Mono", Consolas, monospace; cursor: pointer; }
.preset-row button.active { border-color: var(--ink); color: var(--ink); background: #fff; }

.layers-section { min-height: 210px; }
.empty-layers { padding: 22px 12px; border: 1px dashed #c9c7bf; text-align: center; color: var(--muted); }
.empty-layers .empty-icon { display: block; margin-bottom: 8px; color: var(--accent); font-size: 24px; font-weight: 300; }
.empty-layers strong { display: block; color: var(--ink); font-size: 11px; }
.empty-layers p { margin: 6px auto 0; max-width: 170px; font-size: 9px; line-height: 1.5; }
.layer-list { display: grid; gap: 5px; }
.layer-item { display: grid; grid-template-columns: 28px 1fr 26px; align-items: center; gap: 8px; min-height: 42px; padding: 5px 6px; border: 1px solid transparent; background: #f4f3ed; cursor: pointer; }
.layer-item:hover { border-color: #ceccc4; }
.layer-item.selected { border-color: var(--ink); background: #fff; }
.layer-thumb { width: 28px; height: 28px; display: grid; place-items: center; overflow: hidden; background-image: linear-gradient(45deg,#eee 25%,transparent 25%),linear-gradient(-45deg,#eee 25%,transparent 25%),linear-gradient(45deg,transparent 75%,#eee 75%),linear-gradient(-45deg,transparent 75%,#eee 75%); background-size: 8px 8px; background-position: 0 0,0 4px,4px -4px,-4px 0; }
.layer-thumb img { width: 85%; height: 85%; object-fit: contain; }
.layer-copy { border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 16px; }
.layer-copy:hover { color: var(--accent); }
.layer-item strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 10px; font-weight: 600; }
.shortcuts { display: grid; gap: 9px; margin: 0; }
.shortcuts div { display: flex; justify-content: space-between; font-size: 9px; }
.shortcuts dt { color: var(--muted); }
.shortcuts dd { margin: 0; font: 500 9px "Cascadia Mono", Consolas, monospace; }

.stage-column { min-width: 0; min-height: 0; display: grid; grid-template-rows: 48px minmax(0, 1fr) 112px; background: #e8e7e0; }
.stage-toolbar { display: flex; align-items: center; justify-content: space-between; padding: 0 16px; border-bottom: 1px solid #cecdc6; background: #efeee8; }
.stage-toolbar > div:first-child { display: flex; gap: 12px; align-items: baseline; }
.stage-toolbar strong { font-size: 11px; }
.stage-toolbar span { color: var(--muted); font: 500 9px "Cascadia Mono", Consolas, monospace; }
.zoom-controls { display: flex; align-items: center; height: 28px; border: 1px solid #d3d1ca; background: var(--panel); }
.zoom-controls button { height: 100%; min-width: 28px; padding: 0 8px; border: 0; border-right: 1px solid #dddcd5; background: transparent; cursor: pointer; font-size: 12px; }
.zoom-controls button:last-child { border: 0; font-size: 9px; }
.zoom-controls output { min-width: 48px; text-align: center; color: var(--muted); font: 500 9px "Cascadia Mono", Consolas, monospace; }
.stage-scroller { position: relative; min-height: 0; display: grid; place-items: center; overflow: auto; padding: 56px; background-image: radial-gradient(#c4c2ba 1px, transparent 1px); background-size: 18px 18px; }
.canvas-frame { position: relative; flex: none; width: 600px; height: 600px; background: #fff; box-shadow: var(--shadow), 0 0 0 1px rgba(30,29,25,.16); transform-origin: center; }
#editorCanvas { display: block; width: 100%; height: 100%; overflow: visible; user-select: none; touch-action: none; }
#artworkLayer .texture-item { cursor: move; }
.selection-outline { fill: none; stroke: var(--accent); stroke-width: 1.5; vector-effect: non-scaling-stroke; stroke-dasharray: 5 3; pointer-events: none; }
.selection-handle { fill: #fff; stroke: var(--accent); stroke-width: 1.5; vector-effect: non-scaling-stroke; cursor: nwse-resize; }
.rotation-stem { stroke: var(--accent); stroke-width: 1.5; vector-effect: non-scaling-stroke; pointer-events: none; }
.rotation-handle { fill: var(--accent); stroke: #fff; stroke-width: 2; vector-effect: non-scaling-stroke; cursor: grab; }
.empty-canvas { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; pointer-events: none; text-align: center; color: var(--muted); }
.empty-canvas strong { margin-top: 14px; color: var(--ink); font-size: 15px; }
.empty-canvas p { margin: 6px 0 0; font-size: 10px; }
.upload-glyph { width: 56px; height: 56px; display: grid; place-items: center; border: 1px dashed #a9a69d; border-radius: 50%; color: var(--accent); font-size: 28px; }
.drop-hint { position: absolute; inset: 18px; z-index: 5; display: none; place-items: center; border: 2px dashed var(--accent); background: rgba(255,228,220,.88); color: #8b260d; font-size: 13px; font-weight: 700; pointer-events: none; }
.stage-scroller.dragging .drop-hint { display: grid; }
.preview-strip { display: grid; grid-template-columns: 150px 1fr; align-items: center; gap: 14px; padding: 12px 16px; border-top: 1px solid #cecdc6; background: #efeee8; }
.preview-strip > div:first-child strong { display: block; font-size: 11px; }
.preview-strip > div:first-child span { display: block; margin-top: 5px; color: var(--muted); font-size: 9px; line-height: 1.4; }
.tile-preview { height: 86px; border: 1px solid #c7c5bd; background-color: #fff; background-position: center; box-shadow: inset 0 0 0 1px rgba(255,255,255,.6); }

.no-selection { min-height: 260px; display: grid; place-content: center; padding: 30px; text-align: center; }
.no-selection span { font-size: 12px; font-weight: 600; }
.no-selection p { max-width: 170px; margin: 7px auto; color: var(--muted); font-size: 10px; line-height: 1.5; }
.range-field { display: grid; gap: 10px; margin-top: 15px; }
.range-field > span { display: flex; justify-content: space-between; color: var(--muted); font-size: 10px; }
.range-field b { font-weight: 600; }
.range-field output { color: var(--ink); font: 500 9px "Cascadia Mono", Consolas, monospace; }
input[type="range"] { width: 100%; height: 3px; accent-color: var(--accent); cursor: pointer; }
.switch { display: inline-flex; }
.switch input { position: absolute; opacity: 0; }
.switch span { position: relative; width: 30px; height: 17px; border-radius: 20px; background: #d3d1ca; cursor: pointer; transition: .2s; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 11px; height: 11px; border-radius: 50%; background: #fff; transition: .2s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(13px); }
.effect-controls { transition: opacity .2s; }
.effect-controls.disabled { opacity: .38; pointer-events: none; }
.action-section { padding-bottom: 30px; }
.button-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }

.toast { position: fixed; left: 50%; bottom: 24px; z-index: 30; padding: 11px 16px; color: #fff; background: var(--ink); box-shadow: 0 8px 25px rgba(0,0,0,.2); font-size: 11px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none; transition: .22s; }
.toast.show { transform: translate(-50%, 0); opacity: 1; }

@media (max-width: 1250px) {
  .workspace { grid-template-columns: 230px minmax(500px, 1fr) 250px; }
  .top-actions .ghost:first-child { display: none; }
}
