:root {
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --secondary: #8b5cf6;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --info: #3b82f6;
  
  --bg: #f8fafc;
  --bg-secondary: #ffffff;
  --text: #1e293b;
  --text-secondary: #64748b;
  --border: #e2e8f0;
  --shadow: rgba(0, 0, 0, 0.1);
  --shadow-lg: rgba(0, 0, 0, 0.15);
  
  --gradient-1: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  --gradient-2: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
  --gradient-3: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
  --gradient-instagram: linear-gradient(45deg, #f09433 0%, #e6683c 25%, #dc2743 50%, #cc2366 75%, #bc1888 100%);
}

body.dark {
  --bg: #0f172a;
  --bg-secondary: #1e293b;
  --text: #f1f5f9;
  --text-secondary: #94a3b8;
  --border: #334155;
  --shadow: rgba(0, 0, 0, 0.3);
  --shadow-lg: rgba(0, 0, 0, 0.5);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Roboto', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  transition: background 0.3s, color 0.3s;
}

.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 20px;
}

/* Theme Toggle */
.theme-toggle {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 1000;
}

.theme-btn {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  border: none;
  background: var(--gradient-1);
  color: white;
  font-size: 1.3rem;
  cursor: pointer;
  box-shadow: 0 4px 15px var(--shadow);
  transition: transform 0.3s, box-shadow 0.3s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.theme-btn:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 20px var(--shadow-lg);
}

.sun-icon {
  display: none;
}

body.dark .moon-icon {
  display: none;
}

body.dark .sun-icon {
  display: block;
}

/* Header */
.header {
  background: var(--gradient-1);
  color: white;
  padding: 30px 0;
  margin-bottom: 40px;
  box-shadow: 0 4px 20px var(--shadow);
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 20px;
}

.main-title {
  font-size: 3rem;
  font-weight: 700;
  margin-bottom: 5px;
  display: flex;
  align-items: center;
  gap: 5px;
}

.du-text {
  color: #fff;
  text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}

.write-text {
  background: linear-gradient(45deg, #ffd700, #ffed4e);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.subtitle {
  font-size: 1.1rem;
  opacity: 0.95;
}

.creator-info {
  text-align: right;
}

.made-by {
  margin-bottom: 10px;
  font-size: 1rem;
}

.heart-icon {
  color: #ff6b6b;
  animation: heartbeat 1.5s infinite;
}

@keyframes heartbeat {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.2); }
}

.social-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: 25px;
  text-decoration: none;
  font-weight: 600;
  transition: all 0.3s;
  border: none;
  cursor: pointer;
}

.instagram-btn {
  background: var(--gradient-instagram);
  color: white;
  box-shadow: 0 4px 15px rgba(188, 24, 136, 0.4);
}

.instagram-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(188, 24, 136, 0.6);
}

/* Cards */
.card {
  background: var(--bg-secondary);
  border-radius: 16px;
  padding: 30px;
  box-shadow: 0 4px 20px var(--shadow);
  transition: transform 0.3s, box-shadow 0.3s;
}

.card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 30px var(--shadow-lg);
}

.section-title {
  font-size: 1.8rem;
  margin-bottom: 20px;
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: 10px;
}

.section-title small {
  font-size: 0.7rem;
  color: var(--text-secondary);
  font-weight: normal;
}

/* Main Grid */
.main-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 30px;
  margin-bottom: 40px;
}

.input-label {
  display: block;
  margin-bottom: 15px;
  font-weight: 500;
  color: var(--text-secondary);
}

/* Paper */
.paper-wrapper {
  margin: 20px 0;
  display: flex;
  justify-content: center;
}

.page-paper {
  width: 100%;
  max-width: 420px;
  aspect-ratio: 8.3 / 11.7;
  background: #ffffff;
  border: 1px solid var(--border);
  position: relative;
  box-shadow: 0 8px 30px var(--shadow);
  border-radius: 4px;
  overflow: hidden;
}

.content-area {
  position: relative;
  height: calc(100% - 50px);
}

.paper-content {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 10px;
  font-family: var(--handwriting-font, 'Homemade Apple');
  color: var(--ink-color, #000f55);
  font-size: 10pt;
  line-height: 1.5em;
  outline: none;
  overflow-y: auto;
  z-index: 1;
}

.page-paper.lines .paper-content {
  background-image: repeating-linear-gradient(
    transparent 0,
    transparent calc(1.5em - 1px),
    #ddd calc(1.5em - 1px),
    #ddd 1.5em
  );
  background-size: 100% 1.5em;
  background-position: 0 0;
}

.top-margin {
  height: 50px;
  border-bottom: 2px solid #ffc0cb;
  display: none;
  outline: none;
}

.left-margin {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 50px;
  border-right: 2px solid #ffc0cb;
  display: none;
  outline: none;
  z-index: 2;
}

.page-paper.margined .top-margin {
  display: block;
}

.page-paper.margined .left-margin {
  display: block;
}

.page-paper.margined .paper-content {
  left: 55px;
  top: 5px;
  right: 5px;
  padding: 5px;
}

.paper-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
  display: none;
  z-index: 10;
}

