:root {
  --bg: #f7f6f2;
  --surface: #ffffff;
  --surface-2: #fff8dc;
  --ink: #20232a;
  --muted: #67717f;
  --line: #dde2ea;
  --accent: #7c4dff;
  --accent-2: #ffd54f;
  --good: #17845b;
  --bad: #c2413d;
  --shadow: 0 16px 36px rgba(32, 35, 42, 0.09);
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", sans-serif;
}

body[data-theme="quest"] {
  --bg: #f2f7ec;
  --surface-2: #fff6cf;
  --accent: #2f7d32;
  --accent-2: #f2b705;
  --ink: #1f2a1f;
}

body[data-theme="piggy"] {
  --bg: #fff4f0;
  --surface-2: #eaf7ee;
  --accent: #de5f7c;
  --accent-2: #68b684;
  --ink: #30262a;
}

body[data-theme="family"] {
  --bg: #f5f7fa;
  --surface-2: #edf3f8;
  --accent: #2563a8;
  --accent-2: #efb04d;
  --ink: #223044;
}

body[data-theme="space"] {
  --bg: #0f172a;
  --surface: #17223b;
  --surface-2: #22345b;
  --ink: #f5f8ff;
  --muted: #b9c4d6;
  --line: #33466e;
  --accent: #5eead4;
  --accent-2: #f6d365;
  --good: #72e3a6;
  --bad: #ff8a8a;
  --shadow: 0 16px 36px rgba(0, 0, 0, 0.24);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1160px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 40px;
}

.app-header {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 20px;
  align-items: stretch;
  min-height: 160px;
  padding: 28px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.header-kitty {
  position: absolute;
  right: 268px;
  bottom: 18px;
  width: 86px;
  height: 86px;
  object-fit: contain;
  opacity: 0.96;
  transform: rotate(-3deg);
  pointer-events: none;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 0.86rem;
  font-weight: 800;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 10px;
  font-size: 2.35rem;
  letter-spacing: 0;
}

h2 {
  font-size: 1.35rem;
  letter-spacing: 0;
}

h3 {
  font-size: 1rem;
  letter-spacing: 0;
}

.header-copy {
  margin-bottom: 0;
  color: var(--muted);
}

.header-balance {
  min-width: 230px;
  display: grid;
  place-content: center;
  gap: 6px;
  padding: 20px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.header-balance span,
.metric-card span,
.metric-card small,
.record-item span,
.request-item span,
.goal-card small {
  color: var(--muted);
}

.header-balance strong {
  font-size: 2.35rem;
  color: var(--accent);
  letter-spacing: 0;
}

.header-reset {
  margin-top: 8px;
}

.theme-switcher,
.role-tabs,
.page-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 14px 2px 4px;
}

.theme-switcher button,
.role-tabs button,
.page-tabs button,
.ghost-button,
.mini-button {
  min-height: 40px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 8px;
}

.theme-switcher button,
.role-tabs button,
.page-tabs button {
  flex: 0 0 auto;
  padding: 9px 12px;
  font-weight: 700;
}

.theme-switcher button span {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  margin-right: 4px;
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--accent);
}

.theme-switcher .is-active,
.role-tabs .is-active,
.page-tabs .is-active {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--surface);
}

.page-grid {
  display: grid;
  gap: 16px;
  margin-top: 16px;
}

