/* ===== Xuyên Không – giao diện (phong cách 2.5D hoạt hình) ===== */
:root {
  --sky1: #ff9f5a; --sky2: #ffe3b3;
  --ground1: #8b6b43; --ground2: #6a4f2e;
  --plot: #7a5a33; --plot-border: #4f3820;
  --accent: #d9822b;
  --wood1: #6b4526; --wood2: #4a2e17; --wood-edge: #2e1c0e;
  --paper: #fff8ea; --paper2: #fbebcf; --ink: #3b2a18; --muted: #6f5a40;
  --ok: #2e9e4f; --no: #c0392b; --line: #efdcb6; --gold: #ffcf4a;
  --radius: 16px;
  --title: 'Baloo 2', 'Nunito', system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: 'Nunito', 'Segoe UI', system-ui, sans-serif;
  background: var(--wood2); color: var(--ink); overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
button { font-family: inherit; }
svg { display: block; }

#app { display: flex; flex-direction: column; height: 100vh; }

/* ---------- Thanh trên (gỗ) ---------- */
#topbar {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 8px 16px; color: #fff3dc; position: relative; z-index: 3;
  background:
    repeating-linear-gradient(90deg, rgba(255,255,255,.03) 0 2px, transparent 2px 34px),
    linear-gradient(180deg, var(--wood1), var(--wood2));
  border-bottom: 4px solid var(--wood-edge);
  box-shadow: 0 4px 0 rgba(0,0,0,.18);
}
.brand { display: flex; align-items: center; gap: 6px; font-family: var(--title); font-weight: 800; font-size: 22px; color: var(--gold); text-shadow: 0 2px 0 var(--wood-edge); }
.brand span { letter-spacing: .5px; }
.era-box { padding-left: 14px; border-left: 2px solid rgba(255,255,255,.15); }
#era-name { font-family: var(--title); font-weight: 800; font-size: 18px; line-height: 1.1; }
#era-year { font-size: 12.5px; opacity: .85; }
.stats { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-left: auto; }
.stat {
  background: rgba(0,0,0,.28); padding: 5px 14px; border-radius: 99px; font-size: 15px; white-space: nowrap;
  box-shadow: inset 0 2px 3px rgba(0,0,0,.35), 0 1px 0 rgba(255,255,255,.12);
}
.stat b { font-weight: 900; color: #fff; }
.stat.level { display: flex; align-items: center; gap: 8px; font-weight: 800; }
.xpbar { width: 90px; height: 10px; background: rgba(0,0,0,.35); border-radius: 9px; overflow: hidden; }
.xpbar i { display: block; height: 100%; background: linear-gradient(180deg, #b6f27a, #5cc23a); transition: width .4s; }
.icon-btn {
  background: linear-gradient(180deg, #8a5a33, #6b4526); border: 0; border-radius: 12px; font-size: 18px; padding: 6px 9px;
  cursor: pointer; color: inherit; box-shadow: 0 3px 0 var(--wood-edge);
}
.icon-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--wood-edge); }
.modal .icon-btn { background: var(--paper2); box-shadow: 0 3px 0 var(--line); }
#goal {
  position: relative; z-index: 2; background: var(--accent-dark, var(--accent));
  color: #fff; font-weight: 800; padding: 6px 16px; font-size: 14px; text-shadow: 0 1px 0 rgba(0,0,0,.3);
  box-shadow: 0 3px 0 rgba(0,0,0,.15);
}

/* ---------- Bố cục ---------- */
#main { flex: 1; display: flex; min-height: 0; }
#panel {
  width: 410px; background: var(--paper); display: flex; flex-direction: column; min-height: 0;
  border-left: 6px solid var(--wood1); box-shadow: -4px 0 0 var(--wood-edge);
}

