/* ───────────────────────────────────────────────
   IRP / ISA Simulator — Design System (v2)
   Inspired by Korean fintech (Toss / KakaoBank)
   ─────────────────────────────────────────────── */

/* Font — Pretendard via CDN with system fallback */
@import url("https://cdn.jsdelivr.net/gh/orioncactus/pretendard@v1.3.9/dist/web/static/pretendard.css");

:root {
  /* Surface */
  --bg:           #f3f5f9;
  --bg-grad:      radial-gradient(1200px 600px at 0% -10%, #e9eaff 0%, transparent 60%),
                  radial-gradient(900px 500px at 100% 0%, #e7fff5 0%, transparent 55%),
                  #f3f5f9;
  --surface:      #ffffff;
  --surface-elev: #ffffff;
  --border:       rgba(15, 23, 42, 0.06);
  --border-strong:rgba(15, 23, 42, 0.10);

  /* Ink */
  --ink-1:  #0a0e1a;
  --ink-2:  #2c3344;
  --ink-3:  #6b7488;
  --ink-4:  #a7afc2;
  --ink-5:  #d6dae3;

  /* Brand */
  --brand:        #4f46e5;
  --brand-2:      #7c3aed;
  --brand-soft:   #eef0ff;
  --brand-grad:   linear-gradient(135deg, #6366f1 0%, #8b5cf6 45%, #a855f7 100%);

  /* Accent (절세/긍정) */
  --accent:       #10b981;
  --accent-2:     #14b8a6;
  --accent-soft:  #d1fae5;
  --accent-grad:  linear-gradient(135deg, #10b981 0%, #14b8a6 100%);

  /* Comparison (일반계좌) */
  --blue:         #2563eb;
  --blue-soft:    #dbeafe;

  /* Status */
  --warn:         #f59e0b;
  --warn-soft:    #fef3c7;
  --danger:       #ef4444;

  /* Scenario palette */
  --sc-1: #4f46e5;
  --sc-2: #10b981;
  --sc-3: #f59e0b;
  --sc-4: #ec4899;

  /* Shadows */
  --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.04), 0 1px 2px rgba(15, 23, 42, 0.03);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.05), 0 2px 4px rgba(15, 23, 42, 0.03);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.08), 0 4px 8px rgba(15, 23, 42, 0.04);
  --shadow-hero: 0 32px 64px -16px rgba(79, 70, 229, 0.35), 0 0 0 1px rgba(255, 255, 255, 0.05) inset;
  --ring:      0 0 0 3px rgba(79, 70, 229, 0.18);

  /* Radii */
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 22px;
  --r-2xl: 28px;

  /* Transitions */
  --t-fast: 120ms cubic-bezier(0.4, 0, 0.2, 1);
  --t: 200ms cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
  background: var(--bg-grad);
  color: var(--ink-1);
  font-family: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont,
    "Apple SD Gothic Neo", "Malgun Gothic", "Segoe UI", system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.55;
  letter-spacing: -0.01em;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
}

/* ────────── Typography ────────── */
h1, h2, h3, h4 { margin: 0; font-weight: 700; letter-spacing: -0.025em; }
h1 { font-size: 20px; }
h2 { font-size: 11px; letter-spacing: 0.12em; color: var(--ink-3); text-transform: uppercase; margin-bottom: 14px; font-weight: 700; }
h3 { font-size: 15px; color: var(--ink-1); }
.muted { color: var(--ink-3); font-size: 12.5px; }
.tiny { font-size: 11.5px; color: var(--ink-3); }

/* ────────── Topbar ────────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 32px;
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: saturate(180%) blur(16px);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}
.brand { display: flex; gap: 12px; align-items: center; }
.brand .logo {
  width: 36px; height: 36px;
  border-radius: 10px;
  background: var(--brand-grad);
  color: #fff;
  display: grid; place-items: center;
  font-weight: 800;
  font-size: 16px;
  box-shadow: 0 6px 16px -4px rgba(99, 102, 241, 0.5);
}
.brand-title { line-height: 1.2; }
.brand-title h1 { font-size: 15.5px; }
.brand-title p { font-size: 12px; margin: 1px 0 0; color: var(--ink-3); }

.topbar-actions { display: flex; gap: 8px; align-items: center; }
.btn-ghost, .btn-primary {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px;
  border-radius: var(--r-md);
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: var(--t);
  border: 1px solid transparent;
  letter-spacing: -0.01em;
}
.btn-ghost {
  background: rgba(15, 23, 42, 0.04);
  color: var(--ink-2);
  border-color: transparent;
}
.btn-ghost:hover { background: rgba(15, 23, 42, 0.07); }
.btn-primary {
  background: var(--brand-grad);
  color: #fff;
  border: none;
  box-shadow: 0 6px 16px -4px rgba(99, 102, 241, 0.45);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 10px 24px -6px rgba(99, 102, 241, 0.55); }
.btn-primary:active { transform: translateY(0); }

/* ────────── Hero ────────── */
.hero {
  margin: 24px 32px 0;
  padding: 36px 40px;
  border-radius: var(--r-2xl);
  background: var(--brand-grad);
  color: #fff;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-hero);
}
.hero::before, .hero::after {
  content: ""; position: absolute; border-radius: 50%;
  filter: blur(60px); opacity: 0.5; pointer-events: none;
}
.hero::before { width: 320px; height: 320px; background: #ec4899; top: -100px; right: -80px; }
.hero::after { width: 280px; height: 280px; background: #06b6d4; bottom: -120px; left: 20%; }
.hero-content { position: relative; z-index: 1; display: flex; justify-content: space-between; align-items: end; gap: 32px; flex-wrap: wrap; }
.hero-line { font-size: 13px; opacity: 0.88; font-weight: 500; letter-spacing: 0.02em; margin-bottom: 4px; }
.hero-headline {
  font-size: 14px;
  opacity: 0.9;
  font-weight: 500;
  letter-spacing: 0.02em;
  margin-bottom: 12px;
}
.hero-amount {
  font-size: 56px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
}
.hero-amount .unit { font-size: 22px; font-weight: 600; opacity: 0.85; margin-left: 6px; letter-spacing: -0.02em; }
.hero-meta { font-size: 13.5px; opacity: 0.88; margin-top: 14px; max-width: 480px; }

.hero-side { display: flex; gap: 12px; }
.hero-stat {
  background: rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.18);
  padding: 14px 18px;
  border-radius: var(--r-lg);
  min-width: 130px;
}
.hero-stat-label { font-size: 11.5px; opacity: 0.82; font-weight: 500; }
.hero-stat-value { font-size: 22px; font-weight: 700; margin-top: 4px; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.hero-stat-value .unit { font-size: 12.5px; font-weight: 600; opacity: 0.82; margin-left: 3px; }

/* ────────── Layout ────────── */
.layout {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 20px;
  padding: 24px 32px 80px;
  align-items: start;
}
@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; }
  .hero { margin: 16px; padding: 24px; }
  .hero-amount { font-size: 40px; }
  .topbar { padding: 14px 16px; }
}

.inputs-wrap {
  position: sticky;
  top: 80px;
  max-height: calc(100vh - 100px);
  overflow-y: auto;
  padding-right: 4px;
  scrollbar-width: thin;
}
.inputs-wrap::-webkit-scrollbar { width: 6px; }
.inputs-wrap::-webkit-scrollbar-thumb { background: var(--ink-5); border-radius: 3px; }

/* ────────── Card ────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  padding: 22px;
  box-shadow: var(--shadow-sm);
}
.card-header {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-bottom: 14px;
}
.card-header .subtitle {
  color: var(--ink-3); font-size: 12px; margin-top: 2px;
}
.results { display: flex; flex-direction: column; gap: 20px; }

/* ────────── Form Inputs ────────── */
.form-group {
  margin-bottom: 22px;
}
.form-group:last-child { margin-bottom: 0; }
.form-group-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-3);
  margin-bottom: 10px;
  display: flex; align-items: center; gap: 6px;
}
.form-group-title::after {
  content: ""; flex: 1; height: 1px; background: var(--border);
}

