/* ============================================================
   Đổ Xăm Hường — giao diện
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: var(--ink-900);
  color: var(--ink);
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

body {
  background:
    radial-gradient(120% 90% at 50% -10%, #5C1526 0%, #320B16 42%, #14060B 100%);
}

/* ánh sáng + hoa văn nền */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(60% 40% at 82% 8%, rgba(255, 214, 120, .14), transparent 70%),
    radial-gradient(50% 36% at 12% 16%, rgba(255, 160, 90, .10), transparent 70%);
}

.app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: calc(var(--safe-top) + 6px) 0 calc(var(--safe-bottom) + 6px);
  max-width: 560px;
  margin: 0 auto;
}

/* ---------- thanh trên ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: var(--s2);
  padding: 0 var(--s4) var(--s2);
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--s2);
  min-width: 0;
}
.brand__mark {
  width: 30px; height: 30px;
  display: grid; place-items: center;
  border-radius: 9px;
  background: linear-gradient(160deg, #6E2A8F, #3A0D3F);
  box-shadow: inset 0 0 0 1px rgba(255, 220, 150, .45), 0 3px 10px rgba(0, 0, 0, .4);
  color: var(--gold-200);
  flex: none;
}
.brand__name {
  font-family: var(--font-display);
  font-size: 17px;
  letter-spacing: .02em;
  white-space: nowrap;
  color: var(--gold-100);
}

.spacer { flex: 1; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 12px;
  border-radius: var(--r-pill);
  background: rgba(255, 233, 168, .10);
  box-shadow: inset 0 0 0 1px rgba(255, 220, 150, .38);
  color: var(--gold-200);
  font-weight: 700;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}
.pill--points { color: var(--gold-100); }
.pill svg { flex: none; }

.icon-btn {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  border: 0;
  border-radius: 12px;
  background: rgba(255, 233, 168, .08);
  box-shadow: inset 0 0 0 1px rgba(255, 220, 150, .22);
  color: var(--gold-200);
  position: relative;
  cursor: pointer;
}
.icon-btn:active { transform: scale(.94); }
.icon-btn__dot {
  position: absolute;
  top: 6px; right: 6px;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #FF5B49;
  box-shadow: 0 0 0 2px rgba(20, 6, 11, .9);
}

/* ---------- chiếu bài ---------- */
.table {
  position: relative;
  flex: 1;
  margin: 0 var(--s3) var(--s2);
  padding: var(--s4) var(--s3);
  border-radius: var(--r-xl);
  background:
    radial-gradient(120% 90% at 50% 0%, #175247 0%, var(--felt-800) 48%, var(--felt-900) 100%);
  box-shadow:
    inset 0 0 0 2px rgba(255, 220, 150, .30),
    inset 0 0 0 6px rgba(0, 0, 0, .18),
    inset 0 18px 40px rgba(0, 0, 0, .35),
    0 10px 30px rgba(0, 0, 0, .45);
  display: flex;
  flex-direction: column;
  gap: var(--s3);
  overflow: hidden;
}
.table::after {
  /* vân chiếu */
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image:
    repeating-linear-gradient(45deg, rgba(255,255,255,.018) 0 2px, transparent 2px 5px),
    radial-gradient(80% 60% at 50% 50%, transparent 55%, rgba(0,0,0,.35) 100%);
}

.corner {
  position: absolute;
  width: 54px; height: 54px;
  color: rgba(255, 220, 150, .38);
  pointer-events: none;
}
.corner svg { width: 100%; height: 100%; display: block; }
.corner--tl { top: 8px; left: 8px; }
.corner--tr { top: 8px; right: 8px; transform: scaleX(-1); }
.corner--bl { bottom: 8px; left: 8px; transform: scaleY(-1); }
.corner--br { bottom: 8px; right: 8px; transform: scale(-1, -1); }

/* lưới 6 cửa */
.cua-grid {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--s2);
}

.cua {
  position: relative;
  border: 0;
  padding: 10px 4px 8px;
  border-radius: var(--r-md);
  background:
    linear-gradient(180deg, rgba(255, 246, 220, .10), rgba(255, 246, 220, .04));
  box-shadow:
    inset 0 0 0 1px rgba(255, 230, 170, .28),
    0 3px 0 rgba(0, 0, 0, .28);
  color: var(--ink);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  cursor: pointer;
  transition: transform var(--t-fast), box-shadow var(--t-fast);
}
.cua:active { transform: translateY(1px) scale(.985); }

