:root {
  --bg: #cabb95;
  --card-bg: rgba(202, 187, 149, 0.8);
  --card-bg-solid: #cabb95;
  --card-border: #33291f;
  --card-highlight: rgba(51, 41, 31, 0.06);
  --text-primary: #33291f;
  --text-secondary: rgba(51, 41, 31, 0.64);
  --text-tertiary: rgba(51, 41, 31, 0.44);

  --accent-1: #33291f;
  --accent-2: #33291f;
  --accent-3: #6b5136;
  --accent-soft: rgba(51, 41, 31, 0.07);

  --interest: #786246;
  --interest-soft: rgba(120, 98, 70, 0.18);
  --contrib: #33291f;
  --contrib-soft: rgba(51, 41, 31, 0.14);
  --multiple: #6b5136;

  --shadow-sm: none;
  --shadow-md: none;
  --shadow-lg: none;
  --shadow-glow: none;

  --track: rgba(51, 41, 31, 0.25);
  --input-bg: rgba(51, 41, 31, 0.05);
  --input-border: #33291f;

  --radius-lg: 0px;
  --radius-md: 0px;
  --radius-sm: 0px;

  --blob-1: transparent;
  --blob-2: transparent;
  --blob-3: transparent;
}

[data-theme="dark"] {
  --bg: #21170f;
  --card-bg: rgba(33, 23, 15, 0.78);
  --card-bg-solid: #21170f;
  --card-border: #e6d9bd;
  --card-highlight: rgba(230, 217, 189, 0.06);
  --text-primary: #e6d9bd;
  --text-secondary: rgba(230, 217, 189, 0.66);
  --text-tertiary: rgba(230, 217, 189, 0.44);

  --accent-1: #e6d9bd;
  --accent-2: #e6d9bd;
  --accent-3: #c2a67d;
  --accent-soft: rgba(230, 217, 189, 0.08);

  --interest: #b39a76;
  --interest-soft: rgba(179, 154, 118, 0.2);
  --contrib: #e6d9bd;
  --contrib-soft: rgba(230, 217, 189, 0.14);
  --multiple: #c2a67d;

  --shadow-sm: none;
  --shadow-md: none;
  --shadow-lg: none;
  --shadow-glow: none;

  --track: rgba(230, 217, 189, 0.26);
  --input-bg: rgba(230, 217, 189, 0.06);
  --input-border: #e6d9bd;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  /* Stand-in for Shackleton (Adobe Fonts) until a Typekit kit is linked — see index.html <head> comment. */
  font-family: 'Fraunces', Georgia, 'Times New Roman', serif;
  background: var(--bg);
  color: var(--text-primary);
  min-height: 100vh;
  transition: background 0.4s ease, color 0.4s ease;
  position: relative;
  overflow-x: hidden;
}

.bg-decoration {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
  background-image: url("TableV2Background.jpg");
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  transition: filter 0.4s ease;
}
[data-theme="dark"] .bg-decoration {
  filter: brightness(0.32) contrast(1.15) saturate(0.9);
}

.app {
  position: relative;
  z-index: 1;
  max-width: 1180px;
  margin: 0 auto;
  padding: 48px 24px 72px;
}

.app-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 36px;
  padding-bottom: 24px;
  border-bottom: 2px solid var(--text-primary);
}

.brand {
  display: flex;
  align-items: flex-start;
  gap: 16px;
}

.brand-mark {
  flex-shrink: 0;
  width: 46px;
  height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-primary);
  background: transparent;
  border: 2px solid var(--text-primary);
}
.brand-mark svg { width: 22px; height: 22px; }

.kicker {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent-3);
  margin-bottom: 6px;
}

.header-text h1 {
  font-family: 'Fraunces', Georgia, serif;
  font-size: clamp(1.6rem, 3vw, 2.2rem);
  margin: 0 0 6px;
  letter-spacing: -0.01em;
  font-weight: 700;
  font-variation-settings: "opsz" 40;
  line-height: 1.15;
}

