/* =========================================
   Web Paint - Styles
   ========================================= */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #f3f4f6;
  --bg-panel: #ffffff;
  --bg-soft: #f9fafb;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --text: #111827;
  --text-muted: #6b7280;
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --primary-soft: #eef2ff;
  --canvas-bg: #ffffff;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.06);
  --shadow: 0 4px 14px rgba(0,0,0,.08);
  --radius: 10px;
  --radius-sm: 6px;
}

html, body {
  height: 100%;
}

body {
  font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, 'Segoe UI',
    'Apple SD Gothic Neo', 'Noto Sans KR', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  overflow: hidden;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  background: none;
  border: none;
}

input, select {
  font: inherit;
}

fieldset { border: none; }

/* ========== Header ========== */
.app-header {
  padding: 14px 24px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: baseline;
  gap: 14px;
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
}
.app-title {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.02em;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.app-logo { font-size: 22px; }
.app-sub {
  color: var(--text-muted);
  font-size: 13px;
}

/* ========== Layout ========== */
.app {
  flex: 1;
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 0;
  overflow: hidden;
}

/* ========== Toolbar ========== */
.toolbar {
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  padding: 16px 14px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.toolbar::-webkit-scrollbar { width: 8px; }
.toolbar::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }

.tool-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.tool-group:last-child { border-bottom: none; }
.tool-group legend {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1.5px;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-bottom: 4px;
}

/* 도구 버튼 */
.tool-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}
.tool-btn {
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
  transition: all .15s ease;
  color: var(--text);
}
.tool-btn svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}
.tool-btn:hover {
  background: var(--primary-soft);
  border-color: var(--primary);
}
.tool-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

/* 색상 */
.color-preview {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.color-swatch {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
  cursor: pointer;
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
  gap: 8px;
  transition: border-color .15s;
}
.color-swatch:hover { border-color: var(--primary); }
.color-swatch input[type="color"] {
  width: 22px;
  height: 22px;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  padding: 0;
  cursor: pointer;
  background: none;
}
.color-swatch input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.color-swatch input[type="color"]::-webkit-color-swatch { border: none; border-radius: 3px; }

.palette {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 5px;
}
.swatch {
  aspect-ratio: 1 / 1;
  border-radius: 4px;
  border: 1px solid transparent;
  transition: transform .12s, box-shadow .12s;
}
.swatch:hover {
  transform: scale(1.15);
  box-shadow: 0 2px 8px rgba(0,0,0,.18);
}

/* 굵기 */
.slider-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.slider-row input[type="range"] {
  flex: 1;
  accent-color: var(--primary);
}
.size-preview {
  display: inline-block;
  width: 28px;
  height: 28px;
  position: relative;
  flex-shrink: 0;
}
.size-preview::after {
  content: '';
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: var(--s, 6px);
  height: var(--s, 6px);
  background: var(--text);
  border-radius: 50%;
  transition: width .1s, height .1s;
}
#sizeValue {
  min-width: 24px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--text-muted);
}

/* 체크박스 */
.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  padding: 4px 2px;
  font-size: 13.5px;
  color: var(--text);
}
.check-row input { accent-color: var(--primary); width: 15px; height: 15px; }

/* 동작 버튼 */
.action-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
.btn {
  padding: 10px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
  font-size: 13px;
  font-weight: 600;
  transition: all .15s;
  white-space: nowrap;
  color: var(--text);
}
.btn:hover {
  background: var(--primary-soft);
  border-color: var(--primary);
  color: var(--primary-hover);
}
.btn:disabled {
  opacity: .45;
  cursor: not-allowed;
  background: var(--bg-soft);
  border-color: var(--border);
  color: var(--text-muted);
}
.btn-primary {
  grid-column: span 2;
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  padding: 12px;
  font-size: 14px;
}
.btn-primary:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
  color: #fff;
}

/* ========== Canvas area ========== */
.canvas-area {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background:
    linear-gradient(45deg, #e5e7eb 25%, transparent 25%),
    linear-gradient(-45deg, #e5e7eb 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e5e7eb 75%),
    linear-gradient(-45deg, transparent 75%, #e5e7eb 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
  background-color: #f3f4f6;
}

.canvas-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow: auto;
  min-height: 0;
}

#board {
  background: var(--canvas-bg);
  border-radius: 6px;
  box-shadow: 0 8px 30px rgba(0,0,0,.12), 0 2px 6px rgba(0,0,0,.06);
  max-width: 100%;
  max-height: 100%;
  cursor: crosshair;
  touch-action: none;
  display: block;
}

/* 도구별 커서 */
#board.cursor-pen { cursor: crosshair; }
#board.cursor-eraser { cursor: cell; }
#board.cursor-fill { cursor: pointer; }
#board.cursor-picker { cursor: copy; }
#board.cursor-move { cursor: crosshair; }

/* 상태바 */
.status-bar {
  flex-shrink: 0;
  padding: 8px 16px;
  background: var(--bg-panel);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.status-bar .divider { color: var(--border-strong); }
.hotkey-hint { margin-left: auto; }

/* ========== Responsive ========== */
@media (max-width: 860px) {
  body { overflow: auto; }
  .app {
    grid-template-columns: 1fr;
  }
  .toolbar {
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: none;
    order: 2;
  }
  .canvas-area { order: 1; min-height: 60vh; }
  .hotkey-hint { display: none; }
  .tool-row { grid-template-columns: repeat(8, 1fr); }
  .palette { grid-template-columns: repeat(12, 1fr); }
}
