/* فونت وزیرمتن داخل خود برنامه است تا در ایران به Google Fonts وابسته نباشد (مجوز OFL: fonts/OFL.txt) */
@font-face { font-family: 'Vazirmatn'; src: url('/fonts/Vazirmatn-Regular.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Vazirmatn'; src: url('/fonts/Vazirmatn-SemiBold.woff2') format('woff2'); font-weight: 600; font-display: swap; }
@font-face { font-family: 'Vazirmatn'; src: url('/fonts/Vazirmatn-ExtraBold.woff2') format('woff2'); font-weight: 800; font-display: swap; }

:root {
  color-scheme: light;
  --bg: #f4f1ff;
  --surface: #ffffff;
  --ink: #2b2347;
  --muted: #7a7393;
  --line: #e7e2f7;
  --brand: #6d5dfc;
  --brand-ink: #ffffff;
  --gold: #f5b301;
  --ok: #16a34a;
  --ok-bg: #e8f8ee;
  --wait: #b45309;
  --wait-bg: #fff4dd;
  --bad: #dc2626;
  --bad-bg: #fdecec;
  --accent: var(--brand);
  --radius: 20px;
  --shadow: 0 4px 0 rgba(43, 35, 71, .06), 0 10px 24px rgba(43, 35, 71, .06);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: 'Vazirmatn', Tahoma, 'Segoe UI', sans-serif;
  background: radial-gradient(circle at 100% 0, #ffe9f5 0, transparent 40%), radial-gradient(circle at 0 30%, #e3f4ff 0, transparent 40%), var(--bg);
  background-attachment: fixed;
  color: var(--ink);
  min-height: 100vh;
  line-height: 1.7;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { margin: 0; line-height: 1.4; }

#app { max-width: 920px; margin: 0 auto; padding: 16px 16px calc(32px + env(safe-area-inset-bottom)); }

/* ---------- عناصر پایه ---------- */
.btn {
  border: 0; border-radius: 14px; padding: 10px 18px; font-weight: 600;
  background: var(--brand); color: var(--brand-ink);
  box-shadow: 0 3px 0 rgba(0, 0, 0, .15); transition: transform .08s;
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
}
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0, 0, 0, .15); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.ghost { background: var(--surface); color: var(--ink); box-shadow: 0 0 0 2px var(--line) inset; }
.btn.ok { background: var(--ok); }
.btn.bad { background: var(--bad); }
.btn.small { padding: 6px 12px; font-size: .9rem; border-radius: 10px; }
.btn.icon { padding: 8px 10px; }
.btn.block { width: 100%; }

.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.muted { color: var(--muted); }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.stack > * + * { margin-top: 12px; }
.center { text-align: center; }

.coin-pill {
  display: inline-flex; align-items: center; gap: 6px;
  background: #fff8db; color: #8a5a00; border: 2px solid #ffe08a;
  border-radius: 999px; padding: 4px 14px; font-weight: 800; white-space: nowrap;
}
.coin {
  display: inline-block; width: 1em; height: 1em; border-radius: 50%; vertical-align: -.12em;
  background: radial-gradient(circle at 35% 30%, #fff3b0 0 18%, #ffd23f 40%, #e9a100 100%);
  box-shadow: inset 0 0 0 .09em #c98a00;
}
.coin-pill.big { font-size: 1.4rem; padding: 6px 18px; }
.coin-pill.pop { animation: pop .5s; }

.avatar {
  width: 56px; height: 56px; border-radius: 50%;
  display: grid; place-items: center; font-size: 32px; flex: none;
  background: color-mix(in srgb, var(--c, var(--brand)) 22%, white);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--c, var(--brand)) 45%, white);
}
.avatar.lg { width: 96px; height: 96px; font-size: 58px; }
.avatar.sm { width: 40px; height: 40px; font-size: 22px; box-shadow: 0 0 0 3px color-mix(in srgb, var(--c, var(--brand)) 45%, white); }

.chip { display: inline-block; border-radius: 999px; padding: 2px 10px; font-size: .82rem; font-weight: 600; white-space: nowrap; }
.chip.pending { background: var(--wait-bg); color: var(--wait); }
.chip.approved { background: var(--ok-bg); color: var(--ok); }
.chip.rejected, .chip.cancelled { background: var(--bad-bg); color: var(--bad); }
.badge { background: var(--bad); color: #fff; border-radius: 999px; min-width: 22px; height: 22px; padding: 0 6px; font-size: .78rem; display: inline-grid; place-items: center; font-weight: 800; }

.empty { text-align: center; padding: 32px 16px; color: var(--muted); }
.empty .big { font-size: 48px; display: block; }

/* ---------- صفحه اصلی ---------- */
.hero { text-align: center; padding: 12px 0 20px; }
.hero h1 { font-size: 2rem; font-weight: 800; }
.hero .logo { font-size: 56px; display: block; animation: float 3s ease-in-out infinite; }
.kids-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.kid-card {
  border: 0; text-align: inherit; width: 100%;
  display: flex; align-items: center; gap: 16px; padding: 18px;
  background: var(--surface); border-radius: 24px; box-shadow: var(--shadow);
  border-bottom: 6px solid var(--c); transition: transform .12s;
}
.kid-card:hover { transform: translateY(-2px); }
.kid-card:active { transform: scale(.98); }
.kid-card h2 { font-size: 1.3rem; }
.parent-link { display: block; margin: 28px auto 0; }

/* ---------- صفحه کودک ---------- */
.topbar { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.kid-header {
  background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 60%, #6d5dfc));
  color: #fff; border-radius: 28px; padding: 20px; display: flex; align-items: center; gap: 16px; box-shadow: var(--shadow);
}
.kid-header .avatar { background: #fff; box-shadow: 0 0 0 5px rgba(255, 255, 255, .45); }
.kid-header h1 { font-size: 1.5rem; }
.kid-header .muted { color: rgba(255, 255, 255, .85); }

.tabs { display: flex; gap: 8px; margin: 16px 0; background: var(--surface); padding: 6px; border-radius: 18px; box-shadow: var(--shadow); overflow-x: auto; }
.tabs button { flex: 1; border: 0; background: transparent; border-radius: 14px; padding: 10px 12px; font-weight: 600; white-space: nowrap; display: inline-flex; gap: 6px; align-items: center; justify-content: center; }
.tabs button[aria-selected="true"] { background: var(--accent); color: #fff; }
.tabs.compact { overflow: visible; }
.tabs.compact button { position: relative; flex-direction: column; gap: 0; padding: 6px 4px; font-size: .85rem; line-height: 1.5; }
.tabs.compact .ti { font-size: 1.3rem; }
.tabs.compact .badge { position: absolute; top: 2px; left: 6px; }
.badge[hidden] { display: none; }

.progress { height: 14px; border-radius: 999px; background: var(--line); overflow: hidden; }
.progress > span { display: block; height: 100%; background: linear-gradient(90deg, var(--gold), #ffd25a); border-radius: inherit; transition: width .5s; }

.period { margin-top: 18px; }
.period-head { display: flex; align-items: center; gap: 8px; margin: 0 4px 8px; font-weight: 800; font-size: 1.1rem; }
.period-head .now { background: var(--accent); color: #fff; font-size: .75rem; padding: 1px 10px; border-radius: 999px; }
.period.current .tasks { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 50%, white), var(--shadow); }
.tasks { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }

.task {
  width: 100%; border: 0; background: transparent; text-align: inherit;
  display: flex; align-items: center; gap: 14px; padding: 14px 16px; min-height: 68px;
}
.task + .task { border-top: 1px solid var(--line); }
.task .check {
  width: 38px; height: 38px; border-radius: 12px; flex: none; display: grid; place-items: center; font-size: 22px;
  border: 3px solid var(--line); background: #fff; transition: all .2s;
}
.task .title { flex: 1; font-weight: 600; font-size: 1.05rem; }
.task .gain { font-weight: 800; color: #8a5a00; white-space: nowrap; }
.task.pending { background: var(--wait-bg); }
.task.pending .check { border-color: #f6c56b; background: #fff; }
.task.approved { background: var(--ok-bg); }
.task.approved .check { border-color: var(--ok); background: var(--ok); color: #fff; }
.task.approved .title { text-decoration: line-through; text-decoration-color: rgba(22, 163, 74, .5); }
.task.rejected { background: var(--bad-bg); }
.task.rejected .check { border-color: #f3a4a4; }
.task .status { font-size: .8rem; display: block; font-weight: 600; }
.task.pending .status { color: var(--wait); }
.task.approved .status { color: var(--ok); }
.task.rejected .status { color: var(--bad); }

/* ---------- فروشگاه ---------- */
.rewards-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
.reward { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 14px; text-align: center; display: flex; flex-direction: column; gap: 6px; }
.reward .icon { font-size: 48px; line-height: 1.2; }
.reward h3 { font-size: 1.05rem; }
.reward p { margin: 0; font-size: .85rem; color: var(--muted); flex: 1; }
.reward .cost { font-weight: 800; color: #8a5a00; }
.reward.locked .icon { filter: grayscale(.7); opacity: .7; }
.reward .need { font-size: .8rem; color: var(--muted); }

/* ---------- لیست‌ها ---------- */
.list { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; }
.list-item + .list-item { border-top: 1px solid var(--line); }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .title { font-weight: 600; }
.list-item .sub { font-size: .82rem; color: var(--muted); }
.list-item.inactive .title { color: var(--muted); text-decoration: line-through; }
.section-title { display: flex; align-items: center; gap: 8px; margin: 22px 4px 10px; font-size: 1.1rem; font-weight: 800; }
.delta-plus { color: var(--ok); font-weight: 800; white-space: nowrap; }
.delta-minus { color: var(--bad); font-weight: 800; white-space: nowrap; }

/* ---------- پنل والد ---------- */
.kid-picker { display: flex; flex-wrap: wrap; gap: 8px; }
.kid-picker button { border: 0; background: var(--surface); border-radius: 999px; padding: 6px 14px 6px 8px; display: inline-flex; align-items: center; gap: 8px; box-shadow: var(--shadow); font-weight: 600; white-space: nowrap; }
.kid-picker button[aria-pressed="true"] { background: var(--c); color: #fff; }
.kid-picker .avatar.sm { width: 32px; height: 32px; font-size: 18px; box-shadow: none; background: #fff; }

.switch { position: relative; width: 48px; height: 28px; flex: none; }
.switch input { opacity: 0; width: 100%; height: 100%; margin: 0; position: absolute; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: #d6d1e6; transition: .2s; }
.switch span::after { content: ''; position: absolute; top: 3px; right: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: .2s; box-shadow: 0 1px 3px rgba(0, 0, 0, .2); }
.switch input:checked + span { background: var(--ok); }
.switch input:checked + span::after { right: 23px; }

.pin-input { font-size: 2rem; letter-spacing: .6em; text-align: center; direction: ltr; }

/* ---------- فرم و مودال ---------- */
dialog { border: 0; border-radius: 24px; padding: 0; width: min(520px, calc(100vw - 32px)); max-height: calc(100vh - 32px); box-shadow: 0 20px 60px rgba(0, 0, 0, .25); color: var(--ink); }
dialog::backdrop { background: rgba(43, 35, 71, .45); }
dialog form, dialog .dlg { padding: 20px; }
dialog h2 { font-size: 1.2rem; margin-bottom: 14px; }
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-weight: 600; margin-bottom: 6px; font-size: .92rem; }
.input { width: 100%; border: 2px solid var(--line); border-radius: 12px; padding: 10px 12px; background: #fff; outline: none; }
.input:focus { border-color: var(--brand); }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg span { display: inline-block; border: 2px solid var(--line); border-radius: 12px; padding: 6px 12px; font-weight: 600; font-size: .9rem; background: #fff; }
.seg input:checked + span { border-color: var(--brand); background: var(--brand); color: #fff; }
.seg input:focus-visible + span { outline: 3px solid color-mix(in srgb, var(--brand) 40%, white); }
.emoji-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 6px; }
.emoji-grid .seg span, .emoji-grid span { font-size: 24px; padding: 4px; text-align: center; display: block; }
.actions { display: flex; gap: 10px; justify-content: flex-start; margin-top: 18px; }
.error-text { color: var(--bad); font-size: .9rem; min-height: 1.4em; }

#toast {
  position: fixed; bottom: calc(24px + env(safe-area-inset-bottom)); left: 50%; transform: translate(-50%, calc(100% + 60px));
  background: var(--ink); color: #fff; padding: 12px 20px; border-radius: 16px; font-weight: 600;
  transition: transform .3s, visibility .3s; z-index: 50; max-width: calc(100vw - 32px); text-align: center; visibility: hidden;
}
#toast.show { transform: translate(-50%, 0); visibility: visible; }
#toast.bad { background: var(--bad); }

.confetti { position: fixed; top: -20px; font-size: 22px; pointer-events: none; z-index: 60; animation: fall 1.6s ease-in forwards; }

@keyframes fall { to { transform: translateY(105vh) rotate(540deg); opacity: .6; } }
@keyframes pop { 0% { transform: scale(1); } 40% { transform: scale(1.25); } 100% { transform: scale(1); } }
@keyframes float { 50% { transform: translateY(-6px); } }

@media (max-width: 520px) {
  .hero h1 { font-size: 1.6rem; }
  .kid-header { padding: 16px; }
  .avatar.lg { width: 76px; height: 76px; font-size: 46px; }
  .rewards-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .tabs button { padding: 8px; font-size: .92rem; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
