:root {
  --bg: #f3f4fb;
  --surface: rgba(255, 255, 255, 0.72);
  --surface-solid: #ffffff;
  --text: #191b29;
  --text-muted: #5b5f77;
  --border: rgba(20, 20, 43, 0.09);
  --primary: #6366f1;
  --primary-2: #8b5cf6;
  --primary-hover: #4f46e5;
  --danger: #dc2626;
  --success: #16a34a;
  --warning-bg: rgba(253, 186, 116, 0.16);
  --warning-border: #fb923c;
  --warning-text: #9a3412;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 1px 2px rgba(20, 20, 43, 0.05), 0 8px 30px rgba(20, 20, 43, 0.07);
  --glow-1: #6366f1;
  --glow-2: #ec4899;
  --glow-3: #22d3ee;
  --glow-4: #22c55e;
  --glow-5: #f59e0b;
  --blob-a: rgba(99, 102, 241, 0.16);
  --blob-b: rgba(34, 211, 238, 0.12);
  --blob-c: rgba(236, 72, 153, 0.10);
}

:root[data-theme="dark"] {
  --bg: #0a0b14;
  --surface: rgba(255, 255, 255, 0.045);
  --surface-solid: #171927;
  --text: #eef0fb;
  --text-muted: #9497b8;
  --border: rgba(255, 255, 255, 0.09);
  --primary: #818cf8;
  --primary-2: #a78bfa;
  --primary-hover: #a5b4fc;
  --danger: #f87171;
  --success: #4ade80;
  --warning-bg: rgba(124, 74, 30, 0.28);
  --warning-border: #c2712f;
  --warning-text: #fdba74;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 12px 40px rgba(0, 0, 0, 0.45);
  --blob-a: rgba(99, 102, 241, 0.28);
  --blob-b: rgba(34, 211, 238, 0.16);
  --blob-c: rgba(236, 72, 153, 0.14);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0a0b14;
    --surface: rgba(255, 255, 255, 0.045);
    --surface-solid: #171927;
    --text: #eef0fb;
    --text-muted: #9497b8;
    --border: rgba(255, 255, 255, 0.09);
    --primary: #818cf8;
    --primary-2: #a78bfa;
    --primary-hover: #a5b4fc;
    --danger: #f87171;
    --success: #4ade80;
    --warning-bg: rgba(124, 74, 30, 0.28);
    --warning-border: #c2712f;
    --warning-text: #fdba74;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 12px 40px rgba(0, 0, 0, 0.45);
    --blob-a: rgba(99, 102, 241, 0.28);
    --blob-b: rgba(34, 211, 238, 0.16);
    --blob-c: rgba(236, 72, 153, 0.14);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.55;
  transition: background 0.3s ease, color 0.3s ease;
  min-height: 100vh;
}
a { color: var(--primary); }
h1, h2, h3 { line-height: 1.25; }
::selection { background: var(--primary); color: #fff; }

/* ---------- animated background ---------- */
.bg-decor {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-color: var(--bg);
  background-image:
    radial-gradient(620px circle at 12% 18%, var(--blob-a), transparent 60%),
    radial-gradient(520px circle at 88% 12%, var(--blob-b), transparent 60%),
    radial-gradient(700px circle at 50% 105%, var(--blob-c), transparent 60%);
  animation: drift 24s ease-in-out infinite alternate;
}
#app, #toast-root { position: relative; z-index: 1; }
@keyframes drift {
  0%   { transform: translate(0, 0) scale(1); }
  100% { transform: translate(-3%, 3%) scale(1.08); }
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes glowPulse {
  0%, 100% { opacity: 0.55; }
  50%      { opacity: 1; }
}

.shell { max-width: 1100px; margin: 0 auto; padding: 0 20px 64px; }

/* ---------- topbar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 14px 24px; border-bottom: 1px solid var(--border);
  background: var(--surface); backdrop-filter: blur(16px) saturate(160%);
  -webkit-backdrop-filter: blur(16px) saturate(160%);
  position: sticky; top: 0; z-index: 10; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.15rem; text-decoration: none; color: var(--text); letter-spacing: -0.01em; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 10px; color: #fff; display: flex;
  align-items: center; justify-content: center; font-weight: 700;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  box-shadow: 0 0 0 1px rgba(255,255,255,0.15) inset, 0 4px 16px rgba(99, 102, 241, 0.45);
}
/* ---------- primary nav ---------- */
.nav { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.nav a {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 999px;
  color: var(--text-muted); text-decoration: none; font-weight: 650; font-size: 0.88rem;
  transition: all 0.2s ease; white-space: nowrap;
}
.nav a:hover { background: var(--border); color: var(--text); }
.nav a.active {
  background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: #fff;
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.35);
}

/* Below 721px, the nav becomes a fixed bottom tab bar (mobile app pattern)
 * instead of squeezing into the topbar row. `.nav` is a child of `.topbar`
 * in the DOM; position:fixed normally pulls an element out of the flow and
 * pins it to the viewport regardless of nesting - BUT `.topbar` has its own
 * backdrop-filter (for its glass effect), and backdrop-filter/filter on an
 * ancestor establishes a new containing block for fixed descendants (same
 * as transform does), so `.nav`'s "fixed to bottom" was computing relative
 * to the small topbar box instead of the viewport - it rendered near the
 * top, with its opaque background covering the topbar's own controls that
 * wrapped onto a second line beneath it. Disabling `.topbar`'s
 * backdrop-filter at this breakpoint removes that trap; `.shell` gets
 * matching bottom padding so content never sits underneath the real bottom
 * nav, and env(safe-area-inset-bottom) clears the home-indicator area on
 * notched phones. */
@media (max-width: 720px) {
  .topbar { backdrop-filter: none; -webkit-backdrop-filter: none; }
  .nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    justify-content: space-around; gap: 0; flex-wrap: nowrap;
    background: var(--surface-solid); backdrop-filter: blur(16px) saturate(160%);
    -webkit-backdrop-filter: blur(16px) saturate(160%);
    border-top: 1px solid var(--border);
    padding: 8px 4px calc(6px + env(safe-area-inset-bottom));
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.18);
  }
  .nav a {
    flex: 1; flex-direction: column; gap: 2px; padding: 6px 2px;
    border-radius: var(--radius-sm); font-size: 0.66rem; white-space: normal;
    text-align: center;
  }
  .nav a span:first-child { font-size: 1.2rem; }
  .nav a.active { box-shadow: 0 2px 10px rgba(99, 102, 241, 0.35); }
  .shell { padding-bottom: 92px; }
}

