/* Phông viết tay đóng gói sẵn (fonts/, giấy phép OFL): chạy cả khi mất mạng và nhúng được vào ảnh chụp */
@font-face { font-family: "Patrick Hand"; src: url("../fonts/PatrickHand-Regular.ttf") format("truetype"); font-display: swap; }
:root {
  --bg: #eef2f3; --text: #1f3a68; --muted: #5f6670; --card: #ffffff; --rule: #c9d6de;
  --btn: #1f3a68; --btn-ink: #ffffff; --danger: #c23b2a; --paper: #fbf7ec; --ink: #3d2616;
  color-scheme: light;
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --bg: #141b26; --text: #d8e3f5; --muted: #9aa6b8; --card: #1c2433; --rule: #2b3a55; --btn: #d8e3f5; --btn-ink: #141b26; --danger: #ff7b6b; color-scheme: dark; }
}
:root[data-theme="dark"] { --bg: #141b26; --text: #d8e3f5; --muted: #9aa6b8; --card: #1c2433; --rule: #2b3a55; --btn: #d8e3f5; --btn-ink: #141b26; --danger: #ff7b6b; color-scheme: dark; }
*, *::before, *::after { box-sizing: inherit; }
/* mọi chữ trong game dùng một phông viết tay: Patrick Hand (cỡ chữ nhỉnh hơn vì phông này nét nhỏ) */
body { margin: 0; background: var(--bg); color: var(--text); font: 18px/1.5 "Patrick Hand", cursive; }
input, textarea, select { font-family: "Patrick Hand", cursive; font-size: 18px; }
main { max-width: 760px; margin: 0 auto; padding: 16px 14px 40px; }
h1 { font: 400 52px/1 "Patrick Hand", cursive; margin: 24px 0 4px; }
h2 { font: 400 30px/1.1 "Patrick Hand", cursive; margin: 0 0 12px; }
.muted { color: var(--muted); }
.card { background: var(--card); border: 2px solid var(--text); border-radius: 8px 14px 10px 12px; padding: 16px; margin: 16px 0; }
label { display: block; font-weight: 600; margin-bottom: 4px; }
input[type="text"], #nameInput { width: 100%; font: inherit; color: var(--text); background: transparent; border: 0; border-bottom: 2px solid var(--text); padding: 6px 2px; outline: none; }
#nameInput:focus-visible { border-bottom-color: var(--danger); }
.hint { font-size: 16px; color: var(--muted); margin: 4px 0; }
.err { color: var(--danger); font-size: 16px; min-height: 1em; margin: 6px 0; }
.warn { border: 2px solid var(--danger); color: var(--danger); border-radius: 8px; padding: 10px 12px; margin: 10px 0; }
button { font: 400 17px/1.2 "Patrick Hand", cursive; cursor: pointer; border-radius: 8px; padding: 10px 14px; border: 2px solid var(--btn); background: transparent; color: var(--text); }
button.primary, button[aria-pressed="true"] { background: var(--btn); color: var(--btn-ink); }
button.danger { color: var(--danger); border-color: var(--danger); }
button:focus-visible { outline: 3px solid #f3d34a; outline-offset: 2px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.row.center { justify-content: center; }

/* ---------- Màn chơi tràn màn hình ---------- */
.game { position: fixed; inset: 0; background: var(--paper); overflow: hidden; z-index: 10; }
.stage { position: absolute; inset: 0; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; cursor: grab; background: var(--paper); }
.stage.dragging { cursor: grabbing; }
/* phố vẽ thành hai lớp: #streetBg (nhà cửa, đường, dây điện: không đổi, trình duyệt vẽ một lần rồi chỉ dịch đi khi vuốt)
   và #street (người, xe, cửa hàng, bong bóng: hay đổi). Tách ra để vuốt không phải vẽ lại cả dãy nhà mỗi khung hình. */
#street, #streetBg { display: block; position: absolute; left: 0; top: 0; will-change: transform; transform: translate3d(0, 0, 0); }
#streetBg { pointer-events: none; }
#street > .you { transition: transform 1.4s ease-in-out; }
.marker { animation: marker 1.2s ease-in-out infinite; }
@keyframes marker { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-4px); } }

