:root {
  --paper: #f3f0e9;
  --paper-strong: #e8e2d7;
  --ink: #202722;
  --muted: #697069;
  --line: #cfc8bb;
  --line-strong: #9d9b91;
  --white: #fffdf8;
  --teal: #147a63;
  --teal-pale: #dcebe5;
  --red: #b4433e;
  --red-pale: #f3dfdb;
  --amber: #b36a2e;
  --amber-pale: #efe0cd;
  --blue: #3c658c;
  --blue-pale: #dde6ee;
  --shadow: 0 18px 48px rgba(49, 45, 37, .08);
  --display: Georgia, "Noto Serif TC", "Source Han Serif TC", serif;
  --body: "Segoe UI", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  --mono: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: light;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background:
    linear-gradient(rgba(60, 52, 41, .035) 1px, transparent 1px),
    var(--paper);
  background-size: 100% 32px;
  color: var(--ink);
  font-family: var(--body);
  font-size: 16px;
  line-height: 1.55;
}

button,
input,
select {
  font: inherit;
}

button {
  color: inherit;
}

.masthead {
  border-bottom: 1px solid var(--line-strong);
  background: var(--ink);
  color: var(--white);
}

.masthead__inner {
  width: min(1560px, calc(100% - 48px));
  margin: 0 auto;
  padding: 42px 0 36px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 48px;
}

.eyebrow,
.section-kicker {
  margin: 0 0 8px;
  color: #aeb7ad;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .16em;
}

.masthead h1 {
  margin: 0;
  max-width: 860px;
  font-family: var(--display);
  font-size: clamp(34px, 5vw, 66px);
  font-weight: 500;
  letter-spacing: -.04em;
  line-height: .98;
  text-wrap: balance;
}

.subtitle {
  max-width: 760px;
  margin: 20px 0 0;
  color: #c9cec8;
  font-size: 17px;
  text-wrap: pretty;
}

.status-chip {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 0;
  border-bottom: 1px solid rgba(255, 255, 255, .34);
  color: #dce2db;
  font-size: 13px;
  white-space: nowrap;
}

.status-chip__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #78c8a7;
  box-shadow: 0 0 0 4px rgba(120, 200, 167, .13);
}

.view-nav {
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 1px solid var(--line);
  background: rgba(243, 240, 233, .94);
  backdrop-filter: blur(14px);
  padding-left: max(24px, calc((100vw - 1560px) / 2));
}

.view-nav__button {
  position: relative;
  border: 0;
  background: transparent;
  padding: 16px 22px 15px;
  color: var(--muted);
  cursor: pointer;
  font-size: 14px;
  font-weight: 700;
}

.view-nav__button::after {
  content: "";
  position: absolute;
  right: 22px;
  bottom: -1px;
  left: 22px;
  height: 3px;
  background: transparent;
}

.view-nav__button:hover,
.view-nav__button.is-active {
  color: var(--ink);
}

.view-nav__button.is-active::after {
  background: var(--ink);
}

.app-shell {
  width: min(1560px, calc(100% - 48px));
  margin: 32px auto 80px;
  display: grid;
  grid-template-columns: minmax(290px, 360px) minmax(0, 1fr);
  gap: 32px;
  align-items: start;
}

.controls {
  position: sticky;
  top: 74px;
  max-height: calc(100vh - 96px);
  overflow-y: auto;
  padding: 26px 24px 32px;
  border: 1px solid var(--line-strong);
  background: rgba(255, 253, 248, .84);
  box-shadow: var(--shadow);
  scrollbar-width: thin;
}

.controls__heading,
.card-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
}

.controls h2,
.card-heading h3,
.scenario-card h3,
.formula-card h3,
.checklist-card h3 {
  margin: 0;
  font-family: var(--display);
  font-weight: 600;
  letter-spacing: -.02em;
}

.controls h2 {
  font-size: 25px;
}

.text-button {
  border: 0;
  border-bottom: 1px solid var(--line-strong);
  background: transparent;
  padding: 3px 0;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
}

