:root {
  color-scheme: light;
  --paper: #fffaf1;
  --surface: #ffffff;
  --ink: #20302c;
  --muted: #66736f;
  --line: #d9e0dc;
  --teal: #1e6f64;
  --teal-dark: #124a43;
  --mint: #dff0e8;
  --sun: #ffe08a;
  --coral: #f08a73;
  --danger: #b34835;
  --shadow: 0 12px 32px rgba(32, 48, 44, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(255, 224, 138, 0.26), transparent 220px),
    var(--paper);
  color: var(--ink);
  font-family:
    -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", "Noto Sans JP",
    sans-serif;
  -webkit-tap-highlight-color: rgba(30, 111, 100, 0.18);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
  touch-action: manipulation;
}

.app-shell {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 44px;
}

.child-shell {
  width: min(760px, calc(100% - 28px));
}

.child-switch-panel {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.child-switch-button {
  min-height: 58px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--teal-dark);
  font-size: 1.12rem;
  font-weight: 800;
}

.child-switch-button.active {
  border-color: var(--teal);
  background: var(--teal);
  color: #fff;
}

.child-total-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 12px;
  border: 1px solid var(--teal);
  border-radius: 8px;
  background: #f4fbf7;
  box-shadow: var(--shadow);
  padding: 16px;
}

.child-total-card span {
  color: var(--teal-dark);
  font-weight: 800;
}

.child-total-card strong {
  color: var(--teal-dark);
  font-size: clamp(1.5rem, 5vw, 2.2rem);
  line-height: 1;
  white-space: nowrap;
}

.app-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.header-actions {
  display: flex;
  align-items: center;
  justify-content: end;
  gap: 10px;
  flex-wrap: wrap;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--teal);
  font-size: 0.82rem;
  font-weight: 700;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(2rem, 5vw, 3.3rem);
  line-height: 1.05;
}

h2 {
  font-size: 1.12rem;
}

.today-badge,
.local-note,
.summary-box,
.tool-panel,
.tool-strip,
.records-section {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.86);
  box-shadow: var(--shadow);
}

.today-badge {
  min-width: 128px;
  padding: 10px 12px;
  border-radius: 999px;
  text-align: center;
  color: var(--teal-dark);
  font-weight: 700;
}

.header-refresh {
  min-width: 86px;
}

.local-note {
  border-radius: 8px;
  padding: 12px 14px;
  color: var(--muted);
  font-size: 0.94rem;
}

.local-note.warning-note,
.startup-error {
  border-color: #d4a62c;
  background: #fff7dc;
  color: #73500b;
}

.startup-error {
  border: 1px solid #d4a62c;
  border-radius: 8px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
  padding: 12px 14px;
  font-weight: 700;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
  margin: 18px 0;
}

.child-entry-form {
  margin: 18px 0;
}

.preset-panel {
  margin-top: 18px;
  padding-bottom: 14px;
}

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

.preset-button {
  display: grid;
  gap: 4px;
  min-height: 62px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 10px;
  text-align: left;
}

.preset-button strong {
  overflow-wrap: anywhere;
}

.preset-button span {
  color: var(--teal-dark);
  font-size: 0.9rem;
  font-weight: 800;
}

.preset-button:hover {
  border-color: var(--teal);
  background: #f4fbf7;
}

.summary-box {
  min-height: 104px;
  border-radius: 8px;
  padding: 16px;
  display: grid;
  align-content: space-between;
}

.summary-box span {
  color: var(--muted);
  font-size: 0.92rem;
}

.summary-box strong {
  font-size: clamp(1.35rem, 3vw, 2rem);
  line-height: 1.1;
}

.summary-box.primary {
  background: var(--teal);
  color: #fff;
  border-color: var(--teal);
}

.summary-box.primary span {
  color: rgba(255, 255, 255, 0.78);
}

.work-area {
  display: grid;
  grid-template-columns: minmax(280px, 0.95fr) minmax(320px, 1.05fr);
  gap: 16px;
  align-items: start;
}

.tool-panel,
.tool-strip,
.records-section {
  border-radius: 8px;
}

.tool-panel {
  padding: 18px;
}

.panel-head,
.records-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.field,
.compact-field {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.field input,
.field select,
.compact-field input,
.compact-field select {
  min-height: 48px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fff;
  color: var(--ink);
  font-size: 16px;
}

.field input:focus,
.field select:focus,
.compact-field input:focus,
.compact-field select:focus {
  outline: 3px solid rgba(30, 111, 100, 0.18);
  border-color: var(--teal);
}

.entry-form {
  display: grid;
  gap: 14px;
}

.item-manager {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfb;
  overflow: hidden;
}

.item-manager summary {
  min-height: 48px;
  padding: 12px 14px;
  color: var(--teal-dark);
  cursor: pointer;
  font-weight: 800;
}

.item-manager-grid {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) 120px auto auto;
  gap: 10px;
  align-items: end;
  border-top: 1px solid var(--line);
  padding: 12px;
}

.child-select {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  border: 0;
  margin: 0;
  padding: 0;
}

.child-select legend {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.child-option {
  position: relative;
}

.child-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.child-option span {
  display: grid;
  min-height: 54px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--teal-dark);
  font-size: 1.06rem;
  font-weight: 800;
}

