:root {
  color-scheme: light;
  --bg: #fff8ef;
  --bg-deep: #f7eadb;
  --card: rgba(255, 255, 255, 0.72);
  --card-strong: rgba(255, 255, 255, 0.9);
  --text: #2f241d;
  --muted: #8a7565;
  --line: rgba(111, 77, 51, 0.12);
  --orange: #ee8b35;
  --orange-dark: #cf6c1c;
  --orange-soft: #fff0df;
  --green: #32936f;
  --green-soft: #e6f6ef;
  --red: #de5b55;
  --red-soft: #fff0ef;
  --shadow: 0 20px 50px rgba(109, 72, 41, 0.12);
  --radius-xl: 28px;
  --radius-lg: 22px;
  --radius-md: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: Inter, ui-rounded, "SF Pro Rounded", "PingFang TC", "Noto Sans TC", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
  min-height: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(circle at 15% 10%, rgba(255, 193, 132, 0.26), transparent 28%),
    radial-gradient(circle at 85% 25%, rgba(255, 232, 202, 0.7), transparent 30%),
    linear-gradient(160deg, #fffaf4 0%, #fff5e9 48%, #f9eadb 100%);
  overflow-x: hidden;
}

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

button {
  color: inherit;
}

button,
select {
  cursor: pointer;
}

button:disabled,
input:disabled,
select:disabled,
textarea:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.88);
  color: var(--text);
  padding: 13px 14px;
  outline: none;
  transition: border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

textarea {
  resize: vertical;
  min-height: 92px;
  line-height: 1.6;
}

input:focus,
select:focus,
textarea:focus {
  border-color: rgba(238, 139, 53, 0.68);
  box-shadow: 0 0 0 4px rgba(238, 139, 53, 0.12);
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

.hidden {
  display: none !important;
}

.background-orb {
  position: fixed;
  width: 340px;
  height: 340px;
  border-radius: 50%;
  filter: blur(30px);
  opacity: 0.3;
  pointer-events: none;
  z-index: -1;
}

.orb-one {
  top: -130px;
  left: -100px;
  background: #ffc17f;
}

.orb-two {
  right: -130px;
  bottom: 10%;
  background: #f0d3a5;
}

.glass-card {
  border: 1px solid rgba(255, 255, 255, 0.72);
  background: var(--card);
  box-shadow: var(--shadow);
  backdrop-filter: blur(22px) saturate(130%);
  -webkit-backdrop-filter: blur(22px) saturate(130%);
  border-radius: var(--radius-xl);
}

.glass-card.compact {
  border-radius: 20px;
  box-shadow: 0 12px 30px rgba(109, 72, 41, 0.08);
}

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: calc(28px + var(--safe-top)) 20px calc(28px + var(--safe-bottom));
}

.auth-card {
  width: min(100%, 460px);
  padding: 28px;
}

.brand-lockup,
.header-brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
  border-radius: 20px;
  background: linear-gradient(145deg, #ffa85f, #e67b24);
  color: white;
  font-weight: 900;
  font-size: 1.5rem;
  box-shadow: 0 12px 24px rgba(231, 123, 36, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.55);
}

.brand-mark.small {
  width: 44px;
  height: 44px;
  border-radius: 15px;
  font-size: 1.1rem;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--orange-dark);
  font-size: 0.68rem;
  line-height: 1;
  letter-spacing: 0.16em;
  font-weight: 900;
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(1.55rem, 5vw, 2rem);
  line-height: 1.24;
}

h2 {
  margin-bottom: 0;
  font-size: 1.5rem;
}

h3 {
  margin-bottom: 0;
  font-size: 1.15rem;
}

.auth-intro {
  color: var(--muted);
  line-height: 1.7;
  margin: 22px 0;
}

.segmented-control {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 5px;
  padding: 5px;
  margin-bottom: 20px;
  border-radius: 16px;
  background: rgba(108, 76, 52, 0.07);
}

.segment {
  border: 0;
  border-radius: 12px;
  padding: 10px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
}

.segment.active {
  background: white;
  color: var(--orange-dark);
  box-shadow: 0 5px 16px rgba(84, 53, 31, 0.09);
}

.auth-form {
  display: grid;
  gap: 15px;
}

.primary-button,
.secondary-button,
.text-button,
.icon-button,
.avatar-button,
.dialog-close,
.prompt-chips button,
.nav-item {
  border: 0;
  transition: transform 150ms ease, box-shadow 150ms ease, background 150ms ease;
}

