/* Nông Trại Pixel 3D — giao diện bảng gỗ + giấy, viền pixel (box-shadow bốn hướng), font VT323 có đủ dấu tiếng Việt */
:root {
  --px: 3px;
  --bg: #231508; --wood: #7a4a26; --wood2: #a8743c; --wood3: #4e2f18; --paper: #f6ecd0; --paper2: #ecdcb0; --paper3: #e0cc98;
  --ink: #3a2a1a; --muted: #7a6648; --green: #58c04a; --green2: #2e8b3d; --gold: #f2b531; --red: #d8402e; --blue: #3a8fe0; --line: #3a2a1a;
  --pxb: 0 calc(var(--px) * -1) 0 0 var(--line), 0 var(--px) 0 0 var(--line), calc(var(--px) * -1) 0 0 0 var(--line), var(--px) 0 0 0 var(--line);
  --sa-t: env(safe-area-inset-top, 0px); --sa-b: env(safe-area-inset-bottom, 0px); --sa-l: env(safe-area-inset-left, 0px); --sa-r: env(safe-area-inset-right, 0px);
  font-family: 'VT323', 'Courier New', monospace;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); overflow: hidden; overscroll-behavior: none; font-size: 22px; line-height: 1.1; -webkit-user-select: none; user-select: none; touch-action: none; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; padding: 0; }
img { image-rendering: pixelated; }
#app { position: fixed; inset: 0; overflow: hidden; }
#stage { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; overflow: hidden; background: #8fd4f0; touch-action: none; }
#stage canvas { flex: none; image-rendering: pixelated; image-rendering: crisp-edges; image-rendering: pixelated; display: block; }
#labels, #fx { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }

