:root {
  --bg: #f4f4f6;
  --panel: #ffffff;
  --text: #1d1d22;
  --muted: #6b6b76;
  --border: #dcdce2;
  --accent: #5b5bf0;
  --accent-text: #ffffff;
  --checker-a: #ffffff;
  --checker-b: #e3e3e8;
  --stage: #e9e9ee;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17171b;
    --panel: #212127;
    --text: #ececf1;
    --muted: #9a9aa6;
    --border: #34343c;
    --accent: #7c7cff;
    --checker-a: #3a3a42;
    --checker-b: #2e2e35;
    --stage: #121215;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", "Malgun Gothic", sans-serif;
  display: flex;
  flex-direction: column;
}
.muted { color: var(--muted); }

button, select, input[type=number] {
  font: inherit;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 10px;
  cursor: pointer;
}
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
button.toggle.on { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
button.link { border: none; background: none; color: var(--muted); padding: 2px 0; font-size: 12px; text-decoration: underline; }
input[type=number] { width: 64px; cursor: text; }

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  padding: 8px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.logo { font-size: 18px; margin: 0 8px 0 0; }
.group { display: flex; align-items: center; gap: 6px; }

.layout { flex: 1; display: flex; min-height: 0; }
.sidebar {
  width: 220px;
  flex-shrink: 0;
  padding: 12px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
}
.sidebar section { margin-bottom: 18px; }
.sidebar h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 0 0 8px; }
.row { display: flex; align-items: center; gap: 8px; margin: 8px 0; }
.row input[type=range] { flex: 1; min-width: 0; }

.tools { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.tool { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 4px; font-size: 18px; }
.tool span { font-size: 12px; }
.tool.active { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }

#colorInput { width: 40px; height: 32px; padding: 0; border: 1px solid var(--border); border-radius: 6px; background: none; }
.palette { display: grid; grid-template-columns: repeat(8, 1fr); gap: 3px; }
.swatch {
  aspect-ratio: 1;
  border-radius: 3px;
  border: 1px solid var(--border);
  padding: 0;
  cursor: pointer;
}
.swatch.active { outline: 2px solid var(--accent); outline-offset: 1px; }
.hint { font-size: 12px; }

.stage {
  flex: 1;
  position: relative;
  overflow: hidden;
  min-width: 0;
  min-height: 0;
  background: var(--stage);
}
#view {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: crosshair;
}
#zoomLabel { cursor: pointer; min-width: 3em; text-align: center; }
.lang { margin-left: auto; }

.status {
  display: flex;
  gap: 16px;
  padding: 4px 16px;
  font-size: 12px;
  background: var(--panel);
  border-top: 1px solid var(--border);
}

dialog {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
  padding: 0;
  width: min(640px, calc(100vw - 32px));
}
dialog::backdrop { background: rgba(0,0,0,.45); }
.dialog { padding: 16px 20px; }
.dialog h2 { margin: 0 0 12px; font-size: 16px; }
.previews { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.previews figure { margin: 0; text-align: center; }
.previews img, .previews canvas {
  width: 100%;
  aspect-ratio: 1;
  object-fit: contain;
  background: var(--stage);
  border-radius: 6px;
  image-rendering: pixelated;
}
figcaption { font-size: 12px; color: var(--muted); margin-top: 4px; }
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }

@media (max-width: 720px) {
  .layout { flex-direction: column; }
  .sidebar { width: auto; border-right: none; border-bottom: 1px solid var(--border); max-height: 40vh; }
  .stage { min-height: 50vh; }
  .lang { margin-left: 0; }
  .palette { grid-template-columns: repeat(12, 1fr); }
}
