/* ── User selection ── */
* {user-select: none;}

/* ═══════════════════════════════════════════════════
   TOKENS
═══════════════════════════════════════════════════ */
:root {
  --gold:    #f5c842;
  --gold-lo: rgba(245,200,66,.12);
  --gold-md: rgba(245,200,66,.25);
  --red:     #ef4444;
  --red-lo:  rgba(239,68,68,.12);
  --green:   #22c55e;
  --blue:    #2979ff;

  --tx:  #fff9f0;
  --txm: rgba(255,249,240,.55);
  --txf: rgba(255,249,240,.22);
  --sur: rgba(255,255,255,.045);
  --bd:  rgba(245,200,66,.14);

    --fh: 'Impact', 'Bebas Neue', system-ui, sans-serif;
    --fb: system-ui, -apple-system, 'Segoe UI', 'DM Sans', sans-serif;
    --fm: 'JetBrains Mono', 'Courier New', ui-monospace, monospace;

  /* Fluid sizing — clamp(min, preferred, max) */
  --topbar-h: clamp(44px, 6.5vw, 56px);
  --circle-r: clamp(110px, 22vw, 180px);
  --die-s:    clamp(28px, 5.5vw, 44px);
  --chip-s:   clamp(44px, 9.5vmin, 60px);
  --center-w: clamp(120px, 16vw, 180px);
  --panel-fs: clamp(28px, 5vw, 58px);

  /* Safe area insets for notched devices */
  --sai-top:    env(safe-area-inset-top, 0px);
  --sai-bottom: env(safe-area-inset-bottom, 0px);
  --sai-left:   env(safe-area-inset-left, 0px);
  --sai-right:  env(safe-area-inset-right, 0px);
}

/* ═══════════════════════════════════════════════════
   RESET + BASE
═══════════════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0 }

html {
  /* dvh = dynamic viewport height — handles mobile browser chrome */
  height: 100dvh;
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

