:root {
  --bg: #17191d;
  --panel: #24272e;
  --btn: #343842;
  --line: #3c414b;
  --text: #e9ebef;
  --muted: #9aa1ae;
  --accent: #4c8dff;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  display: flex;
  font-family: system-ui, "Segoe UI", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

/* ── 왼쪽 도구 모음 ── */
.toolbar {
  flex: 0 0 auto;
  width: 152px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px 10px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  overflow-y: auto;
}

.toolbar__title {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .02em;
  color: var(--muted);
}

.tools {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.tool {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 9px 4px;
  font: inherit;
  font-size: 12px;
  color: var(--text);
  background: var(--btn);
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
}

.tool:hover { filter: brightness(1.12); }

.tool[aria-pressed="true"] {
  background: var(--accent);
  border-color: #8fb4ff;
}

.tool--wide {
  grid-column: 1 / -1;
  flex-direction: row;
  justify-content: center;
  gap: 7px;
}

/* ── 지우개 버튼과 옵션 메뉴 ── */
.tool-group {
  position: relative;
  grid-column: 1 / -1;
}

#eraserButton {
  flex-direction: row;
  gap: 7px;
  padding: 11px 8px;
  font-size: 13px;
  font-weight: 600;
}

#eraserButton svg { width: 20px; height: 20px; }

#eraserButton::after {
  content: "▾";
  font-size: 11px;
  font-weight: 400;
  color: rgba(255, 255, 255, .8);
}

.tool-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 216px;
  padding: 8px;
  background: #2b2f37;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 12px 28px rgba(0, 0, 0, .5);
}

.tool-menu[hidden] { display: none; }

.tool-menu__item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 12px;
  font: inherit;
  font-size: 14px;
  color: var(--text);
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 7px;
  cursor: pointer;
}

.tool-menu__item small { font-size: 11.5px; color: var(--muted); }

.tool-menu__item:hover { background: var(--btn); }

.tool-menu__item[aria-checked="true"] {
  background: var(--accent);
  border-color: #8fb4ff;
}

.tool-menu__item[aria-checked="true"] small { color: #eaf1ff; }

/* ── 도구 모음 / 그림 비율 조절 구분선 ── */
.splitter {
  position: relative;
  z-index: 10;
  flex: 0 0 auto;
  width: 9px;
  margin: 0 -4px;
  cursor: col-resize;
  touch-action: none;
}

.splitter::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 4px;
  width: 1px;
  background: var(--line);
}

.splitter:hover::before,
.splitter.dragging::before { background: var(--accent); width: 2px; left: 3.5px; }

.settings {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

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

.field__value {
  min-width: 18px;
  color: var(--text);
  font-weight: 600;
}

.color-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

input[type="color"] {
  flex: 1 1 auto;
  width: auto;
  min-width: 0;
  height: 34px;
  padding: 0;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
}

.swatch {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  padding: 0;
  background: var(--c, #888);
  border: 2px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
}

.swatch:hover { border-color: var(--accent); }

.swatch[aria-pressed="true"] { border-color: #ffffff; }

.swatch--prev {
  background: linear-gradient(135deg, transparent 45%, rgba(0, 0, 0, .75) 45%, rgba(0, 0, 0, .75) 55%, transparent 55%), var(--c, transparent);
  border-style: dashed;
}

.swatch--prev[hidden] { display: none; }

.presets {
  display: flex;
  gap: 8px;
}

.presets .swatch {
  flex: 1 1 0;
  width: auto;
  height: 26px;
}

.width-preset {
  flex: 1 1 0;
  padding: 7px 4px;
  font: inherit;
  font-size: 11px;
  color: var(--text);
  background: var(--btn);
  border: 1px solid var(--line);
  border-radius: 7px;
  cursor: pointer;
}

.width-preset:hover { filter: brightness(1.12); }

.width-preset[aria-pressed="true"] {
  background: var(--accent);
  border-color: #8fb4ff;
}

input[type="range"] { width: 100%; }

.actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.actions button {
  padding: 8px;
  font: inherit;
  font-size: 12px;
  color: var(--text);
  background: var(--btn);
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
}

.actions button:hover { filter: brightness(1.12); }

.actions button.primary {
  background: var(--accent);
  border-color: #8fb4ff;
  font-weight: 600;
}

.hint {
  margin: auto 0 0;
  font-size: 11px;
  line-height: 1.5;
  color: var(--muted);
}

/* ── 레이어 목록 ── */
.layers {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}

.layers[hidden] { display: none; }

.layer-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.layer-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 6px;
  background: var(--btn);
  border: 1px solid var(--line);
  border-radius: 7px;
  cursor: grab;
  touch-action: none;
  user-select: none;
}

.layer-item--dragging {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(76, 141, 255, .5);
}

.layer-item__grip {
  flex: 0 0 auto;
  font-size: 13px;
  line-height: 1;
  color: var(--muted);
  cursor: grab;
}

.layer-item__name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  font-size: 12px;
  color: var(--text);
  white-space: nowrap;
  text-overflow: ellipsis;
}

.layer-item__remove {
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  padding: 0;
  font: inherit;
  font-size: 14px;
  line-height: 1;
  color: var(--text);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
}

.layer-item__remove:hover {
  background: #d8474a;
  border-color: #d8474a;
  color: #fff;
}

/* ── 캔버스 위 텍스트 입력 ── */
.text-input {
  position: absolute;
  z-index: 30;
  min-width: 90px;
  padding: 2px 6px;
  font-family: inherit;
  color: #111;
  background: rgba(255, 255, 255, .96);
  border: 1px solid var(--accent);
  border-radius: 4px;
  outline: none;
}

/* ── 캔버스 영역 ── */
.stage {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow: auto;
}

#board {
  display: block;
  margin: auto;
  background: #fff;
  border-radius: 6px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, .5);
  cursor: crosshair;
  touch-action: none;
}

.stage.panning,
.stage.panning #board { cursor: grabbing; }

.empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 20px;
  font-size: 14px;
  color: var(--muted);
  text-align: center;
  pointer-events: none;
}

.empty[hidden] { display: none; }

.status {
  position: absolute;
  left: 50%;
  bottom: 14px;
  max-width: 90%;
  margin: 0;
  padding: 7px 14px;
  font-size: 12px;
  color: #fff;
  text-align: center;
  background: rgba(0, 0, 0, .8);
  border-radius: 999px;
  opacity: 0;
  transform: translateX(-50%);
  transition: opacity .2s ease;
  pointer-events: none;
}

.status.show { opacity: 1; }

/* ── 좁은 화면: 도구 모음을 아래로 ── */
@media (max-width: 640px) {
  body { flex-direction: column; }

  .toolbar {
    order: 2;
    width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-right: 0;
    border-top: 1px solid var(--line);
  }

  .toolbar__title { display: none; }
  .hint { display: none; }
  .splitter { display: none; }
  .tool-menu { top: auto; bottom: calc(100% + 6px); }

  .tools {
    flex: 1 1 100%;
    grid-template-columns: repeat(4, 1fr);
  }

  .layers { flex: 1 1 100%; }

  .settings {
    flex: 1 1 100%;
    flex-direction: row;
    gap: 12px;
  }

  .field { flex: 1; }

  .actions {
    flex: 1 1 100%;
    flex-direction: row;
  }

  .actions button { flex: 1; }

  .stage { order: 1; }
}
