:root {
  --bg: #0f0e1a;
  --panel: #1b182a;
  --panel-dark: #131020;
  --border: #3a3154;
  --accent: #f59e0b;
  --gem: #38bdf8;
  --green: #22c55e;
  --red: #ef4444;
  --text: #f8fafc;
  --muted: #94a3b8;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg); color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  user-select: none; overflow-x: hidden;
}

.game-shell {
  max-width: 1320px; margin: 0 auto;
  padding: 12px 16px 20px;
  display: flex; flex-direction: column; gap: 12px;
}

/* HUD */
.hud-bar {
  background: var(--panel); border: 2px solid var(--border); border-radius: 12px;
  padding: 10px 14px; display: flex; align-items: center; justify-content: space-between;
  gap: 10px; flex-wrap: wrap; box-shadow: 0 6px 20px rgba(0,0,0,0.45);
}
.hud-left, .hud-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.logo-pill {
  font-weight: 900; letter-spacing: 0.06em; font-size: 15px;
  background: #2b1d3d; border: 2px solid #8b5cf6; padding: 5px 11px; border-radius: 8px; color: #fde047;
}
.stat-pill {
  background: var(--panel-dark); border: 1px solid var(--border);
  padding: 6px 10px; border-radius: 8px; font-size: 13.5px;
  display: inline-flex; align-items: center; gap: 5px;
}
.stat-gem { border-color: rgba(56,189,248,0.55); cursor: pointer; }
.stat-gem:hover { background: #182638; }
.plus-btn {
  background: var(--gem); color: #0b1120; font-weight: 900;
  width: 18px; height: 18px; border-radius: 4px;
  display: inline-flex; align-items: center; justify-content: center; font-size: 13px; margin-left: 2px;
}
.stat-boss { color: #fca5a5; border-color: rgba(239,68,68,0.4); }

.hud-btn {
  background: #26203a; color: var(--text); border: 2px solid #453a66;
  border-radius: 8px; padding: 7px 12px; font-size: 13px; font-weight: 700; cursor: pointer;
}
.hud-btn:hover { background: #342c50; }
.hud-btn-donate {
  background: linear-gradient(135deg, #d97706, #b45309); border-color: #fbbf24;
  color: #fff; box-shadow: 0 0 14px rgba(245,158,11,0.35);
}
.vip-tag {
  background: #fef08a; color: #713f12; font-size: 10px;
  padding: 1px 5px; border-radius: 4px; margin-left: 4px; font-weight: 900;
}

/* MAIN GRID */
.main-grid {
  display: grid; grid-template-columns: 388px 1fr; gap: 14px; align-items: start;
}

/* DICE TABLE COLUMN */
.dice-column {
  background: #1f1a30; border: 3px solid #524378; border-radius: 16px;
  overflow: hidden; box-shadow: 0 10px 28px rgba(0,0,0,0.48);
  transition: border-color 0.25s, box-shadow 0.25s, background 0.25s;
}
.dice-column.skin-demon {
  background: #2a1216; border-color: #ef4444; box-shadow: 0 0 28px rgba(239,68,68,0.35);
}
.dice-column.skin-gold {
  background: #2c2310; border-color: #facc15; box-shadow: 0 0 28px rgba(250,204,21,0.32);
}
.dice-column.skin-cyber {
  background: #0c1829; border-color: #22d3ee; box-shadow: 0 0 28px rgba(34,211,238,0.35);
}

.board-crown {
  background: rgba(0,0,0,0.38); border-bottom: 2px solid rgba(255,255,255,0.08);
  padding: 9px 12px; display: flex; align-items: center; justify-content: center; gap: 8px;
}
.board-title { font-weight: 900; font-size: 12px; letter-spacing: 0.05em; color: #e2e8f0; }

.board-body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 9px; }
.cost-bar {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 13px; color: #cbd5e1; background: rgba(0,0,0,0.32); padding: 6px 10px; border-radius: 8px;
}
.reroll-pill { color: #fde047; font-size: 12.5px; }
.free-badge { color: #7dd3fc; font-size: 11.5px; font-weight: 700; }

/* FELT TABLE & 5 PIXEL DICE */
.table-felt {
  background: radial-gradient(circle at 50% 35%, #174636 0%, #0d2b22 72%, #081c16 100%);
  border: 3px solid #3c5c4c; border-radius: 12px;
  padding: 10px 10px 12px;
  box-shadow: inset 0 0 26px rgba(0,0,0,0.65);
  display: flex; flex-direction: column; gap: 10px;
}
.dice-column.skin-demon .table-felt {
  background: radial-gradient(circle at 50% 35%, #4a151b 0%, #260a0d 75%, #160507 100%);
  border-color: #991b1b;
}
.dice-column.skin-gold .table-felt {
  background: radial-gradient(circle at 50% 35%, #4b3912 0%, #291e08 75%, #181104 100%);
  border-color: #ca8a04;
}
.dice-column.skin-cyber .table-felt {
  background: radial-gradient(circle at 50% 35%, #0e2c45 0%, #071726 75%, #040d17 100%);
  border-color: #0891b2;
}

.felt-meta {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 11.5px; color: #cbd5e1; opacity: 0.9;
}

.dice-tray {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 10px;
  padding: 6px 2px;
}

.die-card {
  width: 96px; height: 106px;
  background: linear-gradient(180deg, #f1ebd8 0%, #d8cdb0 100%);
  border: 3px solid #7c6f52;
  border-radius: 14px;
  box-shadow: 0 6px 0 #4d4430, 0 10px 18px rgba(0,0,0,0.55);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; position: relative; cursor: pointer;
  transition: transform 0.12s, border-color 0.15s, box-shadow 0.15s;
}
.die-card:hover { transform: translateY(-2px); }
.die-card:active { transform: translateY(2px); }

.dice-column.skin-demon .die-card {
  background: linear-gradient(180deg, #3b1116 0%, #21070a 100%);
  border-color: #ef4444; box-shadow: 0 6px 0 #7f1d1d, 0 0 14px rgba(239,68,68,0.4);
}
.dice-column.skin-gold .die-card {
  background: linear-gradient(180deg, #fef08a 0%, #eab308 100%);
  border-color: #a16207; box-shadow: 0 6px 0 #713f12, 0 0 14px rgba(250,204,21,0.45);
}
.dice-column.skin-cyber .die-card {
  background: linear-gradient(180deg, #0f2942 0%, #081829 100%);
  border-color: #22d3ee; box-shadow: 0 6px 0 #0e7490, 0 0 14px rgba(34,211,238,0.4);
}

.die-card.locked {
  border-color: #facc15 !important;
  box-shadow: 0 0 0 2px #facc15, 0 6px 0 #854d0e, 0 0 18px rgba(250,204,21,0.55) !important;
  transform: translateY(-3px);
}
.die-card.inactive {
  opacity: 0.72;
}
.die-card.rolling {
  animation: dieTumble 0.24s infinite ease-in-out;
}
@keyframes dieTumble {
  0% { transform: rotate(-7deg) scale(0.95); }
  50% { transform: rotate(7deg) scale(1.05); }
  100% { transform: rotate(-7deg) scale(0.95); }
}

.die-idx {
  position: absolute; top: 4px; left: 6px;
  font-size: 10px; font-weight: 900; color: rgba(15,23,42,0.55);
}
.dice-column.skin-demon .die-idx,
.dice-column.skin-cyber .die-idx { color: rgba(248,250,252,0.55); }

.die-lock-badge {
  position: absolute; top: -9px; right: -6px;
  background: #facc15; color: #1c1917; border: 2px solid #713f12;
  font-size: 9.5px; font-weight: 900; padding: 1px 6px; border-radius: 999px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.5);
}

.die-icon {
  width: 54px; height: 54px; image-rendering: pixelated; object-fit: contain;
  filter: drop-shadow(0 2px 2px rgba(0,0,0,0.35));
}
.die-label {
  font-size: 11px; font-weight: 900; color: #1e293b; letter-spacing: 0.02em;
}
.dice-column.skin-demon .die-label,
.dice-column.skin-cyber .die-label { color: #f8fafc; }

.dice-hint {
  text-align: center; font-size: 11px; color: #a7f3d0; opacity: 0.85;
}
.dice-column.skin-demon .dice-hint { color: #fecaca; }
.dice-column.skin-gold .dice-hint { color: #fef08a; }
.dice-column.skin-cyber .dice-hint { color: #a5f3fc; }

/* LIVE COMBO PANEL */
.combo-panel {
  background: #141022; border: 2px solid #4c3f70; border-radius: 10px;
  padding: 9px 12px; text-align: center;
  transition: border-color 0.2s, background 0.2s;
}
.combo-panel.tier-high {
  border-color: #facc15; background: #261f10;
  box-shadow: 0 0 16px rgba(250,204,21,0.25);
}
.combo-panel.tier-mid {
  border-color: #38bdf8; background: #102133;
}
.combo-panel.tier-low {
  border-color: #22c55e; background: #102419;
}
.combo-tag {
  font-size: 13.5px; font-weight: 900; color: #fde047; letter-spacing: 0.03em;
}
.combo-desc {
  font-size: 12px; color: #e2e8f0; margin-top: 3px;
}

/* ACTION BUTTONS */
.dice-actions { display: flex; flex-direction: column; gap: 7px; }
.btn-roll {
  width: 100%; padding: 11px; border-radius: 10px;
  background: linear-gradient(180deg, #22c55e, #15803d); border: 2px solid #86efac;
  color: #fff; font-size: 14px; font-weight: 900; cursor: pointer; box-shadow: 0 4px 0 #14532d;
}
.btn-roll:hover:not(:disabled) { filter: brightness(1.08); }
.btn-roll:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 2px 0 #14532d; }
.btn-roll:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-claim {
  width: 100%; padding: 10px; border-radius: 10px;
  background: linear-gradient(180deg, #f59e0b, #d97706); border: 2px solid #fde68a;
  color: #1c1917; font-size: 14px; font-weight: 900; cursor: pointer; box-shadow: 0 4px 0 #92400e;
}
.btn-claim:hover:not(:disabled) { filter: brightness(1.08); }
.btn-claim:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 2px 0 #92400e; }
.btn-claim:disabled { opacity: 0.42; cursor: not-allowed; box-shadow: none; }

.sub-actions { display: grid; grid-template-columns: 1fr auto; gap: 6px; }
.btn-loaded {
  padding: 9px 10px; border-radius: 9px;
  background: linear-gradient(180deg, #0284c7, #0369a1); border: 2px solid #7dd3fc;
  color: #fff; font-size: 12px; font-weight: 800; cursor: pointer;
}
.btn-loaded:hover { filter: brightness(1.1); }
.btn-autolock {
  padding: 9px 10px; border-radius: 9px;
  background: #27213a; border: 2px solid #4c406e; color: #cbd5e1;
  font-size: 11.5px; font-weight: 800; cursor: pointer;
}
.btn-autolock.active { background: #4c1d95; border-color: #c084fc; color: #fff; }

.daily-chest-btn {
  width: 100%; padding: 8px; border-radius: 9px;
  background: rgba(245,158,11,0.14); border: 1px solid rgba(245,158,11,0.5);
  color: #fde68a; font-size: 12px; font-weight: 700; cursor: pointer;
}
.daily-chest-btn:disabled { opacity: 0.45; cursor: default; }

/* ARENA */
.arena-column { display: flex; flex-direction: column; gap: 10px; }
.arena-frame {
  background: var(--panel); border: 3px solid var(--border); border-radius: 16px;
  overflow: hidden; position: relative; box-shadow: 0 10px 28px rgba(0,0,0,0.45);
}
.world-banner {
  background: #141122; padding: 8px 14px; border-bottom: 2px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
  font-size: 13px; font-weight: 800; color: #e2e8f0;
}
.wave-badge {
  font-size: 11.5px; padding: 3px 9px; border-radius: 999px;
  background: rgba(99,102,241,0.2); color: #a5b4fc;
}
.wave-badge.combat { background: rgba(239,68,68,0.22); color: #fca5a5; }

.boss-bar-wrap {
  position: absolute; top: 48px; left: 50%; transform: translateX(-50%);
  width: 68%; z-index: 5; text-align: center;
}
.boss-name { font-size: 13px; font-weight: 900; color: #fecaca; text-shadow: 0 2px 6px #000; margin-bottom: 4px; }
.boss-bar-bg { height: 14px; background: #0f172a; border: 2px solid #ef4444; border-radius: 7px; overflow: hidden; }
.boss-bar-fill { height: 100%; background: linear-gradient(90deg, #dc2626, #f97316); transition: width 0.12s; }

.summon-banner {
  position: absolute; top: 54px; left: 50%; transform: translateX(-50%);
  background: rgba(15,23,42,0.92); border: 2px solid #facc15; color: #fef08a;
  padding: 7px 16px; border-radius: 10px; font-size: 13.5px; font-weight: 800;
  z-index: 6; pointer-events: none; box-shadow: 0 8px 22px rgba(0,0,0,0.6);
  white-space: nowrap;
}

#arenaCanvas { display: block; width: 100%; height: auto; image-rendering: pixelated; background: #1b2432; }

.arena-footer {
  background: #141122; border-top: 2px solid var(--border); padding: 10px 14px;
  display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap;
}
.skills-bar { display: flex; gap: 7px; flex-wrap: wrap; }
.skill-btn {
  padding: 8px 11px; border-radius: 8px; background: #252038;
  border: 2px solid #473c66; color: #e2e8f0; font-size: 12.5px; font-weight: 700; cursor: pointer;
}
.skill-btn:hover { background: #332c4d; }

.btn-next-wave {
  padding: 10px 20px; border-radius: 10px;
  background: linear-gradient(180deg, #ef4444, #b91c1c); border: 2px solid #fca5a5;
  color: #fff; font-size: 14px; font-weight: 900; cursor: pointer; box-shadow: 0 3px 0 #7f1d1d;
}
.btn-next-wave:disabled { opacity: 0.5; cursor: not-allowed; }

.roster-bar {
  background: var(--panel); border: 2px solid var(--border); border-radius: 12px;
  padding: 10px 12px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; min-height: 58px;
}
.roster-empty { color: var(--muted); font-size: 13px; }
.roster-chip {
  background: #151220; border: 1.5px solid #41375c; border-radius: 8px;
  padding: 4px 10px; font-size: 12px; display: inline-flex; align-items: center; gap: 6px;
}
.roster-chip.rare { border-color: #38bdf8; }
.roster-chip.legendary { border-color: #facc15; background: #262010; }
.roster-avatar { width: 28px; height: 28px; image-rendering: pixelated; object-fit: contain; }
.roster-chip .sell-x { color: #f87171; cursor: pointer; font-weight: 900; margin-left: 4px; }

/* MODALS */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(6,6,12,0.78);
  display: flex; align-items: center; justify-content: center;
  padding: 16px; z-index: 100; backdrop-filter: blur(4px);
}
.modal-box {
  background: #1b1728; border: 2px solid #4d406e; border-radius: 16px;
  width: 100%; max-width: 640px; max-height: 88vh;
  display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 20px 50px rgba(0,0,0,0.7);
}
.modal-wide { max-width: 820px; }
.modal-head {
  padding: 15px 20px; background: #141020; border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: flex-start; gap: 12px;
}
.modal-head h2 { margin: 0; font-size: 18px; }
.modal-sub { margin: 4px 0 0; font-size: 12.5px; color: var(--muted); }
.modal-close {
  background: #2b243f; border: 1px solid #4a3f68; color: #fff;
  width: 32px; height: 32px; border-radius: 8px; cursor: pointer; font-size: 15px;
}
.merchant-banner-wrap { width: 100%; height: 145px; overflow: hidden; border-bottom: 2px solid var(--border); }
.merchant-banner { width: 100%; height: 100%; object-fit: cover; image-rendering: pixelated; }

.combo-guide-strip {
  padding: 10px 20px; background: #151126; border-bottom: 1px solid var(--border);
  display: flex; flex-wrap: wrap; gap: 8px 14px; font-size: 12px; color: #cbd5e1;
}
.combo-guide-strip b { color: #fde047; }

.gateway-strip {
  padding: 10px 20px; background: #191529; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px; font-size: 12.5px; color: var(--muted); flex-wrap: wrap;
}
.gateway-strip select {
  background: #0f0d18; color: #fff; border: 1px solid #4a3f68; border-radius: 7px; padding: 5px 10px; font-size: 12.5px;
}
.tx-counter { margin-left: auto; color: #86efac; font-weight: 700; }

.modal-tabs { display: flex; gap: 6px; padding: 12px 20px 0; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.tab-btn {
  padding: 8px 14px; background: transparent; border: none;
  border-bottom: 3px solid transparent; color: var(--muted); font-size: 13px; font-weight: 700; cursor: pointer;
}
.tab-btn.active { color: #fde047; border-bottom-color: #f59e0b; }

.modal-content {
  padding: 18px 20px; overflow-y: auto;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px;
}
.offer-card {
  background: #141020; border: 2px solid #393052; border-radius: 12px;
  padding: 14px; display: flex; flex-direction: column; justify-content: space-between; gap: 10px; position: relative;
}
.offer-card.popular { border-color: #f59e0b; background: #211a14; }
.offer-badge {
  position: absolute; top: -10px; right: 12px;
  background: #f59e0b; color: #1c1917; font-size: 10px; font-weight: 900; padding: 2px 8px; border-radius: 999px;
}
.offer-title { font-size: 15px; font-weight: 800; color: #fff; }
.offer-desc { font-size: 12.5px; color: #cbd5e1; line-height: 1.45; }
.offer-price-row { display: flex; align-items: baseline; gap: 8px; }
.offer-price { font-size: 19px; font-weight: 900; color: #fde047; }
.offer-old { font-size: 13px; color: #64748b; text-decoration: line-through; }
.btn-buy {
  width: 100%; padding: 9px; border-radius: 8px;
  background: linear-gradient(180deg, #f59e0b, #d97706); border: 1px solid #fde68a;
  color: #1c1917; font-weight: 900; font-size: 13px; cursor: pointer;
}
.btn-buy:disabled { opacity: 0.45; cursor: default; }
.btn-buy-gem { background: linear-gradient(180deg, #38bdf8, #0284c7); color: #fff; border-color: #bae6fd; }
.codex-sprite {
  width: 56px; height: 56px; image-rendering: pixelated; object-fit: contain;
  background: rgba(0,0,0,0.35); border: 1.5px solid #41375c; border-radius: 10px; padding: 4px;
}
.codex-sym {
  width: 24px; height: 24px; image-rendering: pixelated; object-fit: contain; vertical-align: middle;
}
.shop-footer { padding: 12px 20px; border-top: 1px solid var(--border); background: #141020; text-align: right; }
.btn-reroll { padding: 8px 16px; border-radius: 8px; background: #31274a; border: 1px solid #63538c; color: #fff; font-weight: 700; cursor: pointer; }

.toast {
  position: fixed; bottom: 20px; right: 20px; background: #171326;
  border: 2px solid #f59e0b; color: #fff; padding: 10px 16px; border-radius: 10px;
  font-size: 13px; font-weight: 700; box-shadow: 0 10px 30px rgba(0,0,0,0.6);
  opacity: 0; transform: translateY(10px); pointer-events: none; transition: all 0.18s; z-index: 200;
}
.toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 980px) { .main-grid { grid-template-columns: 1fr; } }
