/* Family Piggy Bank — colours from spec 6.2 (checked by test/palette.test.js). No inline styles (CSP). */
:root {
  --bg: #FFF8F0; --card: #FFFFFF; --text: #2B2230; --muted: #5E5560; --line: #E7E1EA;
  --primary: #1F4FB8; --on-primary: #FFFFFF; --in: #1F4FB8; --out: #8C3409;
  --pending-bg: #FDE7A6; --pending-fg: #4A3500; --approved-bg: #1F4FB8; --approved-fg: #FFFFFF; --rejected-bg: #8C3409; --rejected-fg: #FFFFFF;
  --closed: #5E5560; --track: #E7E1EA; --focus: #1F4FB8;
  --msg-good: #E6EDFA; --msg-bad: #FBEADF; --msg-money: #FFF1CC; --disabled-bg: #E7E1EA; --disabled-fg: #4F4752;
  --toast-bg: #2B2230; --toast-fg: #FFFFFF;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1E1B24; --card: #2A2631; --text: #F4F0F6; --muted: #C3BAC8; --line: #45404D;
    --in: #9DBBFF; --out: #FFB27D; --closed: #C3BAC8; --track: #45404D; --focus: #9DBBFF;
    --msg-good: #263252; --msg-bad: #4A2E22; --msg-money: #4A3E1C; --disabled-bg: #45404D; --disabled-fg: #E4DEE8;
    --toast-bg: #F4F0F6; --toast-fg: #1E1B24; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1E1B24; --card: #2A2631; --text: #F4F0F6; --muted: #C3BAC8; --line: #45404D;
  --in: #9DBBFF; --out: #FFB27D; --closed: #C3BAC8; --track: #45404D; --focus: #9DBBFF;
  --msg-good: #263252; --msg-bad: #4A2E22; --msg-money: #4A3E1C; --disabled-bg: #45404D; --disabled-fg: #E4DEE8;
  --toast-bg: #F4F0F6; --toast-fg: #1E1B24; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans TC", "PingFang HK", sans-serif; }
a { color: var(--in); }
h1 { font-size: 1.25rem; margin: 0; }
h2 { font-size: 1.1rem; margin: 1rem 0 .5rem; }
p { margin: .4rem 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 0; background: var(--card); padding: .5rem 1rem; z-index: 10; }
.skip:focus { left: .5rem; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

header.top { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: calc(.75rem + env(safe-area-inset-top)) 1rem .75rem; background: var(--card); border-bottom: 2px solid var(--line); }
main { max-width: 34rem; margin: 0 auto; padding: 1rem 1rem 6rem; outline: none; }
main.loading { text-align: center; padding-top: 20vh; }
nav.bottom { position: fixed; bottom: 0; left: 0; right: 0; display: flex; justify-content: space-around; background: var(--card);
  border-top: 2px solid var(--line); padding-bottom: env(safe-area-inset-bottom); z-index: 2; }
nav.bottom a { flex: 1; text-align: center; min-height: 52px; display: flex; align-items: center; justify-content: center; color: var(--muted); text-decoration: none; font-size: .9rem; }
nav.bottom a.on { color: var(--in); font-weight: 700; }

.card { background: var(--card); border: 1.5px solid var(--line); border-radius: 16px; padding: 1rem; margin: .75rem 0; }
.cards { display: grid; gap: .75rem; }
.center { text-align: center; }
[hidden] { display: none !important; }   /* author display rules (.row, .btn) must not show hidden parts (fix D-07) */
.row { display: flex; gap: .75rem; flex-wrap: wrap; align-items: flex-end; margin: .5rem 0; }
.row > * { flex: 1 1 8rem; }
.hint { color: var(--muted); font-size: .9rem; }
.label { color: var(--muted); margin-bottom: 0; }
.balance { font-size: 2.6rem; font-weight: 800; margin: 0; }
.big-icon { font-size: 2rem; }
.form-error, .pin-error { color: var(--out); font-weight: 600; min-height: 1.2em; }
.notice { border-color: var(--pending-fg); }
.offline-banner { background: var(--pending-bg); color: var(--pending-fg); padding: .6rem 1rem; border-radius: 12px; font-weight: 600; }
.noscript { padding: 2rem; }

/* Buttons: at least 44 × 44 CSS px (NFR-A11Y-04) */
.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 48px; min-width: 44px; padding: .6rem 1rem; border-radius: 12px;
  font: inherit; font-weight: 700; border: 2px solid transparent; cursor: pointer; text-decoration: none; text-align: center; }
.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-outline { background: var(--card); color: var(--in); border-color: var(--in); }
.btn-no { background: var(--rejected-bg); color: var(--rejected-fg); }
.btn-no-outline { background: var(--card); color: var(--out); border-color: var(--out); }
.btn:disabled, .btn[disabled] { background: var(--disabled-bg); color: var(--disabled-fg); border-color: transparent; cursor: not-allowed; }
.btn-small { min-height: 44px; padding: .3rem .8rem; }
.btn-wide { width: 100%; margin-top: .5rem; }
.btn-link { background: none; border: 0; color: var(--in); font: inherit; font-weight: 600; text-decoration: underline; cursor: pointer; min-height: 44px; padding: 0 .4rem; }
.lang { min-width: 44px; }

/* Forms */
.form .field { margin: .75rem 0; }
.field label { display: block; font-weight: 600; margin-bottom: .25rem; }
input[type=text], input[type=password], input[type=url], input[type=number], input[type=date], input[type=month], select, textarea {
  width: 100%; min-height: 48px; padding: .6rem .75rem; font: inherit; color: var(--text); background: var(--card);
  border: 2px solid var(--muted); border-radius: 10px; }
textarea { min-height: 4.5rem; }
.amount-input { font-size: 1.6rem; font-weight: 700; letter-spacing: .02em; }
.check { display: flex; align-items: center; gap: .5rem; min-height: 44px; }
.check input { width: 24px; height: 24px; }

/* Money and status: colour + sign + arrow / icon + word (NFR-A11Y-03) */
.money { font-variant-numeric: tabular-nums; white-space: nowrap; }
.money-in { color: var(--in); }
.money-out { color: var(--out); }
.arrow { width: 16px; height: 12px; flex: none; }
.chip { display: inline-flex; align-items: center; gap: .25rem; padding: .15rem .6rem .15rem .3rem; border-radius: 999px; font-weight: 700; font-size: .85rem; white-space: nowrap; }
.chip-icon { width: 22px; height: 22px; }
.chip-pending { background: var(--pending-bg); color: var(--pending-fg); }
.chip-approved { background: var(--approved-bg); color: var(--approved-fg); }
.chip-rejected { background: var(--rejected-bg); color: var(--rejected-fg); }
.chip-closed { background: var(--card); color: var(--closed); border: 1.5px solid var(--closed); }
.entries { list-style: none; padding: 0; margin: 0; }
.entry { display: flex; align-items: center; gap: .6rem; background: var(--card); border: 1.5px solid var(--line); border-radius: 12px; padding: .6rem .75rem; margin: .5rem 0; min-height: 52px; }
.entry .amt { font-weight: 700; min-width: 5.5rem; }
.entry .desc { flex: 1; display: flex; flex-direction: column; min-width: 0; overflow-wrap: anywhere; }
.entry .actions { display: flex; gap: .25rem; flex-wrap: wrap; }
.message { padding: .75rem 1rem; border-radius: 12px; font-weight: 600; margin: .5rem 0; }
.message-approved, .message-goal_reached, .message-request_sent { background: var(--msg-good); }
.message-rejected, .message-not_enough { background: var(--msg-bad); }
.message-money_in { background: var(--msg-money); }

/* Goal */
.goal h2 { margin-top: 0; }
.bar { height: 14px; background: var(--track); border-radius: 7px; overflow: hidden; margin: .5rem 0; }
.bar .fill { display: block; height: 100%; width: 0; background: var(--primary); border-radius: 7px; }
:root[data-theme="dark"] .bar .fill { background: var(--in); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .bar .fill { background: var(--in); } }
.icons { display: flex; flex-wrap: wrap; gap: .5rem; }
.icon-btn { width: 52px; height: 52px; border-radius: 12px; border: 2px solid var(--line); background: var(--card); font-size: 1.5rem; cursor: pointer; padding: 4px; }
.icon-btn.on { border-color: var(--in); border-width: 3px; }
.icon-btn .piggy svg { width: 40px; height: 40px; }

/* Piggy */
.piggy { display: flex; justify-content: center; }
.piggy svg { width: 180px; height: 180px; }
.profile .piggy svg, .child-card .piggy svg, .req-head .piggy svg { width: 64px; height: 64px; }
.about .piggy svg { width: 80px; height: 80px; }
.pig-deposit .pig-coin { animation: coin 1s ease-in both; }
.pig-deposit, .pig-celebrate { animation: bounce .9s ease-out 1; }
.pig-celebrate .pig-confetti { animation: pop .9s ease-out both; transform-origin: 120px 120px; }
.pig-waiting .pig-bubble { animation: pulse 1.2s ease-in-out 2; transform-origin: 214px 27px; }
.pig-happy .pig-eyes { animation: blink 5s infinite; transform-origin: 120px 112px; }
.pig-sleep .pig-z { animation: float 2.4s ease-in-out infinite; }
@keyframes coin { from { transform: translateY(-24px); opacity: 0; } 60% { opacity: 1; } to { transform: translateY(26px); opacity: 0; } }
@keyframes bounce { 0%, 100% { transform: translateY(0); } 40% { transform: translateY(-8px); } }
@keyframes pop { from { transform: scale(.4); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes pulse { 50% { transform: scale(1.12); } }
@keyframes blink { 0%, 96%, 100% { transform: scaleY(1); } 98% { transform: scaleY(.1); } }
@keyframes float { 50% { transform: translateY(-4px); } }
@media (prefers-reduced-motion: reduce) { .piggy *, .piggy svg, .pig * { animation: none !important; } }

/* Sign-in */
.profiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(9rem, 1fr)); gap: .75rem; }
.profile { display: flex; flex-direction: column; align-items: center; gap: .3rem; padding: 1rem .5rem; background: var(--card); color: var(--text);
  border: 2px solid var(--line); border-radius: 16px; font: inherit; cursor: pointer; min-height: 44px; }
.pname { font-weight: 700; font-size: 1.1rem; }
.pin-wrap { max-width: 20rem; margin: 0 auto; }
.pin-dots { display: flex; justify-content: center; gap: .6rem; margin: 1rem 0 .25rem; min-height: 20px; }
.dot { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--text); }
.dot.on { background: var(--text); }
.pin-pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: .6rem; padding: .25rem; border-radius: 16px; }
.key { min-height: 60px; font: inherit; font-size: 1.5rem; font-weight: 700; border-radius: 14px; border: 2px solid var(--line); background: var(--card); color: var(--text); cursor: pointer; }
.key-ok { font-size: 1.1rem; }
.key-icon { width: 28px; height: 20px; }

