:root {
  --primary: #6366f1;
  --primary-light: #818cf8;
  --primary-dark: #4f46e5;
  --secondary: #10b981;
  --accent: #f59e0b;
  --warning: #ef4444;
  --bg-primary: #f8fafc;
  --bg-secondary: #ffffff;
  --bg-card: #ffffff;
  --text-primary: #1f2937;
  --text-secondary: #374151;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --border-light: #f3f4f6;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow: 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);
  --radius: 12px;
  --radius-lg: 16px;
  --example-bg: #f3f4f6;
  --example-text: #374151;
  --example-border: #d1d5db;
}

[data-theme="dark"] {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-card: #334155;
  --text-primary: #f1f5f9;
  --text-secondary: #e2e8f0;
  --text-muted: #cbd5e1;
  --border: #475569;
  --border-light: #374151;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -1px rgba(0, 0, 0, 0.2);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.3), 0 4px 6px -2px rgba(0, 0, 0, 0.2);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.3), 0 10px 10px -5px rgba(0, 0, 0, 0.2);
  --example-bg: #374151;
  --example-text: #e2e8f0;
  --example-border: #4b5563;
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  transition: all 0.3s ease;
}

.header {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 50%, var(--secondary) 100%);
  color: white;
  padding: 4rem 1rem;
  text-align: center;
  position: relative;
  overflow: hidden;
}

.header::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><defs><pattern id="grain" width="100" height="100" patternUnits="userSpaceOnUse"><circle cx="25" cy="25" r="1" fill="white" opacity="0.1"/><circle cx="75" cy="75" r="1" fill="white" opacity="0.1"/><circle cx="50" cy="10" r="0.5" fill="white" opacity="0.1"/><circle cx="10" cy="60" r="0.5" fill="white" opacity="0.1"/><circle cx="90" cy="40" r="0.5" fill="white" opacity="0.1"/></pattern></defs><rect width="100" height="100" fill="url(%23grain)"/></svg>');
  pointer-events: none;
}

.header h1 {
  font-size: 3rem;
  font-weight: 800;
  margin-bottom: 1rem;
  letter-spacing: -0.025em;
  position: relative;
  z-index: 1;
}

.header .subtitle {
  font-size: 1.25rem;
  opacity: 0.95;
  max-width: 900px;
  margin: 0 auto 2rem auto;
  font-weight: 400;
  position: relative;
  z-index: 1;
}

.header-link {
  display: inline-block;
  background: rgba(255,255,255,0.15);
  border: 2px solid rgba(255,255,255,0.3);
  color: white;
  padding: 1rem 2rem;
  border-radius: var(--radius);
  text-decoration: none;
  font-weight: 600;
  transition: all 0.3s ease;
  backdrop-filter: blur(20px);
  position: relative;
  z-index: 1;
}

.header-link:hover {
  background: rgba(255,255,255,0.25);
  border-color: rgba(255,255,255,0.5);
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(0,0,0,0.2);
}

.theme-toggle {
  position: fixed;
  top: 1.5rem;
  right: 1.5rem;
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.2);
  color: white;
  padding: 0.875rem;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1.25rem;
  z-index: 1000;
  transition: all 0.3s ease;
  backdrop-filter: blur(20px);
  box-shadow: var(--shadow);
}

.theme-toggle:hover {
  background: rgba(255,255,255,0.25);
  transform: scale(1.1);
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 3rem 1rem;
}

.card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
  overflow: hidden;
  backdrop-filter: blur(10px);
}

/* How This Works Cards */
.how-it-works {
  margin-bottom: 3rem;
}

.how-it-works h2 {
  font-size: 2rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 2rem;
  text-align: center;
}

.method-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 2rem;
  margin-bottom: 2rem;
}

.method-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 2rem;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
}

.method-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.method-card.expected-value::before {
  background: linear-gradient(90deg, var(--primary), var(--primary-light));
}

.method-card.risk-assessment::before {
  background: linear-gradient(90deg, var(--secondary), #34d399);
}

.method-card.sensitivity::before {
  background: linear-gradient(90deg, var(--accent), #fbbf24);
}

.method-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-xl);
}

.method-icon {
  width: 3rem;
  height: 3rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  margin-bottom: 1.5rem;
}

.method-card.expected-value .method-icon {
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: white;
}

