/* ─── Variables ─────────────────────────────────────────────── */
:root {
  --chrome:     #111827;  /* dark UI: header, table header, button — stays dark */
  --ink:        #111827;
  --ink-mid:    #374151;
  --ink-muted:  #6b7280;
  --ink-faint:  #9ca3af;
  --accent:     #00a770;
  --accent-dim: #6ee7b7;
  --bg:         #ffffff;
  --surface:    #f9fafb;
  --border:     #e5e7eb;
  --positive:   #059669;
  --negative:   #dc2626;
  --row-hover:  #ecfdf5;
  --font:       system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono:       "SF Mono", "Fira Code", ui-monospace, "Courier New", monospace;
}

[data-theme="dark"] {
  color-scheme: dark;
  --chrome:     #1c2128;
  --ink:        #e6edf3;
  --ink-mid:    #c9d1d9;
  --ink-muted:  #8b949e;
  --ink-faint:  #6e7681;
  --accent-dim: #00a770;
  --bg:         #0d1117;
  --surface:    #161b22;
  --border:     #30363d;
  --positive:   #3fb950;
  --negative:   #f85149;
  --row-hover:  #0d2a1f;
}

[data-theme="dark"] .site-header .subtitle {
  color: var(--ink-mid);
}

/* ─── Reset ─────────────────────────────────────────────────── */
html {
  scroll-behavior: smooth;
}

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

/* ─── Base ──────────────────────────────────────────────────── */
body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
}

/* ─── Header ────────────────────────────────────────────────── */
.site-header {
  background: var(--chrome);
  border-top: 3px solid var(--accent);
  padding: 48px 24px 44px;
}

.header-inner {
  max-width: 960px;
  margin: 0 auto;
}

.header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-icon {
  width: 30px;
  height: 30px;
  flex-shrink: 0;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.lang-select {
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  color: rgba(255, 255, 255, 0.7);
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  padding: 0 10px;
  height: 36px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.lang-select:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
  border-color: rgba(255, 255, 255, 0.4);
}

.lang-select:focus {
  outline: none;
  border-color: var(--accent);
  color: #ffffff;
}

.lang-select option {
  background: var(--chrome);
  color: #ffffff;
}

.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  color: rgba(255, 255, 255, 0.7);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  flex-shrink: 0;
}

.theme-toggle:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
  border-color: rgba(255, 255, 255, 0.4);
}

.theme-toggle svg {
  width: 18px;
  height: 18px;
}

.icon-sun { display: none; }
.icon-moon { display: block; }

[data-theme="dark"] .icon-sun { display: block; }
[data-theme="dark"] .icon-moon { display: none; }

/* Dark mode overrides for hardcoded colors */
[data-theme="dark"] .drift-state--before {
  background: #3d2a00;
  color: #fbbf24;
}

[data-theme="dark"] .drift-state--after {
  background: #052e16;
  color: #4ade80;
}