.paper-overlay.active {
  display: block;
  background: linear-gradient(135deg, rgba(0,0,0,0.1), transparent);
}

/* Settings */
.settings-group {
  margin-bottom: 25px;
  padding: 20px;
  background: var(--bg);
  border-radius: 12px;
  border: 1px solid var(--border);
}

.group-title {
  font-size: 1.1rem;
  margin-bottom: 15px;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}

.hint-text {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 20px;
  padding: 10px;
  background: var(--warning);
  background: rgba(245, 158, 11, 0.1);
  border-left: 3px solid var(--warning);
  border-radius: 4px;
}

/* Inputs */
.select-input,
.number-input {
  width: 100%;
  padding: 12px 15px;
  border: 2px solid var(--border);
  border-radius: 8px;
  background: var(--bg-secondary);
  color: var(--text);
  font-size: 1rem;
  transition: border-color 0.3s, box-shadow 0.3s;
}

.select-input:focus,
.number-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 15px;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 15px;
}

.input-group label {
  display: block;
  margin-bottom: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-secondary);
}

/* File Upload */
.file-label {
  display: block;
  margin-top: 15px;
  padding: 12px 20px;
  background: var(--gradient-3);
  color: white;
  border-radius: 8px;
  cursor: pointer;
  text-align: center;
  transition: transform 0.3s;
  font-weight: 500;
}

.file-label:hover {
  transform: translateY(-2px);
}

.file-input {
  display: none;
}

/* Checkboxes */
.checkbox-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 15px;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-weight: 500;
}

.checkbox-label input[type="checkbox"] {
  display: none;
}

.checkbox-custom {
  width: 24px;
  height: 24px;
  border: 2px solid var(--border);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s;
}

.checkbox-label input[type="checkbox"]:checked + .checkbox-custom {
  background: var(--primary);
  border-color: var(--primary);
}

.checkbox-label input[type="checkbox"]:checked + .checkbox-custom::after {
  content: "✓";
  color: white;
  font-weight: bold;
}

/* Buttons */
.generate-btn {
  width: 100%;
  padding: 16px 32px;
  background: var(--gradient-1);
  color: white;
  border: none;
  border-radius: 12px;
  font-size: 1.2rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.3s;
  box-shadow: 0 4px 15px rgba(99, 102, 241, 0.4);
  margin-top: 20px;
}

.generate-btn:hover {
  transform: translateY(-3px);
  box-shadow: 0 6px 25px rgba(99, 102, 241, 0.6);
}

.secondary-btn {
  padding: 12px 24px;
  background: var(--text-secondary);
  color: white;
  border: none;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s;
  margin-top: 15px;
}

.secondary-btn:hover {
  background: var(--text);
  transform: translateY(-2px);
}

/* Output */
.output-container {
  min-height: 300px;
  padding: 30px;
  border: 3px dashed var(--border);
  border-radius: 16px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 30px;
}

.empty-state {
  text-align: center;
  color: var(--text-secondary);
}

.empty-icon {
  font-size: 4rem;
  opacity: 0.3;
  margin-bottom: 15px;
}

.output-img-wrapper {
  position: relative;
  animation: fadeIn 0.5s;
}

@keyframes fadeIn {
  from { opacity: 0; transform: scale(0.9); }
  to { opacity: 1; transform: scale(1); }
}

.output-img-wrapper img {
  max-width: 320px;
  width: 100%;
  border-radius: 12px;
  box-shadow: 0 8px 30px var(--shadow-lg);
  transition: transform 0.3s;
}

.output-img-wrapper:hover img {
  transform: scale(1.02);
}

.img-close-btn {
  position: absolute;
  top: -12px;
  right: -12px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--danger);
  color: white;
  border: 3px solid var(--bg-secondary);
  font-size: 1.2rem;
  cursor: pointer;
  transition: all 0.3s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.img-close-btn:hover {
  background: #dc2626;
  transform: rotate(90deg);
}