.method-card.risk-assessment .method-icon {
  background: linear-gradient(135deg, var(--secondary), #34d399);
  color: white;
}

.method-card.sensitivity .method-icon {
  background: linear-gradient(135deg, var(--accent), #fbbf24);
  color: white;
}

.method-card h3 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 1rem;
  color: var(--text-primary);
}

.method-card p {
  color: var(--text-secondary);
  font-size: 1rem;
  line-height: 1.6;
}

.example-highlight {
  background: var(--example-bg);
  color: var(--example-text);
  padding: 1.5rem;
  border-radius: var(--radius);
  font-style: italic;
  margin-top: 2rem;
  border: 1px solid var(--example-border);
  position: relative;
}

.example-text {
  color: var(--example-text);
  font-style: italic;
}

.quick-guide {
  background: linear-gradient(135deg, #ecfdf5, #d1fae5);
  color: #065f46;
  padding: 1.5rem;
  border-radius: var(--radius);
  margin-bottom: 2rem;
  border: 1px solid #a7f3d0;
  position: relative;
}

[data-theme="dark"] .quick-guide {
  background: linear-gradient(135deg, #064e3b, #065f46);
  color: #6ee7b7;
  border-color: #047857;
}

.quick-guide h3 {
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.quick-guide ol {
  margin-left: 1.5rem;
  margin-bottom: 0.5rem;
}

.quick-guide li {
  margin-bottom: 0.5rem;
}

.tabs {
  display: flex;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}

.tab-button {
  flex: 1;
  background: none;
  border: none;
  padding: 1.25rem 1.5rem;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  color: var(--text-secondary);
  border-bottom: 3px solid transparent;
  transition: all 0.3s ease;
  white-space: nowrap;
  min-width: 160px;
  position: relative;
}

.tab-button.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.05), rgba(129, 140, 248, 0.05));
}

.tab-button:hover:not(.active) {
  background: var(--border-light);
  color: var(--text-primary);
}

.tab-content {
  display: none;
  padding: 3rem;
}

.tab-content.active {
  display: block;
}

.section-title {
  font-size: 2rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 2rem;
  padding-bottom: 1rem;
  border-bottom: 2px solid var(--border);
  position: relative;
}

.section-title::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 0;
  width: 60px;
  height: 2px;
  background: var(--primary);
}

.choice-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2rem;
  margin-bottom: 2rem;
  position: relative;
  transition: all 0.3s ease;
  box-shadow: var(--shadow);
}

.choice-card:hover {
  box-shadow: var(--shadow-xl);
  transform: translateY(-2px);
}

.choice-card .remove-choice {
  position: absolute;
  top: 1.5rem;
  right: 1.5rem;
  background: none;
  border: none;
  color: var(--warning);
  font-size: 1.25rem;
  cursor: pointer;
  padding: 0.5rem;
  border-radius: 50%;
  transition: all 0.2s ease;
  width: 2.5rem;
  height: 2.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.choice-card .remove-choice:hover {
  background: rgba(239, 68, 68, 0.1);
  transform: scale(1.1);
}

.form-group {
  margin-bottom: 1.5rem;
}

label {
  display: block;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.75rem;
  font-size: 0.875rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

input[type="text"], input[type="number"], select, textarea {
  width: 100%;
  padding: 1rem;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  background: var(--bg-secondary);
  color: var(--text-primary);
  transition: all 0.3s ease;
  font-family: inherit;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
  transform: translateY(-1px);
}

.outcome-grid {
  display: grid;
  grid-template-columns: 2fr 120px 120px 120px 50px;
  gap: 1rem;
  align-items: center;
  margin-bottom: 1rem;
  padding: 1rem;
  background: var(--bg-secondary);
  border-radius: var(--radius);
  border: 2px solid var(--border-light);
  transition: all 0.3s ease;
}

.outcome-grid:hover {
  box-shadow: var(--shadow);
  border-color: var(--border);
}

.btn {
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: white;
  border: none;
  padding: 1rem 2rem;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  text-decoration: none;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}

.btn::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
  transition: left 0.5s;
}

.btn:hover::before {
  left: 100%;
}

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

.btn-outline {
  background: transparent;
  color: var(--primary);
  border: 2px solid var(--primary);
  box-shadow: none;
}

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

.btn-large {
  width: 100%;
  padding: 1.5rem;
  font-size: 1.25rem;
  margin-top: 3rem;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 50%, var(--secondary) 100%);
}

.actions {
  display: flex;
  gap: 1rem;
  margin-top: 2rem;
  flex-wrap: wrap;
}

.results-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  border-left: 4px solid var(--primary);
  box-shadow: var(--shadow);
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: all 0.3s ease;
}

.results-card:hover {
  transform: translateX(4px);
  box-shadow: var(--shadow-lg);
}

.badge {
  padding: 0.5rem 1rem;
  border-radius: 9999px;
  font-size: 0.875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.025em;
}