.hero-panel {
  display: grid;
  grid-template-columns: 170px 1fr;
  gap: 22px;
  align-items: center;
  min-height: 220px;
  padding: 30px;
  background: var(--surface);
  border-bottom: 6px solid var(--accent-2);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.theme-quest .hero-panel {
  border-bottom-color: var(--accent);
}

.theme-space .hero-panel {
  background: #141f36;
}

.hero-graphic {
  display: grid;
  place-items: center;
  width: 150px;
  height: 150px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 4.5rem;
}

.balance-number {
  font-size: 3rem;
  font-weight: 900;
  color: var(--accent);
  letter-spacing: 0;
}

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

.metric-card {
  min-height: 124px;
  display: grid;
  align-content: center;
  gap: 8px;
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.metric-card strong {
  font-size: 1.75rem;
  color: var(--accent);
}

.content-band,
.form-band {
  padding: 22px;
  background: color-mix(in srgb, var(--surface) 92%, var(--bg));
  border: 1px solid var(--line);
  border-radius: 8px;
}

.section-heading {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 14px;
}

.section-heading h2 {
  margin: 0;
}

.record-list,
.request-list,
.goal-grid,
.mom-tools {
  display: grid;
  gap: 10px;
}

.record-item,
.request-item {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
  min-height: 72px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.record-item div,
.request-item div {
  display: grid;
  gap: 4px;
}

.record-item b {
  color: var(--good);
  white-space: nowrap;
}

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

.smart-form label,
.tool-panel {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-weight: 700;
}

.smart-form input,
.smart-form select,
.tool-panel input,
.tool-panel select {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 8px;
}

.wide {
  grid-column: 1 / -1;
}

.primary-button,
.danger-button {
  min-height: 44px;
  padding: 10px 14px;
  border: 0;
  border-radius: 8px;
  font-weight: 800;
}

.primary-button {
  background: var(--accent);
  color: var(--surface);
}

.primary-button:disabled {
  cursor: default;
  opacity: 0.72;
  background: var(--surface-2);
  color: var(--muted);
}

.danger-button {
  background: var(--bad);
  color: #fff;
}

.ghost-button,
.mini-button {
  padding: 8px 12px;
  font-weight: 700;
}

.status-pill,
.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 5px 10px;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 800;
}

.status-pill,
.status-pending {
  color: #7a4d00;
  background: #fff0be;
}

.status-approved {
  color: #075f3f;
  background: #dff7e8;
}

.status-rejected {
  color: #8c211e;
  background: #ffe1df;
}

.request-action {
  align-items: stretch;
}

.action-row {
  display: flex !important;
  flex-direction: row;
  align-items: center;
}

.mom-tools {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.tool-panel {
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.tool-panel h3 {
  margin-bottom: 4px;
  color: var(--ink);
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  min-width: 820px;
  border-collapse: collapse;
  background: var(--surface);
  border-radius: 8px;
  overflow: hidden;
}

th,
td {
  padding: 13px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

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

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

.goal-card {
  display: grid;
  gap: 10px;
  min-height: 210px;
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.goal-submit {
  margin-top: 4px;
  width: 100%;
}

.goal-icon {
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  background: var(--surface-2);
  border-radius: 8px;
  font-size: 2rem;
}

.goal-icon img {
  width: 52px;
  height: 42px;
  object-fit: contain;
  display: block;
}

.goal-card h3,
.goal-card p {
  margin-bottom: 0;
}

.goal-edit-form {
  display: grid;
  gap: 8px;
}

.goal-edit-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

.goal-edit-form input {
  min-height: 40px;
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 8px;
  font-weight: 800;
}

.progress {
  position: relative;
  height: 12px;
  background: var(--surface-2);
  border-radius: 8px;
  overflow: hidden;
}

.progress span,
.progress i {
  position: absolute;
  inset: 0 auto 0 0;
  display: block;
  height: 100%;
}

.progress span {
  background: var(--accent);
  z-index: 1;
}

.progress i {
  inset: 0 auto auto 0;
  height: 100%;
  background: #ffd54f;
  z-index: 2;
  opacity: 0.95;
  border-radius: 8px;
}

.progress.is-over {
  box-shadow: 0 0 0 2px rgba(255, 213, 79, 0.25);
}

.empty-state {
  min-height: 74px;
  display: grid;
  place-items: center;
  color: var(--muted);
  background: var(--surface);
  border: 1px dashed var(--line);
  border-radius: 8px;
}

#toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(360px, calc(100% - 36px));
  padding: 12px 14px;
  background: var(--ink);
  color: var(--surface);
  border-radius: 8px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

#toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 820px) {
  .app-shell {
    width: min(100% - 20px, 1160px);
    padding-top: 10px;
  }

  .app-header,
  .hero-panel {
    grid-template-columns: 1fr;
  }

  h1 {
    font-size: 1.85rem;
  }

  .header-balance {
    min-width: 0;
  }

  .header-kitty {
    right: 18px;
    bottom: 18px;
    width: 64px;
    height: 64px;
    opacity: 0.55;
  }

  .metric-grid,
  .smart-form,
  .mom-tools,
  .goal-grid {
    grid-template-columns: 1fr;
  }

  .hero-graphic {
    width: 112px;
    height: 112px;
    font-size: 3.2rem;
  }

  .balance-number {
    font-size: 2.25rem;
  }

  .record-item,
  .request-item,
  .section-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .action-row {
    width: 100%;
  }

  .action-row button {
    flex: 1;
  }
}
