:root {
  --bg: #f3ede1;
  --paper: #fffdf8;
  --paper-2: #faf6ec;
  --rule: #ebe6da;
  --ink: #1f2b47;
  --ink-soft: #46506a;
  --ink-2: #8a3566;
  --muted: #6b665c;
  --line-soft: rgba(31, 43, 71, 0.1);
  --green: #3f7a52;
  --green-soft: #e3efe4;
  --note: #fff1a6;
  --danger: #b5412f;
  --row: 56px;
  --hand: "Caveat", "Marhey", cursive;
  --ui: "Nunito", "Cairo", system-ui, sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --shadow: 0 1px 2px rgba(60, 45, 20, 0.06), 0 12px 30px -16px rgba(60, 45, 20, 0.3);
}
html[lang="ar"] { --ui: "Cairo", "Nunito", system-ui, sans-serif; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; min-height: 100%; }
body { font-family: var(--ui); font-size: 16px; color: var(--ink); background: var(--bg); overscroll-behavior-y: contain; -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input { font: inherit; }
:focus-visible { outline: 2.5px solid var(--ink); outline-offset: 2px; border-radius: 12px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.muted { color: var(--muted); }
.small { font-size: 14px; }
[hidden] { display: none !important; }
.hand { font-family: var(--hand); }
.hand-ar, html[lang="ar"] .hand { font-family: "Marhey", var(--hand); }

/* ---------- lock ---------- */
.screen { min-height: 100dvh; display: grid; place-items: center; padding: 24px 18px calc(24px + var(--safe-b)); }
.lock-card, .who-card { width: min(360px, 100%); text-align: center; animation: rise 0.45s cubic-bezier(0.2, 0.9, 0.3, 1) both; }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } }
.lock-mark { width: 66px; height: 66px; margin: 0 auto 14px; display: grid; place-items: center; border-radius: 22px; background: var(--paper); box-shadow: var(--shadow); color: var(--ink); }
.lock-title { font-weight: 700; font-size: 46px; margin: 0; line-height: 1.1; }
html[lang="ar"] .lock-title { font-size: 38px; }
.lock-hint { margin: 6px 0 0; font-size: 16px; font-weight: 600; color: var(--ink-soft); }
.dots { display: flex; justify-content: center; gap: 16px; margin: 26px 0 6px; height: 20px; direction: ltr; }
.dot { width: 16px; height: 16px; border-radius: 50%; border: 2px solid rgba(31, 43, 71, 0.32); transition: background 0.15s, border-color 0.15s, transform 0.15s; }
.dot.on { background: var(--ink); border-color: var(--ink); transform: scale(1.12); }
.dots.ok .dot { background: var(--green); border-color: var(--green); }
.dots.shake { animation: shake 0.42s; }
@keyframes shake { 20%, 60% { transform: translateX(-9px); } 40%, 80% { transform: translateX(9px); } }
.lock-msg { min-height: 24px; margin: 6px 0 4px; font-size: 15px; font-weight: 600; color: var(--danger); }
.lock-msg.good { color: var(--green); }
.len-pick { display: inline-flex; gap: 4px; margin: 0 0 12px; padding: 4px; border-radius: 999px; background: rgba(31, 43, 71, 0.06); }
.len { font-size: 14px; font-weight: 700; padding: 6px 14px; border-radius: 999px; color: var(--muted); }
.len.on { background: var(--paper); color: var(--ink); box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1); }