[data-theme="dark"] .drift-delta--over  { color: #fbbf24; }
[data-theme="dark"] .drift-delta--under { color: #60a5fa; }

[data-theme="dark"] .drift-fill--over  { background: #d97706; }
[data-theme="dark"] .drift-fill--under { background: #3b82f6; }

.eyebrow {
  display: block;
  font-family: var(--mono);
  font-size: 0.68rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--accent);
  margin-bottom: 14px;
}

.site-header h1 {
  font-size: clamp(2rem, 5vw, 2.8rem);
  font-weight: 800;
  letter-spacing: -0.04em;
  line-height: 1.1;
  color: #ffffff;
  margin-bottom: 14px;
}

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

.subtitle {
  font-size: 0.875rem;
  color: var(--ink-faint);
  max-width: 420px;
}

/* ─── Explainer section ─────────────────────────────────────── */
.explainer {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.explainer-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 72px 24px 80px;
  display: flex;
  flex-direction: column;
  gap: 72px;
}

.section-tag {
  display: inline-block;
  font-family: var(--mono);
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--accent);
  margin-bottom: 16px;
}

/* Lead */
.explainer-lead {
  max-width: 680px;
}

.explainer-lead h2 {
  font-size: clamp(1.8rem, 4vw, 2.4rem);
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.15;
  color: var(--ink);
  margin-bottom: 24px;
}

.explainer-lead p {
  font-size: 1rem;
  color: var(--ink-mid);
  line-height: 1.75;
  margin-bottom: 14px;
}

.explainer-lead p:last-child {
  margin-bottom: 0;
}

.explainer-lead strong {
  color: var(--ink);
  font-weight: 600;
}

/* ─── CTA button ────────────────────────────────────────────── */
.cta-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  padding: 12px 28px;
  font-size: 0.9rem;
  font-weight: 700;
  font-family: var(--font);
  letter-spacing: 0.01em;
  background: #007a52;
  color: #ffffff;
  border-radius: 6px;
  text-decoration: none;
  transition: background 0.15s, transform 0.1s, box-shadow 0.15s;
  box-shadow: 0 2px 12px rgba(0, 122, 82, 0.35);
}

.cta-button:hover {
  background: #006040;
  box-shadow: 0 4px 16px rgba(0, 167, 112, 0.45);
  text-decoration: none;
}

.cta-button:active {
  transform: translateY(1px);
  box-shadow: none;
}

.steps-cta {
  display: flex;
  justify-content: flex-start;
  margin-top: 32px;
}

/* ─── Drift chart ───────────────────────────────────────────── */
.drift-block {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 24px;
  align-items: center;
}

.drift-panel {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 24px;
}

.drift-panel-label {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.drift-state {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 3px 10px;
  border-radius: 20px;
}

.drift-state--before {
  background: #fef3c7;
  color: #92400e;
}

.drift-state--after {
  background: #d1fae5;
  color: #065f46;
}

.drift-caption {
  font-size: 0.8rem;
  color: var(--ink-muted);
}

.drift-chart {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.drift-row {
  display: grid;
  grid-template-columns: 110px 1fr 36px 46px;
  align-items: center;
  gap: 10px;
}

.drift-name {
  font-size: 0.78rem;
  color: var(--ink-mid);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.drift-track {
  position: relative;
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: visible;
}

.drift-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.4s ease;
}

.drift-fill--over  { background: #f59e0b; }
.drift-fill--under { background: #93c5fd; }
.drift-fill--ok    { background: var(--accent); }

.drift-target-mark {
  position: absolute;
  top: -5px;
  width: 2px;
  height: 18px;
  background: var(--ink);
  border-radius: 1px;
  transform: translateX(-50%);
}

.drift-pct {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--ink-mid);
  text-align: right;
}

.drift-delta {
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 600;
  text-align: right;
}

.drift-delta--over  { color: #b45309; }
.drift-delta--under { color: #3b82f6; }
.drift-delta--ok    { color: var(--positive); }

.drift-legend {
  display: flex;
  gap: 16px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
  grid-column: 1 / -1;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  color: var(--ink-muted);
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  flex-shrink: 0;
}

.legend-dot--fill  { background: var(--border); border: 1px solid var(--ink-faint); }
.legend-dot--over  { background: #f59e0b; }
.legend-dot--under { background: #93c5fd; }

.legend-mark-icon {
  display: inline-block;
  width: 2px;
  height: 12px;
  background: var(--ink);
  border-radius: 1px;
  flex-shrink: 0;
}

/* Arrow between panels */
.drift-arrow {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 0 4px;
}

.drift-arrow-line {
  width: 1px;
  height: 32px;
  background: var(--border);
}

.drift-arrow-label {
  font-size: 0.7rem;
  color: var(--ink-muted);
  text-align: center;
  line-height: 1.4;
}

.drift-arrow-tip {
  font-size: 1.2rem;
  color: var(--accent);
  line-height: 1;
}

/* ─── Three pillars ─────────────────────────────────────────── */
.pillars {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 32px;
}

.pillar {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.pillar-icon {
  width: 40px;
  height: 40px;
  color: var(--accent);
}

.pillar-icon svg {
  width: 100%;
  height: 100%;
}

.pillar h3 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -0.01em;
}

.pillar p {
  font-size: 0.875rem;
  color: var(--ink-muted);
  line-height: 1.7;
}

/* ─── How it works ──────────────────────────────────────────── */
.how-it-works {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.steps {
  display: flex;
  align-items: flex-start;
  gap: 0;
  margin-top: 24px;
}

.step {
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1;
}

.step-num {
  font-family: var(--mono);
  font-size: 2rem;
  font-weight: 700;
  color: var(--ink-muted);
  line-height: 1;
  letter-spacing: -0.04em;
}

.step-body h3 {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 6px;
}

.step-body p {
  font-size: 0.85rem;
  color: var(--ink-muted);
  line-height: 1.65;
}

.step-body em {
  font-style: normal;
  font-weight: 600;
  color: var(--ink-mid);
}

.step-divider {
  width: 48px;
  height: 1px;
  background: var(--border);
  flex-shrink: 0;
  margin-top: 16px;
}

/* ─── Calculator divider ────────────────────────────────────── */
.calculator-divider {
  display: flex;
  align-items: center;
  gap: 16px;
  max-width: 960px;
  margin: 48px auto 0;
  padding: 0 24px;
}

.calculator-divider::before,
.calculator-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

.calculator-divider span {
  font-family: var(--mono);
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--ink-faint);
  white-space: nowrap;
}

/* ─── Main layout ───────────────────────────────────────────── */
#content {
  max-width: 960px;
  margin: 0 auto;
  padding: 56px 24px 80px;
  display: flex;
  flex-direction: column;
  gap: 64px;
}

/* ─── Form ──────────────────────────────────────────────────── */
.form-section {
  display: flex;
  flex-direction: column;
}

.form-group {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 8px 40px;
  align-items: start;
  padding: 28px 0;
  border-bottom: 1px solid var(--border);
}

.form-group--action {
  border-bottom: none;
  padding-top: 32px;
}

label {
  padding-top: 2px;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--ink-muted);
  line-height: 1.4;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.hint {
  font-size: 0.78rem;
  color: var(--ink-muted);
  font-family: var(--mono);
  line-height: 1.5;
}

input[type="text"] {
  font-family: var(--mono);
  font-size: 1.15rem;
  font-weight: 500;
  color: var(--ink);
  background: transparent;
  border: none;
  border-bottom: 2px solid var(--border);
  border-radius: 0;
  padding: 6px 0;
  width: 180px;
  outline: none;
  transition: border-color 0.15s;
}

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

#assetinput {
  font-family: var(--mono);
  font-size: 0.8rem;
  line-height: 1.85;
  color: var(--ink-mid);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 14px 16px;
  white-space: pre;
  overflow: auto;
  resize: vertical;
  width: 100%;
  outline: none;
  transition: border-color 0.15s;
}

#assetinput:focus {
  border-color: var(--ink-muted);
}

/* ─── Button ────────────────────────────────────────────────── */
#calculatebutton {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 11px 24px;
  font-size: 0.875rem;
  font-weight: 600;
  font-family: var(--font);
  letter-spacing: 0.01em;
  background: var(--chrome);
  color: #ffffff;
  border: 2px solid var(--chrome);
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}

#calculatebutton:hover {
  background: var(--accent);
  border-color: var(--accent);
}

#calculatebutton:active {
  transform: translateY(1px);
}

/* ─── Results ───────────────────────────────────────────────── */
.results-card {
  display: none;
}

.results-card.visible {
  display: block;
}

.results-header {
  padding-bottom: 16px;
  margin-bottom: 24px;
  border-bottom: 2px solid var(--ink);
}

.results-header h2 {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--ink-muted);
}

#results {
  overflow-x: auto;
}