.field { display: block; margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }
.field-label {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 12.5px;
  color: var(--ink-2);
  font-weight: 600;
  margin-bottom: 7px;
}
.field-value-badge {
  background: var(--brand-soft);
  color: var(--brand);
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.input,
.select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  font-size: 14px;
  font-weight: 500;
  background: var(--surface);
  color: var(--ink-1);
  font-family: inherit;
  font-variant-numeric: tabular-nums;
  transition: var(--t);
}
.input:focus, .select:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: var(--ring);
}
.input-row { display: flex; align-items: center; gap: 8px; }
.input-suffix {
  position: relative;
}
.input-suffix .input { padding-right: 38px; }
.input-suffix::after {
  content: attr(data-suffix);
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 12.5px;
  color: var(--ink-3);
  font-weight: 500;
  pointer-events: none;
}
.hint { color: var(--ink-3); font-size: 11.5px; margin-top: 5px; display: block; line-height: 1.4; }

/* Custom slider */
.slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  background: linear-gradient(to right, var(--brand) 0%, var(--brand) var(--p, 50%), var(--ink-5) var(--p, 50%));
  border-radius: 999px;
  outline: none;
  cursor: pointer;
}
.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px; height: 20px;
  background: #fff;
  border: 3px solid var(--brand);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(79, 70, 229, 0.3);
  transition: var(--t-fast);
}
.slider::-webkit-slider-thumb:hover { transform: scale(1.1); }
.slider::-moz-range-thumb {
  width: 20px; height: 20px;
  background: #fff;
  border: 3px solid var(--brand);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(79, 70, 229, 0.3);
}

