/* ═══════════════════════════════════════
   ПЕНЗЛИК v3 — Design System
   Font: Nunito
   Style: Rounded Neo-Brutalism
═══════════════════════════════════════ */

:root {
  --bg: #fdf8f0;
  --sb-bg: #ffffff;
  --panel-bg: #f5f0e6;
  --border: #1c1c1c;
  --shadow: 3px 3px 0 #1c1c1c;
  --shadow-lg: 5px 5px 0 #1c1c1c;
  --r: 12px;
  --r-sm: 8px;

  --primary: #4f46e5;
  --primary-h: #4338ca;
  --success: #16a34a;
  --danger: #dc2626;
  --accent: #f59e0b;
  --text: #1c1c1c;
  --muted: #6b7280;

  --font: 'Nunito', sans-serif;
}

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

.noscript-warning {
  background: #fee2e2;
  color: #dc2626;
  text-align: center;
  padding: 10px;
  font-weight: 700;
  border-bottom: 2px solid var(--danger);
}

/* ── LAYOUT ── */
.app {
  display: flex;
  height: 100vh;
  max-width: 1400px;
  margin: 0 auto;
}

/* ── SIDEBAR ── */
.sidebar {
  width: 230px;
  flex-shrink: 0;
  background: var(--sb-bg);
  border-right: 3px solid var(--border);
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 10px 14px;
  scrollbar-width: thin;
  scrollbar-color: #d1d5db transparent;
}

.sidebar::-webkit-scrollbar {
  width: 3px;
}

.sidebar::-webkit-scrollbar-thumb {
  background: #d1d5db;
  border-radius: 4px;
}

/* ── TITLE ── */
.app-title {
  font-family: var(--font);
  font-weight: 900;
  font-size: 22px;
  color: var(--primary);
  text-align: center;
  padding: 4px 0 8px;
  border-bottom: 3px solid var(--border);
  margin-bottom: 2px;
  letter-spacing: -0.3px;
}

.app-title i {
  color: var(--accent);
}

/* ── PANEL ── */
.panel {
  background: var(--panel-bg);
  border: 2px solid var(--border);
  border-radius: var(--r);
  padding: 9px 9px 10px;
  box-shadow: var(--shadow);
}

.panel-label {
  font-weight: 800;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: var(--muted);
  margin-bottom: 7px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 7px;
}

/* ── TOOL BUTTONS ── */
.tools-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
}

.tool-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 7px 4px 6px;
  font-family: var(--font);
  font-size: 10px;
  font-weight: 800;
  background: var(--primary);
  color: #fff;
  border: 2px solid var(--border);
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: transform .1s, box-shadow .1s, background .1s;
  box-shadow: var(--shadow);
  line-height: 1;
}

.tool-btn i {
  font-size: 14px;
}

.tool-btn:hover {
  background: #6366f1;
  transform: translate(-1px, -1px);
  box-shadow: 4px 4px 0 var(--border);
}

.tool-btn:active {
  transform: translate(1px, 1px);
  box-shadow: 1px 1px 0 var(--border);
}

.tool-btn.active {
  background: var(--text);
  color: var(--accent);
  transform: translate(1px, 1px);
  box-shadow: 1px 1px 0 var(--border);
}

/* ── SHAPES ── */
.shapes-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
}

.shape-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 34px;
  font-size: 13px;
  background: #e0e7ff;
  color: var(--primary);
  border: 2px solid var(--border);
  border-radius: var(--r-sm);
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: all .1s;
}

.shape-btn:hover {
  background: #c7d2fe;
  transform: translate(-1px, -1px);
  box-shadow: 4px 4px 0 var(--border);
}

.shape-btn.active {
  background: var(--primary);
  color: #fff;
  transform: translate(1px, 1px);
  box-shadow: 1px 1px 0 var(--border);
}

/* ── STAMPS ── */
.stamps-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
}

.stamp {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 38px;
  font-size: 22px;
  background: #fef3c7;
  border: 2px solid var(--border);
  border-radius: var(--r-sm);
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: all .1s;
  user-select: none;
}

.stamp:hover {
  background: #fde68a;
  transform: translate(-1px, -1px);
  box-shadow: 4px 4px 0 var(--border);
}

.stamp.active {
  background: var(--accent);
  transform: translate(1px, 1px);
  box-shadow: 1px 1px 0 var(--border);
}

/* ── ICON BTN ── */
.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  background: #fff;
  color: var(--text);
  border: 2px solid var(--border);
  border-radius: 7px;
  font-size: 11px;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: all .1s;
}

