:root {
  --ink: #1a1814;
  --muted: #5f584f;
  --paper: #f4f0e8;
  --card: #fffcf7;
  --line: #e3dcd0;
  --green: #0c6b52;
  --amber: #8a5a12;
  --danger: #8f3a32;
  --shadow: 0 20px 50px rgba(40, 32, 20, 0.14);
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
}

body {
  background: #e6e0d6;
  color: var(--ink);
  font-family: "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}

button, input, textarea, select { font: inherit; color: inherit; }

button { cursor: pointer; }

a { color: inherit; }

#app {
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--paper);
}

.screen {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--paper);
}

.screen-body {
  flex: 1 0 auto;
  padding: 16px 16px calc(92px + env(safe-area-inset-bottom));
}

.num {
  font-family: Bahnschrift, "Segoe UI", sans-serif;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
}

.noscript { padding: 24px; }

.login {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--paper);
}

.login-hero {
  padding: calc(36px + env(safe-area-inset-top)) 24px 40px;
  background: var(--ink);
  color: #f4efe6;
}

.seal {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: #f4efe6;
  color: var(--ink);
  font-weight: 700;
}

.login-hero h1 {
  margin: 18px 0 0;
  font-size: 34px;
  line-height: 1.1;
  letter-spacing: -0.04em;
}

.login-hero p {
  margin: 10px 0 0;
  max-width: 18em;
  color: #d9d0c3;
}

.login-panel {
  flex: 1;
  margin-top: -18px;
  padding: 22px 20px calc(28px + env(safe-area-inset-bottom));
  border-radius: 22px 22px 0 0;
  background: var(--paper);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 14px;
}

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

.field input,
.field select,
.field textarea {
  width: 100%;
  appearance: none;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  padding: 13px 14px;
  font-size: 16px;
}

.field textarea {
  min-height: 96px;
  resize: vertical;
}

.field select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath d='M5 7.5 10 12.5 15 7.5' fill='none' stroke='%231a1814' stroke-width='1.6' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 18px;
  padding-right: 40px;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: 2px solid var(--ink);
  outline-offset: 1px;
  border-color: var(--ink);
}

.field-error {
  margin: -4px 0 12px;
  color: var(--danger);
  font-size: 13px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 48px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: 12px;
  text-decoration: none;
  font-size: 16px;
}

.btn-primary { background: var(--ink); color: #f6f3ec; }

.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-ghost {
  margin-top: 10px;
  border-color: var(--line);
  background: transparent;
  color: var(--ink);
}

.btn-line {
  border-color: var(--line);
  background: #fff;
  color: var(--ink);
  font-size: 14px;
}

.login-note,
.hint {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.home-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding-top: calc(8px + env(safe-area-inset-top));
}

.eyebrow {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.home-head h1,
.section-title {
  margin: 2px 0 0;
  font-size: 28px;
  line-height: 1.15;
  letter-spacing: -0.04em;
}

.section-title {
  margin: 22px 0 10px;
  font-size: 16px;
  letter-spacing: 0;
}

.avatar {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--ink);
  color: #f4efe6;
  text-decoration: none;
  font-size: 14px;
}

.list-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 16px;
}

.search { flex: 1; min-width: 0; }

.search input {
  width: 100%;
  height: 46px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  padding: 0 14px;
  font-size: 16px;
}

.search input:focus {
  outline: 2px solid var(--ink);
  outline-offset: 1px;
  border-color: var(--ink);
}

.search-btn,
.refresh-btn {
  display: inline-flex;
  align-items: center;
  flex: none;
  height: 46px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
}

.refresh-btn { display: none; }

.card-state { margin-top: 10px; }

.refresh-btn:disabled { opacity: 0.45; }

.pull {
  height: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  line-height: 36px;
  text-align: center;
}

.summary {
  display: grid;
  grid-template-columns: 0.7fr 1.3fr;
  gap: 12px;
  margin: 18px 0 16px;
  padding: 16px 18px;
  border-radius: 18px;
  background: var(--ink);
  color: #f6f3ec;
}

.summary span {
  display: block;
  color: #c9c0b4;
  font-size: 12px;
}

.summary strong {
  display: block;
  margin-top: 4px;
  font-size: clamp(22px, 6.4vw, 28px);
  font-weight: 600;
  letter-spacing: -0.04em;
}

.card {
  margin-bottom: 12px;
  padding: 16px;
  border: 1px solid rgba(28, 24, 18, 0.08);
  border-radius: 18px;
  background: var(--card);
}

