/* ChoreStars — kid-friendly bilingual chore chart */
:root {
  --bg1: #dff3ff;
  --bg2: #efe6ff;
  --ink: #232a4d;
  --ink-soft: #5a6291;
  --card: #ffffff;
  --accent: #00b4d8;
  --purple: #8338ec;
  --green: #06d6a0;
  --pink: #ff006e;
  --gold: #ffb703;
  --red: #ef476f;
  --radius: 26px;
  --shadow: 0 10px 30px rgba(56, 44, 128, 0.14);
  --shadow-sm: 0 4px 14px rgba(56, 44, 128, 0.10);
  font-size: 16px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: ui-rounded, -apple-system, "SF Pro Rounded", "Segoe UI", system-ui, "Noto Sans Arabic", sans-serif;
  color: var(--ink);
  background: linear-gradient(160deg, var(--bg1), var(--bg2) 60%, #ffe9f3);
  background-attachment: fixed;
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: contain;
  padding-bottom: env(safe-area-inset-bottom);
}
#app { max-width: 560px; margin: 0 auto; padding: 14px 14px 90px; }
button { font-family: inherit; color: inherit; border: none; background: none; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 1rem; }
h1, h2, h3 { margin: 0; }
.hidden { display: none !important; }

/* ---------- generic card ---------- */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 16px;
  margin-bottom: 14px;
}

