:root {
  --desk: #e8e2d6;
  --panel: #ffffff;
  --ink: #2b2b2b;
  --muted: #7a746a;
  --hover: #f4f1ea;
  --accent: #3b62d9;
  --accent-bg: #edf1ff;
  --accent-line: #c7d3fb;
  --paper: #ffffff;
  --current: #1f1f1f;
}

* { box-sizing: border-box; }

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

body {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--desk);
  color: var(--ink);
  font-family: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

/* ── 도구 막대 ─────────────────────────────── */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 22px;
  margin: 12px 16px 0;
  padding: 8px 12px;
  background: var(--panel);
  border-radius: 14px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 4px 16px rgba(0, 0, 0, .06);
}

.group {
  display: flex;
  align-items: center;
  gap: 6px;
}

button { font: inherit; }

.tool {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 5px 10px 4px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: none;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
}
.tool svg { width: 28px; height: 28px; overflow: visible; }
.tool .tip { fill: var(--current); }
.tool:hover { background: var(--hover); }
.tool.active {
  background: var(--accent-bg);
  border-color: var(--accent-line);
  color: var(--accent);
  font-weight: 600;
}

.palette { flex-wrap: wrap; gap: 7px; }

.swatch {
  position: relative;
  width: 26px;
  height: 26px;
  padding: 0;
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .18);
  cursor: pointer;
  transition: transform .1s;
}
.swatch:hover { transform: scale(1.12); }
.swatch.active { box-shadow: 0 0 0 2px var(--ink); transform: scale(1.12); }

.swatch.custom {
  overflow: hidden;
  background: conic-gradient(#f44336, #ffeb3b, #4caf50, #00bcd4, #3f51b5, #e91e63, #f44336);
}
.swatch.custom input {
  position: absolute;
  inset: -4px;
  width: calc(100% + 8px);
  height: calc(100% + 8px);
  opacity: 0;
  cursor: pointer;
}

.size input[type="range"] {
  width: 120px;
  accent-color: var(--ink);
}
.size-preview {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
}
#sizeDot {
  border-radius: 50%;
  background: var(--current);
}
#sizeDot.marker { opacity: .45; }
#sizeDot.eraser { background: #fff; box-shadow: inset 0 0 0 1.5px #9a9388; }
.size output {
  min-width: 2.5ch;
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.actions { margin-left: auto; gap: 2px; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: none;
  border-radius: 10px;
  background: none;
  color: var(--ink);
  cursor: pointer;
}
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn:hover:not(:disabled) { background: var(--hover); }
.icon-btn:disabled { opacity: .28; cursor: default; }

.tool:focus-visible, .icon-btn:focus-visible, .swatch:focus-visible, .swatch:focus-within {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ── 스케치북 ─────────────────────────────── */
.desk {
  display: flex;
  flex: 1;
  min-height: 0;
  padding: 30px 16px 16px;
}

.sketchbook {
  position: relative;
  display: flex;
  flex: 1;
  min-width: 0;
}

.page {
  position: relative;
  flex: 1;
  overflow: hidden;
  background: var(--paper);
  border-radius: 4px 4px 6px 6px;
  box-shadow:
    0 2px 0 #dcd5c6,
    0 4px 0 #cfc7b6,
    0 14px 30px rgba(70, 50, 20, .16);
  touch-action: none;
  cursor: crosshair;
}
.page.show-cursor { cursor: none; }

.page canvas {
  position: absolute;
  top: 0;
  left: 0;
}
#live { pointer-events: none; }

/* 스프링과 구멍 — 둘 다 32px 간격으로 맞춰져 있다 */
.rings, .holes {
  position: absolute;
  left: 28px;
  right: 28px;
  pointer-events: none;
  background-repeat: repeat-x;
  background-position: center 0;
}
.rings {
  top: -18px;
  z-index: 2;
  height: 30px;
  background-image: radial-gradient(ellipse 3.5px 14px at 50% 15px, #9ba1aa 0 85%, transparent 100%);
  background-size: 32px 30px;
}
.holes {
  top: 0;
  height: 20px;
  background-image: radial-gradient(circle 4.5px at 50% 12px, #d8d1c3 0 85%, transparent 100%);
  background-size: 32px 20px;
}

.brush-cursor {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 3;
  display: none;
  border: 1px solid rgba(0, 0, 0, .65);
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, .85);
  pointer-events: none;
}
.page.show-cursor .brush-cursor { display: block; }

@media (max-width: 640px) {
  .toolbar { margin: 8px 8px 0; gap: 8px 14px; }
  .desk { padding: 26px 8px 8px; }
  .actions { margin-left: 0; }
  .size input[type="range"] { width: 100px; }
}