.header-text p {
  margin: 0;
  color: var(--text-secondary);
  font-size: 0.96rem;
  white-space: nowrap;
  font-style: italic;
}

.theme-toggle {
  flex-shrink: 0;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 2px solid var(--text-primary);
  background: var(--bg);
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.2s ease, background 0.2s ease, color 0.2s ease;
  position: relative;
}

.theme-toggle:hover { transform: translateY(-2px); }
.theme-toggle svg { width: 19px; height: 19px; position: absolute; transition: opacity 0.25s ease, transform 0.4s ease; }
.icon-moon { opacity: 1; }
.icon-sun { opacity: 0; transform: rotate(-90deg) scale(0.7); }
[data-theme="dark"] .icon-moon { opacity: 0; transform: rotate(90deg) scale(0.7); }
[data-theme="dark"] .icon-sun { opacity: 1; transform: rotate(0) scale(1); }

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

.card {
  background: var(--card-bg);
  border: 2px solid var(--card-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 28px;
  position: relative;
}

.card h2 {
  font-family: 'Fraunces', Georgia, serif;
  font-size: 1.15rem;
  margin: 0 0 22px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.inputs-card {
  position: sticky;
  top: 24px;
}

.field {
  margin-bottom: 24px;
}

.field:last-child { margin-bottom: 0; }

.field label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 9px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.input-prefix, .input-suffix {
  display: flex;
  align-items: center;
  background: var(--input-bg);
  border: 2px solid var(--input-border);
  border-radius: var(--radius-sm);
  padding: 0 16px;
  transition: background 0.15s ease;
}

.input-prefix:focus-within, .input-suffix:focus-within {
  background: var(--accent-soft);
}

.input-prefix span, .input-suffix span {
  color: var(--text-tertiary);
  font-weight: 700;
  font-size: 0.98rem;
}

.input-prefix input, .input-suffix input {
  border: none;
  background: transparent;
  outline: none;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
  padding: 12px 8px;
  width: 100%;
  font-family: 'Fraunces', Georgia, serif;
  letter-spacing: -0.01em;
}

.input-suffix input { text-align: left; }

select#frequency {
  width: 100%;
  padding: 13px 16px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--input-border);
  background: var(--input-bg);
  color: var(--text-primary);
  font-size: 0.98rem;
  font-weight: 650;
  outline: none;
  cursor: pointer;
  appearance: none;
  font-family: inherit;
  transition: background 0.15s ease;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%232c2822' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
}
[data-theme="dark"] select#frequency {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23e7dcc4' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
}
select#frequency:focus {
  background: var(--accent-soft);
}

.slider {
  width: 100%;
  margin-top: 14px;
  -webkit-appearance: none;
  appearance: none;
  height: 3px;
  border-radius: 0;
  background: linear-gradient(to right, var(--text-primary) 0%, var(--text-primary) var(--fill, 50%), var(--track) var(--fill, 50%), var(--track) 100%);
  outline: none;
  cursor: pointer;
}

.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--text-primary);
  border: 3px solid var(--bg);
  box-shadow: 0 0 0 1.5px var(--text-primary);
  cursor: pointer;
  transition: transform 0.12s ease;
}
.slider::-webkit-slider-thumb:hover { transform: scale(1.15); }

.slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--text-primary);
  border: 3px solid var(--bg);
  box-shadow: 0 0 0 1.5px var(--text-primary);
  cursor: pointer;
}
.slider::-moz-range-progress {
  background: var(--text-primary);
  height: 3px;
  border-radius: 0;
}

.segmented {
  display: flex;
  background: transparent;
  border: 2px solid var(--input-border);
  border-radius: var(--radius-sm);
  padding: 0;
  gap: 0;
}

