/* ===== THEMES =====
   Five curated themes. The visible dashboard cards (card-1, card-2,
   card-5) use vibrant gradients that work with white text; each
   theme tints the page background, header, and accent. card-3,
   card-4, card-6 are unused at runtime (those slots render as
   .highlight-card) but kept for completeness. */

/* Runway Theme (default) — uses the space backdrop image on the header */
:root[data-theme="runway"] {
  --xp-bg: #f3f4fb;
  --xp-panel: #ffffff;
  --xp-text: #1a237e;
  --xp-border: #5c6bc0;
  --xp-border-light: #c5cae9;
  --xp-accent: #3f51b5;
  --xp-accent-light: #7986cb;
  --xp-gradient-start: #0a0e2a;
  --xp-gradient-end: #2a1d50;
  --xp-body-tint: rgba(63, 81, 181, 0.10);
  --card-1: linear-gradient(135deg, #66bb6a 0%, #2e7d32 100%);
  --card-2: linear-gradient(135deg, #ef5350 0%, #c62828 100%);
  --card-3: linear-gradient(135deg, #5c6bc0 0%, #283593 100%);
  --card-4: linear-gradient(135deg, #5c6bc0 0%, #283593 100%);
  --card-5: linear-gradient(135deg, #5c6bc0 0%, #283593 100%);
  --card-6: linear-gradient(135deg, #5c6bc0 0%, #283593 100%);
}

/* Space backdrop on the Runway header. Sub-header keeps the
   default gradient (driven by --xp-gradient-* vars) so the
   tagline strip looks like the rest of the themes. */
:root[data-theme="runway"] .unified-header {
  background:
    linear-gradient(135deg, rgba(8, 12, 38, 0.55) 0%, rgba(38, 22, 70, 0.45) 100%),
    url('space-bg.jpg');
  background-size: cover, cover;
  background-position: center, 50% 50%;
  background-repeat: no-repeat, no-repeat;
  animation: runway-bg-wave 75s ease-in-out infinite;
}
@keyframes runway-bg-wave {
  0%, 100% { background-position: center, 50% 50%; }
  50%      { background-position: center, 53% 47%; }
}
@media (prefers-reduced-motion: reduce) {
  :root[data-theme="runway"] .unified-header { animation: none; }
}

/* Deep Space Theme — black-hole backdrop on the header */
:root[data-theme="deep-space"] {
  --xp-bg: #f0f1f8;
  --xp-panel: #ffffff;
  --xp-text: #1a237e;
  --xp-border: #5c6bc0;
  --xp-border-light: #c5cae9;
  --xp-accent: #5e35b1;
  --xp-accent-light: #9575cd;
  --xp-gradient-start: #1a0b3a;
  --xp-gradient-end: #3d1a6a;
  --xp-body-tint: rgba(94, 53, 177, 0.11);
  --card-1: linear-gradient(135deg, #66bb6a 0%, #2e7d32 100%);
  --card-2: linear-gradient(135deg, #ef5350 0%, #c62828 100%);
  --card-3: linear-gradient(135deg, #7e57c2 0%, #4527a0 100%);
  --card-4: linear-gradient(135deg, #7e57c2 0%, #4527a0 100%);
  --card-5: linear-gradient(135deg, #7e57c2 0%, #4527a0 100%);
  --card-6: linear-gradient(135deg, #7e57c2 0%, #4527a0 100%);
}
:root[data-theme="deep-space"] .unified-header {
  background:
    linear-gradient(135deg, rgba(10, 5, 30, 0.5) 0%, rgba(45, 15, 80, 0.4) 100%),
    url('deep-space.jpg');
  background-size: cover, cover;
  background-position: center, 50% 50%;
  background-repeat: no-repeat, no-repeat;
  animation: deep-space-wave 90s ease-in-out infinite;
}
@keyframes deep-space-wave {
  0%, 100% { background-position: center, 48% 50%; }
  50%      { background-position: center, 52% 50%; }
}
@media (prefers-reduced-motion: reduce) {
  :root[data-theme="deep-space"] .unified-header { animation: none; }
}

/* Azure Theme — bright blue cosmic */
:root[data-theme="azure"] {
  --xp-bg: #ebf3fb;
  --xp-panel: #ffffff;
  --xp-text: #0d47a1;
  --xp-border: #64b5f6;
  --xp-border-light: #bbdefb;
  --xp-accent: #1976d2;
  --xp-accent-light: #42a5f5;
  --xp-gradient-start: #0a3a8a;
  --xp-gradient-end: #1976d2;
  --xp-body-tint: rgba(25, 118, 210, 0.10);
  --card-1: linear-gradient(135deg, #66bb6a 0%, #2e7d32 100%);
  --card-2: linear-gradient(135deg, #ef5350 0%, #c62828 100%);
  --card-3: linear-gradient(135deg, #42a5f5 0%, #1565c0 100%);
  --card-4: linear-gradient(135deg, #42a5f5 0%, #1565c0 100%);
  --card-5: linear-gradient(135deg, #42a5f5 0%, #1565c0 100%);
  --card-6: linear-gradient(135deg, #42a5f5 0%, #1565c0 100%);
}
:root[data-theme="azure"] .unified-header {
  background:
    linear-gradient(135deg, rgba(8, 30, 80, 0.45) 0%, rgba(20, 60, 130, 0.35) 100%),
    url('azure.jpg');
  background-size: cover, cover;
  background-position: center, 50% 50%;
  background-repeat: no-repeat, no-repeat;
  animation: azure-wave 82s ease-in-out infinite;
}
@keyframes azure-wave {
  0%, 100% { background-position: center, 48% 50%; }
  50%      { background-position: center, 52% 50%; }
}
@media (prefers-reduced-motion: reduce) {
  :root[data-theme="azure"] .unified-header { animation: none; }
}

/* Portal Theme — green nebula */
:root[data-theme="portal"] {
  --xp-bg: #ecf3ec;
  --xp-panel: #ffffff;
  --xp-text: #1b5e20;
  --xp-border: #81c784;
  --xp-border-light: #c8e6c9;
  --xp-accent: #2e7d32;
  --xp-accent-light: #66bb6a;
  --xp-gradient-start: #1b5e20;
  --xp-gradient-end: #43a047;
  --xp-body-tint: rgba(46, 125, 50, 0.10);
  --card-1: linear-gradient(135deg, #66bb6a 0%, #2e7d32 100%);
  --card-2: linear-gradient(135deg, #ef6c00 0%, #bf360c 100%);
  --card-3: linear-gradient(135deg, #6d4c41 0%, #3e2723 100%);
  --card-4: linear-gradient(135deg, #6d4c41 0%, #3e2723 100%);
  --card-5: linear-gradient(135deg, #6d4c41 0%, #3e2723 100%);
  --card-6: linear-gradient(135deg, #6d4c41 0%, #3e2723 100%);
}
:root[data-theme="portal"] .unified-header {
  background:
    linear-gradient(135deg, rgba(10, 40, 18, 0.5) 0%, rgba(20, 60, 25, 0.4) 100%),
    url('portal.jpg');
  background-size: cover, cover;
  background-position: center, 50% 50%;
  background-repeat: no-repeat, no-repeat;
  animation: portal-wave 80s ease-in-out infinite;
}
@keyframes portal-wave {
  0%, 100% { background-position: center, 48% 50%; }
  50%      { background-position: center, 52% 50%; }
}
@media (prefers-reduced-motion: reduce) {
  :root[data-theme="portal"] .unified-header { animation: none; }
}

/* Cosmic Theme — warm pink/orange nebula */
:root[data-theme="cosmic"] {
  --xp-bg: #fdf0f4;
  --xp-panel: #ffffff;
  --xp-text: #ad1457;
  --xp-border: #f06292;
  --xp-border-light: #f8bbd0;
  --xp-accent: #c2185b;
  --xp-accent-light: #ec407a;
  --xp-gradient-start: #6a1b4a;
  --xp-gradient-end: #c2185b;
  --xp-body-tint: rgba(194, 24, 91, 0.10);
  --card-1: linear-gradient(135deg, #66bb6a 0%, #2e7d32 100%);
  --card-2: linear-gradient(135deg, #ef5350 0%, #c62828 100%);
  --card-3: linear-gradient(135deg, #ec407a 0%, #ad1457 100%);
  --card-4: linear-gradient(135deg, #ec407a 0%, #ad1457 100%);
  --card-5: linear-gradient(135deg, #ec407a 0%, #ad1457 100%);
  --card-6: linear-gradient(135deg, #ec407a 0%, #ad1457 100%);
}
:root[data-theme="cosmic"] .unified-header {
  background:
    linear-gradient(135deg, rgba(80, 10, 35, 0.45) 0%, rgba(80, 30, 80, 0.35) 100%),
    url('cosmic.jpg');
  background-size: cover, cover;
  background-position: center, 50% 50%;
  background-repeat: no-repeat, no-repeat;
  animation: cosmic-wave 85s ease-in-out infinite;
}
@keyframes cosmic-wave {
  0%, 100% { background-position: center, 50% 50%; }
  50%      { background-position: center, 53% 47%; }
}
@media (prefers-reduced-motion: reduce) {
  :root[data-theme="cosmic"] .unified-header { animation: none; }
}

/* Default fallback (matches runway) */
:root {
  --xp-bg: #f3f4fb;
  --xp-panel: #ffffff;
  --xp-text: #1a237e;
  --xp-border: #5c6bc0;
  --xp-border-light: #c5cae9;
  --xp-accent: #3f51b5;
  --xp-accent-light: #7986cb;
  --xp-gradient-start: #0a0e2a;
  --xp-gradient-end: #2a1d50;
  --xp-body-tint: rgba(63, 81, 181, 0.10);
  --card-1: linear-gradient(135deg, #66bb6a 0%, #2e7d32 100%);
  --card-2: linear-gradient(135deg, #ef5350 0%, #c62828 100%);
  --card-3: linear-gradient(135deg, #5c6bc0 0%, #283593 100%);
  --card-4: linear-gradient(135deg, #5c6bc0 0%, #283593 100%);
  --card-5: linear-gradient(135deg, #5c6bc0 0%, #283593 100%);
  --card-6: linear-gradient(135deg, #5c6bc0 0%, #283593 100%);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', sans-serif;
  color: var(--xp-text);
  background-color: var(--xp-bg);
  background-image:
    linear-gradient(var(--xp-body-tint, rgba(255,255,255,0)), var(--xp-body-tint, rgba(255,255,255,0))),
    url('stars-bg.jpg');
  background-size: auto, 360px auto;
  background-repeat: repeat;
  min-height: 100vh;
  padding: 20px;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
}

.hero {
  background: linear-gradient(135deg, var(--xp-gradient-start) 0%, var(--xp-gradient-end) 100%);
  color: white;
  padding: 30px;
  margin-bottom: 30px;
  border-radius: 0;
  text-align: left;
  box-shadow: none;
  display: flex;
  align-items: center;
  gap: 20px;
}

.hero h1 {
  margin: 0;
  font-size: 1.8rem;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.hero p {
  margin: 5px 0 0 0;
  font-size: 0.9rem;
  opacity: 0.9;
  font-weight: 400;
}

.logo {
  width: 48px;
  height: 48px;
  flex-shrink: 0;
}

header {
  margin-bottom: 25px;
}

section {
  background-color: var(--xp-panel);
  border-radius: 8px;
  padding: 25px;
  margin-bottom: 20px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  border: 1px solid var(--xp-border-light);
}

section > h2 {
  margin: 0 0 20px 0;
  padding: 8px 0;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--xp-accent);
  border-bottom: 2px solid var(--xp-accent);
  letter-spacing: -0.3px;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 15px;
  margin-bottom: 20px;
}

.card {
  background: var(--card-1);
  border: 2px solid rgba(0, 0, 0, 0.1);
  border-radius: 12px;
  padding: 24px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  transition: all 0.3s ease;
  color: white;
  min-width: 0;
  overflow-wrap: anywhere;
}

.card:nth-child(1) { background: var(--card-1); }
.card:nth-child(2) { background: var(--card-2); }
.card:nth-child(3) { background: var(--card-3); }
.card:nth-child(4) { background: var(--card-4); }
.card:nth-child(5) { background: var(--card-5); }
.card:nth-child(6) { background: var(--card-6); }

.card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  border-color: var(--xp-accent-light);
}

.card.highlight-card {
  background: var(--xp-bg);
  border: 2px solid var(--xp-accent);
  position: relative;
}

.card.highlight-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--xp-accent) 0%, var(--xp-accent-light) 100%);
  border-radius: 8px 8px 0 0;
}

.card.highlight-card h3 {
  color: var(--xp-accent);
  font-weight: 800;
}

.card.highlight-card p {
  color: var(--xp-accent);
  font-size: clamp(1rem, 4.8vw, 2.2rem);
}

.card.highlight-card small {
  color: var(--xp-accent);
  opacity: 0.85;
}

.card h3 {
  margin: 0 0 12px 0;
  font-size: 0.75rem;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.9);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.card p {
  margin: 0;
  font-size: clamp(1.1rem, 5.2vw, 2.4rem);
  font-weight: 800;
  color: white;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', monospace;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: clip;
}

/* "/ month" label sits on its own small line under the headline number */
.card .period {
  font-size: 0.78rem;
  font-weight: 600;
  font-style: italic;
  opacity: 0.85;
  margin-top: 4px;
  letter-spacing: 0.3px;
}
.card .period + small {
  margin-top: 4px;
}

/* Meaningful card colors regardless of grid position */
.dashboard-grid .card.card-income { background: linear-gradient(135deg, #66bb6a 0%, #2e7d32 100%); }
.dashboard-grid .card.card-expense { background: linear-gradient(135deg, #ef5350 0%, #c62828 100%); }

.card small {
  display: block;
  color: rgba(255, 255, 255, 0.85);
  font-size: 0.85rem;
  margin-top: 8px;
  font-weight: 500;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 20px;
  margin-bottom: 20px;
}

.grid-2 > div {
  background: linear-gradient(135deg, #ffffff 0%, #f9fbff 100%);
  border: 1px solid var(--xp-border);
  border-radius: 8px;
  padding: 20px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
}

.grid-2 > div h2 {
  margin: 0 0 16px 0;
  padding: 0 0 12px 0;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--xp-accent);
  border-bottom: 2px solid var(--xp-accent);
  letter-spacing: -0.3px;
}

.grid-4 {
  background: linear-gradient(135deg, #ffffff 0%, #f9fbff 100%);
  border: 1px solid var(--xp-border);
  border-radius: 8px;
  padding: 20px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 15px;
  margin-bottom: 20px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
}

.estimator-form {
  display: flex;
  flex-direction: column;
  gap: 25px;
}

.estimator-section {
  background: linear-gradient(135deg, #ffffff 0%, #f9fbff 100%);
  border: 1px solid var(--xp-border);
  border-radius: 8px;
  padding: 20px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
}

.estimator-section h3 {
  margin: 0 0 16px 0;
  font-size: 1rem;
  font-weight: 700;
  color: var(--xp-accent);
  border-bottom: 2px solid var(--xp-accent);
  padding-bottom: 8px;
  letter-spacing: -0.3px;
}

.estimator-section label {
  margin-bottom: 15px;
}

.estimator-section label:last-of-type {
  margin-bottom: 0;
}

.strategy-selector {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
  margin-bottom: 15px;
}

.strategy-option {
  position: relative;
  display: flex;
  gap: 12px;
  padding: 15px;
  border: 2px solid var(--xp-border);
  border-radius: 6px;
  background: white;
  cursor: pointer;
  transition: all 0.3s ease;
}

.strategy-option:hover {
  border-color: var(--xp-accent);
  box-shadow: 0 4px 12px rgba(0, 82, 204, 0.1);
}

.strategy-option input[type="radio"] {
  margin: 0;
  width: 20px;
  height: 20px;
  cursor: pointer;
  flex-shrink: 0;
  margin-top: 2px;
}

.strategy-option input[type="radio"]:checked + .strategy-content strong {
  color: var(--xp-accent);
}

.strategy-option input[type="radio"]:checked + .strategy-content {
  color: var(--xp-accent);
}

.strategy-content {
  flex: 1;
}

.strategy-content strong {
  display: block;
  margin-bottom: 4px;
  font-weight: 700;
  transition: color 0.2s ease;
}

.strategy-content small {
  display: block;
  color: #666;
  font-size: 0.8rem;
  font-weight: 500;
}

.estimator-actions {
  display: flex;
  gap: 12px;
  margin-top: 10px;
}

.estimator-actions button {
  flex: 1;
  padding: 12px 20px;
  font-size: 0.9rem;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.9rem;
  font-weight: 500;
}

label small {
  color: var(--xp-accent);
  font-weight: 700;
  text-transform: uppercase;
  font-size: 0.7rem;
  letter-spacing: 0.5px;
}

input, select, textarea {
  padding: 10px 12px;
  border: 1px solid var(--xp-border);
  border-radius: 6px;
  background-color: white;
  color: var(--xp-text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 0.9rem;
  transition: all 0.2s ease;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--xp-accent);
  box-shadow: 0 0 0 3px rgba(0, 82, 204, 0.1);
  background-color: white;
}

button, .btn {
  padding: 10px 18px;
  border: 1px solid var(--xp-border);
  border-radius: 6px;
  background: linear-gradient(135deg, #f5f7fa 0%, #f0f3f8 100%);
  color: var(--xp-text);
  cursor: pointer;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 0.85rem;
  font-weight: 700;
  text-decoration: none;
  display: inline-block;
  min-width: 70px;
  text-align: center;
  user-select: none;
  transition: all 0.2s ease;
  letter-spacing: 0.3px;
}

button:hover, .btn:hover {
  background: linear-gradient(135deg, #ffffff 0%, #f5f7fa 100%);
  border-color: var(--xp-accent-light);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

button:active, .btn:active {
  transform: translateY(0);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}

.btn {
  background: linear-gradient(135deg, var(--xp-accent) 0%, var(--xp-accent-light) 100%);
  color: white;
  border-color: var(--xp-accent);
  font-weight: 700;
}

.btn:hover {
  background: linear-gradient(135deg, #0052cc 0%, #0052cc 100%);
  border-color: #0052cc;
  box-shadow: 0 4px 16px rgba(0, 82, 204, 0.25);
}

.btn.secondary {
  background: linear-gradient(135deg, #f5f7fa 0%, #f0f3f8 100%);
  color: var(--xp-text);
  border-color: var(--xp-border);
}

.btn.secondary:hover {
  background: linear-gradient(135deg, #ffffff 0%, #f5f7fa 100%);
  border-color: var(--xp-accent);
  color: var(--xp-accent);
}

.help-icon {
  display: inline-block;
  width: 20px;
  height: 20px;
  background: linear-gradient(135deg, var(--xp-accent) 0%, var(--xp-accent-light) 100%);
  color: white;
  border: none;
  border-radius: 50%;
  text-align: center;
  line-height: 20px;
  font-size: 0.7rem;
  font-weight: 700;
  cursor: help;
  margin-left: 6px;
  transition: all 0.2s ease;
  box-shadow: 0 2px 6px rgba(0, 82, 204, 0.2);
}

.help-icon:hover {
  transform: scale(1.1);
  box-shadow: 0 4px 12px rgba(0, 82, 204, 0.3);
}

.tooltip {
  position: fixed;
  background: linear-gradient(135deg, #1a1a1a 0%, #2a2a2a 100%);
  color: white;
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 0.85rem;
  max-width: 220px;
  z-index: 1000;
  pointer-events: none;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
  font-weight: 500;
  line-height: 1.4;
}

.breakdown-card {
  background: linear-gradient(135deg, #ffffff 0%, #f9fbff 100%);
  border: 1px solid var(--xp-border);
  border-radius: 8px;
  padding: 16px;
  text-align: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
  transition: all 0.3s ease;
}

.breakdown-card:nth-child(1) { background: linear-gradient(135deg, #f5e6d3 0%, #e8dcc8 100%); border-color: #d4c0b0; }
.breakdown-card:nth-child(2) { background: linear-gradient(135deg, #e3f1f5 0%, #d9e8f0 100%); border-color: #c0d8e8; }
.breakdown-card:nth-child(3) { background: linear-gradient(135deg, #e6f5e6 0%, #d9f0d9 100%); border-color: #c0e0c0; }
.breakdown-card:nth-child(4) { background: linear-gradient(135deg, #f5f1e3 0%, #ede8d9 100%); border-color: #ddd0c0; }
.breakdown-card:nth-child(5) { background: linear-gradient(135deg, #f5e3f1 0%, #ede9f0 100%); border-color: #dcc0d8; }

.breakdown-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  border-color: var(--xp-accent-light);
}

.breakdown-card h3 {
  margin: 0 0 12px 0;
  color: var(--xp-accent);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  font-weight: 700;
}

.breakdown-card p {
  color: var(--xp-accent);
  font-weight: 700;
  font-size: 1.4rem;
  margin: 0 0 6px 0;
}

.history {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 15px;
  background: linear-gradient(135deg, #ffffff 0%, #f9fbff 100%);
  padding: 16px;
  border: 1px solid var(--xp-border);
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
  transition: all 0.3s ease;
}

.history-item:hover {
  background: linear-gradient(135deg, #f9fbff 0%, #f5f8ff 100%);
  border-color: var(--xp-accent-light);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.history-item h4 {
  margin: 0;
  color: var(--xp-accent);
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.history-item p {
  margin: 6px 0 0 0;
  color: #666;
  font-size: 0.8rem;
  font-weight: 500;
}

#incomeList, #expenseList {
  min-height: 40px;
}

#scenarioList, #historyList {
  min-height: 60px;
}

@media (max-width: 700px) {
  .hero {
    padding: 30px 20px;
  }

  .hero h1 {
    font-size: 1.8rem;
  }

  .grid-2 {
    grid-template-columns: 1fr;
  }

  .grid-4 {
    grid-template-columns: 1fr;
  }

  .cards {
    grid-template-columns: 1fr;
  }

  section {
    padding: 15px;
  }

  section > h2 {
    font-size: 1.1rem;
  }

  .card {
    padding: 12px;
    border-radius: 10px;
  }

  .card h3 {
    font-size: 0.65rem;
    letter-spacing: 0.5px;
  }

  .card small {
    font-size: 0.75rem;
  }
}

/* ===== ANIMATIONS ===== */

/* Confetti pieces fired by celebrate() */
.confetti-piece {
  position: fixed;
  top: -20px;
  width: 10px;
  height: 14px;
  border-radius: 2px;
  pointer-events: none;
  z-index: 9999;
  animation: confetti-fall 2s ease-out forwards;
}

@keyframes confetti-fall {
  0%   { transform: translateY(-10vh) rotate(0deg); opacity: 1; }
  100% { transform: translateY(110vh) rotate(var(--rot, 720deg)); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .confetti-piece { display: none; }
}

/* ===== GUIDED TOUR ===== */
.tour-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 14, 30, 0.55);
  z-index: 9000;
  pointer-events: auto;
  animation: tour-fade 0.25s ease-out;
}
@keyframes tour-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Lift target above backdrop and ring it with the accent color */
.tour-spotlight {
  position: relative !important;
  z-index: 9100 !important;
  box-shadow: 0 0 0 4px var(--xp-accent-light), 0 0 0 9999px rgba(10, 14, 30, 0.55) !important;
  border-radius: 10px;
  transition: box-shadow 0.25s ease;
}

/* Spacey backdrop divs surround the cutout. They persist across
   tour steps and transition top/left/width/height so the cutout
   smoothly morphs from one target rect to the next. */
.tour-mask {
  position: fixed;
  z-index: 9000;
  pointer-events: auto;
  background:
    radial-gradient(ellipse at 25% 15%, rgba(63, 81, 181, 0.14), transparent 55%),
    radial-gradient(ellipse at 78% 82%, rgba(120, 30, 100, 0.10), transparent 55%),
    #000004;
  overflow: hidden;
  transition: top 0.45s cubic-bezier(0.22, 1, 0.36, 1),
              left 0.45s cubic-bezier(0.22, 1, 0.36, 1),
              width 0.45s cubic-bezier(0.22, 1, 0.36, 1),
              height 0.45s cubic-bezier(0.22, 1, 0.36, 1);
  will-change: top, left, width, height;
  animation: tour-fade 0.3s ease-out;
}
.tour-mask::before,
.tour-mask::after {
  content: '';
  position: absolute;
  inset: -200px;
  pointer-events: none;
}
/* Drifting starfield (small white pinpoints) */
.tour-mask::before {
  background-image:
    radial-gradient(1px 1px at 12% 18%, rgba(255,255,255,0.95), transparent 60%),
    radial-gradient(1px 1px at 28% 62%, rgba(255,255,255,0.85), transparent 60%),
    radial-gradient(1.5px 1.5px at 47% 30%, rgba(255,255,255,1), transparent 60%),
    radial-gradient(1px 1px at 62% 78%, rgba(255,255,255,0.75), transparent 60%),
    radial-gradient(1px 1px at 75% 12%, rgba(255,255,255,0.9), transparent 60%),
    radial-gradient(2px 2px at 88% 50%, rgba(255,255,255,0.95), transparent 60%),
    radial-gradient(1px 1px at 33% 90%, rgba(255,255,255,0.7), transparent 60%),
    radial-gradient(1px 1px at 91% 90%, rgba(255,255,255,0.8), transparent 60%);
  background-size: 220px 220px;
  background-repeat: repeat;
  animation: tour-drift 90s linear infinite;
}
/* Bigger twinkling white stars on a slower opposite drift */
.tour-mask::after {
  background-image:
    radial-gradient(1.6px 1.6px at 22% 70%, rgba(255,255,255,0.95), transparent 60%),
    radial-gradient(2px 2px at 70% 22%, rgba(255,255,255,0.9), transparent 60%),
    radial-gradient(1.4px 1.4px at 8% 44%, rgba(255,255,255,0.85), transparent 60%),
    radial-gradient(1.8px 1.8px at 55% 85%, rgba(255,255,255,0.8), transparent 60%),
    radial-gradient(2.2px 2.2px at 84% 60%, rgba(255,255,255,1), transparent 60%);
  background-size: 360px 360px;
  background-repeat: repeat;
  animation: tour-drift 130s linear infinite reverse, tour-twinkle 5s ease-in-out infinite;
  opacity: 0.7;
}
@keyframes tour-drift {
  from { transform: translate(0, 0); }
  to   { transform: translate(220px, 220px); }
}
@keyframes tour-twinkle {
  0%, 100% { opacity: 0.4; }
  50%      { opacity: 0.9; }
}

.tour-ring {
  position: fixed;
  z-index: 9001;
  pointer-events: none;
  border-radius: 10px;
  box-shadow: 0 0 0 4px var(--xp-accent-light), 0 0 24px 6px rgba(255,255,255,0.18);
  transition: top 0.45s cubic-bezier(0.22, 1, 0.36, 1),
              left 0.45s cubic-bezier(0.22, 1, 0.36, 1),
              width 0.45s cubic-bezier(0.22, 1, 0.36, 1),
              height 0.45s cubic-bezier(0.22, 1, 0.36, 1),
              opacity 0.3s ease;
  will-change: top, left, width, height;
  animation: tour-ring-pulse 1.6s ease-in-out infinite;
}

/* Big astronaut that drifts in the dim backdrop during the tour */
.tour-astronaut {
  position: fixed;
  width: 110px;
  height: 110px;
  z-index: 9050;
  pointer-events: none;
  filter: drop-shadow(0 6px 16px rgba(0,0,0,0.5));
  animation: tour-astro-float 18s ease-in-out infinite;
  transition: top 0.6s cubic-bezier(0.22, 1, 0.36, 1),
              left 0.6s cubic-bezier(0.22, 1, 0.36, 1);
  will-change: transform;
}
@keyframes tour-astro-float {
  0%, 100% { transform: translate(0, 0) rotate(0deg); }
  20%      { transform: translate(22px, -14px) rotate(18deg); }
  40%      { transform: translate(-18px, 20px) rotate(-12deg); }
  60%      { transform: translate(28px, 8px) rotate(25deg); }
  80%      { transform: translate(-12px, -22px) rotate(-18deg); }
}
@media (prefers-reduced-motion: reduce) {
  .tour-astronaut { animation: none; transition: none; }
}
@keyframes tour-ring-pulse {
  0%, 100% { box-shadow: 0 0 0 4px var(--xp-accent-light), 0 0 18px 4px rgba(255,255,255,0.18); }
  50%      { box-shadow: 0 0 0 6px var(--xp-accent-light), 0 0 28px 10px rgba(255,255,255,0.35); }
}
@media (prefers-reduced-motion: reduce) {
  .tour-mask, .tour-mask::before, .tour-mask::after, .tour-ring {
    animation: none;
    transition: none;
  }
}

.tour-card {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  width: min(440px, calc(100vw - 24px));
  background: white;
  color: #2c2c3a;
  padding: 18px 20px 14px;
  border-radius: 14px;
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.42), 0 0 0 1px rgba(255,255,255,0.06);
  z-index: 10000;
}
.tour-card.tour-card-top {
  bottom: auto;
  top: 16px;
}

/* Slide animations — direction controlled by classes added in JS */
.tour-card-enter-right {
  animation: tour-slide-in-right 0.42s cubic-bezier(0.22, 1, 0.36, 1) both;
}
.tour-card-enter-left {
  animation: tour-slide-in-left 0.42s cubic-bezier(0.22, 1, 0.36, 1) both;
}
.tour-card-exit-left {
  animation: tour-slide-out-left 0.32s cubic-bezier(0.4, 0, 1, 1) both;
}
.tour-card-exit-right {
  animation: tour-slide-out-right 0.32s cubic-bezier(0.4, 0, 1, 1) both;
}
@keyframes tour-slide-in-right {
  from { transform: translateX(calc(-50% + 110vw)); opacity: 0; }
  to   { transform: translateX(-50%); opacity: 1; }
}
@keyframes tour-slide-in-left {
  from { transform: translateX(calc(-50% - 110vw)); opacity: 0; }
  to   { transform: translateX(-50%); opacity: 1; }
}
@keyframes tour-slide-out-left {
  from { transform: translateX(-50%); opacity: 1; }
  to   { transform: translateX(calc(-50% - 110vw)); opacity: 0; }
}
@keyframes tour-slide-out-right {
  from { transform: translateX(-50%); opacity: 1; }
  to   { transform: translateX(calc(-50% + 110vw)); opacity: 0; }
}
.tour-card h3 {
  margin: 0 0 8px 0;
  color: var(--xp-accent);
  font-size: 1.05rem;
}
.tour-card p {
  margin: 0 0 14px 0;
  font-size: 0.9rem;
  line-height: 1.5;
}
.tour-card p + p {
  margin-top: -4px;
}
.tour-controls {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.tour-controls .tour-step {
  font-size: 0.72rem;
  color: #999;
  margin-right: auto;
  font-weight: 600;
  letter-spacing: 0.5px;
}
.tour-controls button {
  padding: 7px 14px;
  font-size: 0.82rem;
  font-weight: 700;
  border-radius: 6px;
  cursor: pointer;
  border: 1px solid var(--xp-border);
  background: white;
  color: var(--xp-text);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.tour-controls button.tour-primary {
  background: var(--xp-accent);
  color: white;
  border-color: var(--xp-accent);
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
}
.tour-controls button:hover:not([disabled]) {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}
.tour-controls button[disabled] {
  opacity: 0.4;
  cursor: not-allowed;
}

@media (max-width: 700px) {
  .tour-card {
    bottom: 8px;
    padding: 14px 16px 12px;
    width: calc(100vw - 16px);
  }
  .tour-card.tour-card-top { top: 8px; }
  .tour-card h3 { font-size: 0.95rem; }
  .tour-card p { font-size: 0.83rem; }
  .tour-controls button { padding: 6px 10px; font-size: 0.78rem; }
}

@media (prefers-reduced-motion: reduce) {
  .tour-card,
  .tour-card-enter-right,
  .tour-card-enter-left,
  .tour-card-exit-left,
  .tour-card-exit-right { animation: none; }
}