.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  padding: 11px 18px;
  border-radius: 15px;
  background: linear-gradient(145deg, #f7a152, #e57b26);
  color: white;
  font-weight: 900;
  box-shadow: 0 11px 24px rgba(226, 117, 31, 0.26), inset 0 1px 0 rgba(255, 255, 255, 0.5);
}

.primary-button:hover,
.secondary-button:hover,
.icon-button:hover,
.avatar-button:hover,
.prompt-chips button:hover {
  transform: translateY(-1px);
}

.primary-button:active,
.secondary-button:active,
.icon-button:active,
.avatar-button:active,
.prompt-chips button:active {
  transform: translateY(0) scale(0.985);
}

.secondary-button {
  min-height: 38px;
  padding: 8px 13px;
  border: 1px solid rgba(238, 139, 53, 0.22);
  border-radius: 13px;
  background: rgba(255, 247, 238, 0.9);
  color: var(--orange-dark);
  font-weight: 850;
}

.text-button {
  padding: 8px;
  background: transparent;
  color: var(--orange-dark);
  font-weight: 800;
}

.full {
  width: 100%;
}

.form-message {
  min-height: 1.2em;
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.5;
}

.form-message.error {
  color: var(--red);
}

.form-message.success {
  color: var(--green);
}

.app-shell {
  width: min(100%, 920px);
  min-height: 100vh;
  margin: 0 auto;
  padding: calc(18px + var(--safe-top)) 18px calc(108px + var(--safe-bottom));
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 2px 14px;
}

.avatar-button,
.icon-button {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border: 1px solid rgba(255, 255, 255, 0.78);
  background: rgba(255, 255, 255, 0.72);
  box-shadow: 0 8px 22px rgba(104, 67, 39, 0.1);
  backdrop-filter: blur(15px);
  -webkit-backdrop-filter: blur(15px);
}

.avatar-button {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  color: var(--orange-dark);
  font-weight: 900;
}

.icon-button {
  width: 40px;
  height: 40px;
  border-radius: 14px;
  color: var(--orange-dark);
  font-size: 1.2rem;
  font-weight: 900;
}

.book-switcher {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 13px 15px;
  margin-bottom: 18px;
}

.book-switcher > div:first-child {
  flex: 1;
  min-width: 0;
}

.book-switcher select {
  border: 0;
  padding: 3px 28px 3px 0;
  background-color: transparent;
  box-shadow: none;
  font-size: 1.04rem;
  font-weight: 900;
  text-overflow: ellipsis;
}

.book-actions {
  display: flex;
  gap: 8px;
}

.small-label {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
}

.page-container {
  min-height: 55vh;
}

.page {
  display: none;
  animation: pageIn 220ms ease;
}

.page.active {
  display: block;
}

@keyframes pageIn {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}

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

.summary-card {
  min-width: 0;
  padding: 15px 14px;
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, 0.7);
  box-shadow: 0 10px 26px rgba(89, 58, 35, 0.08);
}

.summary-card p {
  margin-bottom: 8px;
  font-size: 0.76rem;
  font-weight: 800;
  opacity: 0.72;
}

.summary-card strong {
  display: block;
  overflow: hidden;
  font-size: clamp(0.95rem, 4vw, 1.28rem);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.income-card {
  background: linear-gradient(145deg, rgba(231, 249, 241, 0.95), rgba(255, 255, 255, 0.78));
  color: #247858;
}

.expense-card {
  background: linear-gradient(145deg, rgba(255, 237, 234, 0.96), rgba(255, 255, 255, 0.78));
  color: #c64b45;
}

.balance-card {
  background: linear-gradient(145deg, rgba(255, 237, 212, 0.98), rgba(255, 255, 255, 0.8));
  color: #bd681e;
}

.ai-card,
.settings-card,
.chart-card {
  padding: 20px;
}

.ai-card {
  margin-bottom: 22px;
}

.section-heading,
.page-title-row,
.dialog-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 15px;
}

.section-heading {
  margin-bottom: 15px;
}

.status-dot {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 14px;
  background: var(--orange-soft);
  color: var(--orange-dark);
  font-size: 0.72rem;
  font-weight: 950;
}

.prompt-chips {
  display: flex;
  gap: 7px;
  overflow-x: auto;
  padding: 10px 0 12px;
  scrollbar-width: none;
}