.preset-row {
  margin: 22px 0 4px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border: 1px solid var(--line);
}

.preset-button {
  min-height: 44px;
  border: 0;
  border-right: 1px solid var(--line);
  background: transparent;
  padding: 8px 6px;
  color: var(--muted);
  cursor: pointer;
  font-size: 11px;
  font-weight: 700;
}

.preset-button:last-child {
  border-right: 0;
}

.preset-button:hover,
.preset-button.is-active {
  background: var(--ink);
  color: var(--white);
}

.control-group {
  margin: 24px 0 0;
  padding: 22px 0 0;
  border: 0;
  border-top: 1px solid var(--line);
}

.control-group legend {
  float: left;
  width: 100%;
  margin-bottom: 15px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
}

.control-group legend + * {
  clear: both;
}

.field {
  display: block;
  margin-bottom: 14px;
}

.field > span {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
  color: #495149;
  font-size: 12px;
  font-weight: 700;
}

.field small,
.microcopy,
.switch-field small {
  color: #858a84;
  font-size: 10px;
  font-weight: 500;
}

.field input,
.field select,
.input-suffix {
  width: 100%;
  min-height: 43px;
  border: 1px solid var(--line);
  border-radius: 0;
  outline: 0;
  background: var(--white);
  color: var(--ink);
}

.field input,
.field select {
  padding: 9px 11px;
}

.field input:focus,
.field select:focus,
.input-suffix:focus-within {
  border-color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--ink);
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.input-suffix {
  display: flex;
  align-items: center;
}

.input-suffix input {
  min-width: 0;
  border: 0;
  box-shadow: none !important;
}

.input-suffix b {
  padding: 0 11px 0 4px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
}

.switch-field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 12px 0 0;
}

.switch-field span {
  display: grid;
  gap: 2px;
  font-size: 12px;
}

.switch-field input {
  appearance: none;
  flex: 0 0 42px;
  width: 42px;
  height: 23px;
  margin: 0;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: #d6d2c9;
  cursor: pointer;
}

.switch-field input::before {
  content: "";
  display: block;
  width: 17px;
  height: 17px;
  margin: 2px;
  border-radius: 50%;
  background: var(--white);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .2);
  transition: transform .18s ease;
}

.switch-field input:checked {
  border-color: var(--red);
  background: var(--red);
}

.switch-field input:checked::before {
  transform: translateX(19px);
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  margin: 4px 0 14px;
  border: 1px solid var(--line);
}

.segmented__button {
  border: 0;
  border-right: 1px solid var(--line);
  background: var(--white);
  padding: 9px 6px;
  color: var(--muted);
  cursor: pointer;
  font-size: 11px;
  font-weight: 700;
}

.segmented__button:last-child {
  border-right: 0;
}

.segmented__button.is-active {
  background: var(--ink);
  color: var(--white);
}

.random-options {
  padding: 14px 14px 2px;
  background: var(--paper);
}

.microcopy {
  margin: 3px 0 12px;
  line-height: 1.5;
}

.workspace {
  min-width: 0;
}

.view-panel {
  display: none;
}

.view-panel.is-active {
  display: block;
  animation: panel-enter .34s ease both;
}