.icon-btn:hover {
  background: var(--accent);
  transform: translate(-1px, -1px);
  box-shadow: 3px 3px 0 var(--border);
}

.icon-btn.active {
  background: var(--primary);
  color: #fff;
}

/* ── COLOR PALETTE ── */
.color-palette {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 5px;
  margin-bottom: 2px;
}

.color {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid rgba(0, 0, 0, .18);
  transition: transform .15s;
  box-shadow: 1px 1px 0 rgba(0, 0, 0, .2);
}

.color:hover {
  transform: scale(1.18);
  box-shadow: 2px 2px 0 var(--border);
}

.color.active {
  border: 3px solid var(--border);
  transform: scale(1.1);
  box-shadow: 2px 2px 0 var(--border);
}

/* ── NATIVE PICKER ── */
.native-color-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  background: linear-gradient(135deg, #ff0080, #ff8c00, #ffff00, #00ff80, #00bfff, #8000ff);
  border: 2px solid var(--border);
  border-radius: 7px;
  cursor: pointer;
  font-size: 11px;
  color: #fff;
  text-shadow: 0 0 3px rgba(0, 0, 0, .6);
  box-shadow: var(--shadow);
  transition: all .1s;
  position: relative;
  overflow: hidden;
}

.native-color-btn:hover {
  transform: translate(-1px, -1px);
  box-shadow: 3px 3px 0 var(--border);
}

.native-color-btn input[type="color"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
}

/* ── INLINE COLOR MIXER ── */
.color-mixer {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 2px dashed #d1d5db;
}

.mixer-top {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.mixer-swatch {
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  border-radius: var(--r-sm);
  border: 2px solid var(--border);
  background: #000;
  box-shadow: var(--shadow);
}

.mixer-codes {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 11px;
}

.code-row {
  display: flex;
  gap: 5px;
  align-items: baseline;
}

.code-lbl {
  font-weight: 900;
  font-size: 9px;
  text-transform: uppercase;
  color: var(--muted);
  min-width: 22px;
}

/* Binary row */
.binary-block {
  display: flex;
  align-items: flex-start;
  gap: 5px;
  margin-bottom: 6px;
  background: #1c1c1c;
  border-radius: var(--r-sm);
  padding: 5px 7px;
  border: 2px solid var(--border);
}

.binary-block .code-lbl {
  color: #9ca3af;
  padding-top: 1px;
}

.binary-display {
  display: flex;
  flex-direction: column;
  gap: 1px;
  font-family: 'Courier New', monospace;
  font-size: 10px;
  font-weight: 700;
  line-height: 1.5;
}

.bin-r {
  color: #f87171;
}

.bin-g {
  color: #4ade80;
}

.bin-b {
  color: #60a5fa;
}

/* Sliders */
.mixer-sliders {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 7px;
}

.ch-row {
  display: flex;
  align-items: center;
  gap: 5px;
}

.ch-lbl {
  font-size: 10px;
  font-weight: 900;
  width: 12px;
  flex-shrink: 0;
}

.ch-lbl.r {
  color: #ef4444;
}

.ch-lbl.g {
  color: #22c55e;
}

.ch-lbl.b {
  color: #3b82f6;
}

.ch-range {
  flex: 1;
  height: 5px;
  cursor: pointer;
  border-radius: 4px;
}

.r-range {
  accent-color: #ef4444;
}

.g-range {
  accent-color: #22c55e;
}

.b-range {
  accent-color: #3b82f6;
}

.ch-num {
  font-size: 11px;
  font-weight: 700;
  min-width: 24px;
  text-align: right;
}

.apply-btn {
  width: 100%;
  padding: 7px;
  font-family: var(--font);
  font-weight: 800;
  font-size: 12px;
  background: var(--success);
  color: #fff;
  border: 2px solid var(--border);
  border-radius: var(--r-sm);
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: all .1s;
}

.apply-btn:hover {
  background: #22c55e;
  transform: translate(-1px, -1px);
  box-shadow: 4px 4px 0 var(--border);
}

.apply-btn:active {
  transform: translate(1px, 1px);
  box-shadow: 1px 1px 0 var(--border);
}

/* ── SIZE + OPACITY ── */
.so-row {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.so-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.badge {
  display: inline-block;
  padding: 1px 6px;
  background: var(--primary);
  color: #fff;
  border: 2px solid var(--border);
  border-radius: 20px;
  font-size: 10px;
  font-weight: 800;
}

.range-input {
  width: 100%;
  height: 5px;
  accent-color: var(--primary);
  cursor: pointer;
}

/* ── ACTIONS ── */
.action-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
  margin-bottom: 7px;
}

.action-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 8px 5px;
  font-family: var(--font);
  font-size: 11px;
  font-weight: 800;
  background: var(--primary);
  color: #fff;
  border: 2px solid var(--border);
  border-radius: var(--r-sm);
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: all .1s;
  white-space: nowrap;
}

