/* Thành phần dùng chung: nút, chip, thanh trên, popup, toast, thanh tiến độ. Theo docs/07; cỡ bấm tối thiểu 44px. */
:root {
  --screen-bg: #e8dcc4;
  --panel: #f6ecd6;
  --panel-line: #8d6a43;
  --green: #4d7c3a;
  --green-deep: #3a5f2b;
  --gold: #f0b429;
  --danger: #a83e28;
  --ink-soft: #6b5640;
}

.screen.page { background: var(--screen-bg); align-items: stretch; }
.page { max-width: 34rem; margin-inline: auto; width: 100%; }
#app[data-orientation='portrait'] .screen.page { max-width: none; }
.screen.page > * { width: 100%; max-width: 34rem; margin-inline: auto; flex: none; }

.topbar { display: flex; align-items: center; gap: var(--space-3); }
.topbar h1 { flex: 1; min-width: 0; font-size: 1.375rem; }
.topbar-right { margin-left: auto; }
.back { width: 3.25rem; height: 3.25rem; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem; min-height: 2.9rem; padding: 0.55rem 1.25rem;
  border: 2px solid var(--panel-line); border-radius: 0.9rem; font-family: var(--font-display); font-size: 1.125rem; font-weight: 800; line-height: 1.15; text-align: center;
  transition: transform 120ms ease-out, filter 120ms; box-shadow: 0 3px 0 rgb(58 38 22 / 0.35);
}
.btn:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 rgb(58 38 22 / 0.35); }
.btn-primary { background: var(--green); border-color: var(--green-deep); color: #fff; }
.btn-light { background: var(--panel); color: var(--ink); }
.btn-danger { background: var(--danger); border-color: #7b2616; color: #fff; }
.btn-gold { background: var(--gold); border-color: #b9831a; color: #3a2616; }
.btn-block { display: flex; width: 100%; }
.btn:disabled, .btn[aria-disabled='true'] { opacity: 0.5; box-shadow: none; filter: saturate(0.5); }
/* Nút bị khoá: nền be, chữ nâu đậm → vẫn đọc rõ lý do (vd. "Không đủ ATP") */
.btn:is(.btn-primary, .btn-gold, .btn-danger):disabled { opacity: 1; filter: none; background: #e4d8bd; border-color: #b9a888; color: #5a4630; }
.btn.btn-lg { min-height: 3.5rem; font-size: 1.375rem; }
.btn small { display: block; font-family: var(--font-body); font-size: 0.8rem; font-weight: 700; opacity: 0.9; }
@media (hover: hover) { .btn:hover:not(:disabled) { filter: brightness(1.05); transform: translateY(-1px); } }

.chip {
  display: inline-flex; align-items: center; gap: 0.3rem; min-height: 2.75rem; padding: 0.2rem 0.85rem; border: 2px solid var(--panel-line); border-radius: 999px;
  background: var(--panel); font-family: var(--font-display); font-weight: 700; font-size: 1rem; white-space: nowrap; line-height: 1;
}
.chip img { width: 1.5rem; height: 1.5rem; }
.chip b { font-weight: 800; margin-right: 0.35rem; }
.chip b:last-child { margin-right: 0; }

.field {
  width: 100%; min-height: 2.9rem; padding: 0.5rem 1rem; border: 2px solid var(--panel-line); border-radius: 0.9rem; background: var(--panel);
  font: inherit; font-weight: 700; color: var(--ink);
}
.field::placeholder { color: var(--ink-soft); opacity: 0.8; }
select.field { width: auto; padding-right: 0.5rem; }

.panel { border: 2px solid var(--panel-line); border-radius: 1rem; background: var(--panel); padding: var(--space-4); box-shadow: 0 2px 0 rgb(58 38 22 / 0.2); }
.panel h2 { font-family: var(--font-display); font-size: 1.15rem; font-weight: 800; line-height: 1.25; margin-bottom: 0.25rem; }
.muted { color: var(--ink-soft); font-weight: 600; font-size: 0.95rem; }
.row { display: flex; align-items: center; gap: 0.6rem; }
.stack { display: flex; flex-direction: column; gap: 0.75rem; }
.grow { flex: 1; min-width: 0; }
.hide { display: none !important; }

.bar { height: 0.75rem; border-radius: 999px; background: #d9c8a4; overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: inherit; background: var(--green); transition: width 300ms ease-out; }
.bar.gold i { background: #d99a2b; }

.pills { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.pill-btn {
  min-height: 2.75rem; padding: 0.35rem 1rem; border: 2px solid var(--panel-line); border-radius: 999px; background: var(--panel);
  font-family: var(--font-display); font-weight: 800; font-size: 1rem; line-height: 1.1;
}
.pill-btn[aria-pressed='true'], .pill-btn.is-on { background: var(--green); border-color: var(--green-deep); color: #fff; }

.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; }
.seg .btn { min-height: 3.25rem; }

/* Popup: đóng bằng nút X đỏ, bấm ra ngoài hoặc phím Esc */
.popup-backdrop {
  position: absolute; inset: 0; z-index: 50; display: grid; place-items: center; padding: 1rem; overflow-y: auto;
  background: rgb(30 20 10 / 0.62); animation: fade-in 140ms ease-out;
}
.popup-backdrop > :not(.popup-x) { grid-area: 1 / 1; }
.popup-x {
  grid-area: 1 / 1; position: sticky; top: 0; justify-self: end; align-self: start; z-index: 6; margin: -0.3rem -0.3rem 0 0;
  width: 3rem; height: 3rem; border: 3px solid #fff6e0; border-radius: 50%; background: #d3382a; color: #fff;
  font: 800 2rem/1 var(--font-display); display: grid; place-items: center; padding: 0 0 0.2rem; cursor: pointer; box-shadow: 0 3px 8px rgb(0 0 0 / 0.5);
}
.popup-x.popup-x-in { position: absolute; grid-area: auto; top: -0.9rem; right: -0.9rem; margin: 0; }
.popup-x:active { transform: scale(0.92); }
.popup-backdrop.is-leaving { opacity: 0; transition: opacity 140ms; }
.popup-box { width: min(100%, 26rem); padding: 1.25rem; border: 2px solid var(--panel-line); border-radius: 1.1rem; background: var(--panel); animation: pop-in 180ms cubic-bezier(.2,.9,.3,1.2); }
.popup-box.kw-box, .popup-box.guide-box { position: relative; }
.guide-steps { list-style: none; display: flex; flex-direction: column; gap: 0.4rem; margin: 0.6rem 0 0.9rem; }
.guide-steps li { display: flex; gap: 0.6rem; align-items: center; padding: 0.45rem 0.7rem; border-radius: 0.7rem; background: #f3e6c9; font-weight: 700; }
.guide-steps li.done { background: #dcebc6; color: #3b5a22; }
.guide-tick { flex: none; width: 1.5rem; height: 1.5rem; display: grid; place-items: center; border-radius: 50%; border: 2px solid currentColor; font-weight: 800; font-size: 0.9rem; }
.popup-box h2 { font-family: var(--font-display); font-size: 1.35rem; font-weight: 800; margin-bottom: 0.4rem; line-height: 1.2; }
.popup-box p { margin-bottom: 0.5rem; }
.popup-actions { display: flex; gap: 0.6rem; margin-top: 0.8rem; }
.popup-actions .btn { flex: 1; }
.kw-box h2 { color: var(--keyword); }
.kw-group { font-size: 0.85rem; color: var(--ink-soft); }
@keyframes fade-in { from { opacity: 0; } }
@keyframes pop-in { from { opacity: 0; transform: scale(0.92) translateY(8px); } }

.toast {
  position: absolute; z-index: 60; left: 50%; bottom: calc(1.25rem + var(--safe-bottom)); transform: translateX(-50%); max-width: min(92%, 28rem);
  padding: 0.65rem 1.1rem; border-radius: 0.9rem; background: #3a2616; color: #fff6e0; font-weight: 800; text-align: center; box-shadow: var(--lift); animation: toast-in 200ms ease-out;
}
.toast.good { background: var(--green-deep); }
.toast.bad { background: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 10px); } }

.fx-layer { position: fixed; inset: 0; width: 100vw; height: 100vh; z-index: 90; pointer-events: none; }
.empty-note { padding: 1.25rem; border: 2px dashed var(--panel-line); border-radius: 1rem; background: #d9c8a4; text-align: center; font-weight: 700; color: var(--ink-soft); }
.screen.page { padding-bottom: calc(var(--space-6) + var(--safe-bottom)); gap: var(--space-3); }

/* Thanh trên cùng dính khi cuộn (quay lại / bộ lọc luôn trong tầm tay) */
.screen.page > .topbar, .screen.page > .sticky-head {
  position: sticky; z-index: 20; background: inherit;
  top: calc(-1 * (var(--space-4) + var(--safe-top))); margin-top: calc(-1 * (var(--space-4) + var(--safe-top)));
  padding-top: calc(var(--space-3) + var(--safe-top));
}
.sticky-head { display: flex; flex-direction: column; gap: 0.4rem; padding-bottom: 0.4rem; }
.sticky-head .topbar { width: 100%; }
.screen.page > .topbar { padding-bottom: 0.3rem; }
.filters-compact { display: flex; flex-direction: column; gap: 0.4rem; }
.filters-row { display: flex; gap: 0.5rem; align-items: center; }
.filters-row .field { flex: 1; min-width: 0; min-height: 2.75rem; }
.filters-toggle { flex: none; min-height: 2.75rem; padding: 0.2rem 0.9rem; font-size: 0.95rem; }
.filters-panel { padding: 0.5rem; border: 2px solid var(--panel-line); border-radius: 0.9rem; background: var(--panel); }

/* Nút bị khoá: giữ nền đặc (không làm mờ) để chữ không bị lẫn với nền phía sau, thêm ổ khoá + viền đỏ */
.btn.is-locked { opacity: 1; filter: none; background: #5a4636; border-color: #d3382a; color: #ffe1db; box-shadow: none; position: relative; }
.btn.is-locked::before {
  content: ''; display: inline-block; width: 1.05em; height: 1.05em; margin-right: 0.35em; vertical-align: -0.12em;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23ffe1db'%3E%3Cpath d='M17 9h-1V7a4 4 0 0 0-8 0v2H7a2 2 0 0 0-2 2v8a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2v-8a2 2 0 0 0-2-2zm-7-2a2 2 0 0 1 4 0v2h-4V7z'/%3E%3C/svg%3E") center / contain no-repeat;
}
.deck-counter.over { background: #d3382a; border-color: #8e1f15; color: #fff; }

/* Hướng dẫn lần đầu */