.topbar-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.icon-btn {
  background: none; border: 1px solid transparent; cursor: pointer; color: var(--text-muted);
  padding: 7px; border-radius: var(--radius-sm); transition: background 0.2s ease, color 0.2s ease, transform 0.15s ease;
  line-height: 1;
}
.icon-btn:hover { background: var(--border); color: var(--text); transform: translateY(-1px); }

/* ---------- buttons & forms ---------- */
button { font: inherit; }
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 11px 20px;
  border-radius: var(--radius-sm); border: 1px solid transparent; cursor: pointer;
  font-weight: 650; font-size: 0.95rem; color: #fff;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.28), 0 0 0 1px rgba(255,255,255,0.08) inset;
  transition: transform 0.15s ease, box-shadow 0.2s ease, filter 0.2s ease;
}
.btn:hover { filter: brightness(1.08); transform: translateY(-1px); box-shadow: 0 6px 18px rgba(99, 102, 241, 0.4), 0 0 0 1px rgba(255,255,255,0.1) inset; }
.btn:active { transform: translateY(0) scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; filter: none; transform: none; box-shadow: none; }
.btn-secondary {
  background: var(--surface); color: var(--text); border-color: var(--border);
  box-shadow: var(--shadow); backdrop-filter: blur(8px);
}
.btn-secondary:hover { border-color: var(--primary); box-shadow: 0 4px 16px rgba(99, 102, 241, 0.2); filter: none; }
.btn-ghost { background: none; color: var(--primary); box-shadow: none; }
.btn-ghost:hover { background: var(--border); box-shadow: none; transform: none; filter: none; }
.btn-danger { background: linear-gradient(135deg, #ef4444, #dc2626); box-shadow: 0 2px 8px rgba(220, 38, 38, 0.35); }

/* icon-only social sign-in chips (login.js) - small, side by side, each
   holding just the provider's own full-color brand mark, no label text */
.social-btns { display: flex; justify-content: center; gap: 12px; }
.social-btn {
  display: flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; flex: none; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface);
  cursor: pointer; transition: filter .12s, transform .05s;
}
.social-btn svg { width: 18px; height: 18px; }
.social-btn:hover { filter: brightness(.97); }
[data-theme="dark"] .social-btn:hover { filter: brightness(1.15); }
.social-btn:active { transform: scale(.98); }
.social-btn:disabled { opacity: .5; cursor: not-allowed; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field label { font-size: 0.85rem; font-weight: 650; color: var(--text-muted); }
.field input, .field select {
  padding: 11px 13px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface-solid); color: var(--text); font-size: 1rem;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.field input:focus, .field select:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.18);
}
.field .hint { font-size: 0.78rem; color: var(--text-muted); }
.row { display: flex; gap: 16px; flex-wrap: wrap; }
.row > .field { flex: 1; min-width: 200px; }

