:root {
  --font-heading: 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;

  --bg-gradient: radial-gradient(circle at 15% 15%, #ffeef4 0%, #fff7ed 35%, #f0f4ff 75%, #fdf2f8 100%);
  --surface: rgba(255, 255, 255, 0.85);
  --surface-border: rgba(255, 255, 255, 0.6);
  --surface-shadow: 0 20px 45px -15px rgba(220, 160, 190, 0.25), 0 0 0 1px rgba(255, 255, 255, 0.9);
  
  --primary: #ec4899;
  --primary-hover: #db2777;
  --primary-light: #fce7f3;
  --secondary: #6366f1;
  
  --text-main: #1e293b;
  --text-muted: #64748b;
  --text-subtle: #94a3b8;
  
  --border-color: #e2e8f0;
  --radius-lg: 20px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

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

body {
  font-family: var(--font-body);
  background: var(--bg-gradient);
  min-height: 100vh;
  color: var(--text-main);
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  padding: 24px;
  position: relative;
  overflow-x: hidden;
}

/* Ambient Decorative Blobs */
.ambient-blob {
  position: fixed;
  border-radius: 50%;
  filter: blur(80px);
  z-index: -1;
  pointer-events: none;
  opacity: 0.55;
  animation: float 14s ease-in-out infinite alternate;
}

.blob-1 {
  width: 420px;
  height: 420px;
  background: #fbcfe8;
  top: -80px;
  left: -80px;
}

.blob-2 {
  width: 480px;
  height: 480px;
  background: #fed7aa;
  bottom: -100px;
  right: -80px;
  animation-duration: 18s;
}

.blob-3 {
  width: 360px;
  height: 360px;
  background: #c7d2fe;
  top: 40%;
  left: 60%;
  animation-duration: 12s;
}

@keyframes float {
  0% { transform: translate(0px, 0px) scale(1); }
  50% { transform: translate(30px, -20px) scale(1.06); }
  100% { transform: translate(-20px, 30px) scale(0.96); }
}

/* Layout Container */
.app-container {
  max-width: 1240px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
  flex: 1;
}

/* Header */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
  padding: 10px 4px;
}

.brand-wrapper {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-icon {
  width: 48px;
  height: 48px;
  background: linear-gradient(135deg, #ec4899, #f43f5e);
  color: #fff;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 16px -4px rgba(236, 72, 153, 0.4);
}

.brand-icon svg {
  width: 26px;
  height: 26px;
}

.title-group h1 {
  font-family: var(--font-heading);
  font-size: 1.85rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, #0f172a, #334155);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.title-group p {
  font-size: 0.9rem;
  color: var(--text-muted);
}

.header-badges {
  display: flex;
  align-items: center;
  gap: 10px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 9999px;
  font-size: 0.8rem;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid rgba(226, 232, 240, 0.8);
  backdrop-filter: blur(8px);
  color: var(--text-muted);
}

.badge-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #10b981;
  box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.2);
}

/* Control Toolbar */
.toolbar-card {
  background: var(--surface);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-radius: var(--radius-lg);
  padding: 16px 20px;
  box-shadow: var(--surface-shadow);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.controls-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
}

.control-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.control-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.select-input {
  appearance: none;
  background: #ffffff;
  border: 1px solid var(--border-color);
  padding: 8px 32px 8px 12px;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-main);
  cursor: pointer;
  outline: none;
  transition: var(--transition);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2364748b'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  background-size: 16px;
}

.select-input:hover, .select-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(236, 72, 153, 0.15);
}

.btn-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 16px;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 1px solid transparent;
  transition: var(--transition);
  text-decoration: none;
  white-space: nowrap;
}

.btn svg {
  width: 17px;
  height: 17px;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), #f43f5e);
  color: #ffffff;
  box-shadow: 0 4px 12px -2px rgba(236, 72, 153, 0.35);
}

