/* ============================================================
   Flycam 3D: bản đồ phủ toàn trang, các thanh / bảng nổi trên bản đồ (kính mờ)
   Giao diện duy nhất của game: body luôn có class .fly (index.html)
   ============================================================ */

#fly-root, #fly-hud { display: none; }
#fly-loading {
  position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; font: 800 22px var(--title); color: #fff;
  background: radial-gradient(circle, rgba(20,40,80,.55), rgba(10,15,30,.85));
}
#fly-loading[hidden] { display: none; }

/* ---------- Chế độ Flycam ---------- */
body.fly #fly-root { display: block; position: fixed; inset: 0; z-index: 0; background: #7fb2d9; }
body.fly #fly-root canvas { display: block; width: 100%; height: 100%; cursor: grab; touch-action: none; }
body.fly #fly-root canvas:active { cursor: grabbing; }
body.fly #app { position: fixed; inset: 0; height: auto; pointer-events: none; background: transparent; z-index: 5; }
body.fly #main { display: block; }

/* Thanh trên: kính gỗ mờ, bo tròn, nổi trên bản đồ */
body.fly #topbar {
  position: fixed; top: 10px; left: 10px; right: 10px; pointer-events: auto; border-radius: 18px; border-bottom: 0;
  background: linear-gradient(180deg, rgba(107,69,38,.78), rgba(74,46,23,.78));
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  box-shadow: 0 8px 24px rgba(0,0,0,.28), inset 0 1px 0 rgba(255,255,255,.15);
}
/* Dòng mục tiêu: viên thuốc nổi dưới thanh trên */
body.fly #goal {
  position: fixed; top: calc(var(--fly-top, 70px) + 10px); left: 50%; transform: translateX(-50%); pointer-events: auto;
  max-width: min(720px, calc(100vw - 24px)); border-radius: 99px; padding: 7px 18px; text-align: center;
  box-shadow: 0 6px 18px rgba(0,0,0,.25);
}

/* Bảng điều khiển (đơn hàng, kho…): thẻ nổi, mở bằng 📋 */
body.fly #panel { display: none; }
body.fly.fly-panel #panel {
  display: flex; position: fixed; right: 76px; top: calc(var(--fly-top, 70px) + 58px); bottom: 96px; width: 400px; pointer-events: auto;
  border: 0; border-radius: 20px; overflow: hidden; background: rgba(255,248,234,.96);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  box-shadow: 0 14px 40px rgba(0,0,0,.35); animation: flySheet .22s ease-out;
}
@keyframes flySheet { from { opacity: 0; transform: translateY(14px); } }