@keyframes panel-enter {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.error-banner {
  margin-bottom: 18px;
  border: 1px solid var(--red);
  background: var(--red-pale);
  padding: 12px 15px;
  color: #7d2b28;
  font-weight: 700;
}

.verdict-card {
  min-height: 190px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 36px;
  align-items: end;
  padding: clamp(28px, 5vw, 52px);
  border-top: 8px solid var(--ink);
  background: var(--white);
  box-shadow: var(--shadow);
}

.verdict-card--positive {
  border-top-color: var(--teal);
  background: linear-gradient(115deg, var(--white), var(--teal-pale));
}

.verdict-card--negative {
  border-top-color: var(--red);
  background: linear-gradient(115deg, var(--white), var(--red-pale));
}

.verdict-card h2 {
  max-width: 800px;
  margin: 0;
  font-family: var(--display);
  font-size: clamp(28px, 4vw, 48px);
  font-weight: 600;
  letter-spacing: -.035em;
  line-height: 1.08;
  text-wrap: balance;
}

.verdict-card p:not(.section-kicker) {
  max-width: 820px;
  margin: 15px 0 0;
  color: var(--muted);
  text-wrap: pretty;
}

.verdict-card__amount {
  min-width: 180px;
  padding-left: 28px;
  border-left: 1px solid var(--line-strong);
  text-align: right;
}

.verdict-card__amount span,
.verdict-card__amount small {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.verdict-card__amount strong {
  display: block;
  margin: 6px 0;
  font-family: var(--mono);
  font-size: clamp(24px, 4vw, 42px);
  letter-spacing: -.06em;
  white-space: nowrap;
}

.is-positive {
  color: var(--teal) !important;
}

.is-negative {
  color: var(--red) !important;
}

.is-zero {
  color: var(--muted) !important;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-top: 18px;
  border: 1px solid var(--line-strong);
  background: var(--white);
}

.metric {
  min-width: 0;
  padding: 22px 20px;
  border-right: 1px solid var(--line);
}

.metric:last-child {
  border-right: 0;
}

.metric--report {
  background: var(--blue-pale);
}

.metric span,
.metric small {
  display: block;
  color: var(--muted);
  font-size: 11px;
}

.metric strong {
  display: block;
  overflow: hidden;
  margin: 7px 0 5px;
  font-family: var(--mono);
  font-size: clamp(19px, 2vw, 27px);
  letter-spacing: -.055em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#volumeDirectionCount {
  font-size: clamp(16px, 1.75vw, 23px);
  white-space: normal;
}

.flow-card,
.table-card,
.chart-card,
.scenario-card,
.formula-card,
.checklist-card {
  margin-top: 18px;
  border: 1px solid var(--line-strong);
  background: var(--white);
  box-shadow: var(--shadow);
}

.flow-card,
.chart-card,
.formula-card,
.checklist-card {
  padding: clamp(24px, 4vw, 38px);
}

.card-heading h3,
.scenario-card h3,
.formula-card h3,
.checklist-card h3 {
  font-size: 24px;
}

.card-heading > p {
  max-width: 460px;
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 12px;
  text-align: right;
}

.money-flow {
  margin-top: 32px;
  display: grid;
  grid-template-columns: 1fr auto 1fr auto 1fr auto 1fr auto 1fr;
  gap: 8px;
  align-items: stretch;
}

.money-flow__step {
  min-width: 0;
  padding: 18px 14px;
  border-top: 3px solid var(--line-strong);
  background: var(--paper);
}

.money-flow__step--actual {
  border-top-color: var(--amber);
  background: var(--amber-pale);
}

.money-flow__step--report {
  border-top-color: var(--blue);
  background: var(--blue-pale);
}

.money-flow__step span,
.money-flow__step small {
  display: block;
  color: var(--muted);
  font-size: 10px;
}

.money-flow__step strong {
  display: block;
  overflow: hidden;
  margin: 8px 0 6px;
  font-family: var(--mono);
  font-size: 16px;
  letter-spacing: -.04em;
  text-overflow: ellipsis;
}

.money-flow__arrow {
  align-self: center;
  color: var(--line-strong);
  font-family: var(--display);
  font-size: 24px;
}

.table-card {
  overflow: hidden;
}

.table-card .card-heading {
  padding: 30px 34px 22px;
}

.table-wrap {
  overflow-x: auto;
  border-top: 1px solid var(--line);
}

table {
  width: 100%;
  min-width: 980px;
  border-collapse: collapse;
  font-size: 12px;
}

th,
td {
  padding: 13px 14px;
  border-right: 1px solid #dfd9cf;
  border-bottom: 1px solid #dfd9cf;
  text-align: right;
  white-space: nowrap;
}

th:first-child,
td:first-child {
  text-align: left;
}

th:last-child,
td:last-child {
  border-right: 0;
}

thead th {
  background: var(--ink);
  color: var(--white);
  font-size: 10px;
  letter-spacing: .05em;
}

tbody tr:hover {
  background: #f7f3ec;
}

.cell-actual {
  background: var(--amber-pale);
}

.cell-report {
  background: var(--blue-pale);
}

.cell-note {
  display: block;
  color: var(--red);
  font-size: 9px;
}

tfoot th,
tfoot td {
  border-bottom: 0;
  background: var(--paper-strong);
  font-family: var(--mono);
  font-weight: 800;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 16px;
  color: var(--muted);
  font-size: 11px;
}

.chart-legend span {
  display: flex;
  align-items: center;
  gap: 7px;
}

.legend-line {
  width: 22px;
  height: 3px;
  display: inline-block;
}

.legend-line--settlement {
  background: var(--teal);
}

.legend-line--tail {
  background: var(--amber);
}

.chart-wrap {
  position: relative;
  min-height: 320px;
  margin-top: 26px;
}

#driftChart {
  display: block;
  max-width: 100%;
}

.chart-empty {
  position: absolute;
  inset: 50% auto auto 50%;
  transform: translate(-50%, -50%);
  background: var(--paper);
  padding: 8px 12px;
  color: var(--muted);
  font-size: 12px;
}

.chart-axis-notes {
  display: flex;
  justify-content: space-between;
  padding-left: 68px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 10px;
}

.scenario-card {
  display: grid;
  grid-template-columns: minmax(180px, .7fr) minmax(0, 1.7fr) auto;
  gap: 28px;
  align-items: center;
  padding: 28px 34px;
  border-left: 6px solid var(--red);
}

.scenario-card p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  text-wrap: pretty;
}

