* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background: #1a6b3c;
  background-image:
    radial-gradient(ellipse at center, #1e7d47 0%, #145230 70%, #0d3a22 100%);
  min-height: 100vh;
  font-family: 'Plus Jakarta Sans', sans-serif;
  color: #fff;
  display: flex;
  justify-content: center;
  align-items: center;
}

#app {
  width: 100%;
  max-width: 760px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Header */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: relative;
  padding: 12px 20px;
  background: rgba(0,0,0,0.35);
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.12);
}

.header-left {
  flex-shrink: 0;
}

header h1 {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  font-size: 1.8rem;
  letter-spacing: 3px;
  text-shadow: 2px 2px 6px rgba(0,0,0,0.6);
  white-space: nowrap;
  pointer-events: none;
}

#btn-menu {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 2px solid rgba(255,255,255,0.5);
  background: rgba(255,255,255,0.12);
  color: #fff;
  font-size: 1.2rem;
  cursor: pointer;
  padding: 0;
  line-height: 1;
  transition: background 0.15s, border-color 0.15s;
}

#btn-menu:hover {
  background: rgba(255,255,255,0.25);
  border-color: rgba(255,255,255,0.8);
  transform: none;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-self: end;
}

#balance-display {
  font-size: 1.1rem;
  background: rgba(255,215,0,0.15);
  border: 1px solid rgba(255,215,0,0.4);
  padding: 6px 14px;
  border-radius: 20px;
  color: #ffd700;
  font-weight: bold;
  display: flex;
  align-items: center;
  gap: 6px;
}

#info-wrapper {
  position: relative;
}

#btn-info {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.5);
  background: rgba(255,255,255,0.12);
  color: #fff;
  font-size: 1rem;
  font-weight: bold;
  cursor: pointer;
  padding: 0;
  line-height: 1;
  transition: background 0.15s, border-color 0.15s;
}

#btn-info:hover {
  background: rgba(255,255,255,0.25);
  border-color: rgba(255,255,255,0.8);
  transform: none;
}

#highscore-tooltip {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  background: rgba(10,20,10,0.96);
  border: 1px solid rgba(255,215,0,0.5);
  border-radius: 10px;
  padding: 12px 20px;
  text-align: center;
  white-space: nowrap;
  z-index: 100;
  box-shadow: 0 4px 20px rgba(0,0,0,0.6);
  animation: tooltip-pop 0.2s ease-out;
}

@keyframes tooltip-pop {
  from { opacity: 0; transform: translateY(-6px) scale(0.92); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

#highscore-tooltip::before {
  content: '';
  position: absolute;
  top: -7px;
  right: 11px;
  width: 12px;
  height: 12px;
  background: rgba(10,20,10,0.96);
  border-left: 1px solid rgba(255,215,0,0.5);
  border-top: 1px solid rgba(255,215,0,0.5);
  transform: rotate(45deg);
}

.hs-label {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 2px;
  opacity: 0.7;
  margin-bottom: 4px;
}

#highscore-value,
#reset-value {
  font-size: 1.5rem;
  font-weight: 800;
  color: #ffd700;
}

.hs-divider {
  border: none;
  border-top: 1px solid rgba(255,215,0,0.2);
  margin: 10px 0 8px;
}

.coin-icon {
  font-size: 1.3rem;
  animation: coin-spin 3s ease-in-out infinite;
  display: inline-block;
  filter: drop-shadow(0 0 4px rgba(255,215,0,0.6));
}

@keyframes coin-spin {
  0%, 100% { transform: rotateY(0deg); }
  40%       { transform: rotateY(0deg); }
  50%       { transform: rotateY(90deg); }
  60%       { transform: rotateY(0deg); }
}

/* Table */
main {
  background: #1a7a42;
  border-radius: 16px;
  border: 6px solid #8B6914;
  box-shadow:
    0 0 0 2px #c41e3a,
    0 8px 32px rgba(0,0,0,0.5),
    inset 0 1px 0 rgba(255,255,255,0.1);
  padding: 24px 20px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  position: relative;
  height: clamp(480px, 80vh, 760px);
}

.table-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex: 1;
}

.label {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 2px;
  opacity: 0.8;
  display: flex;
  align-items: center;
  gap: 8px;
}

.score {
  background: rgba(0,0,0,0.4);
  border-radius: 10px;
  padding: 2px 10px;
  font-size: 1rem;
  font-weight: bold;
  letter-spacing: 0;
}

/* Card row */
.card-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  min-height: 110px;
  align-items: center;
}