/* ---------- cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 24px; box-shadow: var(--shadow); backdrop-filter: blur(14px) saturate(160%);
  -webkit-backdrop-filter: blur(14px) saturate(160%);
  animation: fadeInUp 0.45s ease both;
}
.card + .card { margin-top: 16px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 18px; }
.grid > .card + .card { margin-top: 0; }

.calc-card {
  --glow: var(--glow-1);
  display: flex; flex-direction: column; gap: 10px; text-decoration: none; color: var(--text);
  position: relative; overflow: hidden;
  transition: transform 0.25s cubic-bezier(.2,.8,.2,1), box-shadow 0.25s ease, border-color 0.25s ease;
}
.calc-card::before {
  content: ""; position: absolute; inset: -40% -40% auto auto; width: 160px; height: 160px;
  background: radial-gradient(circle, var(--glow), transparent 70%);
  opacity: 0.22; filter: blur(10px); transition: opacity 0.3s ease, transform 0.3s ease; pointer-events: none;
}
.calc-card:hover {
  transform: translateY(-4px) scale(1.015);
  border-color: color-mix(in srgb, var(--glow) 55%, var(--border));
  box-shadow: 0 10px 30px -8px color-mix(in srgb, var(--glow) 45%, transparent), var(--shadow);
}
.calc-card:hover::before { opacity: 0.38; transform: scale(1.15); }
.calc-card:nth-of-type(5n+1) { --glow: var(--glow-1); }
.calc-card:nth-of-type(5n+2) { --glow: var(--glow-2); }
.calc-card:nth-of-type(5n+3) { --glow: var(--glow-3); }
.calc-card:nth-of-type(5n+4) { --glow: var(--glow-4); }
.calc-card:nth-of-type(5n+5) { --glow: var(--glow-5); }
.grid > .calc-card { animation: fadeInUp 0.5s ease both; }
.grid > .calc-card:nth-of-type(1) { animation-delay: 0.02s; }
.grid > .calc-card:nth-of-type(2) { animation-delay: 0.08s; }
.grid > .calc-card:nth-of-type(3) { animation-delay: 0.14s; }
.grid > .calc-card:nth-of-type(4) { animation-delay: 0.2s; }
.grid > .calc-card:nth-of-type(5) { animation-delay: 0.26s; }
.grid > .calc-card:nth-of-type(n+6) { animation-delay: 0.3s; }

.calc-card .emoji {
  width: 52px; height: 52px; display: flex; align-items: center; justify-content: center;
  font-size: 1.6rem; border-radius: 14px;
  background: linear-gradient(135deg, color-mix(in srgb, var(--glow) 30%, transparent), color-mix(in srgb, var(--glow) 10%, transparent));
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--glow) 30%, var(--border)) inset;
}
.calc-card h3 { margin: 0; font-size: 1.08rem; }
.calc-card p { margin: 0; color: var(--text-muted); font-size: 0.88rem; }

/* ---------- disclaimer ---------- */
.disclaimer {
  display: flex; gap: 12px; align-items: flex-start; background: var(--warning-bg);
  border: 1px solid var(--warning-border); color: var(--warning-text);
  border-radius: var(--radius-sm); padding: 14px 16px; font-size: 0.85rem; margin-bottom: 20px;
  backdrop-filter: blur(10px);
}
.disclaimer span:first-child { animation: glowPulse 2.4s ease-in-out infinite; font-size: 1.05rem; }
.disclaimer-inline {
  display: inline-block; font-size: 0.72rem; color: var(--text-muted); font-weight: 600;
  border: 1px solid var(--border); border-radius: 999px; padding: 3px 10px; margin-left: 6px;
  background: var(--surface);
}

/* ---------- results ---------- */
.result-stat { display: flex; flex-direction: column; gap: 3px; }
.result-stat .label { font-size: 0.8rem; color: var(--text-muted); font-weight: 600; }
.result-stat .value {
  font-size: 1.65rem; font-weight: 800; letter-spacing: -0.01em;
  background: linear-gradient(135deg, var(--text), var(--primary));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.result-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 16px; margin: 16px 0; }