/* ---------- Khung cảnh 2.5D (vườn hàng xóm trong hộp thoại) ---------- */
.scene-svg { position: absolute; left: 0; bottom: 0; width: 100%; height: 100%; }
.spin-slow { transform-origin: 60px 62px; animation: spin 6s linear infinite; }
.deco { position: absolute; line-height: 1; filter: drop-shadow(0 4px 2px rgba(0,0,0,.2)); transform-origin: bottom center; }
.deco.svg svg { width: 100%; height: auto; }
.deco.new { animation: pop .8s ease-out; }
@keyframes pop { 0% { transform: scale(0); } 70% { transform: scale(1.15); } 100% { transform: scale(1); } }
.flame { transform-origin: 50% 90%; animation: flicker .6s ease-in-out infinite alternate; }
@keyframes flicker { from { transform: scale(1, 1); } to { transform: scale(.92, 1.08); } }
.puff { animation: puff 3s ease-in-out infinite; }
@keyframes puff { 0% { transform: translate(0, 6px); opacity: .6; } 50% { opacity: 1; } 100% { transform: translate(8px, -8px); opacity: .5; } }
/* ---------- Ô ruộng (vườn hàng xóm trong hộp thoại) ---------- */
.plot {
  position: relative; aspect-ratio: 100 / 92; border: 0; padding: 0; background: none; cursor: pointer;
  transition: transform .12s;
}
.plot:disabled { cursor: default; }
.plot .tile { position: absolute; inset: 0; filter: drop-shadow(0 5px 0 rgba(0,0,0,.22)); }
.plot .tile svg, .plot .tile img { width: 100%; height: 100%; }
.plot:not(:disabled):hover { transform: translateY(-3px); }
.plot:not(:disabled):hover .tile { filter: drop-shadow(0 8px 0 rgba(0,0,0,.2)) brightness(1.06); }
.sprite { position: absolute; left: 12%; width: 76%; bottom: 30%; pointer-events: none; }
.sprite svg, .sprite img { width: 100%; height: auto; overflow: visible; filter: drop-shadow(0 3px 0 rgba(0,0,0,.18)); }
.sprite .fruit { position: absolute; left: 50%; top: 22%; transform: translateX(-50%); font-size: 34px; line-height: 1; filter: drop-shadow(0 2px 1px rgba(0,0,0,.35)); }
.sprite .fruit.small { font-size: 20px; top: 34%; opacity: .75; }
.sprite.ripe { animation: bounce 1.4s ease-in-out infinite; }
.plot.ready .tile::after { content: ''; }
.plot.ready::before {
  content: ''; position: absolute; left: 14%; right: 14%; top: 18%; height: 40%; border-radius: 50%;
  background: radial-gradient(closest-side, rgba(255,236,120,.75), transparent); animation: glow 1.4s ease-in-out infinite alternate;
}
@keyframes glow { from { opacity: .45; } to { opacity: 1; } }
@keyframes bounce { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }
.badge { position: absolute; font-size: 20px; line-height: 1; z-index: 2; filter: drop-shadow(0 2px 1px rgba(0,0,0,.4)); }
.badge.bug { top: 6%; left: 4%; animation: wiggle .5s ease-in-out infinite alternate; }
.badge.drop { top: 6%; right: 4%; animation: bob 1.6s ease-in-out infinite; }
.badge.hand { bottom: 20%; right: 6%; font-size: 18px; }
@keyframes wiggle { from { transform: rotate(-15deg); } to { transform: rotate(15deg); } }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-3px); } }
.plotbar { position: absolute; left: 16%; right: 16%; bottom: 16%; height: 7px; z-index: 2; box-shadow: 0 0 0 2px rgba(59,42,24,.6); }
/* ---------- Thanh tiến độ ---------- */
.bar { height: 8px; background: rgba(0,0,0,.3); border-radius: 9px; overflow: hidden; }
.bar i { display: block; height: 100%; background: linear-gradient(180deg, #b6f27a, #5cc23a); transition: width .5s linear; }
.card .bar { background: #eadbc0; margin-top: 8px; }

/* ---------- Tab ---------- */
#tabs { display: grid; grid-template-columns: repeat(8, 1fr); gap: 3px; padding: 6px 6px 0; background: var(--paper2); border-bottom: 3px solid var(--line); }
.tab {
  position: relative; border: 0; background: transparent; padding: 7px 2px 6px; cursor: pointer; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 1px; border-radius: 12px 12px 0 0;
}
.tab:hover { background: rgba(255,255,255,.5); }
.tab .ti { font-size: 21px; line-height: 0; transition: transform .15s; }
.tab:hover .ti { transform: scale(1.12); }
.tab .tn { font-size: 9.5px; font-weight: 800; white-space: nowrap; }
.tab.on { color: var(--ink); background: var(--paper); box-shadow: inset 0 3px 0 var(--accent); }
.tab .tb {
  position: absolute; top: 2px; right: 5px; background: var(--no); color: #fff; font-size: 10px; font-weight: 900; border-radius: 99px;
  min-width: 18px; padding: 1px 5px; box-shadow: 0 2px 0 rgba(0,0,0,.25); animation: pulseBadge 1.6s ease-in-out infinite;
}
@keyframes pulseBadge { 50% { transform: scale(1.12); } }
#panel-body { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 14px; }
#panel-body h3, .modal h3 { margin: 0 0 4px; font-family: var(--title); font-weight: 800; font-size: 21px; }
.sub { margin: 0 0 12px; color: var(--muted); font-size: 13px; }

/* ---------- Thẻ ---------- */
.card {
  background: #fff; border: 2px solid var(--line); border-radius: var(--radius); padding: 11px 12px; margin-bottom: 11px;
  box-shadow: 0 3px 0 var(--line);
}
.card.locked { opacity: .55; filter: grayscale(.4); }
.card.done { border-color: #ffd54f; background: linear-gradient(180deg, #fffdf0, #fff6d0); box-shadow: 0 3px 0 #f3d36a; }
.card.busy { border-color: #b3e5fc; box-shadow: 0 3px 0 #b3e5fc; }
.card-head { display: flex; align-items: center; gap: 10px; }
.grow { flex: 1; min-width: 0; }
.big-ic { font-size: 30px; line-height: 1; width: 44px; height: 44px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; background: var(--paper2); border-radius: 12px; }
.avatar { font-size: 34px; width: 52px; height: 52px; display: flex; align-items: center; justify-content: center; background: var(--paper2); border-radius: 50%; flex-shrink: 0; }
.muted { color: var(--muted); font-size: 12.5px; }
.small { font-size: 11.5px; }
.right { text-align: right; }
.row { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.row.end { justify-content: flex-end; }
.eratag { font-size: 13px; opacity: .8; }
.tag { font-size: 11px; font-weight: 800; padding: 2px 8px; border-radius: 99px; }
.tag.ok { background: #e3f6e8; color: var(--ok); }
.tag.future { background: #efe3ff; color: #7b3fe4; }
.ok-text { color: var(--ok); font-weight: 800; }
.chip { display: inline-flex; align-items: center; gap: 3px; font-size: 13px; font-weight: 800; padding: 3px 9px; border-radius: 99px; margin: 2px 2px 2px 0; background: #f4ecdc; white-space: nowrap; }
.chip.ok { background: #e3f6e8; color: var(--ok); }
.chip.no { background: #fde8e6; color: var(--no); }
.chip.out { background: #fff3cf; color: #8a5a00; }

/* Nút kiểu game: nổi khối, nhấn lún xuống */
.btn {
  border: 0; border-radius: 12px; padding: 8px 13px; font-weight: 800; font-size: 13px; cursor: pointer; white-space: nowrap;
  background: linear-gradient(180deg, #fbf1dc, #ecdcbc); color: var(--ink); box-shadow: 0 3px 0 #cdb58a;
  transition: transform .08s, filter .15s;
}
.btn:disabled { opacity: .45; cursor: default; filter: grayscale(.5); }
.btn:not(:disabled):hover { filter: brightness(1.06); transform: translateY(-1px); }
.btn:not(:disabled):active { transform: translateY(2px); box-shadow: 0 1px 0 #cdb58a; }
.btn.primary {
  background: linear-gradient(180deg, #33873a, #276a2b); color: #fff; text-shadow: 0 1px 0 rgba(0,0,0,.3);
  box-shadow: 0 3px 0 #1b4d1f;
}
.btn.primary:not(:disabled):active { box-shadow: 0 1px 0 #1b4d1f; }
.btn.danger { background: linear-gradient(180deg, #ef6b5b, #c0392b); color: #fff; box-shadow: 0 3px 0 #8a2419; }
.btn.ghost { background: transparent; box-shadow: none; color: var(--muted); }
.btn.sm { padding: 6px 10px; font-size: 12px; }
.btn.big { padding: 12px 18px; font-size: 15px; width: 100%; margin-top: 8px; white-space: normal; }
.pulse { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { filter: brightness(1); } 50% { filter: brightness(1.15); } }

/* Biểu tượng SVG (vật phẩm, nhân vật, xưởng) */
.ico { display: inline-block; width: 1.45em; height: 1.45em; vertical-align: -.38em; line-height: 0; }
.ico svg { width: 100%; height: 100%; overflow: visible; }
.chip .ico { width: 20px; height: 20px; vertical-align: -5px; }
.big-ic .ico { width: 36px; height: 36px; vertical-align: 0; }
.avatar .ico, .order-head .who .ico { width: 100%; height: 100%; vertical-align: 0; }
.avatar, .order-head .who { overflow: hidden; }
.modal-head h3 .ico { width: 34px; height: 34px; vertical-align: -10px; background: var(--paper2); border-radius: 50%; }
.bld-ic { position: relative; padding: 4px 3px 2px; }
.bld-ic svg { width: 100%; height: auto; }
.mini-sign { position: absolute; right: -6px; bottom: -6px; width: 22px; height: 22px; border-radius: 50%; background: #fffaf0; border: 2px solid var(--wood1); display: flex; align-items: center; justify-content: center; font-size: 12px; }
.toast .ico { width: 20px; height: 20px; vertical-align: -5px; }
.floater .ico { width: 24px; height: 24px; vertical-align: -6px; filter: drop-shadow(0 2px 0 #3b2a18); }

/* Đơn hàng */
.order.empty { color: var(--muted); text-align: center; border-style: dashed; box-shadow: none; background: transparent; }
.order.can { border-color: #8bd46e; box-shadow: 0 3px 0 #8bd46e; }
.order-head { display: flex; gap: 10px; align-items: center; }
.order-head .who { font-size: 30px; width: 48px; height: 48px; display: flex; align-items: center; justify-content: center; background: var(--paper2); border-radius: 50%; flex-shrink: 0; }
.reward { font-size: 13px; margin-top: 6px; }
.warn-line { margin-top: 6px; font-size: 12px; font-weight: 800; color: #b26a00; background: #fff4e0; border-radius: 8px; padding: 4px 8px; }
/* Kho */
.inv-row { display: flex; align-items: center; gap: 8px; padding: 8px 4px; border-bottom: 1px dashed var(--line); }
/* Xưởng */
.recipes { margin-top: 6px; }
.recipe { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-top: 1px dashed var(--line); }
.queue { margin-top: 6px; display: grid; gap: 4px; }
.qjob { display: flex; align-items: center; gap: 8px; font-size: 12px; padding: 4px 8px; border-radius: 10px; background: #f6f0e3; }
.qjob.done { background: #fffbe6; }
.qjob .bar { margin-top: 0; }
.qjob .timer { font-weight: 800; }
.loot { margin-top: 6px; font-size: 12px; color: var(--muted); }
.unlocks { margin: 6px 0 0 54px; }
.tech.done { opacity: .7; }
/* Kỳ quan */
.timeline { display: flex; align-items: center; margin: 10px 0 20px; }
.tl { display: flex; flex-direction: column; align-items: center; width: 30px; flex-shrink: 0; position: relative; }
.tl span { font-size: 17px; width: 30px; height: 30px; border-radius: 50%; display: flex; align-items: center; justify-content: center; background: #eee; border: 2px solid #ddd; }
.tl small { display: none; }
.tl.now small { display: block; position: absolute; top: 33px; left: 50%; transform: translateX(-50%); font-size: 9px; color: var(--muted); white-space: nowrap; }
.tl.past span { background: #e3f6e8; border-color: #9ad6a8; }
.tl.now span { background: var(--gold); border-color: #e0a526; box-shadow: 0 0 0 3px #fff3c2; }
.tl.future { opacity: .5; }
.tl-line { flex: 1; min-width: 4px; height: 4px; background: var(--line); border-radius: 4px; }
.wonder { text-align: center; }
.wonder-ic { font-size: 64px; filter: drop-shadow(0 4px 0 rgba(0,0,0,.15)); }
.wonder h4 { margin: 4px 0; font-size: 22px; font-family: var(--title); }

/* Chơi online */
.card.online { border-color: #b388ff; box-shadow: 0 3px 0 #d6c2ff; }
.card.online.conflict { border-color: #f5b400; background: #fffbe6; box-shadow: 0 3px 0 #f3d36a; }
.card.online.off { border-color: var(--line); box-shadow: 0 3px 0 var(--line); }
.rp-list { margin-top: 8px; }
.rp-row { display: flex; align-items: center; gap: 8px; padding: 6px 2px; border-top: 1px dashed var(--line); }
.rp-era { font-size: 22px; width: 32px; text-align: center; }
.inbox { margin-top: 8px; background: #f6f0ff; border-radius: 10px; padding: 6px 10px; }
.warn-text { color: #b23a2b; font-weight: 800; }
.lb-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.lb-row { display: flex; align-items: center; gap: 8px; padding: 7px 8px; border-radius: 10px; }
.lb-row:nth-child(odd) { background: #fff; }
.lb-row.me { background: #fff3cf; box-shadow: inset 0 0 0 2px var(--gold); }
.lb-rank { width: 34px; text-align: center; font-weight: 900; font-size: 16px; }
.lb-val { font-weight: 800; font-size: 13px; white-space: nowrap; }
.text-in { width: 100%; padding: 10px 12px; border-radius: 12px; border: 2px solid var(--line); font: inherit; font-weight: 700; margin: 6px 0; background: #fff; }
.text-in:focus { outline: none; border-color: var(--accent); }
.lbl { display: block; font-weight: 800; font-size: 13px; margin-top: 6px; }
code { background: var(--paper2); padding: 1px 5px; border-radius: 5px; font-size: 12px; }

/* Kinh tế */
.econ-actions { display: grid; gap: 8px; margin: 4px 0 16px; }
h3.mt { margin-top: 8px !important; }
.growth { display: grid; gap: 6px; }
.grow-row { display: grid; grid-template-columns: 30px 1fr; gap: 2px 8px; align-items: center; background: #fff; border: 2px solid var(--line); border-radius: 12px; padding: 6px 8px; }
.grow-row.now { border-color: var(--gold); background: #fffbe6; }
.grow-era { font-size: 20px; grid-row: span 2; text-align: center; }
.grow-bar { position: relative; height: 20px; background: #f4ecdc; border-radius: 99px; overflow: hidden; }
.grow-bar i { position: absolute; inset: 0 auto 0 0; background: linear-gradient(90deg, #7ed957, #45a82e); border-radius: 99px; }
.grow-bar span { position: relative; font-size: 11.5px; font-weight: 900; padding-left: 8px; line-height: 20px; color: var(--ink); text-shadow: 0 0 3px #fff; }
.grow-meta { font-size: 11px; color: var(--muted); font-weight: 700; }
.lot-preview { display: flex; justify-content: center; align-items: flex-end; height: 150px; margin: 4px 0 8px; background: linear-gradient(180deg, var(--sky2, #eaf6ff), #fff); border-radius: 14px; border: 2px solid var(--line); padding-bottom: 8px; }
.lot-preview span { display: block; max-height: 140px; }
.lot-preview svg, .lot-preview img { width: 100%; height: auto; max-height: 140px; }

/* ---------- Modal ---------- */
.backdrop { position: fixed; inset: 0; background: rgba(30,15,0,.6); z-index: 50; backdrop-filter: blur(2px); }
.modal {
  position: fixed; z-index: 51; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(540px, calc(100vw - 24px)); max-height: calc(100vh - 40px); overflow-y: auto;
  background: var(--paper); border-radius: 22px; padding: 16px 18px; border: 4px solid var(--wood1);
  box-shadow: 0 6px 0 var(--wood-edge), 0 24px 60px rgba(0,0,0,.5);
  animation: modalIn .2s ease-out;
}
.modal.wide { width: min(800px, calc(100vw - 24px)); }
@keyframes modalIn { from { transform: translate(-50%, -46%); opacity: 0; } }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.modal-head h3 { margin: 0; }
.seed { display: flex; align-items: center; gap: 8px; padding: 8px 4px; border-bottom: 1px dashed var(--line); }
.seed.locked { opacity: .5; }
.seed-art { width: 48px; height: 48px; position: relative; flex-shrink: 0; background: var(--paper2); border-radius: 12px; padding: 2px 4px 0; }
.seed-art svg { width: 100%; height: auto; }
.seed-art .fruit { position: absolute; left: 50%; top: 20%; transform: translateX(-50%); font-size: 20px; }
.statgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 10px 0; }
.statgrid div { background: #fff; border: 2px solid var(--line); border-radius: 12px; padding: 8px 10px; font-size: 13px; display: flex; justify-content: space-between; gap: 6px; }
.menu-btns { display: grid; gap: 8px; margin: 12px 0; }
.audio-set { display: grid; gap: 6px; background: #fff; border: 2px solid var(--line); border-radius: 12px; padding: 8px 12px; }
.audio-set label { display: flex; justify-content: space-between; align-items: center; gap: 10px; font-weight: 800; font-size: 13px; }
.audio-set input { flex: 1; max-width: 220px; accent-color: var(--accent); }
/* Menu → Đồ họa Cao / Thấp (nút gạt 2 lựa chọn) */
.gfx-set { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 8px; background: #fff; border: 2px solid var(--line); border-radius: 12px; padding: 8px 12px; font-weight: 800; font-size: 13px; }
.seg { display: flex; background: var(--paper2); border-radius: 99px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; color: var(--muted); font: inherit; font-weight: 800; padding: 6px 16px; border-radius: 99px; cursor: pointer; }
.seg button.on { background: var(--accent-dark, var(--accent)); color: #fff; box-shadow: 0 2px 0 rgba(0,0,0,.2); }
.seg .ico { margin-right: 3px; }
.help ol { padding-left: 20px; } .help li { margin-bottom: 6px; }
textarea.code { width: 100%; height: 140px; font-family: monospace; font-size: 11px; border-radius: 10px; border: 2px solid var(--line); padding: 8px; word-break: break-all; }
/* Vườn hàng xóm */
.nscene { border-radius: 16px; overflow: hidden; border: 3px solid var(--wood1); }
.nsky { position: relative; height: 130px; background: linear-gradient(180deg, var(--sky1), var(--sky2)); overflow: hidden; }
.ndecor { position: absolute; inset: 0 0 4px; }
.nsky .deco { transform: scale(.7); animation: none; }
.nground { padding: 20px 14px 16px; background: linear-gradient(180deg, var(--ground1), var(--ground2)); }
.nfield { display: grid; grid-template-columns: repeat(auto-fill, minmax(80px, 1fr)); gap: 16px 10px; padding-top: 12px; }
.victory { text-align: center; }
.victory h2 { font-family: var(--title); }
.vic-ic { font-size: 64px; }

#update-banner { position: fixed; top: 10px; left: 50%; transform: translateX(-50%); z-index: 120; background: #2e7d32; color: #fff; font-weight: 800; padding: 8px 10px 8px 16px; border-radius: 14px; box-shadow: 0 6px 20px rgba(0,0,0,.35); display: flex; align-items: center; gap: 10px; width: max-content; max-width: calc(100vw - 20px); }
#update-banner[hidden] { display: none; }

/* ---------- Toast & chữ bay ---------- */
#toasts { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 90; display: flex; flex-direction: column; gap: 6px; align-items: center; pointer-events: none; }
.toast { background: #3b2a18; color: #fff; padding: 9px 16px; border-radius: 14px; font-weight: 700; font-size: 14px; box-shadow: 0 4px 0 rgba(0,0,0,.25), 0 8px 20px rgba(0,0,0,.3); animation: toastIn .25s ease-out; transition: opacity .4s, transform .4s; max-width: 90vw; text-align: center; }
.toast.good { background: #2e7d32; } .toast.warn { background: #b23a2b; } .toast.level { background: linear-gradient(90deg, #7b3fe4, #d9822b); }
.toast.out { opacity: 0; transform: translateY(10px); }
@keyframes toastIn { from { transform: translateY(20px); opacity: 0; } }
.floater { position: fixed; z-index: 95; transform: translateX(-50%); font-weight: 900; font-size: 17px; color: #fff; text-shadow: 0 2px 0 #3b2a18, 0 0 6px rgba(0,0,0,.4); pointer-events: none; animation: floatUp 1.3s ease-out forwards; white-space: nowrap; }
@keyframes floatUp { to { transform: translate(-50%, -60px); opacity: 0; } }

/* ---------- Hiệu ứng xuyên không ---------- */
#warp { position: fixed; inset: 0; z-index: 100; display: none; background: radial-gradient(circle, #3a1f7a, #0b0033 70%); color: #fff; overflow-y: auto; }
#warp.on { display: flex; align-items: center; justify-content: center; }
.warp-inner { text-align: center; padding: 24px; max-width: 620px; }
.vortex { font-size: 120px; animation: spin 1.2s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.warp-title { font-family: var(--title); font-weight: 800; letter-spacing: 8px; font-size: 22px; opacity: .8; }
.warp-year { font-family: var(--title); font-weight: 800; font-size: 48px; margin: 6px 0 16px; text-shadow: 0 0 20px #b388ff; }
.warp-era.hidden { display: none; }
.warp-era { animation: modalIn2 .6s ease-out; }
@keyframes modalIn2 { from { opacity: 0; transform: translateY(20px); } }
.warp-ic { font-size: 56px; }
.warp-era h2 { margin: 4px 0; font-size: 30px; font-family: var(--title); }
.warp-years { opacity: .7; margin: 0 0 10px; }
.warp-story { line-height: 1.6; font-size: 16px; }

/* ---------- Điện thoại / máy tính bảng ---------- */
@media (max-width: 900px) {
  body { overflow: auto; }
  #app { height: auto; min-height: 100vh; }
  #main { flex-direction: column; }
  #panel { width: 100%; border-left: 0; box-shadow: none; border-top: 6px solid var(--wood1); }
  #panel-body { overflow: visible; }
  #topbar { padding: 8px 12px; gap: 8px; }
  .brand span { display: none; }
  .era-box { padding-left: 8px; }
  .stats { margin-left: 0; }
  .xpbar { width: 50px; }
  .tab .tn { font-size: 9px; }
  .sprite .fruit { font-size: 26px; }
}

/* ---------- Đợt 3: dễ bấm trên điện thoại, giảm chuyển động, gợi ý tân thủ ---------- */
.order .btn.ghost { min-width: 40px; min-height: 40px; }
@media (max-width: 480px) {
  /* 8 tab chia 2 hàng để mỗi tab đủ rộng cho ngón tay */
  #tabs { grid-template-columns: repeat(4, 1fr); }
  .tab { padding: 8px 2px; }
  .tab .tn { font-size: 10.5px; }
}
/* Tôn trọng cài đặt "giảm chuyển động" của hệ điều hành */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
/* Vòng sáng chỉ chỗ cần bấm cho người mới */
.coach { position: relative; z-index: 4; animation: coach 1.3s ease-in-out infinite; border-radius: 16px; }
@keyframes coach { 0%, 100% { box-shadow: 0 0 0 3px rgba(255, 207, 74, .95), 0 0 0 0 rgba(255, 207, 74, .6); } 50% { box-shadow: 0 0 0 3px rgba(255, 207, 74, .95), 0 0 0 12px rgba(255, 207, 74, 0); } }
.toast .times:not(:empty) { background: rgba(255,255,255,.25); border-radius: 99px; padding: 0 6px; margin-left: 6px; font-size: 12px; }

/* ---------- Nhiệm vụ ngày & thành tựu ---------- */
.card.daily { border-color: #ffd54f; background: linear-gradient(180deg, #fffdf0, #fff4d6); }
.daily-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; margin-bottom: 4px; }
.quest, .achv { display: flex; align-items: center; gap: 10px; padding: 6px 0; border-top: 1px dashed var(--line); }
.quest .bar, .achv .bar { margin-top: 4px; }
.quest.done { opacity: .6; }
.q-ic { font-size: 22px; width: 30px; text-align: center; flex: none; }
.q-done { font-size: 20px; flex: none; }
.daily-foot { justify-content: space-between; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.tb.inline { display: inline-block; margin-left: 4px; background: var(--no); color: #fff; font-size: 11px; font-weight: 900; border-radius: 99px; min-width: 18px; padding: 1px 6px; text-align: center; }
.achv-list { max-height: 60vh; overflow-y: auto; }
.achv.locked { opacity: .7; }
.achv.ready { background: #fff6d0; border-radius: 10px; padding-left: 6px; }

/* ---------- Sự kiện theo mùa ---------- */
/* Trang trí sự kiện: dải đèn lồng / cành mai ngay dưới thanh trên, nổi trên bản đồ 3D, không chặn bấm (dưới #app, #fly-hud) */
#event-deco { position: fixed; left: 0; right: 0; top: var(--fly-top, 70px); height: 150px; pointer-events: none; z-index: 4; overflow: hidden; }
body.title-on #event-deco { visibility: hidden; }
.ev-deco { position: absolute; inset: 0; }
.ev-cord { position: absolute; left: 0; top: 0; width: 100%; height: 30px; }
.ev-lantern { position: absolute; width: 26px; height: 46px; margin-left: -13px; transform-origin: 50% 0; animation: evSwing 2.7s ease-in-out infinite; filter: drop-shadow(0 0 6px rgba(255, 190, 80, .75)); }
.ev-lantern svg, .ev-branch { display: block; width: 100%; height: 100%; }
.ev-branch { position: absolute; top: 0; width: 150px; height: 128px; }
.ev-branch.left { left: 0; }
.ev-branch.right { right: 0; transform: scaleX(-1); }
@keyframes evSwing { 0%, 100% { transform: rotate(-5deg); } 50% { transform: rotate(5deg); } }
@media (prefers-reduced-motion: reduce) { .ev-lantern { animation: none; } }
@media (max-width: 480px) { .ev-branch { width: 100px; height: 86px; } .ev-lantern { width: 20px; height: 36px; margin-left: -10px; } }
.card.event { border-color: #e0402f; background: linear-gradient(180deg, #fff4ec, #ffe3d3); }
.card.event.ev-tet { border-color: #d4a017; background: linear-gradient(180deg, #fff8e1, #ffe7b0); }
.ev-row { justify-content: space-between; align-items: center; gap: 8px; margin: 6px 0; }
.ev-tokens { font-size: 16px; }
.ev-tokens.big { font-size: 18px; margin: 8px 0; text-align: center; }

/* ---------- Góp ý ---------- */
.fb-stars { display: flex; gap: 6px; justify-content: center; margin: 4px 0 10px; }
.fb-star { font-size: 34px; line-height: 1; background: none; border: 0; cursor: pointer; color: #d8c8a8; padding: 2px 4px; transition: transform .1s; }
.fb-star.on { color: #f5b301; text-shadow: 0 2px 0 #b07800; }
.fb-star:hover { transform: scale(1.15); }
.fb-kinds { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.fb-kind { cursor: pointer; border: 2px solid var(--line); background: var(--paper); font: inherit; font-weight: 700; padding: 6px 10px; }
.fb-kind.on { border-color: var(--accent-dark, #8a4a12); background: #fff1c8; }
textarea.code.fb-msg { min-height: 110px; font-family: inherit; font-size: 15px; }
/* Điện thoại hẹp: thanh trên cùng gọn 1 hàng (ẩn thanh kinh nghiệm, số cấp vẫn hiện) */
@media (max-width: 400px) {
  .xpbar { display: none; }
  .stats { gap: 6px; }
  .stat { padding: 5px 10px; font-size: 14px; }
  .icon-btn { padding: 5px 7px; font-size: 16px; }
}

/* Chữ dành cho crawler và trình đọc màn hình (tools/gen-seo.js), không hiện trên giao diện game */
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* Icon giao diện (js/ui/icons.js): cùng cỡ và màu với chữ xung quanh */
.ico { width: 1em; height: 1em; vertical-align: -0.14em; flex-shrink: 0; }
.icon-btn .ico { width: 1.15em; height: 1.15em; display: block; }
.icon-btn { color: #fff3dc; }
.modal .icon-btn { color: var(--ink); }
.btn .ico { margin-right: 4px; }
h3 .ico { margin-right: 6px; opacity: .85; }

/* ---------- Màn hình tiêu đề (trước khi vào chơi) ----------
   Phủ lên game. Ban đầu che kín bằng nền trời đêm riêng (::before); chỉ khi Flycam 3D đã vẽ xong
   (class .ts-reveal, js/main.js) nền mới mờ dần để thấy khu vườn bay vòng phía sau.
   Máy không chạy được 3D: giữ nền che kín, thay nút chơi bằng lời báo (.ts-no3d). */
#title-screen {
  position: fixed; inset: 0; z-index: 80; display: flex; align-items: center; justify-content: center;
  padding: 24px 16px; overflow-y: auto; color: #fff;
  background:
    radial-gradient(ellipse at 50% 45%, rgba(20,10,50,.35), rgba(11,0,51,.82) 75%),
    linear-gradient(180deg, rgba(11,0,51,.55), rgba(11,0,51,.2) 40%, rgba(11,0,51,.7));
  transition: opacity .45s ease, visibility .45s;
}
#title-screen::before {
  content: ''; position: fixed; inset: 0; z-index: -1; pointer-events: none; transition: opacity 1.4s ease;
  background:
    /* sao nhỏ rải đều (lặp theo ô 200×160) */
    radial-gradient(1.5px 1.5px at 20px 30px, rgba(255,255,255,.9), transparent),
    radial-gradient(1px 1px at 90px 80px, rgba(255,255,255,.7), transparent),
    radial-gradient(1.5px 1.5px at 150px 20px, rgba(255,240,200,.85), transparent),
    radial-gradient(1px 1px at 60px 140px, rgba(255,255,255,.6), transparent),
    radial-gradient(1px 1px at 170px 120px, rgba(200,220,255,.8), transparent),
    /* đồi xa và ánh chân trời */
    radial-gradient(120% 60% at 20% 108%, #1d3a2a 45%, transparent 46%),
    radial-gradient(110% 55% at 85% 112%, #16301f 45%, transparent 46%),
    radial-gradient(90% 40% at 50% 100%, rgba(255,160,90,.35), transparent 70%),
    radial-gradient(60% 45% at 50% 38%, rgba(120,80,255,.35), transparent 70%),
    linear-gradient(180deg, #0b0033 0%, #22105e 55%, #4a2a6e 85%, #6b3a5a 100%);
  background-size: 200px 160px, 200px 160px, 200px 160px, 200px 160px, 200px 160px, auto, auto, auto, auto, auto;
  background-repeat: repeat, repeat, repeat, repeat, repeat, no-repeat, no-repeat, no-repeat, no-repeat, no-repeat;
}
#title-screen.ts-reveal::before { opacity: 0; }
#title-screen.out { opacity: 0; visibility: hidden; pointer-events: none; }
body.title-on #topbar, body.title-on #goal, body.title-on #fly-hud, body.title-on #panel { visibility: hidden; }
html body.title-on, body.title-on #panel-body, body.title-on #main { overflow: hidden; }
.ts-inner { text-align: center; max-width: 520px; width: 100%; margin: auto; }
.ts-logo { width: 96px; height: 96px; margin: 0 auto; display: block; border-radius: 22px; filter: drop-shadow(0 8px 22px rgba(120,90,255,.55)); animation: tsFloat 3.2s ease-in-out infinite; }
@keyframes tsFloat { 50% { transform: translateY(-6px); } }
@keyframes tsSpin { to { transform: rotate(360deg); } }
.ts-name { font: 800 clamp(40px, 11vw, 64px)/1 var(--title); margin-top: 10px; color: var(--gold); text-shadow: 0 3px 0 #7a4a12, 0 8px 24px rgba(0,0,0,.45); }
.ts-tag { font: 800 20px var(--title); margin: 6px 0 4px; letter-spacing: .5px; }
.ts-desc { margin: 0 auto 18px; max-width: 420px; line-height: 1.5; opacity: .9; text-shadow: 0 1px 4px rgba(0,0,0,.5); }
.ts-sum {
  display: inline-block; margin: 0 0 12px; padding: 8px 16px; border-radius: 14px; line-height: 1.45;
  background: rgba(255,255,255,.12); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
}
.ts-sum b { color: var(--gold); }
.ts-sum small { display: block; opacity: .85; }
.ts-sum[hidden] { display: none; }
.ts-play {
  display: flex; align-items: center; justify-content: center; gap: 10px; margin: 0 auto;
  width: min(100%, 340px); min-height: 60px; border: 0; border-radius: 99px; cursor: pointer;
  font: 800 22px var(--title); color: #fff; background: linear-gradient(180deg, #4cc05a, #2e9e4f);
  box-shadow: 0 5px 0 #1b6a30, 0 12px 28px rgba(0,0,0,.35);
  animation: tsPulse 2.2s ease-in-out infinite;
}
.ts-play:not(:disabled):active { transform: translateY(3px); box-shadow: 0 2px 0 #1b6a30; }
.ts-play:disabled { cursor: wait; animation: none; background: linear-gradient(180deg, #6f6a8a, #56507a); box-shadow: 0 5px 0 #37325a; font-size: 18px; }
.ts-play:focus-visible { outline: 3px solid var(--gold); outline-offset: 4px; }
@keyframes tsPulse { 50% { transform: scale(1.04); } }
.ts-spin { width: 18px; height: 18px; border-radius: 50%; border: 3px solid rgba(255,255,255,.35); border-top-color: #fff; animation: tsSpin .8s linear infinite; }
.ts-play:not(:disabled) .ts-spin { display: none; }
.ts-eras { display: flex; justify-content: center; gap: 6px; margin: 22px auto 0; flex-wrap: wrap; }
.ts-eras:empty { display: none; }
.ts-era {
  position: relative; width: 40px; height: 40px; display: grid; place-items: center; font-size: 22px; border-radius: 12px;
  background: rgba(255,255,255,.14);
}
.ts-era.done { background: rgba(255,207,74,.28); }
.ts-era.now { background: rgba(255,207,74,.5); box-shadow: 0 0 0 2px var(--gold); }
.ts-era.lock { filter: grayscale(1); opacity: .4; }
.ts-era.lock::after { content: '🔒'; position: absolute; right: -3px; bottom: -3px; font-size: 11px; filter: none; }
.ts-links { display: flex; justify-content: center; flex-wrap: wrap; gap: 4px 18px; margin-top: 22px; }
.ts-links a, .ts-link {
  color: #e6ddff; font: 700 15px 'Nunito', sans-serif; text-decoration: none; background: none; border: 0; padding: 6px 2px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 5px;
}
.ts-links a:hover, .ts-link:hover { color: #fff; text-decoration: underline; }
.ts-link[hidden], .ts-play[hidden] { display: none; }
.ts-no3d {
  margin: 0 auto; max-width: 460px; text-align: left; line-height: 1.5; padding: 14px 18px; border-radius: 16px;
  background: rgba(255,255,255,.12); border: 1px solid rgba(255,255,255,.25); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
}
.ts-no3d > b { display: block; font: 800 18px/1.3 var(--title); color: var(--gold); }
.ts-no3d p { margin: 8px 0 4px; }
.ts-no3d ul { margin: 4px 0; padding-left: 20px; }
.ts-no3d li { margin-bottom: 4px; }
.ts-no3d-sm { font-size: 13px; opacity: .8; }
.ts-no3d .ts-retry { margin-top: 12px; min-height: 50px; font-size: 19px; }
@media (max-height: 640px) { .ts-logo { width: 64px; height: 64px; } .ts-desc { display: none; } .ts-eras { margin-top: 14px; } }
@media (max-width: 400px) { .ts-era { width: 34px; height: 34px; font-size: 19px; } .ts-eras { gap: 4px; } }
@media (prefers-reduced-motion: reduce) { .ts-logo, .ts-play { animation: none; } }

/* Nút bỏ qua hiệu ứng xuyên không */
.warp-skip { position: absolute; right: 16px; bottom: 16px; }
/* Hướng dẫn nhanh 3 bước cho người mới */
.first-steps { list-style: none; padding: 0; margin: 10px 0 14px; display: grid; gap: 10px; }
.first-steps li { display: flex; gap: 12px; align-items: center; background: var(--paper2); border-radius: 14px; padding: 10px 12px; }
.first-steps .fs-n { flex-shrink: 0; width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font: 800 18px var(--title); color: #fff; background: var(--accent); }
.brand-ic { font-style: normal; display: flex; }
.statgrid .ico, .lb-list .ico, .card-head .ico { margin-right: 3px; }
/* Dấu hiệu nổi trên ô ruộng: nền tròn sáng để icon đơn sắc vẫn nổi bật */
.badge { background: #fffdf6; border: 2px solid #2e1c0e; border-radius: 50%; padding: 3px; box-sizing: content-box; color: #2e1c0e; }
.badge .ico { display: block; }
.badge.bug { color: #c2410c; } .badge.drop { color: #1e88e5; } .badge.hand { color: #2e7d32; }

/* ---------- Thanh cuộn (menu, hộp thoại, bảng bên) ---------- */
@supports not selector(::-webkit-scrollbar) {   /* Firefox: chỉ có thanh mảnh đổi màu */
  .modal, #panel-body, .achv-list, #warp { scrollbar-width: thin; scrollbar-color: var(--wood1) transparent; }
}
.modal::-webkit-scrollbar, #panel-body::-webkit-scrollbar, .achv-list::-webkit-scrollbar, #warp::-webkit-scrollbar { width: 12px; }
.modal::-webkit-scrollbar-track, #panel-body::-webkit-scrollbar-track, .achv-list::-webkit-scrollbar-track, #warp::-webkit-scrollbar-track {
  background: var(--paper2); border-radius: 99px; margin: 14px 0;    /* chừa chỗ cho góc bo của khung */
  box-shadow: inset 0 0 0 1px var(--line);
}
.modal::-webkit-scrollbar-thumb, #panel-body::-webkit-scrollbar-thumb, .achv-list::-webkit-scrollbar-thumb, #warp::-webkit-scrollbar-thumb {
  background: linear-gradient(90deg, var(--accent), var(--wood1)); border-radius: 99px;
  border: 3px solid var(--paper2); min-height: 40px;                 /* viền tạo cảm giác thanh trượt mảnh, nổi trên rãnh */
}
.modal::-webkit-scrollbar-thumb:hover, #panel-body::-webkit-scrollbar-thumb:hover, .achv-list::-webkit-scrollbar-thumb:hover { background: linear-gradient(90deg, var(--gold), var(--accent)); }
#warp::-webkit-scrollbar-track { background: rgba(255,255,255,.08); box-shadow: none; }
#warp::-webkit-scrollbar-thumb { border-color: transparent; background: rgba(255,255,255,.35); }

/* ---------- Thông báo hành động (thu hoạch, tưới…): thẻ nhỏ ở cạnh trái, không che nút ---------- */
#toasts {
  left: 12px; right: auto; bottom: auto; top: 46%; transform: translateY(-50%);
  align-items: flex-start; gap: 8px; width: min(300px, calc(100vw - 96px));
  flex-direction: column-reverse;                 /* thông báo mới nhất nằm trên cùng */
}
.toast {
  --tc: var(--wood1);
  position: relative; display: flex; align-items: center; gap: 8px; text-align: left; max-width: 100%;
  background: var(--paper); color: var(--ink); font-size: 13.5px; font-weight: 800; line-height: 1.25;
  padding: 9px 12px 9px 16px; border-radius: 12px; border: 2px solid var(--line);
  box-shadow: 0 3px 0 rgba(46,28,14,.22), 0 8px 18px rgba(0,0,0,.22);
  animation: toastSlide .28s cubic-bezier(.2,.9,.3,1.2); transition: opacity .4s, transform .4s;
  overflow: hidden;
}
.toast::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 6px; background: var(--tc); }
.toast.good { --tc: var(--ok); background: #f1fbf1; border-color: #bfe3c4; }
.toast.warn { --tc: var(--no); background: #fff1ee; border-color: #f0c2ba; }
.toast.level { --tc: #7b3fe4; background: #f6f0ff; border-color: #d9c8f5; }
.toast.level::before { background: linear-gradient(180deg, #7b3fe4, #d9822b); }
.toast .times:not(:empty) { margin-left: auto; flex: none; background: var(--tc); color: #fff; }
.toast.out { opacity: 0; transform: translateX(-18px); }
@keyframes toastSlide { from { transform: translateX(-26px); opacity: 0; } }
@media (max-width: 900px) {
  /* Điện thoại: thả xuống dưới thanh trên và dòng mục tiêu, không đè nút ở đáy */
  #toasts { left: 50%; top: 148px; transform: translateX(-50%); align-items: center; width: min(360px, calc(100vw - 24px)); flex-direction: column; }
  .toast { width: 100%; }
}
