:root {
  color-scheme: light;
  --paper: #f1eee6;
  --surface: #faf8f2;
  --ink: #18221e;
  --muted: #68716c;
  --line: #cbc9bf;
  --asset: #236a50;
  --asset-soft: #dce9e1;
  --liability: #a84636;
  --liability-soft: #f0dfda;
  --gold: #a9813b;
  --shadow: 0 22px 55px rgba(24, 34, 30, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background:
    linear-gradient(rgba(24, 34, 30, 0.025) 1px, transparent 1px),
    var(--paper);
  background-size: 100% 28px;
  font-family: "Hiragino Sans", "Yu Gothic", Meiryo, system-ui, sans-serif;
  line-height: 1.65;
}

button, input { font: inherit; }
button, label { -webkit-tap-highlight-color: transparent; }
button { color: inherit; cursor: pointer; }

.app-shell {
  width: min(1120px, calc(100% - 36px));
  margin: 0 auto;
  padding: 54px 0 72px;
}

.hero {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 40px;
  padding: 20px 0 52px;
  border-bottom: 1px solid var(--ink);
}

.eyebrow, .section-label {
  margin: 0;
  color: var(--asset);
  font-family: Georgia, "Times New Roman", serif;
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .16em;
}

.hero h1 {
  margin: 9px 0 0;
  font-family: Georgia, "Yu Mincho", "Hiragino Mincho ProN", serif;
  font-size: clamp(2.6rem, 7vw, 5.6rem);
  font-weight: 400;
  letter-spacing: -.04em;
  line-height: 1.02;
}

.hero-copy {
  max-width: 400px;
  margin: 0 0 8px;
  color: var(--muted);
  font-family: "Yu Mincho", "Hiragino Mincho ProN", serif;
  font-size: 1rem;
}

section {
  margin-top: 28px;
  padding: clamp(22px, 4vw, 38px);
  border: 1px solid var(--line);
  background: rgba(250, 248, 242, .94);
  box-shadow: var(--shadow);
}

.panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 26px;
}

h2 {
  margin: 3px 0 0;
  font-family: Georgia, "Yu Mincho", "Hiragino Mincho ProN", serif;
  font-size: clamp(1.45rem, 3vw, 2rem);
  font-weight: 400;
  line-height: 1.35;
}

.record-count { margin: 8px 0 0; color: var(--muted); font-size: .82rem; }

.balance-summary {
  display: grid;
  grid-template-columns: 1fr 1fr .8fr;
  border: 1px solid var(--line);
}

.balance-card, .net-card { min-width: 0; padding: 25px; }
.balance-card { position: relative; border-right: 1px solid var(--line); }
.balance-card p, .net-card p { margin: 0 0 20px; font-weight: 700; }
.balance-card p small { display: block; margin-top: 2px; color: var(--muted); font-weight: 400; }
.balance-card strong, .net-card strong {
  display: block;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(2.6rem, 6vw, 4.5rem);
  font-weight: 400;
  line-height: 1;
}
.balance-card > span:last-child { color: var(--muted); font-size: .64rem; letter-spacing: .15em; }
.card-mark { position: absolute; top: 20px; right: 22px; font-size: 1.4rem; }
.asset-card strong, .asset-card .card-mark { color: var(--asset); }
.liability-card strong, .liability-card .card-mark { color: var(--liability); }

