/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #09090f;
  --bg2: #0f0f1a;
  --bg3: #141422;
  --border: #1e1e30;
  --border2: #252538;
  --text: #e2e8f0;
  --muted: #7c8799;
  --accent: #f59e0b;
  --accent2: #fbbf24;
  --accent-dim: rgba(245,158,11,0.12);
  --danger: #ef4444;
  --danger-dim: rgba(239,68,68,0.12);
  --success: #22c55e;
  --success-dim: rgba(34,197,94,0.10);
  --mid: #f97316;
  --mid-dim: rgba(249,115,22,0.12);
  --deflation: #60a5fa;
  --deflation-dim: rgba(96,165,250,0.12);
  --radius: 14px;
  --radius-sm: 8px;
}

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Plus Jakarta Sans', system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  overflow-x: hidden;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ===== LAYOUT ===== */
.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 0 16px;
}

.section { padding: 24px 0; }
.section-sm { padding: 8px 0; }

/* ===== HEADER ===== */
.header {
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(8px);
}

.header-inner {
  max-width: 900px;
  margin: 0 auto;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: 'Sora', sans-serif;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text);
}
.logo-icon { font-size: 1.3rem; }
.logo-accent { color: var(--accent); }

.region-toggle {
  display: flex;
  gap: 6px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
}

.region-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 5px 14px;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.18s;
  white-space: nowrap;
}
.region-btn.active {
  background: var(--accent);
  color: #000;
}
.region-btn:hover:not(.active) { color: var(--text); }

/* ===== HERO ===== */
.hero {
  background: linear-gradient(180deg, var(--bg2) 0%, var(--bg) 100%);
  border-bottom: 1px solid var(--border);
  padding: 36px 0 28px;
  text-align: center;
}

.hero-title {
  font-family: 'Sora', sans-serif;
  font-size: clamp(1.6rem, 5vw, 2.6rem);
  font-weight: 800;
  line-height: 1.15;
  margin-bottom: 10px;
}

.accent { color: var(--accent); }

.hero-sub {
  color: var(--muted);
  font-size: 0.95rem;
  max-width: 480px;
  margin: 0 auto;
}

/* ===== CARDS ===== */
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 0;
}

.card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.card-header .card-icon { font-size: 1.2rem; }

.card-header h2 {
  font-family: 'Sora', sans-serif;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
}

.card-sub {
  color: var(--muted);
  font-size: 0.8rem;
  margin-left: auto;
}

/* ===== CALC CARD ===== */
.calc-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 14px;
  margin-bottom: 20px;
}

.calc-input-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.calc-input-group label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.amount-input-wrap {
  display: flex;
  align-items: center;
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.currency-symbol {
  padding: 0 10px;
  color: var(--accent);
  font-family: 'JetBrains Mono', monospace;
  font-size: 1rem;
  font-weight: 500;
  border-right: 1px solid var(--border2);
  white-space: nowrap;
  background: var(--bg3);
}

input[type="number"], select {
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 0.95rem;
  padding: 9px 12px;
  width: 100%;
  outline: none;
  transition: border-color 0.15s;
  -webkit-appearance: none;
  appearance: none;
}

.amount-input-wrap input[type="number"] {
  border: none;
  border-radius: 0;
  flex: 1;
  min-width: 0;
}

input[type="number"]:focus, select:focus { border-color: var(--accent); }

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%237c8799' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
  cursor: pointer;
}

/* ===== CALC RESULT ===== */
.calc-result {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  align-items: center;
}

.result-box {
  background: var(--accent-dim);
  border: 1px solid rgba(245,158,11,0.25);
  border-radius: var(--radius-sm);
  padding: 16px 18px;
  text-align: center;
}

.result-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
}

.result-amount {
  font-family: 'Sora', sans-serif;
  font-size: clamp(1.5rem, 4vw, 2rem);
  font-weight: 800;
  color: var(--accent);
  line-height: 1.1;
}

.result-detail {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 4px;
}

.result-stats {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.stat-item {
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
}

.stat-value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 1rem;
  font-weight: 500;
  color: var(--text);
}

.stat-label {
  font-size: 0.72rem;
  color: var(--muted);
}

/* ===== POWER BAR ===== */
.power-bar-wrap {
  margin-top: 4px;
}

.power-bar {
  display: flex;
  height: 24px;
  border-radius: 999px;
  overflow: hidden;
  background: var(--bg3);
  border: 1px solid var(--border2);
}