table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); }
th { color: var(--text-muted); font-weight: 650; }
tbody tr { transition: background 0.15s ease; }
tbody tr:hover { background: var(--border); }

/* ---------- wizard (income tax) ---------- */
.wizard-steps { display: flex; gap: 8px; margin-bottom: 20px; flex-wrap: wrap; position: relative; }
.wizard-step-pill {
  padding: 7px 14px; border-radius: 999px; font-size: 0.8rem; font-weight: 650;
  background: var(--surface-solid); color: var(--text-muted); border: 1px solid var(--border);
  transition: all 0.25s ease;
}
.wizard-step-pill.active {
  background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: #fff; border-color: transparent;
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.4);
}
.wizard-step-pill.done { color: var(--success); border-color: color-mix(in srgb, var(--success) 40%, var(--border)); }
.wizard-nav { display: flex; justify-content: space-between; margin-top: 20px; }

.regime-compare { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 640px) { .regime-compare { grid-template-columns: 1fr; } }
.regime-card { border-radius: var(--radius); border: 2px solid var(--border); padding: 20px; transition: all 0.25s ease; }
.regime-card.winner { border-color: var(--success); box-shadow: 0 0 0 1px color-mix(in srgb, var(--success) 30%, transparent), 0 10px 30px -10px color-mix(in srgb, var(--success) 50%, transparent); }
.regime-card .badge {
  display: inline-block; background: linear-gradient(135deg, var(--success), #22c55e); color: #fff;
  font-size: 0.72rem; font-weight: 700; padding: 3px 10px; border-radius: 999px; margin-bottom: 8px;
  box-shadow: 0 2px 8px rgba(34, 197, 94, 0.35);
}

/* ---------- portfolio mix ---------- */
.mix-row { display: grid; grid-template-columns: 1fr 140px 110px auto; gap: 10px; align-items: end; margin-bottom: 10px; }
@media (max-width: 720px) { .mix-row { grid-template-columns: 1fr 1fr; } }

/* ---------- toast ---------- */
#toast-root { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast {
  background: var(--surface-solid); color: var(--text); padding: 12px 18px; border-radius: var(--radius-sm);
  font-size: 0.9rem; font-weight: 600; box-shadow: var(--shadow); border: 1px solid var(--border);
  animation: fadeInUp 0.25s ease both;
}

/* ---------- misc ---------- */
.muted { color: var(--text-muted); }
.section-title { margin: 32px 0 12px; }
.empty-state { text-align: center; padding: 40px 20px; color: var(--text-muted); }
footer.app-footer { text-align: center; padding: 28px; color: var(--text-muted); font-size: 0.8rem; }
.app-footer-links { display: flex; justify-content: center; gap: 20px; flex-wrap: wrap; margin-bottom: 10px; }
.app-footer-links a { color: var(--text-muted); text-decoration: none; font-weight: 650; font-size: 0.82rem; transition: color 0.2s ease; }
.app-footer-links a:hover { color: var(--primary); }

/* ---------- FAQ ---------- */
.faq-item { border-bottom: 1px solid var(--border); padding: 14px 0; }
.faq-item:last-of-type { border-bottom: none; }
.faq-item summary {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  cursor: pointer; font-weight: 650; list-style: none;
}
.faq-item summary::-webkit-details-marker { display: none; }
.faq-item[open] .faq-chevron { transform: rotate(180deg); }
.faq-chevron { transition: transform 0.2s ease; color: var(--text-muted); flex-shrink: 0; }
.faq-answer { padding-top: 10px; color: var(--text-muted); }
.faq-answer p { margin: 0; }
.history-item { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 0; border-bottom: 1px solid var(--border); transition: background 0.15s ease; }
.history-item:hover { background: var(--border); border-radius: var(--radius-sm); }
.history-item:last-child { border-bottom: none; }

/* ---------- scrollbar ---------- */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: color-mix(in srgb, var(--primary) 40%, transparent); border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: color-mix(in srgb, var(--primary) 60%, transparent); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
  .bg-decor { animation: none; }
}

@media (max-width: 480px) {
  .shell { padding: 0 14px 48px; }
  .card { padding: 18px; border-radius: var(--radius-sm); }
  .topbar { padding: 12px 16px; }
}
