:root {
  color-scheme: light;
  font-family: "Fraunces", "Iowan Old Style", "Palatino Linotype", serif;
  --font-sans: "Inter", "Space Grotesk", sans-serif;
  --bg: #f5f7fa;
  --bg-strong: #eef1f5;
  --card: #ffffff;
  --ink: #1a202c;
  --ink-soft: #718096;
  --accent: #6366f1; /* Indigo */
  --accent-strong: #4f46e5;
  --accent-soft: #e0e7ff;
  --mint: #10b981; /* Emerald */
  --mint-strong: #059669;
  --mint-soft: #d1fae5;
  --blue: #3b82f6;
  --blue-soft: #dbeafe;
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-hover: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --ring: rgba(99, 102, 241, 0.4);
  --grid-gap: 16px;
  --radius: 16px;
  --radius-lg: 24px;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0f172a;
    --bg-strong: #1e293b;
    --card: #1e293b;
    --ink: #f8fafc;
    --ink-soft: #94a3b8;
    --accent: #818cf8;
    --accent-strong: #6366f1;
    --accent-soft: #312e81;
    --mint: #34d399;
    --mint-strong: #10b981;
    --mint-soft: #064e3b;
    --blue: #60a5fa;
    --blue-soft: #1e3a8a;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.5), 0 2px 4px -1px rgba(0, 0, 0, 0.3);
    --shadow-hover: 0 10px 15px -3px rgba(0, 0, 0, 0.6), 0 4px 6px -2px rgba(0, 0, 0, 0.4);
    --ring: rgba(129, 140, 248, 0.4);
  }
}

html.dark {
  color-scheme: dark;
  --bg: #0f172a;
  --bg-strong: #1e293b;
  --card: #1e293b;
  --ink: #f8fafc;
  --ink-soft: #94a3b8;
  --accent: #818cf8;
  --accent-strong: #6366f1;
  --accent-soft: #312e81;
  --mint: #34d399;
  --mint-strong: #10b981;
  --mint-soft: #064e3b;
  --blue: #60a5fa;
  --blue-soft: #1e3a8a;
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.5), 0 2px 4px -1px rgba(0, 0, 0, 0.3);
  --shadow-hover: 0 10px 15px -3px rgba(0, 0, 0, 0.6), 0 4px 6px -2px rgba(0, 0, 0, 0.4);
  --ring: rgba(129, 140, 248, 0.4);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(ellipse at top right, rgba(99, 102, 241, 0.08), transparent 50%),
    radial-gradient(ellipse at bottom left, rgba(16, 185, 129, 0.06), transparent 50%),
    linear-gradient(180deg, var(--bg), var(--bg-strong));
  color: var(--ink);
  /* PWA standalone: respect safe areas (notch, home indicator) */
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.page {
  width: min(1200px, 92vw);
  margin: 0 auto;
  padding: 48px 0 80px;
  display: flex;
  flex-direction: column;
  gap: 32px;
}

.app-header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 24px;
  position: relative;
}

.header-left {
  justify-self: start;
}

.header-center {
  justify-self: center;
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-right {
  justify-self: end;
  position: absolute;
  right: 0;
}

.eyebrow {
  font-family: var(--font-sans);
  text-transform: uppercase;
  letter-spacing: 0.28em;
  font-size: 0.72rem;
  color: var(--ink-soft);
  margin: 0;
}

h1 {
  font-size: clamp(2.4rem, 4vw, 3.4rem);
  margin: 0 0 12px;
}

.subtitle {
  font-family: var(--font-sans);
  margin: 0;
  color: var(--ink-soft);
  max-width: 560px;
  line-height: 1.5;
}

.btn-icon-compact {
  padding: 10px;
  border: none;
  background: transparent;
  box-shadow: none;
  color: var(--ink);
  transition: all 0.3s ease;
}

.btn-icon-compact:hover {
  background: var(--accent-soft);
  color: var(--accent);
  transform: none;
  box-shadow: none;
}

/* Settings Panel */
.settings-panel {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1000;
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
}

.settings-panel[hidden] {
  display: none;
}

.settings-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(26, 22, 20, 0.6);
  backdrop-filter: blur(8px);
  animation: fadeIn 0.3s ease;
}

.settings-content {
  position: relative;
  background: var(--card);
  height: 100vh;
  width: 100%;
  max-width: 400px;
  box-shadow: -4px 0 24px rgba(0, 0, 0, 0.2);
  animation: slideInRight 0.4s ease;
  display: flex;
  flex-direction: column;
}

