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

/* Body */
body {
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  background: linear-gradient(
    135deg,
    #667eea 0%,
    #764ba2 50%,
    #9f0caf 100%
  );
  min-height: 100vh;
  padding: 0px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.container {
  max-width: 1200px;
  width: 100%;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(20px);
  border-radius: 20px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.15);
  overflow: hidden;
  animation: fadeInUp 0.8s ease-out;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.header {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 0px;
  margin: 0px;
  text-align: center;
  position: relative;
}

.header::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, #f093fb, #f5576c, #4facfe, #00f2fe);
}

.header h1 {
  font-size: clamp(1.8rem, 5vw, 3rem);
  font-weight: 700;
  margin-bottom: 8px;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

.header p {
  font-size: clamp(0.9rem, 2.5vw, 1.2rem);
  opacity: 0.9;
}

.main-content {
  padding: 20px 15px;
}

/* Toolbar */
.toolbar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 10px;
  background: #f8f9fa;
  padding: 20px 15px;
  border-radius: 15px;
  box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.05);
}

.color-palette {
  display: flex;
  flex-wrap: wrap;
  gap: 15px;
  align-items: center;
  justify-content: center;
}

.color-btn,
.eraser-btn {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  position: relative;
  touch-action: manipulation;
}

.color-btn:hover,
.eraser-btn:hover {
  transform: scale(1.1);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.25);
}

.color-btn.active {
  transform: scale(1.15);
  box-shadow: 0 0 0 3px white, 0 0 0 5px currentColor;
}

/* Color Buttons */
.color-btn.black {
  background-color: #2c3e50;
}
.color-btn.red { background-color: #e74c3c;
}
.color-btn.pink { background-color: #e91e63;
}
.color-btn.purple { background-color: #9b59b6;
}
.color-btn.brown { background-color: #8d4e25;
}
.color-btn.blue { background-color: #3498db;
}
.color-btn.teal { background-color: #1abc9c;
}
.color-btn.green { background-color: #27ae60;
}
.color-btn.lime { background-color: #8bc34a;
}
.color-btn.yellow { background-color: #f1c40f;
}
.color-btn.orange { background-color: #f39c12;
}

/* Eraser Button */
.eraser-btn {
  border: 2px solid #6c757d;
  background: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}

.eraser-btn.active {
  transform: scale(1.15);
  box-shadow: 0 0 0 3px white, 0 0 0 5px #6c757d;
  background: #f8f9fa;
}

.stroke-control {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 15px;
}

.stroke-control label {
  font-weight: 600;
  color: #555;
  font-size: 14px;
}

.stroke-slider {
  width: 120px;
  height: 6px;
  background: linear-gradient(90deg, #667eea, #764ba2);
  border-radius: 3px;
  outline: none;
  touch-action: manipulation;
}

.stroke-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  background: #667eea;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

/* Stroke Display */
.stroke-display {
  background: #870f0f;
  color: white;
  padding: 8px 12px;
  border-radius: 20px;
  font-weight: 600;
  min-width: 50px;
  text-align: center;
  font-size: 14px;
}

.action-buttons {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 10px;
}

/* Buttons */
.btn {
  padding: 14px 20px;
  border: none;
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  touch-action: manipulation;
  white-space: nowrap;
}

/* Disabled State */
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
}

/* Reset Button */
.btn-reset {
  background: linear-gradient(135deg, #ff6b6b, #ff5252);
  color: white;
}
.btn-save {
  background: linear-gradient(135deg, #4facfe, #00f2fe);
  color: white;
}
.btn-clear {
  background: linear-gradient(135deg, #ff9a56, #ff6b6b);
  color: white;
}
.btn-calculate {
  background: linear-gradient(135deg, #43e97b, #38f9d7);
  color: white;
}
.btn-undo {
  background: linear-gradient(135deg, #ffeaa7, #fab1a0);
  color: #2d3436;
}
.btn-redo {
  background: linear-gradient(135deg, #fd79a8, #fdcb6e);
  color: white;
}
.btn-erase {
  background: linear-gradient(135deg, #a29bfe, #6c5ce7);
  color: white;
}

.btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.2);
}

.canvas-section {
  display: flex;
  flex-direction: column;
  gap: 20px;
  margin-bottom: 20px;
}

.canvas-container {
  background: white;
  border-radius: 15px;
  padding: 15px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
  border: 2px solid #e9ecef;
}

/* Drawing Canvas */
#drawingCanvas {
  width: 100%;
  height: 60vh;
  min-height: 300px;
  max-height: 500px;
  border: 2px dashed #dee2e6;
  border-radius: 12px;
  cursor: crosshair;
  touch-action: none;
  background: #fafafa;
  transition: border-color 0.3s ease;
}

#drawingCanvas:hover {
  border-color: #667eea;
}

/* Eraser Mode */
#drawingCanvas.eraser-mode {
  cursor: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M7 21h10"/><path d="M12 21v-9"/><path d="M3 7l6 6 2-2-6-6c-1-1-3 1-2 2z"/></svg>')
      10 10,
    auto;
}

.results-panel {
  background: white;
  border-radius: 15px;
  padding: 10px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
  border: 2px solid #e9ecef;
}

.results-header {
  display: flex;
  align-items: center;
  gap: 15px;
  margin-bottom: 15px;
  padding-bottom: 12px;
  border-bottom: 2px solid #f1f3f4;
}

.results-header h3 {
  color: #667eea;
  font-size: clamp(1.1rem, 3vw, 1.4rem);
  font-weight: 700;
}

.status-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #ddd;
  transition: all 0.3s ease;
  flex-shrink: 0;
}

.status-dot.active {
  background: #43e97b;
  box-shadow: 0 0 10px rgba(67, 233, 123, 0.5);
}

.status-dot.processing {
  background: #ffa500;
  animation: pulse 1.5s infinite;
}
.status-dot.error-message {
  background: #ff4c4c;
  box-shadow: 0 0 10px rgba(255, 76, 76, 0.5);
}

@keyframes pulse {
  0%,
  100% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.3);
    opacity: 0.7;
  }
}