.net-card { display: flex; flex-direction: column; justify-content: center; color: #fff; background: var(--ink); }
.net-card p { opacity: .72; }
.net-card span { margin-top: 13px; font-weight: 700; letter-spacing: .12em; }
.net-card.is-asset { background: var(--asset); }
.net-card.is-liability { background: var(--liability); }

.balance-meter { margin-top: 25px; }
.meter-labels { display: flex; justify-content: space-between; margin-bottom: 7px; font-size: .76rem; font-weight: 700; }
.meter-track { display: flex; width: 100%; height: 9px; overflow: hidden; background: #dedbd2; }
.meter-asset { width: 50%; background: var(--asset); transition: width .35s ease; }
.meter-liability { width: 50%; background: var(--liability); transition: width .35s ease; }
.meter-empty { margin: 10px 0 0; color: var(--muted); font-size: .8rem; }

fieldset { min-width: 0; margin: 0; padding: 0; border: 0; }
fieldset legend, .field > span { margin-bottom: 9px; color: var(--muted); font-size: .78rem; font-weight: 700; }

.type-selector, .weight-selector { display: grid; gap: 10px; }
.type-selector { grid-template-columns: 1fr 1fr; }
.type-selector legend, .weight-selector legend { grid-column: 1 / -1; }
.type-option { position: relative; }
.type-option input, .weight-option input { position: absolute; opacity: 0; pointer-events: none; }
.type-option > span:not(.radio-icon) {
  display: flex;
  flex-direction: column;
  padding: 18px 20px 18px 58px;
  border: 1px solid var(--line);
  background: #fff;
  transition: .18s ease;
}
.type-option small { color: var(--muted); }
.radio-icon { position: absolute; z-index: 1; top: 22px; left: 23px; font-size: 1.25rem; }
.asset-option input:checked + .radio-icon + span { border-color: var(--asset); background: var(--asset-soft); box-shadow: inset 4px 0 var(--asset); }
.liability-option input:checked + .radio-icon + span { border-color: var(--liability); background: var(--liability-soft); box-shadow: inset 4px 0 var(--liability); }
.type-option input:focus-visible + .radio-icon + span, .weight-option input:focus-visible + span { outline: 3px solid rgba(35, 106, 80, .25); outline-offset: 2px; }

.form-grid { display: grid; grid-template-columns: .7fr 1.3fr; gap: 17px; margin-top: 24px; }
.field { display: flex; flex-direction: column; }
.field-wide { grid-column: 1 / -1; }
.suggestion-wrap { position: relative; display: block; margin: 0 !important; }
.person-suggestions {
  position: absolute;
  z-index: 10;
  top: calc(100% + 4px);
  left: 0;
  width: 100%;
  border: 1px solid var(--ink);
  background: #fff;
  box-shadow: 0 14px 30px rgba(24, 34, 30, .14);
}
.person-suggestion {
  display: block;
  width: 100%;
  padding: 11px 14px;
  border: 0;
  border-bottom: 1px solid var(--line);
  text-align: left;
  background: #fff;
}
.person-suggestion:last-child { border-bottom: 0; }
.person-suggestion:hover, .person-suggestion.is-active { color: #fff; background: var(--asset); }
.field input {
  width: 100%;
  height: 52px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 0;
  color: var(--ink);
  background: #fff;
}
.field input:focus { border-color: var(--asset); outline: 2px solid rgba(35, 106, 80, .14); }

.weight-selector { grid-template-columns: repeat(3, 1fr); margin-top: 24px; }
.weight-option { position: relative; }
.weight-option > span {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 70px;
  padding: 12px 16px;
  border: 1px solid var(--line);
  background: #fff;
  transition: .18s ease;
}
.weight-option strong { font-family: Georgia, serif; font-size: 1.6rem; font-weight: 400; }
.weight-option small { color: var(--muted); }
.weight-option input:checked + span { border-color: var(--gold); background: #f2ead8; box-shadow: inset 0 -3px var(--gold); }

.form-footer { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-top: 26px; }
.status { min-height: 1.5em; margin: 0; color: var(--asset); font-size: .84rem; }
.status.is-error { color: var(--liability); }

.primary-button, .secondary-button, .danger-button {
  min-height: 46px;
  padding: 0 20px;
  border: 1px solid var(--ink);
  border-radius: 0;
  font-weight: 700;
}
.primary-button { min-width: 170px; color: #fff; background: var(--ink); }
.primary-button span { margin-left: 18px; }
.primary-button:hover { background: var(--asset); }
.secondary-button { display: inline-flex; align-items: center; justify-content: center; background: transparent; }
.secondary-button:hover { background: #e8e4da; }
.danger-button { color: #fff; border-color: var(--liability); background: var(--liability); }
.text-button { padding: 5px 0; border: 0; border-bottom: 1px solid currentColor; color: var(--asset); background: none; font-size: .8rem; }

.people-list { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.person-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 20px;
  width: 100%;
  padding: 18px 20px;
  border: 1px solid var(--line);
  text-align: left;
  background: #fff;
}
.person-card:hover, .person-card.is-active { border-color: var(--ink); background: #f1eee6; }
.person-name { overflow: hidden; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.person-net { font-family: Georgia, serif; font-size: 1.25rem; }
.person-stats { grid-column: 1 / -1; color: var(--muted); font-size: .75rem; }
.person-status { color: var(--muted); font-size: .7rem; letter-spacing: .06em; }

.history-heading { align-items: flex-end; }
.filters { display: flex; border-bottom: 1px solid var(--line); }
.filter-button { padding: 8px 14px; border: 0; color: var(--muted); background: transparent; font-size: .8rem; }
.filter-button.is-active { color: var(--ink); box-shadow: 0 2px var(--ink); font-weight: 700; }
.active-filter { margin: -10px 0 18px; padding: 9px 12px; color: var(--asset); background: var(--asset-soft); font-size: .8rem; }
.history-list { border-top: 1px solid var(--line); }
.history-item {
  display: grid;
  grid-template-columns: 85px 78px minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 14px;
  padding: 17px 4px;
  border-bottom: 1px solid var(--line);
}
.history-date { color: var(--muted); font-family: Georgia, serif; font-size: .85rem; }
.entry-badge { display: inline-flex; align-items: center; justify-content: center; gap: 5px; padding: 3px 7px; font-size: .7rem; font-weight: 700; }
.entry-badge.asset { color: var(--asset); background: var(--asset-soft); }
.entry-badge.liability { color: var(--liability); background: var(--liability-soft); }
.history-main { min-width: 0; }
.history-main strong, .history-main span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-main span { color: var(--muted); font-size: .8rem; }
.history-points { min-width: 52px; text-align: right; font-family: Georgia, serif; font-size: 1.35rem; }
.history-actions { display: flex; gap: 4px; }
.icon-button { width: 34px; height: 34px; padding: 0; border: 1px solid transparent; color: var(--muted); background: transparent; }
.icon-button:hover { border-color: var(--line); color: var(--ink); }

.empty-state { grid-column: 1 / -1; margin: 0; padding: 35px 15px; border: 1px dashed var(--line); color: var(--muted); text-align: center; }
.data-panel { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 20px; }
.data-panel p:not(.section-label):not(.status) { margin: 6px 0 0; color: var(--muted); font-size: .82rem; }
.data-controls { display: flex; gap: 10px; }
.file-button { cursor: pointer; }
.file-button input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.data-panel .status { flex-basis: 100%; }

footer { display: flex; justify-content: space-between; width: min(1120px, calc(100% - 36px)); margin: 0 auto; padding: 0 0 30px; color: var(--muted); font-size: .68rem; letter-spacing: .1em; }
footer a { color: var(--ink); text-underline-offset: 4px; }
footer a:hover { color: var(--asset); }

dialog { width: min(480px, calc(100% - 32px)); padding: 28px; border: 1px solid var(--line); border-radius: 0; color: var(--ink); background: var(--surface); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(24, 34, 30, .55); }
dialog p:not(.section-label) { color: var(--muted); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 25px; }

@media (max-width: 760px) {
  .app-shell { width: min(100% - 24px, 640px); padding-top: 24px; }
  .hero { display: block; padding-bottom: 30px; }
  .hero-copy { margin-top: 24px; }
  section { margin-top: 16px; padding: 20px 16px; }
  .balance-summary { grid-template-columns: 1fr 1fr; }
  .balance-card { padding: 18px 14px; }
  .balance-card:nth-child(2) { border-right: 0; }
  .net-card { grid-column: 1 / -1; min-height: 145px; }
  .type-selector, .form-grid { grid-template-columns: 1fr; }
  .field-wide { grid-column: auto; }
  .weight-option > span { flex-direction: column; justify-content: center; gap: 0; padding: 9px 4px; text-align: center; }
  .people-list { grid-template-columns: 1fr; }
  .history-heading { display: block; }
  .filters { margin-top: 16px; }
  .history-item { grid-template-columns: 64px minmax(0, 1fr) auto; gap: 10px; }
  .entry-badge { grid-row: 2; }
  .history-main { grid-column: 2; grid-row: 1 / span 2; }
  .history-points { grid-column: 3; grid-row: 1; }
  .history-actions { grid-column: 3; grid-row: 2; justify-content: flex-end; }
  .form-footer, .data-panel { align-items: stretch; flex-direction: column; }
  .primary-button { width: 100%; }
  .data-controls { display: grid; grid-template-columns: 1fr 1fr; }
  footer { width: calc(100% - 24px); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