.cua__emblem {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 32%, rgba(255,255,255,.16), rgba(0,0,0,.22));
  box-shadow: inset 0 0 0 1.5px currentColor;
  color: var(--c1);
}
.cua__emblem svg { width: 22px; height: 22px; }

.cua__name {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .01em;
  color: var(--ink-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.cua__bet {
  min-height: 18px;
  font-size: 11px;
  font-weight: 800;
  color: var(--gold-200);
  font-variant-numeric: tabular-nums;
}

.cua[data-active="1"] {
  background: linear-gradient(180deg, rgba(255, 220, 140, .22), rgba(255, 220, 140, .06));
  box-shadow:
    inset 0 0 0 2px var(--gold-300),
    0 0 18px rgba(255, 214, 120, .22),
    0 3px 0 rgba(0, 0, 0, .28);
}
.cua[data-hit="1"] {
  animation: hit-pop 520ms var(--t-slow);
  box-shadow:
    inset 0 0 0 2px var(--win),
    0 0 24px rgba(86, 214, 138, .45),
    0 3px 0 rgba(0, 0, 0, .28);
}
.cua[data-win="1"] {
  box-shadow:
    inset 0 0 0 2px var(--win),
    0 0 26px rgba(86, 214, 138, .5);
}

@keyframes hit-pop {
  0% { transform: scale(1); }
  35% { transform: scale(1.06); }
  100% { transform: scale(1); }
}

/* máng xúc xắc */
.tray {
  position: relative;
  z-index: 1;
  padding: 10px 8px;
  border-radius: var(--r-lg);
  background: rgba(0, 0, 0, .26);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .06), inset 0 -2px 8px rgba(0, 0, 0, .4);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  min-height: 92px;
}

.die {
  width: 62px; height: 62px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: linear-gradient(155deg, #FFFDF6 0%, #F3E3C4 58%, #DCC095 100%);
  box-shadow:
    inset 0 -3px 0 rgba(140, 100, 40, .35),
    inset 0 2px 0 rgba(255, 255, 255, .8),
    0 6px 14px rgba(0, 0, 0, .45);
  color: #4A2C0A;
  transition: transform var(--t-fast);
}
.die svg { width: 34px; height: 34px; }
.die--empty { color: rgba(74, 44, 10, .30); }
.die--rolling { animation: die-shake 260ms infinite; }
.die--land { animation: die-land 420ms var(--t-slow); }

@keyframes die-shake {
  0%, 100% { transform: translateY(0) rotate(-6deg); }
  50% { transform: translateY(-8px) rotate(7deg); }
}
@keyframes die-land {
  0% { transform: scale(1.18) rotate(-8deg); }
  60% { transform: scale(.96) rotate(2deg); }
  100% { transform: scale(1) rotate(0); }
}

/* kết quả nổi trên chiếu */
.result {
  position: absolute;
  left: 50%;
  top: 42%;
  transform: translate(-50%, -50%) scale(.9);
  z-index: 3;
  padding: 10px 20px;
  border-radius: var(--r-pill);
  font-size: 22px;
  font-weight: 800;
  letter-spacing: .02em;
  color: var(--gold-100);
  background: rgba(20, 6, 11, .82);
  box-shadow: 0 0 0 1.5px rgba(255, 220, 150, .45), 0 8px 26px rgba(0, 0, 0, .5);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--t-mid), transform var(--t-mid);
  font-variant-numeric: tabular-nums;
}
.result.is-show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.result.is-win { color: #CFF7DD; box-shadow: 0 0 0 1.5px rgba(86, 214, 138, .7), 0 0 30px rgba(86, 214, 138, .35); }
.result.is-lose { color: #FFD4CF; box-shadow: 0 0 0 1.5px rgba(226, 86, 76, .7), 0 0 30px rgba(226, 86, 76, .3); }

/* ---------- khu điều khiển ---------- */
.controls {
  padding: 0 var(--s3);
  display: flex;
  flex-direction: column;
  gap: var(--s2);
}

.chips {
  display: flex;
  gap: var(--s2);
  justify-content: center;
}
.chip {
  flex: 1;
  height: 42px;
  border: 0;
  border-radius: var(--r-md);
  background: linear-gradient(180deg, rgba(255, 233, 168, .16), rgba(255, 233, 168, .06));
  box-shadow: inset 0 0 0 1px rgba(255, 220, 150, .35), 0 2px 0 rgba(0, 0, 0, .3);
  color: var(--gold-200);
  font-weight: 800;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}
.chip[data-on="1"] {
  background: linear-gradient(180deg, #F6D98A, #C9962F);
  color: #3A2205;
  box-shadow: inset 0 0 0 1px #FFE9A8, 0 0 14px rgba(255, 214, 120, .35);
}
.chip:active { transform: translateY(1px); }

.actions {
  display: flex;
  gap: var(--s2);
}

.btn {
  border: 0;
  border-radius: var(--r-md);
  font-weight: 800;
  font-size: 15px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform var(--t-fast), filter var(--t-fast);
}
.btn:active { transform: translateY(1px) scale(.99); filter: brightness(.95); }
.btn:disabled { opacity: .45; cursor: default; }

.btn--ghost {
  width: 64px;
  height: 54px;
  background: rgba(255, 233, 168, .08);
  box-shadow: inset 0 0 0 1px rgba(255, 220, 150, .3);
  color: var(--ink-2);
  font-size: 14px;
}

.btn--roll {
  flex: 1;
  height: 54px;
  font-size: 17px;
  letter-spacing: .04em;
  color: #3A2205;
  background: linear-gradient(180deg, #FFE9A8 0%, #F2C96A 46%, #C9962F 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .7),
    0 4px 0 #7A5313,
    0 8px 22px rgba(0, 0, 0, .45);
  text-shadow: 0 1px 0 rgba(255, 255, 255, .35);
}
.btn--roll:active { box-shadow: inset 0 1px 0 rgba(255,255,255,.6), 0 2px 0 #7A5313, 0 4px 12px rgba(0,0,0,.4); }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 96px);
  transform: translateX(-50%) translateY(10px);
  z-index: 40;
  padding: 9px 16px;
  border-radius: var(--r-pill);
  background: rgba(20, 6, 11, .92);
  box-shadow: inset 0 0 0 1px rgba(255, 220, 150, .32);
  color: var(--gold-100);
  font-size: 13.5px;
  font-weight: 600;
  opacity: 0;
  transition: opacity var(--t-mid), transform var(--t-mid);
  pointer-events: none;
  max-width: 82vw;
  text-align: center;
}
.toast.is-show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(8, 2, 5, .62);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  padding: var(--s3);
  padding-bottom: calc(var(--safe-bottom) + var(--s3));
  animation: fade-in var(--t-mid);
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.sheet {
  width: 100%;
  max-width: 520px;
  max-height: 86vh;
  overflow: auto;
  border-radius: var(--r-xl);
  background: linear-gradient(180deg, #2A0F19, #1A0810);
  box-shadow:
    inset 0 0 0 1px rgba(255, 220, 150, .28),
    0 24px 60px rgba(0, 0, 0, .6);
  padding: var(--s4) var(--s4) var(--s5);
  animation: sheet-up var(--t-slow);
}
@keyframes sheet-up {
  from { transform: translateY(24px); opacity: .6; }
  to { transform: translateY(0); opacity: 1; }
}

.sheet__head {
  display: flex;
  align-items: center;
  gap: var(--s2);
  margin-bottom: var(--s3);
}
.sheet__title {
  font-family: var(--font-display);
  font-size: 19px;
  color: var(--gold-100);
  margin: 0;
  flex: 1;
}
.sheet__close {
  width: 32px; height: 32px;
  border: 0;
  border-radius: 10px;
  background: rgba(255, 233, 168, .08);
  color: var(--ink-2);
  font-size: 18px;
  cursor: pointer;
}

.sheet p, .sheet li {
  color: var(--ink-2);
  font-size: 14px;
  line-height: 1.65;
}
.sheet h4 {
  color: var(--gold-200);
  font-size: 14px;
  margin: var(--s4) 0 var(--s2);
}
.sheet .rule-list { margin: 0; padding-left: 18px; }

/* ---------- bảng tin ---------- */
.news-item { padding: var(--s3) 0; border-bottom: 1px solid rgba(255, 233, 168, .12); }
.news-item:last-child { border-bottom: 0; }
.news-item__top {
  display: flex;
  align-items: center;
  gap: var(--s2);
  margin-bottom: 6px;
}
.news-item__tag {
  font-size: 11px;
  font-weight: 700;
  color: #2A0F19;
  background: linear-gradient(180deg, #FFE9A8, #D8A93F);
  border-radius: var(--r-pill);
  padding: 2px 8px;
}
.news-item__date { font-size: 11.5px; color: var(--muted); }
.news-item__title {
  margin: 0 0 4px;
  font-size: 15.5px;
  font-weight: 800;
  color: var(--gold-100);
}
.news-item__body {
  margin: 0;
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--ink-2);
  white-space: pre-wrap;
}
.news-item__go {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  font-size: 13px;
  font-weight: 700;
  color: var(--gold-200);
}
.news-empty { color: var(--muted); font-size: 13.5px; text-align: center; padding: var(--s5) 0; }

/* ---------- cửa sổ nổi bảng tin ---------- */
.notice {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--safe-bottom) + 12px);
  width: calc(100% - 24px);
  max-width: 520px;
  z-index: 45;
  border-radius: var(--r-lg);
  background: linear-gradient(180deg, #2E111B, #1B0810);
  box-shadow:
    inset 0 0 0 1px rgba(255, 220, 150, .35),
    0 18px 40px rgba(0, 0, 0, .55);
  overflow: hidden;
  animation: notice-in 160ms var(--t-mid);
}
@keyframes notice-in { from { opacity: 0; } to { opacity: 1; } }

.notice__head {
  display: flex;
  align-items: center;
  gap: var(--s2);
  padding: 10px var(--s3);
  border-bottom: 1px solid rgba(255, 233, 168, .14);
}
.notice__title {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--gold-300);
  flex: 1;
}
.notice__x {
  width: 26px; height: 26px;
  border: 0;
  border-radius: 8px;
  background: rgba(255, 233, 168, .08);
  color: var(--ink-2);
  cursor: pointer;
}
.notice__body {
  max-height: 38vh;
  overflow: auto;
  padding: var(--s2) var(--s3) var(--s3);
}
.notice__body .news-item__body { font-size: 13px; }

/* ---------- màn chào ---------- */
.welcome {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  background: radial-gradient(120% 90% at 50% 20%, #5C1526, #14060B 75%);
  text-align: center;
  padding: var(--s6);
}
.welcome__lantern {
  position: absolute;
  top: 6%;
  width: 46px;
  color: #E2564C;
  opacity: .8;
}
.welcome__lantern--l { left: 8%; }
.welcome__lantern--r { right: 8%; transform: scaleX(-1); }

.welcome__logo {
  width: 96px; height: 96px;
  margin: 0 auto var(--s4);
  border-radius: 26px;
  display: grid;
  place-items: center;
  background: linear-gradient(160deg, #7B3AA8, #3A0D3F);
  box-shadow: inset 0 0 0 2px rgba(255, 220, 150, .5), 0 16px 40px rgba(0, 0, 0, .5);
  color: var(--gold-200);
}
.welcome__title {
  font-family: var(--font-display);
  font-size: 34px;
  letter-spacing: .02em;
  margin: 0 0 6px;
  color: var(--gold-100);
}
.welcome__sub {
  margin: 0 0 var(--s6);
  color: var(--ink-2);
  font-size: 14px;
  letter-spacing: .16em;
  text-transform: uppercase;
}
.welcome__btn {
  width: 100%;
  max-width: 300px;
  height: 56px;
  font-size: 17px;
}

/* ---------- hàng lịch sử ---------- */
.history {
  display: flex;
  gap: 6px;
  justify-content: center;
  padding: 0 var(--s3) 2px;
  overflow: hidden;
}
.history__item {
  display: flex;
  gap: 3px;
  padding: 4px 6px;
  border-radius: 10px;
  background: rgba(0, 0, 0, .26);
  box-shadow: inset 0 0 0 1px rgba(255, 233, 168, .12);
}
.history__item svg { width: 14px; height: 14px; }
.history__item[data-win="1"] { box-shadow: inset 0 0 0 1px rgba(86, 214, 138, .5); }

/* [hidden] phải thắng display:flex của .modal/.toast */
.modal[hidden], .toast[hidden], #notice[hidden] { display: none !important; }

/* ---------- tiện ích ---------- */
.hidden { display: none !important; }
.center { text-align: center; }
.mt3 { margin-top: var(--s3); }
.mt4 { margin-top: var(--s4); }

.settings-row {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: var(--s3) 0;
  border-bottom: 1px solid rgba(255, 233, 168, .1);
}
.settings-row__label { flex: 1; font-size: 14.5px; color: var(--ink); }
.settings-row__hint { display: block; font-size: 11.5px; color: var(--muted); margin-top: 2px; }

.switch {
  width: 46px; height: 27px;
  border-radius: 999px;
  border: 0;
  background: rgba(255, 255, 255, .14);
  position: relative;
  cursor: pointer;
  transition: background var(--t-mid);
}
.switch::after {
  content: "";
  position: absolute;
  top: 3px; left: 3px;
  width: 21px; height: 21px;
  border-radius: 50%;
  background: #F7EDD8;
  transition: transform var(--t-mid);
}
.switch[data-on="1"] { background: linear-gradient(90deg, #C9962F, #F2C96A); }
.switch[data-on="1"]::after { transform: translateX(19px); }