.secondary-button {
  border: 1px solid var(--ink);
  background: transparent;
  padding: 11px 16px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.secondary-button:hover {
  background: var(--ink);
  color: var(--white);
}

.accounting-hero {
  min-height: 330px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: clamp(32px, 7vw, 74px);
  background: var(--ink);
  color: var(--white);
}

.accounting-hero h2 {
  max-width: 980px;
  margin: 0;
  font-family: var(--display);
  font-size: clamp(34px, 5vw, 58px);
  font-weight: 500;
  letter-spacing: -.045em;
  line-height: 1.02;
  text-wrap: balance;
}

.accounting-hero > p:last-child {
  max-width: 840px;
  margin: 22px 0 0;
  color: #c9cec8;
  text-wrap: pretty;
}

.accounting-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin-top: 18px;
  border: 1px solid var(--line-strong);
}

.accounting-card {
  min-height: 280px;
  padding: 30px;
  border-right: 1px solid var(--line-strong);
  background: var(--white);
}

.accounting-card:last-child {
  border-right: 0;
}

.accounting-card--actual {
  border-top: 5px solid var(--amber);
}

.accounting-card--report {
  border-top: 5px solid var(--blue);
  background: var(--blue-pale);
}

.accounting-card--difference {
  border-top: 5px solid var(--ink);
}

.accounting-card--difference.is-positive {
  border-top-color: var(--teal);
  background: var(--teal-pale);
}

.accounting-card--difference.is-negative {
  border-top-color: var(--red);
  background: var(--red-pale);
}

.accounting-card h3 {
  margin: 0;
  font-family: var(--display);
  font-size: 24px;
}

.accounting-card strong {
  display: block;
  margin: 32px 0 14px;
  font-family: var(--mono);
  font-size: clamp(26px, 3vw, 40px);
  letter-spacing: -.06em;
}

