:root {
  color-scheme: light;
  --ink: #241f1b;
  --muted: #6d645b;
  --paper: #f6f1e6;
  --page: #ebe4d8;
  --panel: #fbf8f3;
  --line: #e3dbce;
  --accent: #1f4b3a;
  --accent-ink: #f7f4ee;
  --baseline: #a33b32;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  font-family: "Segoe UI", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: var(--page);
}

button, input, textarea {
  font: inherit;
  color: inherit;
}

.app {
  height: 100%;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px 18px;
  padding: 12px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.brand h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 650;
  letter-spacing: 0.01em;
}

.brand p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.field {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
}

.field select,
.field input[type="text"] {
  width: 140px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
}

.field select { width: auto; }

.field input[type="range"] {
  width: 110px;
  accent-color: var(--accent);
}

.field b {
  min-width: 1.6em;
  color: var(--ink);
  font-weight: 600;
}

.modes {
  display: flex;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f3eee4;
}

.modes button {
  border: 0;
  background: transparent;
  border-radius: 999px;
  padding: 6px 14px;
  cursor: pointer;
}

.modes button.is-on {
  background: var(--ink);
  color: var(--paper);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-left: auto;
}

.actions button {
  border: 1px solid var(--line);
  background: white;
  border-radius: 6px;
  padding: 7px 10px;
  cursor: pointer;
}

.actions button:hover { border-color: #c9bfb0; }

#export {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}

#edit.is-on {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}

#pad.is-editing { cursor: default; }

.workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 232px minmax(0, 1fr) 320px;
}

.palette {
  overflow: auto;
  padding: 12px;
  border-right: 1px solid var(--line);
  background: var(--panel);
}

.palette h2 {
  margin: 12px 0 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.palette h2:first-child { margin-top: 0; }

.grid {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.cell {
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 5px;
  background: transparent;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 16px;
  cursor: pointer;
}

.cell:hover { background: #efe8dc; }

.cell.is-done {
  background: #e7efe9;
}

.cell-stroke { min-width: 4.2em; }
.cell-part { font-family: "Microsoft YaHei", "PingFang SC", sans-serif; }
.cell.is-on {
  border-color: var(--accent);
  background: #dce8e1;
}

.stage {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 12px;
  gap: 8px;
}

.stage-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 28px;
}

#photo {
  margin-left: auto;
  flex: none;
  border: 1px solid var(--line);
  background: white;
  border-radius: 6px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 13px;
}

#photo:hover { border-color: #c9bfb0; }

#current-label {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 28px;
  line-height: 1;
  min-width: 1ch;
}

#stage-hint {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.canvas-wrap {
  flex: 1;
  min-height: 280px;
  border: 1px solid #e4dccf;
  border-radius: 8px;
  overflow: hidden;
}

#pad {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: crosshair;
  background: var(--paper);
}

.preview {
  min-height: 0;
  overflow: auto;
  padding: 14px 14px 18px;
  border-left: 1px solid var(--line);
  background: var(--panel);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.preview h2 {
  margin: 0;
  font-size: 14px;
}

#sample {
  width: 100%;
  min-height: 220px;
  resize: vertical;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  line-height: 1.45;
  font-size: 30px;
}

#status {
  margin: 0;
  font-size: 13px;
  line-height: 1.5;
}

.note {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
}

.source-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.source-row button {
  border: 1px solid var(--line);
  background: white;
  border-radius: 6px;
  padding: 7px 10px;
  cursor: pointer;
}

.source-row button:hover { border-color: #c9bfb0; }

#reset {
  align-self: flex-start;
  border: none;
  background: transparent;
  color: var(--baseline);
  padding: 0;
  cursor: pointer;
  font-size: 12px;
}

@media (max-width: 980px) {
  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(360px, 1fr) auto;
    overflow: auto;
  }

  .palette {
    border-right: none;
    border-bottom: 1px solid var(--line);
    max-height: 180px;
  }

  .preview {
    border-left: none;
    border-top: 1px solid var(--line);
  }

  .actions { margin-left: 0; }
}