/* HUD Flycam */
body.fly #fly-hud { display: block; position: fixed; inset: 0; pointer-events: none; z-index: 6; }
#fly-hud > * { pointer-events: auto; }
.fly-stats {
  position: fixed; top: calc(var(--fly-top, 70px) + 58px); left: 12px; display: flex; flex-direction: column; gap: 6px;
}
.fly-stats span, .fly-btn, .fly-round {
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
}
.fly-stats span {
  background: rgba(20,28,40,.55); color: #fff; font-weight: 700; font-size: 13.5px; padding: 6px 12px; border-radius: 99px;
  box-shadow: 0 4px 12px rgba(0,0,0,.2); width: max-content;
}
.fly-stats b { font-weight: 900; }
.fly-bar {
  position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); display: flex; gap: 8px;
  max-width: calc(100vw - 24px); overflow-x: auto; padding: 4px; scrollbar-width: none;
}
.fly-bar::-webkit-scrollbar { display: none; }
.fly-btn {
  flex: none; border: 0; cursor: pointer; font: 800 14px var(--title); color: var(--ink); padding: 10px 14px; border-radius: 16px;
  background: rgba(255,248,234,.9); box-shadow: 0 4px 0 rgba(59,42,24,.35), 0 8px 18px rgba(0,0,0,.22); white-space: nowrap;
}
.fly-btn i { font-style: normal; background: var(--no); color: #fff; border-radius: 99px; padding: 0 7px; margin-left: 3px; font-size: 12px; }
.fly-btn.gold { background: linear-gradient(180deg, #ffe082, #ffc53d); }
.fly-btn:disabled { opacity: .55; cursor: default; box-shadow: 0 2px 0 rgba(59,42,24,.25); }
.fly-btn:not(:disabled):active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(59,42,24,.35); }
.fly-cam { position: fixed; right: 12px; top: 50%; transform: translateY(-50%); display: flex; flex-direction: column; gap: 10px; }
.fly-round {
  width: 50px; height: 50px; border-radius: 50%; border: 0; cursor: pointer; font-size: 22px;
  background: rgba(255,248,234,.9); box-shadow: 0 4px 0 rgba(59,42,24,.35), 0 8px 18px rgba(0,0,0,.22);
}
.fly-round.on { background: linear-gradient(180deg, #7ed957, #3f9e2c); }
.fly-round:active { transform: translateY(3px); }

/* Điện thoại: thanh trên 2 hàng, bảng điều khiển thành tấm trượt từ dưới lên */
@media (max-width: 760px) {
  body.fly #topbar { top: 6px; left: 6px; right: 6px; border-radius: 14px; }
  body.fly #goal { font-size: 12.5px; padding: 6px 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: calc(100vw - 16px); }
  /* Thanh trên gọn 1 hàng số liệu trong Flycam */
  body.fly #topbar { padding: 6px 8px; gap: 6px; }
  body.fly .stats { gap: 5px; }
  body.fly .stat { padding: 4px 9px; font-size: 13px; }
  body.fly .icon-btn { padding: 4px 6px; font-size: 15px; }
  body.fly .xpbar { display: none; }
  .fly-stats { top: auto; bottom: 84px; left: 8px; flex-direction: row; flex-wrap: wrap; right: 70px; }
  .fly-stats span { font-size: 12px; padding: 5px 9px; }
  .fly-cam { top: calc(var(--fly-top, 110px) + 52px); transform: none; right: 8px; gap: 8px; flex-direction: row; }
  .fly-round { width: 44px; height: 44px; font-size: 19px; }
  .fly-bar { bottom: 12px; left: 8px; right: 8px; transform: none; max-width: none; }
  .fly-btn { padding: 9px 11px; font-size: 13px; }
  /* Cao hơn một chút nhưng không che hàng nút tròn phía trên (fly-top + 52px + nút 44px + khoảng hở) */
  body.fly.fly-panel #panel { left: 6px; right: 6px; top: auto; bottom: 76px; width: auto; height: min(66vh, calc(100vh - var(--fly-top, 110px) - 106px - 76px)); }
  /* 8 tab gộp 1 hàng cuộn ngang (thay 2 hàng) → vùng nội dung rộng hơn; kéo ngang hoặc bấm tab, tab đang chọn tự cuộn vào giữa */
  body.fly #tabs {
    display: flex; grid-template-columns: none; gap: 2px; padding: 5px 6px 0; overflow-x: auto; overflow-y: hidden;
    scroll-snap-type: x proximity; scrollbar-width: none; overscroll-behavior-x: contain; touch-action: pan-x;
    -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 14px, #000 calc(100% - 14px), transparent 100%);
    mask-image: linear-gradient(90deg, transparent 0, #000 14px, #000 calc(100% - 14px), transparent 100%);
  }
  body.fly #tabs::-webkit-scrollbar { display: none; }
  body.fly .tab { flex: 0 0 auto; min-width: 68px; padding: 6px 8px 5px; scroll-snap-align: center; }
  body.fly .tab .ti { font-size: 19px; }
  body.fly .tab .tn { font-size: 10.5px; }
  body.fly.fly-panel .fly-stats { display: none; }
}
@media (prefers-reduced-motion: reduce) { body.fly.fly-panel #panel { animation: none; } }
/* Bảng nổi có chiều cao cố định → nội dung phải tự cuộn bên trong. style.css @media 900px đặt #panel-body overflow: visible
   nên ở đây phải bật lại, kèm min-height: 0 để phần tử flex co được.
   overscroll-behavior: cuộn tới cuối không kéo theo bản đồ / trang phía sau. */
body.fly.fly-panel #panel { flex-direction: column; }
body.fly.fly-panel #panel-body {
  flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden;
  overscroll-behavior: contain; -webkit-overflow-scrolling: touch; touch-action: pan-y;
}

/* Đồng hồ + thanh tiến độ nổi trên từng ô ruộng */
#fly-labels { display: none; }
body.fly #fly-labels { display: block; position: fixed; inset: 0; pointer-events: none; z-index: 4; overflow: hidden; }
.fly-label {
  position: absolute; left: 0; top: 0; background: rgba(255,248,234,.92); border-radius: 9px; padding: 2px 6px 3px;
  font: 800 11px var(--title); color: var(--ink); text-align: center; box-shadow: 0 2px 6px rgba(0,0,0,.25); min-width: 40px; will-change: transform;
}
.fly-label b { display: block; line-height: 1.2; }
.fly-lbar { display: block; height: 4px; background: #eadbc0; border-radius: 4px; overflow: hidden; margin-top: 1px; }
.fly-lbar i { display: block; height: 100%; background: linear-gradient(90deg, #7ed957, #3f9e2c); }
.fly-round.coach { animation: coach 1.3s ease-in-out infinite; }

/* ============================================================
   Kính mờ (glassmorphism): mọi khung nổi trên bản đồ có nền trong, làm nhòe cảnh phía sau
   → vẫn thấy bản đồ xuyên qua. Chữ giữ độ tương phản bằng nền đủ đậm + bóng chữ nhẹ.
   ============================================================ */
body.fly {
  --glass-light: rgba(255, 250, 240, .52);
  --glass-light-2: rgba(255, 250, 240, .68);
  --glass-dark: rgba(30, 22, 14, .38);
  --glass-edge: rgba(255, 255, 255, .45);
  --glass-blur: blur(14px) saturate(1.5);
}
/* Thanh trên: gỗ trong suốt */
body.fly #topbar {
  background: linear-gradient(180deg, rgba(92, 60, 34, .5), rgba(60, 38, 20, .42));
  -webkit-backdrop-filter: var(--glass-blur); backdrop-filter: var(--glass-blur);
  border: 1px solid rgba(255, 255, 255, .22);
  box-shadow: 0 8px 28px rgba(0, 0, 0, .22), inset 0 1px 0 rgba(255, 255, 255, .25);
  text-shadow: 0 1px 2px rgba(0, 0, 0, .45);
}
body.fly #topbar .stat { background: rgba(0, 0, 0, .22); box-shadow: inset 0 1px 2px rgba(0, 0, 0, .25), 0 1px 0 rgba(255, 255, 255, .12); }
body.fly #topbar .icon-btn { background: rgba(255, 255, 255, .16); box-shadow: 0 2px 0 rgba(0, 0, 0, .25), inset 0 1px 0 rgba(255, 255, 255, .25); }
/* Dòng mục tiêu: viên kính màu nhấn */
body.fly #goal {
  background: var(--accent-dark, #1e6fb8);
  background: color-mix(in srgb, var(--accent-dark, #1e6fb8) 62%, transparent);
  -webkit-backdrop-filter: var(--glass-blur); backdrop-filter: var(--glass-blur);
  border: 1px solid rgba(255, 255, 255, .3);
}
/* Chỉ số dân số / thuế / giá trị */
.fly-stats span {
  background: var(--glass-dark); border: 1px solid rgba(255, 255, 255, .18);
  -webkit-backdrop-filter: var(--glass-blur); backdrop-filter: var(--glass-blur); text-shadow: 0 1px 2px rgba(0, 0, 0, .5);
}
/* Nút thao tác nhanh + nút camera */
.fly-btn, .fly-round {
  background: var(--glass-light); border: 1px solid var(--glass-edge);
  -webkit-backdrop-filter: var(--glass-blur); backdrop-filter: var(--glass-blur);
  box-shadow: 0 6px 18px rgba(0, 0, 0, .18), inset 0 1px 0 rgba(255, 255, 255, .6);
}
.fly-btn:hover:not(:disabled), .fly-round:hover { background: var(--glass-light-2); }
.fly-btn:disabled { background: rgba(255, 250, 240, .32); box-shadow: 0 3px 10px rgba(0, 0, 0, .12); }
.fly-btn.gold { background: linear-gradient(180deg, rgba(255, 224, 130, .78), rgba(255, 197, 61, .7)); }
.fly-round.on { background: linear-gradient(180deg, rgba(126, 217, 87, .8), rgba(63, 158, 44, .75)); }
/* Đồng hồ trên ruộng */
.fly-label {
  background: rgba(255, 250, 240, .62); border: 1px solid rgba(255, 255, 255, .5);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
}
.fly-lbar { background: rgba(120, 90, 50, .25); }
/* Bảng điều khiển: kính sáng, thẻ bên trong cũng trong để thấy bản đồ phía sau */
body.fly.fly-panel #panel {
  background: rgba(255, 250, 240, .5); border: 1px solid var(--glass-edge);
  -webkit-backdrop-filter: blur(18px) saturate(1.5); backdrop-filter: blur(18px) saturate(1.5);
  box-shadow: 0 14px 40px rgba(0, 0, 0, .28), inset 0 1px 0 rgba(255, 255, 255, .6);
}
body.fly #tabs { background: rgba(255, 244, 220, .35); border-bottom-color: rgba(255, 255, 255, .35); }
body.fly .tab.on { background: rgba(255, 250, 240, .8); }
body.fly #panel-body .card { background: rgba(255, 255, 255, .62); border-color: rgba(255, 255, 255, .6); box-shadow: 0 3px 10px rgba(0, 0, 0, .08); }
body.fly #panel-body .card.daily, body.fly #panel-body .card.event { background: rgba(255, 246, 214, .66); }
/* Cửa sổ (modal) trên bản đồ: kính sáng hơn chút để dễ đọc */
body.fly .backdrop { background: rgba(20, 12, 4, .28); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); }
body.fly .modal {
  background: rgba(255, 250, 240, .78); border: 1px solid var(--glass-edge);
  -webkit-backdrop-filter: blur(20px) saturate(1.4); backdrop-filter: blur(20px) saturate(1.4);
  box-shadow: 0 20px 50px rgba(0, 0, 0, .35), inset 0 1px 0 rgba(255, 255, 255, .7);
}
/* Máy không hỗ trợ làm nhòe nền: tăng độ đục để chữ vẫn dễ đọc */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .fly-btn, .fly-round, .fly-label { background: rgba(255, 250, 240, .9); }
  body.fly.fly-panel #panel, body.fly .modal { background: rgba(255, 250, 240, .95); }
  body.fly #topbar { background: rgba(74, 46, 23, .88); }
}
.fly-btn .ico, .fly-stats .ico { margin-right: 3px; }
.fly-round .ico { display: block; margin: auto; }

/* ---------- PC: thanh trên tách 2 box (trái: logo + thời đại · phải: chỉ số + nút) ----------
   Khoảng giữa trong suốt, không nhận chuột → vẫn kéo/xoay bản đồ được, bớt che bản đồ.
   #topbar vẫn giữ nguyên vị trí/chiều cao để --fly-top (flycam.js) tính đúng chỗ cho dòng mục tiêu và các nút. */
@media (min-width: 761px) {
  body.fly #topbar {
    background: none; border: 0; box-shadow: none; -webkit-backdrop-filter: none; backdrop-filter: none;
    padding: 0; gap: 0; align-items: stretch; pointer-events: none;
  }
  body.fly #topbar > * { pointer-events: auto; }
  body.fly #topbar .brand, body.fly #topbar .era-box, body.fly #topbar .stats {
    background: linear-gradient(180deg, rgba(92, 60, 34, .5), rgba(60, 38, 20, .42));
    -webkit-backdrop-filter: var(--glass-blur); backdrop-filter: var(--glass-blur);
    border: 1px solid rgba(255, 255, 255, .22);
    box-shadow: 0 6px 18px rgba(0, 0, 0, .2), inset 0 1px 0 rgba(255, 255, 255, .25);
  }
  body.fly #topbar .brand { padding: 8px 12px 8px 16px; border-radius: 18px 0 0 18px; border-right: 0; }
  body.fly #topbar .era-box {
    display: flex; flex-direction: column; justify-content: center; padding: 6px 18px 6px 14px;
    border-radius: 0 18px 18px 0; border-left: 1px solid rgba(255, 255, 255, .15);
  }
  body.fly #topbar .stats { margin-left: auto; padding: 7px 10px; border-radius: 18px; flex-wrap: nowrap; }
}
/* Màn PC hẹp: 2 box cộng lại ~880px → bỏ chữ cạnh logo và thanh kinh nghiệm (số cấp vẫn hiện) để không đè nhau */
@media (min-width: 761px) and (max-width: 960px) {
  body.fly #topbar .brand span, body.fly #topbar .xpbar { display: none; }
}
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  @media (min-width: 761px) {
    body.fly #topbar { background: none; }
    body.fly #topbar .brand, body.fly #topbar .era-box, body.fly #topbar .stats { background: rgba(74, 46, 23, .88); }
  }
}

/* ---------- weather3d: chỉ báo thời tiết + mùa (js/flycam/weather3d.js), viên kính mờ nhỏ, không nhận chuột ---------- */
#fly-wx { display: none; }
body.fly #fly-wx {
  display: block; position: fixed; left: 12px; bottom: 82px; z-index: 6; pointer-events: none;
  background: var(--glass-dark); color: #fff; font-weight: 700; font-size: 12.5px; padding: 5px 11px; border-radius: 99px;
  border: 1px solid rgba(255, 255, 255, .18); box-shadow: 0 4px 12px rgba(0, 0, 0, .2); text-shadow: 0 1px 2px rgba(0, 0, 0, .5);
  -webkit-backdrop-filter: var(--glass-blur); backdrop-filter: var(--glass-blur); white-space: nowrap;
}
body.fly #fly-wx[hidden] { display: none; }
@media (max-width: 760px) {
  body.fly #fly-wx { bottom: auto; top: calc(var(--fly-top, 110px) + 60px); left: 8px; font-size: 11.5px; padding: 4px 9px; }
}
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  body.fly #fly-wx { background: rgba(30, 22, 14, .75); }
}