.settings-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 28px 28px 20px;
  border-bottom: 1px solid rgba(113, 128, 150, 0.15);
  flex-shrink: 0;
}

.settings-header h2 {
  margin: 0;
  font-size: 1.5rem;
  color: var(--ink);
}

.settings-body {
  flex: 1;
  overflow-y: auto;
  padding: 24px 28px;
}

.settings-section {
  margin-bottom: 32px;
}

.settings-section:last-child {
  margin-bottom: 0;
}

.settings-section h3 {
  margin: 0 0 16px;
  font-size: 0.9rem;
  font-family: var(--font-sans);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-soft);
  font-weight: 600;
}

.settings-option {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px;
  background: var(--bg);
  border: 1.5px solid rgba(113, 128, 150, 0.15);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.3s ease;
  font-family: var(--font-sans);
  text-align: left;
}

.settings-option:hover {
  border-color: var(--accent);
  background: var(--card);
  transform: translateX(-4px);
  box-shadow: var(--shadow);
}

.option-icon {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 50%;
}

.option-content {
  flex: 1;
}

.option-label {
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 4px;
}

.option-description {
  font-size: 0.85rem;
  color: var(--ink-soft);
}

.settings-auth-user {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 16px;
  background: var(--bg);
  border-radius: var(--radius);
  border: 1.5px solid rgba(113, 128, 150, 0.15);
}

.auth-info {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.auth-label {
  font-family: var(--font-sans);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-soft);
  font-weight: 600;
}

.auth-email {
  font-family: var(--font-sans);
  font-size: 0.95rem;
  color: var(--ink);
  font-weight: 500;
}

/* Buttons */
.btn-primary {
  font-family: var(--font-sans);
  padding: 12px 24px;
  border-radius: 999px;
  border: none;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: white;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.25);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(99, 102, 241, 0.35);
}

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

.btn-secondary {
  font-family: var(--font-sans);
  padding: 10px 20px;
  border-radius: 999px;
  border: 1.5px solid var(--ink-soft);
  background: transparent;
  color: var(--ink);
  font-weight: 500;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.3s ease;
}

.btn-secondary:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}

.btn-icon {
  font-family: var(--font-sans);
  padding: 10px;
  border-radius: 50%;
  border: 1.5px solid rgba(113, 128, 150, 0.3);
  background: var(--card);
  color: var(--ink);
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow);
}

.btn-icon:hover {
  border-color: var(--accent);
  color: var(--accent);
  transform: translateY(-2px);
  box-shadow: var(--shadow-hover);
}

.btn-block {
  width: 100%;
}

/* Modal */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal[hidden] {
  display: none;
}

.modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(26, 22, 20, 0.6);
  backdrop-filter: blur(8px);
  animation: fadeIn 0.3s ease;
}

.modal-content {
  position: relative;
  background: var(--card);
  border-radius: var(--radius-lg);
  box-shadow: 0 24px 64px rgba(26, 22, 20, 0.2);
  width: 100%;
  max-width: 480px;
  animation: slideUp 0.4s ease;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 28px 28px 20px;
  border-bottom: 1px solid rgba(113, 128, 150, 0.15);
}

.modal-header h2 {
  margin: 0;
  font-size: 1.5rem;
  color: var(--ink);
}

.modal-body {
  padding: 28px;
}

.auth-description {
  margin: 0 0 24px;
  font-family: var(--font-sans);
  color: var(--ink-soft);
  line-height: 1.6;
  font-size: 0.95rem;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

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

.form-group label {
  font-family: var(--font-sans);
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--ink);
}

.form-group input {
  padding: 12px 16px;
  border-radius: 12px;
  border: 1.5px solid rgba(113, 128, 150, 0.25);
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 1rem;
  transition: all 0.3s ease;
}

.form-group input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--ring);
  background: var(--card);
}

.auth-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 8px;
}

.save-status {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  font-family: var(--font-sans);
  font-size: 0.85rem;
  color: var(--ink-soft);
  padding: 8px 14px;
  background: var(--card);
  border-radius: 999px;
  box-shadow: var(--shadow);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--mint);
  box-shadow: 0 0 0 2px var(--mint-soft);
  animation: pulse 2s ease-in-out infinite;
}

