:root {
  --ink: #162029;
  --muted: #5d6b76;
  --line: #d8cfc3;
  --paper: rgba(255, 252, 248, 0.96);
  --bg0: #f3ebe1;
  --bg1: #e7eef4;
  --slate: #243746;
  --copper: #b86b3c;
  --copper-deep: #8f4f28;
  --income: #1f7a5a;
  --expense: #b86b3c;
  --warn: #b7811a;
  --danger: #b54141;
  --shadow: 0 12px 28px rgba(36, 55, 70, 0.08);
  --radius: 20px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  min-height: 100%;
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  background:
    radial-gradient(90% 55% at 0% 0%, rgba(184, 107, 60, 0.16), transparent 55%),
    radial-gradient(70% 45% at 100% 0%, rgba(36, 55, 70, 0.1), transparent 50%),
    linear-gradient(180deg, var(--bg0), var(--bg1) 48%, #eef3f7);
}

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

.app {
  width: min(720px, 100%);
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 14px 14px calc(18px + var(--safe-bottom));
  gap: 12px;
}

.hero {
  color: var(--ink);
  padding: 8px 4px 2px;
  animation: fade-up 0.4s ease both;
}

.hero-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  gap: 10px;
}

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

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  background: linear-gradient(180deg, #d08a57, var(--copper-deep));
  box-shadow: 0 8px 18px rgba(143, 79, 40, 0.22);
  animation: pulse-mark 2.8s ease-in-out infinite;
}

@keyframes pulse-mark {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.04); }
}