/* ---------- timelapse: tua nhanh thời gian khi chuyển thời đại (js/flycam/timelapse3d.js) ----------
   Lớp phủ mỏng (bộ đếm năm + thời đại cũ → mới + Bỏ qua) rồi thẻ thời đại kính mờ nổi trên bản đồ. */
body.fly-tl #fly-hud, body.fly-tl #fly-labels, body.fly-tl #goal { display: none; }
body.fly-tl #fly-root canvas { cursor: default !important; }
.tl-layer { position: fixed; inset: 0; z-index: 70; pointer-events: none; color: #fff; }
.tl-layer > * { pointer-events: auto; }
.tl-top {
  position: absolute; left: 50%; top: calc(var(--fly-top, 70px) + 12px); transform: translateX(-50%);
  min-width: 240px; max-width: calc(100vw - 24px); padding: 10px 22px 12px; text-align: center; border-radius: 20px;
  background: rgba(20, 14, 40, .38); border: 1px solid rgba(255, 255, 255, .28);
  -webkit-backdrop-filter: blur(10px) saturate(1.3); backdrop-filter: blur(10px) saturate(1.3);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .3); animation: tlIn .5s ease-out; pointer-events: none;
}
.tl-cap { font-size: 12px; font-weight: 800; letter-spacing: 3px; text-transform: uppercase; opacity: .85; }
.tl-year { font-family: var(--title); font-weight: 800; font-size: 40px; line-height: 1.1; margin: 2px 0 4px; font-variant-numeric: tabular-nums; text-shadow: 0 0 18px rgba(179, 136, 255, .8), 0 2px 0 rgba(0, 0, 0, .35); }
.tl-eras { display: flex; gap: 10px; justify-content: center; align-items: center; flex-wrap: wrap; font-weight: 800; font-size: 14px; }
.tl-eras span:first-child { opacity: .7; }
.tl-eras b { color: #ffd23f; }
.tl-bar { height: 4px; margin-top: 8px; border-radius: 4px; background: rgba(255, 255, 255, .2); overflow: hidden; }
.tl-bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #b388ff, #ffd23f); border-radius: 4px; }
.tl-skip { position: absolute; right: 16px; bottom: 16px; }
.tl-done .tl-top { opacity: 0; transition: opacity .4s; }
.tl-card {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(520px, calc(100vw - 24px)); max-height: calc(100vh - 32px); overflow-y: auto; box-sizing: border-box;
  padding: 22px 24px 20px; text-align: center; border-radius: 24px; color: #2b1d0e;
  background: rgba(255, 250, 240, .72); border: 1px solid var(--glass-edge, rgba(255, 255, 255, .45));
  -webkit-backdrop-filter: blur(20px) saturate(1.4); backdrop-filter: blur(20px) saturate(1.4);
  box-shadow: 0 20px 50px rgba(0, 0, 0, .35), inset 0 1px 0 rgba(255, 255, 255, .7);
  animation: tlCard .6s cubic-bezier(.2, 1.3, .4, 1);
}
.tl-ic { font-size: 54px; line-height: 1.1; }
.tl-card h2 { margin: 4px 0; font-size: 28px; font-family: var(--title); }
.tl-years { margin: 0 0 10px; opacity: .7; font-weight: 700; }
.tl-story { line-height: 1.6; font-size: 15px; margin: 0 0 16px; }
@keyframes tlIn { from { opacity: 0; transform: translate(-50%, -12px); } }
@keyframes tlCard { from { opacity: 0; transform: translate(-50%, -44%) scale(.92); } }
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .tl-top { background: rgba(20, 14, 40, .8); }
  .tl-card { background: rgba(255, 250, 240, .96); }
}
@media (max-width: 760px) {
  .tl-top { padding: 8px 14px 10px; min-width: 0; width: max-content; }
  .tl-year { font-size: 30px; }
  .tl-eras { font-size: 12px; gap: 6px; }
  .tl-card { padding: 18px 16px 16px; border-radius: 20px; }
  .tl-ic { font-size: 44px; }
  .tl-card h2 { font-size: 23px; }
  .tl-story { font-size: 14px; line-height: 1.5; }
  .tl-skip { right: 10px; bottom: 12px; }
}
@media (prefers-reduced-motion: reduce) {
  .tl-top, .tl-card { animation: none; }
  .tl-done .tl-top { transition: none; }
}