#results > p {
  font-size: 0.8rem;
  font-family: var(--mono);
  color: var(--ink-muted);
  margin-bottom: 20px;
  line-height: 1.6;
}

/* ─── Table ─────────────────────────────────────────────────── */
#resulttable {
  table-layout: fixed;
  width: 100%;
  min-width: 660px;
  border-collapse: collapse;
}

#resulttable .assetname {
  text-align: left;
  width: 16%;
}

.amountcolumn {
  width: 13%;
}

/* Columns without a class: share price (2nd) and target (6th) */
#resulttable th:nth-child(2),
#resulttable td:nth-child(2) { width: 11%; }

#resulttable th:nth-child(6),
#resulttable td:nth-child(6) { width: 13%; }

/* Header row */
tr.header {
  background: var(--chrome);
  color: #ffffff;
}

tr.header th {
  font-family: var(--mono);
  font-size: 0.65rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 12px 8px;
  text-align: right;
  vertical-align: bottom;
  overflow-wrap: break-word;
}

tr.header .assetname {
  text-align: left;
}

/* Body rows */
#resulttable tbody tr:nth-child(even) {
  background: var(--surface);
}

#resulttable tbody tr:hover {
  background: var(--row-hover);
}

#resulttable td {
  padding: 12px;
  text-align: right;
  vertical-align: middle;
  border-bottom: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 0.82rem;
  color: var(--ink-mid);
}

