/* ===== RESET & BIẾN ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg:        #0d0f14;
  --bg-panel:  #161a22;
  --bg-panel2: #1d222c;
  --border:    #2a3140;
  --text:      #e6e9ef;
  --muted:     #8b95a7;
  --accent:    #e63946;
  --accent2:   #ff6b6b;
  --green:     #2ecc71;
  --yellow:    #f1c40f;
  --blue:      #3498db;
  --card-bg:   #fdfdfd;
  --card-red:  #c0392b;
  --card-blk:  #1a1a1a;
  --radius:    12px;
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: radial-gradient(ellipse at top, #141822 0%, #0a0c10 60%);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
  padding: 24px 16px 60px;
}

.wrap {
  max-width: 860px;
  margin: 0 auto;
}

/* ===== HEADER ===== */
header {
  text-align: center;
  margin-bottom: 28px;
}

h1 {
  font-size: clamp(1.5rem, 4vw, 2.1rem);
  letter-spacing: -0.5px;
  margin-bottom: 10px;
}

h1 .accent {
  color: var(--accent2);
}

.sub {
  color: var(--muted);
  font-size: 0.95rem;
  max-width: 620px;
  margin: 0 auto;
}

.sub strong {
  color: var(--yellow);
}

/* ===== PANEL CHUNG ===== */
.panel {
  background: linear-gradient(180deg, var(--bg-panel), var(--bg-panel2));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}

.panel h2 {
  font-size: 1.05rem;
  margin-bottom: 14px;
  color: var(--text);
  letter-spacing: 0.2px;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.panel-head h2 {
  margin-bottom: 0;
}

/* ===== BADGE ===== */
.badge {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(46, 204, 113, 0.15);
  color: var(--green);
  border: 1px solid rgba(46, 204, 113, 0.35);
  transition: all 0.25s ease;
  white-space: nowrap;
}

.badge.warn {
  background: rgba(241, 196, 15, 0.15);
  color: var(--yellow);
  border-color: rgba(241, 196, 15, 0.35);
}

.badge.danger {
  background: rgba(230, 57, 70, 0.18);
  color: var(--accent2);
  border-color: rgba(230, 57, 70, 0.45);
}

/* ===== SLIDER ===== */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 8px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--green) 0%, var(--yellow) 50%, var(--accent) 100%);
  outline: none;
  margin: 8px 0 16px;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--accent);
  box-shadow: 0 2px 8px rgba(0,0,0,0.5);
  cursor: grab;
  transition: transform 0.15s;
}

input[type="range"]::-webkit-slider-thumb:active {
  transform: scale(1.15);
  cursor: grabbing;
}

input[type="range"]::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--accent);
  cursor: grab;
}

/* ===== PRESETS ===== */
.presets {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.presets button {
  flex: 1 1 auto;
  min-width: 90px;
  padding: 8px 12px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
  background: var(--bg-panel2);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.18s ease;
}

.presets button:hover {
  background: #252c38;
  border-color: #3a4459;
  transform: translateY(-1px);
}

.presets button:active {
  transform: translateY(0);
}

/* ===== HINT ===== */
.hint {
  font-size: 0.85rem;
  color: var(--muted);
  padding: 10px 14px;
  background: rgba(255,255,255,0.03);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  margin-bottom: 14px;
  transition: color 0.25s;
}

/* ===== TOGGLE ===== */
.toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.88rem;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}

.toggle input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* ===== BÀN CHƠI ===== */
.table {
  background: linear-gradient(160deg, #14532d 0%, #0f3d22 100%);
  border: 1px solid #1e6b3a;
  border-radius: var(--radius);
  padding: 24px 20px;
  margin-bottom: 20px;
  box-shadow: inset 0 0 60px rgba(0,0,0,0.5), 0 8px 24px rgba(0,0,0,0.4);
}

.hand {
  margin-bottom: 6px;
}

.hand-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 10px;
}

.hand-head h3 {
  font-size: 0.9rem;
  letter-spacing: 2px;
  color: #b8e6c8;
  font-weight: 700;
}

.score {
  font-size: 1.2rem;
  font-weight: 800;
  color: #fff;
  background: rgba(0,0,0,0.35);
  padding: 2px 12px;
  border-radius: 8px;
  min-width: 52px;
  text-align: center;
  transition: color 0.2s;
}

.score.bust { color: var(--accent2); }
.score.blackjack { color: var(--yellow); }

.cards {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 104px;
  align-items: center;
}

.divider {
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
  margin: 18px 0;
}

/* ===== LÁ BÀI ===== */
.card {
  width: 70px;
  height: 100px;
  border-radius: 8px;
  background: var(--card-bg);
  color: var(--card-blk);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 6px 8px;
  font-weight: 800;
  font-size: 1.05rem;
  box-shadow: 0 4px 10px rgba(0,0,0,0.45);
  animation: dealIn 0.3s ease-out;
  position: relative;
  transition: box-shadow 0.25s, transform 0.2s;
}

.card:hover {
  transform: translateY(-3px);
}

.card.red { color: var(--card-red); }

.card .corner {
  font-size: 0.75rem;
  line-height: 1;
}

.card .corner.bottom {
  align-self: flex-end;
  transform: rotate(180deg);
}

.card .suit-big {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 1.9rem;
  opacity: 0.9;
}

