:root {
  --bg: #FAF8F3;
  --surface: #FFFFFF;
  --border: #E3DFD4;
  --text: #2B2B28;
  --text-secondary: #6B675E;
  --accent: #2F8F7F;
  --accent-dark: #256F63;
  --accent-tint: #E4F3EF;
  --goal-accent: #C9982E;
  --goal-tint: #FBF1DD;
  --gain: #3A7D44;
  --loss: #B5484D;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.5;
}

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 32px 20px 64px;
}

header.site-header {
  text-align: center;
  margin-bottom: 32px;
}

header.site-header h1 {
  margin: 0 0 4px;
  font-size: 2rem;
  color: var(--text);
}

.site-logo {
  max-width: 320px;
  width: 100%;
  height: auto;
}

.header-banner {
  max-width: 280px;
  width: 100%;
  height: auto;
  border-radius: 12px;
  margin-bottom: 16px;
}

header.site-header p {
  margin: 0;
  color: var(--text-secondary);
}

.layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 24px;
}

@media (min-width: 800px) {
  .layout.has-results {
    grid-template-columns: 380px 1fr;
    align-items: start;
  }
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
}

.card + .card { margin-top: 24px; }

/* "The Projection Machine" preview card on account.php — deliberately
   breaks from the public site's light theme to give a real taste of the
   tracker's own dark look before clicking in. The giant faint background
   wordmark is ported from Machine's real .header::before treatment
   (huge low-opacity Bebas Neue text behind the real heading), using this
   app's own gold accent (the tracker's real --gold) rather than Machine's
   own green, since gold is what's actually waiting behind this link. */
.machine-preview-card {
  position: relative;
  overflow: hidden;
  background: #0a0a0a;
  border: 1px solid #ffc40040;
  border-radius: 12px;
  padding: 28px 24px;
  margin: 24px 0;
  box-shadow: 0 0 30px rgba(255, 196, 0, 0.08);
}
.machine-preview-wordmark {
  position: absolute;
  top: -14px;
  left: -4px;
  font-family: 'Bebas Neue', sans-serif;
  font-size: 90px;
  letter-spacing: 4px;
  color: #ffffff08;
  white-space: nowrap;
  pointer-events: none;
  line-height: 1;
}
.machine-preview-title {
  position: relative;
  font-family: 'Bebas Neue', sans-serif;
  font-size: 30px;
  letter-spacing: 3px;
  color: #f0f0f0;
  margin: 0 0 10px;
}
.machine-preview-title span { color: #ffc400; }
.machine-preview-desc {
  position: relative;
  font-family: 'DM Mono', monospace;
  font-size: 0.85rem;
  color: #888;
  line-height: 1.6;
  margin: 0 0 18px;
}
.machine-preview-btn {
  position: relative;
  display: inline-block;
  font-family: 'DM Mono', monospace;
  letter-spacing: 1px;
  text-transform: uppercase;
  font-size: 0.85rem;
  padding: 12px 20px;
  border: 1px solid #ffc400;
  border-radius: 6px;
  background: #ffc40018;
  color: #ffc400;
  text-decoration: none;
  transition: all 0.15s;
}
.machine-preview-btn:hover { background: #ffc400; color: #0a0a0a; }

.field { margin-bottom: 18px; }

.field label {
  display: block;
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 6px;
}

.field input[type="number"],
.field input[type="text"],
.field input[type="email"],
.field input[type="date"],
.field input[type="url"],
.field select,
.field textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  color: var(--text);
  background: var(--bg);
  font-family: inherit;
}
.field textarea { resize: vertical; }

.field input[type="number"]:focus,
.field input[type="text"]:focus,
.field input[type="email"]:focus,
.field input[type="date"]:focus,
.field input[type="url"]:focus,
.field select:focus,
.field textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* Compact multi-field rows (add-holding forms) — several short fields side
   by side instead of one full-width field per line, wrapping on narrow
   screens. .field-narrow/.field-shares size the field itself (shares gets
   more room — real fractional share counts run to 8-10 digits); the input
   inside still fills that field's width via the rules above. */
.field-row {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: flex-end;
}
.field-row .field { flex: 1 1 170px; min-width: 140px; }
.field-row .field-narrow { flex: 0 1 100px; min-width: 90px; }
.field-row .field-shares { flex: 0 1 160px; min-width: 140px; }
.field-row .checkbox-field { margin-bottom: 18px; }

/* Ticker lookup — highlights whichever field the lookup actually filled in. */
.field input.auto-filled {
  border-color: var(--accent);
  background: var(--accent-tint);
}

/* Stat grid — a row of bordered label/value cells (grand totals, per-account
   and per-holding stats). auto-fit/minmax reflows on narrow screens without
   a separate mobile breakpoint. */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  margin: 14px 0;
}
.stat-cell { background: var(--surface); padding: 10px 12px; }
.stat-cell .stat-label {
  display: block;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  margin-bottom: 4px;
}
.stat-cell .stat-value { font-size: 1.05rem; font-weight: 700; }
.stat-cell .stat-value.gain { color: var(--gain); }
.stat-cell .stat-value.loss { color: var(--loss); }