.child-option input:checked + span {
  border-color: var(--teal);
  background: var(--teal);
  color: #fff;
}

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

.calculated-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-radius: 8px;
  background: #f7f5ec;
  padding: 14px;
  font-weight: 700;
}

.calculated-line output {
  font-size: 1.3rem;
  color: var(--teal-dark);
}

.main-button,
.secondary-button,
.text-button,
.small-button {
  border: 0;
  border-radius: 8px;
  min-height: 48px;
  padding: 10px 14px;
  font-weight: 700;
}

.large-button {
  min-height: 60px;
  font-size: 1.12rem;
}

.main-button {
  background: var(--teal);
  color: #fff;
}

.main-button:hover {
  background: var(--teal-dark);
}

.secondary-button {
  background: var(--mint);
  color: var(--teal-dark);
}

.secondary-button:hover {
  background: #cbe5da;
}

.text-button,
.small-button {
  background: transparent;
  color: var(--teal);
}

.text-button:hover,
.small-button:hover {
  background: var(--mint);
}

.small-button.danger {
  color: var(--danger);
}

.danger-button {
  color: var(--danger);
}

.parent-panel {
  display: grid;
  gap: 14px;
}

.child-name-editor {
  display: grid;
  gap: 10px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 14px;
}

.settlement-actions,
.export-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.tool-strip {
  display: flex;
  align-items: end;
  gap: 12px;
  margin: 16px 0;
  padding: 14px;
}

.compact-field {
  min-width: 150px;
}

.compact-field.grow {
  flex: 1 1 220px;
}

.records-section {
  padding: 18px;
}

.records-head p {
  color: var(--muted);
  font-weight: 700;
}

.records-list {
  display: grid;
  gap: 10px;
}

.record-row {
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr) minmax(92px, auto) auto;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-left: 6px solid var(--coral);
  border-radius: 8px;
  background: #fff;
  padding: 12px;
}

.read-only-row {
  grid-template-columns: minmax(0, 1fr) minmax(92px, auto) auto;
}

.compact-records {
  box-shadow: none;
}

.record-row.settled {
  border-left-color: var(--teal);
  background: #fbfdfb;
}

.record-check input {
  width: 20px;
  height: 20px;
  accent-color: var(--teal);
}

.record-main {
  min-width: 0;
}

.record-title {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 6px;
}

.record-title strong {
  min-width: 0;
  overflow-wrap: anywhere;
}

.status-pill {
  border-radius: 999px;
  padding: 4px 8px;
  background: #fff1d2;
  color: #7c4f04;
  font-size: 0.78rem;
  font-weight: 700;
}

.child-pill {
  border-radius: 999px;
  padding: 4px 8px;
  background: #eaf4f1;
  color: var(--teal-dark);
  font-size: 0.78rem;
  font-weight: 800;
}

.status-pill.settled {
  background: var(--mint);
  color: var(--teal-dark);
}

.record-meta,
.settlement-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  color: var(--muted);
  font-size: 0.9rem;
}

.record-total {
  color: var(--ink);
  font-size: 1.14rem;
  font-weight: 800;
  text-align: right;
  white-space: nowrap;
}

.record-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: end;
  gap: 4px;
}

.empty-state {
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 28px 16px;
  color: var(--muted);
  text-align: center;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%) translateY(20px);
  max-width: min(92vw, 460px);
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  padding: 12px 16px;
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 180ms ease,
    transform 180ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 860px) {
  .summary-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .work-area {
    grid-template-columns: 1fr;
  }

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

  .export-actions {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 620px) {
  .app-shell {
    width: min(100% - 20px, 1120px);
    padding-top: 18px;
  }

  .app-header {
    align-items: start;
    flex-direction: column;
  }

  .header-actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    width: 100%;
  }

  .today-badge {
    width: 100%;
  }

  .header-actions .today-badge {
    width: auto;
  }

  .child-total-card {
    align-items: start;
    flex-direction: column;
  }

  .summary-grid,
  .field-row,
  .item-manager-grid,
  .child-select,
  .child-switch-panel,
  .preset-grid,
  .export-actions {
    grid-template-columns: 1fr;
  }

  .record-row {
    grid-template-columns: 30px minmax(0, 1fr);
  }

  .record-total,
  .record-actions {
    grid-column: 2;
    justify-self: stretch;
    text-align: left;
  }

  .record-actions {
    justify-content: start;
  }

  .read-only-row {
    grid-template-columns: 1fr;
  }

  .read-only-row .record-total,
  .read-only-row .record-actions {
    grid-column: 1;
  }
}

@media (min-width: 768px) and (max-width: 1180px) {
  .app-shell {
    width: min(100% - 40px, 1040px);
  }

  .tool-panel {
    padding: 22px;
  }

  .main-button,
  .secondary-button,
  .text-button,
  .small-button {
    min-height: 52px;
  }
}

@media print {
  body {
    background: #fff;
  }

  .entry-form,
  .parent-panel,
  .tool-strip,
  .toast,
  .record-actions,
  .record-check {
    display: none !important;
  }

  .app-shell {
    width: 100%;
    padding: 0;
  }

  .summary-box,
  .records-section,
  .local-note,
  .today-badge {
    box-shadow: none;
  }
}
