:root {
  --bg: #f7f6f1;
  --surface: #ffffff;
  --ink: #20241f;
  --muted: #74796f;
  --line: #e8e7df;
  --green: #316c4e;
  --green-dark: #24563d;
  --green-soft: #e7f1e9;
  --coral: #d96b5e;
  --coral-soft: #faece8;
  --blue: #4d7695;
  --blue-soft: #e9f1f6;
  --shadow: 0 18px 45px rgba(39, 49, 41, 0.1);
  --radius-lg: 28px;
  --radius-md: 18px;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background:
    radial-gradient(circle at 90% 2%, rgba(157, 191, 165, 0.2), transparent 24rem),
    var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", sans-serif;
  -webkit-font-smoothing: antialiased;
}

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

.app-shell { width: min(100% - 32px, 920px); margin: 0 auto; padding-bottom: 64px; }

.topbar {
  min-height: 78px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); font-weight: 800; text-decoration: none; letter-spacing: -0.02em; }
.brand-mark { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 12px 12px 12px 4px; background: var(--green); color: white; font-family: Georgia, serif; }
.today-date { margin: 0; color: var(--muted); font-size: 0.86rem; }

.hero-card {
  position: relative;
  overflow: hidden;
  padding: 31px 24px 24px;
  border: 1px solid rgba(49, 108, 78, 0.08);
  border-radius: var(--radius-lg);
  background: linear-gradient(145deg, #eff5eb 0%, #e4efdf 100%);
}

.hero-card::after { content: ""; position: absolute; width: 210px; height: 210px; right: -85px; top: -95px; border: 38px solid rgba(255, 255, 255, 0.28); border-radius: 50%; }
.hero-decoration { position: absolute; right: 25px; top: 25px; z-index: 1; font-size: 1.7rem; transform: rotate(8deg); }
.eyebrow { margin: 0 0 7px; color: var(--green); font-size: 0.76rem; font-weight: 800; letter-spacing: 0.13em; }
.hero-amount { margin: 0; font-size: clamp(2.35rem, 10vw, 4.25rem); font-weight: 850; letter-spacing: -0.06em; line-height: 1.08; }
.hero-caption { margin: 9px 0 24px; color: #62705f; font-size: 0.88rem; }

.primary-action, .submit-button {
  min-height: 50px;
  border: 0;
  border-radius: 15px;
  background: var(--green);
  color: #fff;
  font-weight: 750;
  box-shadow: 0 8px 18px rgba(49, 108, 78, 0.18);
  transition: transform 160ms ease, background 160ms ease;
}
.primary-action { position: relative; z-index: 1; width: 100%; font-size: 1rem; }
.primary-action span { margin-right: 4px; font-size: 1.25rem; }
.primary-action:hover, .submit-button:hover { background: var(--green-dark); }
.primary-action:active, .submit-button:active, .quick-button:active { transform: scale(0.98); }

.quick-actions { position: relative; z-index: 1; display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 12px; }
.quick-button { display: flex; min-width: 0; min-height: 67px; flex-direction: column; justify-content: center; align-items: center; gap: 4px; border: 1px solid rgba(49, 108, 78, 0.09); border-radius: 14px; background: rgba(255, 255, 255, 0.62); font-size: 0.75rem; font-weight: 700; transition: transform 150ms ease, background 150ms ease; }
.quick-button:hover { background: rgba(255, 255, 255, 0.88); }
.quick-button span:first-child { font-size: 1.25rem; }

.monthly-section, .records-section { margin-top: 34px; }
.section-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 15px; }
.section-heading h2 { margin: 0; font-size: 1.24rem; letter-spacing: -0.03em; }
.month-label, .record-count { color: var(--muted); font-size: 0.8rem; }
.summary-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.summary-card { display: flex; align-items: center; gap: 13px; min-width: 0; padding: 18px; border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--surface); }
.summary-icon { display: grid; flex: 0 0 auto; place-items: center; width: 38px; height: 38px; border-radius: 12px; font-weight: 900; }
.expense-summary .summary-icon { background: var(--coral-soft); color: var(--coral); }
.income-summary .summary-icon { background: var(--green-soft); color: var(--green); }
.summary-card p { margin: 0 0 4px; color: var(--muted); font-size: 0.76rem; }
.summary-card strong { display: block; overflow: hidden; font-size: clamp(0.95rem, 3.4vw, 1.25rem); text-overflow: ellipsis; white-space: nowrap; }

