:root { --bg: #0d1230; --accent: #7c9bff; --accent2: #ff7ab6; --gold: #ffd36b; --text: #eef1ff; }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden; color: var(--text);
  background: radial-gradient(1100px 650px at 50% -12%, #28337a 0%, #121845 45%, #0b0f2a 100%) fixed, var(--bg);
  font-family: system-ui, "Segoe UI", Roboto, Arial, sans-serif;
  user-select: none; -webkit-user-select: none; overscroll-behavior: none; touch-action: none;
}
button { font-family: inherit; cursor: pointer; color: inherit; }
#app {
  height: 100%; display: flex; flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* ---------- đầu trang ---------- */
header { display: flex; align-items: center; gap: 8px; padding: 8px 10px 4px; flex: none; }
.brand { flex: 1; min-width: 0; display: flex; align-items: center; gap: 7px; font-weight: 900; font-size: 19px; letter-spacing: .3px; white-space: nowrap; }
.brand .logo { width: 26px; height: 26px; flex: none; filter: drop-shadow(0 0 6px rgba(124, 155, 255, .6)); }
.brand .logo g { stroke: #c9d4ff; }
.brand .logo circle:first-of-type { fill: #c9d4ff; }
.brand span { background: linear-gradient(90deg, #a9bcff, #ff9ccb); -webkit-background-clip: text; background-clip: text; color: transparent; overflow: hidden; text-overflow: ellipsis; }
.levels {
  display: flex; gap: 2px; padding: 3px; border-radius: 12px; flex: none;
  background: rgba(255, 255, 255, .07); border: 1px solid rgba(255, 255, 255, .12);
}
.levels button {
  background: none; border: 0; color: #c3ccf5; font-weight: 800; font-size: 14px; padding: 6px 12px; border-radius: 9px;
  transition: background .2s, color .2s;
}
.levels button:hover { color: #fff; }
.levels button.on { background: linear-gradient(135deg, #8aa6ff, #5b74f0); color: #fff; box-shadow: 0 2px 10px rgba(80, 110, 255, .45); }
.hbtn {
  flex: none; background: rgba(255, 255, 255, .08); border: 1px solid rgba(255, 255, 255, .16); border-radius: 10px;
  padding: 7px 10px; font-size: 14px; line-height: 1; font-weight: 700; white-space: nowrap;
}
.hbtn:hover { background: rgba(255, 255, 255, .15); }

/* ---------- thanh trạng thái ---------- */
.status { flex: none; display: flex; justify-content: center; align-items: center; gap: 16px; padding: 4px 10px 8px; }
.pill {
  min-width: 92px; display: flex; align-items: center; justify-content: center; gap: 8px;
  background: rgba(0, 0, 0, .3); border: 1px solid rgba(255, 255, 255, .1); border-radius: 999px; padding: 6px 14px;
  font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums; box-shadow: inset 0 2px 6px rgba(0, 0, 0, .35);
}
.pill svg { width: 20px; height: 20px; flex: none; }
.pill b { min-width: 2.2ch; text-align: center; }
#pill-mines b { color: #ffb3b3; }
#pill-time b { color: #bfe6ff; }
.pill.bump { animation: bump .25s ease; }
@keyframes bump { 50% { transform: scale(1.12); } }
#face {
  width: 50px; height: 50px; border-radius: 50%; font-size: 27px; line-height: 1; padding: 0; border: 0; flex: none;
  background: radial-gradient(circle at 35% 30%, #fff8d6, #ffd36b 55%, #eea42a);
  box-shadow: 0 4px 0 #b4701a, 0 7px 16px rgba(0, 0, 0, .45); transition: transform .08s, box-shadow .08s;
}
#face:hover { filter: brightness(1.06); }
#face:active { transform: translateY(3px); box-shadow: 0 1px 0 #b4701a, 0 3px 8px rgba(0, 0, 0, .4); }

/* ---------- bàn chơi ---------- */
#stage { flex: 1; min-height: 0; position: relative; touch-action: none; }
#cv { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: pointer; }
.zoom { position: absolute; right: 10px; bottom: 10px; display: flex; flex-direction: column; gap: 6px; z-index: 2; }
.zoom button {
  width: 40px; height: 40px; border-radius: 12px; font-size: 22px; font-weight: 800; line-height: 1;
  background: rgba(20, 26, 70, .85); border: 1px solid rgba(255, 255, 255, .2); box-shadow: 0 4px 12px rgba(0, 0, 0, .4);
}
.hidden { display: none !important; }

/* ---------- chân trang ---------- */
footer { flex: none; display: flex; align-items: center; gap: 12px; padding: 8px 12px 10px; }
#btn-flag {
  flex: none; display: flex; align-items: center; gap: 7px; font-size: 15px; font-weight: 800; padding: 10px 16px; border-radius: 14px;
  background: rgba(255, 255, 255, .08); border: 1px solid rgba(255, 255, 255, .18); transition: background .15s, transform .1s;
}
#btn-flag .fl { font-size: 18px; filter: grayscale(.6); transition: filter .15s; }
#btn-flag.on { background: linear-gradient(135deg, #ff7b7b, #e0434f); border-color: transparent; box-shadow: 0 4px 16px rgba(240, 70, 80, .45); }
#btn-flag.on .fl { filter: none; }
#btn-flag:active { transform: scale(.96); }
.foot-info { flex: 1; min-width: 0; text-align: right; }
.hint { margin: 0; font-size: 13px; opacity: .65; line-height: 1.35; }
.besttime { margin: 2px 0 0; font-size: 13px; color: var(--gold); font-weight: 700; }
.besttime:empty { display: none; }

/* ---------- bảng kết quả ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 10; display: flex; align-items: center; justify-content: center; padding: 16px;
  background: rgba(6, 8, 30, .55); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
  animation: fade .25s ease;
}
@keyframes fade { from { opacity: 0; } }
.panel {
  width: 100%; max-width: 400px; max-height: 100%; overflow: auto; touch-action: pan-y; text-align: center; padding: 22px 22px 18px; border-radius: 20px;
  background: linear-gradient(165deg, rgba(40, 48, 120, .97), rgba(16, 20, 56, .97));
  border: 1px solid rgba(170, 180, 255, .25); box-shadow: 0 24px 60px rgba(0, 0, 0, .6), 0 0 40px rgba(110, 130, 255, .2);
  animation: pop .35s cubic-bezier(.2, 1.4, .4, 1);
}
@keyframes pop { from { transform: scale(.85) translateY(10px); opacity: 0; } }
.r-icon { font-size: 46px; line-height: 1; margin-bottom: 4px; }
.panel h2 { margin: 0 0 10px; font-size: 26px; }
.panel.win h2 { background: linear-gradient(90deg, #ffe08a, #ff9ccb); -webkit-background-clip: text; background-clip: text; color: transparent; }
.panel.lose h2 { color: #ff9a9a; }
.r-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 6px 0 10px; }
.r-stats div { background: rgba(255, 255, 255, .07); border-radius: 12px; padding: 8px 4px; }
.r-stats span { display: block; font-size: 12px; opacity: .7; }
.r-stats b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; margin-top: 2px; }
.r-stats b.gold { color: var(--gold); }
.badge { display: inline-block; margin: 0 0 8px; padding: 4px 12px; border-radius: 999px; font-size: 13px; font-weight: 800; color: #2a1800; background: linear-gradient(90deg, #ffe08a, #ffb347); animation: pulse 1.2s ease infinite; }
@keyframes pulse { 50% { transform: scale(1.06); } }
.r-best { font-size: 13px; opacity: .9; margin-bottom: 4px; }
.r-best table { margin: 0 auto; border-collapse: collapse; }
.r-best td { padding: 2px 10px; }
.r-best td:first-child { text-align: right; opacity: .75; }
.r-best td:last-child { text-align: left; font-weight: 800; font-variant-numeric: tabular-nums; }
.r-best tr.cur td:last-child { color: var(--gold); }
.p-btns { display: flex; gap: 10px; justify-content: center; margin-top: 12px; }
.p-btns button { font-size: 16px; font-weight: 800; padding: 11px 20px; border-radius: 13px; border: 1px solid rgba(255, 255, 255, .2); background: rgba(255, 255, 255, .1); }
.p-btns button.primary { border: 0; color: #fff; background: linear-gradient(135deg, #8aa6ff, #5b74f0); box-shadow: 0 5px 16px rgba(80, 110, 255, .45); }
.p-btns button:hover { filter: brightness(1.1); }

@media (max-width: 460px) {
  .brand span { display: none; }
  .levels button { padding: 6px 10px; }
  .status { gap: 12px; }
  .pill { min-width: 84px; font-size: 18px; padding: 5px 12px; }
  .hint { font-size: 12px; }
}
@media (max-height: 520px) {
  header { padding-top: 4px; }
  .status { padding-bottom: 4px; }
  #face { width: 40px; height: 40px; font-size: 22px; }
  .pill { font-size: 16px; padding: 3px 12px; }
  footer { padding: 4px 12px 6px; }
  #btn-flag { padding: 7px 12px; }
}
@media (max-height: 520px) and (min-width: 600px) {
  /* điện thoại xoay ngang: nút cắm cờ lên hàng trạng thái, bỏ dòng hướng dẫn để bàn chơi cao hơn */
  #app { position: relative; }
  footer { position: absolute; left: calc(10px + env(safe-area-inset-left)); top: calc(48px + env(safe-area-inset-top)); padding: 0; z-index: 3; }
  .foot-info { display: none; }
}
