:root {
  color-scheme: dark;
  --bg: #17151f;
  --panel: #211e2b;
  --panel-2: #292536;
  --line: #3b354a;
  --muted: #8e879c;
  --text: #f6f1ff;
  --accent: #ff5c7a;
  --purple: #9d7bff;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; min-height: 100vh; background: var(--bg); color: var(--text); }
button, input { font: inherit; }
button { color: inherit; }

.app-shell { min-height: 100vh; display: grid; grid-template-rows: 72px 1fr 38px; }
.topbar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: 0 28px; border-bottom: 1px solid var(--line); background: rgba(24, 21, 32, .96); }
.brand { display: inline-flex; align-items: center; gap: 12px; width: max-content; color: var(--text); text-decoration: none; font-weight: 900; letter-spacing: .14em; font-size: 18px; }
.brand-mark { width: 28px; height: 28px; display: grid; grid-template-columns: repeat(2, 1fr); gap: 2px; transform: rotate(4deg); }
.brand-mark i { display: block; background: var(--accent); }
.brand-mark i:nth-child(2), .brand-mark i:nth-child(3) { background: var(--purple); }
.history-actions { display: flex; gap: 6px; }
.icon-button, .zoom-button { display: grid; place-items: center; border: 1px solid var(--line); background: var(--panel); border-radius: 8px; cursor: pointer; }
.icon-button { width: 38px; height: 38px; }
.icon-button svg, .export-button svg, .tool svg { width: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: square; stroke-linejoin: miter; }
button:disabled { opacity: .3; cursor: default; }
button:not(:disabled):hover { border-color: #625875; background-color: #302b3d; }
.export-button { justify-self: end; display: flex; align-items: center; gap: 9px; padding: 11px 16px; border: 0; border-radius: 7px; background: var(--accent); color: #20161c; font-size: 12px; font-weight: 900; letter-spacing: .08em; cursor: pointer; box-shadow: 0 5px 20px rgba(255, 92, 122, .18); }
.export-button:hover { background: #ff738d !important; }

.workspace { display: grid; grid-template-columns: 216px minmax(400px, 1fr) 190px; gap: 22px; padding: 22px; min-height: 0; }
.panel { border: 1px solid var(--line); border-radius: 10px; background: var(--panel); align-self: start; overflow: hidden; }
.panel-heading { height: 42px; padding: 0 14px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 10px; font-weight: 800; letter-spacing: .15em; }
.key-hint { opacity: .6; }
.tool-list { padding: 10px; display: grid; gap: 6px; }
.tool { height: 44px; padding: 0 10px; border: 1px solid transparent; border-radius: 7px; display: grid; grid-template-columns: 27px 1fr auto; align-items: center; text-align: left; background: transparent; cursor: pointer; color: #bbb4c8; }
.tool span { font-size: 13px; font-weight: 700; }
.tool kbd { font-family: inherit; font-size: 10px; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 2px 6px; background: #191720; }
.tool.active { border-color: rgba(255,92,122,.42); color: var(--text); background: rgba(255,92,122,.1); }
.tool.active svg { color: var(--accent); }
.section-label { margin: 6px 14px 9px; color: var(--muted); font-size: 10px; font-weight: 800; letter-spacing: .14em; }
.brush-sizes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; padding: 0 10px 18px; }
.brush-size { height: 54px; display: grid; place-items: center; align-content: center; gap: 5px; border: 1px solid var(--line); border-radius: 7px; background: #1b1924; cursor: pointer; }
.brush-size small { color: var(--muted); font-size: 9px; }
.brush-size.active { border-color: var(--purple); background: rgba(157,123,255,.1); }
.dot { background: currentColor; display: block; }
.dot-1 { width: 5px; height: 5px; }.dot-2 { width: 9px; height: 9px; }.dot-3 { width: 13px; height: 13px; }
.color-field { margin: 0 10px 10px; padding: 9px; display: grid; grid-template-columns: 38px 1fr; gap: 9px; align-items: center; border: 1px solid var(--line); border-radius: 7px; position: relative; }
.color-preview { width: 38px; height: 38px; border: 0; border-radius: 5px; background: var(--accent); cursor: pointer; }
.color-field span { display: block; color: var(--muted); font-size: 8px; font-weight: 800; letter-spacing: .12em; }
.color-field strong { font-size: 12px; letter-spacing: .06em; }
#colorInput { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.palette { padding: 0 10px 14px; display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.swatch { aspect-ratio: 1; border: 2px solid #211e2b; border-radius: 5px; cursor: pointer; box-shadow: 0 0 0 1px var(--line); }
.swatch.active { box-shadow: 0 0 0 2px var(--text); }

.canvas-area { min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; overflow: hidden; }
.canvas-meta { width: min(100%, 620px); display: flex; justify-content: space-between; margin-bottom: 9px; color: var(--muted); font-size: 9px; font-weight: 800; letter-spacing: .12em; }
.canvas-meta b { color: #cfc8dc; }
.canvas-stage { width: min(100%, 620px); min-height: 300px; max-height: calc(100vh - 230px); overflow: auto; padding: 22px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 10px; background-color: #1d1a26; background-image: linear-gradient(rgba(255,255,255,.018) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.018) 1px, transparent 1px); background-size: 16px 16px; box-shadow: inset 0 0 45px rgba(0,0,0,.2); }
#editorCanvas { display: block; width: 512px; height: 512px; max-width: none; cursor: crosshair; touch-action: none; box-shadow: 0 14px 50px rgba(0,0,0,.38); image-rendering: pixelated; }
.zoom-controls { margin-top: 13px; display: flex; align-items: center; gap: 10px; }
.zoom-button { width: 28px; height: 28px; font-size: 17px; }
#zoomSlider { width: 140px; accent-color: var(--accent); }
#zoomValue { width: 48px; color: var(--muted); font-size: 10px; font-weight: 800; }

.preview-panel { padding-bottom: 12px; }
.preview-box { margin: 14px; aspect-ratio: 1; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 7px; background-color: #dedce1; background-image: linear-gradient(45deg,#c6c3ca 25%,transparent 25%),linear-gradient(-45deg,#c6c3ca 25%,transparent 25%),linear-gradient(45deg,transparent 75%,#c6c3ca 75%),linear-gradient(-45deg,transparent 75%,#c6c3ca 75%); background-size: 12px 12px; background-position: 0 0,0 6px,6px -6px,-6px 0; overflow: hidden; }
#previewCanvas { width: 100%; height: 100%; image-rendering: pixelated; }
.tip { display: flex; gap: 8px; margin: 4px 14px 14px; color: var(--muted); font-size: 9px; line-height: 1.55; }
.tip span { color: var(--purple); font-size: 13px; }.tip p { margin: 0; }.tip b { color: #c5bdd2; letter-spacing: .1em; }
.clear-button { display: block; width: calc(100% - 28px); margin: 0 14px; padding: 9px; border: 1px solid var(--line); border-radius: 6px; background: transparent; color: var(--muted); font-size: 10px; font-weight: 800; letter-spacing: .08em; cursor: pointer; }

footer { display: flex; align-items: center; justify-content: space-between; padding: 0 28px; border-top: 1px solid var(--line); color: #6f687c; font-size: 9px; font-weight: 800; letter-spacing: .13em; }
.status { display: flex; align-items: center; gap: 7px; }.status i { width: 5px; height: 5px; border-radius: 50%; background: #62d49d; box-shadow: 0 0 7px #62d49d; }
.toast { position: fixed; left: 50%; bottom: 56px; transform: translate(-50%, 20px); padding: 10px 16px; border-radius: 7px; background: #f6f1ff; color: #211e2b; font-size: 12px; font-weight: 800; opacity: 0; pointer-events: none; transition: .2s ease; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
:focus-visible { outline: 2px solid var(--purple); outline-offset: 2px; }

@media (max-width: 860px) {
  .workspace { grid-template-columns: 190px 1fr; }
  .preview-panel { display: none; }
}
@media (max-width: 620px) {
  .app-shell { grid-template-rows: 62px auto 34px; }
  .topbar { padding: 0 14px; grid-template-columns: 1fr auto; }.history-actions { display: none; }.export-button { padding: 10px 12px; }
  .workspace { display: flex; flex-direction: column; padding: 12px; gap: 12px; }
  .tools-panel { width: 100%; }.panel-heading { display: none; }.tool-list { grid-template-columns: 1fr 1fr; }.section-label { margin-top: 8px; }
  .brush-sizes { float: left; width: 48%; }.color-field { margin-left: 50%; }.palette { margin-left: 50%; grid-template-columns: repeat(5, 1fr); }
  .canvas-area { overflow: visible; }.canvas-stage { min-height: 330px; max-height: 430px; padding: 14px; }
  footer { padding: 0 14px; } footer > span:first-child, footer > span:last-child { display: none; }
}