/* Cards */
.card {
  width: 72px;
  height: 104px;
  border-radius: 8px;
  background: #fff;
  color: #111;
  border: 1px solid #ccc;
  box-shadow: 2px 4px 10px rgba(0,0,0,0.4);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 5px 6px;
  font-size: 1rem;
  font-weight: bold;
  position: relative;
  animation: deal 0.35s cubic-bezier(0.34, 1.4, 0.64, 1) both;
  flex-shrink: 0;
}

@keyframes deal {
  from { opacity: 0; transform: translateY(-50px) scale(0.75) rotate(-6deg); }
  to   { opacity: 1; transform: translateY(0) scale(1) rotate(0deg); }
}

@keyframes card-sweep {
  to { transform: translateX(120%) rotate(12deg); opacity: 0; }
}

.card.red { color: #c0392b; }

.card-top { align-self: flex-start; line-height: 1; }
.card-bot { align-self: flex-end; transform: rotate(180deg); line-height: 1; }

.card-suit {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 1.8rem;
  opacity: 0.15;
}

.card.face-down {
  background: repeating-linear-gradient(
    45deg,
    #1a3e6b,
    #1a3e6b 6px,
    #1e4f8a 6px,
    #1e4f8a 12px
  );
  border: 1px solid #163060;
  color: transparent;
}

.card.face-down .card-top,
.card.face-down .card-bot,
.card.face-down .card-suit {
  display: none;
}

.card.face-down::after {
  content: '🂠';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 2.5rem;
  opacity: 0.3;
}

/* Message */
#message {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0,0,0,0.85);
  border: 2px solid #ffd700;
  border-radius: 14px;
  padding: 18px 36px;
  font-size: 1.6rem;
  font-weight: bold;
  text-align: center;
  white-space: nowrap;
  z-index: 10;
  box-shadow: 0 4px 24px rgba(0,0,0,0.6);
  animation: pop 0.3s ease-out;
}

@keyframes pop {
  from { opacity: 0; transform: translate(-50%, -50%) scale(0.8); }
  to   { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

#message.win  { border-color: #2ecc71; color: #2ecc71; }
#message.lose { border-color: #e74c3c; color: #e74c3c; }
#message.push { border-color: #f39c12; color: #f39c12; }
#message.blackjack { border-color: #ffd700; color: #ffd700; }

.hidden { display: none !important; }

/* Panels */
#betting-panel,
#game-panel,
#next-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  background: rgba(0,0,0,0.3);
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.1);
  margin-top: auto;
}

/* Chips */
#chips {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

.chip {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: none;
  color: #fff;
  font-weight: 800;
  font-size: 0.8rem;
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.12s;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  text-shadow: 0 1px 2px rgba(0,0,0,0.5);
}

/* Outer ring */
.chip::before {
  content: '';
  position: absolute;
  inset: 4px;
  border-radius: 50%;
  border: 2px dashed rgba(255,255,255,0.45);
  pointer-events: none;
}

/* Inner highlight */
.chip::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 28%, rgba(255,255,255,0.25) 0%, transparent 60%);
  pointer-events: none;
}

/* Per-denomination colours */
.chip[data-amount="5"] {
  background: radial-gradient(circle at 35% 35%, #e84a4a, #b80a0a);
  box-shadow: 0 4px 10px rgba(184,10,10,0.55), 0 2px 4px rgba(0,0,0,0.4);
}
.chip[data-amount="10"] {
  background: radial-gradient(circle at 35% 35%, #4a8ae8, #0a47b8);
  box-shadow: 0 4px 10px rgba(10,71,184,0.55), 0 2px 4px rgba(0,0,0,0.4);
}
.chip[data-amount="25"] {
  background: radial-gradient(circle at 35% 35%, #4ac84a, #0a8a0a);
  box-shadow: 0 4px 10px rgba(10,138,10,0.55), 0 2px 4px rgba(0,0,0,0.4);
}
.chip[data-amount="50"] {
  background: radial-gradient(circle at 35% 35%, #555, #1a1a1a);
  box-shadow: 0 4px 10px rgba(0,0,0,0.7), 0 2px 4px rgba(0,0,0,0.4);
}
.chip[data-amount="100"] {
  background: radial-gradient(circle at 35% 35%, #a04ae8, #6200b8);
  box-shadow: 0 4px 10px rgba(98,0,184,0.55), 0 2px 4px rgba(0,0,0,0.4);
}
.chip[data-amount="250"] {
  background: radial-gradient(circle at 35% 35%, #f5a623, #c47a00);
  box-shadow: 0 4px 10px rgba(196,122,0,0.6), 0 2px 4px rgba(0,0,0,0.4);
}

.chip:hover {
  transform: scale(1.12) translateY(-3px);
}
.chip[data-amount="5"]:hover   { box-shadow: 0 8px 20px rgba(184,10,10,0.7); }
.chip[data-amount="10"]:hover  { box-shadow: 0 8px 20px rgba(10,71,184,0.7); }
.chip[data-amount="25"]:hover  { box-shadow: 0 8px 20px rgba(10,138,10,0.7); }
.chip[data-amount="50"]:hover  { box-shadow: 0 8px 20px rgba(0,0,0,0.85); }
.chip[data-amount="100"]:hover { box-shadow: 0 8px 20px rgba(98,0,184,0.7); }
.chip[data-amount="250"]:hover { box-shadow: 0 8px 20px rgba(196,122,0,0.8); }

.chip:active { transform: scale(0.96); }

#bet-display,
#active-bet-display {
  font-size: 1.15rem;
  color: #ffd700;
  font-weight: bold;
}

/* Buttons */
#betting-actions,
#game-actions {
  display: flex;
  gap: 10px;
}

button {
  padding: 10px 22px;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-weight: bold;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s, opacity 0.15s;
}

button:active { transform: scale(0.97); }
button:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

#btn-deal {
  background: #27ae60;
  color: #fff;
}
#btn-deal:not(:disabled):hover { background: #219a52; }

#btn-clear-bet {
  background: #7f8c8d;
  color: #fff;
}
#btn-clear-bet:hover { background: #6c7a7b; }

#btn-hit {
  background: #2980b9;
  color: #fff;
}
#btn-hit:hover { background: #2471a3; }

#btn-stand {
  background: #c0392b;
  color: #fff;
}
#btn-stand:hover { background: #a93226; }

