:root {
  --bg: #eef2ff;
  --panel: rgba(255, 255, 255, 0.92);
  --panel-solid: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #dbe3f0;
  --brand: #4f46e5;
  --brand-2: #06b6d4;
  --danger: #ef4444;
  --shadow: 0 18px 45px rgba(15, 23, 42, 0.12);
  --radius: 16px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 10% 0%, rgba(79, 70, 229, 0.18), transparent 34%),
    radial-gradient(circle at 90% 8%, rgba(6, 182, 212, 0.16), transparent 32%),
    var(--bg);
}

button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { opacity: 0.45; cursor: not-allowed; }

.app-shell { padding: 12px; }
.layout {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
}

/* ---------- Sidebar ---------- */
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: calc(100vh - 24px);
  overflow-y: auto;
  padding-right: 2px;
}
.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(79, 70, 229, 0.25); border-radius: 99px; }

.section-block {
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.65);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.07);
  backdrop-filter: blur(12px);
}
.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.14em;
  color: var(--muted);
}
.section-caption {
  display: grid;
  place-items: center;
  width: 22px; height: 22px;
  border-radius: 8px;
  background: linear-gradient(135deg, rgba(79, 70, 229, 0.12), rgba(6, 182, 212, 0.12));
  color: var(--brand);
  font-size: 10px;
}

.tool-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.tool-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 9px 4px 7px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-solid);
  color: var(--muted);
  transition: 0.16s ease;
}
.tool-btn svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.tool-btn span { font-size: 11px; font-weight: 700; }
.tool-btn kbd {
  font-size: 9px; padding: 1px 5px; border-radius: 5px;
  background: rgba(100, 116, 139, 0.1); color: var(--muted);
}
.tool-btn:hover { border-color: rgba(79, 70, 229, 0.4); transform: translateY(-1px); }
.tool-btn.active {
  color: #fff;
  border-color: transparent;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  box-shadow: 0 8px 18px rgba(79, 70, 229, 0.28);
}
.tool-btn.active kbd { background: rgba(255, 255, 255, 0.22); color: #fff; }
.tool-hint { margin: 9px 0 0; font-size: 11.5px; line-height: 1.45; color: var(--muted); }

.history-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.history-btn {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 9px 4px 7px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--panel-solid); color: var(--ink); font-size: 11px; font-weight: 700;
  transition: 0.16s ease;
}
.history-btn svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.history-btn:hover:not(:disabled) { border-color: rgba(79, 70, 229, 0.45); color: var(--brand); transform: translateY(-1px); }

.current-color-row { display: flex; align-items: center; gap: 9px; margin-bottom: 10px; }
.current-color-swatch {
  width: 38px; height: 38px; border-radius: 12px; border: 3px solid #fff;
  box-shadow: 0 0 0 1px var(--line), 0 4px 10px rgba(15, 23, 42, 0.12);
  background: #1f2937; flex: none;
}
.current-color-copy { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.current-color-label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-weight: 700; }
.current-color-value { font-size: 14px; font-weight: 800; }
.custom-color-button {
  display: grid; place-items: center; width: 32px; height: 32px; border-radius: 10px;
  border: 1px dashed var(--line); color: var(--muted); cursor: pointer; position: relative;
}
.custom-color-button svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; }
.custom-color-button input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.palette { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.color-swatch {
  width: 100%; aspect-ratio: 1; border-radius: 9px; border: 2px solid #fff;
  background: var(--swatch); box-shadow: 0 0 0 1px var(--line);
  transition: 0.14s ease;
}
.color-swatch:hover { transform: scale(1.08); }
.color-swatch.selected { box-shadow: 0 0 0 2px var(--brand), 0 4px 10px rgba(79, 70, 229, 0.25); transform: scale(1.06); }
.eyedropper-note { display: flex; gap: 7px; margin-top: 10px; font-size: 11px; line-height: 1.4; color: var(--muted); }
.note-icon {
  display: grid; place-items: center; flex: none; width: 17px; height: 17px;
  border-radius: 50%; background: rgba(79, 70, 229, 0.12); color: var(--brand);
  font-size: 11px; font-weight: 800; font-style: italic;
}

.range-block + .range-block { margin-top: 10px; }
.range-label-row { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; font-weight: 700; }
.range-label-row output { color: var(--brand); }
.range-input { width: 100%; margin: 6px 0 2px; accent-color: var(--brand); }
.range-minmax { display: flex; justify-content: space-between; font-size: 10px; color: var(--muted); }

.sidebar-bottom { margin-top: auto; }
.clear-button {
  width: 100%; display: flex; align-items: center; justify-content: center; gap: 7px;
  padding: 10px; border: 1px solid rgba(239, 68, 68, 0.25); border-radius: 12px;
  background: rgba(239, 68, 68, 0.08); color: #b91c1c; font-size: 12px; font-weight: 800;
  transition: 0.16s ease;
}
.clear-button svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.clear-button:hover { background: rgba(239, 68, 68, 0.15); }

/* ---------- Board ---------- */
.board-panel {
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.65);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px;
  backdrop-filter: blur(12px);
  min-width: 0;
}
.board-header { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.board-title { font-size: 14px; font-weight: 800; letter-spacing: 0.02em; }
.board-badge {
  font-size: 10.5px; font-weight: 700; color: var(--brand);
  background: rgba(79, 70, 229, 0.1); border: 1px solid rgba(79, 70, 229, 0.18);
  padding: 4px 9px; border-radius: 99px;
}
.canvas-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: #fff;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.8);
}
#drawingCanvas, #previewCanvas {
  position: absolute; inset: 0; width: 100%; height: 100%;
  display: block; touch-action: none;
}
#previewCanvas { cursor: crosshair; }
.canvas-frame[data-tool="eraser"] #previewCanvas { cursor: cell; }
.canvas-frame[data-tool="eyedropper"] #previewCanvas { cursor: copy; }
.canvas-empty-hint {
  position: absolute; inset: 0; display: grid; place-content: center; justify-items: center;
  gap: 4px; color: #94a3b8; pointer-events: none; text-align: center;
}
.canvas-empty-hint.hidden { display: none; }
.canvas-empty-hint span { font-weight: 800; color: #64748b; }
.canvas-empty-hint small { font-size: 11.5px; }
.empty-icon {
  display: grid; place-items: center; width: 46px; height: 46px; border-radius: 14px;
  background: rgba(79, 70, 229, 0.08); color: var(--brand); margin-bottom: 4px;
}
.empty-icon svg { width: 25px; height: 25px; }

.board-footer {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin-top: 9px; font-size: 11px; color: var(--muted); flex-wrap: wrap;
}
.footer-left { display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }
.footer-left b { color: var(--ink); }
.keyboard-icon { opacity: 0.6; }
.footer-bullet { opacity: 0.4; }
#footerStatus { color: var(--brand); font-weight: 700; }

.toast {
  position: fixed; left: 50%; bottom: 18px; transform: translate(-50%, 20px);
  padding: 9px 16px; border-radius: 99px; background: #0f172a; color: #fff;
  font-size: 12px; font-weight: 700; opacity: 0; pointer-events: none;
  transition: 0.22s ease; z-index: 50; max-width: calc(100vw - 30px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 640px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { max-height: none; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sidebar-bottom { grid-column: 1 / -1; }
}
@media (max-width: 560px) {
  .app-shell { padding: 8px; }
  .sidebar { grid-template-columns: 1fr; }
  .board-badge { display: none; }
  .board-footer { font-size: 10px; }
}
