:root {
  --bg: #f6f5f2;
  --panel: #ffffff;
  --ink: #1c1c1c;
  --accent: #5b4bff;
  --accent-dark: #4638d1;
  --danger: #d1453b;
  --border: #ddd8ce;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--ink);
}

.topbar {
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  padding: 1.25rem 2rem 0;
}

.topbar h1 {
  margin: 0;
  font-size: 1.8rem;
}

.tagline {
  margin: 0.25rem 0 1rem;
  color: #555;
}

.tabs {
  display: flex;
  gap: 0.5rem;
}

.tab-btn {
  border: none;
  background: transparent;
  padding: 0.75rem 1.1rem;
  font-size: 1rem;
  cursor: pointer;
  border-bottom: 3px solid transparent;
  color: #555;
}

.tab-btn.active {
  border-bottom-color: var(--accent);
  color: var(--ink);
  font-weight: 600;
}

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem 2rem 3rem;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.hint {
  color: #777;
  font-size: 0.9rem;
}

.glyphs-layout {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 2rem;
  align-items: start;
}

.glyph-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(48px, 1fr));
  gap: 6px;
  max-height: 60vh;
  overflow-y: auto;
  padding: 4px;
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: 8px;
}

.glyph-cell {
  width: 48px;
  height: 48px;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.1rem;
  position: relative;
  overflow: hidden;
}

.glyph-cell.selected {
  outline: 2px solid var(--accent);
}

.glyph-cell.filled {
  border-style: solid;
}

.glyph-cell img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.glyph-cell .char-label {
  position: absolute;
  bottom: 1px;
  right: 3px;
  font-size: 0.55rem;
  color: #999;
  pointer-events: none;
}

.editor-wrap {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
}

.canvas-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  margin-bottom: 0.5rem;
  font-size: 0.85rem;
}

.canvas-toolbar label {
  display: flex;
  flex-direction: column;
  font-size: 0.75rem;
  color: #555;
  gap: 2px;
}

.tool-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  width: 100%;
}

.tool-btn {
  padding: 0.4rem 0.65rem;
  font-size: 0.8rem;
}

.tool-btn.active {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}

.canvas-stage {
  position: relative;
  width: 100%;
  max-width: 300px;
  aspect-ratio: 1 / 1;
  border: 1px dashed var(--border);
  background: #fff;
  border-radius: 4px;
}

.canvas-stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

#drawCanvas {
  touch-action: none;
  cursor: crosshair;
}

#guideCanvas {
  pointer-events: none;
}

.guide-hint {
  max-width: 300px;
  margin: 0.4rem 0 0;
  font-size: 0.78rem;
  line-height: 1.35;
}

.check {
  display: inline-flex !important;
  flex-direction: row !important;
  align-items: center;
  gap: 4px !important;
  font-size: 0.78rem;
  color: #555;
  cursor: pointer;
}

.check input {
  margin: 0;
}

.editor-actions, .export-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-top: 0.75rem;
}

.upload-label {
  font-size: 0.8rem;
  color: #555;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

button {
  border: 1px solid var(--border);
  background: #fff;
  padding: 0.5rem 0.9rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
}

button:hover { background: #f0eee8; }

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

button.primary:hover { background: var(--accent-dark); }

button.danger {
  color: var(--danger);
  border-color: var(--danger);
}

.export-all {
  margin-top: 1.25rem;
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex-wrap: wrap;
}

.export-all label {
  font-size: 0.8rem;
  color: #555;
}

.export-all-sep {
  width: 1px;
  align-self: stretch;
  background: var(--border);
  margin: 0 0.25rem;
}

.export-font {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex-wrap: wrap;
}

.export-font label {
  font-size: 0.8rem;
  color: #555;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.export-font input {
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.9rem;
  min-width: 200px;
}

.export-font .hint {
  flex-basis: 100%;
  margin: 0.25rem 0 0;
}

#testerInput {
  width: 100%;
  font-size: 1rem;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  resize: vertical;
}

.tester-controls {
  display: flex;
  gap: 1.5rem;
  margin: 0.75rem 0;
  font-size: 0.85rem;
}

.tester-controls label {
  display: flex;
  flex-direction: column;
  gap: 2px;
  color: #555;
}

#testerCanvas {
  width: 100%;
  border: 1px solid var(--border);
  background: #fffdf3;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.project-row {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.project-row input {
  flex: 1;
  min-width: 200px;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.project-list {
  list-style: none;
  padding: 0;
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.project-list li {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.3rem 0.8rem;
  font-size: 0.85rem;
  cursor: pointer;
}

.project-list li:hover {
  border-color: var(--accent);
}

@media (max-width: 800px) {
  .glyphs-layout {
    grid-template-columns: 1fr;
  }
}
