:root {
  --paper: #fff9e9;
  --paper-deep: #f6edcf;
  --ink: #293739;
  --muted: #6f7b78;
  --amber: #f5b94c;
  --amber-dark: #bb7623;
  --coral: #eb765f;
  --teal: #438f83;
  --mint: #bfe1c7;
  --blue: #7f9dd1;
  --purple: #a783be;
  --positive: #3e8d61;
  --negative: #c95049;
  --white: #fffef8;
  --line: #ddd4bd;
  --surface: #fffdf6;
  --shadow: 0 12px 30px rgba(72, 55, 31, .12);
  --touch-target: 44px;
  --radius: 20px;
  font-family: "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
  color: var(--ink);
  background: var(--paper);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; margin: 0; }
body {
  background:
    radial-gradient(circle at 12% 18%, rgba(245,185,76,.13) 0 2px, transparent 3px),
    radial-gradient(circle at 87% 72%, rgba(67,143,131,.1) 0 2px, transparent 3px),
    linear-gradient(145deg, #fffaf0, #f8efda);
  background-size: 48px 48px, 62px 62px, auto;
}
button, input, select, textarea { font: inherit; }
button, a, input, select { min-height: var(--touch-target); }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }
:focus-visible { outline: 3px solid #1b6f75; outline-offset: 3px; }

.paper-sky { position: fixed; inset: 0; overflow: hidden; pointer-events: none; z-index: -1; }
.doodle { position: absolute; color: rgba(126, 98, 47, .18); font-family: Georgia, serif; }
.doodle-sun { top: 5%; left: 6%; font-size: 74px; transform: rotate(-12deg); }
.doodle-cloud { top: 12%; right: 8%; font-size: 82px; }
.doodle-star { bottom: 7%; left: 12%; font-size: 60px; transform: rotate(18deg); }
#app { min-height: 100vh; }

.boot-card, .state-card { min-height: 220px; display: grid; place-content: center; justify-items: center; gap: 12px; color: var(--muted); text-align: center; }
.spinner { width: 32px; height: 32px; border: 4px solid rgba(67,143,131,.18); border-top-color: var(--teal); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.login-page { min-height: 100vh; display: grid; grid-template-columns: minmax(260px, 430px) minmax(320px, 480px); place-content: center; align-items: center; gap: clamp(32px, 7vw, 110px); padding: 36px; }
.house-illustration { filter: drop-shadow(0 20px 24px rgba(80,57,25,.14)); transform: rotate(-1.5deg); }
.roof { position: relative; width: 88%; margin: 0 auto -2px; padding: 72px 20px 28px; color: #fff9e8; text-align: center; font-size: clamp(28px, 4vw, 48px); font-weight: 900; letter-spacing: .08em; background: var(--coral); clip-path: polygon(50% 0, 100% 62%, 93% 100%, 7% 100%, 0 62%); text-shadow: 0 3px rgba(130,58,44,.28); }
.house-body { min-height: 210px; padding: 56px 36px 30px; background: #f4c967; border: 6px solid #fff2c8; border-radius: 10px 10px 28px 28px; display: flex; justify-content: space-around; align-items: flex-end; box-shadow: inset 0 -18px rgba(178,115,33,.12); }
.house-body span { display: grid; place-items: center; width: 86px; aspect-ratio: 1; font-size: 44px; background: #fff8df; border: 4px solid rgba(104,78,39,.22); border-radius: 50% 50% 12px 12px; }
.scrapbook-card { position: relative; background: rgba(255,254,248,.96); border: 2px solid rgba(83,72,49,.14); border-radius: 14px 26px 18px 24px; box-shadow: var(--shadow); }
.scrapbook-card::before { content: ""; position: absolute; top: -14px; left: 34%; width: 110px; height: 30px; background: rgba(246,206,118,.7); transform: rotate(-2deg); }
.login-card { padding: clamp(28px, 5vw, 52px); }
.eyebrow { margin: 0 0 10px; color: var(--amber-dark); font-size: 12px; font-weight: 800; letter-spacing: .13em; }
.login-card h1 { margin: 0; font-family: KaiTi, STKaiti, serif; font-size: clamp(42px, 6vw, 66px); line-height: 1; }
.login-lead { color: var(--muted); margin: 16px 0 28px; }
.form-stack { display: grid; gap: 16px; }
.form-stack label { display: grid; gap: 7px; color: #53615e; font-size: 14px; font-weight: 700; }
input, select, textarea { width: 100%; border: 2px solid #ddd4bd; border-radius: 12px; padding: 10px 13px; color: var(--ink); background: #fffdf6; }
select { appearance: none; padding-right: 36px; background-color: var(--surface); background-image: linear-gradient(45deg, transparent 50%, var(--teal) 50%), linear-gradient(135deg, var(--teal) 50%, transparent 50%); background-position: calc(100% - 16px) 50%, calc(100% - 11px) 50%; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; }
input:focus, select:focus, textarea:focus { border-color: var(--teal); }
.form-error { min-height: 20px; margin: -4px 0; color: var(--negative); font-size: 14px; }
.button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: var(--touch-target); border: 0; border-radius: 13px 17px 12px 16px; padding: 9px 18px; font-weight: 800; transition: transform .16s, box-shadow .16s; }
.button:hover { transform: translateY(-2px); }
.button-primary { color: #fff; background: var(--teal); box-shadow: 0 7px 0 #2d7068; }
.button-primary:active { transform: translateY(4px); box-shadow: 0 3px 0 #2d7068; }
.button-large { width: 100%; min-height: 52px; }
.button-ghost { color: var(--ink); background: #eee8d8; }
.button-danger { color: #fff; background: var(--negative); }
.button-small { min-height: 36px; padding: 6px 12px; font-size: 13px; }
.demo-logins { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 26px; padding-top: 18px; border-top: 1px dashed #cfc3a8; }
.demo-logins span { flex-basis: 100%; color: var(--muted); font-size: 12px; }
.demo-logins button { flex: 1; border: 1px solid #d7cbb2; border-radius: 12px; background: #fff9e9; }
.login-note { grid-column: 1 / -1; justify-self: center; margin: -8px 0 0; color: var(--muted); font-size: 12px; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 230px 1fr; }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 28px 18px; background: rgba(255,250,233,.9); border-right: 2px solid rgba(93,77,48,.1); backdrop-filter: blur(14px); }
.brand { display: flex; align-items: center; gap: 10px; margin: 0 8px 34px; font-family: KaiTi, STKaiti, serif; font-size: 25px; font-weight: 900; }
.brand-mark { display: grid; place-items: center; width: 42px; aspect-ratio: 1; border-radius: 14px 17px 12px 15px; background: var(--amber); transform: rotate(-4deg); }
.nav-list { display: grid; gap: 8px; }
.nav-button { width: 100%; display: flex; align-items: center; gap: 12px; padding: 10px 13px; border: 0; border-radius: 14px; color: var(--muted); background: transparent; text-align: left; font-weight: 700; }
.nav-button.active { color: #fff; background: var(--teal); box-shadow: 0 6px 0 #2d7068; }
.nav-icon { font-size: 20px; }
.sidebar-footer { position: absolute; bottom: 24px; left: 18px; right: 18px; }
.profile-chip { display: flex; align-items: center; gap: 10px; padding: 10px; border: 1px solid #ded3b9; border-radius: 16px; background: #fffaf0; }
.avatar { display: grid; place-items: center; width: 40px; aspect-ratio: 1; border-radius: 50%; background: var(--mint); font-size: 24px; }
.profile-chip strong, .profile-chip small { display: block; }
.profile-chip small { color: var(--muted); }
.logout-button { margin-left: auto; border: 0; background: transparent; color: var(--muted); font-size: 18px; }
.app-main { min-width: 0; padding: 26px clamp(20px, 4vw, 56px) 60px; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 20px; margin-bottom: 26px; }
.topbar h1 { margin: 0; font-family: KaiTi, STKaiti, serif; font-size: clamp(32px, 4vw, 50px); }
.topbar p { margin: 6px 0 0; color: var(--muted); }
.points-pill { display: flex; align-items: center; gap: 10px; min-height: 54px; padding: 8px 18px; border: 2px solid #ecc45e; border-radius: 30px 28px 32px 26px; background: #fff5c9; box-shadow: 0 5px 0 #e5c464; font-weight: 900; white-space: nowrap; }
.points-pill span { font-size: 24px; }
.content-grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 18px; }
.card { position: relative; padding: 20px; border: 1px solid rgba(80,68,43,.12); border-radius: var(--radius); background: rgba(255,254,248,.94); box-shadow: 0 7px 20px rgba(74,57,31,.08); }
.card h2, .card h3 { margin-top: 0; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; }
.card-head h2 { margin: 0; font-size: 20px; }
.metric-card { min-height: 150px; overflow: hidden; }
.metric-value { margin: 14px 0 4px; font-size: 34px; font-weight: 900; }
.metric-caption { color: var(--muted); font-size: 13px; }
.span-3 { grid-column: span 3; }.span-4 { grid-column: span 4; }.span-5 { grid-column: span 5; }.span-6 { grid-column: span 6; }.span-7 { grid-column: span 7; }.span-8 { grid-column: span 8; }.span-12 { grid-column: 1 / -1; }
.list { display: grid; gap: 10px; }
.list-row { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; padding: 12px; border-radius: 14px; background: #faf5e8; }
.list-row-main { flex: 1; min-width: 0; }
.list-row-main strong, .list-row-main small { display: block; }
.list-row-main small { margin-top: 3px; color: var(--muted); }
.status { display: inline-flex; align-items: center; min-height: 26px; padding: 3px 9px; border-radius: 20px; font-size: 12px; font-weight: 800; white-space: nowrap; }
.status-pending, .status-assigned, .status-submitted { color: #8e641b; background: #fff0b8; }
.status-approved, .status-fulfilled, .status-completed { color: #246748; background: #d9f1df; }
.status-rejected, .status-cancelled { color: #a53d39; background: #f9d8d3; }
.chip-row { display: flex; gap: 8px; overflow-x: auto; padding: 3px 0 9px; scrollbar-width: thin; }
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.compact-select { display: flex; align-items: center; gap: 6px; white-space: nowrap; color: var(--muted); font-size: 13px; }
.compact-select select { width: auto; min-width: 86px; min-height: 38px; padding: 0 32px 0 10px; border: 1px solid var(--line); border-radius: 10px; background-color: var(--surface); color: var(--ink); font-size: 13px; box-shadow: 0 2px 0 rgba(72,55,31,.06); }
.chip { flex: 0 0 auto; border: 1px solid #ded4bc; border-radius: 22px; padding: 7px 13px; background: #fffaf0; color: var(--muted); }
.chip.active { color: #fff; border-color: var(--teal); background: var(--teal); }
.task-grid, .store-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.task-card, .store-card { display: flex; flex-direction: column; min-height: 190px; padding: 17px; border: 2px solid color-mix(in srgb, var(--task-color, var(--amber)) 35%, white); border-radius: 18px 24px 17px 21px; background: #fffdf7; }
.task-card.is-filtered-out { display: none !important; }
.list-row.is-filtered-out { display: none !important; }
.task-card-icon, .store-card-icon { font-size: 30px; }
.task-card h3, .store-card h3 { margin: 10px 0 6px; }
.task-card p, .store-card p { color: var(--muted); font-size: 13px; }
.task-card-footer, .store-card-footer { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: auto; }
.point-reward { color: var(--positive); font-size: 18px; font-weight: 900; }
.point-cost { color: var(--amber-dark); font-weight: 900; }
.progress-track { height: 12px; overflow: hidden; border-radius: 20px; background: #ebe4d1; }
.progress-fill { height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--teal), #72b697); }
.ledger-positive { color: var(--positive); font-weight: 900; }.ledger-negative { color: var(--negative); font-weight: 900; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 11px 9px; border-bottom: 1px solid #e7dfcd; text-align: left; white-space: nowrap; }
th { color: var(--muted); font-size: 12px; }
.dialog-card { width: min(520px, calc(100% - 28px)); padding: 0; border: 0; border-radius: 22px; background: var(--white); box-shadow: 0 30px 80px rgba(31,37,35,.25); }
.dialog-card::backdrop { background: rgba(40,48,46,.42); backdrop-filter: blur(3px); }
.dialog-head, .dialog-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 20px; }
.dialog-head { border-bottom: 1px solid #e8e0ce; }.dialog-head h2 { margin: 0; }.dialog-actions { justify-content: flex-end; border-top: 1px solid #e8e0ce; }
.dialog-body { padding: 20px; }.icon-button { width: 42px; border: 0; border-radius: 50%; background: #f2ecde; font-size: 25px; }
.toast-region { position: fixed; z-index: 50; top: 18px; right: 18px; display: grid; gap: 10px; }
.toast { max-width: 360px; padding: 13px 17px; border-radius: 14px; color: #fff; background: var(--teal); box-shadow: var(--shadow); animation: slide-in .2s ease-out; }
.toast-error { background: var(--negative); }
@keyframes slide-in { from { transform: translateY(-10px); opacity: 0; } }
.mobile-nav { display: none; }

@media (max-width: 960px) {
  .login-page { grid-template-columns: minmax(300px, 520px); }
  .house-illustration { display: none; }
  .login-note { grid-column: auto; }
  .span-3 { grid-column: span 6; }.span-4, .span-5, .span-7, .span-8 { grid-column: span 6; }
}

@media (max-width: 820px) {
  .app-shell { display: block; padding-bottom: 78px; }
  .sidebar { display: none; }
  .app-main { padding: 22px 18px 42px; }
  .mobile-nav { position: fixed; z-index: 20; left: 10px; right: 10px; bottom: max(10px, env(safe-area-inset-bottom)); display: flex; justify-content: space-around; padding: 7px; border: 1px solid rgba(73,62,40,.14); border-radius: 22px; background: rgba(255,252,240,.94); box-shadow: 0 12px 36px rgba(54,45,28,.2); backdrop-filter: blur(16px); }
  .mobile-nav .nav-button { width: auto; min-width: 54px; display: grid; justify-items: center; gap: 1px; padding: 5px 8px; font-size: 10px; }
  .mobile-nav .nav-button.active { box-shadow: none; }
  .mobile-nav .nav-icon { font-size: 20px; }
  .admin-mobile-nav { justify-content: flex-start; overflow-x: auto; }
  .admin-mobile-nav .nav-button { flex: 0 0 58px; }
}

@media (max-width: 600px) {
  .login-page { padding: 18px; align-content: center; }
  .login-card { padding: 30px 22px; }
  .app-shell { display: block; padding-bottom: 78px; }
  .sidebar { display: none; }
  .app-main { padding: 20px 14px 34px; }
  .topbar { align-items: flex-start; }
  .topbar h1 { font-size: 34px; }
  .topbar p { font-size: 13px; }
  .points-pill { min-height: 46px; padding: 6px 12px; font-size: 13px; }
  .points-pill span { font-size: 18px; }
  .content-grid { gap: 12px; }
  .card-head { flex-wrap: wrap; align-items: flex-start; }
  .card-head > .toolbar { width: 100%; margin-top: 2px; }
  .toolbar { flex-wrap: wrap; align-items: center; justify-content: flex-start; gap: 8px; }
  .toolbar > .chip-row { flex: 1 1 100%; width: 100%; }
  .toolbar .compact-select { flex: 0 1 auto; }
  .compact-select select { min-height: 38px; max-width: 150px; }
  .list-row { align-items: flex-start; }
  .list-row-main { flex: 1 1 calc(100% - 56px); min-width: 0; }
  .list-row > .status { margin-left: auto; }
  .list-row > .button { margin-left: 52px; }
  .span-3, .span-4, .span-5, .span-6, .span-7, .span-8 { grid-column: span 12; }
  .metric-card { min-height: 120px; }
  .task-grid, .store-grid { grid-template-columns: 1fr; }
  .mobile-nav { position: fixed; z-index: 20; left: 10px; right: 10px; bottom: max(10px, env(safe-area-inset-bottom)); display: flex; justify-content: space-around; padding: 7px; border: 1px solid rgba(73,62,40,.14); border-radius: 22px; background: rgba(255,252,240,.94); box-shadow: 0 12px 36px rgba(54,45,28,.2); backdrop-filter: blur(16px); }
  .mobile-nav .nav-button { width: auto; min-width: 54px; display: grid; justify-items: center; gap: 1px; padding: 5px 8px; font-size: 10px; }
  .mobile-nav .nav-button.active { box-shadow: none; }
  .mobile-nav .nav-icon { font-size: 20px; }
  .admin-mobile-nav { justify-content: flex-start; overflow-x: auto; }
  .admin-mobile-nav .nav-button { flex: 0 0 58px; }
  .dialog-actions .button { flex: 1; }
  .toast-region { left: 14px; right: 14px; }.toast { max-width: none; }
}

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