:root {
  color-scheme: light;
  --bg: #eee9de;
  --surface: #fbf8f0;
  --ink: #10203a;
  --muted: #5f625e;
  --line: #9c978b;
  --accent: #10294d;
  --accent-ink: #ffffff;
  --warning: #a35d13;
  --danger: #ad332b;
  --success: #1e6c45;
  --radius: 2px;
  --shadow: 0 18px 50px rgb(52 42 24 / 0.14);
  font-family: "Avenir Next", Inter, ui-sans-serif, system-ui, sans-serif;
}

body {
  background-color: var(--bg);
  background-image:
    linear-gradient(rgb(16 32 58 / 0.035) 1px, transparent 1px);
  background-size: 100% 32px;
}

.site-header {
  border-color: #7f7a6e;
  background: rgb(251 248 240 / 0.96);
}

.brand {
  gap: 14px;
}

.brand-word,
h1,
.ledger-title h2,
.method-grid h2,
.faq-section h2 {
  font-family: Georgia, "Times New Roman", serif;
}

.brand-word {
  font-size: 1.45rem;
}

.brand-divider {
  width: 1px;
  height: 28px;
  background: var(--line);
}

.brand-subtitle {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 500;
}

.header-note {
  margin: 0;
}

.page-shell {
  width: min(1560px, 100%);
  padding-top: 28px;
}

.page-intro {
  margin-bottom: 20px;
}

h1 {
  max-width: 1250px;
  font-size: clamp(2.25rem, 4.25vw, 4.65rem);
  font-weight: 500;
  line-height: 1.02;
  letter-spacing: -0.045em;
}

.lede {
  max-width: 1050px;
  color: #373d43;
}

.value-warning {
  max-width: 1040px;
  padding: 10px 12px;
  border-left: 3px solid var(--warning);
  background: rgb(255 255 255 / 0.42);
  color: #4e4c45;
  font-size: 0.88rem;
  line-height: 1.5;
}

.value-warning strong {
  color: #783f0a;
}

.worksheet {
  display: grid;
  grid-template-columns: minmax(310px, 0.68fr) minmax(660px, 1.32fr);
  gap: 0;
  border: 1px solid #77736b;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.input-ledger,
.output-ledger {
  min-width: 0;
  padding: clamp(18px, 2vw, 28px);
}

.input-ledger {
  border-right: 1px solid #77736b;
}

.ledger-title {
  display: flex;
  gap: 10px;
  align-items: baseline;
  margin-bottom: 16px;
  padding-bottom: 10px;
  border-bottom: 2px solid var(--ink);
}

.ledger-title span {
  font: 700 1.08rem/1 Georgia, serif;
}

.ledger-title h2 {
  margin: 0;
  font-size: 1.4rem;
  letter-spacing: -0.01em;
}

fieldset {
  min-width: 0;
  margin: 0 0 22px;
  padding: 0;
  border: 0;
}

legend {
  width: 100%;
  margin-bottom: 10px;
  padding-bottom: 7px;
  border-bottom: 1px solid #b7b1a5;
  color: #394359;
  font: 700 0.72rem/1.4 "SFMono-Regular", Consolas, monospace;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.ledger-fields {
  display: grid;
  gap: 0;
  border: 1px solid #b7b1a5;
}

.ledger-fields label {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 130px;
  align-items: center;
  gap: 12px;
  min-height: 46px;
  padding-left: 12px;
  border-bottom: 1px solid #cbc5b9;
  font-size: 0.8rem;
}

.ledger-fields label:last-child {
  border-bottom: 0;
}

.ledger-fields input {
  height: 45px;
  border: 0;
  border-left: 1px solid #b7b1a5;
  border-radius: 0;
  background: #fffdf7;
  font-family: "SFMono-Regular", Consolas, monospace;
  text-align: right;
}

.csv-fieldset textarea {
  min-height: 132px;
  border-color: #a9a398;
  border-radius: 0;
  background: #fffdf7;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.78rem;
}

.mapping-note {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 0.74rem;
  line-height: 1.55;
}

.mapping-note code {
  color: var(--ink);
}

.csv-actions,
.form-actions,
.memo-actions {
  display: flex;
  gap: 8px;
}

.csv-status,
.form-message {
  min-height: 1.3em;
  margin: 9px 0 0;
  color: var(--muted);
  font-size: 0.75rem;
  line-height: 1.45;
}

.csv-status[data-tone="success"] {
  color: var(--success);
}

.csv-status[data-tone="error"],
.form-message {
  color: var(--danger);
}

.form-actions {
  flex-direction: column;
}

.metric-row-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(116px, 1fr));
  border: 1px solid #8b867c;
}

.ledger-metric {
  min-width: 0;
  padding: 16px 10px;
  border-right: 1px solid #aaa397;
  text-align: center;
}

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

.ledger-metric span,
.ledger-metric small {
  display: block;
}

.ledger-metric span {
  min-height: 2.4em;
  color: #4f5661;
  font-family: Georgia, serif;
  font-size: 0.78rem;
}

.ledger-metric strong {
  display: block;
  margin: 7px 0 5px;
  font: 700 clamp(1rem, 1.65vw, 1.45rem)/1 "SFMono-Regular", Consolas, monospace;
}