.action-btn:hover {
  background: #6366f1;
  transform: translate(-1px, -1px);
  box-shadow: 4px 4px 0 var(--border);
}

.action-btn:active {
  transform: translate(1px, 1px);
  box-shadow: 1px 1px 0 var(--border);
}

.action-btn:disabled {
  opacity: .45;
  pointer-events: none;
}

.action-btn.danger {
  background: var(--danger);
}

.action-btn.danger:hover {
  background: #ef4444;
}

.action-btn.success {
  background: var(--success);
}

.action-btn.success:hover {
  background: #22c55e;
}

/* ── UPLOAD ── */
.upload-label {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px;
  font-family: var(--font);
  font-weight: 700;
  font-size: 12px;
  color: var(--text);
  background: #fff;
  border: 2px dashed #9ca3af;
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: all .15s;
  position: relative;
  overflow: hidden;
}

.upload-label:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: #e0e7ff;
}

.upload-label input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

/* ── SHORTCUTS ── */
.shortcuts-panel {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px;
  padding: 7px;
  background: var(--panel-bg);
  border: 2px solid var(--border);
  border-radius: var(--r);
  box-shadow: var(--shadow);
}

.sc {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  color: var(--muted);
  font-weight: 600;
}

kbd {
  display: inline-block;
  padding: 1px 4px;
  background: #fff;
  border: 1.5px solid #d1d5db;
  border-radius: 4px;
  font-family: var(--font);
  font-size: 9px;
  font-weight: 800;
  box-shadow: 0 1px 0 #9ca3af;
  white-space: nowrap;
}

/* ═══ CANVAS ═══ */
.canvas-area {
  flex: 1;
  padding: 14px;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

#canvas-container {
  position: relative;
  flex: 1;
  border: 3px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  background: #fff;
  cursor: crosshair;
}

#drawing-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: inherit;
}

/* ── TOOL INDICATOR ── */
.tool-indicator {
  position: absolute;
  top: 12px;
  right: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  background: rgba(255, 255, 255, .92);
  backdrop-filter: blur(4px);
  border: 2px solid var(--border);
  border-radius: 20px;
  font-family: var(--font);
  font-weight: 700;
  font-size: 13px;
  box-shadow: var(--shadow);
  pointer-events: none;
}

/* ═══ MODAL ═══ */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(28, 28, 28, .55);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-box {
  background: #fff;
  border: 3px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  padding: 28px 28px 22px;
  max-width: 340px;
  width: 90%;
  text-align: center;
  animation: modal-pop .18s cubic-bezier(.34, 1.56, .64, 1);
}

@keyframes modal-pop {
  from {
    transform: scale(.8);
    opacity: 0;
  }

  to {
    transform: scale(1);
    opacity: 1;
  }
}

.modal-icon {
  font-size: 40px;
  margin-bottom: 10px;
}

.modal-title {
  font-weight: 900;
  font-size: 18px;
  margin-bottom: 6px;
}

.modal-text {
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 18px;
  line-height: 1.5;
}

.modal-btns {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.modal-btn {
  padding: 9px 22px;
  font-family: var(--font);
  font-weight: 800;
  font-size: 14px;
  border: 2px solid var(--border);
  border-radius: var(--r-sm);
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: all .1s;
}

.modal-btn:hover {
  transform: translate(-1px, -1px);
  box-shadow: 4px 4px 0 var(--border);
}

.modal-btn:active {
  transform: translate(1px, 1px);
  box-shadow: 1px 1px 0 var(--border);
}

.modal-btn.cancel {
  background: #f3f4f6;
  color: var(--text);
}

.modal-btn.confirm {
  background: var(--primary);
  color: #fff;
}

.modal-btn.confirm.danger-btn {
  background: var(--danger);
}

/* ═══ RESPONSIVE ═══ */
@media (max-width: 860px) {
  body {
    overflow: auto;
  }

  .app {
    flex-direction: column;
    height: auto;
  }

  .sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 3px solid var(--border);
    flex-direction: row;
    flex-wrap: wrap;
    overflow-x: auto;
    overflow-y: visible;
    padding: 8px;
    gap: 6px;
  }

  .app-title {
    width: 100%;
  }

  .panel {
    flex-shrink: 0;
  }

  .canvas-area {
    height: 70vh;
  }

  .shortcuts-panel {
    display: none;
  }
}