/* =========================================================================
   Hang MU — home.css
   Design system của hangmu.online (tokens :root) + style trang Home,
   dialogs (Name / Quiz / Legal), Consent, Donate, UpdateNotice, PWA,
   FPS badge, penalty overlay, name tags.
   Load SAU cavescreen.css (chỉ bổ sung, không đè layout hang).
   ========================================================================= */

/* ============ DESIGN TOKENS — :root (theme "hang đá vôi" gốc) ============ */
:root {
  /* vật liệu đá vôi (slab) */
  --hm-limestone: #e8e0d2;
  --hm-limestone-hi: #f7f2e9;
  --hm-limestone-lo: #cbbfa9;
  --hm-ink: #1d150c;

  /* men / đồng mạ vàng */
  --hm-enamel: #0e2a3d;
  --hm-enamel-hi: #16425c;
  --hm-enamel-deep: #081a27;
  --hm-gilt: #d4a83c;
  --hm-gilt-hi: #ecd08c;
  --hm-gilt-lo: #a88438;

  /* phấn / chữ */
  --hm-chalk: #f3e7d8;
  --hm-chalk-dim: #efe9ddb3;

  /* đỏ MU */
  --hm-red: #c8102e;
  --hm-red-hi: #e01f3f;
  --hm-red-deep: #8f0a1f;

  /* đêm / bóng */
  --hm-night: #120b08;
  --hm-shade: #000000;
  --hm-drop: 0 14px 40px -16px #000c;
  --hm-grain: none;

  /* phản hồi */
  --hm-ok: #3fb36b;
  --hm-bad: #ff5a48;
  --hm-perfect: #ffe9a8;
  --hm-torch: #f2c14e;

  /* font */
  --hm-f-body: 'Be Vietnam Pro', system-ui, sans-serif;
  --hm-f-carve: 'Bitter', Georgia, serif;

  /* bảng màu đội (tug/ball) */
  --hm-team-red: #da291c;
  --hm-team-white: #f6f1e7;
}

/* ============ BASE ============ */
html, body {
  margin: 0;
  padding: 0;
  background: #120b08;
  color: #f3e7d8;
  font-family: var(--hm-f-body);
  -webkit-font-smoothing: antialiased;
}
* { box-sizing: border-box; }
#root { min-height: 100dvh; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  clip: rect(0 0 0 0); overflow: hidden; white-space: nowrap;
}