body {
  font-family: var(--fb);
  background: #0d0305;
  color: var(--tx);
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
  /* Allow safe area */
  padding-top: var(--sai-top);
  padding-left: var(--sai-left);
  padding-right: var(--sai-right);
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

body::before {
  content: '';
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background:
    radial-gradient(ellipse 80% 60% at 50% -10%, rgba(200,16,46,.32) 0%, transparent 60%),
    radial-gradient(ellipse 60% 40% at 10% 90%, rgba(200,16,46,.12) 0%, transparent 50%),
    radial-gradient(ellipse 60% 40% at 90% 90%, rgba(26,58,140,.18) 0%, transparent 50%),
    repeating-linear-gradient(45deg, rgba(255,255,255,.01) 0, rgba(255,255,255,.01) 1px, transparent 1px, transparent 8px),
    repeating-linear-gradient(-45deg, rgba(255,255,255,.01) 0, rgba(255,255,255,.01) 1px, transparent 1px, transparent 8px);
}

/* ═══════════════════════════════════════════════════
   SCROLLBAR
═══════════════════════════════════════════════════ */
::-webkit-scrollbar { width: 4px; height: 4px }
::-webkit-scrollbar-track { background: transparent }
::-webkit-scrollbar-thumb { background: rgba(245,200,66,.2); border-radius: 99px }
::-webkit-scrollbar-thumb:hover { background: rgba(245,200,66,.4) }

/* ═══════════════════════════════════════════════════
   TOPBAR
═══════════════════════════════════════════════════ */
.topbar {
  position: relative; z-index: 50;
  display: flex; align-items: center; gap: 6px;
  height: var(--topbar-h);
  padding: 0 clamp(8px, 2.5vw, 20px);
  background: rgba(5,0,3,.88);
  border-bottom: 1px solid rgba(245,200,66,.18);
  flex-shrink: 0;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  /* Ensure logo + right don't push pts badge off center */
  overflow: hidden;
}

.logo {
  display: flex; align-items: center; gap: 5px;
  font-family: var(--fh);
  font-size: clamp(14px, 3.5vw, 20px);
  letter-spacing: 1px;
  flex-shrink: 0;
  min-width: 0;
}
.logo .txt {
  color: var(--gold); text-shadow: 0 0 14px rgba(245,200,66,.5);
  /* Hide text label on very small screens, keep icon */
  overflow: hidden;
  white-space: nowrap;
  max-width: clamp(0px, 18vw, 80px);
}

.top-pts {
  position: absolute; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 5px;
  background: linear-gradient(135deg, rgba(245,200,66,.14), rgba(245,200,66,.05));
  border: 1.5px solid var(--gold-md);
  border-radius: 99px;
  padding: clamp(4px,1vw,6px) clamp(10px,2.5vw,18px);
  pointer-events: none;
  white-space: nowrap;
  /* Prevent overflow on small/medium phones */
  max-width: min(200px, 38vw);
  overflow: hidden;
}
.top-pts .amt {
  font-family: var(--fh);
  font-size: clamp(15px, 4vw, 22px);
  color: var(--gold);
  text-shadow: 0 0 16px rgba(245,200,66,.45);
  min-width: 0;
  text-align: center;
  letter-spacing: .5px;
  /* Truncate if number too long */
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 140px;
}
.top-pts.win  { border-color: var(--green); animation: ptsBounce .45s ease }
.top-pts.lose { border-color: var(--red);   animation: ptsBounce .45s ease }
@keyframes ptsBounce {
  0%,100% { transform: translateX(-50%) scale(1) }
  50%      { transform: translateX(-50%) scale(1.07) }
}

.topbar-right {
  margin-left: auto;
  display: flex; align-items: center;
  gap: clamp(3px, 1.2vw, 8px);
  flex-shrink: 0;
}

/* Shared button primitives */
.tbtn {
  display: flex; align-items: center; justify-content: center; gap: 5px;
  height: clamp(28px, 5vw, 36px);
  padding: 0 clamp(7px, 1.8vw, 14px);
  border-radius: 8px;
  font-family: var(--fb); font-size: clamp(11px, 2.3vw, 13px); font-weight: 700;
  background: var(--sur); border: 1px solid var(--bd);
  color: var(--txm); cursor: pointer;
  transition: border-color .15s, color .15s;
  white-space: nowrap;
}
.tbtn:hover { border-color: var(--gold); color: var(--gold) }

.tbtn-icon {
  width: clamp(28px, 5vw, 36px);
  height: clamp(28px, 5vw, 36px);
  padding: 0;
  font-size: clamp(14px, 3vw, 17px);
}

.exit-btn {
  height: clamp(30px, 5.5vw, 36px);
  padding: 0 clamp(8px,2vw,12px);
  border-radius: 8px;
  font-family: var(--fb); font-size: clamp(11px,2.5vw,13px); font-weight: 700;
  background: rgba(239,68,68,.12);
  border: 1px solid rgba(239,68,68,.28);
  color: #ef4444; cursor: pointer;
  transition: all .15s;
  display: flex; align-items: center; gap: 4px;
  white-space: nowrap;
}
.exit-btn:hover { background: rgba(239,68,68,.22); border-color: #ef4444 }

/* On very small screens hide text labels */


/* ═══════════════════════════════════════════════════
   MODALS (shared base)
═══════════════════════════════════════════════════ */
.overlay {
  display: none; position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,.75);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  align-items: center; justify-content: center;
  padding: clamp(12px, 4vw, 24px);
  padding-bottom: max(clamp(12px, 4vw, 24px), var(--sai-bottom));
  overscroll-behavior: contain;
}
.overlay.on { display: flex }

.sheet {
  background: linear-gradient(160deg, #1e0d18 0%, #0d0305 100%);
  border: 1px solid rgba(245,200,66,.2);
  border-radius: clamp(14px, 3vw, 22px);
  width: 100%; max-width: 560px;
  max-height: calc(88dvh - var(--sai-top) - var(--sai-bottom));
  display: flex; flex-direction: column;
  box-shadow: 0 20px 70px rgba(0,0,0,.65), 0 0 36px rgba(200,16,46,.08);
  animation: modalPop .2s cubic-bezier(.4,0,.2,1);
  overflow: hidden;
}
@keyframes modalPop {
  from { opacity: 0; transform: scale(.93) }
  to   { opacity: 1; transform: scale(1) }
}

.sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: clamp(14px,3vw,20px) clamp(16px,4vw,26px) clamp(12px,2.5vw,16px);
  border-bottom: 1px solid rgba(245,200,66,.1);
  flex-shrink: 0;
}
.sheet-head h3 {
  font-size: clamp(15px,3.5vw,20px); font-weight: 800; color: var(--gold); letter-spacing: .3px;
}
.sheet-body {
  overflow-y: auto; flex: 1;
  padding: clamp(14px,3vw,20px) clamp(16px,4vw,26px) clamp(20px,5vw,32px);
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  display: flex; flex-direction: column; gap: clamp(12px,2.5vw,16px);
}

/* ─── History sheet ─── */
.history-sheet {
  max-width: min(660px, 94vw);
  max-height: min(calc(88dvh - var(--sai-top) - var(--sai-bottom)), 560px);
}

/* Compact stats row */
.h-stats { display: grid; grid-template-columns: repeat(3,1fr); gap: clamp(5px,1.5vw,10px) }
.h-stat-card {
  background: var(--sur); border: 1px solid var(--bd); border-radius: clamp(6px,1.5vw,10px);
  padding: clamp(6px,1.5vw,10px) clamp(6px,1.5vw,12px); text-align: center;
}
.h-stat-card .n { font-size: clamp(16px,3.5vw,22px); font-weight: 800; font-family: var(--fm) }
.h-stat-card .l { font-size: clamp(9px,1.8vw,11px); color: var(--txm); margin-top: 2px }

.streak-box {
  background: var(--gold-lo); border: 1px solid rgba(245,200,66,.18);
  border-radius: clamp(6px,1.5vw,8px);
  padding: clamp(5px,1.2vw,8px) clamp(10px,2vw,14px);
  font-size: clamp(11px,2.2vw,13px);
}

.h-recent-title {
  font-size: clamp(9px,1.8vw,11px); font-weight: 800;
  text-transform: uppercase; letter-spacing: 1.5px; color: var(--txf);
}
.h-recent-list {
  display: flex; flex-direction: column; gap: clamp(3px,0.8vw,5px);
  overflow-y: auto;
  max-height: clamp(160px, 38vh, 300px);
  padding-right: 3px; -webkit-overflow-scrolling: touch;
}
.h-recent-item {
  display: flex; align-items: center; gap: clamp(5px,1.5vw,10px);
  background: var(--sur); border-radius: clamp(5px,1.2vw,8px);
  padding: clamp(5px,1.2vw,8px) clamp(8px,2vw,12px);
  font-size: clamp(10px,2vw,13px);
}
.h-recent-idx  { font-family:var(--fm); font-size:clamp(8px,1.6vw,10px); color:var(--txf); min-width:16px; text-align:right; flex-shrink:0 }
.h-recent-dice { font-size:clamp(12px,2.8vw,16px); letter-spacing:1px; flex-shrink:0 }
.h-recent-total { font-family:var(--fm); color:var(--txm); font-size:clamp(9px,1.8vw,12px) }
.h-recent-label { margin-left:auto; font-weight:800; font-size:clamp(10px,2vw,13px); flex-shrink:0 }
.h-recent-label.tai    { color:#ff6680 }
.h-recent-label.xiu    { color:#7eb0ff }
.h-recent-label.triple { color:#ffaa44 }

/* sheet-body padding compact on small screens */
@media (max-height: 640px), (max-width: 400px) {
  .history-sheet .sheet-body {
    padding: 10px 12px 14px;
    gap: 8px;
  }
  .history-sheet .sheet-head {
    padding: 10px 12px 8px;
  }
  .history-sheet {
    max-height: min(calc(92dvh - var(--sai-top) - var(--sai-bottom)), 480px);
  }
}

/* ─── Advanced bets sheet ─── */
.modal-stitle {
  font-size: clamp(9px,2vw,12px); font-weight: 800;
  color: var(--txf); text-transform: uppercase; letter-spacing: 2px; margin-bottom: 7px;
}
.modal-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(clamp(110px,24vw,135px), 1fr));
  gap: clamp(6px,1.5vw,8px);
}
.modal-btn {
  padding: clamp(8px,2vw,11px) clamp(8px,2vw,12px);
  border-radius: clamp(8px,2vw,11px);
  background: var(--sur); border: 1.5px solid rgba(255,255,255,.07);
  color: var(--txm); cursor: pointer;
  font-family: var(--fb); font-size: clamp(12px,2.8vw,14px); font-weight: 700;
  display: flex; align-items: center; justify-content: space-between;
  transition: all .15s; min-height: 44px;
}
.modal-btn:hover  { border-color: var(--gold); color: var(--tx); background: var(--gold-lo) }
.modal-btn.selected { border-color: var(--gold); background: var(--gold-lo); color: var(--gold) }
.modal-btn .odds { font-family:var(--fm); font-size:clamp(9px,2vw,11px); color:var(--txf); margin-left:4px }
.modal-btn.selected .odds { color: rgba(245,200,66,.6) }

/* ═══════════════════════════════════════════════════
   LOGOUT + PASSWORD MODALS
═══════════════════════════════════════════════════ */
.dialog-overlay {
  display: none; position: fixed; inset: 0; z-index: 400;
  background: rgba(0,0,0,.78);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  align-items: center; justify-content: center;
  padding: clamp(12px,4vw,20px);
  padding-bottom: max(clamp(12px,4vw,20px), var(--sai-bottom));
  overflow-y: auto;
}
.dialog-overlay.on { display: flex; animation: fadeIn .15s ease }

.dialog-box {
  border-radius: clamp(14px,3vw,22px);
  padding: clamp(22px,5vw,30px) clamp(22px,5vw,32px);
  width: 100%; max-width: 360px;
  text-align: center;
  animation: modalPop .2s cubic-bezier(.4,0,.2,1);
  max-height: calc(92dvh - var(--sai-top) - var(--sai-bottom));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  flex-shrink: 0;
}

.dialog-icon { font-size: clamp(36px,8vw,48px); margin-bottom: 10px }
.dialog-title {
  font-family: var(--fh);
  font-size: clamp(18px,4vw,22px); font-weight: 700;
  margin-bottom: 7px;
}
.dialog-msg {
  font-size: clamp(12px,2.8vw,15px); line-height: 1.55;
  color: var(--txm); margin-bottom: 8px;
}
.dialog-countdown {
  font-family: var(--fh); font-size: clamp(20px,5vw,24px);
  font-weight: 700; color: var(--gold); margin-bottom: 18px;
  text-shadow: 0 0 10px rgba(245,200,66,.45);
}
.dialog-actions { display: flex; gap: clamp(8px,2vw,12px); justify-content: center }
.dialog-btn {
  flex: 1; padding: clamp(10px,2.5vw,12px);
  border-radius: clamp(8px,2vw,12px);
  font-family: var(--fh); font-size: clamp(13px,3vw,15px); font-weight: 700;
  cursor: pointer; transition: all .15s; min-height: 44px;
}

/* Logout dialog */
.logout-box {
  background: linear-gradient(160deg,#2a1818,#1a0a0a);
  border: 2px solid rgba(239,68,68,.45);
  box-shadow: 0 16px 50px rgba(239,68,68,.18);
}
.logout-box .dialog-title { color: #ef4444; text-shadow: 0 0 14px rgba(239,68,68,.45) }
.btn-cancel-dialog {
  background: rgba(255,255,255,.07); border: 1px solid rgba(255,255,255,.1); color: var(--tx);
}
.btn-cancel-dialog:hover { background: rgba(255,255,255,.14) }
.btn-danger-dialog {
  background: linear-gradient(135deg,#ef4444,#b91c1c);
  border: none; color: #fff;
  box-shadow: 0 4px 14px rgba(239,68,68,.38);
}
.btn-danger-dialog:disabled { opacity: .35; cursor: not-allowed; transform: none; box-shadow: none }
.btn-danger-dialog:hover:not(:disabled) { box-shadow: 0 6px 22px rgba(239,68,68,.55) }

/* Password dialog */
.password-box {
  background: linear-gradient(160deg,#1e2a18,#0a1508);
  border: 2px solid var(--gold);
  box-shadow: 0 16px 50px rgba(245,200,66,.18);
}
.password-box .dialog-title { color: var(--gold) }
.password-input {
  width: 100%;
  padding: clamp(10px,2.5vw,12px) clamp(12px,3vw,16px);
  border-radius: clamp(8px,2vw,12px);
  background: rgba(0,0,0,.3);
  border: 2px solid rgba(245,200,66,.28);
  color: var(--tx); font-family: var(--fm);
  /* prevent iOS zoom */
  font-size: max(16px, 14px);
  margin-bottom: 12px; outline: none; transition: all .15s;
}
.password-input:focus { border-color: var(--gold); background: rgba(245,200,66,.04) }
.btn-gold-dialog {
  background: linear-gradient(135deg,#d4a500,#f5c842);
  border: none; color: #1a0800;
  box-shadow: 0 4px 14px rgba(245,200,66,.35);
}
.btn-gold-dialog:hover { box-shadow: 0 6px 22px rgba(245,200,66,.55) }

/* ═══════════════════════════════════════════════════
   TOAST
═══════════════════════════════════════════════════ */
#toast-area {
  position: fixed;
  bottom: max(calc(var(--topbar-h) + 12px), calc(var(--sai-bottom) + 10px));
  right: max(10px, var(--sai-right));
  z-index: 300;
  display: flex; flex-direction: column; gap: 5px; align-items: flex-end;
  pointer-events: none;
}
.toast {
  background: rgba(15,5,10,.95); border: 1px solid var(--bd);
  border-radius: clamp(8px,2vw,10px);
  padding: clamp(7px,1.8vw,9px) clamp(12px,3vw,15px);
  font-size: clamp(11px,2.5vw,13px); font-weight: 700; color: var(--tx);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  animation: toastIn .2s ease;
  max-width: min(280px, 80vw);
}
@keyframes toastIn {
  from { opacity: 0; transform: translateX(20px) }
  to   { opacity: 1; transform: translateX(0) }
}
.toast.success { border-color: var(--green); color: var(--green) }
.toast.error   { border-color: var(--red);   color: var(--red) }
.toast.info    { border-color: var(--gold);  color: var(--gold) }


/* ═══════════════════════════════════════════════════
   SPINNER
═══════════════════════════════════════════════════ */
.spinner {
  display: inline-block;
  width: clamp(14px,3vw,18px); height: clamp(14px,3vw,18px);
  border-radius: 50%;
  border: 2px solid rgba(245,200,66,.18);
  border-top-color: var(--gold);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg) } }

/* ═══════════════════════════════════════════════════
   RECOVERY ROW BUTTON
═══════════════════════════════════════════════════ */
.btn-recover-row {
  display: block; width: 100%; margin-top: 10px;
  padding: clamp(8px,2vw,10px);
  background: none; border: 1px dashed rgba(245,200,66,.2);
  border-radius: clamp(8px,2vw,10px);
  color: var(--txf); font-family: var(--fb);
  font-size: clamp(11px,2.5vw,13px); font-weight: 600;
  cursor: pointer; transition: all .15s; text-align: center;
}
.btn-recover-row:hover { border-color: rgba(245,200,66,.5); color: var(--txm) }