/* ---------- top bar ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 8px 2px 14px; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand img { width: 44px; height: 44px; border-radius: 12px; box-shadow: var(--shadow-sm); }
.brand .t { font-weight: 800; font-size: 1.25rem; letter-spacing: .2px; }
.brand .s { font-size: .78rem; color: var(--ink-soft); font-weight: 600; }
.iconbtn {
  width: 44px; height: 44px; border-radius: 14px; background: #fff;
  box-shadow: var(--shadow-sm); font-size: 1.25rem; display: grid; place-items: center;
  transition: transform .15s;
}
.iconbtn:active { transform: scale(.9); }

/* ---------- gate ---------- */
.gate { display: flex; flex-direction: column; align-items: center; padding-top: 8vh; }
.gate .lock { font-size: 4rem; margin-bottom: 8px; }
.gate h1 { font-size: 1.4rem; margin-bottom: 4px; text-align: center; }
.gate p { color: var(--ink-soft); margin: 0 0 20px; text-align: center; font-weight: 600; }
.dots { display: flex; gap: 14px; margin-bottom: 26px; min-height: 20px; }
.dots span { width: 16px; height: 16px; border-radius: 50%; background: #d9d4f4; transition: background .15s, transform .15s; }
.dots span.on { background: var(--purple); transform: scale(1.15); }
.dots.err span { background: var(--red); animation: shake .4s; }
@keyframes shake { 0%,100%{transform:translateX(0)} 25%{transform:translateX(-7px)} 75%{transform:translateX(7px)} }
.keypad { display: grid; grid-template-columns: repeat(3, 76px); gap: 14px; }
.key {
  width: 76px; height: 76px; border-radius: 50%; background: #fff; font-size: 1.7rem; font-weight: 800;
  box-shadow: var(--shadow-sm); transition: transform .1s; color: var(--ink);
}
.key:active { transform: scale(.88); background: #f1edff; }
.key.ghost { background: transparent; box-shadow: none; font-size: 1.35rem; }

/* ---------- home ---------- */
.hello { font-size: 1.5rem; font-weight: 800; margin: 4px 2px 2px; }
.subtle { color: var(--ink-soft); font-weight: 600; font-size: .9rem; margin: 0 2px 14px; }
.kids-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 16px; }
.kidcard {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px 12px 14px; text-align: center; transition: transform .15s; position: relative; overflow: hidden;
}
.kidcard:active { transform: scale(.96); }
.kidcard .avatar { font-size: 3.2rem; line-height: 1; margin-bottom: 6px; }
.kidcard .name { font-weight: 800; font-size: 1.15rem; }
.kidcard .name-ar { color: var(--ink-soft); font-weight: 700; font-size: .95rem; margin-bottom: 8px; }
.kidcard .stars {
  display: inline-flex; align-items: center; gap: 6px; background: #fff7e0; color: #9a6b00;
  border-radius: 999px; padding: 5px 12px; font-weight: 800; font-size: .95rem;
}
.kidcard .streak { position: absolute; top: 10px; right: 10px; font-size: .8rem; font-weight: 800; color: #ff6d00; background: #fff1e4; border-radius: 999px; padding: 3px 8px; }
.kidcard .done-today { margin-top: 8px; font-size: .78rem; font-weight: 700; color: var(--ink-soft); }
.vs { text-align: center; font-weight: 800; color: var(--ink-soft); margin: 2px 0 14px; font-size: .9rem; }
.racebar { display: flex; height: 18px; border-radius: 999px; overflow: hidden; background: #eee9ff; box-shadow: inset 0 2px 5px rgba(0,0,0,.06); }
.racebar div { transition: width .6s cubic-bezier(.2,.8,.2,1); }

/* ---------- kid screen ---------- */
.kidhead { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.kidhead .avatar { font-size: 2.6rem; }
.kidhead .who { flex: 1; }
.kidhead .who .n { font-size: 1.3rem; font-weight: 800; }
.kidhead .who .sub { color: var(--ink-soft); font-size: .85rem; font-weight: 700; }
.starcount {
  display: flex; flex-direction: column; align-items: center; background: linear-gradient(135deg,#ffd166,#ffb703);
  color: #6b4a00; padding: 8px 16px; border-radius: 20px; box-shadow: var(--shadow-sm); min-width: 74px;
}
.starcount .num { font-size: 1.5rem; font-weight: 900; line-height: 1.05; }
.starcount .lbl { font-size: .68rem; font-weight: 800; letter-spacing: .3px; }
.pill-row { display: flex; gap: 8px; margin-bottom: 14px; }
.pill { flex: 1; text-align: center; background: #fff; border-radius: 16px; padding: 8px 4px; box-shadow: var(--shadow-sm); font-size: .78rem; font-weight: 700; color: var(--ink-soft); }
.pill b { display: block; font-size: 1.05rem; color: var(--ink); }
.tabs { display: flex; background: #e9e2ff; border-radius: 18px; padding: 5px; margin-bottom: 14px; }
.tab { flex: 1; text-align: center; padding: 10px 4px; border-radius: 14px; font-weight: 800; font-size: .9rem; color: #6a5aa8; transition: all .2s; }
.tab.on { background: #fff; color: var(--ink); box-shadow: var(--shadow-sm); }

/* chore cards (today) */
.chore {
  display: flex; align-items: center; gap: 12px; background: #fff; border-radius: 22px;
  padding: 12px 14px; margin-bottom: 10px; box-shadow: var(--shadow-sm);
  border-left: 8px solid var(--accent); transition: transform .12s, opacity .3s;
}
.chore:active { transform: scale(.98); }
.chore .em { font-size: 2rem; width: 44px; text-align: center; flex-shrink: 0; }
.chore .txt { flex: 1; font-weight: 700; font-size: .98rem; line-height: 1.3; unicode-bidi: plaintext; }
.chore .pts { font-size: .78rem; font-weight: 800; color: #9a6b00; background: #fff7e0; padding: 3px 9px; border-radius: 999px; flex-shrink: 0; }
.chk {
  width: 46px; height: 46px; border-radius: 16px; border: 3px solid #d8d2f0; background: #faf9ff;
  display: grid; place-items: center; font-size: 1.5rem; color: transparent; flex-shrink: 0; transition: all .18s;
}
.chore.done { opacity: .82; }
.chore.done .chk { background: var(--green); border-color: var(--green); color: #fff; animation: pop .35s; }
.chore.done .txt { text-decoration: line-through; text-decoration-color: rgba(35,42,77,.35); }
@keyframes pop { 0%{transform:scale(.5)} 60%{transform:scale(1.2)} 100%{transform:scale(1)} }
.allmsg { text-align: center; font-weight: 800; color: #0b8a68; background: #e2fbf2; border-radius: 18px; padding: 12px; margin: 6px 0 12px; }

/* week grid */
.weekwrap { overflow-x: auto; -webkit-overflow-scrolling: touch; background: #fff; border-radius: 20px; box-shadow: var(--shadow-sm); padding: 10px; }
table.week { border-collapse: collapse; width: 100%; min-width: 470px; }
table.week th, table.week td { text-align: center; padding: 6px 4px; font-size: .8rem; }
table.week th.day { font-weight: 800; color: var(--ink-soft); }
table.week th.day.today { color: #fff; background: var(--purple); border-radius: 10px; }
table.week td.label { text-align: left; font-weight: 700; font-size: .78rem; max-width: 130px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; unicode-bidi: plaintext; }
.cell { width: 34px; height: 34px; border-radius: 10px; border: 2px solid #e4defa; background: #faf9ff; display: inline-grid; place-items: center; font-size: 1rem; color: transparent; transition: all .15s; }
.cell.done { background: var(--green); border-color: var(--green); color: #fff; }
.cell:active { transform: scale(.85); }

/* weekly tasks */
.wtask { border-left-color: var(--purple); }

/* adjustments list */
.adj { display: flex; justify-content: space-between; align-items: center; padding: 9px 4px; border-bottom: 1px dashed #e7e2f7; font-weight: 700; font-size: .9rem; }
.adj:last-child { border-bottom: none; }
.adj .amt { font-weight: 900; }
.adj .amt.neg { color: var(--red); }
.adj .amt.pos { color: #0b8a68; }

/* trophies */
.trophies { display: flex; gap: 10px; }
.trophy { flex: 1; text-align: center; background: #fff; border-radius: 18px; padding: 12px 6px; box-shadow: var(--shadow-sm); }
.trophy .big { font-size: 1.5rem; }
.trophy b { display: block; font-size: 1.1rem; }
.trophy span { font-size: .7rem; color: var(--ink-soft); font-weight: 700; }

/* ---------- buttons ---------- */
.btn {
  display: block; width: 100%; padding: 15px; border-radius: 18px; font-weight: 800; font-size: 1rem;
  background: linear-gradient(135deg, var(--accent), #0096c7); color: #fff; box-shadow: var(--shadow-sm);
  transition: transform .12s; text-align: center;
}
.btn:active { transform: scale(.97); }
.btn.purple { background: linear-gradient(135deg, #9d5cff, var(--purple)); }
.btn.green { background: linear-gradient(135deg, #12e3af, #06b88a); }
.btn.gray { background: #eceafb; color: var(--ink); }
.btn.danger { background: linear-gradient(135deg, #ff6b8a, var(--red)); }
.btn.small { width: auto; display: inline-block; padding: 9px 16px; font-size: .85rem; border-radius: 13px; }
.backrow { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.backrow .title { font-weight: 800; font-size: 1.1rem; }

/* ---------- admin ---------- */
.admin-section h3 { font-size: 1rem; margin-bottom: 10px; display: flex; align-items: center; gap: 8px; }
.mrow { display: flex; align-items: center; gap: 10px; padding: 9px 2px; border-bottom: 1px dashed #eee9fb; }
.mrow:last-child { border-bottom: none; }
.mrow .em { font-size: 1.4rem; width: 34px; text-align: center; }
.mrow .nm { flex: 1; font-weight: 700; font-size: .88rem; unicode-bidi: plaintext; }
.mrow .rw { font-size: .78rem; font-weight: 800; color: #9a6b00; background: #fff7e0; padding: 2px 8px; border-radius: 999px; }
.mrow .edit { font-size: 1.05rem; padding: 6px; }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: .8rem; font-weight: 800; color: var(--ink-soft); margin-bottom: 5px; }
.field input[type=text], .field input[type=number], .field input[type=password], .field select {
  width: 100%; padding: 12px 14px; border-radius: 14px; border: 2px solid #e6e0fa; background: #faf9ff; font-weight: 600;
}
.field input:focus { outline: none; border-color: var(--purple); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.colorpick { display: flex; gap: 8px; flex-wrap: wrap; }
.colorpick .c { width: 34px; height: 34px; border-radius: 50%; border: 3px solid transparent; }
.colorpick .c.on { border-color: var(--ink); transform: scale(1.1); }
.share-qr { display: block; width: 240px; max-width: 76%; margin: 10px auto; border-radius: 14px; box-shadow: var(--shadow-sm); }
.share-url { text-align: center; font-weight: 700; font-size: .85rem; word-break: break-all; background: #f4f1ff; border-radius: 12px; padding: 10px; margin: 8px 0; }
.note { font-size: .8rem; color: var(--ink-soft); font-weight: 600; line-height: 1.45; }
.warn { background: #fff6e4; border-radius: 14px; padding: 10px 12px; font-size: .8rem; font-weight: 700; color: #8a6100; margin: 10px 0; line-height: 1.4; }

/* modal */
.modal-bg { position: fixed; inset: 0; background: rgba(30,20,60,.45); display: grid; place-items: center; padding: 18px; z-index: 50; backdrop-filter: blur(3px); }
.modal { background: #fff; border-radius: 24px; box-shadow: var(--shadow); padding: 20px; width: 100%; max-width: 420px; max-height: 86vh; overflow-y: auto; }
.modal h3 { margin-bottom: 14px; }

/* toast */
#toast {
  position: fixed; left: 50%; bottom: 30px; transform: translateX(-50%) translateY(80px);
  background: var(--ink); color: #fff; font-weight: 700; padding: 12px 20px; border-radius: 999px;
  box-shadow: var(--shadow); transition: transform .3s; z-index: 99; font-size: .9rem; max-width: 86vw; text-align: center;
}
#toast.show { transform: translateX(-50%) translateY(0); }

/* confetti canvas */
#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 90; }

/* big center star burst */
.burst { position: fixed; font-size: 3rem; pointer-events: none; z-index: 91; animation: rise 1s forwards; }
@keyframes rise { 0%{transform:scale(.4); opacity:1} 100%{transform:scale(1.6) translateY(-70px); opacity:0} }

@media (min-width: 700px) {
  #app { max-width: 640px; }
  .keypad { grid-template-columns: repeat(3, 84px); }
}

/* ================= v2 additions ================= */

/* SAR chip */
.sar { font-weight: 800; color: #0b7a5c; white-space: nowrap; }
.sar.neg { color: var(--red); }

/* parent login */
.loginbox { max-width: 380px; margin: 6vh auto 0; }

/* kid switcher chips */
.kidswitch { display: flex; gap: 10px; margin-bottom: 14px; }
.kidchip {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 8px;
  background: #fff; border: 3px solid transparent; border-radius: 18px; padding: 10px 8px;
  font-weight: 800; font-size: 1rem; box-shadow: var(--shadow-sm); transition: all .15s; color: var(--ink);
}
.kidchip .av { font-size: 1.5rem; }
.kidchip.on { border-color: var(--purple); background: #f6f1ff; }
.kidchip:active { transform: scale(.96); }

/* payouts */
.payout { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 4px; border-bottom: 1px dashed #eee9fb; }
.payout:last-child { border-bottom: none; }
.payout .who { display: flex; align-items: center; gap: 8px; font-weight: 800; }
.payout .wk { font-size: .75rem; color: var(--ink-soft); font-weight: 700; display: block; }
.paidbtn { padding: 8px 14px; border-radius: 12px; font-weight: 800; font-size: .82rem; box-shadow: var(--shadow-sm); }
.paidbtn.unpaid { background: #ffe9ec; color: #c2185b; }
.paidbtn.paid { background: #e2fbf2; color: #0b8a68; }

/* board */
.board-wrap { max-width: 900px; margin: 0 auto; padding: 12px; }
.board-head { text-align: center; margin: 8px 0 16px; }
.board-head .t { font-size: 1.5rem; font-weight: 900; }
.board-head .d { color: var(--ink-soft); font-weight: 700; font-size: .95rem; }
.board-kids { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 480px) { .board-kids { grid-template-columns: 1fr; } }
.bkid { background: #fff; border-radius: 28px; box-shadow: var(--shadow); padding: 22px 16px; text-align: center; border-top: 10px solid var(--accent); }
.bkid .avatar { font-size: 4rem; line-height: 1.1; }
.bkid .nm { font-size: 1.4rem; font-weight: 900; margin: 4px 0 2px; }
.bkid .nm-en { color: var(--ink-soft); font-weight: 700; font-size: .9rem; margin-bottom: 12px; }
.bkid .total { font-size: 2.4rem; font-weight: 900; color: #0b7a5c; line-height: 1.1; }
.bkid .total small { font-size: 1rem; font-weight: 800; }
.bkid .sub { color: var(--ink-soft); font-weight: 700; font-size: .82rem; margin-bottom: 14px; }
.bstats { display: flex; gap: 8px; }
.bstat { flex: 1; background: #f7f4ff; border-radius: 16px; padding: 10px 4px; }
.bstat b { display: block; font-size: 1.05rem; }
.bstat span { font-size: .68rem; color: var(--ink-soft); font-weight: 700; }
.progressbar { height: 14px; background: #eee9ff; border-radius: 999px; overflow: hidden; margin: 10px 0 12px; box-shadow: inset 0 2px 4px rgba(0,0,0,.05); }
.progressbar div { height: 100%; border-radius: 999px; background: linear-gradient(90deg, #12e3af, #06b88a); transition: width .7s cubic-bezier(.2,.8,.2,1); }
.board-race { margin-top: 18px; }
.board-refresh { text-align: center; color: var(--ink-soft); font-weight: 600; font-size: .75rem; margin-top: 16px; }

/* week table money header */
table.week td.money { font-size: .72rem; font-weight: 800; color: #0b7a5c; }

/* history */
.hweek { padding: 10px 4px; border-bottom: 1px dashed #eee9fb; }
.hweek:last-child { border-bottom: none; }
.hweek .hd { display: flex; justify-content: space-between; font-weight: 800; font-size: .9rem; }
.hweek .bd { color: var(--ink-soft); font-weight: 700; font-size: .84rem; margin-top: 3px; }

/* balance carry-over bar */
.balbar {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  background: #fffbe9; border: 2px dashed #f4d06f; border-radius: 16px;
  padding: 10px 14px; margin-bottom: 12px; font-weight: 800; font-size: .85rem; color: #7a6416;
}
