* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #12141c;
  --panel: #1c1f2b;
  --panel-2: #252939;
  --text: #eef1f8;
  --muted: #8f97ad;
  --accent: #ff3b30;
  --accent-2: #007aff;
  --radius: 14px;
}

body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Верхняя панель */
.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 18px;
  background: var(--panel);
  border-bottom: 1px solid #2e3346;
  flex-wrap: wrap;
}

.logo {
  font-weight: 800;
  font-size: 20px;
  background: linear-gradient(90deg, #ff3b30, #ff9500, #ffcc00, #34c759, #007aff, #af52de);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.group {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: var(--panel-2);
  border-radius: var(--radius);
}

.group.right { margin-left: auto; }

.tool {
  border: none;
  background: transparent;
  color: var(--text);
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 14px;
  cursor: pointer;
  transition: background .15s, transform .1s;
}

.tool:hover { background: #333a52; }
.tool:active { transform: scale(.96); }

.tool.active {
  background: var(--accent-2);
  box-shadow: 0 0 12px rgba(0,122,255,.5);
}

.tool.danger:hover { background: #58232b; }
.tool.accent {
  background: linear-gradient(135deg, #34c759, #00b894);
  color: #06210f;
  font-weight: 700;
}
.tool.accent:hover { filter: brightness(1.1); background: linear-gradient(135deg, #34c759, #00b894); }

.slider-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
}

input[type="range"] {
  accent-color: var(--accent-2);
  width: 130px;
  cursor: pointer;
}

.badge {
  min-width: 30px;
  text-align: center;
  background: #10131d;
  border-radius: 8px;
  padding: 4px 6px;
  font-variant-numeric: tabular-nums;
  font-size: 13px;
}

/* Рабочая область */
.workspace {
  flex: 1;
  display: flex;
  gap: 18px;
  padding: 18px;
}

.sidebar {
  width: 230px;
  flex-shrink: 0;
  background: var(--panel);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  height: fit-content;
}

.sidebar h2 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
}

.palette {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}

.swatch-btn {
  aspect-ratio: 1;
  border-radius: 10px;
  border: 2px solid rgba(255,255,255,.12);
  cursor: pointer;
  transition: transform .12s, border-color .12s;
}

.swatch-btn:hover { transform: scale(1.12); }
.swatch-btn.active {
  border-color: #fff;
  box-shadow: 0 0 0 3px var(--accent-2);
}

.custom-color {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 14px;
  color: var(--muted);
  background: var(--panel-2);
  padding: 8px 12px;
  border-radius: 10px;
  cursor: pointer;
}

.custom-color input {
  width: 42px;
  height: 28px;
  border: none;
  background: none;
  cursor: pointer;
}

.current {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 14px;
  background: var(--panel-2);
  padding: 8px 12px;
  border-radius: 10px;
}

.swatch {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 2px solid rgba(255,255,255,.2);
}

/* Стадия с холстом */
.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
}

.canvas-frame {
  background:
    repeating-conic-gradient(#20232f 0% 25%, #191c26 0% 50%) 0 0 / 24px 24px;
  padding: 14px;
  border-radius: var(--radius);
  box-shadow: 0 20px 50px rgba(0,0,0,.45);
  max-width: 100%;
  transition: outline-color .15s;
  outline: 3px solid transparent;
}

.canvas-frame.dragover { outline-color: var(--accent-2); }

canvas#board {
  display: block;
  background: #fff;
  border-radius: 6px;
  touch-action: none;
  cursor: crosshair;
  max-width: 100%;
  height: auto;
}

.hint {
  color: var(--muted);
  font-size: 13px;
}

.hint b { color: var(--text); }

@media (max-width: 860px) {
  .workspace { flex-direction: column; }
  .sidebar { width: 100%; }
  .palette { grid-template-columns: repeat(10, 1fr); }
}

/* Типы кистей */
.brushes {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.brush-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: var(--panel-2);
  border: 2px solid transparent;
  border-radius: 10px;
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  transition: 0.15s;
}

.brush-btn:hover { background: rgba(255, 255, 255, 0.1); }

.brush-btn.active {
  border-color: var(--accent);
  background: rgba(120, 90, 255, 0.2);
}

.brush-icon {
  width: 22px;
  text-align: center;
  font-size: 16px;
  color: #9b8cff;
}

/* Слои */
.layers {
  display: flex;
  flex-direction: column;
  gap: 5px;
  max-height: 210px;
  overflow-y: auto;
}

.layer-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  background: var(--panel-2);
  border: 2px solid transparent;
  border-radius: 10px;
  cursor: pointer;
  transition: 0.12s;
  font-size: 14px;
}

.layer-row:hover { background: #2e3346; }

.layer-row.active {
  border-color: var(--accent-2);
  background: rgba(0, 122, 255, 0.15);
}

.layer-row.hidden-layer .layer-name { opacity: 0.45; text-decoration: line-through; }

.layer-eye {
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 14px;
  padding: 0 2px;
  color: var(--text);
}

.layer-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.mini {
  flex: 1;
  padding: 7px 0;
  background: var(--panel-2);
  border: none;
  border-radius: 8px;
  color: var(--text);
  font-size: 15px;
  cursor: pointer;
  transition: background .12s;
}

.mini:hover { background: #333a52; }

/* Линейка */
.ruler-wrap {
  position: relative;
  width: fit-content;
  margin: 0 auto 6px;
}

.ruler-wrap.hidden { display: none; }

canvas#ruler {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: 6px;
}

.ruler-tip {
  position: absolute;
  top: -10px;
  transform: translateX(-50%);
  background: #ff5b5b;
  color: #fff;
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 6px;
  pointer-events: none;
  opacity: 0;
  transition: opacity .1s;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.ruler-tip.show { opacity: 1; }

/* Тост-уведомления */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #2e3346;
  color: var(--text);
  padding: 10px 18px;
  border-radius: 12px;
  font-size: 14px;
  box-shadow: 0 10px 30px rgba(0,0,0,.5);
  opacity: 0;
  pointer-events: none;
  transition: .25s;
  z-index: 50;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