.prompt-chips::-webkit-scrollbar {
  display: none;
}

.prompt-chips button {
  flex: 0 0 auto;
  padding: 8px 11px;
  border-radius: 999px;
  background: rgba(255, 239, 222, 0.9);
  color: var(--orange-dark);
  font-size: 0.78rem;
  font-weight: 800;
}

.list-heading {
  margin: 8px 2px 12px;
}

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

.transaction-item {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 13px 14px;
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.69);
  box-shadow: 0 9px 22px rgba(96, 63, 40, 0.07);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  cursor: pointer;
}

.transaction-icon {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 15px;
  background: rgba(255, 241, 226, 0.92);
  font-size: 1.35rem;
}

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

.transaction-main strong,
.transaction-main span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.transaction-main strong {
  margin-bottom: 4px;
  font-size: 0.92rem;
}

.transaction-main span,
.transaction-side span {
  color: var(--muted);
  font-size: 0.74rem;
}

.transaction-side {
  text-align: right;
}

.transaction-side strong {
  display: block;
  margin-bottom: 4px;
  font-size: 0.92rem;
}

.transaction-side strong.expense {
  color: var(--red);
}

.transaction-side strong.income {
  color: var(--green);
}

.empty-state {
  padding: 34px 20px;
  border: 1px dashed rgba(140, 102, 72, 0.18);
  border-radius: 20px;
  color: var(--muted);
  text-align: center;
  background: rgba(255, 255, 255, 0.36);
}

.page-title-row {
  margin: 6px 2px 16px;
}

.compact-button {
  min-height: 40px;
  padding: 8px 14px;
}

.filter-card {
  display: grid;
  grid-template-columns: 1.05fr 0.85fr 1fr;
  gap: 8px;
  padding: 10px;
  margin-bottom: 14px;
}

.filter-card input,
.filter-card select,
.month-input {
  min-width: 0;
  padding: 10px;
  font-size: 0.82rem;
}

.stats-summary {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.chart-card {
  margin-bottom: 14px;
}

.bar-chart {
  display: grid;
  gap: 13px;
}

.bar-row {
  display: grid;
  grid-template-columns: minmax(88px, 0.7fr) minmax(120px, 2fr) auto;
  align-items: center;
  gap: 10px;
}

.bar-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.82rem;
  font-weight: 800;
}

.bar-track {
  height: 11px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(107, 76, 52, 0.08);
}

.bar-fill {
  height: 100%;
  min-width: 3px;
  border-radius: inherit;
  background: linear-gradient(90deg, #f7a65c, #e67d2a);
}

.bar-fill.income {
  background: linear-gradient(90deg, #62bd98, #2f8c68);
}

.bar-value {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
}

.settings-card {
  margin-bottom: 14px;
}

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

.muted-text {
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.55;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.88rem;
}

.settings-row span {
  color: var(--muted);
}

.invite-block {
  margin-top: 16px;
  padding: 14px;
  border-radius: 16px;
  background: rgba(255, 242, 227, 0.72);
}

.invite-code-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 8px;
}

.invite-code-row code {
  overflow: hidden;
  font-size: 1rem;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-overflow: ellipsis;
}

.danger-zone {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

.danger-outline {
  border-color: rgba(222, 91, 85, 0.28);
  color: var(--red);
  background: rgba(255, 244, 243, 0.8);
}

.danger-text {
  color: var(--red);
}

.category-form {
  display: grid;
  grid-template-columns: 62px minmax(100px, 1fr) minmax(110px, 0.8fr) auto;
  gap: 8px;
  margin-bottom: 14px;
}

.category-form input,
.category-form select {
  min-width: 0;
}

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

.category-item {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 15px;
  background: rgba(255, 255, 255, 0.56);
  border: 1px solid rgba(112, 78, 52, 0.08);
}

.category-item .category-emoji {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 13px;
  background: var(--orange-soft);
  font-size: 1.2rem;
}

.category-meta {
  min-width: 0;
}

.category-meta strong,
.category-meta span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.category-meta span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.74rem;
}

.category-delete {
  border: 0;
  background: transparent;
  color: var(--red);
  font-weight: 900;
}

.protected-badge {
  padding: 5px 8px;
  border-radius: 999px;
  background: rgba(107, 76, 52, 0.07);
  color: var(--muted);
  font-size: 0.67rem;
  font-weight: 800;
}

.bottom-nav {
  position: fixed;
  z-index: 30;
  left: 50%;
  bottom: calc(12px + var(--safe-bottom));
  transform: translateX(-50%);
  width: min(calc(100% - 28px), 680px);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding: 7px;
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.77);
  box-shadow: 0 16px 38px rgba(76, 49, 29, 0.17);
  backdrop-filter: blur(26px) saturate(145%);
  -webkit-backdrop-filter: blur(26px) saturate(145%);
}