.status-dot[data-status="saving"] {
  background: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.status-dot[data-status="error"] {
  background: #e63946;
  box-shadow: 0 0 0 2px rgba(230, 57, 70, 0.2);
  animation: none;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.scenario-grid-wrap {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center; /* Center the narrower grid */
  gap: 24px;
}

.scenario-box {
  background: var(--card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  border: 1px solid rgba(113, 128, 150, 0.1);
  overflow: hidden;
  width: 100%;
  max-width: 450px; /* Reduced from 600px */
}

.box-title {
  margin: 0;
  padding: 10px 14px;
  font-size: 0.85rem;
  color: var(--ink-soft);
  border-bottom: 1px solid rgba(113, 128, 150, 0.1);
  background: var(--bg);
  font-weight: 600;
  letter-spacing: 0.02em;
}

.main-header {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  padding: 0 10px;
  margin-bottom: 8px;
  position: relative;
  z-index: 10;
  width: 100%;
  max-width: 450px; /* Reduced from 600px */
  gap: 8px;
}

.main-header .grid-cell {
  background: var(--accent-soft);
  border-radius: 4px;
  padding: 8px 4px;
  font-weight: 700;
  color: var(--accent-strong);
  font-size: 0.95rem;
  text-align: center; /* Ensure headers are centered */
  justify-content: center; /* For flex alignment */
  display: flex;
  align-items: center;
}

.grid-body {
  padding: 8px 0;
}

.grid-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  padding: 6px 10px;
  border-bottom: 1px solid rgba(113, 128, 150, 0.08);
  transition: background 0.2s ease;
  gap: 8px;
}

.grid-row:last-child {
  border-bottom: none;
}

/* Adjust cell padding since row has padding now */
.grid-cell {
  background: transparent;
}

.grid-cell:first-child {
  padding-left: 0;
}

.grid-cell:last-child {
  padding-right: 0;
}

.grid-row-title {
  grid-column: 1 / -1;
  font-family: var(--font-sans);
  color: var(--ink-soft);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  margin-bottom: 4px;
  font-weight: 600;
}

.grid-cell.scenario {
  display: flex;
  align-items: center;
  justify-content: center; /* Center align all cells */
  gap: 10px;
  font-family: var(--font-sans);
  padding: 0 4px;
}

.grid-cell.scenario strong {
  font-family: inherit;
}

.grid-cell input {
  width: 100%;
  padding: 4px 6px;
  border-radius: 4px;
  border: 1px solid rgba(113, 128, 150, 0.2);
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 0.85rem;
  font-weight: 500;
  transition: all 0.3s ease;
}

.grid-cell input:hover {
  border-color: rgba(113, 128, 150, 0.35);
}

.grid-cell input:focus {
  outline: 2px solid var(--ring);
  border-color: var(--accent);
}

.value-pill {
  width: 100%;
  padding: 5px 6px;
  border-radius: 4px;
  background: linear-gradient(135deg, var(--accent-soft), rgba(99, 102, 241, 0.08));
  text-align: center;
  font-weight: 600;
  font-family: var(--font-sans);
  font-size: 0.85rem;
  border: 1px solid rgba(99, 102, 241, 0.15);
  transition: all 0.3s ease;
}

.value-pill:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.15);
}

.value-pill.mint {
  background: linear-gradient(135deg, var(--mint-soft), rgba(16, 185, 129, 0.08));
  border-color: rgba(16, 185, 129, 0.15);
}

.value-pill.mint:hover {
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.15);
}

.value-pill small {
  display: block;
  font-weight: 400;
  font-size: 0.75rem;
  color: var(--ink-soft);
  margin-top: 4px;
}

@media (max-width: 960px) {
  .app-header {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
    gap: 16px;
  }

  .header-left {
    grid-column: 1;
    grid-row: 2;
    justify-self: center;
  }

  .header-center {
    grid-column: 1;
    grid-row: 1;
  }

  .header-right {
    grid-column: 1;
    grid-row: 1;
    position: absolute;
    right: 0;
    top: 0;
  }

  .scenario-grid-wrap {
    overflow-x: auto;
    width: 100%;
    padding-bottom: 20px;
    align-items: flex-start; /* Left align on mobile for scrolling */
  }

  .scenario-box,
  .main-header {
    min-width: 360px; /* Reduced from 480px */
  }

  .main-header,
  .grid-row {
    grid-template-columns: repeat(3, 1fr);
  }

  .modal-content {
    max-width: 90vw;
  }
}

.fade-in {
  animation: fadeUp 0.6s ease forwards;
}

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

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes slideInRight {
  from {
    opacity: 0;
    transform: translateX(100%);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}
