:root {
  --primary: #3b82f6;
  --primary-glow: rgba(59, 130, 246, 0.15);
  --green: #22c55e;
  --green-glow: rgba(34, 197, 94, 0.15);
  --red: #ef4444;
  --red-glow: rgba(239, 68, 68, 0.15);
  --yellow: #eab308;

  --bg: #0f1117;
  --bg-card: rgba(25, 28, 39, 0.85);
  --bg-input: #1e2130;
  --border: rgba(255,255,255,0.08);
  --border-focus: rgba(59,130,246,0.5);
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --text-heading: #ffffff;

  --radius: 12px;
  --radius-sm: 8px;
  --max-width: 820px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="light"] {
  --bg: #f1f5f9;
  --bg-card: rgba(255,255,255,0.9);
  --bg-input: #e2e8f0;
  --border: rgba(0,0,0,0.08);
  --border-focus: rgba(59,130,246,0.5);
  --text: #1e293b;
  --text-muted: #64748b;
  --text-heading: #0f172a;
}

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

html { scroll-behavior: smooth; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  transition: background var(--transition), color var(--transition);
  overflow-x: hidden;
}

/* ── Layout ── */
.container { max-width: var(--max-width); margin: 0 auto; padding: 0 1.25rem; }

/* ── Header ── */
.site-header {
  position: sticky; top: 0; z-index: 100;
  background: rgba(15,17,23,0.8);
  backdrop-filter: blur(16px) saturate(180%);
  -webkit-backdrop-filter: blur(16px) saturate(180%);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 0;
  transition: background var(--transition);
}

[data-theme="light"] .site-header {
  background: rgba(241,245,249,0.85);
}

.header-inner {
  display: flex; justify-content: space-between; align-items: center;
}

.logo {
  font-size: 1.15rem; font-weight: 800; color: var(--text-heading);
  text-decoration: none; letter-spacing: -0.5px;
}
.logo span { color: var(--primary); }

.header-actions { display: flex; align-items: center; gap: 0.75rem; }

.theme-toggle {
  background: var(--bg-input); border: 1px solid var(--border);
  color: var(--text); border-radius: 50%; width: 36px; height: 36px;
  cursor: pointer; font-size: 1rem; display: grid; place-items: center;
  transition: all var(--transition);
}
.theme-toggle:hover { border-color: var(--primary); transform: rotate(20deg); }

/* ── Hero ── */
.hero {
  text-align: center;
  padding: 4rem 0 2.5rem;
}

.hero h1 {
  font-size: clamp(1.8rem, 5vw, 2.6rem);
  font-weight: 800;
  color: var(--text-heading);
  letter-spacing: -1px;
  line-height: 1.2;
  margin-bottom: 1rem;
}

.hero h1 .accent { color: var(--primary); }

.hero .subtitle {
  font-size: 1.1rem; color: var(--text-muted);
  max-width: 560px; margin: 0 auto;
}

/* ── Glass Card ── */
.card {
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  margin-bottom: 2.5rem;
  box-shadow: 0 8px 32px rgba(0,0,0,0.12);
  transition: border-color var(--transition);
}

/* ── Calculator ── */
.calc-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 1.5rem; flex-wrap: wrap; gap: 0.75rem;
}

.calc-header h2 {
  font-size: 1.3rem; color: var(--text-heading); font-weight: 700;
}

.calc-actions { display: flex; gap: 0.5rem; }

.btn {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.55rem 1.1rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem; font-weight: 600;
  cursor: pointer; border: none;
  transition: all var(--transition);
  font-family: var(--font);
}

.btn-primary {
  background: var(--primary); color: #fff;
}
.btn-primary:hover { filter: brightness(1.15); transform: translateY(-1px); }

.btn-ghost {
  background: transparent; color: var(--text-muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover { border-color: var(--red); color: var(--red); }

.btn-green { background: var(--green); color: #fff; }
.btn-green:hover { filter: brightness(1.1); }

/* ── Table ── */
.purchase-table {
  width: 100%; border-collapse: collapse; margin-bottom: 1.5rem;
}

.purchase-table th {
  text-align: left; font-size: 0.75rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-muted); padding: 0 0 0.75rem;
}

.purchase-table td { padding: 0.35rem 0; }

.purchase-table .row-num {
  width: 32px; color: var(--text-muted); font-size: 0.85rem;
  font-weight: 600; text-align: center;
}

.purchase-table input {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.65rem 0.85rem;
  color: var(--text);
  font-size: 0.95rem;
  font-family: var(--font);
  transition: all var(--transition);
  -moz-appearance: textfield;
}

.purchase-table input::-webkit-inner-spin-button,
.purchase-table input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }

.purchase-table input:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

.purchase-table input::placeholder { color: var(--text-muted); opacity: 0.5; }

.remove-row {
  background: none; border: none; color: var(--text-muted);
  cursor: pointer; font-size: 1.1rem; padding: 0.3rem;
  border-radius: 4px; transition: all var(--transition);
  display: grid; place-items: center;
}
.remove-row:hover { color: var(--red); background: var(--red-glow); }

/* ── Courtage Row ── */
.courtage-row {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.75rem 0; margin-bottom: 1rem;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}

.courtage-row label {
  font-size: 0.85rem; color: var(--text-muted); font-weight: 500;
  white-space: nowrap;
}

.courtage-row input {
  max-width: 120px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.75rem;
  color: var(--text);
  font-size: 0.9rem;
  font-family: var(--font);
  transition: all var(--transition);
  -moz-appearance: textfield;
}

.courtage-row input:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

/* ── Results ── */
.results-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 1rem;
}

.result-box {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1rem 1.25rem;
  text-align: center;
  transition: all 0.3s ease;
}