.btn-primary:hover {
  background: linear-gradient(135deg, var(--primary-hover), #e11d48);
  box-shadow: 0 6px 16px -2px rgba(236, 72, 153, 0.45);
  transform: translateY(-1px);
}

.btn-secondary {
  background: #ffffff;
  color: var(--text-main);
  border-color: var(--border-color);
}

.btn-secondary:hover {
  background: #f8fafc;
  border-color: #cbd5e1;
  transform: translateY(-1px);
}

.btn-secondary.active {
  background: var(--primary-light);
  color: var(--primary);
  border-color: var(--primary);
}

/* Visualization Main Card */
.visual-card {
  position: relative;
  background: var(--surface);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-radius: var(--radius-lg);
  box-shadow: var(--surface-shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 540px;
}

.visual-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 22px;
  border-bottom: 1px solid rgba(226, 232, 240, 0.7);
}

.visual-meta {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.meta-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(241, 245, 249, 0.9);
  padding: 4px 10px;
  border-radius: 9999px;
  font-weight: 500;
}

.meta-pill strong {
  color: var(--text-main);
}

.chart-stage {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 32px 20px;
  background: radial-gradient(circle at center, rgba(248, 250, 252, 0.7) 0%, rgba(241, 245, 249, 0.85) 100%);
  overflow-x: auto;
  width: 100%;
}

#chart-container.letter-sheet {
  background: #ffffff;
  border-radius: 6px;
  box-shadow: 0 16px 40px -10px rgba(15, 23, 42, 0.15), 0 0 0 1px rgba(203, 213, 225, 0.9);
  position: relative;
  transition: max-width 0.25s ease, aspect-ratio 0.25s ease;
}

/* 8.5 x 11 inches Letter Portrait: Height is 1.294x Width (aspect-ratio: 8.5 / 11) */
#chart-container.letter-sheet.portrait {
  width: 100%;
  max-width: 520px;
  aspect-ratio: 8.5 / 11;
}

/* 11 x 8.5 inches Letter Landscape: Width is 1.294x Height (aspect-ratio: 11 / 8.5) */
#chart-container.letter-sheet.landscape {
  width: 100%;
  max-width: 760px;
  aspect-ratio: 11 / 8.5;
}

/* Empty State / Loading State Overlay */
.chart-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(4px);
  z-index: 10;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.chart-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

.spinner {
  width: 38px;
  height: 38px;
  border: 3px solid rgba(236, 72, 153, 0.2);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Quick Word Inspector Tooltip Display */
.word-inspector {
  padding: 12px 22px;
  background: rgba(248, 250, 252, 0.8);
  border-top: 1px solid rgba(226, 232, 240, 0.7);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.825rem;
  color: var(--text-muted);
}

.inspector-highlight {
  font-weight: 600;
  color: var(--primary);
}

/* Modal for Data Editing */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(6px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.modal-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.modal-content {
  background: #ffffff;
  border-radius: var(--radius-lg);
  max-width: 600px;
  width: 100%;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
  transform: translateY(12px) scale(0.98);
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  overflow: hidden;
}

.modal-backdrop.open .modal-content {
  transform: translateY(0) scale(1);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
  font-family: var(--font-heading);
  font-size: 1.25rem;
  font-weight: 700;
}

.close-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.close-btn:hover {
  background: #f1f5f9;
  color: var(--text-main);
}

.modal-body {
  padding: 20px 24px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-body p {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.data-textarea {
  width: 100%;
  height: 280px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 12px;
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: 0.85rem;
  line-height: 1.4;
  resize: vertical;
  outline: none;
  transition: var(--transition);
}

.data-textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(236, 72, 153, 0.15);
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  background: #fafafa;
}

/* Footer */
.app-footer {
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
  padding: 12px 0 6px;
}

/* Responsive */
@media (max-width: 860px) {
  body {
    padding: 16px;
  }
  .app-header {
    flex-direction: column;
    align-items: flex-start;
  }
  .toolbar-card {
    flex-direction: column;
    align-items: stretch;
  }
  .controls-group {
    justify-content: space-between;
  }
  .control-item {
    flex: 1 1 45%;
  }
  .btn-actions {
    justify-content: stretch;
  }
  .btn-actions .btn {
    flex: 1 1 45%;
    justify-content: center;
  }
  #chart-container.letter-sheet.portrait {
    max-width: 100%;
    aspect-ratio: 8.5 / 11;
  }
  #chart-container.letter-sheet.landscape {
    max-width: 100%;
    aspect-ratio: 11 / 8.5;
  }
}

/* Print Styles for Direct US Letter Printing */
@media print {
  body {
    background: #ffffff !important;
    padding: 0 !important;
  }
  .ambient-blob,
  .app-header,
  .toolbar-card,
  .visual-topbar,
  .word-inspector,
  .app-footer,
  .modal-backdrop,
  .chart-overlay {
    display: none !important;
  }
  .app-container,
  .visual-card,
  .chart-stage {
    display: block !important;
    margin: 0 !important;
    padding: 0 !important;
    box-shadow: none !important;
    background: transparent !important;
    border: none !important;
    width: 100% !important;
    max-width: 100% !important;
  }
  #chart-container.letter-sheet {
    box-shadow: none !important;
    border: none !important;
    border-radius: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    height: 100vh !important;
    page-break-inside: avoid;
  }
  @page {
    size: letter portrait;
    margin: 0.5in;
  }
}
