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

:root {
  /* Modern, refined color palette */
  --primary: #2563eb;
  --primary-dark: #1e40af;
  --accent: #7c3aed;
  --success: #10b981;
  --error: #ef4444;

  /* Neutral colors */
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;

  /* UI colors */
  --bg-primary: #ffffff;
  --bg-secondary: var(--gray-50);
  --text-primary: var(--gray-900);
  --text-secondary: var(--gray-600);
  --border: var(--gray-200);

  /* Shadows */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);

  /* Typography */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: "Inter", var(--font-sans);

  /* Spacing */
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-display);
  background: var(--bg-secondary);
  color: var(--text-primary);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Layout */
.page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.container {
  width: 100%;
  max-width: 680px;
  margin: 0 auto;
  padding: 0 20px;
}

/* Header */
header {
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border);
  padding: 20px 0;
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(10px);
  background: rgba(255, 255, 255, 0.8);
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.logo {
  font-size: 24px;
  font-weight: 700;
  color: var(--primary);
  text-decoration: none;
  letter-spacing: -0.02em;
}

.nav {
  display: flex;
  gap: 24px;
  align-items: center;
}

.nav a {
  color: var(--text-secondary);
  text-decoration: none;
  font-weight: 500;
  font-size: 15px;
  transition: color 0.2s ease;
}

.nav a:hover {
  color: var(--primary);
}

/* Main Content */
main {
  flex: 1;
  padding: 48px 0;
}

/* Hero Section */
.hero {
  text-align: center;
  margin-bottom: 48px;
}

.hero h1 {
  font-size: clamp(32px, 5vw, 48px);
  font-weight: 800;
  line-height: 1.1;
  margin-bottom: 16px;
  letter-spacing: -0.03em;
  color: var(--text-primary);
}

.hero p {
  font-size: 18px;
  color: var(--text-secondary);
  max-width: 560px;
  margin: 0 auto 32px;
  line-height: 1.7;
}

/* Generator Card */
.generator {
  background: var(--bg-primary);
  border-radius: var(--radius-xl);
  padding: 40px;
  box-shadow: var(--shadow-lg);
  margin-bottom: 48px;
}

/* Form Styles */
form {
  display: flex;
  flex-direction: column;
  gap: 20px;
  margin-bottom: 32px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

label {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

input[type="url"],
input[type="text"],
select {
  width: 100%;
  padding: 12px 16px;
  font-size: 16px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-display);
  transition: all 0.2s ease;
}

input[type="url"]:focus,
input[type="text"]:focus,
select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

input[type="color"] {
  width: 100%;
  height: 48px;
  padding: 4px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.2s ease;
}

input[type="color"]:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 16px;
}

/* Buttons */
button,
.btn {
  padding: 14px 24px;
  font-size: 16px;
  font-weight: 600;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: var(--font-display);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

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

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-dark);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

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

.btn-secondary {
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--gray-100);
  border-color: var(--gray-300);
}

/* Preview */
.preview {
  background: var(--gray-50);
  border-radius: var(--radius-lg);
  padding: 40px;
  min-height: 360px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 24px;
  border: 2px dashed var(--border);
}

.preview canvas,
.preview svg {
  max-width: 100%;
  height: auto;
  filter: drop-shadow(var(--shadow));
}

.hidden {
  display: none !important;
}

/* Actions */
.actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

@media (min-width: 640px) {
  .actions {
    grid-template-columns: 2fr 1fr 1fr;
  }
}

/* Status Message */
.status {
  text-align: center;
  font-size: 14px;
  font-weight: 500;
  min-height: 20px;
  margin-top: 16px;
}

.status[style*="color: rgb(16, 185, 129)"],
.status[style*="color: #38f8c0"] {
  color: var(--success) !important;
}

.status[style*="color: rgb(239, 68, 68)"],
.status[style*="color: #f87171"] {
  color: var(--error) !important;
}

/* Features Section */
.features {
  margin-top: 64px;
  text-align: center;
}

.features h2 {
  font-size: 32px;
  font-weight: 700;
  margin-bottom: 40px;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.feature-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 24px;
  max-width: 900px;
  margin: 0 auto;
}

.feature {
  padding: 24px;
  background: var(--bg-primary);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  transition: all 0.2s ease;
}

.feature:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.feature h3 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text-primary);
}

.feature p {
  font-size: 15px;
  color: var(--text-secondary);
  line-height: 1.6;
}

/* Footer */
footer {
  background: var(--bg-primary);
  border-top: 1px solid var(--border);
  padding: 32px 0;
  margin-top: 64px;
  text-align: center;
}

.footer-content {
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-items: center;
}

.footer-links {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
  justify-content: center;
}

.footer-links a {
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 14px;
  transition: color 0.2s ease;
}

.footer-links a:hover {
  color: var(--primary);
}

footer p {
  font-size: 14px;
  color: var(--text-secondary);
}

/* History Sidebar */
.sidebar {
  position: fixed;
  top: 0;
  right: 0;
  width: 320px;
  height: 100vh;
  background: var(--bg-primary);
  box-shadow: var(--shadow-xl);
  padding: 24px;
  transform: translateX(100%);
  transition: transform 0.3s ease;
  z-index: 200;
  overflow-y: auto;
}

.sidebar[data-visible="true"] {
  transform: translateX(0);
}

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

.sidebar-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
}

.sidebar-clear {
  background: none;
  border: none;
  color: var(--primary);
  font-weight: 600;
  cursor: pointer;
  padding: 8px;
  font-size: 14px;
}

.sidebar-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 32px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  transition: all 0.2s ease;
}

.sidebar-close:hover {
  background: var(--gray-100);
  color: var(--text-primary);
}

.sidebar-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sidebar-list li {
  padding: 16px;
  background: var(--gray-50);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.sidebar-list .meta {
  margin-bottom: 12px;
}

.sidebar-list .meta strong {
  display: block;
  font-size: 14px;
  margin-bottom: 4px;
  word-break: break-all;
  color: var(--text-primary);
}

.sidebar-list .meta span {
  font-size: 12px;
  color: var(--text-secondary);
}

.sidebar-list .actions {
  display: flex;
  gap: 8px;
}

.sidebar-list button {
  padding: 6px 12px;
  font-size: 13px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-weight: 500;
}

.sidebar-list button:hover {
  background: var(--gray-100);
}

.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  z-index: 150;
}

.sidebar-overlay[data-visible="true"] {
  opacity: 1;
  pointer-events: auto;
}

.history-btn {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  padding: 8px 16px;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 14px;
  color: var(--text-primary);
}

.history-btn:hover {
  background: var(--gray-50);
}

/* Dialog */
dialog {
  border: none;
  border-radius: var(--radius-lg);
  padding: 32px;
  max-width: 400px;
  box-shadow: var(--shadow-xl);
  background: var(--bg-primary);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.5);
}

dialog form {
  gap: 16px;
}

dialog button {
  padding: 10px 20px;
}

/* Responsive */
@media (max-width: 768px) {
  .generator {
    padding: 24px;
  }

  .hero h1 {
    font-size: 32px;
  }

  .hero p {
    font-size: 16px;
  }

  .sidebar {
    width: 100%;
    max-width: 320px;
  }
}

/* Animations */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.generator {
  animation: fadeIn 0.4s ease;
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Focus visible */
*:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}