/* ---------- nút / khung ---------- */
.ib, .tool, .nb, .btn, .chip { position: relative; background: var(--wood); color: #fff6dc; box-shadow: var(--pxb), inset 0 -4px 0 rgba(0,0,0,.35), inset 0 3px 0 rgba(255,255,255,.18); margin: var(--px); text-shadow: 0 2px 0 rgba(0,0,0,.45); }
.ib { width: 38px; height: 38px; font-size: 24px; display: grid; place-items: center; }
.btn { padding: 6px 12px 8px; font-size: 21px; min-height: 36px; }
.btn.green { background: var(--green2); } .btn.gold { background: #c98a1a; } .btn.red { background: #a8321f; } .btn.blue { background: #2a6ab8; }
.btn:disabled, .btn.off { background: #6a6258; color: #b8ae9c; box-shadow: var(--pxb), inset 0 -4px 0 rgba(0,0,0,.25); cursor: default; text-shadow: none; }
.ib:active, .tool:active, .nb:active, .btn:active:not(:disabled) { transform: translateY(2px); }
:focus-visible { outline: 3px solid #5ad2e6; outline-offset: 2px; }

/* ---------- thanh trên ---------- */
#hud { position: absolute; left: 0; right: 0; top: 0; display: flex; align-items: center; gap: 6px; padding: calc(var(--sa-t) + 6px) calc(var(--sa-r) + 8px) 4px calc(var(--sa-l) + 8px); pointer-events: none; }
#hud > * { pointer-events: auto; }
.lvl { color: #fff6dc; width: 46px; height: 46px; flex: none; background: var(--green2); display: grid; place-items: center; align-content: center; }
.lvl .lv-n { font-size: 28px; line-height: .9; } .lvl small { font-size: 13px; opacity: .85; line-height: .8; }
.xp { flex: 1; min-width: 56px; margin: var(--px); }
.xpbar { height: 14px; background: var(--wood3); box-shadow: var(--pxb); position: relative; overflow: hidden; }
.xpbar i { display: block; height: 100%; width: 0; background: repeating-linear-gradient(90deg, #7ae060 0 6px, #58c04a 6px 12px); transition: width .6s steps(8); }
.xp small { display: block; font-size: 15px; color: #fff6dc; text-shadow: 0 2px 0 #000, 0 0 3px #000; margin-top: 2px; }
.money, .clock { display: flex; align-items: center; gap: 5px; background: var(--wood3); color: #fff6dc; padding: 4px 8px 5px; margin: var(--px); box-shadow: var(--pxb); font-size: 24px; }
.money b { min-width: 2ch; text-align: right; }
.coin { width: 16px; height: 16px; background: var(--gold); box-shadow: 0 -2px 0 #8a5a10, 0 2px 0 #8a5a10, -2px 0 0 #8a5a10, 2px 0 0 #8a5a10, inset 3px 3px 0 #ffe27a, inset -3px -3px 0 #d8901a; display: inline-block; }
.clock { font-size: 20px; padding: 4px 7px 5px; } .clock span { font-size: 18px; }
@media (max-width: 400px) { .clock span { display: none; } .money { font-size: 22px; } }

#chips { position: absolute; left: calc(var(--sa-l) + 8px); right: calc(var(--sa-r) + 8px); top: calc(var(--sa-t) + 62px); display: flex; gap: 2px; flex-wrap: nowrap; pointer-events: none; }
.chip { display: flex; align-items: center; gap: 5px; padding: 3px 8px 5px; font-size: 20px; pointer-events: auto; background: var(--wood3); }
.chip b { min-width: 1.4ch; } .chip i { font-style: normal; font-size: 15px; opacity: .8; }
.chip { flex: none; } .chip.ev { flex: 1 1 0; min-width: 0; } .chip.ev em { font-style: normal; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip.up { background: #2a6a30; }

#tip { position: absolute; left: 50%; transform: translateX(-50%); width: max-content; top: calc(var(--sa-t) + 110px); max-width: min(86vw, 480px); background: var(--paper); color: var(--ink); padding: 6px 12px 8px; margin: var(--px); box-shadow: var(--pxb); font-size: 19px; text-align: center; pointer-events: none; display: none; }
#tip.on { display: block; animation: bob 1.4s steps(2) infinite; }
@keyframes bob { 50% { transform: translateX(-50%) translateY(-3px); } }

/* ---------- camera ---------- */
#side { position: absolute; right: calc(var(--sa-r) + 6px); top: 40%; transform: translateY(-50%); display: flex; flex-direction: column; }

/* ---------- dock ---------- */
#dock { position: absolute; left: 0; right: 0; bottom: 0; padding: 0 calc(var(--sa-r) + 6px) calc(var(--sa-b) + 4px) calc(var(--sa-l) + 6px); display: flex; flex-direction: column; gap: 2px; pointer-events: none; }
#dock > * { pointer-events: auto; }
#toolrow { display: flex; align-items: stretch; gap: 0; min-height: 70px; }
.tool { flex: none; width: 52px; display: grid; place-items: center; align-content: center; font-size: 17px; background: var(--wood3); } .tool span { font-size: 22px; line-height: 1; }
.tool.on { background: var(--green2); }
#seeds { flex: 1; min-width: 0; display: flex; gap: 2px; overflow-x: auto; overflow-y: hidden; padding: 4px 4px 6px; margin: var(--px); background: rgba(35, 21, 8, .78); box-shadow: var(--pxb); scrollbar-width: none; touch-action: pan-x; }
#seeds::-webkit-scrollbar { display: none; }
.seed { flex: none; width: 60px; background: var(--paper2); box-shadow: var(--pxb), inset 0 -3px 0 rgba(0,0,0,.18); margin: var(--px); padding: 2px 0 3px; display: grid; place-items: center; text-align: center; color: var(--ink); font-size: 16px; line-height: 1; position: relative; }
.seed img { width: 32px; height: 32px; } .seed small { font-size: 15px; color: var(--muted); }
.seed.sel { background: #fff3b0; box-shadow: 0 0 0 var(--px) var(--gold), 0 0 0 calc(var(--px) * 2) var(--line), inset 0 -3px 0 rgba(0,0,0,.18); }
.seed.lock { filter: grayscale(1) brightness(.8); opacity: .7; }
.seed.lock::after { content: attr(data-lock); position: absolute; inset: 0; display: grid; place-items: center; background: rgba(30, 20, 10, .62); color: #fff; font-size: 16px; text-align: center; }
.seed.fish { background: #cfe8f6; }
#nav { display: flex; gap: 0; }
.nb { flex: 1; min-width: 0; padding: 5px 0 6px; display: grid; place-items: center; font-size: 16px; line-height: 1; } .nb span { font-size: 24px; line-height: 1.1; }
.badge { position: absolute; top: -6px; right: -4px; min-width: 20px; height: 20px; padding: 0 4px; background: var(--red); color: #fff; font-style: normal; font-size: 16px; line-height: 20px; box-shadow: var(--pxb); display: none; text-align: center; text-shadow: none; }
.badge.on { display: block; }

/* ---------- nhãn trên bản đồ, chữ nổi ---------- */
.lab { position: absolute; transform: translate(-50%, -100%); background: rgba(246, 236, 208, .92); color: var(--ink); padding: 1px 6px 3px; font-size: 17px; white-space: nowrap; box-shadow: var(--pxb); }
.lab.lock { background: rgba(60, 40, 20, .9); color: #ffe9b0; } .lab.dim { opacity: .0; }
.lab.zone { background: rgba(88, 192, 74, .92); color: #fff; text-shadow: 0 1px 0 rgba(0,0,0,.5); }
.fxt { position: absolute; transform: translate(-50%, -50%); font-size: 26px; color: #fff; text-shadow: 0 2px 0 #000, 2px 0 0 #000, -2px 0 0 #000, 0 -2px 0 #000; white-space: nowrap; animation: rise 1.15s steps(12) forwards; display: flex; align-items: center; gap: 3px; }
.fxt img { width: 26px; height: 26px; } .fxt.gold { color: #ffe27a; } .fxt.red { color: #ff7a6a; } .fxt.blue { color: #8ad0ff; }
@keyframes rise { 0% { opacity: 0; margin-top: 8px; } 12% { opacity: 1; } 80% { opacity: 1; } 100% { opacity: 0; margin-top: -46px; } }

/* ---------- thông báo ---------- */
#toasts { position: absolute; left: 0; right: 0; bottom: calc(var(--sa-b) + 168px); display: flex; flex-direction: column; align-items: center; gap: 4px; pointer-events: none; z-index: 5; }
.toast { background: var(--paper); color: var(--ink); padding: 5px 12px 7px; margin: var(--px); box-shadow: var(--pxb); font-size: 20px; max-width: 92vw; text-align: center; animation: pop .25s steps(4), fade .4s steps(4) 2.6s forwards; }
.toast.good { background: #d8f2c0; } .toast.bad { background: #f8d0c8; } .toast.lv { background: var(--gold); font-size: 26px; padding: 8px 18px 10px; }
@keyframes pop { from { transform: scale(.6); opacity: 0; } } @keyframes fade { to { opacity: 0; transform: translateY(-8px); } }

/* ---------- bảng (sheet) ---------- */
#sheetWrap { position: absolute; inset: 0; display: none; z-index: 10; }
#sheetWrap.on { display: block; }
#sheetBack { position: absolute; inset: 0; background: rgba(20, 12, 4, .55); }
#sheet { position: absolute; left: 50%; bottom: 0; transform: translateX(-50%); width: min(100vw, 560px); max-height: calc(100% - var(--sa-t) - 56px); display: flex; flex-direction: column; background: var(--paper); color: var(--ink); box-shadow: var(--pxb), 0 -6px 0 var(--wood); animation: up .22s steps(5); margin-bottom: 0; border-top: 6px solid var(--wood2); }
@keyframes up { from { transform: translateX(-50%) translateY(40px); opacity: 0; } }
@media (min-width: 720px) { #sheet { bottom: 50%; transform: translate(-50%, 50%); max-height: 86%; animation: none; border: 0; margin: 0; } }
#sheet > header { display: flex; align-items: center; justify-content: space-between; background: var(--wood); color: #fff6dc; padding: 4px 6px 4px 14px; text-shadow: 0 2px 0 rgba(0,0,0,.45); }
#sheet h2 { margin: 0; font-size: 28px; font-weight: 400; }
#sheetTabs { display: flex; gap: 0; padding: 6px 8px 0; background: var(--paper2); overflow-x: auto; scrollbar-width: none; }
#sheetTabs:empty { display: none; }
.tab { flex: none; padding: 4px 12px 5px; font-size: 21px; background: var(--paper3); color: var(--muted); margin: 0 3px 0 0; box-shadow: var(--pxb); } .tab.on { background: var(--paper); color: var(--ink); }
#sheetBody { padding: 10px 10px calc(var(--sa-b) + 14px); overflow-y: auto; overscroll-behavior: contain; touch-action: pan-y; -webkit-user-select: text; user-select: text; flex: 1; }
.card { display: flex; align-items: center; gap: 10px; background: var(--paper2); margin: 8px 4px; padding: 8px 10px; box-shadow: var(--pxb); }
.card.lock { opacity: .72; } .card.hl { background: #fff3b0; } .card.done { background: #d8f2c0; }
.card img.ico { width: 44px; height: 44px; flex: none; }
.card .meta { flex: 1; min-width: 0; } .card .meta b { font-size: 24px; font-weight: 400; display: block; } .card .meta small { display: block; font-size: 17px; color: var(--muted); line-height: 1.05; margin-top: 2px; }
.card .act { flex: none; display: flex; flex-direction: column; align-items: flex-end; gap: 2px; text-align: right; }
.price { font-size: 22px; display: inline-flex; align-items: center; gap: 4px; } .price .coin { width: 13px; height: 13px; }
.up { color: #2a8a30; } .down { color: #b8321f; } .sub { font-size: 17px; color: var(--muted); }
.note { background: #fff3b0; padding: 6px 10px 8px; margin: 6px 4px; box-shadow: var(--pxb); font-size: 19px; line-height: 1.1; }
.note.blue { background: #d8ecfa; } .note.green { background: #d8f2c0; }
.bar { height: 12px; background: var(--paper3); box-shadow: var(--pxb); margin: 5px 3px 3px; overflow: hidden; } .bar i { display: block; height: 100%; background: repeating-linear-gradient(90deg, #7ae060 0 6px, #58c04a 6px 12px); }
.row { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; } .row.end { justify-content: flex-end; }
.lines { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 3px; } .line { display: inline-flex; align-items: center; gap: 2px; font-size: 20px; } .line img { width: 28px; height: 28px; } .line.miss { color: #b8321f; }
h3 { font-size: 24px; margin: 12px 4px 2px; font-weight: 400; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 4px; } .stat { background: var(--paper2); margin: 6px 4px; padding: 6px 10px 8px; box-shadow: var(--pxb); } .stat b { display: block; font-size: 28px; font-weight: 400; } .stat small { font-size: 17px; color: var(--muted); }
a { color: #2a6ab8; }
.tiers .btn { padding: 2px 9px 4px; min-height: 30px; font-size: 19px; }
textarea { width: 100%; height: 76px; font: 15px/1.1 monospace; background: #fff; border: 3px solid var(--line); padding: 4px; user-select: text; -webkit-user-select: text; resize: none; }

/* ---------- quiz ---------- */
.q-card { background: #fff; box-shadow: var(--pxb); margin: 8px 4px; padding: 14px 10px 16px; text-align: center; }
.q-word { font-size: 40px; line-height: 1; margin: 2px 0 6px; } .q-hint { font-size: 18px; color: var(--muted); }
.opts { display: grid; gap: 4px; margin: 4px; }
.opt { text-align: left; background: var(--paper2); box-shadow: var(--pxb), inset 0 -4px 0 rgba(0,0,0,.14); margin: 4px 3px; padding: 9px 12px 11px; font-size: 23px; line-height: 1.05; }
.opt:active { transform: translateY(2px); } .opt.ok { background: #8fe070; } .opt.no { background: #f2a090; } .opt[disabled] { cursor: default; }
.rew { display: inline-flex; gap: 10px; font-size: 22px; } .big { font-size: 30px; }

/* ---------- tải trang ---------- */
#splash { position: absolute; inset: 0; background: #1b1f4a; display: grid; place-items: center; z-index: 50; overflow: hidden; transition: opacity .6s steps(6), transform .6s steps(6); }
#splash.off { opacity: 0; transform: scale(1.12); pointer-events: none; }
.sp-box { position: relative; z-index: 3; text-align: center; color: #fff6dc; width: min(80vw, 340px); }
.sp-logo { font-size: 54px; line-height: .95; color: var(--gold); text-shadow: 4px 4px 0 #6a3a10; margin-bottom: 8px; letter-spacing: 2px; }
.sp-logo .ln { display: block; white-space: nowrap; } .sp-logo .l2 { color: #7ae060; text-shadow: 4px 4px 0 #1e5a24; }
.sp-logo b { display: inline-block; font-weight: 400; min-width: .28em; opacity: 0; animation: letterIn .55s steps(6) forwards, letterBob 2.4s steps(2) infinite; animation-delay: calc(var(--i) * 70ms + 400ms), calc(var(--i) * 70ms + 1600ms); }
.sp-sub { font-size: 20px; opacity: 0; text-shadow: 0 2px 0 rgba(0,0,0,.5); margin-bottom: 14px; animation: fadeIn .6s steps(6) 1.5s forwards; }
.sp-track { position: relative; padding-top: 24px; }
.sp-bar { height: 16px; background: #4e2f18; box-shadow: var(--pxb); margin: var(--px); overflow: hidden; } .sp-bar i { display: block; height: 100%; width: 4%; background: repeating-linear-gradient(90deg, #7ae060 0 6px, #58c04a 6px 12px); transition: width .25s steps(6); }
.sp-run { position: absolute; left: 4%; top: 0; width: 0; height: 24px; transition: left .25s steps(6); }
.sp-chick { position: absolute; left: -9px; top: 3px; width: 3px; height: 3px; background: transparent; animation: hop .28s steps(2) infinite;
  box-shadow: 9px 0 0 #e03030, 6px 3px 0 #fffaf0, 9px 3px 0 #fffaf0, 12px 3px 0 #222, 15px 3px 0 #f2a22a, 0 6px 0 #fffaf0, 3px 6px 0 #fffaf0, 6px 6px 0 #fffaf0, 9px 6px 0 #fffaf0, 12px 6px 0 #fffaf0, 3px 9px 0 #f2ecd8, 6px 9px 0 #fffaf0, 9px 9px 0 #fffaf0, 12px 9px 0 #f2ecd8, 6px 12px 0 #f2a22a, 9px 12px 0 #f2a22a; }
#spTxt { font-size: 19px; display: block; margin-top: 4px; text-shadow: 0 2px 0 rgba(0,0,0,.5); }
#spErr { color: #ffb0a0; font-size: 18px; margin-top: 12px; }
/* nền động: bình minh lên trên nông trại */
.sp-sky { position: absolute; inset: 0; background-color: #1b1f4a; animation: dawn 3.2s steps(16) forwards; }
.sp-sky::after { content: ''; position: absolute; inset: 0; background: linear-gradient(transparent 45%, rgba(255, 200, 120, .5)); opacity: 0; animation: glow 3.2s steps(16) forwards; }
.sp-sun { position: absolute; left: 50%; top: 24%; width: 48px; height: 48px; margin-left: -24px; background: #ffe27a; box-shadow: 0 0 0 6px rgba(255,226,122,.35), 0 0 0 14px rgba(255,226,122,.18), inset -6px -6px 0 #f2b531; transform: translateY(220px); animation: sunrise 3s steps(15) .2s forwards; }
.sp-cloud { position: absolute; width: 24px; height: 9px; background: #fff; opacity: .9; box-shadow: 12px -9px 0 #fff, 24px 0 0 #fff, 36px -9px 0 #fff, 48px 0 0 #fff; animation: drift 16s linear infinite; }
.sp-cloud.c1 { top: 12%; left: -80px; } .sp-cloud.c2 { top: 22%; left: -80px; animation-duration: 22s; animation-delay: -9s; transform: scale(1.3); } .sp-cloud.c3 { top: 7%; left: -80px; animation-duration: 28s; animation-delay: -18s; opacity: .6; }
.sp-hill { position: absolute; left: 0; right: 0; bottom: 0; }
.sp-hill.h1 { height: 34%; background: #2f7a36; clip-path: polygon(0 45%, 14% 45%, 14% 25%, 32% 25%, 32% 0, 56% 0, 56% 30%, 80% 30%, 80% 12%, 100% 12%, 100% 100%, 0 100%); }
.sp-hill.h2 { height: 22%; background: #58c04a; clip-path: polygon(0 30%, 20% 30%, 20% 10%, 44% 10%, 44% 40%, 70% 40%, 70% 0, 92% 0, 92% 25%, 100% 25%, 100% 100%, 0 100%); }
.sp-field { position: absolute; left: 0; right: 0; bottom: 0; height: 12%; background: repeating-linear-gradient(90deg, #5a3a1f 0 12px, #4e3320 12px 24px); }
.sp-field::before { content: ''; position: absolute; left: 0; right: 0; top: -9px; height: 9px; background: repeating-linear-gradient(90deg, transparent 0 8px, #7ae060 8px 14px, transparent 14px 24px); animation: sway 1.1s steps(2) infinite alternate; }
@keyframes dawn { 0% { background-color: #1b1f4a; } 40% { background-color: #6a4a8a; } 70% { background-color: #f0a060; } 100% { background-color: #8fd4f0; } }
@keyframes glow { 0% { opacity: 0; } 55% { opacity: 1; } 100% { opacity: 0; } }
@keyframes sunrise { to { transform: translateY(0); } }
@keyframes drift { to { transform: translateX(calc(100vw + 200px)); } }
@keyframes sway { to { transform: translateY(-3px); } }
@keyframes hop { 50% { transform: translateY(-3px); } }
@keyframes fadeIn { to { opacity: 1; } }
@keyframes letterIn { 0% { opacity: 0; transform: translateY(-46px) scale(1.5); } 70% { opacity: 1; transform: translateY(6px) scale(1); } 100% { opacity: 1; transform: none; } }
@keyframes letterBob { 0%, 100% { transform: none; } 50% { transform: translateY(-3px); } }
/* nhập cảnh vào game: tối viền + màu theo giờ trong ngày */
#vig, #tint { position: absolute; inset: 0; pointer-events: none; }
#vig { background: radial-gradient(ellipse at 50% 45%, transparent 58%, rgba(20, 10, 0, .3) 100%); }
#tint { background: rgba(30, 40, 110, 0); transition: background .8s linear; }
#stage.intro canvas { animation: introIn 1.2s steps(10) both; }
@keyframes introIn { from { opacity: 0; transform: scale(1.08); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { #splash *, #splash *::before, #splash *::after, #stage.intro canvas { animation: none !important; } .sp-logo b, .sp-sub { opacity: 1; } .sp-sun { transform: none; } .sp-sky { background-color: #8fd4f0; } }
/* màn rộng: gom HUD / dock vào giữa cho dễ nhìn */
@media (min-width: 820px) {
  #hud, #dock { left: 50%; right: auto; width: 780px; transform: translateX(-50%); }
  #chips { left: 50%; right: auto; width: 780px; transform: translateX(-50%); padding: 0 8px; }
  #toasts { bottom: calc(var(--sa-b) + 190px); }
  .tool { width: 60px; }
}
@media (prefers-reduced-motion: reduce) { * { animation-duration: .01ms !important; } }