.accounting-card > p:last-child {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.formula-card {
  display: grid;
  grid-template-columns: minmax(180px, .65fr) minmax(0, 1.7fr);
  gap: 34px;
  align-items: center;
}

.formula {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 22px;
  border: 1px solid var(--line);
  background: var(--paper);
  font-family: var(--mono);
  font-size: 13px;
  text-align: center;
}

.formula-card > p {
  grid-column: 2;
  margin: -18px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.checklist {
  margin: 28px 0 0;
  padding: 0;
  counter-reset: audit;
  list-style: none;
  border-top: 1px solid var(--line);
}

.checklist li {
  counter-increment: audit;
  display: grid;
  grid-template-columns: 190px minmax(0, 1fr);
  gap: 28px;
  padding: 20px 0 20px 46px;
  border-bottom: 1px solid var(--line);
  position: relative;
}

.checklist li::before {
  content: counter(audit, decimal-leading-zero);
  position: absolute;
  left: 0;
  color: var(--line-strong);
  font-family: var(--mono);
  font-weight: 800;
}

.checklist span {
  color: var(--muted);
  font-size: 13px;
}

footer {
  border-top: 1px solid var(--line-strong);
  background: var(--paper-strong);
  padding: 24px;
  color: var(--muted);
  font-size: 11px;
  text-align: center;
}

footer p {
  margin: 0;
}

@media (max-width: 1220px) {
  .app-shell {
    grid-template-columns: 300px minmax(0, 1fr);
    gap: 22px;
  }

  .metric-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .metric:nth-child(2) {
    border-right: 0;
  }

  .metric:nth-child(-n + 2) {
    border-bottom: 1px solid var(--line);
  }

  .money-flow {
    grid-template-columns: repeat(5, 1fr);
  }

  .money-flow__arrow {
    display: none;
  }

  .scenario-card {
    grid-template-columns: 1fr;
  }

  .scenario-card .secondary-button {
    justify-self: start;
  }
}

@media (max-width: 900px) {
  .masthead__inner {
    align-items: flex-start;
    flex-direction: column;
    gap: 24px;
  }

  .app-shell {
    display: block;
  }

  .controls {
    position: static;
    max-height: none;
    margin-bottom: 24px;
  }

  .verdict-card {
    grid-template-columns: 1fr;
  }

  .verdict-card__amount {
    padding: 18px 0 0;
    border-top: 1px solid var(--line-strong);
    border-left: 0;
    text-align: left;
  }

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

  .accounting-card {
    min-height: 230px;
    border-right: 0;
    border-bottom: 1px solid var(--line-strong);
  }

  .accounting-card:last-child {
    border-bottom: 0;
  }

  .formula-card {
    grid-template-columns: 1fr;
  }

  .formula-card > p {
    grid-column: auto;
    margin: 0;
  }
}

@media (max-width: 640px) {
  .masthead__inner,
  .app-shell {
    width: min(100% - 28px, 1560px);
  }

  .masthead__inner {
    padding: 32px 0;
  }

  .subtitle {
    font-size: 14px;
  }

  .view-nav {
    overflow-x: auto;
    padding-left: 7px;
    white-space: nowrap;
  }

  .view-nav__button {
    padding-inline: 14px;
  }

  .view-nav__button::after {
    right: 14px;
    left: 14px;
  }

  .app-shell {
    margin-top: 18px;
  }

  .controls {
    padding: 22px 18px;
  }

  .field-grid,
  .metric-grid {
    grid-template-columns: 1fr;
  }

  .metric {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .metric:last-child {
    border-bottom: 0;
  }

  .verdict-card {
    padding: 26px 22px;
  }

  .flow-card,
  .chart-card,
  .formula-card,
  .checklist-card {
    padding: 24px 20px;
  }

  .card-heading {
    display: block;
  }

  .card-heading > p,
  .chart-legend {
    margin-top: 14px;
    justify-content: flex-start;
    text-align: left;
  }

  .money-flow {
    grid-template-columns: 1fr;
  }

  .table-card .card-heading {
    padding: 24px 20px;
  }

  .accounting-hero {
    min-height: 380px;
    padding: 34px 24px;
  }

  .accounting-card {
    padding: 26px 22px;
  }

  .formula {
    align-items: stretch;
    flex-direction: column;
  }

  .checklist li {
    grid-template-columns: 1fr;
    gap: 6px;
    padding-left: 38px;
  }

  .chart-wrap {
    min-height: 300px;
    margin-left: -14px;
  }

  .chart-axis-notes {
    padding-left: 52px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
}