#btn-double {
  background: #8e44ad;
  color: #fff;
}
#btn-double:hover { background: #7d3c98; }

#btn-next {
  background: #f39c12;
  color: #fff;
  padding: 12px 40px;
  font-size: 1.1rem;
}
#btn-next:hover { background: #d68910; }

#btn-next.game-over {
  background: linear-gradient(135deg, #c0392b, #e74c3c);
  animation: pulse-red 1.4s ease-in-out infinite;
}
#btn-next.game-over:hover { background: linear-gradient(135deg, #a93226, #c0392b); }

@keyframes pulse-red {
  0%, 100% { box-shadow: 0 0 0 0 rgba(231,76,60,0.5); }
  50%       { box-shadow: 0 0 0 10px rgba(231,76,60,0); }
}


/* Divider between dealer/player */
.table-divider {
  border: none;
  border-top: 1px solid rgba(255,255,255,0.15);
  margin: 4px 0;
}

/* History overlay */
#history-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 200;
  backdrop-filter: blur(2px);
}

/* History sidebar */
#history-sidebar {
  position: fixed;
  left: 0;
  top: 0;
  height: 100vh;
  width: 300px;
  max-width: 90vw;
  background: linear-gradient(180deg, #0d2a18 0%, #081a0f 100%);
  border-right: 1px solid rgba(255,215,0,0.3);
  z-index: 201;
  transform: translateX(-100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
  box-shadow: 6px 0 32px rgba(0,0,0,0.7);
}

#history-sidebar.open {
  transform: translateX(0);
}

#history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 20px;
  border-bottom: 1px solid rgba(255,215,0,0.2);
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 1px;
  color: #ffd700;
  flex-shrink: 0;
}

#btn-close-menu {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.3);
  background: rgba(255,255,255,0.08);
  color: #fff;
  font-size: 0.85rem;
  cursor: pointer;
  padding: 0;
  line-height: 1;
  transition: background 0.15s;
}

#btn-close-menu:hover {
  background: rgba(255,255,255,0.2);
  transform: none;
}

#history-summary {
  padding: 12px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  flex-shrink: 0;
}

.history-summary-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.82rem;
  opacity: 0.75;
  margin-bottom: 6px;
}

.history-net {
  font-size: 1.3rem;
  font-weight: 800;
  text-align: center;
  letter-spacing: 1px;
}

