/* ============================================================
 * PLOW & GROW — style.css
 * Theme "cartoon nông trại" đồng nhất:
 *  - Thẻ kem-gỗ viền nâu dày + bóng đổ cứng (chunky, như board game)
 *  - Chữ nâu đậm trên nền kem; tiền/giá luôn màu hổ phách
 *  - Nút mọng kiểu 3D (mép dưới đậm, ấn lún xuống)
 *  - Cỡ LỚN: mục tiêu chạm >= 52px, chữ chính 30px+
 * ============================================================ */
:root {
  --card: linear-gradient(#fff8e6, #f7e7c3);
  --card-flat: #fdf3da;
  --wood: #8a5a34;
  --wood-dark: #6e4224;
  --ink: #5a3a1a;
  --amber: #e08a10;
  --green: #58c53c;
  --green-dark: #3da02c;
  --green-edge: #2f8022;
  --red: #e8402e;
  --radius: 22px;
  --chunk: 0 5px 0 rgba(110, 66, 36, 0.35), 0 8px 18px rgba(60, 40, 15, 0.25);
  --font: 'Segoe UI', 'Arial Rounded MT Bold', Arial, sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: #8ee8f7;
  font-family: var(--font);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }

/* Vignette nhẹ kiểu banner — miễn phí hiệu năng, dưới HUD (z 10) */
#vignette {
  position: fixed; inset: 0; z-index: 5; pointer-events: none;
  background: radial-gradient(ellipse at center,
    transparent 62%, rgba(20, 40, 60, 0.16) 100%);
}

/* ---------- Loading ---------- */
#loading {
  position: fixed; inset: 0; z-index: 100;
  background: linear-gradient(#1e9be0, #bdf2ff);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-size: 64px; color: #fff;
}
#loading small { font-size: 24px; margin-top: 16px; opacity: 0.95; letter-spacing: 5px; font-weight: 900; text-shadow: 0 2px 6px rgba(0,60,90,0.4); }
#loading .spin { animation: bounce 0.9s infinite alternate ease-in-out; }
@keyframes bounce { from { transform: translateY(0); } to { transform: translateY(-18px); } }

/* ---------- Thẻ gỗ-kem chung cho mọi HUD ---------- */
.hud { position: fixed; z-index: 10; pointer-events: none; }
#money, #objective, #contract-chip, #cargo, #toast,
#btn-mute, #btn-full, #btn-ad-double, #btn-ad-grow {
  background: var(--card);
  border: 3px solid var(--wood);
  box-shadow: var(--chunk);
  color: var(--ink);
}

/* ---------- Tiền (trên trái) ---------- */
#money {
  top: max(12px, env(safe-area-inset-top)); left: 14px;
  display: flex; align-items: center; gap: 12px;
  border-radius: var(--radius); padding: 10px 24px 10px 12px;
  color: var(--ink); font-size: 32px; font-weight: 900;
}
#money .coin {
  width: 40px; height: 40px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffe98a, #f0b429 60%, #c98a10);
  border: 3px solid #a86e08;
  flex-shrink: 0;
}

/* ---------- Mục tiêu (trên giữa) ---------- */
#objective {
  top: max(12px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  display: none; align-items: center; gap: 14px;
  border-radius: var(--radius); padding: 10px 24px;
  font-size: 32px;
}
#obj-bar {
  width: 170px; height: 22px;
  background: #e8d5ac;
  border: 2px solid var(--wood);
  border-radius: 11px; overflow: hidden;
}
#obj-fill { height: 100%; width: 0; background: linear-gradient(#8ee87a, var(--green-dark)); border-radius: 8px; transition: width 0.15s; }
#obj-pct { font-size: 22px; font-weight: 900; min-width: 58px; text-align: right; color: var(--ink); }

/* ---------- Contract chip (dưới mục tiêu) ---------- */
#contract-chip {
  top: calc(max(12px, env(safe-area-inset-top)) + 72px); left: 50%; transform: translateX(-50%);
  display: none; align-items: center; gap: 10px;
  border-radius: 18px; padding: 8px 18px;
  font-size: 21px; font-weight: 900;
  white-space: nowrap; flex-wrap: nowrap; /* không xuống dòng trên màn hẹp */
}
#contract-chip .c-rw { color: var(--amber); }

