/* ============================================================
   Trà Sữa Idle — giao diện
   ------------------------------------------------------------
   Mobile-first, tông ấm kiểu quán trà. Mọi hình vẽ đều là SVG
   nhúng sẵn (không icon font, không emoji của hệ điều hành) nên
   hiển thị giống nhau trên mọi máy và chơi offline được.

   Quy ước màu của "ô icon": mỗi mục game được gán một hue (xem
   js/look.js), CSS tự suy ra nền/viền/màu nét từ hue đó. Nhờ vậy
   danh sách nhiều màu mà không phải khai báo từng mã màu.
   ============================================================ */
:root {
  --bg: #fdf3e4;
  --bg-2: #f7e7cd;
  --panel: #fffaf2;
  --panel-2: #fdf6ea;
  --line: #eddcc0;
  --line-2: #e0c9a4;

  --ink: #3a2317;
  --ink-2: #7a5a48;
  --ink-3: #a68b6d;

  --pink: #ef6f8e;
  --pink-ink: #9c3250;
  --gold: #d99423;
  --gold-d: #a96f1f;
  --brand-1: #8a5a2b;
  --brand-2: #6f4218;
  --mint: #2f7355;
  --mint-2: #245c44;

  --radius: 15px;
  --shadow-s: 0 1px 2px rgba(58, 35, 23, .05), 0 3px 8px rgba(58, 35, 23, .05);
  --shadow-m: 0 2px 4px rgba(58, 35, 23, .06), 0 10px 24px rgba(58, 35, 23, .08);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  font-size: 15px;
  line-height: 1.4;
  -webkit-user-select: none; user-select: none;
  overscroll-behavior-y: none;
}

button { font: inherit; color: inherit; }
button:focus-visible, [tabindex]:focus-visible {
  outline: 3px solid var(--pink);
  outline-offset: 2px;
}
.ico { display: block; flex: none; }
.cico { display: block; flex: none; }
/* Hình màu tự vẽ của game (xem js/art.js). */
.art { display: block; flex: none; }
/* Kho <symbol> ẩn: chỉ để <use> tham chiếu tới. */
.ico-sprite, .art-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.app {
  max-width: 560px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
}

/* ============================================================
   Header
   ============================================================ */
