* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: #021a2e; color: #eef7ff;
  font-family: system-ui, "Segoe UI", Roboto, Arial, sans-serif;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; overscroll-behavior: none;
}
button { font: inherit; }
.hidden { display: none !important; }

#game { position: fixed; inset: 0; overflow: hidden; }
#cv { position: absolute; left: 0; top: 0; display: block; touch-action: none; cursor: crosshair; }
#safe {
  position: absolute; visibility: hidden; pointer-events: none;
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
}
.vign, #frost, #redv { position: absolute; inset: 0; pointer-events: none; }
.vign { background: radial-gradient(ellipse at 50% 42%, transparent 58%, rgba(0, 8, 22, .55) 100%); }
#frost {
  background: radial-gradient(ellipse at 50% 50%, transparent 45%, rgba(170, 236, 255, .55) 100%);
  box-shadow: inset 0 0 60px rgba(220, 250, 255, .6); opacity: 0; transition: opacity .4s;
}
#frost.on { opacity: 1; }
#redv { background: radial-gradient(ellipse at 50% 50%, transparent 50%, rgba(255, 30, 40, .55) 100%); opacity: 0; }
#redv.on { animation: redp .45s ease-in-out infinite alternate; }
@keyframes redp { from { opacity: .15; } to { opacity: 1; } }