.result-content {
  background: #f8f9fa;
  border-radius: 12px;
  padding: 15px;
  min-height: 200px;
  max-height: 400px;
  overflow-y: auto;
  font-size: clamp(0.9rem, 2.5vw, 1.05rem);
  line-height: 1.6;
}

.placeholder-text {
  text-align: center;
  color: #6c757d;
  font-style: italic;
  padding: 30px 15px;
}

.loading-animation {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  padding: 30px 15px;
}

.spinner {
  width: 35px;
  height: 35px;
  border: 4px solid #f3f3f3;
  border-top: 4px solid #667eea;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

.solution-text {
  color: #2c3e50;
}

.solution-text h4 {
  color: #667eea;
  margin: 15px 0 8px 0;
  font-size: clamp(1rem, 2.5vw, 1.2rem);
}

.solution-text .step {
  background: white;
  margin: 10px 0;
  padding: 15px;
  border-radius: 8px;
  border-left: 4px solid #667eea;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.error-message {
  background: #ffe6e6;
  color: #d32f2f;
  padding: 15px;
  border-radius: 12px;
  border-left: 4px solid #d32f2f;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.footer {
  text-align: center;
  padding: 25px 15px;
  background: #f8f9fa;
  color: #6c757d;
  border-radius: 0 0 20px 20px;
  font-size: clamp(0.8rem, 2vw, 0.9rem);
  line-height: 1.5;
}

.footer p {
  margin: 5px 0;
}

.developer-name {
  color: #667eea;
  font-weight: 600;
}

/* Desktop and larger screens */
@media (min-width: 768px) {
  body {
    padding: 20px;
  }
  .container {
    border-radius: 25px;
  }
  .header {
    padding: 30px;
  }
  .main-content {
    padding: 40px;
  }
  .toolbar {
    flex-direction: row;
    align-items: center;
  }
  .color-palette {
    justify-content: flex-start;
  }
  .stroke-control {
    margin-left: auto;
  }
  .action-buttons {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-start;
  }
  .btn {
    min-width: 120px;
    flex: 0 0 auto;
  }
  .canvas-section {
    display: grid;
    grid-template-columns: 1fr 350px;
    gap: 30px;
  }
  #drawingCanvas {
    height: 500px;
  }
}

/* Very small screens */
@media (max-width: 480px) {
  body {
    padding: 5px;
  }
  .container {
    border-radius: 15px;
  }
  .header {
    padding: 15px 10px;
  }
  .main-content {
    padding: 15px 10px;
  }
  .toolbar {
    padding: 15px 10px;
    gap: 15px;
  }
  .color-palette {
    gap: 8px;
  }
  .color-btn,
  .eraser-btn {
    width: 35px;
    height: 35px;
  }
  .btn {
    padding: 12px 16px;
    font-size: 0.8rem;
  }
  .action-buttons {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
  .canvas-container,
  .results-panel {
    padding: 12px;
  }
  #drawingCanvas {
    min-height: 250px;
  }
  .result-content {
    padding: 12px;
    min-height: 150px;
  }
  .footer {
    padding: 20px 10px;
  }
}

/* Landscape orientation on mobile */
@media (max-height: 500px) and (orientation: landscape) {
  #drawingCanvas {
    height: 40vh;
    min-height: 200px;
  }
  .result-content {
    max-height: 200px;
  }
}

/* Touch improvements */
@media (hover: none) and (pointer: coarse) {
  .btn:hover {
    transform: none;
  }
  .color-btn:hover,
  .eraser-btn:hover {
    transform: none;
  }
  .btn:active {
    transform: scale(0.98);
  }
  .color-btn:active,
  .eraser-btn:active {
    transform: scale(0.95);
  }
}