/* garden.css — หน้า "🌳 สวนของฉัน" (รางวัล) — คู่กับ garden.js
 * โหลดต่อจาก styles.css / manage.css / records.css / member.css → ใช้ตัวแปรและ .panel/.user-avatar เดิมได้
 * ตัวแปรที่ใช้: --ink --muted --card --line --radius --shadow --primary --ring (นิยามใน styles.css/manage.css)
 * โทน: พาสเทล "กระดาษสมุดครู" — การ์ดนุ่ม มุมมน หัวข้อฟอนต์ Prompt
 * มือถือเป็นหลัก แล้วค่อยขยายที่ 561 / 1025 */

/* ---------------- โครงหน้า ---------------- */
.garden { display: flex; flex-direction: column; gap: 18px; padding-bottom: 8px; }
.garden-loading,
.garden-error {
  text-align: center; color: var(--muted); font-family: "Prompt", sans-serif;
  padding: 60px 16px; font-size: 1rem;
}
.garden-error small { color: #b91c1c; }

/* ---------------- แถบหัว + กระเป๋าแต้ม ---------------- */
.garden-head {
  display: flex; flex-direction: column; gap: 14px;
  padding: 20px 22px; border-radius: var(--radius);
  border: 1px solid rgba(99, 102, 241, 0.14); box-shadow: var(--shadow);
  /* ลายเดียวกับการ์ดทักทายหน้าแรก: กริดขาว + ไล่เฉดพาสเทล */
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.5) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.5) 1px, transparent 1px),
    linear-gradient(135deg, #d1fae5 0%, #e0f2fe 34%, #ede9fe 66%, #fce7f3 100%);
  background-size: 50px 50px, 50px 50px, 100% 100%;
}
.gh-title { min-width: 0; }
.garden-title {
  font-family: "Prompt", sans-serif; font-weight: 700; margin: 0;
  font-size: clamp(1.3rem, 4vw, 1.7rem); line-height: 1.3; color: var(--ink);
}
.garden-sub { margin: 4px 0 0; font-size: 0.9rem; color: #475569; }

.wallet { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.w-chip {
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  background: rgba(255, 255, 255, 0.82); border: 1px solid rgba(99, 102, 241, 0.16);
  border-radius: 16px; padding: 10px 8px; text-align: center;
  box-shadow: 0 6px 14px -12px rgba(30, 58, 138, 0.4);
}
.w-chip .w-ic { font-size: 1.15rem; line-height: 1; }
.w-chip b { font-family: "Prompt", sans-serif; font-weight: 700; font-size: 1.15rem; color: var(--ink); line-height: 1.2; }
.w-chip small { font-size: 0.72rem; color: var(--muted); }
.w-chip.w-points { background: linear-gradient(135deg, #fef9c3, #fde68a); border-color: #fcd34d; }
.w-chip.w-points b { color: #92400e; }

/* ---------------- โครง 2 คอลัมน์: ต้นไม้ | (โปรไฟล์ + รางวัล) ---------------- */
.garden-main { display: grid; grid-template-columns: 1fr; gap: 18px; align-items: start; }
.garden-side { display: flex; flex-direction: column; gap: 18px; }

/* ---------------- แผงต้นไม้ (พระเอก) ---------------- */
.tree-panel { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.tree-stage {
  position: relative; overflow: hidden;
  width: 100%; border-radius: 18px;
  /* ท้องฟ้าพาสเทลอ่อน → พื้นหญ้ามินต์ */
  background:
    radial-gradient(120% 80% at 50% 120%, #d9f5e4 0%, rgba(217, 245, 228, 0) 55%),
    linear-gradient(180deg, #eaf6ff 0%, #f2fbff 52%, #eafaf0 100%);
  border: 1px solid #e5eefc;
}
.tree-svg { display: block; width: 100%; max-width: 280px; height: auto; margin: 6px auto 0; }

/* ชิ้นส่วน SVG */
.tree-shadow { fill: rgba(30, 58, 138, 0.12); }
.pot-rim { fill: #d98d54; }
.pot-body { fill: #e8a06b; }
.soil { fill: #6b4a2f; }
.pot-hint { font-size: 22px; opacity: 0.5; }
.seed-dot { fill: #c8e6a0; }

/* กลุ่มต้นไม้ + สีใบ/เปลือกผ่านตัวแปร (เปลี่ยนตามสุขภาพ) */
.plant { --leaf-a: #2f8f46; --leaf-b: #5cbf6f; --bark: #7c5a3a; }
.gl-a { fill: var(--leaf-a); }
.gl-b { fill: var(--leaf-b); }
.br { fill: none; stroke: var(--bark); stroke-linecap: round; stroke-linejoin: round; }
.fl-p { fill: #ffffff; stroke: #e5e7eb; stroke-width: 0.4; }
.fl-c { fill: #fde047; }

/* ระยะออกดอกหายาก → ดอกชมพู เกสรทอง */
.plant.rare .fl-p { fill: #fbcfe8; stroke: #f9a8d4; }
.plant.rare .fl-c { fill: #f59e0b; }

/* สุขภาพ: แข็งแรง = เขียวสด + แกว่งเบา ๆ; เหี่ยว = เหลืองอมเขียว; พักตัว/ตาย = น้ำตาลเทา */
.plant.state-healthy { --leaf-a: #2f8f46; --leaf-b: #5cbf6f; }
.plant.state-wilting { --leaf-a: #8a9a3a; --leaf-b: #b6c25a; }
.plant.state-dormant { --leaf-a: #9a8b6b; --leaf-b: #b7a988; --bark: #8a7a63; }
.plant.state-dead { --bark: #9ca3af; }

/* จุดหมุนที่โคนต้น (ล่างกลางของ bbox) — แกว่งไกวยามลม */
.plant { transform-box: fill-box; transform-origin: 50% 100%; }
.plant.state-healthy { animation: gsway 4.6s ease-in-out infinite; }
.plant.state-wilting { animation: gswayWilt 6s ease-in-out infinite; }
@keyframes gsway {
  0%, 100% { transform: rotate(-1.6deg); }
  50% { transform: rotate(1.6deg); }
}
@keyframes gswayWilt {
  0%, 100% { transform: rotate(-0.6deg) translateY(1px); }
  50% { transform: rotate(0.8deg) translateY(2px); }
}
/* ดอกเต้นระยิบเบา ๆ ตอนบาน */
.flowers .fl { transform-box: fill-box; transform-origin: center; animation: gtwinkle 3.2s ease-in-out infinite; }
@keyframes gtwinkle {
  0%, 100% { transform: scale(1); opacity: 0.96; }
  50% { transform: scale(1.12); opacity: 1; }
}

/* ป้ายสถานะต้นไม้ */
.tree-state-chip {
  font-family: "Prompt", sans-serif; font-weight: 600; font-size: 0.88rem;
  padding: 6px 16px; border-radius: 999px; text-align: center;
}
.tree-state-chip.st-healthy { background: #dcfce7; color: #15803d; }
.tree-state-chip.st-wilting { background: #fef9c3; color: #a16207; }
.tree-state-chip.st-dormant { background: #f1f5f9; color: #475569; }
.tree-state-chip.st-dead { background: #fee2e2; color: #b91c1c; }
.tree-state-chip.st-empty { background: #eef2ff; color: #4338ca; }

/* แถบเติบโต */
.growth { width: 100%; }
.growth-bar { height: 12px; border-radius: 999px; background: #e8eefb; overflow: hidden; box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.08); }
.growth-bar span {
  display: block; height: 100%; border-radius: 999px;
  background: linear-gradient(90deg, #86efac, #22c55e);
  transition: width 0.5s cubic-bezier(0.22, 1, 0.36, 1);
}
.growth-label { text-align: center; font-size: 0.82rem; color: var(--muted); margin-top: 6px; }
.growth-label b { color: #15803d; font-family: "Prompt", sans-serif; }
.growth.bloomed .growth-label { color: #b45309; font-weight: 600; }

/* สถิติต้นไม้ */
.tree-stats { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 16px; font-size: 0.84rem; color: var(--muted); }
.tree-stats b { color: var(--ink); font-family: "Prompt", sans-serif; }
.tree-stats .rare-tag { color: #be185d; font-weight: 600; }

/* ปุ่มดูแลต้นไม้ */
.tree-actions { display: flex; flex-direction: column; align-items: center; gap: 8px; width: 100%; }
.tree-btns { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; width: 100%; }
.tree-hint { margin: 0; font-size: 0.8rem; color: #b45309; text-align: center; }

/* ปุ่มหลัก (action) — ฐานร่วม, สีแยกตาม data-act */
.g-btn {
  font-family: "Prompt", sans-serif; font-weight: 600; font-size: 0.92rem;
  color: #fff; border: none; border-radius: 14px; cursor: pointer;
  padding: 12px 18px; display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  box-shadow: 0 8px 18px -10px rgba(30, 58, 138, 0.5);
  transition: transform 0.15s ease, filter 0.15s ease, box-shadow 0.15s ease;
}
.g-btn:hover:not(:disabled) { transform: translateY(-2px); filter: brightness(1.05); }
.g-btn:active:not(:disabled) { transform: translateY(0); }
.g-btn:disabled { background: #e2e8f0; color: #9aa6b2; box-shadow: none; cursor: not-allowed; }
.g-btn .cost { font-size: 0.78rem; font-weight: 700; opacity: 0.92; }
.g-btn[data-act="water"] { background: linear-gradient(135deg, #60a5fa, #38bdf8); }
.g-btn[data-act="fertilize"] { background: linear-gradient(135deg, #34d399, #10b981); }
.g-btn[data-act="plant"] { background: linear-gradient(135deg, #4ade80, #22c55e); }
.g-btn[data-act="revive"] { background: linear-gradient(135deg, #a78bfa, #8b5cf6); }
.g-btn[data-act="savehandle"] { background: linear-gradient(135deg, #6366f1, #8b5cf6); }

/* confetti โปรยตอนออกดอก */
.g-confetti { position: absolute; top: -14px; will-change: transform, opacity; pointer-events: none; animation: gfall 1.4s ease-in forwards; z-index: 2; }
@keyframes gfall {
  0% { transform: translateY(0) rotate(0); opacity: 0; }
  15% { opacity: 1; }
  100% { transform: translateY(220px) rotate(200deg); opacity: 0; }
}

/* ---------------- หัวข้อแผงย่อย (ใช้ทั่วหน้า) ---------------- */
.g-panel-title { font-family: "Prompt", sans-serif; font-weight: 700; font-size: 1.05rem; margin: 0; color: var(--ink); }
.g-panel-sub { color: var(--muted); font-size: 0.85rem; margin: 4px 0 14px; }
.g-panel-sub b { color: var(--ink); font-family: "Prompt", sans-serif; }

/* ---------------- แผงโปรไฟล์ ---------------- */
.gp-preview { display: grid; place-items: center; padding: 8px 0 4px; }
.gp-preview { display: grid; place-items: center; padding: 8px 0 4px; }
/* วงอวตารพรีวิว — override .user-avatar ให้ใหญ่; ปล่อยให้ setAvatar วาดกรอบ/อวตาร/สีพื้นเอง */
.gp-avatar {
  width: 100px; height: 100px; font-size: 2rem;
}
.gp-meta { display: flex; flex-direction: column; gap: 4px; margin-top: 12px; font-size: 0.86rem; color: var(--muted); text-align: center; }
.gp-meta b { color: var(--ink); font-family: "Prompt", sans-serif; }

/* ---------------- หิ้งรางวัล ---------------- */
.trophy-shelf { display: flex; flex-wrap: wrap; gap: 6px; }
.trophy { font-size: 1.5rem; line-height: 1; animation: gpop 0.4s ease backwards; }
@keyframes gpop { from { opacity: 0; transform: scale(0.4) translateY(6px); } }
.trophy-more { margin: 10px 0 0; font-size: 0.82rem; color: var(--muted); }
.trophy-empty { margin: 6px 0 0; color: var(--muted); font-size: 0.9rem; }

/* ---------------- ร้านค้าแต้ม ---------------- */
.shop-panel .panel-head { margin-bottom: 12px; }
.shop-tabs { display: flex; gap: 8px; overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 4px; margin-bottom: 14px; }
.shop-tab {
  flex: 0 0 auto; font-family: "Prompt", sans-serif; font-size: 0.9rem;
  padding: 9px 16px; border-radius: 999px; border: 1.5px solid var(--line);
  background: #fff; color: var(--muted); cursor: pointer; white-space: nowrap;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.shop-tab:hover { color: var(--ink); border-color: var(--primary); }
.shop-tab.active { background: var(--primary); border-color: var(--primary); color: #fff; }

.care-note {
  margin: 0 0 14px; font-size: 0.85rem; color: #4338ca;
  background: #eef2ff; border-radius: 12px; padding: 10px 14px;
}
.shop-empty { color: var(--muted); font-size: 0.9rem; text-align: center; padding: 24px 0; }

.shop-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.shop-card {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  background: #fff; border: 1px solid #eef2ff; border-radius: 16px;
  padding: 16px 12px 14px; text-align: center;
  box-shadow: 0 8px 18px -14px rgba(30, 58, 138, 0.35);
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}
.shop-card:hover { transform: translateY(-3px); box-shadow: 0 16px 30px -18px rgba(30, 58, 138, 0.45); }
.shop-card.is-equipped { border-color: #86efac; background: #f0fdf4; }
.sc-emoji {
  font-size: 1.7rem; width: 56px; height: 56px; display: grid; place-items: center;
  border-radius: 16px; background: #f4f7ff; margin-bottom: 2px;
}
/* พรีวิวในการ์ดร้านค้า: อวตารสัตว์ (SVG) / สีพื้นหลัง (สแวตช์) / กรอบ (วง+ornament) */
.sc-preview { width: 56px; height: 56px; margin: 0 auto 2px; display: grid; place-items: center; position: relative; }
.sc-animal { border-radius: 50%; overflow: hidden; width: 56px; height: 56px; }
.sc-animal svg { width: 100%; height: 100%; display: block; }
.sc-swatch { width: 52px; height: 52px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 2px 6px -1px rgba(15, 23, 42, 0.3); }
.sc-frame { width: 44px; height: 44px; }
.sc-frame .sc-frame-in {
  width: 44px; height: 44px; border-radius: 50%; background: #eef2ff;
  display: grid; place-items: center; font-size: 1.1rem;
}
.sc-name { font-family: "Prompt", sans-serif; font-weight: 600; font-size: 0.92rem; color: var(--ink); line-height: 1.3; }
.sc-desc { font-size: 0.78rem; color: var(--muted); line-height: 1.35; }
.sc-price { font-family: "Prompt", sans-serif; font-weight: 600; font-size: 0.82rem; color: #b45309; }
.sc-price.free { color: #15803d; }
.sc-price.owned { color: #15803d; }
.sc-price.locked { color: #7c3aed; font-size: 0.76rem; }

/* ปุ่มในการ์ดร้านค้า (เล็กกว่า .g-btn) */
.sc-btn {
  margin-top: 4px; font-family: "Prompt", sans-serif; font-weight: 600; font-size: 0.85rem;
  padding: 8px 16px; border-radius: 999px; border: none; cursor: pointer;
  background: var(--primary); color: #fff; transition: filter 0.15s ease, transform 0.15s ease;
}
.sc-btn:hover:not(:disabled) { filter: brightness(1.06); transform: translateY(-1px); }
.sc-btn:disabled { background: #e2e8f0; color: #9aa6b2; cursor: not-allowed; }
.sc-btn.equip { background: #22c55e; }
.sc-btn.unequip { background: #fff; color: #b91c1c; border: 1.5px solid #fecaca; }
.sc-btn.danger { background: #fff; color: #b91c1c; border: 1.5px solid #fecaca; }
.sc-btn.upload { display: inline-flex; align-items: center; justify-content: center; background: #4338ca; }

/* การ์ดความสามารถอัปโหลดรูป — เต็มแถว ใต้ตาราง char */
.ability-wrap { margin-top: 12px; }
.ability-card { flex-direction: row; flex-wrap: wrap; align-items: center; text-align: left; gap: 10px; }
.ability-card .sc-emoji { margin-bottom: 0; }
.ability-card .sc-name { flex: 1 1 120px; min-width: 0; }
.ability-card .sc-desc { flex: 1 1 100%; }

/* ---------------- กระดานผู้นำ ---------------- */
.lb-form { display: flex; gap: 8px; margin-bottom: 8px; }
.lb-input {
  flex: 1; min-width: 0; padding: 10px 14px; border: 1.5px solid var(--line);
  border-radius: 12px; font-family: inherit; font-size: 0.92rem; color: var(--ink); background: #fff;
}
.lb-input:focus { border-color: var(--primary); box-shadow: 0 0 0 4px var(--ring); outline: none; }
.lb-hint { margin: 0 0 12px; font-size: 0.78rem; color: var(--muted); }
.lb-empty { color: var(--muted); font-size: 0.9rem; text-align: center; padding: 24px 0; }

.lb-table { display: flex; flex-direction: column; gap: 6px; margin-top: 4px; }
.lb-metable { margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--line); }
.lb-row {
  display: grid; grid-template-columns: 34px 1fr auto auto; align-items: center; gap: 10px;
  padding: 10px 12px; border: 1px solid #eef2ff; border-radius: 12px; background: #fff;
}
.lb-row.lb-head { background: transparent; border: none; padding: 0 12px; }
.lb-row.lb-head span { font-size: 0.74rem; color: var(--muted); font-weight: 600; }
.lb-rank { font-family: "Prompt", sans-serif; font-weight: 700; color: var(--muted); text-align: center; }
.lb-handle { font-family: "Prompt", sans-serif; font-weight: 600; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.lb-handle em { font-style: normal; font-size: 0.66rem; font-weight: 700; background: #e0e7ff; color: #4338ca; padding: 1px 7px; border-radius: 999px; margin-left: 4px; }
.lb-score { font-family: "Prompt", sans-serif; font-weight: 700; color: #1d4ed8; font-size: 0.92rem; }
.lb-blooms { font-size: 0.86rem; color: var(--muted); min-width: 30px; text-align: right; }
.lb-row.lb-me { border-color: #c4b5fd; background: #f5f3ff; box-shadow: 0 6px 14px -12px rgba(99, 102, 241, 0.6); }
/* อันดับ 1–3 เน้นทอง/เงิน/ทองแดง */
.lb-table .lb-row:not(.lb-head):nth-child(2) .lb-rank { color: #d97706; }
.lb-table .lb-row:not(.lb-head):nth-child(3) .lb-rank { color: #64748b; }
.lb-table .lb-row:not(.lb-head):nth-child(4) .lb-rank { color: #b45309; }

/* ===================== จอกว้างขึ้น ===================== */
@media (min-width: 561px) {
  .garden-head { flex-direction: row; align-items: center; justify-content: space-between; }
  .wallet { grid-template-columns: repeat(4, 1fr); flex: 0 0 auto; }
  .w-chip { min-width: 78px; }
  .shop-grid { grid-template-columns: repeat(3, 1fr); }
  .tree-btns { flex-wrap: nowrap; }
}
@media (min-width: 1025px) {
  .garden-main { grid-template-columns: 1.5fr 1fr; }
  .tree-svg { max-width: 320px; }
  .shop-grid { grid-template-columns: repeat(4, 1fr); }
}

/* ===================== เคารพผู้ปิดแอนิเมชัน ===================== */
@media (prefers-reduced-motion: reduce) {
  .plant,
  .plant.state-healthy,
  .plant.state-wilting,
  .flowers .fl,
  .trophy,
  .g-confetti { animation: none !important; }
  .growth-bar span { transition: none; }
  .g-btn,
  .sc-btn,
  .shop-card,
  .shop-tab { transition: none; }
  .g-btn:hover:not(:disabled),
  .sc-btn:hover:not(:disabled),
  .shop-card:hover { transform: none; }
}