.head {
  position: relative;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: calc(env(safe-area-inset-top, 0px) + 13px) 14px 14px;
  background:
    radial-gradient(120% 80% at 88% -20%, rgba(255, 255, 255, .18), transparent 60%),
    radial-gradient(circle at 1px 1px, rgba(255, 255, 255, .07) 1.5px, transparent 0) 0 0 / 13px 13px,
    linear-gradient(155deg, var(--brand-1), var(--brand-2));
  color: #fff;
  border-radius: 0 0 20px 20px;
  box-shadow: 0 6px 18px rgba(58, 35, 23, .18);
}
.head-brand { display: flex; align-items: center; gap: 11px; min-width: 0; }
.head-logo {
  flex: none; line-height: 0; border-radius: 13px;
  box-shadow: 0 3px 10px rgba(0, 0, 0, .25);
}
.head-logo svg,
.head-logo img { display: block; border-radius: 13px; }
.head-txt { min-width: 0; }
.head h1 {
  margin: 0; font-size: 19px; font-weight: 800; letter-spacing: .01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.head-sub {
  margin: 2px 0 0; font-size: 11px; font-weight: 600;
  color: rgba(255, 255, 255, .76);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.icon-btn {
  flex: none;
  display: grid; place-items: center;
  width: 40px; height: 40px; padding: 0;
  background: rgba(255, 255, 255, .15);
  border: 1px solid rgba(255, 255, 255, .18);
  border-radius: 12px; color: #fff; cursor: pointer;
  transition: background .15s, transform .1s;
}
.icon-btn .ico { width: 20px; height: 20px; }
.icon-btn:hover { background: rgba(255, 255, 255, .26); }
.icon-btn:active { transform: scale(.93); }

/* ============================================================
   Tài nguyên
   ============================================================ */
.stats {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 8px; padding: 12px 12px 4px;
}
.stat {
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 9px 4px 8px;
  box-shadow: var(--shadow-s);
  text-align: center; min-width: 0;
}
.stat-ico { line-height: 0; margin-bottom: 2px; }
.stat-ico .art { width: 25px; height: 25px; }
.stat-label {
  font-size: 9px; font-weight: 700; letter-spacing: .14em;
  text-transform: uppercase; color: var(--ink-3);
}
.stat-val {
  font-size: 17px; font-weight: 800; letter-spacing: -.01em;
  font-variant-numeric: tabular-nums;
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.stat-rate {
  font-size: 10px; font-weight: 700; color: var(--mint);
  font-variant-numeric: tabular-nums;
}
.stat-rate.is-flat { color: var(--ink-3); }

/* ============================================================
   Nút pha trà
   ============================================================ */
.brew { padding: 8px 12px 4px; }
.brew-btn {
  position: relative; display: flex; align-items: center; justify-content: center;
  gap: 14px; width: 100%; padding: 14px 16px;
  border: 0; border-radius: 22px; cursor: pointer; overflow: hidden;
  color: #fff;
  background:
    radial-gradient(90% 120% at 20% -20%, rgba(255, 255, 255, .28), transparent 60%),
    linear-gradient(168deg, #e0a53a, var(--gold-d));
  box-shadow: 0 6px 0 #8c5a15, 0 12px 26px rgba(169, 111, 31, .34);
  transition: transform .08s ease, box-shadow .08s ease;
}
.brew-btn:active, .brew-btn.is-pop {
  transform: translateY(4px);
  box-shadow: 0 2px 0 #8c5a15, 0 6px 14px rgba(169, 111, 31, .3);
}
.brew-art { position: relative; line-height: 0; filter: drop-shadow(0 4px 6px rgba(90, 50, 10, .3)); }
.brew-art svg { display: block; }
.brew-txt { display: flex; flex-direction: column; align-items: flex-start; gap: 3px; }
.brew-label { font-size: 19px; font-weight: 900; letter-spacing: .16em; }
.brew-sub { font-size: 11.5px; font-weight: 700; color: rgba(255, 255, 255, .88); }

/* hơi nước bốc lên */
.cup-steam { opacity: .55; animation: steam 3s ease-in-out infinite; }
.cup-steam path:nth-child(2) { animation-delay: .9s; }
@keyframes steam {
  0%   { opacity: 0; transform: translateY(4px); }
  30%  { opacity: .7; }
  70%  { opacity: .45; }
  100% { opacity: 0; transform: translateY(-7px); }
}
/* bong bóng trà nổi lên */
.cup-bub { opacity: 0; animation: bubb 2.8s ease-in infinite; }
.cup-bub.b2 { animation-delay: .9s; }
.cup-bub.b3 { animation-delay: 1.7s; }
@keyframes bubb {
  0%   { opacity: 0; transform: translateY(6px) scale(.7); }
  25%  { opacity: .75; }
  100% { opacity: 0; transform: translateY(-13px) scale(1); }
}

/* số bay lên khi bấm */
.floaty {
  position: absolute; left: 50%; top: 45%;
  transform: translateX(-50%);
  font-size: 14px; font-weight: 900; color: #fff;
  text-shadow: 0 1px 4px rgba(90, 50, 10, .5);
  white-space: nowrap; pointer-events: none;
  animation: floatUp .95s cubic-bezier(.2, .7, .3, 1) forwards;
}
@keyframes floatUp {
  0%   { opacity: 0; transform: translate(-50%, 8px) scale(.85); }
  18%  { opacity: 1; transform: translate(-50%, -4px) scale(1.06); }
  100% { opacity: 0; transform: translate(-50%, -42px) scale(1); }
}
/* tia sáng bắn ra khi bấm */
.spark {
  position: absolute; width: 9px; height: 9px; pointer-events: none;
  background: #fff6d8;
  clip-path: polygon(50% 0, 60% 40%, 100% 50%, 60% 60%, 50% 100%, 40% 60%, 0 50%, 40% 40%);
  animation: sparkOut .62s ease-out forwards;
}
@keyframes sparkOut {
  0%   { opacity: 1; transform: translate(0, 0) scale(.4) rotate(0deg); }
  100% { opacity: 0; transform: translate(var(--dx), var(--dy)) scale(1.1) rotate(140deg); }
}

/* Huy hiệu "tay nhanh" khi bấm liên tiếp */
.combo {
  position: absolute; top: 9px; right: 12px;
  padding: 3px 9px; border-radius: 999px;
  background: rgba(255, 255, 255, .22);
  border: 1px solid rgba(255, 255, 255, .32);
  color: #fff; font-size: 10px; font-weight: 900; letter-spacing: .05em;
  animation: comboIn .18s ease-out;
}
.combo.is-hot { background: #fff; color: var(--gold-d); border-color: #fff; }
@keyframes comboIn { from { opacity: 0; transform: translateY(-5px) scale(.9); } to { opacity: 1; transform: none; } }
.floaty.is-crit { font-size: 19px; color: #fff7dc; letter-spacing: .02em; }
.brew-btn.is-crit { animation: critShake .26s ease-out; }
@keyframes critShake {
  0%, 100% { transform: translateY(4px); }
  25%      { transform: translate(3px, 4px); }
  75%      { transform: translate(-3px, 4px); }
}

.hint {
  margin: 9px 6px 0; font-size: 11.5px; line-height: 1.5;
  color: var(--ink-2); text-align: center;
}

/* ============================================================
   Tab
   ============================================================ */
.tabbar {
  position: sticky; top: 0; z-index: 6;
  display: grid; grid-template-columns: repeat(5, 1fr);
  gap: 5px; padding: 10px 12px 9px;
  background: rgba(253, 243, 228, .93);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.tab {
  position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 7px 2px 6px; cursor: pointer;
  background: var(--panel); color: var(--ink-2);
  border: 1px solid var(--line); border-radius: 12px;
  font-size: 9.5px; font-weight: 700; line-height: 1.1;
  transition: background .15s, color .15s, border-color .15s;
}
.tab .ico { width: 16px; height: 16px; }
.tab.is-active {
  color: #fff; border-color: transparent;
  background: linear-gradient(160deg, var(--brand-1), var(--brand-2));
  box-shadow: 0 3px 10px rgba(111, 66, 24, .28);
}
.tab-dot {
  position: absolute; top: 4px; right: 6px;
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--pink); border: 1.5px solid var(--panel);
}
.tab.is-active .tab-dot { border-color: var(--brand-2); }

/* ============================================================
   Danh sách
   ============================================================ */
.list { flex: 1; padding: 2px 12px 20px; }

.summary {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px;
  margin: 2px 2px 10px; font-size: 11.5px; font-weight: 600; color: var(--ink-2);
}
.summary .ico { width: 14px; height: 14px; color: var(--ink-3); }
.summary b { color: var(--ink); font-variant-numeric: tabular-nums; }

.group-head {
  display: flex; align-items: center; gap: 7px;
  margin: 15px 2px 8px; font-size: 10.5px; font-weight: 800;
  letter-spacing: .12em; text-transform: uppercase; color: var(--ink-3);
}
.group-head:first-child { margin-top: 4px; }
.group-head .ico { width: 15px; height: 15px; }
.group-head b { color: var(--ink-2); font-weight: 800; }

.row {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center; gap: 10px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 10px;
  margin-bottom: 8px; box-shadow: var(--shadow-s);
  transition: border-color .18s, box-shadow .18s;
}
.row.is-buyable {
  border-color: #dcb571;
  box-shadow: 0 0 0 1px rgba(217, 148, 35, .22), 0 4px 14px rgba(169, 111, 31, .12);
}

/* ô icon: màu suy ra từ --h */
.tile {
  display: grid; place-items: center;
  width: 46px; height: 46px; flex: none;
  border-radius: 13px;
  background: linear-gradient(160deg, hsl(var(--h) 82% 95%), hsl(var(--h) 72% 89%));
  border: 1px solid hsl(var(--h) 48% 82%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .7);
}
.tile .art { width: 30px; height: 30px; }
.tile .ico { width: 22px; height: 22px; color: hsl(var(--h) 52% 33%); }
.row.is-muted .tile { filter: grayscale(.7) opacity(.7); }

.row-body { min-width: 0; }
.row-top { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.row-name { margin: 0; font-size: 14px; font-weight: 800; line-height: 1.25; }
.row-desc {
  margin: 3px 0 0; font-size: 11.5px; line-height: 1.45; color: var(--ink-2);
}
.row-meta {
  display: flex; flex-wrap: wrap; gap: 3px 9px; margin-top: 5px;
  font-size: 10.5px; font-weight: 600; color: var(--ink-3);
}
.meta { display: inline-flex; align-items: center; gap: 3px; }
.meta .ico { width: 13px; height: 13px; color: currentColor; }
.meta .art { width: 15px; height: 15px; }
.meta.is-good { color: var(--mint); }

.pill {
  display: inline-flex; align-items: center; gap: 3px;
  padding: 1px 7px; border-radius: 999px;
  background: var(--bg-2); color: var(--gold-d);
  font-size: 10px; font-weight: 800; white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.pill.is-mint { background: #e2f0e8; color: var(--mint); }
.pill.is-plain { background: #f0e7d8; color: var(--ink-2); }

.buy {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  min-width: 92px; padding: 9px 9px; cursor: pointer;
  border: 0; border-radius: 12px; color: #fff;
  background: linear-gradient(160deg, #3a8463, var(--mint-2));
  box-shadow: 0 2px 0 #1c4835, 0 3px 8px rgba(36, 92, 68, .25);
  font-size: 11px; font-weight: 800; line-height: 1.2; text-align: center;
  transition: transform .08s, box-shadow .08s, filter .15s;
}
.buy .ico { width: 15px; height: 15px; opacity: .9; }
.buy b { font-size: 11.5px; font-variant-numeric: tabular-nums; }
.buy:active { transform: translateY(2px); box-shadow: 0 0 0 #1c4835; }
.buy.is-gold {
  background: linear-gradient(160deg, #e0a53a, var(--gold-d));
  box-shadow: 0 2px 0 #8c5a15, 0 3px 8px rgba(169, 111, 31, .25);
}
.buy.is-gold:active { box-shadow: 0 0 0 #8c5a15; }
/* Trạng thái khoá phải đứng SAU .is-gold: hai selector cùng độ ưu tiên,
   selector đứng sau thắng — nếu để trước, nút vàng hết tiền vẫn trông như bấm được. */
.buy:disabled, .buy.is-gold:disabled {
  background: #ded3c0; color: #a1907a; box-shadow: none;
  cursor: default; filter: none;
}
.buy:disabled .ico { opacity: .6; }

/* ---- thành tựu ---- */
.ach-summary { margin-bottom: 12px; }
.bar {
  flex: 1 1 100%; height: 7px; border-radius: 999px;
  background: var(--bg-2); overflow: hidden;
}
.bar > i { display: block; height: 100%; border-radius: 999px;
  background: linear-gradient(90deg, var(--gold), var(--pink)); transition: width .35s; }

.ach.is-done { border-color: #b6d9c6; background: #fbfdf9; }
.ach.is-done .row-name { color: var(--mint); }
.ach.is-locked .row-name { color: var(--ink-2); }
.ach.is-locked .row-desc { color: var(--ink-3); }
.ach-mark { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 10px; flex: none; }
.ach-mark .ico { width: 19px; height: 19px; }
.ach.is-done .ach-mark { background: #e2f0e8; color: var(--mint); }
.ach.is-locked .ach-mark { background: #f2ebdd; color: var(--ink-3); }

/* ---- trạng thái rỗng ---- */
.empty {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  margin: 18px 0; padding: 26px 18px; text-align: center;
  border: 1.5px dashed var(--line-2); border-radius: var(--radius);
  color: var(--ink-3); font-size: 12.5px; line-height: 1.5;
}
.empty .ico { width: 26px; height: 26px; }

/* ============================================================
   Toast
   ============================================================ */
.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom, 0px) + 22px);
  z-index: 60;
  display: flex; align-items: center; gap: 8px;
  max-width: min(88vw, 400px);
  padding: 10px 15px 10px 12px;
  transform: translateX(-50%);
  background: linear-gradient(160deg, #4a2f14, #33200e);
  color: #fff; border-radius: 999px;
  font-size: 12.5px; font-weight: 700; line-height: 1.3;
  box-shadow: 0 8px 22px rgba(58, 35, 23, .32);
  animation: toastIn .26s cubic-bezier(.2, .9, .3, 1.2);
}
.toast .art { width: 23px; height: 23px; }
.toast .ico { width: 18px; height: 18px; color: var(--gold); }
.toast.out { opacity: 0; transform: translate(-50%, 10px); transition: opacity .35s, transform .35s; }
@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, 14px) scale(.9); }
  to   { opacity: 1; transform: translate(-50%, 0) scale(1); }
}

/* ============================================================
   Bộ lọc nhóm thành tựu (125 mục nên phải chia nhóm)
   ============================================================ */
.chips {
  display: flex; gap: 6px; overflow-x: auto;
  padding: 2px 2px 10px; margin: 0 -2px;
  -webkit-overflow-scrolling: touch; scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; padding: 6px 11px; cursor: pointer; white-space: nowrap;
  background: var(--panel); color: var(--ink-2);
  border: 1px solid var(--line); border-radius: 999px;
  font-size: 11px; font-weight: 700;
}
.chip b { font-weight: 800; opacity: .7; font-variant-numeric: tabular-nums; }
.chip.is-on {
  color: #fff; border-color: transparent;
  background: linear-gradient(160deg, var(--brand-1), var(--brand-2));
}
.chip.is-on b { opacity: .88; }
.ach-next { flex: 1 1 100%; margin-top: 3px; font-size: 11px; color: var(--ink-3); }

/* ============================================================
   Chi nhánh (vòng chơi thứ hai)
   ============================================================ */
.branch-card {
  display: flex; align-items: center; gap: 11px;
  margin: 2px 0 10px; padding: 12px;
  border: 1px solid var(--line-2); border-radius: 16px;
  background: linear-gradient(160deg, #fffaf0, #f8e9d0);
  box-shadow: var(--shadow-s);
}
.branch-card-b { min-width: 0; }
.branch-n { font-size: 14px; font-weight: 800; }
.branch-n b { font-size: 20px; font-variant-numeric: tabular-nums; }
.branch-m { margin-top: 2px; font-size: 11.5px; color: var(--ink-2); }
.branch-req { margin: 0 2px 10px; }
.branch-req .bar { display: block; margin-top: 6px; }
.branch-note {
  display: flex; gap: 8px; align-items: flex-start;
  margin-bottom: 12px; padding: 10px 12px;
  background: var(--bg-2); border-radius: 12px;
  font-size: 11px; line-height: 1.55; color: var(--ink-2);
}
.branch-note .ico { width: 15px; height: 15px; flex: none; margin-top: 1px; color: var(--ink-3); }
.branch-note b { color: var(--ink); }
.buy.wide {
  flex-direction: row; justify-content: center; gap: 8px;
  width: 100%; min-width: 0; margin-bottom: 6px;
  padding: 14px 12px; font-size: 13px;
}
.buy.wide b { font-size: 12px; font-weight: 700; opacity: .92; }
.buy.wide .ico { width: 18px; height: 18px; }
.branch-row .tile { width: 38px; height: 38px; border-radius: 11px; }
.branch-row .tile .ico { width: 19px; height: 19px; }
.branch-row.is-done { border-color: #b6d9c6; background: #fbfdf9; }

/* ============================================================
   Hộp thoại xác nhận (làm lại từ đầu)
   ============================================================ */
.sheet {
  position: fixed; inset: 0; z-index: 80;
  display: grid; place-items: center; padding: 20px;
  background: rgba(58, 35, 23, .46);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  animation: sheetIn .16s ease-out;
}
.sheet-card {
  width: 100%; max-width: 330px;
  padding: 22px 18px 16px; text-align: center;
  background: var(--panel); border-radius: 20px;
  box-shadow: 0 18px 46px rgba(58, 35, 23, .38);
  animation: cardIn .22s cubic-bezier(.2, .9, .3, 1.14);
}
.sheet-ico {
  display: grid; place-items: center;
  width: 62px; height: 62px; margin: 0 auto 10px;
  border-radius: 19px; background: var(--bg-2);
}
.sheet-card h2 { margin: 0 0 7px; font-size: 17px; font-weight: 800; }
.sheet-card p { margin: 0; font-size: 12.5px; line-height: 1.5; color: var(--ink-2); }
.sheet-lose {
  margin-top: 12px; padding: 10px 12px; text-align: left;
  background: var(--bg-2); border-radius: 12px;
  font-size: 11.5px; line-height: 1.5; color: var(--ink-2);
}
.sheet-lose b { color: var(--ink); }
.sheet-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 16px; }
.sheet-actions button {
  padding: 12px 8px; border: 0; border-radius: 13px;
  font-size: 13px; font-weight: 800; cursor: pointer;
  transition: transform .08s;
}
.sheet-actions button:active { transform: translateY(1px); }
.btn-ghost { background: var(--bg-2); color: var(--ink-2); border: 1px solid var(--line); }
.btn-danger {
  color: #fff;
  background: linear-gradient(160deg, #e2574c, #b93a2b);
  box-shadow: 0 3px 10px rgba(185, 58, 43, .3);
}
@keyframes sheetIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes cardIn {
  from { opacity: 0; transform: translateY(12px) scale(.94); }
  to   { opacity: 1; transform: none; }
}

/* ============================================================
   Chân trang + màn hình rộng
   ============================================================ */
.foot {
  padding: 12px 12px calc(env(safe-area-inset-bottom, 0px) + 14px);
  text-align: center; font-size: 10.5px; color: var(--ink-3);
}

@media (min-width: 561px) {
  body { background: linear-gradient(170deg, #f6e6cd, #efdcc0); }
  .app {
    min-height: auto; margin: 16px auto 28px;
    border-radius: 22px; overflow: hidden;
    box-shadow: var(--shadow-m), 0 24px 60px rgba(58, 35, 23, .16);
  }
  .tabbar { border-radius: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
}