.history-net.pos     { color: #2ecc71; }
.history-net.neg     { color: #e74c3c; }
.history-net.neutral { color: #f39c12; }

#history-list {
  flex: 1;
  overflow-y: auto;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#history-list::-webkit-scrollbar { width: 4px; }
#history-list::-webkit-scrollbar-track { background: transparent; }
#history-list::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 2px; }

.history-empty {
  text-align: center;
  opacity: 0.45;
  font-size: 0.88rem;
  padding: 40px 20px;
}

.history-entry {
  border-radius: 10px;
  padding: 10px 12px;
  border: 1px solid rgba(255,255,255,0.1);
  background: rgba(255,255,255,0.04);
}

.history-entry.win       { border-color: rgba(46,204,113,0.45);  background: rgba(46,204,113,0.08); }
.history-entry.lose      { border-color: rgba(231,76,60,0.45);   background: rgba(231,76,60,0.08); }
.history-entry.push      { border-color: rgba(243,156,18,0.45);  background: rgba(243,156,18,0.08); }
.history-entry.blackjack { border-color: rgba(255,215,0,0.55);   background: rgba(255,215,0,0.1); }

.history-entry-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 5px;
}

.history-round-num {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  opacity: 0.5;
}

.history-bet-info {
  font-size: 0.75rem;
  opacity: 0.55;
}

.history-entry-bottom {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.history-result-text {
  font-weight: 700;
  font-size: 0.9rem;
}

.history-entry.win .history-result-text       { color: #2ecc71; }
.history-entry.lose .history-result-text      { color: #e74c3c; }
.history-entry.push .history-result-text      { color: #f39c12; }
.history-entry.blackjack .history-result-text { color: #ffd700; }

.history-balances {
  font-size: 0.78rem;
  opacity: 0.65;
  white-space: nowrap;
}

/* ===========================
   RESPONSIVE: Tablet (≤640px)
   =========================== */
@media (max-width: 640px) {
  header h1 {
    font-size: 1.4rem;
    letter-spacing: 2px;
  }

  .card {
    width: 64px;
    height: 92px;
    font-size: 0.9rem;
  }

  .card-suit { font-size: 1.5rem; }

  .chip {
    width: 58px;
    height: 58px;
  }

  #chips { gap: 8px; }

  main { padding: 18px 16px 16px; }
}

/* ===========================
   RESPONSIVE: Mobile (≤480px)
   =========================== */
@media (max-width: 480px) {
  body {
    align-items: flex-start;
    padding: 12px 0 16px;
  }

  #app {
    padding: 12px;
    gap: 12px;
  }

  header {
    padding: 10px 14px;
  }

  header h1 {
    position: static;
    transform: none;
    flex: 1;
    text-align: center;
    font-size: 1.1rem;
    letter-spacing: 1px;
  }

  .coin-icon { display: none; }

  #balance-display {
    font-size: 0.9rem;
    padding: 5px 10px;
  }

  #btn-menu {
    width: 32px;
    height: 32px;
    font-size: 1.05rem;
  }

  main {
    padding: 14px 12px 12px;
    border-width: 4px;
    gap: 8px;
    height: clamp(440px, 80vh, 760px);
  }

  .card-row {
    gap: 6px;
    min-height: 82px;
  }

  .card {
    width: 56px;
    height: 80px;
    font-size: 0.8rem;
    padding: 4px 5px;
  }

  .card-suit { font-size: 1.3rem; }

  .card.face-down::after { font-size: 1.9rem; }

  .chip {
    width: 52px;
    height: 52px;
    font-size: 0.72rem;
  }

  #chips {
    display: grid;
    grid-template-columns: repeat(3, 52px);
    gap: 8px;
  }

  #betting-panel,
  #game-panel,
  #next-panel {
    padding: 12px 14px;
    gap: 10px;
  }

  #betting-actions,
  #game-actions {
    gap: 8px;
    flex-wrap: wrap;
    justify-content: center;
  }

  button {
    padding: 9px 16px;
    font-size: 0.9rem;
  }

  #btn-next {
    padding: 10px 28px;
    font-size: 1rem;
  }

  #message {
    font-size: 1.2rem;
    padding: 14px 22px;
    white-space: normal;
    max-width: 85%;
    text-align: center;
  }
}

/* ===========================
   RESPONSIVE: Small (≤360px)
   =========================== */
@media (max-width: 360px) {
  #app { padding: 10px; }

  header h1 {
    font-size: 1rem;
    letter-spacing: 0;
  }

  #balance-display {
    font-size: 0.82rem;
    padding: 4px 8px;
  }

  main {
    height: clamp(420px, 80vh, 760px);
    padding: 12px 10px 10px;
  }

  .card {
    width: 50px;
    height: 72px;
    font-size: 0.75rem;
    padding: 3px 4px;
  }

  .card-suit { font-size: 1.1rem; }

  .card-row { min-height: 74px; }

  .chip {
    width: 46px;
    height: 46px;
    font-size: 0.68rem;
  }

  #chips {
    grid-template-columns: repeat(3, 46px);
    gap: 6px;
  }

  button {
    padding: 8px 13px;
    font-size: 0.85rem;
  }

  #btn-double { font-size: 0.8rem; }

  #bet-display,
  #active-bet-display { font-size: 1rem; }
}