.card.back {
  background:
    repeating-linear-gradient(45deg, #1e3a8a 0 8px, #1e40af 8px 16px);
  border: 2px solid #93c5fd;
}

.card.back .corner,
.card.back .suit-big {
  display: none;
}

/* Lá bị can thiệp */
.card.rigged {
  box-shadow: 0 0 0 2px var(--accent), 0 0 14px rgba(230,57,70,0.7);
}

.card.rigged::after {
  content: "⚠";
  position: absolute;
  top: -8px;
  right: -8px;
  background: var(--accent);
  color: #fff;
  font-size: 0.7rem;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(0,0,0,0.5);
}

@keyframes dealIn {
  from {
    opacity: 0;
    transform: translateY(-24px) rotate(-6deg) scale(0.9);
  }
  to {
    opacity: 1;
    transform: translateY(0) rotate(0) scale(1);
  }
}

/* ===== NÚT HÀNH ĐỘNG ===== */
.actions {
  display: flex;
  gap: 10px;
  margin-top: 22px;
  flex-wrap: wrap;
}

.actions button {
  flex: 1 1 auto;
  min-width: 120px;
  padding: 12px 18px;
  font-size: 0.95rem;
  font-weight: 700;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-panel2);
  color: var(--text);
  cursor: pointer;
  transition: all 0.18s ease;
  letter-spacing: 0.3px;
}

.actions button:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(0,0,0,0.4);
}

.actions button:active:not(:disabled) {
  transform: translateY(0);
}

.actions button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.actions button.primary {
  background: linear-gradient(180deg, var(--accent2), var(--accent));
  border-color: var(--accent);
  color: #fff;
}

.actions button.primary:hover:not(:disabled) {
  box-shadow: 0 6px 20px rgba(230,57,70,0.5);
}

/* ===== THÔNG BÁO ===== */
.msg {
  margin-top: 18px;
  padding: 14px 16px;
  border-radius: 10px;
  background: rgba(0,0,0,0.35);
  border-left: 4px solid var(--muted);
  font-size: 0.95rem;
  text-align: center;
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
}

.msg.win {
  border-left-color: var(--green);
  background: rgba(46,204,113,0.12);
  color: #b9f6ca;
}

.msg.lose {
  border-left-color: var(--accent);
  background: rgba(230,57,70,0.12);
  color: #ffc9cd;
}

.msg.push {
  border-left-color: var(--yellow);
  background: rgba(241,196,15,0.12);
  color: #ffeaa7;
}

/* ===== THỐNG KÊ ===== */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.stat {
  background: var(--bg-panel2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 12px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat .num {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--text);
}

.stat .lbl {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--muted);
}

.stat.house .num { color: var(--accent2); }
.stat.player .num { color: var(--green); }
.stat.push .num { color: var(--yellow); }

/* ===== THANH TỈ LỆ ===== */
.bar {
  display: flex;
  height: 14px;
  border-radius: 999px;
  overflow: hidden;
  background: var(--bg-panel2);
  border: 1px solid var(--border);
  margin-bottom: 18px;
}

.bar > div {
  transition: width 0.4s ease;
  min-width: 0;
}

.bar-house  { background: linear-gradient(90deg, #b91c1c, var(--accent2)); }
.bar-push   { background: linear-gradient(90deg, #a08400, var(--yellow)); }
.bar-player { background: linear-gradient(90deg, #15803d, var(--green)); }

/* ===== MÔ PHỎNG ===== */
.sim {
  border-top: 1px dashed var(--border);
  padding-top: 16px;
}

.sim button {
  width: 100%;
  padding: 12px 18px;
  font-size: 0.92rem;
  font-weight: 700;
  border-radius: 10px;
  border: 1px solid var(--blue);
  background: rgba(52,152,219,0.12);
  color: #7ec8f0;
  cursor: pointer;
  transition: all 0.18s ease;
}

.sim button:hover {
  background: rgba(52,152,219,0.22);
  transform: translateY(-2px);
}

.sim-result {
  margin-top: 12px;
  font-size: 0.9rem;
  color: var(--muted);
  text-align: center;
  min-height: 22px;
}

.sim-result strong {
  color: var(--text);
}

/* ===== GIẢI THÍCH ===== */
.explain .muted {
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 12px;
}

.explain .muted.small {
  font-size: 0.82rem;
  font-style: italic;
  border-top: 1px dashed var(--border);
  padding-top: 12px;
  margin-top: 14px;
}

.list {
  list-style: none;
  margin: 12px 0;
}

.list li {
  padding: 8px 0 8px 26px;
  position: relative;
  font-size: 0.9rem;
  color: #cbd3e0;
  border-bottom: 1px solid rgba(255,255,255,0.04);
}

.list li::before {
  content: "▸";
  position: absolute;
  left: 6px;
  color: var(--accent2);
  font-weight: 900;
}

.list li:last-child {
  border-bottom: none;
}

.list b {
  color: var(--text);
}

/* ===== FOOTER ===== */
.foot {
  text-align: center;
  font-size: 0.8rem;
  color: var(--muted);
  padding: 20px 8px 0;
  opacity: 0.7;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 520px) {
  .card { width: 58px; height: 84px; font-size: 0.9rem; }
  .card .suit-big { font-size: 1.5rem; }
  .presets button { flex: 1 1 calc(50% - 8px); }
  .stat .num { font-size: 1.3rem; }
  .actions button { min-width: 90px; padding: 10px 12px; font-size: 0.85rem; }
}