@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap');

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

body {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  font-family: 'Roboto', sans-serif;
  min-height: 100vh;
  padding: 20px;
  position: relative;
}

/* Back Navigation */
.back-nav {
  position: fixed;
  top: 10px;
  right: 10px;
  z-index: 1000;
}

.back-link {
  display: inline-block;
  padding: 8px 16px;
  background: rgba(45, 45, 45, 0.85);
  color: #fff;
  text-decoration: none;
  border-radius: 4px;
  font-size: 14px;
  font-weight: 700;
  transition: all 0.3s ease;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
}

.back-link:hover {
  background: rgba(61, 61, 61, 0.9);
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

.container {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  justify-content: center;
  max-width: 100%;
  margin: 0 auto;
  gap: 15px;
  flex-wrap: wrap;
}

.toolbox {
  background: rgba(255, 255, 255, 0.95);
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  width: 200px;
  min-width: 180px;
  justify-content: flex-start;
  align-items: stretch;
  backdrop-filter: blur(10px);
  max-height: 650px;
  overflow-y: auto;
}

.tool-group {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  padding: 8px;
  background: rgba(240, 240, 240, 0.5);
  border-radius: 8px;
}

.tool-group > * {
  width: 100%;
}

/* Size control group should be horizontal */
.tool-group:first-child,
.tool-group:nth-child(3),
.tool-group:nth-child(5) {
  flex-direction: row;
  align-items: center;
  justify-content: center;
}

.tool-group:first-child > *,
.tool-group:nth-child(3) > *,
.tool-group:nth-child(5) > * {
  width: auto;
  flex: 1;
}

.btn {
  background: #fff;
  border: 2px solid #e0e0e0;
  border-radius: 6px;
  cursor: pointer;
  font-size: 16px;
  height: 36px;
  min-width: 36px;
  padding: 0 10px;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 500;
}

.btn:hover:not(:disabled) {
  background: #f0f0f0;
  border-color: #667eea;
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.btn:active:not(:disabled) {
  transform: translateY(0);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-danger {
  background: #ff4444;
  color: white;
  border-color: #cc0000;
}

.btn-danger:hover:not(:disabled) {
  background: #ff6666;
  border-color: #ff0000;
}

.btn-success {
  background: #4caf50;
  color: white;
  border-color: #45a049;
}

.btn-success:hover:not(:disabled) {
  background: #66bb6a;
  border-color: #4caf50;
}

.btn-primary {
  background: #2196f3;
  color: white;
  border-color: #1976d2;
}

.btn-primary:hover:not(:disabled) {
  background: #42a5f5;
  border-color: #2196f3;
}

.tool-btn.active {
  background: #667eea;
  color: white;
  border-color: #5568d3;
}

.size-display {
  font-size: 14px;
  font-weight: 700;
  text-align: center;
  color: #333;
  padding: 6px;
  background: white;
  border-radius: 4px;
  min-width: 30px;
}

.color-picker {
  width: 100%;
  height: 36px;
  border: 2px solid #e0e0e0;
  border-radius: 6px;
  cursor: pointer;
  padding: 0;
  background: none;
}

.color-picker::-webkit-color-swatch-wrapper {
  padding: 0;
}

.color-picker::-webkit-color-swatch {
  border: none;
  border-radius: 4px;
}

.color-label,
.tool-label {
  font-size: 11px;
  color: #666;
  text-align: center;
  font-weight: 500;
  margin-bottom: 2px;
}

.select-tool {
  padding: 6px 10px;
  border: 2px solid #e0e0e0;
  border-radius: 6px;
  background: white;
  font-size: 13px;
  cursor: pointer;
  font-family: 'Roboto', sans-serif;
  transition: all 0.2s ease;
  height: 36px;
}

.select-tool:hover {
  border-color: #667eea;
}

.select-tool:focus {
  outline: none;
  border-color: #667eea;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

canvas {
  border: 3px solid #fff;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
  background: white;
  cursor: crosshair;
  touch-action: none;
  max-width: 100%;
  height: auto;
}

canvas:active {
  cursor: grabbing;
}

/* Responsive Design */
@media (max-width: 1024px) {
  .container {
    flex-direction: column;
    align-items: center;
  }

  .toolbox {
    width: 100%;
    max-width: 800px;
    flex-direction: row;
    flex-wrap: wrap;
    max-height: none;
    overflow-y: visible;
  }

  .tool-group {
    flex-direction: row;
    flex: 1;
    min-width: auto;
  }

  .tool-group > * {
    width: auto;
  }
}

@media (max-width: 768px) {
  body {
    padding: 10px;
  }

  .toolbox {
    padding: 10px;
    gap: 8px;
  }

  .tool-group {
    padding: 8px;
    gap: 5px;
  }

  .btn {
    height: 36px;
    min-width: 36px;
    font-size: 16px;
    padding: 0 8px;
  }

  .color-picker {
    width: 36px;
    height: 36px;
  }

  .size-display {
    font-size: 14px;
  }

  canvas {
    border-width: 2px;
  }
}

@media (max-width: 480px) {
  .toolbox {
    flex-direction: column;
  }

  .tool-group {
    flex-direction: row;
    justify-content: center;
  }

  .back-link {
    font-size: 12px;
    padding: 6px 12px;
  }
}