.nav-item {
  display: grid;
  justify-items: center;
  gap: 3px;
  padding: 8px 5px;
  border-radius: 17px;
  background: transparent;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 800;
}

.nav-icon {
  font-size: 1.08rem;
}

.nav-item.active {
  background: linear-gradient(145deg, #fff0df, #ffe4c5);
  color: var(--orange-dark);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.72);
}

.app-dialog {
  width: min(calc(100% - 28px), 520px);
  max-height: min(88vh, 760px);
  overflow-y: auto;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.85);
  border-radius: 26px;
  background: rgba(255, 250, 245, 0.96);
  color: var(--text);
  box-shadow: 0 30px 80px rgba(70, 43, 25, 0.28);
  backdrop-filter: blur(25px);
  -webkit-backdrop-filter: blur(25px);
}

.app-dialog::backdrop {
  background: rgba(68, 45, 29, 0.3);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
}

.app-dialog form {
  display: grid;
  gap: 15px;
  padding: 22px;
}

.small-dialog {
  width: min(calc(100% - 28px), 430px);
}

.dialog-heading {
  margin-bottom: 4px;
}

.dialog-close {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(107, 76, 52, 0.07);
  color: var(--muted);
  font-size: 1.4rem;
}

.type-toggle {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
  padding: 5px;
  border-radius: 16px;
  background: rgba(107, 76, 52, 0.07);
}

.type-toggle button {
  padding: 10px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  font-weight: 900;
}

.type-toggle button.active[data-type="expense"] {
  background: var(--red-soft);
  color: var(--red);
}

.type-toggle button.active[data-type="income"] {
  background: var(--green-soft);
  color: var(--green);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 9px;
  padding-top: 4px;
}

.code-input {
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-weight: 900;
}

.toast {
  position: fixed;
  z-index: 80;
  left: 50%;
  bottom: calc(95px + var(--safe-bottom));
  transform: translate(-50%, 20px);
  width: max-content;
  max-width: calc(100% - 36px);
  padding: 11px 15px;
  border-radius: 14px;
  background: rgba(54, 40, 31, 0.92);
  color: white;
  box-shadow: 0 12px 30px rgba(42, 28, 18, 0.25);
  font-size: 0.84rem;
  line-height: 1.45;
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}

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

.loading-overlay {
  position: fixed;
  z-index: 100;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 12px;
  background: rgba(255, 248, 239, 0.62);
  color: var(--orange-dark);
  font-weight: 900;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.spinner {
  width: 38px;
  height: 38px;
  border: 4px solid rgba(238, 139, 53, 0.18);
  border-top-color: var(--orange);
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@media (max-width: 650px) {
  .app-shell {
    padding-inline: 14px;
  }

  .summary-grid {
    gap: 7px;
  }

  .summary-card {
    padding: 13px 11px;
    border-radius: 17px;
  }

  .filter-card {
    grid-template-columns: 1fr 1fr;
  }

  .filter-card select:last-child {
    grid-column: 1 / -1;
  }

  .category-form {
    grid-template-columns: 58px 1fr;
  }

  .category-form select,
  .category-form button {
    grid-column: span 1;
  }
}

@media (max-width: 420px) {
  .auth-card {
    padding: 23px 18px;
  }

  .brand-mark {
    width: 52px;
    height: 52px;
  }

  .ai-card,
  .settings-card,
  .chart-card {
    padding: 17px;
  }

  .book-switcher {
    padding: 11px 12px;
  }

  .transaction-item {
    grid-template-columns: 42px minmax(0, 1fr) auto;
    gap: 9px;
    padding: 11px;
  }

  .transaction-icon {
    width: 42px;
    height: 42px;
  }

  .bar-row {
    grid-template-columns: 84px minmax(80px, 1fr) auto;
    gap: 7px;
  }

  .invite-code-row {
    grid-template-columns: 1fr auto;
  }

  .invite-code-row .icon-button {
    grid-column: 1 / -1;
    width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