/* Account list — collapsible <details> sections instead of always-expanded
   cards, so a portfolio with several accounts doesn't turn into a wall of
   tables. */
.account-section {
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 20px;
  background: var(--surface);
  overflow: hidden;
}
.account-section > summary {
  cursor: pointer;
  padding: 16px 20px;
  font-weight: 700;
  font-size: 1.1rem;
  list-style: none;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}
.account-section > summary::-webkit-details-marker { display: none; }
.account-section > summary::before {
  content: '\25B8';
  color: var(--text-secondary);
  font-size: 0.9em;
}
.account-section[open] > summary::before { content: '\25BE'; }
.account-section-body { padding: 4px 20px 20px; border-top: 1px solid var(--border); }
.account-type-badge {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-secondary);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 10px;
}

/* Holding cards — replace the old cramped table-per-account. */
.holding-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 14px;
  background: var(--surface);
}
.holding-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 4px;
}
.holding-card-title { font-size: 1.1rem; font-weight: 700; }
.holding-card-actions {
  display: flex;
  gap: 12px;
  align-items: center;
  font-size: 0.9rem;
}
.holding-card .stat-grid { margin: 10px 0 0; }

.currency-input { position: relative; }
.currency-input .currency-prefix {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-secondary);
  pointer-events: none;
}
.currency-input input[type="number"] { padding-left: 24px; }

.checkbox-field {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 18px;
}

.checkbox-field input { width: 18px; height: 18px; }
.checkbox-field label { font-weight: 600; font-size: 0.9rem; }

.radio-group { margin-bottom: 18px; }
.radio-group > span.group-label {
  display: block;
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 6px;
}
.radio-option {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}
.radio-option label { font-size: 0.95rem; }

.btn-primary {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 12px 20px;
  font-size: 1rem;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  width: 100%;
}
.btn-primary:hover { background: var(--accent-dark); color: #fff; }
.btn-primary:focus-visible { outline: 2px solid var(--accent-dark); outline-offset: 2px; }

.btn-secondary {
  display: inline-block;
  background: transparent;
  color: var(--accent);
  border: 1px dashed var(--accent);
  border-radius: 8px;
  padding: 10px 20px;
  font-size: 0.95rem;
  font-weight: 600;
  text-align: center;
  cursor: pointer;
  width: 100%;
  margin-bottom: 8px;
}
.btn-secondary:hover { background: var(--accent-tint); }

.holding-row {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 16px;
  background: var(--bg);
}
.holding-row-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.holding-row-title { font-size: 0.95rem; }
.remove-holding-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 0.82rem;
  text-decoration: underline;
  cursor: pointer;
  padding: 0;
}
.remove-holding-btn:hover { color: var(--goal-accent); }

.assumptions {
  color: var(--text-secondary);
  font-size: 0.82rem;
  margin-top: 16px;
}
.assumptions ul { margin: 6px 0 0; padding-left: 18px; }
.assumptions a { color: var(--accent); }
.assumptions a:hover { color: var(--accent-dark); }

.invest-guide { margin-top: 24px; }
.invest-guide h2 { margin: 0 0 12px; font-size: 1.35rem; }
.invest-guide h3 { margin: 24px 0 8px; font-size: 1.05rem; }
.invest-guide h3:first-of-type { margin-top: 20px; }
.invest-guide p { margin: 0 0 12px; line-height: 1.6; }
.invest-guide a { color: var(--accent); }
.invest-guide a:hover { color: var(--accent-dark); }
.invest-guide a.btn-primary, .invest-guide a.btn-primary:hover { color: #fff; }
.invest-guide-options {
  list-style: none;
  margin: 0 0 12px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.invest-guide-options li {
  background: var(--accent-tint);
  border-radius: 8px;
  padding: 12px 14px;
  line-height: 1.5;
}

.disclosure-box {
  margin-top: 24px;
  padding: 16px 20px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text-secondary);
  font-size: 0.85rem;
  line-height: 1.5;
}

.results-card {
  border-color: var(--border);
}
.results-card.goal-reached {
  background: var(--goal-tint);
  border-color: var(--goal-accent);
}

.results-headline {
  font-size: 1.3rem;
  font-weight: 700;
  margin: 0 0 4px;
}
.results-card.goal-reached .results-headline { color: var(--goal-accent); }

.results-subline {
  color: var(--text-secondary);
  margin: 0 0 20px;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}
.stat-tile {
  background: var(--accent-tint);
  border-radius: 8px;
  padding: 12px 14px;
}
.results-card.goal-reached .stat-tile { background: #fff; }
.stat-tile .stat-label {
  font-size: 0.78rem;
  color: var(--text-secondary);
  margin-bottom: 4px;
}
.stat-tile .stat-value {
  font-size: 1.15rem;
  font-weight: 700;
}

.chart-wrap { margin: 24px 0; }

details.period-table summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 12px;
}

.table-scroll { overflow-x: auto; }

table.period-detail {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
table.period-detail th, table.period-detail td {
  text-align: right;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
}
table.period-detail th:first-child, table.period-detail td:first-child { text-align: left; }

.label-row, .stat-label-row, .chart-heading {
  display: flex;
  align-items: center;
  gap: 6px;
}
.label-row label { margin-bottom: 0; }
.chart-heading { margin-bottom: 10px; font-weight: 600; font-size: 0.9rem; }

.info-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1.5px solid var(--accent);
  background: var(--accent);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}
.info-btn:hover, .info-btn:focus-visible { background: var(--accent-dark); border-color: var(--accent-dark); outline: none; }

#info-bubble {
  position: fixed;
  display: none;
  max-width: 300px;
  background: var(--surface);
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 0.88rem;
  line-height: 1.4;
  color: var(--text);
  box-shadow: 0 6px 20px rgba(43,43,40,0.18);
  z-index: 1000;
}
#info-bubble.visible { display: block; }

