/* ── Reset & Variables ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0d0f14;
  --bg2: #13161e;
  --bg3: #1a1d27;
  --card: #181b24;
  --card2: #1e2230;
  --border: rgba(255,255,255,0.07);
  --border2: rgba(255,255,255,0.12);
  --text: #e8eaf0;
  --text2: #9099b0;
  --text3: #5a637a;
  --gold: #d4a84b;
  --gold2: #f0c878;
  --gold-dim: rgba(212,168,75,0.15);
  --gold-glow: rgba(212,168,75,0.08);
  --teal: #4ecdc4;
  --teal-dim: rgba(78,205,196,0.12);
  --green: #5cca8e;
  --red: #e05c5c;
  --radius: 14px;
  --radius-sm: 8px;
  --transition: 0.2s ease;
  --font-body: 'Pretendard', 'Noto Serif KR', sans-serif;
  --font-mono: 'DM Mono', monospace;
  --font-serif: 'Noto Serif KR', serif;
}

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ── Background Effects ── */
.noise {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.04'/%3E%3C/svg%3E");
  opacity: 0.5;
}

.glow-orb {
  position: fixed; border-radius: 50%; filter: blur(80px); pointer-events: none; z-index: 0;
}
.glow-orb.one {
  width: 400px; height: 400px;
  background: rgba(212,168,75,0.06);
  top: -100px; right: -100px;
}
.glow-orb.two {
  width: 300px; height: 300px;
  background: rgba(78,205,196,0.04);
  bottom: 10%; left: -80px;
}

/* ── Layout ── */
.page-wrap {
  position: relative; z-index: 1;
  max-width: 1100px;
  margin: 0 auto;
  padding: 40px 20px 80px;
}

/* ── Header ── */
header {
  margin-bottom: 48px;
  display: flex; align-items: flex-start; justify-content: space-between;
  flex-wrap: wrap; gap: 16px;
}
.tag {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11px; font-weight: 500; letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--gold);
  background: var(--gold-dim);
  border: 1px solid rgba(212,168,75,0.2);
  border-radius: 20px;
  padding: 4px 12px;
  margin-bottom: 12px;
}
.tag::before { content: '◈'; font-size: 9px; }
h1 {
  font-family: var(--font-serif);
  font-size: clamp(26px, 4vw, 38px);
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
  line-height: 1.2;
}
h1 span { color: var(--gold); }
.subtitle {
  margin-top: 8px;
  font-size: 14px;
  color: var(--text3);
  font-weight: 300;
}

/* ── Main Grid ── */
.main-grid {
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 24px;
  align-items: start;
}

/* ── Input Panel ── */
.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
}
.panel-title {
  font-size: 11px; font-weight: 600;
  letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--text3);
  margin-bottom: 24px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.input-group { margin-bottom: 22px; }
.input-group:last-child { margin-bottom: 0; }

.input-label {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 13px; color: var(--text2);
  margin-bottom: 8px;
  gap: 8px;
}
.input-label span {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--gold);
  font-weight: 500;
  white-space: nowrap;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.input-row { display: flex; align-items: center; gap: 8px; }

.prefix {
  font-family: var(--font-mono);
  font-size: 14px; color: var(--text3);
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  min-width: 36px;
  text-align: center;
  flex-shrink: 0;
}

input[type="number"], select {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 14px; font-weight: 500;
  padding: 9px 12px;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
  -moz-appearance: textfield;
  appearance: textfield;
}
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; }
input[type="number"]:focus, select:focus {
  border-color: rgba(212,168,75,0.4);
  box-shadow: 0 0 0 3px rgba(212,168,75,0.08);
}
select {
  cursor: pointer;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%235a637a' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}
select option { background: var(--card); color: var(--text); }

.range-wrap { margin-top: 8px; }
input[type="range"] {
  width: 100%; height: 4px;
  -webkit-appearance: none; appearance: none;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 2px;
  outline: none; cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--gold);
  border: 2px solid var(--bg);
  cursor: pointer;
  box-shadow: 0 0 0 4px var(--gold-dim);
  transition: transform var(--transition);
}
input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.15); }
input[type="range"]::-moz-range-thumb {
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--gold);
  border: 2px solid var(--bg);
  cursor: pointer;
}
.range-labels {
  display: flex; justify-content: space-between;
  font-size: 10px; color: var(--text3);
  margin-top: 4px;
  font-family: var(--font-mono);
}

/* ── Right Column ── */
.right-col { display: flex; flex-direction: column; gap: 20px; }

/* ── Result Cards ── */
.result-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}
.result-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 16px;
  position: relative;
  overflow: hidden;
  transition: border-color var(--transition);
  min-width: 0; /* 중요: 숫자 잘림 방지 */
}
.result-card::after {
  content: '';
  position: absolute; top: 0; left: 0; right: 0; height: 2px;
  border-radius: var(--radius) var(--radius) 0 0;
}
.result-card.main { background: var(--card2); border-color: rgba(212,168,75,0.2); }
.result-card.main::after { background: linear-gradient(90deg, var(--gold), var(--gold2)); }
.result-card.invested::after { background: var(--teal); opacity: 0.5; }
.result-card.interest::after { background: var(--gold); opacity: 0.3; }