.card-top,
.row-between,
.ledger-item,
.request-head,
.me-row,
.facts div {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.card-top {
  align-items: center;
}

.card-top .card-name {
  min-width: 0;
}

.card-top .pills {
  flex: none;
  margin-top: 0;
}

.card-name {
  margin: 0;
  font-size: 16px;
  line-height: 1.35;
}

.card-state {
  display: grid;
  place-items: center;
  min-height: 120px;
  color: var(--muted);
  text-align: center;
}

.card-state p { margin: 0; }

.card-id,
.sub {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.pills { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
.pills-start { justify-content: flex-start; margin-top: 10px; }

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 650;
  white-space: nowrap;
}

.pill-ok { background: #e5f3ee; color: var(--green); }
.pill-warn { background: #f8f1e2; color: var(--amber); }
.pill-run { background: #e7eef8; color: #1d4f91; }
.pill-danger { background: #f8ecea; color: var(--danger); }
.pill-muted { background: #eeeae4; color: var(--muted); }

.remain { margin-top: 16px; }
.remain span, .meter-label span { color: var(--muted); font-size: 12px; }

.remain strong {
  display: block;
  margin-top: 2px;
  font-size: 32px;
  font-weight: 600;
  line-height: 1.1;
}

.remain-ok { color: var(--green); }
.remain-low { color: var(--amber); }
.remain-empty { color: var(--danger); }

.meter {
  height: 6px;
  margin-top: 12px;
  overflow: hidden;
  border-radius: 99px;
  background: #eee7dc;
}

.meter span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--ink);
}

.meter-low span { background: #a16207; }
.meter-empty span { background: var(--danger); }

.meter-label,
.split {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
}

.card-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 14px;
}

.topbar {
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 2;
  padding: calc(6px + env(safe-area-inset-top)) 8px 6px;
  background: rgba(244, 240, 232, 0.94);
  backdrop-filter: blur(12px);
}

.topbar h1 {
  margin: 0;
  font-size: 16px;
  text-align: center;
}

.icon-btn {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 0;
  background: transparent;
  color: inherit;
  text-decoration: none;
}

.icon-btn svg, .tab svg { width: 22px; height: 22px; }

.hero-money .value {
  margin: 4px 0 0;
  font-size: clamp(32px, 10vw, 42px);
  font-weight: 600;
  line-height: 1.05;
}

.banner {
  margin: 12px 0;
  padding: 12px 14px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.55;
}

.banner p { margin: 0; }
.banner-warn { background: #f8f1e2; color: #6d4a10; }
.banner-danger { background: #f8ecea; color: #7a332d; }
.banner-ok { background: #e5f3ee; color: #0c6b52; }

.facts { margin: 8px 0 0; }
.facts div {
  align-items: center;
  min-height: 48px;
  border-top: 1px solid var(--line);
}
.facts dt { color: var(--muted); font-size: 13px; }
.facts dd { margin: 0; display: flex; align-items: center; gap: 8px; }

.copy-btn {
  min-height: 36px;
  padding: 0 10px;
  border: 0;
  border-radius: 999px;
  background: #f1ebe2;
  font-size: 12px;
}

.page-action { margin-top: 16px; }

.ledger { list-style: none; margin: 0; padding: 0; }
.ledger-item {
  align-items: center;
  padding: 12px 0;
  border-top: 1px solid var(--line);
}
.ledger-item strong { display: block; font-size: 15px; }
.ledger-item .sub { margin: 0; }
.plus { color: var(--green); font-weight: 650; }
.minus { font-weight: 650; }

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-bottom: 14px;
  padding: 4px;
  border-radius: 14px;
  background: #ebe4d8;
}

.tabs a {
  min-height: 40px;
  display: grid;
  place-items: center;
  border-radius: 11px;
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
}

.tabs a.active {
  background: var(--card);
  color: var(--ink);
  font-weight: 650;
}

.readonly {
  min-height: 48px;
  display: flex;
  align-items: center;
  padding: 0 14px;
  border-radius: 12px;
  background: #efeae1;
}

.request { margin-bottom: 12px; }
.request-head strong { font-size: 14px; }
.bm-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin: 10px 0 0;
  font-size: 14px;
}
.bm-line i { color: var(--muted); font-style: normal; }
.result { margin: 10px 0 0; font-size: 14px; }

.empty {
  padding: 36px 8px;
  text-align: center;
}
.empty h2 { margin: 0 0 8px; font-size: 18px; }
.empty p { margin: 0; color: var(--muted); }

.me-card { padding-top: 4px; padding-bottom: 4px; }
.me-row {
  align-items: center;
  min-height: 52px;
  border-top: 1px solid var(--line);
  font-size: 14px;
}
.me-card .me-row:first-child { border-top: 0; }
.me-row span { color: var(--muted); }
.me-row strong { text-align: right; word-break: break-all; }

.tabbar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  position: sticky;
  bottom: 0;
  z-index: 3;
  padding: 6px 8px calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid rgba(28, 24, 18, 0.08);
  background: rgba(255, 252, 247, 0.94);
  backdrop-filter: blur(12px);
}

.tab {
  min-height: 48px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--muted);
  text-decoration: none;
  font-size: 11px;
}

.tab.active { color: var(--ink); font-weight: 700; }

.toast {
  position: fixed;
  top: calc(14px + env(safe-area-inset-top));
  left: 50%;
  z-index: 50;
  max-width: calc(100vw - 32px);
  padding: 10px 14px;
  border-radius: 999px;
  background: var(--ink);
  color: #f6f3ec;
  font-size: 13px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transform: translateX(-50%) translateY(-8px);
  transition: opacity 160ms ease, transform 160ms ease;
}

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

:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

@media (min-width: 840px) {
  body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    min-height: 100dvh;
  }

  #app {
    width: 400px;
    height: min(844px, calc(100dvh - 48px));
    min-height: 0;
    overflow: hidden;
    border-radius: 28px;
    box-shadow: var(--shadow);
  }

  .screen,
  .login,
  .screen-login {
    height: 100%;
    min-height: 0;
  }

  .screen-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
    padding-bottom: 20px;
  }

  .refresh-btn { display: inline-flex; align-items: center; }
  .pull { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .toast { transition: none; }
}