/* Thanh trên: tiền, địa điểm, nút tròn */
.hud { position: absolute; top: calc(10px + env(safe-area-inset-top, 0px)); left: 10px; right: 10px; display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; pointer-events: none; z-index: 6; }
.hud > * { pointer-events: auto; }
.hud-left { display: flex; flex-wrap: wrap; gap: 6px; min-width: 0; }
.pill { background: var(--card); color: var(--text); border: 2px solid var(--ink); border-radius: 12px 14px 12px 10px; padding: 3px 10px; font-size: 16px; white-space: nowrap; }
.pill.place { font: 400 19px/1.3 "Patrick Hand", cursive; overflow: hidden; text-overflow: ellipsis; max-width: 52vw; }
.tools { display: flex; align-items: flex-start; gap: 8px; }
/* nút chụp ảnh: nền giấy, máy ảnh đỏ vẽ tay, có chữ cho dễ thấy */
.cam { display: flex; flex-direction: column; align-items: center; gap: 0; padding: 4px 8px 4px; background: #fffdf6; color: #b8392a; border: 2.5px solid #3d2616; border-radius: 14px 16px 14px 12px; box-shadow: 0 4px 0 rgba(61, 38, 22, .35); font: 400 15px/1 "Patrick Hand", cursive; }
.cam .ico { width: 34px; height: 34px; margin: 0; }
.cam:active, .hudbtn:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(61, 38, 22, .35); }
/* nút tạm dừng: tròn kiểu kẹo xanh, hai vạch kem vẽ tay */
.hudbtn { width: 50px; height: 50px; padding: 0; display: grid; place-items: center; background: #5b86b5; border: 2.5px solid #3d2616; border-radius: 50%; box-shadow: 0 4px 0 rgba(61, 38, 22, .35); }
.hudbtn .ico { width: 32px; height: 32px; margin: 0; }
.tools .dot { align-self: center; }
.icon { width: 42px; height: 42px; padding: 0; border-radius: 50%; display: grid; place-items: center; background: var(--card); color: var(--text); border: 2px solid var(--ink); }
.icon svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.icon[aria-pressed="true"] { background: var(--btn); color: var(--btn-ink); }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); transition: background .3s; }
.dot.on { background: #3c9a5f; }

/* Màn thoại riêng: chân dung lớn + hộp chữ, đè lên phố. Giữ màu giấy như tranh ở cả chế độ tối. */
.talk { position: fixed; inset: 0; z-index: 15; cursor: pointer; display: flex; flex-direction: column; background: rgba(43, 28, 18, .62); color: #3d2616; animation: talkIn .25s ease-out; }
@keyframes talkIn { from { opacity: 0; } to { opacity: 1; } }
.talking .hud, .talking .next, .talking .swipe-hint { visibility: hidden; }

/* Nút Đi tiếp và gợi ý vuốt: đặt phía trên, vì mép dưới có thể bị thanh trình duyệt điện thoại che */
.next { position: absolute; left: 50%; top: calc(56px + env(safe-area-inset-top, 0px)); transform: translateX(-50%); z-index: 6; font-size: 17px; padding: 11px 24px; border: 2px solid var(--ink); box-shadow: 0 4px 0 rgba(61, 38, 22, .3); white-space: nowrap; animation: nudge 1.6s ease-in-out infinite; }
@keyframes nudge { 0%, 100% { transform: translateX(-50%); } 50% { transform: translateX(calc(-50% + 5px)); } }
.swipe-hint { position: absolute; left: 50%; top: calc(112px + env(safe-area-inset-top, 0px)); transform: translateX(-50%); margin: 0; background: rgba(61, 38, 22, .78); color: #fffdf6; font-size: 15px; padding: 5px 12px; border-radius: 12px; white-space: nowrap; z-index: 5; pointer-events: none; }
.talk-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: calc(10px + env(safe-area-inset-top, 0px)) 10px 0; }
.talk-tools { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.chip { padding: 6px 11px; font-size: 15px; border-radius: 14px; background: #fffdf6; color: #3d2616; border: 2px solid #3d2616; }
.chip[aria-pressed="true"] { background: #3d2616; color: #fffdf6; }
.chip.skip { background: #c8242b; border-color: #3d2616; color: #fffdf6; font-size: 16px; padding: 7px 14px; }
.talk-cast { flex: 1; position: relative; min-height: 0; }
.slot { position: absolute; bottom: -2px; width: 52%; max-width: 300px; height: 100%; display: flex; align-items: flex-end; transition: opacity .2s, transform .2s, filter .2s; }
.slot.left { left: -2%; }
.slot.right { right: -2%; }
.slot .portrait { width: 100%; height: 100%; display: block; }
.slot.dim { filter: saturate(.55) brightness(.62); transform: scale(.94); transform-origin: 50% 100%; }
.slot.empty { visibility: hidden; }
.talk-box { position: relative; margin: 0 10px calc(12px + env(safe-area-inset-bottom, 0px)); background: #fffdf6; border: 2px solid #3d2616; border-radius: 14px 18px 14px 12px; padding: 12px 14px 16px; min-height: 140px; box-shadow: 0 5px 0 rgba(0, 0, 0, .25); cursor: pointer; }
.talk-box .who { position: absolute; top: -16px; left: 14px; font: 400 20px/1 "Patrick Hand", cursive; background: #c8242b; color: #fffdf6; border: 2px solid #3d2616; border-radius: 10px; padding: 4px 12px; }
.talk-box .who.me { left: auto; right: 14px; background: #3f5a7a; }
.talk-box p { margin: 6px 0 0; font-size: 18px; line-height: 1.55; }
.talk-box p.narration { font-style: italic; color: #6b5a4a; }
.talk-box .choices { margin-top: 10px; }
.talk-box .choice { background: #fffdf6; color: #3d2616; border-color: #3d2616; }
.talk-box .choice:hover { background: #f3e7cf; }
.talk-box .choice[disabled] { opacity: .5; cursor: not-allowed; }
.more { position: absolute; right: 14px; bottom: 6px; font-size: 14px; color: #c8242b; animation: more 1s ease-in-out infinite; }
@keyframes more { 50% { transform: translateY(3px); } }
.choice { text-align: left; display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.choices { display: flex; flex-direction: column; gap: 8px; }
.tag { font-size: 14px; font-weight: 600; padding: 2px 8px; border-radius: 8px; background: #c23b2a; color: #fff; white-space: nowrap; }
.tag.plus { background: #3c9a5f; }

/* Người qua đường, chó mèo, xe máy (js/crowd.js) */
.step, .trot, .ride { transform-box: fill-box; transform-origin: 50% 100%; }
.step { animation: step .55s ease-in-out infinite; }
.trot { animation: step .3s ease-in-out infinite; }
.ride { animation: ride .18s linear infinite; }
.still, .off { animation-play-state: paused; }
/* bước chân: nhấc chân lên, đưa về trước, đặt xuống rồi đẩy ra sau (pha chạm đất);
   hai chân lệch nhau nửa nhịp. Nhún người (.step) cao nhất đúng lúc một chân đang nhấc. */
.step .leg, .walking .leg { animation: legstep .55s linear infinite; }
.walking .leg { animation-duration: .4s; }
.step .leg.r { animation-delay: -.275s; }
.walking .leg.r { animation-delay: -.2s; }
.still .leg, .off .leg { animation: none; }
@keyframes legstep {
  0%   { transform: translate(-6px, 0); }
  12%  { transform: translate(-4px, -5px); }
  25%  { transform: translate(0, -8px); }
  38%  { transform: translate(4px, -4px); }
  50%  { transform: translate(6px, 0); }
  100% { transform: translate(-6px, 0); }
}
@keyframes step { 0%, 100% { transform: translateY(0) rotate(0); } 25% { transform: translateY(-3px) rotate(-1.5deg); } 75% { transform: translateY(-3px) rotate(1.5deg); } }
@keyframes ride { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-1px); } }

.idle { animation: idle 2.4s ease-in-out infinite; }
.work { animation: idle .6s ease-in-out infinite; }   /* nhân viên đang làm cho khách */
.player { animation: idle 2s ease-in-out infinite; }
.player.walking { animation: walk .35s ease-in-out infinite; }
@keyframes idle { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-2px); } }
@keyframes walk { 0%, 100% { transform: translateY(0) rotate(0); } 25% { transform: translateY(-5px) rotate(-2deg); } 75% { transform: translateY(-5px) rotate(2deg); } }

/* Thẻ mở đầu ngày */
.sheet.day { text-align: center; }
.sheet.day h2 { margin-bottom: 6px; }
.sheet.day .row { justify-content: center; }

/* Màn chọn ước mơ: trang sổ kẻ ngang, giữ màu giấy ở cả chế độ tối */
.dream { position: fixed; inset: 0; z-index: 18; background: rgba(43, 28, 18, .7); overflow-y: auto; padding: calc(14px + env(safe-area-inset-top, 0px)) 12px calc(18px + env(safe-area-inset-bottom, 0px)); }
.notebook { max-width: 560px; margin: 0 auto; background: #fffdf6 repeating-linear-gradient(#fffdf6 0 27px, #d9e4ec 27px 28px); color: #3d2616; border: 2px solid #3d2616; border-left: 10px solid #c8655a; border-radius: 6px 14px 14px 6px; padding: 16px 16px 18px 20px; box-shadow: 0 6px 0 rgba(0, 0, 0, .25); }
.notebook h2 { color: #3d2616; }
.notebook .hint { color: #6b5a4a; }
.dream-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; margin-top: 10px; }
.dream-card { text-align: left; display: flex; flex-direction: column; gap: 3px; background: #fffdf6; color: #3d2616; border: 2px solid #3d2616; border-radius: 10px 14px 12px 10px; padding: 9px 11px; font-weight: 400; }
.dream-card b { font: 400 21px/1.1 "Patrick Hand", cursive; }
.dream-card .note { font-size: 15px; color: #6b5a4a; }
.dream-card .meta { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 2px; }
.dream-card .chip-s { font-size: 13px; font-weight: 600; padding: 1px 7px; border-radius: 8px; background: #efe3c4; color: #3d2616; }
.dream-card .chip-s.fit { background: #3c9a5f; color: #fff; }
.dream-card[aria-pressed="true"] { background: #fbe7c6; border-color: #c8242b; box-shadow: 0 0 0 2px #c8242b inset; }
.dream-confirm { margin-top: 12px; padding-top: 8px; border-top: 2px dashed #c9b99a; }
.notebook .row button { background: transparent; color: #3d2616; border-color: #3d2616; }
.notebook .row button.primary { background: #3d2616; color: #fffdf6; }
.dream-confirm p { margin: 0; font: 400 21px/1.3 "Patrick Hand", cursive; }

.toast { position: fixed; left: 50%; top: calc(152px + env(safe-area-inset-top, 0px)); transform: translateX(-50%); background: var(--btn); color: var(--btn-ink); padding: 10px 16px; border-radius: 10px; font-size: 16px; max-width: 90vw; z-index: 19; }
.overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 20; }
.sheet { background: var(--card); color: var(--text); border: 2px solid var(--text); border-radius: 10px 16px 12px 14px; padding: 18px; width: min(520px, 100%); max-height: 85vh; overflow: auto; }
.log { list-style: none; padding: 0; margin: 0; max-height: 55vh; overflow: auto; }
.log li { padding: 6px 0; border-bottom: 1px solid var(--rule); }
.stats { padding-left: 20px; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 600; }
[hidden] { display: none !important; }
/* Giảm chuyển động: vẫn đi lại trên phố, chỉ bỏ nhún nhảy và hiệu ứng phụ */
@media (prefers-reduced-motion: reduce) {
  .idle, .player, .player.walking, .step, .trot, .ride, .marker, .more, .talk, .next, .leg { animation: none !important; }
}

/* ---------- Nút kiểu kẹo: khối nổi, viền mực, vệt sáng trên đỉnh ---------- */
.btn { --c: #4f8a3c; position: relative; font: 400 22px/1.15 "Patrick Hand", cursive; color: #fffdf6; background: var(--c); border: 2.5px solid #3d2616; border-radius: 16px 18px 16px 14px; padding: 10px 14px 12px; box-shadow: 0 5px 0 rgba(61, 38, 22, .55), 0 7px 0 rgba(61, 38, 22, .25); box-shadow: 0 5px 0 color-mix(in srgb, var(--c) 55%, #3d2616), 0 7px 0 rgba(61, 38, 22, .25); text-shadow: 0 1.5px 0 rgba(61, 38, 22, .35); transition: transform .08s, box-shadow .08s; }
.btn::before { content: ""; position: absolute; left: 12px; right: 12px; top: 4px; height: 6px; border-radius: 6px; background: rgba(255, 255, 255, .35); pointer-events: none; }
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 rgba(61, 38, 22, .55); box-shadow: 0 1px 0 color-mix(in srgb, var(--c) 55%, #3d2616); }
.btn.big { width: 100%; font-size: 30px; padding: 12px 16px 14px; }
.btn.mid { font-size: 22px; }
.btn.small { font-size: 18px; padding: 7px 10px 9px; }
.btn.tiny { font-size: 17px; padding: 4px 10px 6px; }
.btn.green { --c: #4f8a3c; } .btn.blue { --c: #5b86b5; } .btn.teal { --c: #2f8a7c; } .btn.teal2 { --c: #3d9a8a; }
.btn.orange { --c: #e0892a; } .btn.red { --c: #b8392a; } .btn.purple { --c: #7a5aa8; } .btn.slate { --c: #5e7183; }
.btn.ghost { --c: #efe3c4; color: #3d2616; text-shadow: none; }
.btn small { display: block; font: 400 14px/1.3 "Patrick Hand", cursive; opacity: .9; margin-top: 2px; text-shadow: none; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 14px 0; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 14px 0 6px; }
.sheet.paper { background: #fffdf6; color: #3d2616; border: 2.5px solid #3d2616; border-radius: 18px 22px 20px 16px; box-shadow: 0 8px 0 rgba(0, 0, 0, .25); }
.sheet.paper h2 { color: #b8392a; text-align: center; font-size: 40px; margin: 4px 0 2px; }
.sheet.paper label, .sheet.paper .hint { color: #6b5a4a; }
.sheet.paper #nameInput { color: #3d2616; border-bottom-color: #3d2616; font-size: 20px; }
.sheet.paper .row { justify-content: center; }
.pause .sub { text-align: center; margin: 0 0 14px; font: 400 18px/1.3 "Patrick Hand", cursive; color: #6b5a4a; }
.pause .pid { text-align: center; margin: 10px 0 0; font: 400 19px/1.4 "Patrick Hand", cursive; }
.pause.at-home-menu .game-only { display: none; }

/* ---------- Trang chủ: phố chạy chậm phía sau ---------- */
.home { position: fixed; inset: 0; z-index: 12; display: flex; align-items: center; justify-content: center; padding: 16px; background: linear-gradient(rgba(251, 247, 236, .15), rgba(43, 28, 18, .55)); }
.home-inner { width: min(420px, 100%); display: flex; flex-direction: column; gap: 14px; }
.logo { text-align: center; margin-bottom: 8px; }
.logo h1 { font: 400 76px/1 "Patrick Hand", cursive; color: #b8392a; margin: 0; -webkit-text-stroke: 2px #3d2616; text-shadow: 0 5px 0 #3d2616, 0 8px 14px rgba(0, 0, 0, .3); letter-spacing: 1px; transform: rotate(-3deg); }
.logo .tagline { display: inline-block; margin: 14px 0 0; font: 400 19px/1.3 "Patrick Hand", cursive; color: #3d2616; background: #fffdf6; border: 2px solid #3d2616; border-radius: 12px; padding: 4px 12px; transform: rotate(1.5deg); }
.home-menu { display: flex; flex-direction: column; gap: 14px; }
.home-menu .grid2 { margin: 0; }
.home-foot { text-align: center; margin: 4px 0 0; font: 400 17px/1 "Patrick Hand", cursive; color: #fffdf6; text-shadow: 0 1px 2px rgba(0, 0, 0, .6); }
.at-home .hud, .at-home .next, .at-home .swipe-hint { display: none !important; }
.at-home .stage { pointer-events: none; }

/* ---------- Tạm dừng: mọi chuyển động trên phố đứng yên ---------- */
.paused #street *, .paused #street, .paused #streetBg * { animation-play-state: paused !important; }

/* ---------- Ảnh chụp ---------- */
.flash { position: fixed; inset: 0; z-index: 40; background: #fff; pointer-events: none; animation: flash .45s ease-out forwards; }
@keyframes flash { from { opacity: .95; } to { opacity: 0; } }
.sheet.photo { text-align: center; padding: 14px; }
.sheet.photo img { display: block; width: 100%; max-height: 62vh; object-fit: contain; border-radius: 6px; background: #efe3c4; -webkit-touch-callout: default; user-select: auto; }
.sheet.photo .hint { margin: 10px 0 0; }

/* ---------- Icon vẽ tay (js/icons.js) ---------- */
.ico { width: 1.25em; height: 1.25em; vertical-align: -0.25em; margin-right: .3em; overflow: visible; flex: none; }
.btn .ico { filter: drop-shadow(0 1.5px 0 rgba(61, 38, 22, .35)); }
.btn.big .ico { width: 1.1em; height: 1.1em; }
.btn.tiny .ico { width: 1.1em; height: 1.1em; }
.chip { display: inline-flex; align-items: center; }
.chip .ico { width: 18px; height: 18px; margin-right: 4px; }
/* nút trong màn thoại: nhỏ, có màu, icon kem */
.chip { background: #5e7183; color: #fffdf6; box-shadow: 0 3px 0 rgba(0, 0, 0, .3); font-weight: 600; }
#btnAuto.chip { background: #7a5aa8; }
.chip[aria-pressed="true"] { background: #3c9a5f; color: #fffdf6; }
.next.btn:active { transform: translate(-50%, 3px); }
.next.btn { position: absolute; padding: 9px 20px 11px; font-size: 22px; }
.home .btn.big { display: flex; flex-direction: column; align-items: center; }
.home .btn.big > .ico { position: absolute; left: 18px; top: 50%; transform: translateY(-50%); width: 36px; height: 36px; }
/* chữ trên nút lưới luôn một dòng */
.grid2 .btn, .grid3 .btn { white-space: nowrap; padding-left: 8px; padding-right: 8px; }
.grid2 .btn.mid { font-size: 19px; }
.grid3 .btn.small { font-size: 17px; }
.grid3 .btn .ico { margin-right: .15em; }

/* ---------- Chương 3: làm ăn (work.js) ---------- */
.daybtn { pointer-events: auto; font-family: inherit; font-size: 16px; color: var(--text); display: inline-flex; align-items: center; gap: 4px; cursor: pointer; font-weight: 600; }
.daybtn .ico { width: 22px; height: 22px; }
/* Thời tiết ở thành phố Mơ (#wx đè lên phố, không bắt chạm): mưa rơi, bão (tối trời, chớp), ngập (mưa nhỏ; nước vẽ trong SVG ở live.js), nắng (quầng nắng góc trên) */
.wx { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.wx::before, .wx::after { content: ""; position: absolute; inset: 0; }
.wx-mua::before, .wx-bao::before, .wx-ngap::before { inset: -64px -64px 0 0; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='64' height='64'%3E%3Cg stroke='%235f7f99' stroke-width='1.6' stroke-linecap='round' opacity='.75'%3E%3Cpath d='M6 4l-3 12M30 22l-3 12M50 6l-3 12M18 40l-3 12M44 44l-3 12M62 30l-3 12'/%3E%3C/g%3E%3C/svg%3E"); animation: rain .32s linear infinite; }
.wx-bao::before { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='64' height='64'%3E%3Cg stroke='%235f7f99' stroke-width='1.6' stroke-linecap='round' opacity='.75'%3E%3Cpath d='M6 4l-3 12M30 22l-3 12M50 6l-3 12M18 40l-3 12M44 44l-3 12M62 30l-3 12'/%3E%3C/g%3E%3C/svg%3E"), url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='64' height='64'%3E%3Cg stroke='%235f7f99' stroke-width='1.6' stroke-linecap='round' opacity='.75'%3E%3Cpath d='M6 4l-3 12M30 22l-3 12M50 6l-3 12M18 40l-3 12M44 44l-3 12M62 30l-3 12'/%3E%3C/g%3E%3C/svg%3E"); background-size: 64px 64px, 44px 44px; background-position: 0 0, 20px 10px; animation-duration: .22s; }
.wx-ngap::before { opacity: .55; animation-duration: .45s; }
.wx-mua::after { background: rgba(90, 112, 135, .16); }
.wx-ngap::after { background: rgba(90, 112, 135, .12); }
.wx-bao::after { background: rgba(38, 48, 66, .34); animation: flash 7s linear infinite; }
.wx-nang::after { background: radial-gradient(circle at 92% 4%, rgba(255, 214, 90, .42), rgba(255, 214, 90, .12) 22%, transparent 45%); }
.night .wx-nang::after { display: none; }
@keyframes rain { to { transform: translate(-16px, 64px); } }
@keyframes flash { 0%, 90%, 92.5%, 95.5%, 100% { background: rgba(38, 48, 66, .34); } 91% { background: rgba(255, 253, 230, .55); } 94% { background: rgba(255, 253, 230, .35); } }
.water .wave { animation: wave 2.4s linear infinite; }
@keyframes wave { to { transform: translateX(-40px); } }
@media (prefers-reduced-motion: reduce) { .wx::before, .wx::after, .water .wave { animation: none !important; } }
.paused .wx::before, .paused .wx::after { animation-play-state: paused; }
/* đèn đường thành phố Mơ: chỉ sáng ban đêm */
.lamp-glow { display: none; }
.night .lamp-glow { display: inline; }
/* ban đêm phủ tối cả phố, trừ một vòng sáng như ban ngày quanh nhân vật chính (--lx, --ly, --lr do game.js đặt theo vị trí trên màn hình) */
.night .stage::after { content: ""; position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(circle at var(--lx, -999px) var(--ly, -999px), transparent 0, transparent calc(var(--lr, 60px) * .55), rgba(18, 28, 66, .45) var(--lr, 60px)); }
.work { position: absolute; left: 0; right: 0; bottom: 0; z-index: 7; padding: 0 10px calc(10px + env(safe-area-inset-bottom, 0px)); pointer-events: none; }
.work-sheet { pointer-events: auto; max-width: 560px; margin: 0 auto; background: #fffdf6; color: #3d2616; border: 2.5px solid #3d2616; border-radius: 16px 20px 14px 18px; padding: 10px 14px 12px; max-height: 50vh; overflow-y: auto; box-shadow: 0 6px 0 rgba(0, 0, 0, .25); }
.work-sheet h3 { font: 400 24px/1.1 "Patrick Hand", cursive; margin: 0 0 2px; color: #b8392a; }
.work-sheet .hint { color: #6b5a4a; margin: 0 0 8px; }
.work-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; }
.work-pick { text-align: left; display: flex; flex-direction: column; gap: 1px; background: #fffdf6; color: #3d2616; border: 2px solid #3d2616; border-radius: 10px 14px 12px 10px; padding: 7px 10px; font-weight: 400; }
.work-pick b { font: 400 20px/1.1 "Patrick Hand", cursive; }
.work-pick span { font-size: 15px; color: #6b5a4a; }
.work-pick i { font-style: normal; font-size: 13px; font-weight: 600; align-self: flex-start; margin-top: 3px; padding: 1px 7px; border-radius: 8px; background: #efe3c4; }
.work-pick i.auto { background: #3c9a5f; color: #fff; }
.work-sheet .choice { background: #fffdf6; color: #3d2616; border-color: #3d2616; }
.work-tools { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.work-tools .btn.small { font-size: 17px; }
.work-sleep { width: 100%; margin-top: 8px; }
.work-result { list-style: none; margin: 4px 0; padding: 0; }
.work-result li { padding: 3px 0; border-bottom: 1px dashed #d9c9a8; }
.work-result li span { float: right; font-weight: 600; }
.work-result i { font-size: 15px; color: #6b5a4a; }
.work-total { margin: 6px 0 0; font: 400 21px/1.2 "Patrick Hand", cursive; }
.plus { color: #2f7a3f; } .minus { color: #b8392a; }
.work-sheet .muted, .work-dlg .muted { color: #8a7a66; }
.work-dlg { width: min(620px, 100%); box-sizing: border-box; }   /* tính cả phần đệm, không tràn màn điện thoại */
.work-dlg h4 { margin: 12px 0 4px; font: 400 21px/1.1 "Patrick Hand", cursive; color: #3d2616; }
.work-dlg .center { text-align: center; }
.inv-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.inv { display: flex; flex-direction: column; gap: 2px; border: 2px solid #3d2616; border-radius: 10px 14px 12px 10px; padding: 7px 10px; }
.inv span { font-size: 15px; color: #6b5a4a; }
.inv em { font-style: normal; font-size: 15px; font-weight: 600; color: #2f7a3f; }
.inv .btn { align-self: flex-start; margin-top: 4px; }
.inv.locked { opacity: .6; border-style: dashed; }
.ledger table { width: 100%; border-collapse: collapse; font-size: 15px; }
.ledger th, .ledger td { border-bottom: 1px solid #e3d6bd; padding: 4px 3px; text-align: left; vertical-align: top; }
.ledger th:nth-child(n+2), .ledger td:nth-child(n+2) { text-align: right; white-space: nowrap; }
.ledger td small { display: block; color: #8a7a66; font-size: 13px; }
.ledger tfoot td { font-weight: 600; border-bottom: 0; }
.ledger tfoot tr:last-child td { font-weight: 400; color: #6b5a4a; text-align: left; }
.book-day { margin-bottom: 10px; }
.bank-card { background: linear-gradient(135deg, #1f4f7a, #2f7a6b); color: #fff; border-radius: 14px; padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; border: 2px solid #3d2616; }
.bank-card span { font-size: 14px; opacity: .9; letter-spacing: .5px; }
.bank-card b { font-size: 26px; margin-top: 4px; }
.bank-list { list-style: none; margin: 8px 0 0; padding: 0; font-size: 15px; }
.bank-d { font-weight: 600; color: #6b5a4a; padding: 8px 0 2px; border-bottom: 2px solid #3d2616; }
.bank-t { display: grid; grid-template-columns: 42px 1fr auto; gap: 6px; padding: 5px 0; border-bottom: 1px solid #e3d6bd; }
.bank-t .t { color: #8a7a66; }
.bank-t small { display: block; color: #8a7a66; font-size: 13px; }
.bank-t .a { text-align: right; font-weight: 600; white-space: nowrap; }
.bank-t .a small { font-weight: 400; }

/* mốc đã qua */
#btnMoc { width: 100%; margin-top: 8px; }
.moc-list { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; max-height: 55vh; overflow-y: auto; }
.moc-item { width: 100%; text-align: left; display: flex; flex-direction: column; gap: 1px; background: #fffdf6; color: #3d2616; border: 2px solid #3d2616; border-radius: 10px 14px 12px 10px; padding: 7px 10px; font-weight: 400; }
.moc-item b { font: 400 19px/1.2 "Patrick Hand", cursive; }
.moc-item small { font-size: 14px; color: #8a7a66; }
.moc-item em { display: none; font-style: normal; font-size: 15px; font-weight: 600; color: #b8392a; }
.moc-item.armed { background: #fbe7c6; border-color: #c8242b; }
.moc-item.armed em { display: block; }

/* đồng hồ, đang làm */
.work-clock { margin: 2px 0 6px; font: 400 20px/1.2 "Patrick Hand", cursive; }
.work-feed { list-style: none; margin: 0; padding: 0; font-size: 15px; min-height: 96px; }
.work-feed li { padding: 3px 0; border-bottom: 1px dashed #d9c9a8; animation: talkIn .25s ease-out; }
.work-feed .t { color: #8a7a66; margin-right: 4px; }
.work-feed small { color: #8a7a66; }
.work-feed b { float: right; }

/* chương 3: hàng nút nhỏ, khách tới cửa hàng */
.work-bar { position: absolute; left: 50%; bottom: calc(10px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); z-index: 7; display: flex; gap: 5px; padding: 5px; background: rgba(255, 253, 246, .88); border: 2px solid #3d2616; border-radius: 14px; max-width: calc(100% - 16px); overflow-x: auto; }
.work-bar .wk { display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 4px 7px; min-width: 52px; border: 0; border-radius: 9px; background: transparent; color: #3d2616; font: 400 13px/1.1 "Patrick Hand", cursive; white-space: nowrap; }
.work-bar .wk .ico { width: 24px; height: 24px; margin: 0; }
.work-bar .wk:active { background: #efe3c4; }
.talking .work-bar { visibility: hidden; }
.work-pick.here { border-color: #2f7a3f; box-shadow: 0 0 0 2px #2f7a3f inset; }
.float-up { animation: floatUp 1.5s ease-out forwards; }
@keyframes floatUp { from { opacity: 1; translate: 0 0; } to { opacity: 0; translate: 0 -34px; } }

/* hình vẽ trong màn thoại (ổ bánh mì…) */
.talk-pic { display: flex; justify-content: center; margin: -4px 0 6px; }
.talk-pic[hidden] { display: none; }
.talk-pic-svg { width: min(260px, 70vw); height: auto; animation: talkIn .4s ease-out; }

/* mã bản lưu */
.home-import { width: 100%; margin-top: 8px; font-size: 17px; }
.sheet .wide { width: 100%; margin-top: 8px; }
.code-sheet h2 { font-size: 32px; }
.code-text { width: 100%; min-height: 120px; max-height: 34vh; font: 12px/1.35 ui-monospace, Menlo, Consolas, monospace; color: #3d2616; background: #fffdf6; border: 2px solid #3d2616; border-radius: 10px; padding: 8px; word-break: break-all; resize: vertical; }
.file-btn { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }

/* ---------- Điều kiện nâng cấp, màn giấy tờ, bài kiểm tra (thành phố Mơ) ---------- */
.inv .inv-cond { font-size: 14px; color: #6b5a4a; line-height: 1.45; }
.inv .deal { color: #c8242b; font-weight: 600; }
.cond-list { list-style: none; margin: 8px 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.cond { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; border: 2px solid #3d2616; border-radius: 10px 12px 10px 12px; padding: 6px 10px; font-size: 16px; }
.cond > span:nth-child(2) { flex: 1 1 160px; }
.cond .mark { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; color: #fffdf6; flex: none; }
.cond.ok .mark { background: #2f7a3f; }
.cond.miss .mark { background: #c8242b; }
.cond.info .mark { background: #5b86b5; font-style: italic; }
.cond.miss { background: #fff4ec; color: #3d2616; }
.paper { position: relative; background: #fffdf6; color: #3d2616; border: 2px solid #3d2616; border-radius: 6px 10px 8px 12px; padding: 12px; margin: 6px 0 10px; }
.paper-head { font: 400 20px/1.2 "Patrick Hand", cursive; text-align: center; padding: 6px; margin: -12px -12px 10px; border-bottom: 2px solid #3d2616; border-radius: 6px 10px 0 0; color: #fffdf6; background: #1f3a68; }
.paper-vehicle .paper-head { background: #2f4f7a; }
.paper-app .paper-head { background: #2f9a5f; }
.paper-course .paper-head { background: #8a5a3b; }
.paper-inspect .paper-head { background: #6b4a8a; }
.paper-say { font-size: 16px; margin: 0 0 8px; }
.paper h4 { margin: 8px 0 4px; font-size: 16px; }
.paper-docs { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.paper .doc { box-sizing: border-box; width: 100%; text-align: left; background: #f3efe4; color: #3d2616; border: 1.5px dashed #8a7a66; border-radius: 6px; padding: 6px 10px 6px 32px; position: relative; font-size: 16px; }
.paper .doc::before { content: ""; position: absolute; left: 9px; top: 50%; width: 14px; height: 14px; margin-top: -8px; border: 2px solid #3d2616; border-radius: 3px; background: #fffdf6; }
.paper .doc.on { border-style: solid; border-color: #2f7a3f; background: #e6f2e4; }
.paper .doc.on::after { content: "✓"; position: absolute; left: 11px; top: 50%; margin-top: -11px; font-weight: 700; color: #2f7a3f; }
.paper-fee, .paper-ticket { font-size: 16px; margin: 8px 0; text-align: center; }
.paper-ticket { border: 2px dashed #8a7a66; border-radius: 6px; padding: 8px; background: #f3efe4; }
.stamp { width: max-content; margin: 10px auto 4px; padding: 6px 16px; border: 4px double #c8242b; border-radius: 8px; color: #c8242b; font: 400 26px/1 "Patrick Hand", cursive; letter-spacing: 2px; transform: rotate(-8deg); opacity: .9; }
.quiz { display: flex; flex-direction: column; gap: 6px; }
.quiz .btn { text-align: left; white-space: normal; }
/* hơi nóng bốc lên từ nồi phở, khay cơm trên xe đẩy */
.steam path { animation: steam 1.8s ease-out infinite; transform-box: fill-box; transform-origin: 50% 100%; }
@keyframes steam { 0% { opacity: 0; transform: translateY(4px) scaleY(.6); } 30% { opacity: .85; } 100% { opacity: 0; transform: translateY(-10px) scaleY(1.1); } }
@media (prefers-reduced-motion: reduce) { .steam path { animation: none; } }
.inv .inv-perk { font-size: 14px; color: #2f6b3a; line-height: 1.45; }
.inv .hire { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 6px; padding-top: 6px; border-top: 1px dashed #c9b8a0; }
.inv .hire span { flex: 1 1 180px; font-size: 15px; color: #3d2616; }
.inv .hire .btn { margin-top: 0; }
/* cãi nhau, đánh nhau trên phố: người rung lắc */
.fight { animation: fight .28s ease-in-out infinite; transform-box: fill-box; transform-origin: 50% 100%; }
@keyframes fight { 0%, 100% { transform: translateX(0) rotate(0); } 25% { transform: translateX(-2px) rotate(-4deg); } 75% { transform: translateX(2px) rotate(4deg); } }
@media (prefers-reduced-motion: reduce) { .fight { animation: none; } }
.rename { display: flex; justify-content: center; margin: 8px 0; }
.rename input { width: min(320px, 100%); box-sizing: border-box; font-size: 18px; padding: 8px 10px; border: 2px solid #3d2616; border-radius: 10px; background: #fffdf6; color: #3d2616; }
.err { color: #c8242b; min-height: 1em; }

/* ---------- Hướng dẫn, xác nhận 18 tuổi ---------- */
.guide { width: min(620px, 100%); box-sizing: border-box; }
.guide-tabs, .guide-os { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; margin: 4px 0 10px; }
.gtab, .gos { border: 2px solid #3d2616; background: #fffdf6; color: #3d2616; border-radius: 10px 12px 10px 12px; padding: 6px 12px; font: 400 16px/1.2 "Patrick Hand", cursive; }
.gtab.on, .gos.on { background: #3d2616; color: #fffdf6; }
.gsteps { list-style: none; counter-reset: st; margin: 6px 0 10px; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.gsteps li { counter-increment: st; display: flex; gap: 10px; align-items: center; }
.gsteps li > p::before { content: "Bước " counter(st) ". "; font-weight: 600; color: #c8242b; }
.gsteps p { margin: 0; font-size: 16px; }
.gpic { flex: none; width: 92px; height: 150px; }
.gpic svg { width: 100%; height: 100%; display: block; }
.guide details { border: 2px solid #3d2616; border-radius: 10px; padding: 6px 10px; margin: 6px 0; background: #fffdf6; color: #3d2616; }
.guide summary { font-weight: 600; cursor: pointer; }
.guide details p { margin: 6px 0 2px; font-size: 16px; }
.guide a.btn { text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
.age { z-index: 40; }
.age .sheet { text-align: center; }
/* màn điện thoại hẹp: bảng không tràn lề (chữ viết tay to hơn) */
.overlay .sheet { max-width: calc(100vw - 24px); box-sizing: border-box; }
.inv, .inv-list, .cond, .hire { min-width: 0; }
.inv span, .inv small, .inv b, .hire span { overflow-wrap: anywhere; }
.inv .hire { flex-wrap: wrap; }
.inv .hire span { flex: 1 1 100%; }