/* ---------- Cargo bar (dưới giữa) ---------- */
#cargo {
  display: none;
  bottom: calc(30px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%);
  width: min(380px, 52vw); height: 36px;
  border-radius: 18px; overflow: hidden;
}
#cargo-fill { height: 100%; width: 0; background: linear-gradient(#ffe173, #f0b429); transition: width 0.12s; }
#cargo-txt {
  position: absolute; inset: 0; text-align: center; line-height: 30px;
  color: var(--ink); font-size: 20px; font-weight: 900;
  text-shadow: 0 1px 0 rgba(255, 248, 220, 0.8);
}

.pulse { animation: pulse 0.7s infinite alternate; }
@keyframes pulse { from { filter: brightness(1); } to { filter: brightness(1.35); } }

/* ---------- Hint: thẻ kem icon + dòng text tiếng Anh ---------- */
#hint {
  display: none;
  top: calc(max(12px, env(safe-area-inset-top)) + 134px); left: 50%; transform: translateX(-50%);
  flex-direction: column; align-items: center; gap: 8px;
  background: var(--card);
  border: 3px solid var(--wood);
  box-shadow: var(--chunk);
  border-radius: 20px; padding: 12px 24px;
  animation: hintBob 0.8s infinite alternate ease-in-out;
}
#hint .hint-ico { display: flex; align-items: center; gap: 8px; font-size: 40px; }
#hint .hint-txt {
  font-size: 22px; font-weight: 900; color: var(--ink);
  white-space: nowrap; text-align: center;
}
@keyframes hintBob { from { transform: translateX(-50%) translateY(0); } to { transform: translateX(-50%) translateY(-8px); } }
.key {
  display: inline-block; min-width: 58px; text-align: center;
  padding: 9px 14px; margin: 0 3px;
  background: linear-gradient(#fdfdfd, #d8d8d8);
  border: 3px solid #8a8a8a; border-bottom-width: 7px; border-radius: 13px;
  font-size: 30px; font-weight: 900; color: #444;
}

/* ---------- Save + nút góc ---------- */
#save-ind {
  bottom: calc(14px + env(safe-area-inset-bottom)); left: 14px;
  font-size: 28px; opacity: 0; transition: opacity 0.3s;
}
#save-ind.show { opacity: 0.9; }

#btn-mute, #btn-full {
  position: fixed; z-index: 11; cursor: pointer;
  font-size: 26px; font-weight: 900;
  top: max(12px, env(safe-area-inset-top));
  width: 56px; height: 56px; border-radius: 50%;
}
#btn-mute { right: 14px; }
#btn-full { right: 80px; }
#btn-mute:active, #btn-full:active { transform: translateY(3px); box-shadow: 0 2px 0 rgba(110,66,36,0.35); }

/* ---------- Nút rewarded ads (thẻ kem viền hổ phách) ---------- */
#btn-ad-double, #btn-ad-grow {
  position: fixed; z-index: 26; display: none;
  align-items: center; justify-content: center; gap: 8px;
  left: 14px;
  border-color: var(--amber);
  border-radius: 20px; padding: 14px 22px;
  font-size: 26px; font-weight: 900;
  cursor: pointer;
}
#btn-ad-double { bottom: calc(66px + env(safe-area-inset-bottom)); }
#btn-ad-grow { bottom: calc(142px + env(safe-area-inset-bottom)); }
#btn-ad-double:active, #btn-ad-grow:active { transform: translateY(3px); box-shadow: 0 2px 0 rgba(110,66,36,0.35); }
#btn-ad-double.done { opacity: 0.8; border-color: var(--green-dark); pointer-events: none; }

/* ---------- Toast ---------- */
#toast {
  position: fixed; z-index: 30; left: 50%; top: 34%;
  transform: translate(-50%, -50%) scale(0.6);
  font-size: 38px; font-weight: 900;
  padding: 18px 36px; border-radius: 28px;
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  text-align: center; white-space: nowrap;
}
#toast.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }

/* ---------- Coin bay lên HUD ---------- */
.fly-coin {
  position: fixed; z-index: 40; width: 30px; height: 30px;
  border-radius: 50%; pointer-events: none;
  background: radial-gradient(circle at 35% 30%, #ffe98a, #f0b429 60%, #c98a10);
  border: 2px solid #a86e08;
  transition: transform 0.55s cubic-bezier(0.5, -0.2, 0.6, 1), opacity 0.55s;
}

/* ---------- Touch controls ---------- */
#joy-zone {
  position: fixed; z-index: 20; display: none;
  left: 0; bottom: 0; width: 50%; height: 65%;
}
#joy-base {
  position: fixed; display: none; width: 156px; height: 156px;
  z-index: 26;
  border-radius: 50%;
  background: rgba(255, 246, 220, 0.28);
  border: 4px solid rgba(255, 250, 235, 0.75);
  pointer-events: none;
}
#joy-knob {
  position: absolute; left: 42px; top: 42px; width: 72px; height: 72px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff8e6, #edd9ae);
  border: 3px solid var(--wood);
  box-shadow: 0 4px 10px rgba(60, 40, 10, 0.35);
}

#btn-ctx, #btn-swap {
  position: fixed; z-index: 26; display: none;
  align-items: center; justify-content: center;
  border-radius: 50%;
  color: #fff; cursor: pointer;
  border: 4px solid rgba(255, 250, 235, 0.85);
  box-shadow: var(--chunk);
  font-weight: 900;
  text-shadow: 0 2px 3px rgba(40, 70, 20, 0.4);
}
#btn-ctx {
  right: 22px; bottom: calc(112px + env(safe-area-inset-bottom));
  width: 108px; height: 108px; font-size: 42px;
  background: radial-gradient(circle at 35% 30%, #7ed36a, var(--green-dark));
  flex-direction: column; text-align: center; line-height: 1.1;
}
#btn-ctx .ctx-sub { font-size: 19px; font-weight: 900; line-height: 1; color: #ffe173; }
#btn-swap {
  right: 144px; bottom: calc(40px + env(safe-area-inset-bottom));
  width: 80px; height: 80px; font-size: 34px;
  background: radial-gradient(circle at 35% 30%, #5db2f0, #2d7fc4);
}
#btn-ctx.pressed, #btn-swap.pressed { transform: scale(0.9); filter: brightness(1.15); }
#btn-ctx.glow { animation: glowPulse 0.8s infinite alternate; }
@keyframes glowPulse {
  from { box-shadow: var(--chunk); }
  to { box-shadow: 0 0 34px 12px rgba(140, 255, 120, 0.85), 0 5px 0 rgba(110, 66, 36, 0.35); }
}

body.touch #joy-zone { display: block; }
body:not(.touch) #btn-ctx, body:not(.touch) #btn-swap { display: none !important; }

/* ---------- Shop panel: bảng gỗ nhà kho ---------- */
#shop {
  position: fixed; z-index: 25;
  right: 0; top: 0; bottom: 0;
  width: min(400px, 88vw);
  background: linear-gradient(#fff8e6, #f2e0b8);
  border-left: 5px solid var(--wood);
  box-shadow: -8px 0 28px rgba(60, 40, 10, 0.35);
  transform: translateX(105%);
  transition: transform 0.25s ease-out;
  display: flex; flex-direction: column;
  padding: max(12px, env(safe-area-inset-top)) 16px 16px;
  color: var(--ink);
}
#shop.open { transform: translateX(0); }
#shop-head {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 32px; font-weight: 900;
  padding: 8px 4px 14px;
  color: var(--wood-dark);
}
#shop-close {
  border: 3px solid var(--wood);
  width: 54px; height: 54px; border-radius: 50%;
  background: var(--card-flat); color: var(--ink);
  font-size: 26px; font-weight: 900; cursor: pointer;
  box-shadow: 0 3px 0 rgba(110, 66, 36, 0.3);
}
#shop-close:active { transform: translateY(2px); box-shadow: none; }
#shop-tabs { display: flex; gap: 10px; margin-bottom: 14px; }
#shop-tabs button {
  flex: 1; border: 3px solid var(--wood); padding: 14px 0;
  border-radius: 18px; font-size: 30px; cursor: pointer;
  background: #efd9ab;
  box-shadow: 0 3px 0 rgba(110, 66, 36, 0.3);
}
#shop-tabs button.active {
  background: linear-gradient(#7ed36a, var(--green-dark));
  border-color: var(--green-edge);
}
#shop-body { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }

.shop-item {
  display: flex; align-items: center; gap: 12px;
  background: rgba(255, 252, 242, 0.85);
  border: 3px solid rgba(138, 90, 52, 0.45);
  border-radius: 18px; padding: 14px;
}
.shop-item.selected { border-color: var(--green-dark); background: rgba(140, 220, 110, 0.22); }
.shop-item .s-ico { font-size: 40px; width: 52px; text-align: center; }
.shop-item .s-info { flex: 1; display: flex; flex-direction: column; }
.shop-item .s-info b { font-size: 22px; color: var(--ink); }
.shop-item .s-info small { font-size: 17px; color: #8a6a42; }
.s-buy {
  border: none; border-radius: 16px;
  min-height: 54px; padding: 12px 18px;
  font-size: 21px; font-weight: 900;
  background: linear-gradient(#7ed36a, #4aa348); color: #fff;
  cursor: pointer; white-space: nowrap;
  box-shadow: 0 4px 0 var(--green-edge);
  text-shadow: 0 1px 2px rgba(40, 70, 20, 0.35);
}
.s-buy:active { transform: translateY(3px); box-shadow: none; }
.s-buy.off {
  background: linear-gradient(#c9bfa8, #a89e88);
  box-shadow: 0 4px 0 #857c68; opacity: 0.9;
}
.s-max { font-weight: 900; color: var(--amber); font-size: 21px; padding: 0 12px; }
.shop-contract {
  margin-top: 10px; padding: 16px;
  background: rgba(240, 180, 41, 0.14);
  border: 3px dashed var(--amber); border-radius: 18px;
  font-size: 22px; text-align: center; line-height: 1.6;
  color: var(--ink);
}

/* Portrait: shop hẹp lại để chừa chỗ cho joystick + nút */
@media (orientation: portrait) {
  #shop { width: min(400px, 62vw); }
}

/* Màn hình hẹp: thu nhỏ có tỉ lệ + XẾP TẦNG DỌC
 * (money trên cùng trái, objective/contract/hint lần lượt bên dưới —
 * không bao giờ đè nhau như khi cùng nằm ngang) */
@media (max-width: 560px) {
  #money { font-size: 25px; padding: 8px 18px 8px 10px; }
  #money .coin { width: 32px; height: 32px; }
  #objective {
    font-size: 25px; padding: 8px 16px;
    top: calc(max(12px, env(safe-area-inset-top)) + 64px);
  }
  #obj-bar { width: 115px; height: 18px; }
  #obj-pct { font-size: 18px; min-width: 48px; }
  #contract-chip { font-size: 17px; top: calc(max(12px, env(safe-area-inset-top)) + 124px); }
  /* Hint mobile: gọn, không che gameplay */
  #hint { top: calc(max(12px, env(safe-area-inset-top)) + 172px); padding: 8px 14px; gap: 4px; }
  #hint .hint-ico { font-size: 26px; gap: 5px; }
  #hint .hint-txt { font-size: 16px; }
  .key { font-size: 20px; min-width: 38px; padding: 6px 9px; border-bottom-width: 5px; }
  #toast { font-size: 28px; }
  #cargo { width: min(320px, 54vw); height: 30px; }
  #cargo-txt { font-size: 17px; line-height: 25px; }
  #btn-mute, #btn-full { width: 50px; height: 50px; font-size: 23px; }
  #btn-full { right: 74px; }
  #btn-ad-double, #btn-ad-grow { font-size: 22px; padding: 11px 17px; }
}