#resulttable td.assetname {
  font-family: var(--font);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--ink);
  text-align: left;
}

/* ─── State colors ──────────────────────────────────────────── */
.positive {
  color: var(--positive);
  font-weight: 600;
}

.negative {
  color: var(--negative);
  font-weight: 600;
}

tr.header .positive {
  color: var(--accent-dim);
  font-weight: 500;
}

tr.header .negative {
  color: #fca5a5;
  font-weight: 500;
}

.error {
  color: var(--negative);
  font-size: 0.85rem;
  font-family: var(--mono);
}

/* ─── Footer ────────────────────────────────────────────────── */
.site-footer {
  display: flex;
  justify-content: center;
  padding: 48px 24px 56px;
}

.site-footer img {
  display: block;
  height: 60px;
  width: 217px;
}

/* ─── Responsive ────────────────────────────────────────────── */

@media (max-width: 860px) {
  .drift-block {
    grid-template-columns: 1fr;
  }

  .drift-arrow {
    flex-direction: row;
    padding: 0;
    gap: 12px;
  }

  .drift-arrow-line {
    width: 32px;
    height: 1px;
  }

  .drift-arrow-tip {
    font-size: 1rem;
  }

  .pillars {
    grid-template-columns: 1fr 1fr;
  }

  .steps {
    flex-direction: column;
    gap: 24px;
  }

  .step-divider {
    width: 1px;
    height: 24px;
    margin-top: 0;
  }
}

@media (max-width: 800px) {
  #resulttable td,
  tr.header th {
    padding: 10px 8px;
  }
}

@media (max-width: 640px) {
  .explainer-inner {
    padding: 48px 20px 56px;
    gap: 48px;
  }

  .drift-row {
    grid-template-columns: 80px 1fr 30px 40px;
    gap: 6px;
  }

  .pillars {
    grid-template-columns: 1fr;
    gap: 28px;
  }

  .calculator-divider {
    margin-top: 32px;
  }

  .site-header {
    padding: 32px 20px 28px;
  }

  #content {
    padding: 36px 20px 60px;
    gap: 48px;
  }

  /* Collapse two-column form to single column */
  .form-group {
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 20px 0;
  }

  input[type="text"] {
    width: 100%;
    font-size: 1rem;
  }

  /* ── Card layout for results table ── */
  #results {
    overflow-x: visible;
  }

  #resulttable {
    display: block;
    min-width: unset;
    width: 100%;
  }

  /* Hide the header row — labels go on each cell via ::before */
  #resulttable thead,
  tr.header {
    display: none;
  }

  #resulttable tbody {
    display: flex;
    flex-direction: column;
    gap: 10px;
  }

  /* Each row becomes a card */
  #resulttable tbody tr {
    display: block;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    background: var(--bg);
  }

  /* Cancel alternating background — card handles its own bg */
  #resulttable tbody tr:nth-child(even) {
    background: var(--bg);
  }
  #resulttable tbody tr:hover {
    background: var(--bg);
  }

  /* Asset name: card header strip */
  #resulttable td.assetname {
    display: block;
    background: var(--chrome);
    color: #ffffff;
    font-family: var(--font);
    font-size: 0.875rem;
    font-weight: 600;
    text-align: left;
    padding: 11px 14px;
    width: 100%;
    border-bottom: none;
  }

  /* All other cells: label + value rows */
  #resulttable td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 14px;
    font-size: 0.85rem;
    border-bottom: 1px solid var(--border);
    width: 100%;
  }

  #resulttable td:last-child {
    border-bottom: none;
  }

  /* Hide secondary columns: share price, initial value,
     initial portion, final portion */
  #resulttable td:nth-child(2),
  #resulttable td:nth-child(3),
  #resulttable td:nth-child(4),
  #resulttable td:nth-child(5) {
    display: none;
  }

  /* Inline labels via ::before */
  #resulttable td:nth-child(6)::before { content: "Target"; }
  #resulttable td:nth-child(7)::before { content: "Buy / Sell"; }
  #resulttable td:nth-child(8)::before { content: "Shares"; }

  #resulttable td:nth-child(6)::before,
  #resulttable td:nth-child(7)::before,
  #resulttable td:nth-child(8)::before {
    font-family: var(--font);
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--ink-muted);
  }
}