.seg-btn {
  flex: 1;
  padding: 10px 8px;
  border: none;
  border-right: 2px solid var(--input-border);
  background: transparent;
  border-radius: 0;
  color: var(--text-secondary);
  font-weight: 650;
  font-size: 0.85rem;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.2s ease, color 0.2s ease;
}
.seg-btn:last-child { border-right: none; }

.seg-btn.active {
  background: var(--text-primary);
  color: var(--bg);
}

.results-col {
  display: flex;
  flex-direction: column;
  gap: 24px;
  min-width: 0;
}

.summary-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 24px;
  align-items: stretch;
}

.ledger-card {
  padding: 0;
  overflow: hidden;
}

.ledger-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 24px;
  border-bottom: 2px solid var(--card-border);
  font-size: 1.02rem;
  font-weight: 600;
}
.ledger-row:last-child { border-bottom: none; }

.ledger-row span:last-child {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.ledger-head {
  background: transparent;
  border-bottom-width: 2px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 0.76rem;
  color: var(--text-secondary);
  padding-top: 12px;
  padding-bottom: 12px;
}
.ledger-head span:last-child { font-weight: 600; }

.headline-card {
  padding: 0;
  min-width: 220px;
  display: flex;
  flex-direction: column;
}

.headline-value {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Fraunces', Georgia, serif;
  font-size: clamp(2rem, 4.4vw, 2.9rem);
  font-weight: 700;
  font-variation-settings: "opsz" 40;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  padding: 24px;
  text-align: center;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}
.dot-contrib { background: var(--contrib); }
.dot-interest { background: var(--interest); }
.dot-multiple { background: var(--multiple); }

.chart-header, .table-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}
.chart-header h2, .table-header h2 { margin: 0; }

.legend {
  display: flex;
  gap: 16px;
}
.legend span {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
  color: var(--text-secondary);
  font-weight: 600;
}

.chart-card { position: relative; }

#chart {
  width: 100%;
  display: block;
  cursor: crosshair;
}

.chart-tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--text-primary);
  color: var(--bg);
  padding: 10px 14px;
  border-radius: 0;
  font-size: 0.8rem;
  font-weight: 600;
  opacity: 0;
  transform: translate(-50%, -112%);
  transition: opacity 0.12s ease;
  white-space: nowrap;
  z-index: 5;
  box-shadow: var(--shadow-sm);
  line-height: 1.55;
}

.link-btn {
  background: transparent;
  border: 2px solid var(--text-primary);
  color: var(--text-primary);
  font-weight: 700;
  font-size: 0.85rem;
  cursor: pointer;
  padding: 8px 14px;
  border-radius: 0;
  font-family: inherit;
  transition: background 0.15s ease, color 0.15s ease;
}
.link-btn:hover { background: var(--text-primary); color: var(--bg); }

.table-wrap {
  max-height: 340px;
  overflow-y: auto;
  border-radius: var(--radius-sm);
  border: 2px solid var(--card-border);
}
.table-wrap.hidden { display: none; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

thead th {
  position: sticky;
  top: 0;
  background: var(--bg);
  text-align: right;
  padding: 12px 18px;
  font-weight: 700;
  color: var(--text-primary);
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 2px solid var(--card-border);
}
thead th:first-child, tbody td:first-child { text-align: left; }

tbody td {
  padding: 11px 18px;
  text-align: right;
  border-bottom: 1px solid var(--input-border);
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
  font-weight: 600;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--accent-soft); }

.app-footer {
  margin-top: 36px;
  text-align: center;
}
.app-footer p {
  color: var(--text-tertiary);
  font-size: 0.8rem;
  margin: 0;
  font-style: italic;
}

@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
  }
  .inputs-card {
    position: static;
  }
  .summary-row {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 700px) {
  .header-text p { white-space: normal; }
}

@media (max-width: 480px) {
  .app { padding: 28px 14px 56px; }
  .card { padding: 20px; }
  .brand { gap: 12px; }
  .brand-mark { width: 40px; height: 40px; }
}
