.drawing-widget {
  --dw-surface: #fffaf3;
  --dw-panel: #ffffff;
  --dw-border: #e6dccb;
  --dw-text: #30281f;
  --dw-muted: #7c6f60;
  --dw-primary: #374151;
  --dw-primary-dark: #111827;
  --dw-shadow: 0 18px 45px rgba(72, 54, 34, 0.12);

  box-sizing: border-box;
  width: 100%;
  max-width: 100%;
  padding: 16px;
  border: 1px solid var(--dw-border);
  border-radius: 22px;
  background:
    radial-gradient(circle at top left, rgba(255, 214, 151, 0.45), transparent 32%),
    linear-gradient(135deg, var(--dw-surface), #f7efe4);
  color: var(--dw-text);
  box-shadow: var(--dw-shadow);
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
}

.drawing-widget *,
.drawing-widget *::before,
.drawing-widget *::after {
  box-sizing: border-box;
}

.drawing-widget__toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  width: 100%;
  margin-bottom: 14px;
  padding: 10px;
  border: 1px solid rgba(230, 220, 203, 0.85);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.5);
}

.drawing-widget__control {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  min-width: 0;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--dw-border);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: 0 8px 18px rgba(72, 54, 34, 0.06);
}

.drawing-widget__control--color {
  position: relative;
}

.drawing-widget__control--size {
  flex: 1 1 230px;
  max-width: 100%;
}

.drawing-widget__color-toggle {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font: inherit;
}

.drawing-widget__label,
.drawing-widget__size-value {
  color: var(--dw-muted);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.drawing-widget__icon {
  display: inline-flex;
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  color: currentColor;
}

.drawing-widget__icon svg {
  display: block;
  width: 100%;
  height: 100%;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.drawing-widget__icon circle {
  fill: currentColor;
  stroke: none;
}

.drawing-widget__color {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  border: 0;
  opacity: 0;
  pointer-events: none;
}

.drawing-widget__color-preview {
  width: 34px;
  height: 28px;
  border: 1px solid rgba(48, 40, 31, 0.18);
  border-radius: 8px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.34);
}

.drawing-widget__palette {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: repeat(5, 28px);
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--dw-border);
  border-radius: 16px;
  background: #ffffff;
  box-shadow: 0 18px 45px rgba(72, 54, 34, 0.16);
  opacity: 0;
  pointer-events: none;
  transform: translateY(-4px);
  transition:
    opacity 140ms ease,
    transform 140ms ease;
}

.drawing-widget__palette--visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.drawing-widget__swatch {
  position: relative;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid rgba(48, 40, 31, 0.18);
  border-radius: 999px;
  cursor: pointer;
}

.drawing-widget__swatch:hover,
.drawing-widget__swatch:focus-visible {
  outline: 3px solid rgba(55, 65, 81, 0.18);
  outline-offset: 2px;
}

.drawing-widget__swatch--light {
  border-color: rgba(48, 40, 31, 0.3);
  background: #ffffff;
}

.drawing-widget__swatch--custom {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-color: rgba(55, 65, 81, 0.28);
  background: #f4faf7;
  color: var(--dw-primary);
}