.result-label {
  font-size: 11px; font-weight: 500;
  letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--text3);
  margin-bottom: 8px;
}
.result-value {
  font-family: var(--font-mono);
  /* clamp 범위를 더 넓게 — 카드 너비에 맞게 자동 축소 */
  font-size: clamp(14px, 2vw, 22px);
  font-weight: 500;
  letter-spacing: -0.02em;
  color: var(--text);
  transition: all 0.3s ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}
.result-card.main .result-value {
  color: var(--gold2);
  font-size: clamp(16px, 2.4vw, 28px);
}
.result-sub {
  font-size: 11px;
  color: var(--text3);
  margin-top: 5px;
  font-family: var(--font-mono);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.result-sub.pos { color: var(--green); }

/* ── Chart ── */
.chart-panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}
.chart-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px; flex-wrap: wrap; gap: 12px;
}
.chart-title { font-size: 13px; font-weight: 500; color: var(--text2); }
.legend { display: flex; gap: 16px; }
.legend-item {
  display: flex; align-items: center; gap: 6px;
  font-size: 11px; color: var(--text3);
  font-family: var(--font-mono);
}
.legend-dot { width: 8px; height: 8px; border-radius: 2px; flex-shrink: 0; }
.chart-container { position: relative; width: 100%; height: 260px; }

/* ── Table ── */
.table-panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.table-header {
  padding: 16px 20px;
  font-size: 11px; font-weight: 600;
  letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--text3);
  border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
}
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-family: var(--font-mono); font-size: 13px; }
thead th {
  padding: 10px 16px;
  text-align: right;
  font-size: 10px; font-weight: 500;
  letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--text3);
  border-bottom: 1px solid var(--border);
  background: var(--bg3);
  white-space: nowrap;
}
thead th:first-child { text-align: left; }
tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: rgba(255,255,255,0.02); }
tbody td {
  padding: 10px 16px;
  text-align: right;
  color: var(--text2);
  white-space: nowrap;
}
tbody td:first-child { text-align: left; color: var(--text3); }
tbody td.highlight { color: var(--gold); }
tbody td.teal { color: var(--teal); }

/* ── 모바일 카드 테이블 ── */
.mobile-cards { display: none; }
.m-card {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.m-card:last-child { border-bottom: none; }
.m-card-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 8px;
}
.m-year {
  font-size: 12px; color: var(--text3);
  font-family: var(--font-mono);
}
.m-pct {
  font-size: 12px; color: var(--green);
  font-family: var(--font-mono);
}
.m-total {
  font-family: var(--font-mono);
  font-size: 18px; font-weight: 500;
  color: var(--gold2);
  margin-bottom: 8px;
  letter-spacing: -0.02em;
}
.m-row {
  display: flex; gap: 12px;
  font-size: 11px; color: var(--text3);
  font-family: var(--font-mono);
}
.m-row span { flex: 1; }
.m-row .v { color: var(--text2); }
.m-row .vt { color: var(--teal); }

/* ── Show All Button ── */
.show-all-btn {
  width: 100%; padding: 14px;
  background: transparent;
  border: none; border-top: 1px solid var(--border);
  color: var(--text3); font-family: var(--font-body); font-size: 12px;
  cursor: pointer;
  transition: color var(--transition), background var(--transition);
  display: flex; align-items: center; justify-content: center; gap: 6px;
}
.show-all-btn:hover { color: var(--text2); background: rgba(255,255,255,0.02); }
.show-all-btn svg { transition: transform var(--transition); }
.show-all-btn.open svg { transform: rotate(180deg); }

/* ── Footer ── */
.footer {
  margin-top: 48px;
  text-align: center;
  font-size: 12px; color: var(--text3);
  font-family: var(--font-mono); letter-spacing: 0.05em;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}

/* ── Animations ── */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}
.animate { animation: fadeUp 0.5s ease both; }
.number-animate { transition: all 0.4s cubic-bezier(0.25,0.46,0.45,0.94); }

/* ════════════════════════════════
   RESPONSIVE
════════════════════════════════ */

/* ── 태블릿 (820px 이하) ── */
@media (max-width: 820px) {
  .main-grid { grid-template-columns: 1fr; }
  .page-wrap { padding: 28px 16px 60px; }
  header { margin-bottom: 32px; }
}

/* ── 모바일 (600px 이하) ── */
@media (max-width: 600px) {
  .page-wrap { padding: 20px 12px 50px; }
  header { margin-bottom: 24px; }
  h1 { font-size: 24px; }
  .subtitle { font-size: 13px; }

  /* 결과 카드: 한 줄에 2개, 마지막은 꽉 채움 */
  .result-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .result-card.main {
    grid-column: 1 / -1; /* 최종 자산은 전체 너비 */
  }
  .result-card.main .result-value {
    font-size: clamp(22px, 6vw, 32px);
  }
  .result-value {
    font-size: clamp(16px, 4.5vw, 20px);
  }

  /* 차트 */
  .chart-container { height: 200px; }
  .chart-panel { padding: 16px; }

  /* 테이블 → 카드 전환 */
  .desktop-table { display: none; }
  .mobile-cards { display: block; }

  /* 입력 패널 */
  .panel { padding: 20px 16px; }
  .input-label { font-size: 12px; }
}

/* ── 아주 작은 화면 (380px 이하) ── */
@media (max-width: 380px) {
  .result-grid { grid-template-columns: 1fr; }
  .result-card.main { grid-column: auto; }
}