.field-note {
  color: var(--text-secondary);
  font-size: 0.82rem;
  margin: 6px 0 0;
  min-height: 1.2em;
}

.habit-breakdown {
  margin: 8px 0 0;
  padding: 8px 12px;
  background: var(--accent-tint);
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent-dark);
  min-height: 1.2em;
}

.back-link {
  margin: 0 0 16px;
}
.back-link a {
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.9rem;
}
.back-link a:hover { color: var(--accent-dark); text-decoration: underline; }

.site-nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px 20px;
  margin-bottom: 24px;
  font-size: 0.9rem;
}
.site-nav a {
  color: var(--text-secondary);
  text-decoration: none;
  font-weight: 600;
}
.site-nav a:hover { color: var(--accent-dark); text-decoration: underline; }

.glossary-list dt {
  font-weight: 700;
  color: var(--accent);
  margin-top: 18px;
}
.glossary-list dt:first-child { margin-top: 0; }
.glossary-list dd {
  margin: 4px 0 0;
  color: var(--text-secondary);
  line-height: 1.5;
}

.hub-intro {
  text-align: center;
  color: var(--text-secondary);
  max-width: 640px;
  margin: 0 auto 32px;
}

.hub-card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}
.hub-card-header h2 {
  margin: 0;
  font-size: 1.25rem;
}
.hub-card-icon { font-size: 1.4rem; }

.hub-card-desc {
  color: var(--text-secondary);
  margin: 0 0 20px;
  font-size: 0.92rem;
}

.habit-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 18px;
}
.habit-preset-btn {
  background: var(--accent-tint);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 8px 14px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent-dark);
  cursor: pointer;
}
.habit-preset-btn:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
.habit-preset-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.habit-results {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 14px;
  margin-top: 20px;
}
.habit-result-tile {
  background: var(--accent-tint);
  border-radius: 8px;
  padding: 14px;
  text-align: center;
}
.habit-result-tile .habit-result-years {
  font-size: 0.78rem;
  color: var(--text-secondary);
  margin-bottom: 6px;
}
.habit-result-tile .habit-result-value {
  font-size: 1.2rem;
  font-weight: 700;
}
.habit-result-tile .habit-result-invested {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 2px;
}

.support-links {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 20px;
}
.referral-disclosure {
  color: var(--text-secondary);
  font-size: 0.78rem;
  margin: 8px 0 0;
}

.site-footer {
  margin-top: 40px;
  padding-top: 28px;
  border-top: 1px solid var(--border);
  text-align: center;
}
.site-footer .support-links { justify-content: center; margin-top: 0; }
.site-footer .referral-disclosure { max-width: 560px; margin-left: auto; margin-right: auto; }
.site-footer .referral-disclosure + .referral-disclosure { margin-top: 6px; }

.site-links {
  margin: 0 0 20px;
  color: var(--text-secondary);
  font-size: 0.85rem;
}
.site-links a {
  color: var(--text-secondary);
  text-decoration: none;
  font-weight: 600;
}
.site-links a:hover { color: var(--accent-dark); text-decoration: underline; }

.support-link {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  width: 150px;
  padding: 14px 12px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.82rem;
  text-align: center;
  background: transparent;
}
.support-link:hover { background: var(--accent-tint); }
.support-link-img {
  max-width: 100%;
  max-height: 56px;
  object-fit: contain;
}

.saved-calc-list {
  list-style: none;
  padding: 0;
  margin: 0 0 12px;
}
.saved-calc-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 8px;
}
.saved-calc-row.active {
  border-color: var(--accent);
  background: var(--accent-tint);
}
.saved-calc-row-main { display: flex; flex-direction: column; gap: 2px; }
.saved-calc-row-main a { font-weight: 600; color: var(--accent-dark); text-decoration: none; }
.saved-calc-row-main a:hover { text-decoration: underline; }

.link-btn {
  background: none;
  border: none;
  padding: 0;
  color: var(--goal-accent);
  font-size: 0.82rem;
  font-weight: 600;
  text-decoration: underline;
  cursor: pointer;
}

.comparison-table-wrap { overflow-x: auto; }
.comparison-table { width: 100%; border-collapse: collapse; margin-top: 12px; }
.comparison-table th, .comparison-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}
.comparison-table td:last-child { white-space: nowrap; }
.comparison-table th { color: var(--text-secondary); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.02em; }
.support-link-qr { max-height: 96px; }