/* Toggle chips for account selection */
.chip-group { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  flex: 1;
  min-width: 0;
  position: relative;
  padding: 12px 10px;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--r-md);
  background: var(--surface);
  cursor: pointer;
  transition: var(--t);
  text-align: center;
  display: flex; flex-direction: column; gap: 2px; align-items: center;
}
.chip-name { font-size: 12.5px; font-weight: 700; color: var(--ink-2); }
.chip-sub { font-size: 10.5px; color: var(--ink-3); font-weight: 500; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip:hover { border-color: var(--brand); background: var(--brand-soft); }
.chip:has(input:checked) {
  border-color: var(--brand);
  background: var(--brand);
}
.chip:has(input:checked) .chip-name { color: #fff; }
.chip:has(input:checked) .chip-sub { color: rgba(255, 255, 255, 0.85); }

/* Segmented control */
.segmented {
  display: flex;
  background: rgba(15, 23, 42, 0.04);
  padding: 3px;
  border-radius: var(--r-md);
  gap: 2px;
}
.segmented label {
  flex: 1; text-align: center; padding: 7px 8px;
  font-size: 12.5px; font-weight: 600;
  color: var(--ink-3);
  cursor: pointer;
  border-radius: calc(var(--r-md) - 3px);
  transition: var(--t-fast);
}
.segmented input { display: none; }
.segmented label:has(input:checked) {
  background: #fff;
  color: var(--ink-1);
  box-shadow: var(--shadow-xs);
}

/* ────────── Scenario tabs ────────── */
.scenarios-bar {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  padding: 8px;
  box-shadow: var(--shadow-sm);
  flex-wrap: wrap;
}
.scenario-tab {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 14px 8px 12px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--r-md);
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-2);
  transition: var(--t-fast);
  position: relative;
}
.scenario-tab .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--sc-1); }
.scenario-tab:hover { background: rgba(15, 23, 42, 0.04); }
.scenario-tab.active {
  background: var(--ink-1);
  color: #fff;
}
.scenario-tab.active .dot { background: #fff; }
.scenario-tab .close {
  width: 16px; height: 16px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  display: grid; place-items: center;
  font-size: 11px;
  margin-left: 2px;
  color: rgba(255, 255, 255, 0.7);
  transition: var(--t-fast);
}
.scenario-tab:not(.active) .close {
  background: rgba(15, 23, 42, 0.08);
  color: var(--ink-3);
}
.scenario-tab .close:hover { background: var(--danger); color: #fff; }

.scenario-add {
  margin-left: auto;
  padding: 8px 12px;
  background: var(--brand-soft);
  color: var(--brand);
  border: none;
  border-radius: var(--r-md);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
  transition: var(--t-fast);
}
.scenario-add:hover { background: var(--brand); color: #fff; }

.compare-toggle {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px;
  font-size: 12.5px;
  color: var(--ink-2);
  font-weight: 600;
  cursor: pointer;
}
.compare-toggle input { accent-color: var(--brand); width: 14px; height: 14px; }

/* ────────── KPI cards ────────── */
.kpi-row {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px;
}
@media (max-width: 1200px) { .kpi-row { grid-template-columns: repeat(2, 1fr); } }

.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
  transition: var(--t);
}
.kpi::before {
  content: ""; position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: var(--brand-grad);
  opacity: 0.9;
}
.kpi.accent::before { background: var(--accent-grad); }
.kpi.warn::before { background: linear-gradient(90deg, #f59e0b, #ef4444); }
.kpi-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: 10px;
  background: var(--brand-soft); color: var(--brand);
  margin-bottom: 10px;
  font-size: 16px;
}
.kpi.accent .kpi-icon { background: var(--accent-soft); color: var(--accent); }
.kpi-label { font-size: 12px; color: var(--ink-3); font-weight: 600; margin-bottom: 6px; letter-spacing: 0.01em; }
.kpi-value {
  font-size: 26px;
  font-weight: 800;
  color: var(--ink-1);
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
  transition: color var(--t);
}
.kpi-value .unit { font-size: 13px; font-weight: 600; color: var(--ink-3); margin-left: 3px; letter-spacing: -0.01em; }
.kpi-sub { font-size: 11.5px; color: var(--ink-3); margin-top: 6px; }
.kpi-sub strong { color: var(--accent); font-weight: 700; }

/* ────────── Chart ────────── */
.chart-card { display: flex; flex-direction: column; }
.chart-card h3 { margin-bottom: 2px; }
.chart-card .card-header p { color: var(--ink-3); font-size: 12px; margin: 4px 0 0; }
.chart-wrap { position: relative; }
.chart { width: 100%; height: 280px; }
.chart svg { width: 100%; height: 100%; display: block; overflow: visible; }
.chart-tip {
  position: absolute;
  background: var(--ink-1);
  color: #fff;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  pointer-events: none;
  transform: translate(-50%, calc(-100% - 10px));
  white-space: nowrap;
  box-shadow: 0 10px 24px -6px rgba(0,0,0,0.4);
  opacity: 0;
  transition: opacity var(--t-fast);
  font-variant-numeric: tabular-nums;
  z-index: 5;
}
.chart-tip.visible { opacity: 1; }
.chart-tip::after {
  content: "";
  position: absolute;
  bottom: -4px; left: 50%; transform: translateX(-50%) rotate(45deg);
  width: 8px; height: 8px; background: var(--ink-1);
}
.chart-tip .tip-label { font-size: 10.5px; opacity: 0.7; font-weight: 500; }
.chart-tip .tip-row { display: flex; align-items: center; gap: 6px; margin-top: 3px; }
.chart-tip .tip-row .swatch { width: 8px; height: 8px; border-radius: 50%; }

.legend {
  display: flex; flex-wrap: wrap; gap: 14px; align-items: center;
  font-size: 12px; color: var(--ink-2); margin-top: 8px;
}
.legend-item { display: inline-flex; align-items: center; gap: 6px; font-weight: 500; }
.legend-item .swatch { width: 10px; height: 10px; border-radius: 50%; }

.grid-two { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 900px) { .grid-two { grid-template-columns: 1fr; } }

/* ────────── Portfolio donut ────────── */
.pf-layout { display: grid; grid-template-columns: 200px 1fr; gap: 24px; align-items: center; }
@media (max-width: 720px) { .pf-layout { grid-template-columns: 1fr; } }
.donut { width: 200px; height: 200px; position: relative; }
.donut svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.donut-center {
  position: absolute; inset: 0; display: grid; place-items: center; text-align: center;
}
.donut-center .lbl { font-size: 10.5px; color: var(--ink-3); text-transform: uppercase; letter-spacing: 0.1em; font-weight: 700; }
.donut-center .val { font-size: 20px; font-weight: 800; letter-spacing: -0.02em; margin-top: 2px; }
.donut-center .sub { font-size: 11px; color: var(--ink-3); margin-top: 2px; }

.pf-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.pf-item { display: grid; grid-template-columns: 14px 1fr auto; gap: 10px; align-items: center; padding: 8px 12px; border-radius: var(--r-md); transition: var(--t-fast); }
.pf-item:hover { background: rgba(15, 23, 42, 0.03); }
.pf-item .sw { width: 10px; height: 10px; border-radius: 3px; }
.pf-item .name { font-size: 13px; font-weight: 600; color: var(--ink-1); line-height: 1.3; }
.pf-item .etf { font-size: 11px; color: var(--ink-3); line-height: 1.3; margin-top: 1px; }
.pf-item .w { font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--ink-1); }

/* ────────── Strategy / notes ────────── */
.strategy { list-style: none; padding: 0; margin: 0; }
.strategy li {
  padding: 12px 14px 12px 38px;
  background: rgba(79, 70, 229, 0.04);
  border-left: 3px solid var(--brand);
  border-radius: 6px;
  margin-bottom: 8px;
  font-size: 13px;
  color: var(--ink-2);
  position: relative;
  line-height: 1.55;
}
.strategy li::before {
  content: "✓";
  position: absolute; left: 14px; top: 12px;
  color: var(--brand); font-weight: 800;
  width: 16px; height: 16px;
  display: grid; place-items: center;
}
.strategy li b { color: var(--ink-1); font-weight: 700; }

.notes {
  list-style: none; padding: 0; margin: 0;
  display: grid; gap: 6px;
}
.notes li {
  font-size: 12px;
  color: var(--ink-3);
  padding-left: 16px;
  position: relative;
  line-height: 1.55;
}
.notes li::before {
  content: ""; position: absolute; left: 4px; top: 8px;
  width: 4px; height: 4px; border-radius: 50%; background: var(--ink-4);
}

/* ────────── Comparison table ────────── */
.compare-table {
  width: 100%; border-collapse: collapse;
}
.compare-table th, .compare-table td {
  padding: 10px 12px;
  text-align: right;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
}
.compare-table th:first-child, .compare-table td:first-child { text-align: left; font-weight: 600; color: var(--ink-2); }
.compare-table th { font-size: 11.5px; font-weight: 700; color: var(--ink-3); text-transform: uppercase; letter-spacing: 0.05em; }
.compare-table .sc-label { display: inline-flex; align-items: center; gap: 6px; }
.compare-table .sc-label .dot { width: 8px; height: 8px; border-radius: 50%; }
.compare-table .num { font-weight: 700; color: var(--ink-1); }
.compare-table .best { color: var(--accent); }

/* ────────── Toast ────────── */
.toast {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translate(-50%, 80px);
  background: var(--ink-1);
  color: #fff;
  padding: 12px 20px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 20px 40px -10px rgba(0, 0, 0, 0.5);
  z-index: 200;
  opacity: 0;
  transition: var(--t);
  display: flex; align-items: center; gap: 8px;
}
.toast.visible { transform: translate(-50%, 0); opacity: 1; }
.toast .check {
  width: 18px; height: 18px; background: var(--accent);
  border-radius: 50%; display: grid; place-items: center; font-size: 11px;
}

/* ────────── Animations ────────── */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.card, .kpi, .hero, .scenarios-bar { animation: fadeUp 360ms cubic-bezier(0.4, 0, 0.2, 1) both; }
.kpi:nth-child(2) { animation-delay: 40ms; }
.kpi:nth-child(3) { animation-delay: 80ms; }
.kpi:nth-child(4) { animation-delay: 120ms; }

@keyframes drawIn {
  from { stroke-dashoffset: var(--draw-len, 1000); }
  to   { stroke-dashoffset: 0; }
}
.series { stroke-dasharray: var(--draw-len, 1000); animation: drawIn 800ms cubic-bezier(0.4, 0, 0.2, 1) both; }

/* SVG bits */
.series-regular { fill: none; stroke: var(--blue); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.series-saving  { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.area-fill      { opacity: 0.18; }
.axis text { fill: var(--ink-3); font-size: 10.5px; font-weight: 500; }
.grid line { stroke: rgba(15, 23, 42, 0.05); }
.crosshair { stroke: var(--ink-1); stroke-dasharray: 3 3; stroke-width: 1; opacity: 0.4; }

/* ════════════════════════════════════════════════════════
   App Shell — Sidebar Navigation
   ════════════════════════════════════════════════════════ */
.app-shell { display: flex; min-height: 100vh; }

.sidenav {
  width: 220px;
  background: rgba(255,255,255,0.65);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-right: 1px solid var(--border);
  padding: 18px 14px;
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 14px;
  z-index: 40;
}
.sidenav-brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 12px; }
.sidenav-brand .logo {
  width: 32px; height: 32px;
  border-radius: 9px;
  background: var(--brand-grad); color: #fff;
  display: grid; place-items: center; font-weight: 800;
  box-shadow: 0 6px 16px -4px rgba(99,102,241,0.45);
}
.sidenav-brand .brand-name { font-weight: 800; font-size: 16px; letter-spacing: -0.02em; }
.sidenav-brand .brand-sub { font-size: 10.5px; color: var(--ink-3); letter-spacing: 0.04em; text-transform: uppercase; font-weight: 600; }

.nav-section { font-size: 10.5px; font-weight: 700; color: var(--ink-3); letter-spacing: 0.12em; text-transform: uppercase; padding: 12px 10px 6px; }
.nav-items { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px;
  border-radius: 10px;
  background: transparent;
  border: none;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink-2);
  cursor: pointer;
  text-align: left;
  transition: var(--t-fast);
  position: relative;
}
.nav-item .nav-icon {
  width: 26px; height: 26px;
  border-radius: 8px;
  background: rgba(15,23,42,0.04);
  display: grid; place-items: center;
  font-size: 13px;
  transition: var(--t-fast);
}
.nav-item:hover { background: rgba(15,23,42,0.04); color: var(--ink-1); }
.nav-item.active {
  background: var(--brand-grad);
  color: #fff;
  box-shadow: 0 6px 16px -6px rgba(99,102,241,0.5);
}
.nav-item.active .nav-icon { background: rgba(255,255,255,0.2); }
.nav-spacer { flex: 1; }
.nav-foot { font-size: 11px; color: var(--ink-3); padding: 8px 10px; line-height: 1.4; }

/* main area */
.main-area { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.main-area .topbar { padding: 14px 28px; }
.main-area .topbar-titles h1 { font-size: 18px; }
.main-area .topbar-titles p { font-size: 12.5px; color: var(--ink-3); margin: 2px 0 0; }

@media (max-width: 900px) {
  .sidenav { width: 64px; }
  .sidenav-brand .brand-name, .sidenav-brand .brand-sub { display: none; }
  .nav-item .nav-text, .nav-section { display: none; }
  .nav-item { justify-content: center; padding: 10px; }
  .nav-foot { display: none; }
}

/* views */
.view { display: none; animation: fadeUp 360ms cubic-bezier(0.4,0,0.2,1) both; }
.view.active { display: block; }

.view-content {
  padding: 20px 28px 80px;
  max-width: 1500px;
  margin: 0 auto;
}

/* page header (for tax / compound) */
.page-header {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-2xl);
  padding: 28px 32px;
  margin-bottom: 20px;
  display: flex; align-items: center; justify-content: space-between;
  gap: 24px;
  background: linear-gradient(135deg, #ffffff, #f8f9ff 60%, #f3f6ff);
}
.page-header h2 {
  font-size: 11px; letter-spacing: 0.14em; color: var(--brand);
  text-transform: uppercase; margin-bottom: 6px;
}
.page-header h1 { font-size: 26px; letter-spacing: -0.03em; }
.page-header .page-meta { color: var(--ink-3); font-size: 13.5px; margin-top: 6px; max-width: 540px; }

/* ════════════════════════════════════════════════════════
   Tax view
   ════════════════════════════════════════════════════════ */
.tax-layout {
  display: grid; grid-template-columns: 1fr 1fr; gap: 20px;
}
@media (max-width: 1000px) { .tax-layout { grid-template-columns: 1fr; } }

.tax-field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tax-field-row .field { margin-bottom: 0; }

.tax-result-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tax-stat {
  background: rgba(15,23,42,0.025);
  padding: 16px 18px;
  border-radius: var(--r-md);
}
.tax-stat .lbl { font-size: 11.5px; color: var(--ink-3); font-weight: 600; margin-bottom: 4px; }
.tax-stat .val { font-size: 22px; font-weight: 800; letter-spacing: -0.025em; font-variant-numeric: tabular-nums; }
.tax-stat .val .unit { font-size: 12px; font-weight: 600; color: var(--ink-3); margin-left: 3px; }
.tax-stat.big { grid-column: span 2; background: linear-gradient(135deg, #f0f9ff, #ecfdf5); border: 1px solid #c7f7e0; }
.tax-stat.big .val { font-size: 32px; }

.tax-breakdown { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.tax-breakdown-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 14px;
  background: rgba(15,23,42,0.025);
  border-radius: var(--r-md);
  font-size: 13px;
}
.tax-breakdown-row .lbl { color: var(--ink-3); font-weight: 600; }
.tax-breakdown-row .val { font-weight: 700; font-variant-numeric: tabular-nums; color: var(--ink-1); }

.exempt-banner {
  background: linear-gradient(135deg, #ecfdf5, #d1fae5);
  border: 1px solid #86efac;
  color: #065f46;
  padding: 12px 16px;
  border-radius: var(--r-md);
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 12px;
}

/* ════════════════════════════════════════════════════════
   Compound view
   ════════════════════════════════════════════════════════ */
.cmp-table {
  width: 100%; border-collapse: collapse; margin-top: 10px;
}
.cmp-table th, .cmp-table td {
  padding: 9px 12px; text-align: right;
  font-size: 12.5px; border-bottom: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
}
.cmp-table th { font-size: 11px; font-weight: 700; color: var(--ink-3); text-transform: uppercase; letter-spacing: 0.05em; }
.cmp-table th:first-child, .cmp-table td:first-child { text-align: left; font-weight: 600; color: var(--ink-2); }
.cmp-table tbody tr:hover { background: rgba(79,70,229,0.03); }

.rule72 {
  background: linear-gradient(135deg, #fef3c7, #fde68a);
  border: 1px solid #fbbf24;
  color: #78350f;
  padding: 14px 18px;
  border-radius: var(--r-md);
  font-size: 13.5px;
  margin-top: 12px;
}

/* ════════════════════════════════════════════════════════
   Stock view
   ════════════════════════════════════════════════════════ */
.stock-layout { display: grid; grid-template-columns: 240px 1fr; gap: 20px; align-items: start; }
@media (max-width: 1000px) { .stock-layout { grid-template-columns: 1fr; } }

.stk-sidebar {
  position: sticky; top: 80px;
  display: flex; flex-direction: column; gap: 8px;
}
.stk-card {
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 12px 14px;
  cursor: pointer;
  transition: var(--t-fast);
  font-family: inherit;
  width: 100%;
}
.stk-card:hover { border-color: var(--brand); }
.stk-card.active {
  background: var(--ink-1);
  border-color: var(--ink-1);
  color: #fff;
  box-shadow: var(--shadow-md);
}
.stk-card-head { display: flex; justify-content: space-between; align-items: center; }
.stk-card-name { font-weight: 700; font-size: 13.5px; }
.stk-card-pnl { font-size: 12.5px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stk-card-pnl.up { color: var(--accent); }
.stk-card-pnl.down { color: var(--danger); }
.stk-card.active .stk-card-pnl.up { color: #6ee7b7; }
.stk-card.active .stk-card-pnl.down { color: #fca5a5; }
.stk-card-meta { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 4px; font-size: 11.5px; color: var(--ink-3); }
.stk-card.active .stk-card-meta { color: rgba(255,255,255,0.7); }
.market-tag {
  background: rgba(15,23,42,0.05); padding: 1px 7px; border-radius: 99px; font-weight: 600; font-size: 10.5px;
}
.stk-card.active .market-tag { background: rgba(255,255,255,0.18); color: #fff; }
.stk-add {
  background: var(--brand-soft);
  border: 1.5px dashed var(--brand);
  color: var(--brand);
  font-weight: 700;
  text-align: center;
  padding: 14px;
}
.stk-add:hover { background: var(--brand); color: #fff; }

.stk-header {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  padding: 20px 24px;
  margin-bottom: 16px;
  display: flex; justify-content: space-between; align-items: center; gap: 20px;
}
.stk-head-name { font-size: 20px; font-weight: 800; letter-spacing: -0.025em; }
.stk-head-meta { font-size: 12.5px; color: var(--ink-3); margin-top: 2px; }
.stk-head-price { font-size: 24px; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -0.025em; }
.stk-head-change { font-size: 13px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stk-head-change.up { color: var(--accent); }
.stk-head-change.down { color: var(--danger); }

.stk-fin-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
@media (max-width: 760px) { .stk-fin-grid { grid-template-columns: repeat(2, 1fr); } }
.stk-fin {
  background: rgba(15,23,42,0.025);
  padding: 10px 12px;
  border-radius: 10px;
}
.stk-fin .lbl { font-size: 10.5px; font-weight: 600; color: var(--ink-3); margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.04em; }
.stk-fin input {
  width: 100%; border: none; background: transparent;
  font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--ink-1);
  padding: 0; font-family: inherit;
  letter-spacing: -0.02em;
}
.stk-fin input:focus { outline: none; color: var(--brand); }

.stk-valuation-layout { display: grid; grid-template-columns: 220px 1fr; gap: 24px; align-items: center; }
@media (max-width: 720px) { .stk-valuation-layout { grid-template-columns: 1fr; } }
.stk-radial { width: 220px; height: 220px; position: relative; }
.stk-radial svg { width: 100%; height: 100%; }
.stk-radial-center { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; pointer-events: none; }
.stk-radial-center .score { font-size: 32px; font-weight: 800; letter-spacing: -0.03em; }
.stk-radial-center .lbl { font-size: 11px; color: var(--ink-3); font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; }
.stk-radial-center .sub { font-size: 11.5px; margin-top: 4px; font-weight: 600; }

.stk-form-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
@media (max-width: 760px) { .stk-form-row { grid-template-columns: 1fr; } }

.stk-tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.stk-tab {
  padding: 6px 12px;
  background: rgba(15,23,42,0.05);
  border: none;
  border-radius: 99px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-2);
  cursor: pointer;
}
.stk-tab.active { background: var(--ink-1); color: #fff; }

.danger-btn {
  background: rgba(239,68,68,0.1);
  color: var(--danger);
  border: 1px solid rgba(239,68,68,0.2);
  padding: 6px 12px;
  border-radius: 8px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.danger-btn:hover { background: var(--danger); color: #fff; }

/* ════════════════════════════════════════════════════════
   Mobile Optimization
   ════════════════════════════════════════════════════════ */

/* iOS 줌인 방지: input 폰트 16px 최소 */
@media (max-width: 900px) {
  .input, .select, .stk-fin input { font-size: 16px; }
  .field-label > span { font-size: 13px; }
}

/* ────────── Tablet & Mobile (≤ 900px) ────────── */
@media (max-width: 900px) {
  /* 사이드바 → 하단 탭바 */
  .app-shell { flex-direction: column; padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
  .sidenav {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    top: auto;
    width: 100%;
    height: auto;
    flex-direction: row;
    padding: 6px 4px;
    padding-bottom: calc(6px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--border);
    border-right: none;
    z-index: 100;
    box-shadow: 0 -4px 16px rgba(15, 23, 42, 0.04);
    gap: 0;
  }
  .sidenav-brand, .nav-section, .nav-foot, .nav-spacer { display: none; }
  .nav-items {
    flex-direction: row;
    width: 100%;
    justify-content: space-around;
    gap: 0;
  }
  .nav-item {
    flex: 1;
    flex-direction: column;
    gap: 3px;
    padding: 8px 4px;
    min-height: 56px;
    justify-content: center;
  }
  .nav-item .nav-icon {
    width: 24px; height: 24px;
    background: transparent;
    font-size: 18px;
  }
  .nav-item .nav-text {
    font-size: 10.5px;
    font-weight: 600;
    line-height: 1;
  }
  .nav-item.active {
    background: transparent;
    color: var(--brand);
    box-shadow: none;
  }
  .nav-item.active .nav-icon { background: var(--brand-soft); }

  .main-area { width: 100%; }
  .main-area .topbar {
    padding: 12px 16px;
    position: sticky;
    top: 0;
  }
  .main-area .topbar-titles h1 { font-size: 16px; }
  .main-area .topbar-titles p { font-size: 11.5px; }

  .view-content { padding: 16px 14px 24px; }
}

/* ────────── Phone (≤ 640px) ────────── */
@media (max-width: 640px) {
  /* Hero 축소 */
  .hero {
    margin: 0;
    padding: 24px 20px;
    border-radius: 18px;
  }
  .hero-content { flex-direction: column; align-items: stretch; gap: 16px; }
  .hero-headline { font-size: 12.5px; }
  .hero-amount { font-size: 40px; }
  .hero-amount .unit { font-size: 16px; }
  .hero-meta { font-size: 12px; }
  .hero-side { flex-wrap: wrap; gap: 8px; }
  .hero-stat { flex: 1; min-width: 0; padding: 10px 12px; }
  .hero-stat-label { font-size: 10.5px; }
  .hero-stat-value { font-size: 17px; }
  .hero-stat-value .unit { font-size: 11px; }

  /* Page header 축소 */
  .page-header {
    padding: 20px 18px;
    border-radius: 18px;
    flex-direction: column;
    gap: 8px;
    align-items: flex-start;
  }
  .page-header h1 { font-size: 20px; line-height: 1.25; }
  .page-header h2 { font-size: 10.5px; }
  .page-header .page-meta { font-size: 12.5px; }

  /* 카드 padding 축소 */
  .card { padding: 16px; border-radius: 16px; }
  .card-header { margin-bottom: 10px; }
  .card-header > div p { font-size: 11.5px; }
  h2 { font-size: 10.5px; }
  h3 { font-size: 14px; }

  /* KPI 2열 */
  .kpi-row { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .kpi { padding: 14px 14px; border-radius: 14px; }
  .kpi-icon { width: 28px; height: 28px; font-size: 14px; margin-bottom: 6px; }
  .kpi-label { font-size: 11px; margin-bottom: 4px; }
  .kpi-value { font-size: 19px; }
  .kpi-value .unit { font-size: 11px; }
  .kpi-sub { font-size: 10.5px; margin-top: 4px; }

  /* IRP 레이아웃: input → 결과 순으로 stack */
  .layout {
    grid-template-columns: 1fr !important;
    padding: 0 !important;
    gap: 14px !important;
  }
  .inputs-wrap {
    position: static !important;
    max-height: none !important;
    overflow: visible !important;
  }

  /* Tax/Stock 레이아웃 1열 */
  .tax-layout, .stock-layout { grid-template-columns: 1fr; gap: 14px; }
  .tax-field-row { grid-template-columns: 1fr 1fr; }
  .tax-result-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .tax-stat.big { grid-column: span 2; }
  .tax-stat { padding: 12px 14px; }
  .tax-stat .val { font-size: 18px; }
  .tax-stat.big .val { font-size: 24px; }

  /* 슬라이더 터치 타깃 확대 */
  .slider { height: 8px; }
  .slider::-webkit-slider-thumb {
    width: 28px; height: 28px;
    border-width: 4px;
  }
  .slider::-moz-range-thumb {
    width: 28px; height: 28px;
    border-width: 4px;
  }

  /* 시나리오 탭: 가로 스크롤 */
  .scenarios-bar {
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    padding: 6px;
    border-radius: 14px;
    scrollbar-width: none;
  }
  .scenarios-bar::-webkit-scrollbar { display: none; }
  .scenario-tab { flex-shrink: 0; }
  .scenario-add { flex-shrink: 0; margin-left: auto; }
  .compare-toggle { flex-shrink: 0; }

  /* 차트 높이 축소 */
  .chart { height: 220px; }

  /* 폼 그룹/필드 간격 축소 */
  .form-group { margin-bottom: 16px; }
  .field { margin-bottom: 12px; }
  .field-value-badge { font-size: 11px; padding: 2px 7px; }

  /* Chip group: 가로 스크롤 대신 wrap */
  .chip-group { flex-wrap: wrap; gap: 6px; }
  .chip { min-width: calc(50% - 3px); padding: 10px 8px; }
  .chip-name { font-size: 12px; }
  .chip-sub { font-size: 10px; }

  /* Segmented control */
  .segmented label { padding: 8px 6px; font-size: 12px; }

  /* Compare table 가로 스크롤 */
  .compare-table { font-size: 12px; }
  .compare-table th, .compare-table td { padding: 8px 8px; }

  /* Strategy & notes */
  .strategy li { font-size: 12.5px; padding: 10px 12px 10px 32px; }
  .strategy li::before { left: 10px; top: 10px; }
  .notes li { font-size: 11.5px; }

  /* Portfolio donut 작게 + 1열 */
  .pf-layout { grid-template-columns: 1fr; gap: 16px; justify-items: center; }
  .donut { width: 160px; height: 160px; }
  .pf-list { width: 100%; }

  /* Stock: 사이드바 → 가로 스크롤 카드 */
  .stk-sidebar {
    position: static;
    flex-direction: row;
    overflow-x: auto;
    padding-bottom: 6px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .stk-sidebar::-webkit-scrollbar { display: none; }
  .stk-card {
    min-width: 180px;
    flex-shrink: 0;
  }
  .stk-add { min-width: 120px; }

  /* Stock header */
  .stk-header { flex-direction: column; align-items: flex-start; padding: 16px 18px; gap: 6px; }
  .stk-header > div:last-child { text-align: left; align-self: stretch; display: flex; justify-content: space-between; align-items: baseline; }
  .stk-head-name { font-size: 18px; }
  .stk-head-price { font-size: 20px; }

  /* Stock 폼 1열 */
  .stk-form-row { grid-template-columns: 1fr; gap: 10px; }
  .stk-fin-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .stk-fin input { font-size: 15px; }

  /* Stock valuation 1열 */
  .stk-valuation-layout { grid-template-columns: 1fr; gap: 16px; justify-items: center; }
  .stk-radial { width: 180px; height: 180px; }
  .stk-radial-center .score { font-size: 26px; }

  /* Buttons larger touch area */
  .btn-ghost, .btn-primary { padding: 10px 14px; min-height: 40px; }
  .danger-btn { padding: 10px 14px; min-height: 36px; }

  /* Topbar에서 SVG 아이콘 약간 키움 */
  .nav-item .nav-icon svg { width: 18px; height: 18px; }

  /* Grid 2-column carve outs */
  .grid-two { gap: 14px; }
}

/* ────────── Small Phone (≤ 380px) ────────── */
@media (max-width: 380px) {
  .kpi-row { grid-template-columns: 1fr 1fr; }
  .kpi-value { font-size: 17px; }
  .hero-amount { font-size: 34px; }
  .tax-result-grid { grid-template-columns: 1fr; }
  .tax-stat.big { grid-column: auto; }
  .chip { min-width: calc(50% - 3px); }
  .nav-item .nav-text { font-size: 10px; }
}

/* ────────── Touch & 입력 동작 ────────── */
@media (hover: none) and (pointer: coarse) {
  /* hover 효과 제거 */
  .nav-item:hover { background: transparent; }
  .nav-item.active:hover { background: var(--brand-grad); color: #fff; }
  .scenario-tab:hover { background: transparent; }
  .scenario-tab.active:hover { background: var(--ink-1); color: #fff; }
  .chip:hover { border-color: var(--border-strong); background: var(--surface); }
  .chip:has(input:checked):hover { border-color: var(--brand); background: var(--brand); }
  .stk-card:hover { border-color: var(--border); }
  .pf-item:hover { background: transparent; }
  .btn-primary:hover { transform: none; }
}

/* ────────── 가로 모드 폰 ────────── */
@media (max-width: 900px) and (orientation: landscape) and (max-height: 500px) {
  .hero { padding: 16px 18px; }
  .hero-amount { font-size: 32px; }
  .hero-content { flex-direction: row; }
}

/* ────────── 모바일 토스트 ────────── */
@media (max-width: 640px) {
  .toast {
    bottom: calc(80px + env(safe-area-inset-bottom));
    left: 16px; right: 16px;
    transform: translateY(80px);
    width: auto;
  }
  .toast.visible { transform: translateY(0); }
}