/* Parent */
.child-card { display: flex; align-items: center; gap: 1rem; color: var(--text); text-decoration: none; position: relative; }
.child-card h2 { margin: 0; }
.badge { position: absolute; top: .75rem; right: .75rem; min-width: 32px; height: 32px; padding: 0 .5rem; border-radius: 16px; background: var(--primary); color: var(--on-primary);
  font-weight: 800; display: flex; align-items: center; justify-content: center; }
.req-head { display: flex; gap: .75rem; align-items: center; }
.req-head h2 { margin: 0; }
.code { font-size: 2rem; font-weight: 800; letter-spacing: .15em; font-variant-numeric: tabular-nums; }
.statement { width: 100%; border-collapse: collapse; }
.statement th { text-align: left; font-weight: 600; padding: .4rem 0; }
.statement td { text-align: right; padding: .4rem 0; }
.statement tr.total th, .statement tr.total td { border-top: 2px solid var(--line); font-weight: 800; }
.audit { list-style: none; padding: 0; max-height: 50vh; overflow: auto; font-size: .9rem; }

/* Dialogs and toasts */
.modal-back { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); display: flex; align-items: flex-end; justify-content: center; z-index: 20; }
.modal { background: var(--card); color: var(--text); width: 100%; max-width: 32rem; max-height: 90vh; overflow: auto; border-radius: 20px 20px 0 0; padding: 1rem 1rem calc(1rem + env(safe-area-inset-bottom)); }
@media (min-width: 40rem) { .modal-back { align-items: center; } .modal { border-radius: 20px; } }
.modal-title { margin-top: 0; }
.toast { position: fixed; left: 50%; bottom: 5.5rem; transform: translateX(-50%); background: var(--toast-bg); color: var(--toast-fg); padding: .75rem 1.25rem;
  border-radius: 12px; font-weight: 600; z-index: 30; max-width: 90vw; }