.power-bar-fill {
  background: linear-gradient(90deg, var(--success), #16a34a);
  transition: width 0.5s ease;
  border-radius: 999px 0 0 999px;
}

.power-bar-lost {
  background: linear-gradient(90deg, var(--mid), var(--danger));
  transition: width 0.5s ease;
  border-radius: 0 999px 999px 0;
}

.power-bar-labels {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  font-size: 0.78rem;
}

.pbl-kept { color: var(--success); font-weight: 600; }
.pbl-lost { color: var(--danger); font-weight: 600; }

/* ===== CHART TABS ===== */
.chart-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding-bottom: 2px;
}

.chart-tabs::-webkit-scrollbar { display: none; }

.chart-tab {
  background: var(--bg2);
  border: 1px solid var(--border);
  color: var(--muted);
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 7px 16px;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.18s;
  white-space: nowrap;
}

.chart-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #000;
}

.chart-tab:hover:not(.active) { color: var(--text); border-color: var(--border2); }

.chart-card.hidden { display: none; }

/* ===== CHART ===== */
.chart-wrap {
  position: relative;
  width: 100%;
  height: 260px;
  max-width: 100%;
}

.chart-wrap canvas {
  width: 100% !important;
  max-width: 100%;
}

.chart-legend {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  margin-top: 12px;
  font-size: 0.74rem;
  color: var(--muted);
}

.legend-item { white-space: nowrap; }
.legend-low { color: var(--success); }
.legend-mid { color: var(--mid); }
.legend-high { color: var(--danger); }
.legend-deflation { color: var(--deflation); }

/* ===== CUMULATIVE BASE SELECT ===== */
.cum-base-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  font-size: 0.82rem;
  color: var(--muted);
}

.cum-base-row select {
  width: auto;
  padding: 5px 28px 5px 10px;
  font-size: 0.82rem;
}

/* ===== WORST YEARS ===== */
.worst-years {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.worst-year-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.wy-year {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--muted);
  width: 36px;
  flex-shrink: 0;
}

.wy-bar-wrap {
  flex: 1;
  background: var(--bg3);
  border-radius: 999px;
  height: 20px;
  overflow: hidden;
}

.wy-bar {
  height: 100%;
  border-radius: 999px;
  display: flex;
  align-items: center;
  padding-left: 8px;
  min-width: 40px;
  transition: width 0.4s ease;
}

.wy-rate {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--muted);
  width: 52px;
  text-align: right;
  flex-shrink: 0;
}

/* ===== THEN VS NOW ===== */
.then-now-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.then-now-card {
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
}

.tnc-label {
  font-size: 0.72rem;
  color: var(--muted);
  margin-bottom: 4px;
}

.tnc-years {
  font-size: 0.72rem;
  color: var(--muted);
  font-family: 'JetBrains Mono', monospace;
}

.tnc-from {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text);
}

.tnc-arrow {
  color: var(--accent);
  margin: 0 4px;
  font-size: 0.85rem;
}

.tnc-to {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--accent);
}

.tnc-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 2px;
}

.data-note {
  font-size: 0.72rem;
  color: var(--muted);
  font-style: italic;
}

/* ===== FOOTER ===== */
.footer {
  background: var(--bg2);
  border-top: 1px solid var(--border);
  padding: 24px 0;
  margin-top: 40px;
  text-align: center;
}

.footer p {
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.8;
}

.footer a {
  color: var(--accent);
  text-decoration: none;
}

.footer a:hover { text-decoration: underline; }

.footer-note {
  margin-top: 6px;
  font-style: italic;
  opacity: 0.65;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 640px) {
  .calc-grid {
    grid-template-columns: 1fr 1fr;
  }

  .calc-input-group:first-child {
    grid-column: 1 / -1;
  }

  .calc-result {
    grid-template-columns: 1fr;
  }

  .result-stats {
    flex-direction: row;
    gap: 8px;
  }

  .stat-item {
    flex: 1;
    padding: 8px 10px;
  }

  .stat-value {
    font-size: 0.85rem;
  }

  .stat-label {
    font-size: 0.65rem;
  }

  .chart-wrap {
    height: 220px;
  }

  .then-now-grid {
    grid-template-columns: 1fr 1fr;
  }

  .card-sub { display: none; }

  .hero { padding: 24px 0 18px; }
}

@media (max-width: 400px) {
  .result-stats {
    flex-direction: column;
  }
  .then-now-grid {
    grid-template-columns: 1fr;
  }
}