.drawing-widget__swatch--custom::before {
  position: absolute;
  right: 4px;
  bottom: 4px;
  width: 8px;
  height: 8px;
  border: 1px solid #ffffff;
  border-radius: 999px;
  background: conic-gradient(from 90deg, #ef4444, #f97316, #facc15, #22c55e, #3b82f6, #8b5cf6, #ef4444);
  box-shadow: 0 1px 3px rgba(48, 40, 31, 0.2);
  content: "";
}

.drawing-widget__swatch--custom .drawing-widget__icon {
  position: relative;
  z-index: 1;
  width: 17px;
  height: 17px;
}

.drawing-widget__swatch--active::after {
  position: absolute;
  inset: -5px;
  border: 2px solid var(--dw-primary);
  border-radius: inherit;
  content: "";
}

.drawing-widget__size {
  width: 120px;
  min-width: 72px;
  max-width: 100%;
  flex: 1 1 96px;
  accent-color: var(--dw-primary);
  cursor: pointer;
}

.drawing-widget__size-value {
  min-width: 22px;
  text-align: right;
}

.drawing-widget__button {
  position: relative;
  display: inline-flex;
  width: 44px;
  height: 44px;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid var(--dw-border);
  border-radius: 14px;
  background: var(--dw-panel);
  color: var(--dw-text);
  cursor: pointer;
  font: inherit;
  font-size: 14px;
  font-weight: 800;
  line-height: 1;
  box-shadow: 0 8px 18px rgba(72, 54, 34, 0.06);
  transition:
    transform 160ms ease,
    border-color 160ms ease,
    background-color 160ms ease,
    box-shadow 160ms ease;
}

.drawing-widget__button:hover {
  border-color: rgba(55, 65, 81, 0.48);
  transform: translateY(-1px);
}

.drawing-widget__button:disabled {
  opacity: 0.42;
  cursor: not-allowed;
  transform: none;
}

.drawing-widget__button:disabled:hover {
  border-color: var(--dw-border);
  transform: none;
}

.drawing-widget__button:focus-visible {
  outline: 3px solid rgba(55, 65, 81, 0.22);
  outline-offset: 2px;
}

.drawing-widget__button-label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.drawing-widget__button--active {
  border-color: var(--dw-primary);
  background: #f3f4f6;
  color: var(--dw-primary-dark);
  box-shadow: inset 0 0 0 1px rgba(55, 65, 81, 0.14);
}

.drawing-widget__button--primary {
  border-color: var(--dw-primary);
  background: var(--dw-primary);
  color: #ffffff;
}

.drawing-widget__button--primary:hover {
  background: var(--dw-primary-dark);
}

.drawing-widget__button--muted {
  color: #8b4e35;
}

.drawing-widget__canvas-wrap {
  position: relative;
  overflow: hidden;
  width: 100%;
  border: 1px solid var(--dw-border);
  border-radius: 18px;
  background:
    linear-gradient(45deg, rgba(0, 0, 0, 0.025) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(0, 0, 0, 0.025) 25%, transparent 25%),
    #ffffff;
}

.drawing-widget__canvas {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
  cursor: none;
  touch-action: none;
}

.drawing-widget__cursor {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 2;
  display: block;
  border: 2px solid rgba(55, 65, 81, 0.86);
  border-radius: 50%;
  background: rgba(55, 65, 81, 0.08);
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.86),
    0 8px 20px rgba(31, 41, 51, 0.15);
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 120ms ease,
    width 120ms ease,
    height 120ms ease,
    border-color 120ms ease,
    background-color 120ms ease;
}

.drawing-widget__cursor--visible {
  opacity: 1;
}

.drawing-widget__cursor--eraser {
  border-color: rgba(139, 78, 53, 0.9);
  background: rgba(139, 78, 53, 0.08);
}

.drawing-widget__error {
  margin: 0;
  color: #8b2d21;
  font-weight: 700;
}

@media (max-width: 640px) {
  .drawing-widget {
    max-width: 100%;
    padding: 10px;
    border-radius: 18px;
  }

  .drawing-widget__toolbar {
    align-items: stretch;
    gap: 7px;
    padding: 8px;
    border-radius: 16px;
  }

  .drawing-widget__control {
    min-height: 42px;
    padding: 7px 10px;
  }

  .drawing-widget__control--color {
    flex: 1 1 142px;
  }

  .drawing-widget__control--size {
    flex: 2 1 190px;
    justify-content: space-between;
  }

  .drawing-widget__palette {
    right: 0;
    left: auto;
    grid-template-columns: repeat(5, 30px);
    gap: 9px;
  }

  .drawing-widget__swatch {
    width: 30px;
    height: 30px;
  }

  .drawing-widget__button {
    width: 42px;
    height: 42px;
    flex: 1 1 42px;
    min-width: 42px;
    border-radius: 13px;
  }

  .drawing-widget__size {
    flex: 1;
    width: auto;
  }

  .drawing-widget__canvas-wrap {
    border-radius: 15px;
  }
}

@media (max-width: 380px) {
  .drawing-widget__label {
    font-size: 12px;
  }

  .drawing-widget__control--color,
  .drawing-widget__control--size {
    flex-basis: 100%;
  }

  .drawing-widget__button {
    flex-basis: calc(25% - 6px);
  }
}