.badge-success {
  background: linear-gradient(135deg, var(--secondary), #34d399);
  color: white;
}

.badge-warning {
  background: linear-gradient(135deg, var(--accent), #fbbf24);
  color: white;
}

.badge-error {
  background: linear-gradient(135deg, var(--warning), #f87171);
  color: white;
}

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.8);
  backdrop-filter: blur(8px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.modal-overlay.visible {
  display: flex;
  opacity: 1;
}

.modal {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 3rem;
  max-width: 95vw;
  max-height: 95vh;
  overflow-y: auto;
  box-shadow: var(--shadow-xl);
  position: relative;
  transform: scale(0.9);
  transition: transform 0.3s ease;
  width: 1200px;
  border: 1px solid var(--border);
}

.modal-overlay.visible .modal {
  transform: scale(1);
}

.close-modal {
  position: absolute;
  top: 1.5rem;
  right: 1.5rem;
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-secondary);
  padding: 0.75rem;
  border-radius: 50%;
  transition: all 0.2s ease;
}

.close-modal:hover {
  background: var(--border-light);
  color: var(--text-primary);
  transform: scale(1.1);
}

.chart-container {
  background: var(--bg-secondary);
  padding: 2rem;
  border-radius: var(--radius);
  margin-bottom: 2rem;
  text-align: center;
  border: 1px solid var(--border);
}

.chart-title {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 1rem;
}

.insight-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 1.5rem;
  border-left: 4px solid var(--primary);
  margin-bottom: 1rem;
  box-shadow: var(--shadow-sm);
  transition: all 0.3s ease;
}

.insight-card:hover {
  box-shadow: var(--shadow);
  transform: translateX(4px);
}

@media (max-width: 768px) {
  .header h1 {
    font-size: 2.5rem;
  }
  
  .method-cards {
    grid-template-columns: 1fr;
  }
  
  .outcome-grid {
    grid-template-columns: 1fr;
    gap: 0.75rem;
  }
  
  .modal {
    padding: 2rem;
    width: 95vw;
  }
  
  .actions {
    flex-direction: column;
  }

  .tabs {
    flex-direction: column;
  }

  .tab-button {
    min-width: auto;
  }

  .chart-grid {
    grid-template-columns: 1fr !important;
  }
}

@media (max-width: 480px) {
  .header {
    padding: 2rem 0.5rem;
  }
  .header h1 {
    font-size: 1.5rem;
    padding: 0;
  }
  .header .subtitle {
    font-size: 1rem;
    margin-bottom: 1rem;
  }
  .container {
    padding: 1rem 0.25rem;
  }
  .card {
    padding: 0.5rem;
    border-radius: var(--radius);
  }
  .section-title {
    font-size: 1.25rem;
    padding-bottom: 0.5rem;
    margin-bottom: 1rem;
  }
  .modal {
    padding: 0.5rem;
    width: 99vw;
    max-width: 99vw;
    max-height: 99vh;
    border-radius: var(--radius);
  }
  .close-modal {
    top: 0.5rem;
    right: 0.5rem;
    font-size: 1.25rem;
    padding: 0.5rem;
  }
  .btn, .btn-outline, .btn-large {
    font-size: 1rem;
    padding: 0.75rem 1rem;
    min-width: 44px;
    min-height: 44px;
  }
  input[type="text"], input[type="number"], select, textarea {
    font-size: 1rem;
    padding: 0.75rem;
    min-width: 44px;
    min-height: 44px;
  }
  .outcome-grid {
    padding: 0.5rem;
    gap: 0.5rem;
  }
  .results-card, .insight-card {
    flex-direction: column;
    align-items: flex-start;
    padding: 1rem;
    font-size: 0.95rem;
  }
  .chart-container {
    padding: 0.5rem;
    min-width: 250px;
    overflow-x: auto;
  }
  .chart-title {
    font-size: 1rem;
  }
  #sensitivityTable, #sensitivityTable thead, #sensitivityTable tbody, #sensitivityTable tr, #sensitivityTable th, #sensitivityTable td {
    display: block;
    width: 100%;
    box-sizing: border-box;
    font-size: 0.95rem;
    overflow-x: auto;
  }
  #sensitivityTable {
    overflow-x: auto;
    min-width: 250px;
  }
  .actions {
    gap: 0.5rem;
  }
}

.fade-in {
  animation: fadeIn 0.6s ease-out;
}

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

.chart-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
  margin-bottom: 2rem;
}

/* Instruction box styling */
.instruction-box {
  background: linear-gradient(135deg, var(--bg-secondary), var(--border-light));
  padding: 1.5rem;
  border-radius: var(--radius);
  margin-bottom: 1.5rem;
  font-size: 0.875rem;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  position: relative;
}

.instruction-box::before {
  content: '💡';
  position: absolute;
  top: 1rem;
  left: 1rem;
  font-size: 1.25rem;
}

.instruction-box {
  padding-left: 3.5rem;
}

/* Touch-friendly interactions */
button, .btn, .btn-outline, .btn-large, .tab-button, .remove-choice, .close-modal {
  min-width: 44px;
  min-height: 44px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  outline: none;
}

button:active, .btn:active, .btn-outline:active, .btn-large:active, .tab-button:active, .remove-choice:active, .close-modal:active {
  filter: brightness(0.92);
  box-shadow: 0 0 0 2px var(--primary-light);
}

button:focus-visible, .btn:focus-visible, .btn-outline:focus-visible, .btn-large:focus-visible, .tab-button:focus-visible, .remove-choice:focus-visible, .close-modal:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  box-shadow: 0 0 0 3px var(--primary-light);
}

input[type="text"], input[type="number"], select, textarea {
  min-width: 44px;
  min-height: 44px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

input:active, select:active, textarea:active {
  filter: brightness(0.96);
}

input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  box-shadow: 0 0 0 3px var(--primary-light);
} 