/* ============ HOME — màn hình chính ============ */
.home {
  position: relative;
  min-height: 100dvh;
  display: grid;
  grid-template-rows: 1fr auto auto auto;
  align-items: center;
  justify-items: center;
  gap: 18px;
  padding: max(20px, env(safe-area-inset-top)) 20px max(20px, env(safe-area-inset-bottom));
  overflow: hidden;
  background:
    radial-gradient(120% 90% at 50% 0%, #2b1d12 0%, #140f0c 70%),
    #120b08;
}
.home-scene {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}
.home-scene canvas { display: block; }

/* tấm bia đá (plaque) — nhân vật chính của trang Home */
.plaque {
  position: relative;
  z-index: 1;
  color: var(--hm-chalk);
  background:
    linear-gradient(180deg, rgba(247,242,233,.06), rgba(0,0,0,.35)),
    linear-gradient(180deg, var(--hm-limestone-hi), var(--hm-limestone) 45%, var(--hm-limestone-lo));
  border: 1px solid rgba(0,0,0,.55);
  border-radius: 14px 14px 30px 30px;
  box-shadow:
    inset 0 1px rgba(255,255,255,.55),
    inset 0 -6px 14px rgba(60,42,20,.35),
    inset 0 0 0 4px rgba(236,208,140,.28),
    inset 0 0 0 5px rgba(0,0,0,.35),
    0 24px 60px -20px rgba(0,0,0,.9);
}
.home-panel {
  width: min(560px, 100%);
  text-align: center;
  padding: 26px 30px 24px;
}
.home-head { display: grid; gap: 2px; }
.plaque-kicker {
  margin: 0;
  font: 700 .78rem/1.2 var(--hm-f-body);
  letter-spacing: .28em;
  text-transform: uppercase;
  color: #7a5a24;
}
.plaque-title {
  margin: 0;
  font: 900 clamp(2.6rem, 9vw, 4.2rem)/1 var(--hm-f-carve);
  color: #241708;
  text-shadow: 0 1px 0 #fff9, 0 3px 0 rgba(80,60,40,.25);
}
.plaque-rule {
  border: 0;
  height: 3px;
  margin: 14px auto 12px;
  width: min(320px, 70%);
  background: linear-gradient(90deg, transparent, #a88438, #ecd08c, #a88438, transparent);
  border-radius: 2px;
}
.home-lede {
  margin: 0 auto 10px;
  max-width: 40ch;
  color: #3a2c1c;
  font-size: .98rem;
  line-height: 1.55;
  font-weight: 500;
}
.home-count {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  margin: 4px 0 12px;
  color: #4a3822;
  font-size: .9rem;
  font-weight: 600;
}
.home-wait { color: #7a5a24; }
.home-queue {
  margin: 4px 0 8px;
  padding: 10px 14px;
  color: #3a2c1c;
  background: rgba(0,0,0,.07);
  border: 1px dashed #a88438;
  border-radius: 10px;
  font-size: .9rem;
  line-height: 1.45;
}
.home-queue strong { color: #7a5a24; }
.home-me {
  margin: 12px 0 0;
  font-size: .85rem;
}
.home-me .legal-link {
  color: #5a4424;
  text-decoration: underline;
}

/* ============ NÚT "carved" (khắc đá) ============ */
.carved-btn {
  appearance: none;
  cursor: pointer;
  touch-action: manipulation;
  border: 0;
  font-family: var(--hm-f-carve);
  font-weight: 800;
  border-radius: 10px 10px 18px 10px;
  padding: 13px 26px;
  font-size: 1.05rem;
  transition: filter .15s, transform .1s;
}
.carved-btn:active { transform: scale(.97); }
.carved-btn:focus-visible { outline: 3px solid var(--hm-torch); outline-offset: 3px; }
.carved-btn:disabled { opacity: .45; cursor: default; }
.carved-btn--primary {
  color: #fff4e6;
  background:
    linear-gradient(180deg, rgba(255,255,255,.14), transparent 40%),
    linear-gradient(180deg, var(--hm-red-hi), var(--hm-red) 55%, var(--hm-red-deep));
  box-shadow:
    inset 0 0 0 2px var(--hm-gilt),
    inset 0 0 0 3px rgba(0,0,0,.4),
    0 10px 22px -10px #5a000fcc;
}
.carved-btn--primary:hover { filter: brightness(1.07); }
.carved-btn--ghost {
  color: var(--hm-chalk);
  background:
    linear-gradient(180deg, rgba(247,242,233,.10), transparent 40%),
    linear-gradient(180deg, var(--hm-limestone-hi), var(--hm-limestone) 55%, var(--hm-limestone-lo));
  box-shadow:
    inset 0 1px rgba(255,255,255,.6),
    inset 0 -3px rgba(60,42,20,.4),
    0 6px 14px -8px rgba(0,0,0,.7);
}
.carved-btn--ghost:hover { filter: brightness(1.05); }
.home-enter { min-width: min(320px, 78vw); }

/* ============ HOME LINKS (Telegram + PWA + push) ============ */
.home-links {
  z-index: 1;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 10px;
}
.home-tele {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: #fff;
  text-decoration: none;
  background: linear-gradient(#2aabee, #1b8bc2);
  border-radius: 999px;
  padding: 9px 16px;
  font: 700 .9rem var(--hm-f-body);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.4), 0 6px 18px -6px #229ed9cc;
}
.home-tele:hover { filter: brightness(1.08); }
.home-install, .home-push { flex: none; }
.pwa-button {
  appearance: none;
  cursor: pointer;
  touch-action: manipulation;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--hm-chalk);
  background: rgba(20,13,10,.72);
  border: 1px solid rgba(243,231,216,.35);
  border-radius: 999px;
  padding: 9px 16px;
  font: 600 .9rem var(--hm-f-body);
  transition: background .15s;
}
.pwa-button:hover { background: rgba(20,13,10,.92); }
.pwa-button:focus-visible { outline: 3px solid var(--hm-torch); outline-offset: 2px; }
.pwa-button[data-on] {
  color: #d8ffdd;
  background: rgba(63,179,107,.22);
  border-color: rgba(63,179,107,.6);
}
.pwa-glyph { flex: none; }

/* ============ HOME FOOTER ============ */
.home-footer {
  z-index: 1;
  text-align: center;
  color: rgba(243,231,216,.55);
  font-size: .78rem;
  line-height: 1.5;
  padding: 0 12px;
}
.home-footer .legal-link {
  color: rgba(243,231,216,.75);
  text-decoration: underline;
  background: none; border: 0; cursor: pointer;
  font: inherit;
}

/* ============ TALLY (đếm trong hang) ============ */
.tally {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: #241708;
  font-weight: 800;
}
.tally svg { height: 1.1em; }
.tally-num {
  font: 900 1.15rem/1 var(--hm-f-carve);
  color: #7a5a24;
}

/* ============ DIALOG BACKDROP (Name / Quiz / Legal / PWA) ============ */
.name-backdrop, .legal-backdrop, .pwa-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(6,3,1,.62);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  overflow-y: auto;
}
.name-dialog {
  width: min(460px, 100%);
  text-align: left;
  padding: 26px 28px 24px;
  display: grid;
  gap: 10px;
}
.name-dialog h2 {
  margin: 0;
  font: 900 1.5rem/1.15 var(--hm-f-carve);
  color: #241708;
}
.name-label {
  color: #4a3822;
  font-size: .82rem;
  font-weight: 600;
  line-height: 1.4;
}
.name-input {
  width: 100%;
  color: #241708;
  background: rgba(255,255,255,.55);
  border: 1px solid rgba(80,60,40,.4);
  border-radius: 10px;
  padding: 12px 14px;
  font: 600 1.05rem var(--hm-f-body);
}
.name-input:focus-visible { outline: 3px solid var(--hm-torch); outline-offset: 2px; }
.name-count {
  margin: 0;
  text-align: right;
  color: #6a5230;
  font-size: .78rem;
}
.name-count.is-over { color: #a3301c; font-weight: 700; }
.name-number-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 12px;
}
.name-number-text { display: grid; gap: 2px; }
.name-hint { margin: 0; color: #7a5a24; font-size: .75rem; }
.name-jersey {
  display: grid;
  place-items: center;
  width: 46px; height: 56px;
  border-radius: 7px;
  background:
    linear-gradient(180deg, #c8102e, #8f0a1f);
  box-shadow: inset 0 0 0 2px #f3e7d8, 0 2px 6px rgba(0,0,0,.4);
  position: relative;
}
.name-jersey:after {
  content: "";
  position: absolute;
  left: 8px; right: 8px; bottom: 7px;
  height: 9px;
  background: #f3e7d8;
  border-radius: 3px;
}
.name-jersey-num {
  font: 900 1.5rem/1 var(--hm-f-carve);
  color: #fff;
  z-index: 1;
  margin-bottom: 6px;
}
.name-number { width: 74px; text-align: center; }
.name-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 8px;
  flex-wrap: wrap;
}
.name-actions .carved-btn { padding: 11px 22px; font-size: .95rem; }

/* ============ QUIZ ============ */
.quiz-dialog { text-align: center; }
.quiz-kicker {
  margin: 0;
  font: 700 .8rem/1.2 var(--hm-f-body);
  letter-spacing: .18em;
  text-transform: uppercase;
  color: #7a5a24;
}
.quiz-question {
  margin: 4px 0 2px;
  font: 900 1.3rem/1.25 var(--hm-f-carve);
  color: #241708;
}
.quiz-loading { color: #4a3822; }
.quiz-error { color: #a3301c; font-size: .85rem; }
.quiz-answers {
  display: grid;
  gap: 10px;
  margin-top: 8px;
}
.quiz-answer {
  appearance: none;
  cursor: pointer;
  text-align: left;
  color: #241708;
  background: rgba(255,255,255,.5);
  border: 1px solid rgba(80,60,40,.35);
  border-radius: 10px;
  padding: 12px 16px;
  font: 700 .98rem var(--hm-f-body);
  transition: background .12s, transform .1s;
}
.quiz-answer:hover:not(:disabled) { background: rgba(255,255,255,.8); }
.quiz-answer:disabled { opacity: .7; cursor: default; }
.quiz-answer.is-right {
  background: #3fb36b;
  border-color: #3fb36b;
  color: #fff;
}
.quiz-answer.is-wrong {
  background: #c8102e;
  border-color: #c8102e;
  color: #fff;
}
.quiz-result {
  margin: 6px 0 0;
  font-weight: 700;
  line-height: 1.5;
}
.quiz-result.is-right { color: #1d6b3c; }
.quiz-result.is-wrong { color: #a3301c; }

/* ============ LEGAL ============ */
.legal-dialog {
  width: min(680px, 100%);
  max-height: min(85dvh, 760px);
  display: flex;
  flex-direction: column;
  color: var(--hm-chalk);
  background:
    linear-gradient(180deg, #2e241d, #18120e);
  border: 1px solid #0009;
  border-radius: 14px;
  box-shadow: 0 18px 60px -18px #000;
}
.legal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 22px 14px;
  border-bottom: 1px solid rgba(236,208,140,.25);
}
.legal-head h2 {
  margin: 0;
  font: 900 1.3rem/1.2 var(--hm-f-carve);
  color: var(--hm-gilt-hi);
}
.legal-close {
  appearance: none;
  width: 34px; height: 34px;
  color: var(--hm-chalk);
  cursor: pointer;
  background: rgba(255,255,255,.08);
  border: 0;
  border-radius: 50%;
  font-size: 1.2rem;
  line-height: 1;
}
.legal-close:hover { background: rgba(255,255,255,.16); }
.legal-body {
  overflow-y: auto;
  padding: 16px 22px 22px;
  font-size: .9rem;
  line-height: 1.55;
}
.legal-body h3 {
  margin: 18px 0 6px;
  font: 800 1rem/1.2 var(--hm-f-carve);
  color: var(--hm-gilt-hi);
}
.legal-body h3:first-child { margin-top: 4px; }
.legal-body p { margin: 6px 0; color: #efe9ddd1; }
.legal-body ul { margin: 6px 0; padding-left: 1.4em; color: #efe9ddd1; }
.legal-body li { margin: 4px 0; }
.legal-body b { color: #fff6ec; }
.legal-body code {
  background: rgba(0,0,0,.4);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: .85em;
}
.legal-updated { color: #efe9dd80 !important; font-size: .8rem; }

/* ============ CONSENT ============ */
.consent-banner {
  position: fixed;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  z-index: 1100;
  width: min(560px, calc(100vw - 28px));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  color: var(--hm-chalk);
  background: rgba(14,10,8,.94);
  border: 1px solid rgba(243,231,216,.3);
  border-radius: 14px;
  padding: 12px 16px;
  font-size: .85rem;
  line-height: 1.45;
  box-shadow: 0 18px 50px -12px #000;
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}
.consent-banner p { margin: 0; }
.consent-link {
  color: var(--hm-torch);
  background: none; border: 0; cursor: pointer;
  text-decoration: underline;
  font: inherit;
}
.consent-actions { display: flex; gap: 8px; }
.consent-no, .consent-yes {
  appearance: none;
  cursor: pointer;
  border-radius: 999px;
  padding: 7px 16px;
  font: 700 .85rem var(--hm-f-body);
}
.consent-no {
  color: var(--hm-chalk);
  background: rgba(255,255,255,.1);
  border: 1px solid rgba(255,255,255,.25);
}
.consent-yes {
  color: #fff;
  background: #c8102e;
  border: 1px solid #c8102e;
}

/* ============ DONATE ============ */
.donate { position: relative; z-index: 1; }
.home-donate {
  position: fixed;
  right: 16px;
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 50;
}
.donate-toggle {
  appearance: none;
  cursor: pointer;
  color: #f3e7d8e6;
  background: rgba(20,13,10,.9);
  border: 1px solid rgba(243,231,216,.4);
  border-radius: 999px;
  padding: 9px 15px;
  font: 600 .875rem var(--hm-f-body);
  box-shadow: 0 8px 22px -10px #000c;
}
.donate-toggle:hover { background: rgba(30,20,15,.95); }
.donate-nudge {
  appearance: none;
  cursor: pointer;
  position: absolute;
  right: 0;
  bottom: calc(100% + 10px);
  white-space: nowrap;
  color: #14212b;
  background: #fff;
  border: 0;
  border-radius: 12px 12px 4px 12px;
  padding: 9px 13px;
  font: 700 .82rem var(--hm-f-body);
  box-shadow: 0 12px 28px -12px #000c;
  animation: donate-nudge-in .3s ease-out both;
}
@keyframes donate-nudge-in { from { opacity: 0; transform: translateY(6px); } }
.donate-card {
  position: absolute;
  right: 0;
  bottom: calc(100% + 10px);
  width: min(280px, 88vw);
  text-align: center;
  display: grid;
  justify-items: center;
  gap: 6px;
  color: var(--hm-chalk);
  background: rgba(20,13,10,.96);
  border: 1px solid rgba(243,231,216,.3);
  border-radius: 14px;
  padding: 16px;
  box-shadow: 0 18px 50px -12px #000;
}
.donate-title { margin: 0; font: 800 1.05rem var(--hm-f-carve); color: var(--hm-gilt-hi); }
.donate-qr {
  width: 180px; height: 180px;
  border-radius: 10px;
  background: #fff;
  padding: 4px;
}
.donate-note { margin: 0; color: #efe9ddb3; font-size: .75rem; line-height: 1.4; }

/* ============ UPDATE NOTICE ============ */
.update-notice {
  position: fixed;
  top: max(14px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 1200;
  width: min(420px, calc(100vw - 28px));
  display: grid;
  gap: 6px;
  color: var(--hm-chalk);
  background: rgba(20,13,10,.95);
  border: 1px solid var(--hm-gilt);
  border-radius: 14px;
  padding: 13px 16px;
  font-size: .85rem;
  line-height: 1.45;
  box-shadow: 0 18px 50px -12px #000;
}
.update-notice strong { font: 800 1rem var(--hm-f-carve); color: var(--hm-gilt-hi); }
.update-notice p { margin: 0; }
.update-notice-bar {
  height: 3px;
  background: rgba(255,255,255,.15);
  border-radius: 2px;
  overflow: hidden;
}
.update-notice-bar i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--hm-red), var(--hm-gilt));
  transform-origin: left;
}
.update-notice button {
  justify-self: end;
  appearance: none;
  cursor: pointer;
  color: #fff;
  background: #c8102e;
  border: 0;
  border-radius: 8px;
  padding: 7px 14px;
  font: 700 .82rem var(--hm-f-body);
}

/* ============ FPS BADGE ============ */
.fps-badge {
  position: fixed;
  right: 8px;
  bottom: 8px;
  z-index: 1300;
  color: rgba(243,231,216,.7);
  background: rgba(0,0,0,.5);
  border-radius: 6px;
  padding: 3px 8px;
  font: 600 .72rem/1 var(--hm-f-body);
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}
.fps-badge[data-level="good"] { color: #8fe388; }
.fps-badge[data-level="ok"] { color: #f2c14e; }
.fps-badge[data-level="bad"] { color: #ff8a7a; }

/* ============ NAME TAGS (trong hang) ============ */
.name-tag-layer {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  overflow: hidden;
}
.name-tag {
  position: absolute;
  left: 0; top: 0;
  display: none;
  white-space: nowrap;
  color: #fff6ec;
  background: rgba(0,0,0,.5);
  border-radius: 6px;
  padding: 2px 8px;
  font: 600 .78rem/1.3 var(--hm-f-body);
  text-shadow: 0 1px 2px #000;
  pointer-events: none;
}

/* ============ PENALTY OVERLAY (thiếu trong cavescreen.css) ============ */
.penalty-overlay {
  z-index: 900;
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(6,3,1,.55);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}
.penalty-card {
  width: min(420px, 100%);
  text-align: center;
  display: grid;
  gap: 12px;
  color: var(--hm-chalk);
  background: var(--hm-grain, none),
    linear-gradient(180deg, var(--hm-enamel-hi), var(--hm-enamel));
  background-blend-mode: overlay, normal;
  border: 2px solid var(--hm-gilt);
  border-radius: 14px;
  padding: 20px 22px;
  box-shadow: inset 0 0 0 5px var(--hm-enamel-deep), inset 0 0 0 6px rgba(236,208,140,.5), var(--hm-drop);
}
.penalty-title {
  margin: 0;
  font: 900 1.3rem/1.2 var(--hm-f-carve);
  color: var(--hm-gilt-hi);
}
.penalty-score {
  display: flex;
  justify-content: center;
  gap: 12px;
  font: 800 1rem var(--hm-f-body);
  color: var(--hm-chalk);
}
.penalty-hint { margin: 0; font-size: .9rem; color: var(--hm-chalk-dim); }
.penalty-choices {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.penalty-choice {
  appearance: none;
  cursor: pointer;
  color: #fff4e6;
  background: linear-gradient(180deg, var(--hm-red-hi), var(--hm-red) 55%, var(--hm-red-deep));
  border: 0;
  border-radius: 10px;
  padding: 14px 8px;
  font: 800 .95rem var(--hm-f-body);
  box-shadow: inset 0 0 0 2px var(--hm-gilt), 0 6px 14px -8px #5a000fcc;
}
.penalty-choice:hover { filter: brightness(1.08); }
.penalty-wait { margin: 0; color: var(--hm-gilt-hi); font-weight: 700; }
.penalty-last { margin: 0; font-weight: 800; }
.penalty-last.is-ok { color: #8fe388; }
.penalty-last.is-danger { color: #ff8a7a; }

/* ============ RESPONSIVE ============ */
@media (max-width: 640px) {
  .home { gap: 14px; padding: 14px; }
  .home-panel { padding: 20px 18px 18px; }
  .plaque-title { font-size: clamp(2.2rem, 12vw, 3rem); }
  .name-number-row { grid-template-columns: 1fr auto; }
  .name-number-row .name-jersey { display: none; }
  .name-number { width: 100%; grid-column: 1 / -1; }
  .consent-banner { flex-direction: column; align-items: stretch; text-align: center; }
  .consent-actions { justify-content: center; }
  .home-donate { right: 12px; }
}

/* ============ ACCESSIBILITY: reduced motion ============ */
@media (prefers-reduced-motion: reduce) {
  .carved-btn, .pwa-button, .donate-toggle { transition: none; }
  .donate-nudge, .update-notice { animation: none; }
}