.brand {
  font-family: "Songti SC", "Noto Serif SC", "STSong", Georgia, serif;
  font-size: clamp(2rem, 8vw, 2.55rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.05;
  color: var(--slate);
}

.tagline {
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.95rem;
}

.hero-sum {
  margin-top: 16px;
  display: grid;
  gap: 10px;
  padding: 14px;
  border-radius: var(--radius);
  background: linear-gradient(145deg, #2a3d4d, #1c2a36);
  color: #f7f1ea;
  box-shadow: var(--shadow);
  animation: fade-up 0.45s ease 0.05s both;
}

.sum-main {
  display: grid;
  gap: 4px;
}

.sum-label {
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(247, 241, 234, 0.62);
}

.sum-main strong {
  font-family: "Songti SC", "Noto Serif SC", "STSong", Georgia, serif;
  font-size: clamp(1.8rem, 7vw, 2.3rem);
  font-variant-numeric: tabular-nums;
}

.sum-side {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.sum-side > div {
  display: grid;
  gap: 2px;
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.12);
}

.sum-side span {
  font-size: 0.75rem;
  color: rgba(247, 241, 234, 0.65);
}

.sum-side b {
  font-size: 1.05rem;
  font-variant-numeric: tabular-nums;
}

.badge {
  font-size: 0.72rem;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255,252,248,0.9);
  color: var(--muted);
  white-space: nowrap;
}

.badge.ok {
  color: #176349;
  border-color: #a8d8c2;
  background: rgba(31, 122, 90, 0.1);
}

.badge.warn {
  color: #8a6414;
  border-color: #e6cfa0;
  background: rgba(183, 129, 26, 0.12);
}

.composer, .day-strip, .ai-panel, .pin-card, .entry, .group-card {
  background: var(--paper);
  border: 1px solid rgba(216, 207, 195, 0.95);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.composer {
  padding: 14px;
  display: grid;
  gap: 10px;
  animation: fade-up 0.45s ease 0.08s both;
}

.type-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 4px;
  border-radius: 14px;
  background: #ece7df;
}

.type-btn {
  border: none;
  border-radius: 11px;
  padding: 10px;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, transform 0.15s ease;
}

.type-btn.active {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 2px 8px rgba(22, 32, 41, 0.08);
}

.type-btn:active { transform: scale(0.98); }

.amount-row {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 4px 2px;
}

.yen {
  font-family: "Songti SC", "Noto Serif SC", "STSong", Georgia, serif;
  font-size: 1.6rem;
  color: var(--copper);
}

.amount-input {
  width: 100%;
  border: none;
  background: transparent;
  font-size: 2rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  outline: none;
}

.amount-input::placeholder { color: #c4b8ab; }

.add-row {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 8px;
}

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

.field:focus, .select:focus {
  border-color: var(--copper);
  box-shadow: 0 0 0 3px rgba(184, 107, 60, 0.14);
}

.btn {
  border: none;
  border-radius: 12px;
  padding: 12px 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.15s ease, background 0.15s ease;
}

.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-primary {
  background: linear-gradient(180deg, #c57a49, var(--copper-deep));
  color: #fff;
}

.btn-ghost {
  background: #f3eee6;
  color: var(--slate);
  border: 1px solid #ddd2c4;
  padding: 8px 10px;
  font-size: 0.82rem;
}

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: none;
  padding: 6px 8px;
  font-size: 0.85rem;
}

.day-strip {
  padding: 12px 14px;
  display: grid;
  gap: 10px;
  animation: fade-up 0.45s ease 0.12s both;
}

.day-strip > div:first-child {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.muted { color: var(--muted); font-size: 0.86rem; }

.day-strip strong {
  font-variant-numeric: tabular-nums;
  font-size: 1.15rem;
}

.cats {
  display: grid;
  gap: 7px;
}

.cat-row {
  display: grid;
  grid-template-columns: 52px 1fr 56px;
  gap: 8px;
  align-items: center;
  font-size: 0.78rem;
  color: var(--muted);
}

.cat-bar {
  height: 7px;
  border-radius: 999px;
  background: #e8e0d4;
  overflow: hidden;
}

.cat-bar > i {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, #d08a57, #8f4f28);
  transition: width 0.55s ease;
}

.cat-row b {
  text-align: right;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 4px;
}

.section-head h2 {
  font-size: 0.92rem;
  color: var(--muted);
  font-weight: 650;
}

.list {
  display: grid;
  gap: 8px;
  margin-top: 8px;
}

.entry {
  padding: 12px 14px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: start;
  animation: fade-up 0.28s ease both;
}

.entry-title {
  font-weight: 600;
  line-height: 1.35;
  word-break: break-word;
}

.entry-meta {
  margin-top: 6px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  font-size: 0.72rem;
  padding: 3px 8px;
  border-radius: 999px;
  background: #f1ebe2;
  color: var(--muted);
  border: 1px solid #e2d8cb;
}

.entry-amount {
  font-family: "Songti SC", "Noto Serif SC", "STSong", Georgia, serif;
  font-size: 1.05rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.entry-amount.expense { color: var(--expense); }
.entry-amount.income { color: var(--income); }

.entry-actions {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
}

.empty {
  padding: 28px 16px;
  text-align: center;
  color: var(--muted);
  font-size: 0.92rem;
  background: var(--paper);
  border-radius: var(--radius);
  border: 1px dashed #d7cdc0;
}

.ai-panel {
  margin-top: auto;
  padding: 12px;
  display: grid;
  gap: 10px;
  position: sticky;
  bottom: calc(8px + var(--safe-bottom));
  animation: fade-up 0.45s ease 0.16s both;
}

.ai-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.ai-head h2 {
  font-family: "Songti SC", "Noto Serif SC", "STSong", Georgia, serif;
  font-size: 1.05rem;
}

.ai-log {
  max-height: 160px;
  overflow: auto;
  display: grid;
  gap: 8px;
  padding-right: 2px;
}

.bubble {
  padding: 10px 12px;
  border-radius: 14px;
  font-size: 0.9rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}

.bubble.user {
  background: #efe4d7;
  justify-self: end;
  max-width: 92%;
}

.bubble.bot {
  background: #fff;
  border: 1px solid var(--line);
  max-width: 96%;
}

.ai-compose {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.pin-overlay {
  position: fixed;
  inset: 0;
  background: rgba(36, 55, 70, 0.35);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 40;
  backdrop-filter: blur(6px);
}

.pin-card {
  width: min(360px, 100%);
  padding: 22px 18px;
  display: grid;
  gap: 12px;
}

.pin-card h2 {
  font-family: "Songti SC", "Noto Serif SC", "STSong", Georgia, serif;
  font-size: 1.35rem;
}

.pin-card p {
  color: var(--muted);
  font-size: 0.9rem;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--safe-bottom));
  transform: translateX(-50%) translateY(12px);
  background: rgba(22, 32, 41, 0.92);
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 0.85rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 50;
  max-width: 90vw;
}

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

.hidden { display: none !important; }

@keyframes fade-up {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

.accounts-app {
  animation: fade-up 0.35s ease both;
}

.accounts-hero {
  color: var(--ink);
  padding: 4px 4px 2px;
}

.accounts-nav {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.accounts-nav-label {
  font-size: 0.82rem;
  color: var(--muted);
  letter-spacing: 0.06em;
}

.accounts-brand {
  font-size: clamp(1.7rem, 7vw, 2.2rem);
}

.accounts-sum {
  margin-top: 14px;
}

.accounts-groups,
.accounts-wrap,
.account-composer {
  animation: fade-up 0.4s ease both;
}

.accounts-groups { display: grid; gap: 8px; }

.group-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.group-card {
  padding: 12px;
  display: grid;
  gap: 8px;
  animation: fade-up 0.28s ease both;
}

.group-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.group-balance {
  font-family: "Songti SC", "Noto Serif SC", "STSong", Georgia, serif;
  font-size: 1.15rem;
  font-variant-numeric: tabular-nums;
  color: var(--slate);
}

.account-entry .account-actions {
  gap: 4px;
}

.account-composer {
  padding: 14px;
  display: grid;
  gap: 10px;
}

@media (min-width: 860px) {
  .app:not(.accounts-app) {
    display: grid;
    grid-template-columns: 1.15fr 0.85fr;
    grid-template-rows: auto auto auto 1fr auto;
    gap: 14px 16px;
    padding: 22px 20px 28px;
    align-content: start;
  }
  .app:not(.accounts-app) .hero { grid-column: 1 / -1; }
  .app:not(.accounts-app) .composer { grid-column: 1; }
  .app:not(.accounts-app) .day-strip { grid-column: 1; }
  .app:not(.accounts-app) .ledger-wrap { grid-column: 1; }
  .app:not(.accounts-app) .ai-panel {
    grid-column: 2;
    grid-row: 2 / span 3;
    position: sticky;
    top: 18px;
    align-self: start;
    max-height: calc(100vh - 36px);
    max-height: calc(100dvh - 36px);
  }
  .ai-log { max-height: none; min-height: 240px; }

  .accounts-app {
    display: grid;
    grid-template-columns: 1.1fr 0.9fr;
    gap: 14px 16px;
    padding: 22px 20px 28px;
    align-content: start;
  }
  .accounts-hero { grid-column: 1 / -1; }
  .accounts-groups { grid-column: 1; }
  .accounts-wrap { grid-column: 1; }
  .account-composer {
    grid-column: 2;
    grid-row: 2 / span 2;
    position: sticky;
    top: 18px;
    align-self: start;
  }
}