/* ---------- HUD ---------- */
#hud {
  position: absolute; left: 0; right: 0; top: 0; display: flex; justify-content: space-between; align-items: flex-start; gap: 8px;
  padding: calc(env(safe-area-inset-top, 0px) + 8px) calc(env(safe-area-inset-right, 0px) + 10px) 0 calc(env(safe-area-inset-left, 0px) + 10px);
  pointer-events: none; z-index: 5;
}
.hud-l { display: flex; flex-direction: column; align-items: flex-start; }
.hud-r { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; pointer-events: auto; }
.coinbox {
  display: flex; align-items: center; gap: 8px; padding: 4px 16px 4px 5px; border-radius: 999px;
  background: linear-gradient(180deg, rgba(12, 46, 80, .9), rgba(4, 20, 40, .9));
  border: 1px solid rgba(255, 214, 90, .6); box-shadow: 0 4px 14px rgba(0, 0, 0, .35), inset 0 1px 0 rgba(255, 255, 255, .15);
  font-size: 21px; font-weight: 800; color: #ffe08a; min-width: 128px; font-variant-numeric: tabular-nums;
  text-shadow: 0 1px 0 #7a4b00, 0 0 8px rgba(255, 200, 60, .35);
}
.coinbox b { display: inline-block; }
.coinbox.bump b { animation: bump .22s ease-out; }
@keyframes bump { 45% { transform: scale(1.16); color: #fff6c8; } }
.coin-ic {
  width: 28px; height: 28px; border-radius: 50%; flex: none; position: relative; display: inline-block;
  background: radial-gradient(circle at 35% 30%, #fff8cf, #ffd23f 38%, #d99400 72%, #8a5a00);
  box-shadow: inset 0 0 0 2px #b07800, 0 0 10px rgba(255, 200, 60, .55);
}
.coin-ic::after { content: ''; position: absolute; inset: 6px; border-radius: 50%; border: 2px solid rgba(138, 90, 0, .55); }
.lvbox {
  margin-top: 6px; display: flex; align-items: center; gap: 7px; font-size: 12.5px; white-space: nowrap; font-weight: 800; color: #bfefff;
  padding: 3px 9px; border-radius: 999px; background: rgba(2, 18, 36, .6); border: 1px solid rgba(120, 210, 255, .25);
}
.xpbar { width: 86px; height: 7px; border-radius: 9px; background: rgba(0, 0, 0, .5); overflow: hidden; border: 1px solid rgba(255, 255, 255, .15); }
.xpbar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #41e0ff, #7dffb0); transition: width .35s; }
.note { margin-top: 5px; font-size: 11px; color: rgba(220, 240, 255, .7); text-shadow: 0 1px 2px #000; padding-left: 4px; }
.gift {
  pointer-events: auto; margin-top: 7px; padding: 6px 12px; white-space: nowrap; border-radius: 12px; cursor: pointer; font-weight: 800; font-size: 13.5px;
  color: #3a1d00; border: none; background: linear-gradient(180deg, #ffe27a, #ffad33); box-shadow: 0 4px 14px rgba(255, 170, 40, .45);
  animation: wiggle 1.6s ease-in-out infinite;
}
@keyframes wiggle { 0%, 70%, 100% { transform: rotate(0); } 76% { transform: rotate(-5deg); } 84% { transform: rotate(5deg); } 92% { transform: rotate(-3deg); } }
.ib {
  height: 38px; min-width: 38px; padding: 0 10px; border-radius: 12px; cursor: pointer; white-space: nowrap;
  border: 1px solid rgba(160, 220, 255, .28); background: rgba(4, 26, 52, .78); color: #fff; font-size: 15px; font-weight: 700;
  box-shadow: 0 3px 10px rgba(0, 0, 0, .3);
}
.ib:hover { background: rgba(14, 50, 90, .9); }
.ib:active { transform: translateY(1px); }
.ib.end { background: linear-gradient(180deg, #ff9a4a, #e0532a); border-color: #ffbe8a; text-shadow: 0 1px 0 rgba(0, 0, 0, .3); }

.betb {
  position: absolute; width: 46px; height: 46px; margin: -23px 0 0 -23px; border-radius: 50%; z-index: 4; cursor: pointer;
  font-size: 28px; line-height: 1; font-weight: 900; color: #fff; padding: 0 0 3px;
  border: 2px solid rgba(255, 255, 255, .55); background: radial-gradient(circle at 40% 30%, #4fb8ff, #1260b8 70%, #0a3c78);
  box-shadow: 0 4px 12px rgba(0, 0, 0, .45), inset 0 2px 0 rgba(255, 255, 255, .3);
}
.betb:active { transform: scale(.92); }

/* ---------- thông báo ---------- */
#combo {
  position: absolute; left: 50%; top: calc(env(safe-area-inset-top, 0px) + 92px); transform: translateX(-50%);
  font-size: 30px; font-weight: 900; font-style: italic; color: #fff; pointer-events: none; z-index: 4; white-space: nowrap;
  text-shadow: 0 0 10px #ff7a2e, 0 2px 0 #b2330b, 0 3px 6px rgba(0, 0, 0, .6); opacity: 0;
}
#combo.show { animation: combo .9s ease-out forwards; }
@keyframes combo { 0% { opacity: 0; transform: translateX(-50%) scale(.4); } 18% { opacity: 1; transform: translateX(-50%) scale(1.2); } 32% { transform: translateX(-50%) scale(1); } 75% { opacity: 1; } 100% { opacity: 0; transform: translateX(-50%) translateY(-14px); } }

#warn { position: absolute; left: 0; right: 0; top: 34%; z-index: 6; pointer-events: none; }
#warn .band {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 12px 10px;
  background: repeating-linear-gradient(-45deg, rgba(200, 10, 20, .88) 0 22px, rgba(150, 0, 10, .88) 22px 44px);
  border-top: 3px solid #ffd23f; border-bottom: 3px solid #ffd23f; box-shadow: 0 0 40px rgba(255, 40, 40, .6);
  animation: warnIn .35s ease-out;
}
#warn b { font-size: clamp(26px, 7vw, 46px); font-weight: 900; letter-spacing: 2px; color: #fff; text-shadow: 0 0 12px #ff2020, 0 3px 0 #600; animation: blink .4s steps(2) infinite; }
#warn span { font-size: clamp(14px, 3.6vw, 20px); font-weight: 800; color: #ffe27a; }
@keyframes warnIn { from { transform: scaleY(0); } to { transform: scaleY(1); } }
@keyframes blink { 50% { opacity: .55; } }

#bigwin { position: absolute; left: 50%; top: 40%; transform: translate(-50%, -50%); text-align: center; z-index: 6; pointer-events: none; white-space: nowrap; }
#bigwin.show { animation: bw 2.4s ease-out forwards; }
#bw-title {
  font-size: clamp(28px, min(8vw, 11vh), 60px);
  font-weight: 900; font-style: italic;
  background: linear-gradient(180deg, #fffbe0, #ffd23f 45%, #ff9500); -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 3px 0 #8a3c00) drop-shadow(0 0 16px rgba(255, 190, 40, .8));
}
#bw-amt { font-size: clamp(22px, min(6vw, 8vh), 40px); font-weight: 900; color: #fff; text-shadow: 0 0 12px #ffb300, 0 2px 0 #7a4b00; }
@keyframes bw { 0% { opacity: 0; transform: translate(-50%, -50%) scale(.3); } 12% { opacity: 1; transform: translate(-50%, -50%) scale(1.15); } 22% { transform: translate(-50%, -50%) scale(1); } 80% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -62%) scale(1.05); } }

#toasts { position: absolute; left: 50%; bottom: calc(env(safe-area-inset-bottom, 0px) + 120px); transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 6px; z-index: 7; pointer-events: none; width: max-content; max-width: 92vw; }
.toast {
  padding: 8px 16px; border-radius: 999px; font-weight: 800; font-size: 14.5px; text-align: center;
  background: rgba(4, 26, 52, .92); border: 1px solid rgba(255, 214, 90, .6); color: #ffe9a8; box-shadow: 0 6px 18px rgba(0, 0, 0, .4);
  animation: toast 2.6s ease forwards;
}
@keyframes toast { 0% { opacity: 0; transform: translateY(12px) scale(.9); } 10% { opacity: 1; transform: none; } 82% { opacity: 1; } 100% { opacity: 0; transform: translateY(-10px); } }

#broke {
  position: absolute; left: 50%; top: 46%; transform: translate(-50%, -50%); z-index: 7; text-align: center; width: min(330px, 88vw);
  padding: 16px 18px; border-radius: 18px; background: linear-gradient(180deg, rgba(14, 58, 96, .96), rgba(6, 26, 52, .97));
  border: 1px solid rgba(255, 214, 90, .5); box-shadow: 0 16px 40px rgba(0, 0, 0, .5); animation: pop .25s;
}
#broke > b { font-size: 22px; color: #ffe08a; }
#broke p { margin: 8px 0 10px; font-size: 14.5px; line-height: 1.45; }
#broke .bar { height: 9px; border-radius: 9px; background: rgba(0, 0, 0, .45); overflow: hidden; }
#broke .bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #ffd23f, #ff9a3d); }
#broke .primary { margin-top: 12px; }

/* ---------- overlay ---------- */
.overlay {
  position: absolute; inset: 0; z-index: 10; display: flex; align-items: center; justify-content: center; overflow: auto;
  padding: calc(env(safe-area-inset-top, 0px) + 14px) 14px calc(env(safe-area-inset-bottom, 0px) + 14px);
  background: rgba(0, 12, 28, .5);
}
.panel {
  width: min(430px, 100%); margin: auto; text-align: center; padding: 18px 18px 14px; border-radius: 22px;
  background: linear-gradient(180deg, rgba(16, 64, 104, .96), rgba(6, 26, 52, .97));
  border: 1px solid rgba(120, 210, 255, .35); box-shadow: 0 20px 60px rgba(0, 0, 0, .55), inset 0 1px 0 rgba(255, 255, 255, .12);
  animation: pop .28s ease-out;
}
.panel.wide { width: min(620px, 100%); }
@keyframes pop { from { opacity: 0; transform: scale(.9); } to { opacity: 1; transform: none; } }
#logo-cv { width: 240px; height: 82px; display: block; margin: -4px auto -6px; }
h1 {
  margin: 0; font-size: 44px; font-weight: 900; letter-spacing: 1px; line-height: 1.1;
  background: linear-gradient(180deg, #fffbe0, #ffd23f 50%, #ff9a1f); -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 3px 0 #7a3c00) drop-shadow(0 0 14px rgba(255, 190, 40, .45));
}
h2 { margin: 2px 0 8px; font-size: 24px; color: #ffe08a; }
.sub { margin: 6px 0 10px; font-size: 14px; color: #bfe6ff; }
.how { list-style: none; margin: 0 0 12px; padding: 10px 12px; border-radius: 14px; background: rgba(0, 0, 0, .22); text-align: left; font-size: 13.5px; line-height: 1.45; }
.how li + li { margin-top: 5px; }
.wallet { font-size: 14px; margin-bottom: 10px; color: #d8f1ff; }
.wallet b { color: #ffe08a; }
.primary {
  display: inline-block; min-width: 190px; padding: 13px 26px; border-radius: 16px; border: none; cursor: pointer;
  font-size: 19px; font-weight: 900; color: #3a1d00; letter-spacing: .3px;
  background: linear-gradient(180deg, #fff09a, #ffc533 45%, #ff9a1f); box-shadow: 0 5px 0 #b05e00, 0 10px 24px rgba(255, 160, 30, .35);
}
.primary:active { transform: translateY(3px); box-shadow: 0 2px 0 #b05e00; }
.primary.small { min-width: 0; padding: 9px 16px; font-size: 15px; box-shadow: 0 3px 0 #b05e00; }
.sec {
  padding: 9px 16px; border-radius: 12px; cursor: pointer; font-size: 14.5px; font-weight: 700; color: #fff;
  background: rgba(255, 255, 255, .1); border: 1px solid rgba(255, 255, 255, .25);
}
.sec:hover { background: rgba(255, 255, 255, .18); }
.row { display: flex; gap: 10px; justify-content: center; align-items: center; flex-wrap: wrap; margin-top: 12px; }
.fine { margin: 12px 0 0; font-size: 11.5px; color: rgba(200, 230, 255, .65); }

.big-coins { display: flex; align-items: center; justify-content: center; gap: 10px; font-size: 40px; font-weight: 900; color: #ffe08a; text-shadow: 0 2px 0 #7a4b00, 0 0 14px rgba(255, 200, 60, .45); }
.big-coins .coin-ic { width: 38px; height: 38px; }
.big-coins .coin-ic::after { inset: 8px; }
.r-peak { font-size: 14px; color: #bfe6ff; margin: 2px 0 10px; }
.r-peak b { color: #ffe08a; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; text-align: left; }
.stats div { padding: 7px 10px; border-radius: 11px; background: rgba(0, 0, 0, .24); font-size: 12.5px; color: #a9d4f0; }
.stats div b { display: block; font-size: 15.5px; color: #fff; margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

#skin-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 14px; }
.skin {
  position: relative; padding: 8px 4px 7px; border-radius: 13px; cursor: pointer; color: #fff; font-size: 12px; font-weight: 700;
  background: rgba(0, 0, 0, .25); border: 2px solid transparent;
}
.skin canvas { width: 100%; max-width: 70px; height: auto; display: block; margin: 0 auto 4px; }
.skin.on { border-color: #ffd23f; background: rgba(255, 210, 60, .14); }
.skin.lock { opacity: .55; cursor: default; }
.skin .lk { display: block; font-size: 11px; color: #ffb3a0; font-weight: 600; }

#guide-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(128px, 1fr)); gap: 7px; margin-bottom: 14px; max-height: 58vh; overflow: auto; }
.gf { padding: 6px 6px 7px; border-radius: 12px; background: rgba(0, 0, 0, .24); font-size: 12px; line-height: 1.3; }
.gf canvas { width: 100%; height: 56px; display: block; }
.gf b { display: block; color: #fff; font-size: 12.5px; }
.gf .m { color: #ffe08a; font-weight: 900; font-size: 14px; }
.gf.sp { box-shadow: inset 0 0 0 1px rgba(120, 220, 255, .5); }
.gf.rare { box-shadow: inset 0 0 0 1px rgba(255, 210, 60, .6); }

@media (max-width: 600px) {
  .ib { padding: 0 8px; height: 36px; min-width: 36px; font-size: 14px; }
  .ib.wide span { display: none; }
  .ib.end { font-size: 13px; }
  .coinbox { font-size: 18px; min-width: 0; padding-right: 13px; }
  .coin-ic { width: 24px; height: 24px; }
  .coin-ic::after { inset: 5px; }
  .xpbar { width: 64px; }
  .gift { font-size: 12.5px; padding: 5px 10px; }
  h1 { font-size: 38px; }
  #combo { font-size: 24px; top: calc(env(safe-area-inset-top, 0px) + 150px); }
}
@media (max-height: 520px) {
  .how { display: none; }
  #logo-cv { width: 180px; height: 62px; }
  h1 { font-size: 32px; }
  #guide-grid { max-height: 52vh; }
}