.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px 22px; padding: 8px 10px 0; direction: ltr; }
.key { aspect-ratio: 1; max-width: 78px; width: 100%; justify-self: center; display: grid; place-content: center; border-radius: 50%; background: var(--paper); box-shadow: 0 1px 1px rgba(60, 45, 20, 0.08), 0 6px 16px -8px rgba(60, 45, 20, 0.35); transition: transform 0.08s, background 0.15s; user-select: none; touch-action: manipulation; }
.key span { font-family: "Nunito", system-ui, sans-serif; font-weight: 600; font-size: 30px; line-height: 1; }
.key small { font-family: "Nunito", system-ui, sans-serif; font-size: 9.5px; font-weight: 700; letter-spacing: 0.16em; text-transform: uppercase; color: var(--muted); margin-top: 2px; }
.key:active, .key.press { transform: scale(0.93); background: #ece4d2; }
.key.ghost, .key.ghost-btn { background: none; box-shadow: none; }
.key.ghost-btn { color: var(--ink-soft); }
.key.ghost-btn:active { background: rgba(31, 43, 71, 0.08); }
.keypad.locked { opacity: 0.35; pointer-events: none; }

.who-card h2 { font-size: 34px; margin: 0 0 6px; line-height: 1.2; }
html[lang="ar"] .who-card h2 { font-size: 28px; }
.who-list { display: grid; gap: 12px; margin-top: 22px; }
.who-btn { font-family: var(--hand); font-size: 34px; font-weight: 700; padding: 14px; border-radius: 20px; background: var(--paper); box-shadow: var(--shadow); transition: transform 0.12s; }
.who-btn:active { transform: scale(0.97); }
.who-btn.p0 { color: var(--ink); } .who-btn.p1 { color: var(--ink-2); }

/* ---------- app ---------- */
.wrap { max-width: 560px; margin: 0 auto; padding: 0 14px; }
.top { padding: calc(18px + env(safe-area-inset-top, 0px)) 4px 14px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.title { font-weight: 700; font-size: 44px; line-height: 1; margin: 0; }
html[lang="ar"] .title { font-size: 34px; line-height: 1.3; }
.date { margin: 4px 0 0; font-size: 14px; color: var(--muted); font-weight: 600; }
.top-actions { display: flex; gap: 8px; }
.icon-btn { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 14px; background: var(--paper); box-shadow: 0 1px 2px rgba(60, 45, 20, 0.1); color: var(--ink); transition: transform 0.1s; }
.icon-btn:active { transform: scale(0.94); }

.summary { background: var(--paper); border-radius: 18px; padding: 14px 16px; box-shadow: 0 1px 2px rgba(60, 45, 20, 0.06); margin-bottom: 12px; }
.sum-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.tally { margin: 0; font-size: 15px; color: var(--ink-soft); font-weight: 600; }
.tally b { font-size: 20px; color: var(--ink); font-weight: 800; }
.mini-toggle { font-size: 13px; font-weight: 700; padding: 6px 12px; border-radius: 999px; color: var(--muted); background: rgba(31, 43, 71, 0.06); white-space: nowrap; }
.mini-toggle[aria-pressed="true"] { color: var(--paper); background: var(--ink); }
.bar { height: 8px; border-radius: 99px; background: rgba(31, 43, 71, 0.08); margin-top: 10px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; border-radius: inherit; background: var(--green); transition: width 0.5s cubic-bezier(0.3, 0.8, 0.3, 1); }

.card { background: var(--paper); border-radius: 22px; box-shadow: var(--shadow); overflow: hidden; }
.group-label { display: flex; align-items: center; gap: 9px; padding: 16px 16px 4px; font-size: 12.5px; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
html[lang="ar"] .group-label { letter-spacing: 0; font-size: 14px; }
.group-label + .row .row-inner::before { display: none; }
.gi { width: 26px; height: 26px; display: grid; place-items: center; border-radius: 9px; background: var(--paper-2); box-shadow: inset 0 0 0 1px var(--line-soft); color: var(--ink-soft); }
.gi svg { width: 16px; height: 16px; }
.group-label .n { margin-inline-start: auto; letter-spacing: 0; text-transform: none; font-weight: 700; }
.group-label .n.done { color: var(--green); }

.row { position: relative; touch-action: pan-y; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.row-inner::before { content: ""; position: absolute; top: 0; inset-inline: 62px 16px; height: 1px; background: var(--rule); }
.list > .row:first-child .row-inner::before { display: none; }
.row-erase { position: absolute; inset: 0; display: flex; align-items: center; justify-content: flex-end; padding-inline-end: 22px; font-weight: 800; font-size: 15px; color: #fff; background: var(--danger); opacity: 0; }
.row-inner { position: relative; display: flex; align-items: center; min-height: var(--row); padding-inline: 10px 4px; background: var(--paper); transition: transform 0.25s cubic-bezier(0.2, 0.9, 0.3, 1), background 0.2s; }
.row.dragging .row-inner { transition: none; }
.row.dragging .row-erase, .row.erasing .row-erase { opacity: 1; }
.row.new { animation: write 0.45s ease-out both; }
@keyframes write { from { opacity: 0; transform: translateY(-6px); } }
.row.flash .row-inner { animation: flash 1.2s; }
@keyframes flash { 0%, 50% { background: var(--note); } 100% { background: var(--paper); } }
.row.leaving { animation: leave 0.26s ease-in forwards; }
@keyframes leave { to { opacity: 0; transform: translateX(-30px); } }
html[dir="rtl"] .row.leaving { animation-name: leave-r; }
@keyframes leave-r { to { opacity: 0; transform: translateX(30px); } }

.box { flex: none; width: 44px; height: 44px; display: grid; place-items: center; margin-inline-end: 8px; }
.box svg { width: 27px; height: 27px; overflow: visible; }
.box .sq { fill: none; stroke: rgba(31, 43, 71, 0.5); stroke-width: 1.9; stroke-linejoin: round; transition: fill 0.2s, stroke 0.2s; }
.row.done .box .sq { fill: var(--green-soft); stroke: var(--green); }
.box .tick { fill: none; stroke: var(--green); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 40; stroke-dashoffset: 40; }
.row.done .box .tick { stroke-dashoffset: 0; }
.row.just.done .box .tick { transition: stroke-dashoffset 0.35s ease-out; }

.body { flex: 1; min-width: 0; padding: 8px 0; display: flex; flex-direction: column; gap: 2px; }
.line1 { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.text { position: relative; font-family: var(--hand); font-size: 27px; font-weight: 500; line-height: 1.15; overflow-wrap: anywhere; transition: color 0.3s; }
.text.is-ar { font-family: "Marhey", var(--hand); font-size: 20px; line-height: 1.6; font-weight: 400; }
.qty { font-size: 13px; font-weight: 800; color: var(--ink-2); background: #f6e8ef; padding: 2px 9px; border-radius: 99px; white-space: nowrap; }
.meta { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.strike { position: absolute; inset-inline: -3px; top: 54%; height: 16px; transform: translateY(-50%); pointer-events: none; overflow: visible; width: calc(100% + 6px); }
.strike path { fill: none; stroke: rgba(31, 43, 71, 0.72); stroke-width: 2.2; stroke-linecap: round; stroke-dasharray: 110; stroke-dashoffset: 110; vector-effect: non-scaling-stroke; }
html[dir="rtl"] .strike, .text.is-ar .strike { transform: translateY(-50%) scaleX(-1); }
.row.done .strike path { stroke-dashoffset: 0; }
.row.just.done .strike path { transition: stroke-dashoffset 0.4s 0.1s ease-in-out; }
.row.done .text { color: #a39e93; }
.row.done .qty { opacity: 0.5; }
.del { flex: none; width: 44px; height: 44px; display: grid; place-items: center; border-radius: 12px; color: rgba(31, 43, 71, 0.5); transition: color 0.15s, background 0.15s; }
.del:hover, .del:active { color: var(--danger); background: #f8e5e1; }
.del svg { width: 20px; height: 20px; }

.empty { padding: 34px 24px 36px; text-align: center; color: var(--muted); }
.empty svg { width: 110px; height: 84px; display: block; margin: 0 auto 10px; color: rgba(31, 43, 71, 0.38); }
.empty h3 { font-size: 30px; color: var(--ink); margin: 0 0 6px; font-weight: 700; line-height: 1.3; }
.empty p { margin: 0; font-size: 15px; line-height: 1.7; }

.finish-wrap { padding: 12px; border-top: 1px solid var(--rule); }
.finish { width: 100%; display: flex; align-items: center; justify-content: center; gap: 10px; font-size: 15px; font-weight: 800; padding: 13px 16px; border-radius: 14px; color: var(--green); background: var(--green-soft); transition: transform 0.1s; }
.finish:active { transform: scale(0.98); }
.tip { text-align: center; font-size: 13px; color: var(--muted); margin: 14px 8px 0; line-height: 1.6; }
.spacer { height: calc(170px + var(--safe-b)); }

/* ---------- dock ---------- */
.dock { position: fixed; inset-inline: 0; bottom: 0; z-index: 20; background: var(--paper); border-radius: 24px 24px 0 0; box-shadow: 0 -8px 30px -14px rgba(60, 45, 20, 0.35); padding: 12px 12px calc(12px + var(--safe-b)); }
.dock > * { max-width: 536px; margin-inline: auto; }
.usuals { display: flex; gap: 8px; overflow-x: auto; padding: 0 2px 10px; scrollbar-width: none; }
.usuals::-webkit-scrollbar { display: none; }
.usuals .label { flex: none; align-self: center; font-size: 12px; font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); padding-inline-end: 2px; }
html[lang="ar"] .usuals .label { letter-spacing: 0; font-size: 13px; }
.chip { flex: none; font-size: 14px; font-weight: 700; padding: 7px 13px; border-radius: 999px; background: var(--paper-2); box-shadow: inset 0 0 0 1px var(--line-soft); white-space: nowrap; transition: transform 0.1s; }
.chip:active { transform: scale(0.94); }
.chip::before { content: "+ "; color: var(--green); font-weight: 900; }
.add { display: flex; align-items: center; gap: 6px; background: var(--paper-2); border-radius: 18px; padding: 5px; padding-inline-start: 16px; box-shadow: inset 0 0 0 1.5px var(--line-soft); }
.add:focus-within { box-shadow: inset 0 0 0 2px var(--ink); }
.add-input { flex: 1; min-width: 0; height: 46px; border: 0; outline: 0; background: transparent; font-family: var(--hand); font-size: 24px; color: var(--ink); }
html[lang="ar"] .add-input { font-family: "Marhey", var(--hand); font-size: 17px; }
.add-input::placeholder { color: #9c968b; }
.add-btn { width: 46px; height: 46px; display: grid; place-items: center; border-radius: 14px; color: var(--paper); background: var(--green); transition: opacity 0.15s, transform 0.15s; }
.add:not(.has-text) .add-btn { display: none; }
.mic { flex: none; width: 50px; height: 50px; display: grid; place-items: center; border-radius: 15px; background: var(--ink); color: var(--paper); transition: transform 0.12s; }
.add.has-text .mic { width: 46px; height: 46px; background: transparent; color: var(--ink-soft); }
.mic:active { transform: scale(0.92); }

/* ---------- voice ---------- */
.voice { position: fixed; inset: 0; z-index: 60; display: grid; place-items: end center; background: rgba(30, 24, 14, 0.4); animation: fade 0.2s both; }
@keyframes fade { from { opacity: 0; } }
.voice-card { width: min(560px, 100%); background: var(--paper); border-radius: 28px 28px 0 0; padding: 20px 22px calc(24px + var(--safe-b)); text-align: center; animation: up 0.3s cubic-bezier(0.2, 0.9, 0.3, 1) both; }
@keyframes up { from { transform: translateY(100%); } }
.lang { display: inline-flex; gap: 4px; padding: 4px; border-radius: 999px; background: rgba(31, 43, 71, 0.06); }
.lang-btn { font-size: 14px; font-weight: 700; padding: 6px 16px; border-radius: 999px; color: var(--muted); }
.lang-btn[lang="ar"] { font-family: "Cairo", sans-serif; }
.lang-btn.on { background: var(--paper); color: var(--ink); box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1); }
.orb { position: relative; width: 104px; height: 104px; margin: 26px auto 6px; display: grid; place-items: center; border-radius: 50%; background: var(--ink); color: var(--paper); }
.orb .ring { position: absolute; inset: 0; border-radius: 50%; border: 2px solid var(--ink); opacity: 0; }
.voice.live .orb .ring { animation: ripple 1.8s infinite ease-out; }
.voice.live .orb .r2 { animation-delay: 0.6s; } .voice.live .orb .r3 { animation-delay: 1.2s; }
@keyframes ripple { 0% { transform: scale(1); opacity: 0.5; } 100% { transform: scale(1.9); opacity: 0; } }
.voice.busy .orb { animation: breathe 0.9s infinite alternate; }
@keyframes breathe { to { transform: scale(0.92); opacity: 0.7; } }
.voice-state { margin: 10px 0 0; font-size: 15px; font-weight: 700; color: var(--muted); }
.voice-text { font-family: var(--hand); font-size: 30px; min-height: 84px; margin: 6px 0 8px; line-height: 1.25; }
.voice-text.is-ar { font-family: "Marhey", var(--hand); font-size: 23px; line-height: 1.7; }
.text-btn { margin-top: 10px; font-size: 15px; font-weight: 700; padding: 10px 22px; border-radius: 12px; color: var(--ink-soft); background: rgba(31, 43, 71, 0.06); }

/* ---------- bottom sheet ---------- */
.scrim { position: fixed; inset: 0; z-index: 40; background: rgba(30, 24, 14, 0.4); animation: fade 0.2s both; }
.bsheet { position: fixed; inset-inline: 0; bottom: 0; z-index: 50; max-width: 560px; margin: 0 auto; max-height: 90dvh; overflow-y: auto; background: var(--paper); border-radius: 28px 28px 0 0; padding: 10px 20px calc(24px + var(--safe-b)); animation: up 0.28s cubic-bezier(0.2, 0.9, 0.3, 1) both; outline: 0; }
.grip { width: 40px; height: 5px; border-radius: 3px; background: rgba(31, 43, 71, 0.18); margin: 0 auto 14px; }
.bsheet h2 { font-size: 32px; margin: 0 0 12px; line-height: 1.2; font-weight: 700; }
html[lang="ar"] .bsheet h2 { font-size: 26px; }
.bsheet h3 { font-size: 12px; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); margin: 20px 0 8px; }
html[lang="ar"] .bsheet h3 { letter-spacing: 0; font-size: 13px; }
.field { display: block; margin-bottom: 12px; }
.field span { display: block; font-size: 13px; font-weight: 700; color: var(--muted); margin-bottom: 4px; }
.field input { width: 100%; border: 0; border-radius: 14px; background: var(--paper-2); box-shadow: inset 0 0 0 1.5px var(--line-soft); font-family: var(--hand); font-size: 24px; color: var(--ink); padding: 8px 14px; outline: 0; }
html[lang="ar"] .field input { font-family: "Marhey", var(--hand); font-size: 17px; padding: 10px 14px; }
.field input:focus { box-shadow: inset 0 0 0 2px var(--ink); }
.two { display: grid; grid-template-columns: 1fr 1.7fr; gap: 12px; }
.cats { display: flex; flex-wrap: wrap; gap: 8px; }
.cat { display: inline-flex; align-items: center; gap: 6px; font-size: 13.5px; font-weight: 700; padding: 7px 12px; padding-inline-start: 9px; border-radius: 999px; background: var(--paper-2); box-shadow: inset 0 0 0 1px var(--line-soft); }
.cat svg { width: 17px; height: 17px; }
.cat[aria-pressed="true"] { background: var(--ink); color: var(--paper); box-shadow: none; }
.actions { display: flex; gap: 10px; margin-top: 22px; align-items: center; }
.btn { font-size: 15px; font-weight: 800; padding: 12px 20px; border-radius: 14px; background: var(--ink); color: var(--paper); }
.btn.ghost { background: rgba(31, 43, 71, 0.06); color: var(--ink); }
.btn.danger { background: #f8e5e1; color: var(--danger); display: inline-flex; align-items: center; gap: 6px; }
.btn.danger svg { width: 18px; height: 18px; }
.btn:active { transform: scale(0.97); }
.grow { flex: 1; }
.menu-group { background: var(--paper-2); border-radius: 18px; overflow: hidden; }
.menu-row { display: flex; align-items: center; gap: 14px; width: 100%; text-align: start; padding: 14px 16px; font-size: 16px; font-weight: 700; min-height: 54px; }
.menu-row + .menu-row { border-top: 1px solid var(--rule); }
.menu-row svg { width: 22px; height: 22px; flex: none; color: var(--ink-soft); }
.menu-row .hint { margin-inline-start: auto; font-size: 13px; color: var(--muted); font-weight: 600; }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; border-radius: 16px; background: rgba(31, 43, 71, 0.06); }
.seg button { font-size: 16px; font-weight: 800; padding: 10px 8px; border-radius: 12px; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--paper); color: var(--ink); box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1); }
.seg button.p1[aria-pressed="true"] { color: var(--ink-2); }
.trip { padding: 14px 16px; background: var(--paper-2); border-radius: 16px; margin-bottom: 10px; }
.trip-head { display: flex; justify-content: space-between; font-size: 13px; font-weight: 700; color: var(--muted); }
.trip-items { font-size: 16px; font-weight: 600; line-height: 1.6; margin-top: 4px; }
.trip-again { font-size: 13px; font-weight: 800; color: var(--green); margin-top: 6px; padding: 6px 0; }
.err { color: var(--danger); min-height: 22px; font-size: 14px; margin: 6px 0 0; }
.code-sheet { text-align: center; }
.keypad.compact { gap: 10px 20px; max-width: 290px; margin: 6px auto 0; }
.keypad.compact .key { max-width: 66px; }
.keypad.compact .key span { font-size: 26px; }

/* ---------- toast ---------- */
.toast { position: fixed; left: 50%; bottom: calc(150px + var(--safe-b)); z-index: 70; transform: translateX(-50%); display: flex; align-items: center; gap: 14px; width: max-content; max-width: calc(100% - 32px); padding: 12px 16px; border-radius: 16px; background: var(--ink); color: var(--paper); font-size: 15px; font-weight: 600; box-shadow: 0 12px 30px -10px rgba(20, 20, 40, 0.5); animation: pop 0.28s cubic-bezier(0.2, 1.3, 0.4, 1) both; }
.toast button { font-weight: 800; color: var(--note); white-space: nowrap; padding: 4px 2px; }
@keyframes pop { from { opacity: 0; transform: translateX(-50%) translateY(14px); } }
.offline { position: fixed; top: calc(8px + env(safe-area-inset-top, 0px)); left: 50%; transform: translateX(-50%); z-index: 80; background: var(--ink); color: var(--paper); font-size: 13px; font-weight: 700; padding: 5px 14px; border-radius: 999px; }

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

/* Arabic headings: clear and bold; the handwriting stays on the items. */
html[lang="ar"] .title, html[lang="ar"] .lock-title, html[lang="ar"] .bsheet h2, html[lang="ar"] .who-card h2, html[lang="ar"] .empty h3 { font-family: "Cairo", sans-serif; font-weight: 800; }
html[lang="ar"] .key small { visibility: hidden; }