.records-list { overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--surface); }
.record-item { display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto; align-items: center; gap: 12px; padding: 15px; }
.record-item + .record-item { border-top: 1px solid var(--line); }
.record-icon { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 14px; background: #f4f3ee; font-size: 1.3rem; }
.record-info { min-width: 0; }
.record-name { margin: 0 0 5px; overflow: hidden; font-size: 0.92rem; font-weight: 750; text-overflow: ellipsis; white-space: nowrap; }
.record-meta { margin: 0; overflow: hidden; color: var(--muted); font-size: 0.72rem; text-overflow: ellipsis; white-space: nowrap; }
.record-amount { margin: 0; font-size: 0.93rem; font-weight: 800; white-space: nowrap; }
.record-amount.expense { color: var(--ink); }
.record-amount.income { color: var(--green); }
.record-amount.transfer { color: var(--blue); }
.delete-button { display: grid; place-items: center; width: 34px; height: 34px; border: 0; border-radius: 10px; background: transparent; color: #a3a79f; font-size: 1rem; }
.delete-button:hover { background: var(--coral-soft); color: var(--coral); }
.empty-state { padding: 50px 22px; text-align: center; }
.empty-state-icon { margin-bottom: 10px; font-size: 2rem; }
.empty-state h3 { margin: 0 0 7px; font-size: 1rem; }
.empty-state p { margin: 0; color: var(--muted); font-size: 0.82rem; line-height: 1.6; }

.data-section { margin-top: 28px; }
.data-panel { border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.data-panel summary { display: flex; min-height: 58px; align-items: center; justify-content: space-between; gap: 15px; color: #62685f; cursor: pointer; list-style: none; font-size: 0.86rem; font-weight: 700; }
.data-panel summary::-webkit-details-marker { display: none; }
.data-panel summary::after { content: "＋"; order: 3; color: #959a92; font-size: 1.05rem; font-weight: 400; }
.data-panel[open] summary::after { content: "−"; }
.data-panel summary > span { display: flex; align-items: center; gap: 8px; }
.data-panel summary > small { margin-left: auto; color: #a0a49d; font-size: 0.72rem; font-weight: 500; }
.data-panel-content { padding: 2px 0 18px; }
.data-panel-content > p { margin: 0 0 13px; color: var(--muted); font-size: 0.76rem; line-height: 1.6; }
.data-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; }
.data-button { display: flex; min-width: 0; min-height: 66px; align-items: center; gap: 10px; padding: 11px 13px; border: 1px solid var(--line); border-radius: 13px; background: rgba(255, 255, 255, 0.55); text-align: left; transition: background 150ms ease, border-color 150ms ease; }
.data-button:hover { border-color: #cfd8d0; background: var(--surface); }
.data-button > span:first-child { display: grid; flex: 0 0 auto; width: 30px; height: 30px; place-items: center; border-radius: 9px; background: #eeeee9; color: var(--green); font-weight: 850; }
.data-button > span:last-child { min-width: 0; }
.data-button strong, .data-button small { display: block; }
.data-button strong { margin-bottom: 3px; font-size: 0.77rem; }
.data-button small { overflow: hidden; color: var(--muted); font-size: 0.66rem; font-weight: 400; text-overflow: ellipsis; white-space: nowrap; }
.app-version { margin: 16px 0 0; color: #adb0aa; font-size: 0.67rem; letter-spacing: 0.06em; text-align: center; }

.sheet-backdrop { position: fixed; inset: 0; z-index: 10; background: rgba(24, 29, 25, 0.42); backdrop-filter: blur(3px); }
.entry-sheet { position: fixed; z-index: 11; left: 50%; bottom: 0; width: min(100%, 620px); max-height: calc(100vh - 24px); padding: 9px 20px calc(20px + env(safe-area-inset-bottom)); overflow-y: auto; border-radius: 26px 26px 0 0; background: var(--surface); box-shadow: var(--shadow); transform: translateX(-50%); }
.sheet-handle { width: 40px; height: 4px; margin: 0 auto 15px; border-radius: 10px; background: #d9dbd5; }
.sheet-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 17px; }
.sheet-header h2 { margin: 0; font-size: 1.35rem; }
.icon-button { width: 40px; height: 40px; border: 0; border-radius: 50%; background: #f2f2ee; color: #60665d; font-size: 1.5rem; line-height: 1; }

.type-switch { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; margin: 0 0 16px; padding: 5px; border: 0; border-radius: 14px; background: #f2f2ee; }
.type-switch label { cursor: pointer; }
.type-switch input { position: absolute; opacity: 0; pointer-events: none; }
.type-switch span { display: grid; min-height: 40px; place-items: center; border-radius: 10px; color: var(--muted); font-size: 0.86rem; font-weight: 700; }
.type-switch input:checked + span { background: var(--surface); color: var(--ink); box-shadow: 0 2px 8px rgba(25, 33, 27, 0.08); }
.type-switch input:focus-visible + span { outline: 2px solid var(--green); outline-offset: 2px; }

.amount-field { display: block; margin-bottom: 17px; }
.amount-field > span:first-child, .field > span { display: block; margin-bottom: 7px; color: #555c53; font-size: 0.76rem; font-weight: 750; }
.amount-input-wrap { display: flex; align-items: center; gap: 10px; border-bottom: 2px solid var(--ink); }
.amount-input-wrap b { font-size: 1.05rem; }
.amount-input-wrap input { min-width: 0; width: 100%; height: 60px; padding: 0; border: 0; outline: none; color: var(--ink); font-size: 2.4rem; font-weight: 800; letter-spacing: -0.04em; }
.amount-input-wrap input::placeholder { color: #c8cbc4; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 13px 11px; }
.field-wide { grid-column: 1 / -1; }
.field small { color: #989d95; font-weight: 500; }
.field input, .field select, .field textarea { width: 100%; min-height: 45px; padding: 10px 12px; border: 1px solid #dcddd7; border-radius: 11px; outline: none; background: #fbfbf8; color: var(--ink); }
.field textarea { min-height: 62px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(49, 108, 78, 0.1); }
.submit-button { width: 100%; margin-top: 18px; }

.toast { position: fixed; z-index: 20; left: 50%; bottom: calc(22px + env(safe-area-inset-bottom)); max-width: calc(100% - 40px); padding: 11px 17px; border-radius: 50px; background: #252b26; color: white; font-size: 0.84rem; opacity: 0; pointer-events: none; transform: translate(-50%, 16px); transition: opacity 180ms ease, transform 180ms ease; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
[hidden] { display: none !important; }
body.sheet-open { overflow: hidden; }

@media (min-width: 720px) {
  .app-shell { padding-bottom: 90px; }
  .topbar { min-height: 92px; }
  .hero-card { padding: 42px; }
  .primary-action { width: 210px; }
  .quick-actions { position: absolute; right: 36px; bottom: 34px; width: 330px; }
  .monthly-section, .records-section { margin-top: 42px; }
  .summary-card { padding: 22px; }
  .record-item { padding: 17px 20px; }
  .entry-sheet { bottom: 24px; border-radius: 26px; padding: 12px 28px 28px; }
}

@media (max-width: 430px) {
  .app-shell { width: min(100% - 24px, 920px); }
  .today-date { font-size: 0.76rem; }
  .summary-card { display: block; padding: 15px; }
  .summary-icon { width: 32px; height: 32px; margin-bottom: 10px; }
  .record-item { grid-template-columns: auto minmax(0, 1fr) auto; gap: 10px; }
  .delete-button { grid-column: 3; grid-row: 2; height: 24px; margin-top: -10px; }
  .record-amount { grid-column: 3; grid-row: 1; }
  .data-actions { grid-template-columns: 1fr; }
  .data-button { min-height: 60px; }
}

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