.result-box.highlight {
  border-color: var(--primary);
  background: var(--primary-glow);
}

.result-box.profit {
  border-color: var(--green);
  background: var(--green-glow);
}

.result-box.loss {
  border-color: var(--red);
  background: var(--red-glow);
}

.result-label {
  font-size: 0.72rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.result-value {
  font-size: 1.5rem; font-weight: 800; color: var(--text-heading);
  letter-spacing: -0.5px;
  transition: all 0.3s ease;
}

.result-value.green { color: var(--green); }
.result-value.red { color: var(--red); }

.result-sub {
  font-size: 0.78rem; color: var(--text-muted); margin-top: 2px;
}

/* ── Current Price Section ── */
.current-price-section {
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

.current-price-section h3 {
  font-size: 1rem; font-weight: 700; color: var(--text-heading);
  margin-bottom: 0.75rem;
}

.current-price-row {
  display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap;
}

.current-price-row input {
  max-width: 200px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.65rem 0.85rem;
  color: var(--text);
  font-size: 0.95rem;
  font-family: var(--font);
  transition: all var(--transition);
  -moz-appearance: textfield;
}

.current-price-row input:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

/* ── Progress Bar ── */
.gav-bar-container {
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

.gav-bar {
  height: 10px;
  background: var(--bg-input);
  border-radius: 99px;
  overflow: hidden;
  position: relative;
}

.gav-bar-fill {
  height: 100%;
  border-radius: 99px;
  transition: width 0.5s ease, background 0.3s ease;
  width: 0;
}

.gav-bar-labels {
  display: flex; justify-content: space-between;
  font-size: 0.75rem; color: var(--text-muted);
  margin-top: 0.35rem;
}

/* ── Content Sections ── */
.content-section {
  margin-bottom: 3rem;
}

.content-section h2 {
  font-size: 1.5rem; font-weight: 800; color: var(--text-heading);
  margin-bottom: 1rem; letter-spacing: -0.5px;
}

.content-section h3 {
  font-size: 1.15rem; font-weight: 700; color: var(--text-heading);
  margin: 1.5rem 0 0.5rem;
}

.content-section p {
  margin-bottom: 1rem; color: var(--text); font-size: 1rem;
}

.content-section ul, .content-section ol {
  margin-bottom: 1rem;
  padding-left: 1.5rem;
}

.content-section li {
  margin-bottom: 0.5rem;
}

/* ── Formula Box ── */
.formula-box {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  border-radius: var(--radius-sm);
  padding: 1.25rem 1.5rem;
  margin: 1.5rem 0;
  font-family: 'Courier New', monospace;
  font-size: 1.05rem;
  color: var(--primary);
  text-align: center;
  font-weight: 600;
  overflow-x: auto;
}

/* ── Example Box ── */
.example-box {
  background: var(--green-glow);
  border: 1px solid rgba(34, 197, 94, 0.2);
  border-radius: var(--radius-sm);
  padding: 1.5rem;
  margin: 1.5rem 0;
}

.example-box h4 {
  color: var(--green); font-size: 0.85rem;
  text-transform: uppercase; letter-spacing: 0.06em;
  margin-bottom: 0.75rem;
}

.example-box .step {
  display: flex; gap: 0.75rem; align-items: baseline;
  margin-bottom: 0.5rem; font-size: 0.95rem;
}

.example-box .step-num {
  background: var(--green);
  color: #fff;
  width: 22px; height: 22px;
  border-radius: 50%;
  display: grid; place-items: center;
  font-size: 0.7rem; font-weight: 700;
  flex-shrink: 0;
}

/* ── FAQ ── */
.faq-item {
  border-bottom: 1px solid var(--border);
  padding: 1.25rem 0;
}

.faq-item:last-child { border-bottom: none; }

.faq-question {
  font-size: 1.05rem; font-weight: 700; color: var(--text-heading);
  cursor: pointer; display: flex; justify-content: space-between;
  align-items: center; gap: 1rem;
  user-select: none;
}

.faq-question::after {
  content: '+'; font-size: 1.3rem; color: var(--primary);
  transition: transform 0.2s ease; flex-shrink: 0;
}

.faq-item.open .faq-question::after { content: '−'; }

.faq-answer {
  max-height: 0; overflow: hidden;
  transition: max-height 0.3s ease, padding 0.3s ease;
  color: var(--text); font-size: 0.95rem;
}

.faq-item.open .faq-answer {
  max-height: 400px; padding-top: 0.75rem;
}

/* ── Footer ── */
.site-footer {
  text-align: center;
  padding: 2.5rem 1rem;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-top: 2rem;
}

.site-footer a { color: var(--primary); text-decoration: none; }
.site-footer a:hover { text-decoration: underline; }

.disclaimer {
  max-width: var(--max-width);
  margin: 0 auto 1rem;
  font-size: 0.78rem;
  color: var(--text-muted);
  opacity: 0.7;
  line-height: 1.6;
}

/* ── Responsive ── */
@media (max-width: 640px) {
  .card { padding: 1.25rem; }
  .results-grid { grid-template-columns: repeat(2, 1fr); }
  .hero { padding: 2.5rem 0 1.5rem; }
  .purchase-table th:nth-child(4),
  .purchase-table td:nth-child(4) { display: none; }
  .current-price-row input { max-width: 100%; flex: 1; }
  .courtage-row input { max-width: 100%; flex: 1; }
  .result-value { font-size: 1.2rem; }
}

/* ── Animations ── */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.animate-in {
  animation: fadeInUp 0.4s ease forwards;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.03); }
}

.pulse { animation: pulse 0.4s ease; }