.img-download {
  display: block;
  margin-top: 12px;
  padding: 10px 20px;
  background: var(--success);
  color: white;
  text-decoration: none;
  border-radius: 8px;
  text-align: center;
  font-weight: 600;
  transition: all 0.3s;
}

.img-download:hover {
  background: #059669;
  transform: translateY(-2px);
}

.output-actions {
  display: flex;
  justify-content: center;
  gap: 20px;
  margin-top: 30px;
  flex-wrap: wrap;
}

.action-btn {
  padding: 14px 28px;
  border: none;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.pdf-btn {
  background: var(--success);
  color: white;
  box-shadow: 0 4px 15px rgba(16, 185, 129, 0.4);
}

.pdf-btn:hover {
  background: #059669;
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(16, 185, 129, 0.6);
}

.delete-btn {
  background: var(--danger);
  color: white;
  box-shadow: 0 4px 15px rgba(239, 68, 68, 0.4);
}

.delete-btn:hover {
  background: #dc2626;
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(239, 68, 68, 0.6);
}

/* Modal */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  z-index: 2000;
  justify-content: center;
  align-items: center;
  backdrop-filter: blur(5px);
}

.modal.show {
  display: flex;
}

.modal-content {
  background: var(--bg-secondary);
  padding: 40px;
  border-radius: 20px;
  max-width: 90%;
  max-height: 90%;
  position: relative;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.modal-close {
  position: absolute;
  top: 15px;
  right: 15px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--danger);
  color: white;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  transition: all 0.3s;
}

.modal-close:hover {
  background: #dc2626;
  transform: rotate(90deg);
}

.modal-title {
  font-size: 1.8rem;
  margin-bottom: 20px;
  color: var(--primary);
}

#draw-canvas {
  border: 3px solid var(--border);
  background: white;
  cursor: crosshair;
  display: block;
  border-radius: 12px;
  margin: 20px 0;
  max-width: 100%;
}

.draw-actions {
  display: flex;
  gap: 15px;
  flex-wrap: wrap;
}

.draw-actions button {
  flex: 1;
  min-width: 180px;
}

.primary-btn {
  background: var(--primary);
  color: white;
}

.success-btn {
  background: var(--success);
  color: white;
}

.danger-btn {
  background: var(--danger);
  color: white;
}

/* Loading */
.loading-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  z-index: 3000;
  justify-content: center;
  align-items: center;
  backdrop-filter: blur(10px);
}

.loading-overlay.show {
  display: flex;
}

.loading-spinner {
  text-align: center;
  color: white;
}

.loading-spinner i {
  font-size: 4rem;
  margin-bottom: 20px;
}

.loading-spinner p {
  font-size: 1.3rem;
  font-weight: 600;
}

/* Footer */
.footer {
  background: var(--bg-secondary);
  padding: 40px 0;
  margin-top: 60px;
  border-top: 1px solid var(--border);
  text-align: center;
}

.footer-text {
  margin-bottom: 20px;
  font-size: 1.1rem;
}

.social-links {
  display: flex;
  justify-content: center;
  gap: 20px;
}

.social-link {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: var(--gradient-1);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  text-decoration: none;
  transition: all 0.3s;
}

.social-link:hover {
  transform: translateY(-5px);
  box-shadow: 0 8px 20px var(--shadow-lg);
}

/* Responsive */
@media (max-width: 1024px) {
  .main-grid {
    grid-template-columns: 1fr;
  }
  
  .header-content {
    flex-direction: column;
    text-align: center;
  }
  
  .creator-info {
    text-align: center;
  }
  
  .main-title {
    font-size: 2.5rem;
    justify-content: center;
  }
}

@media (max-width: 768px) {
  .container {
    padding: 0 15px;
  }
  
  .card {
    padding: 20px;
  }
  
  .main-title {
    font-size: 2rem;
  }
  
  .grid-2,
  .grid-3,
  .checkbox-grid {
    grid-template-columns: 1fr;
  }
  
  .page-paper {
    max-width: 100%;
  }
  
  .output-img-wrapper img {
    max-width: 250px;
  }
  
  .modal-content {
    padding: 20px;
  }
  
  #draw-canvas {
    width: 100%;
    height: 300px;
  }
  
  .draw-actions button {
    min-width: 100%;
  }
  
  .theme-toggle {
    top: 10px;
    right: 10px;
  }
  
  .theme-btn {
    width: 45px;
    height: 45px;
  }
}

@media (max-width: 480px) {
  .main-title {
    font-size: 1.8rem;
  }
  
  .section-title {
    font-size: 1.4rem;
  }
  
  .output-actions {
    flex-direction: column;
  }
  
  .action-btn {
    width: 100%;
  }
}