.ledger-metric small {
  min-height: 2.2em;
  color: var(--muted);
  font-size: 0.65rem;
  line-height: 1.35;
}

.ledger-metric.exception strong {
  color: var(--danger);
}

.ledger-metric.positive strong {
  color: var(--success);
}

.result-block {
  margin-top: 22px;
}

.result-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 18px;
  padding-bottom: 8px;
  border-bottom: 1px solid #8d887e;
}

.result-heading h3 {
  margin: 0;
  font: 700 0.78rem/1.3 "SFMono-Regular", Consolas, monospace;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.result-heading p {
  margin: 0;
  color: var(--muted);
  font-size: 0.7rem;
  text-align: right;
}

.table-scroll {
  overflow-x: auto;
  border-right: 1px solid #a9a398;
  border-bottom: 1px solid #a9a398;
  border-left: 1px solid #a9a398;
}

.table-scroll:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 35%, transparent);
  outline-offset: 2px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
  font-size: 0.73rem;
}

th,
td {
  padding: 9px 10px;
  border-right: 1px solid #ccc5b8;
  border-bottom: 1px solid #ccc5b8;
  text-align: left;
  vertical-align: top;
}

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

tbody tr:last-child td,
tbody tr:last-child th {
  border-bottom: 0;
}

thead th {
  background: #f2eee5;
  color: #343c4c;
  font-family: Georgia, serif;
  font-weight: 600;
}

.action-cell {
  font-weight: 800;
  text-transform: uppercase;
}

.action-cell[data-action="keep"] {
  color: var(--success);
}

.action-cell[data-action="cut"] {
  color: var(--danger);
}

.action-cell[data-action="review"] {
  color: var(--warning);
}

.aggregate-note {
  margin: 0;
  padding: 14px;
  color: var(--muted);
  font-size: 0.78rem;
}

.scenario-table th:not(:first-child),
.scenario-table td:not(:first-child) {
  text-align: right;
}

.scenario-table td:nth-child(3) {
  color: var(--success);
  font-weight: 800;
}

.portfolio-action {
  color: var(--warning);
  font: 800 0.78rem/1 "SFMono-Regular", Consolas, monospace;
  text-transform: uppercase;
}

.portfolio-action[data-action="keep"] {
  color: var(--success);
}

.portfolio-action[data-action="cut"] {
  color: var(--danger);
}

.memo-block textarea {
  min-height: 180px;
  margin-top: 10px;
  border-color: #a9a398;
  border-radius: 0;
  background: #fffdf7;
  font: 0.76rem/1.6 "SFMono-Regular", Consolas, monospace;
}

.memo-actions {
  justify-content: flex-end;
  margin-top: 8px;
}

.warning-list {
  margin: 18px 0 0;
  padding: 12px 12px 12px 30px;
  border: 1px solid #c9a578;
  background: #fff7e7;
  color: #754815;
  font-size: 0.74rem;
  line-height: 1.55;
}

.warning-list:empty {
  display: none;
}

.method-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  margin-top: 24px;
}

.method-grid article {
  padding: 24px;
  border: 1px solid #aaa397;
  background: rgb(251 248 240 / 0.76);
}

.method-grid h2,
.faq-section h2 {
  margin-bottom: 12px;
  font-size: 1.25rem;
}

.method-grid li,
.faq-section p {
  color: #545751;
  line-height: 1.65;
}

.faq-section {
  max-width: 1000px;
  margin: 46px 0 20px;
}

.faq-section details {
  padding: 15px 0;
  border-bottom: 1px solid #aaa397;
}

.faq-section summary {
  font-family: Georgia, serif;
  font-size: 1.02rem;
  font-weight: 600;
}

.faq-section p {
  margin: 10px 0 0;
}

.site-footer {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  padding: 24px 4vw 38px;
  border-top: 1px solid #8f897e;
  color: var(--muted);
  font-size: 0.78rem;
}

.site-footer p {
  margin: 0;
}

@media (max-width: 1180px) {
  .worksheet {
    grid-template-columns: 1fr;
  }

  .input-ledger {
    border-right: 0;
    border-bottom: 1px solid #77736b;
  }

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

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

  .ledger-metric:nth-child(-n + 3) {
    border-bottom: 1px solid #aaa397;
  }
}

@media (max-width: 700px) {
  .site-header {
    align-items: flex-start;
    min-height: auto;
    padding-top: 14px;
    padding-bottom: 14px;
  }

  .brand-divider,
  .brand-subtitle {
    display: none;
  }

  .header-note {
    max-width: 145px;
    text-align: right;
  }

  .page-shell {
    padding-top: 24px;
  }

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

  .ledger-metric {
    border-right: 1px solid #aaa397;
    border-bottom: 1px solid #aaa397;
  }

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

  .ledger-metric:nth-last-child(-n + 2) {
    border-bottom: 0;
  }

  .ledger-fields label {
    grid-template-columns: 1fr;
    gap: 0;
    padding: 10px 0 0 10px;
  }

  .ledger-fields input {
    margin-top: 8px;
    border-top: 1px solid #b7b1a5;
    border-left: 0;
  }

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

  .result-heading,
  .site-footer {
    align-items: flex-start;
    flex-direction: column;
  }

  .result-heading p {
    text-align: left;
  }

  .memo-actions,
  .csv-actions {
    flex-direction: column;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}
