/* ── Reset & tokens ──────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --felt:       #0e5c30;
  --felt-deep:  #083d20;
  --felt-hi:    #126b38;
  --gold:       #c9a84c;
  --gold-dim:   #8a6f2e;
  --card-w:     76px;
  --card-h:     106px;
  --card-r:     7px;
  --red:        #c0392b;
  --black:      #1a1a2e;
  --back-blue:  #1c3d8a;
  --ui-bg:      rgba(0, 0, 0, 0.45);
  --border:     rgba(255, 255, 255, 0.09);
  --text:       #f0e6d3;
  --text-dim:   rgba(240, 230, 211, 0.45);

  /* count colours */
  --c-vpos:  #00ff88;
  --c-pos:   #5dde7a;
  --c-neu:   #f0c040;
  --c-neg:   #f07050;
  --c-vneg:  #ff3333;
}

/* ── Base ───────────────────────────────────────────────────────── */
html, body {
  height: 100%;
  overflow: hidden;
}

body {
  background: var(--felt-deep);
  color: var(--text);
  font-family: 'Georgia', 'Times New Roman', serif;
  display: flex;
  justify-content: center;
  align-items: stretch;
}

#app {
  width: 100%;
  max-width: 860px;
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* ── Stats bar ──────────────────────────────────────────────────── */
#stats-bar {
  display: flex;
  align-items: center;
  justify-content: space-around;
  gap: 8px;
  padding: 10px 16px;
  background: var(--ui-bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.stat {
  text-align: center;
  min-width: 60px;
}

.stat-label {
  display: block;
  font-size: 9px;
  font-family: 'Courier New', monospace;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--text-dim);
  margin-bottom: 2px;
}

.stat-value {
  font-size: 17px;
  font-weight: bold;
  font-family: 'Courier New', monospace;
  transition: color 0.3s;
}

/* Count colour classes */
.stat-value.vpos  { color: var(--c-vpos); text-shadow: 0 0 8px var(--c-vpos); }
.stat-value.pos   { color: var(--c-pos); }
.stat-value.neutral { color: var(--c-neu); }
.stat-value.neg   { color: var(--c-neg); }
.stat-value.vneg  { color: var(--c-vneg); text-shadow: 0 0 8px var(--c-vneg); }

.icon-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 50%;
  width: 28px;
  height: 28px;
  cursor: pointer;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.2s, color 0.2s;
  flex-shrink: 0;
}
.icon-btn:hover { border-color: var(--gold); color: var(--gold); }

#stats-bar.hide-count #rc-stat,
#stats-bar.hide-count #tc-stat { visibility: hidden; }

/* ── Table ──────────────────────────────────────────────────────── */
#table {
  flex: 1;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  overflow: hidden;
  background:
    radial-gradient(ellipse 80% 70% at 50% 40%, var(--felt-hi) 0%, var(--felt) 55%, var(--felt-deep) 100%);
}

/* felt texture */
#table::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='6' height='6'%3E%3Ccircle cx='1.5' cy='1.5' r='0.7' fill='rgba(255,255,255,0.025)'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 0;
}

#table > * { position: relative; z-index: 1; }

/* ── Deck pile ──────────────────────────────────────────────────── */
#deck-area {
  position: absolute;
  top: 14px;
  right: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  z-index: 2;
}

#deck-pile {
  position: relative;
  width: var(--card-w);
  height: var(--card-h);
}

.deck-layer {
  position: absolute;
  width: var(--card-w);
  height: var(--card-h);
  border-radius: var(--card-r);
  background: var(--back-blue);
  border: 1px solid rgba(255,255,255,0.13);
  box-shadow: inset 0 0 0 3px rgba(255,255,255,0.04);
}

#pen-bar {
  width: 56px;
  height: 3px;
  background: rgba(255,255,255,0.15);
  border-radius: 2px;
  overflow: hidden;
}

#pen-fill {
  height: 100%;
  background: var(--gold);
  border-radius: 2px;
  transition: width 0.6s ease;
  width: 0%;
}

#deck-label {
  font-size: 9px;
  font-family: 'Courier New', monospace;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-dim);
}

/* ── Dealer / Player sections ───────────────────────────────────── */
#dealer-section, #player-section {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.zone-label {
  font-size: 10px;
  font-family: 'Courier New', monospace;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--text-dim);
}

.card-row {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  justify-content: center;
  align-items: flex-end;
  min-height: var(--card-h);
}

.score-display {
  font-size: 13px;
  font-family: 'Courier New', monospace;
  color: rgba(255,255,255,0.75);
  min-height: 18px;
  text-align: center;
}

/* ── Player hands ───────────────────────────────────────────────── */
#player-hands {
  display: flex;
  gap: 20px;
  justify-content: center;
  flex-wrap: wrap;
}

.hand-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  transition: opacity 0.2s;
}

.hand-wrapper.inactive { opacity: 0.45; }

.hand-score {
  font-size: 13px;
  font-family: 'Courier New', monospace;
  color: rgba(255,255,255,0.75);
  min-height: 18px;
}

.hand-score.bust { color: #ff5555; }
.hand-score.bj   { color: var(--gold); }

.active-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--gold);
  animation: blink 1.1s infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.2; }
}

/* ── Message zone ───────────────────────────────────────────────── */
#message-zone {
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#message {
  font-size: 18px;
  font-weight: bold;
  letter-spacing: 0.5px;
  text-align: center;
  text-shadow: 0 2px 6px rgba(0,0,0,0.6);
  transition: opacity 0.4s;
}

#message.win  { color: var(--gold); }
#message.push { color: #9999ff; }
#message.lose { color: #ff6666; }

/* ── CARDS ──────────────────────────────────────────────────────── */
.card {
  width: var(--card-w);
  height: var(--card-h);
  perspective: 700px;
  flex-shrink: 0;
  cursor: default;
}

.card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.42s cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: var(--card-r);
}

/* flip to face-up */
.card.face-up .card-inner {
  transform: rotateY(180deg);
}

.card-back, .card-face {
  position: absolute;
  inset: 0;
  border-radius: var(--card-r);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  box-shadow: 0 5px 14px rgba(0,0,0,0.5), inset 0 0 0 1px rgba(255,255,255,0.08);
}

/* ── Card back ── */
.card-back {
  background-color: var(--back-blue);
  background-image:
    repeating-linear-gradient( 45deg, transparent, transparent 9px, rgba(255,255,255,0.04) 9px, rgba(255,255,255,0.04) 10px),
    repeating-linear-gradient(-45deg, transparent, transparent 9px, rgba(255,255,255,0.04) 9px, rgba(255,255,255,0.04) 10px);
  overflow: hidden;
}

.card-back::before {
  content: '';
  position: absolute;
  inset: 5px;
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 3px;
}

.card-back::after {
  content: '♠';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 28px;
  color: rgba(255,255,255,0.08);
  pointer-events: none;
}

/* ── Card face ── */
.card-face {
  background: #fff;
  transform: rotateY(180deg);
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding: 5px;
  overflow: hidden;
}

.card-face.red   { color: var(--red); }
.card-face.black { color: var(--black); }

.corner {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.1;
}

.corner.br {
  align-self: end;
  justify-self: end;
  transform: rotate(180deg);
}

.c-rank {
  font-size: 14px;
  font-weight: bold;
  font-family: 'Georgia', serif;
}

.c-suit {
  font-size: 9px;
}

.center-suit {
  font-size: 34px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Deal animation ─────────────────────────────────────────────── */
@keyframes deal-in {
  from {
    opacity: 0;
    transform: translateY(-32px) scale(0.82) rotate(-4deg);
  }
  to {
    opacity: 1;
    transform: translateY(0)    scale(1)    rotate(0deg);
  }
}

.card.dealing {
  animation: deal-in 0.28s ease-out forwards;
}

/* ── Controls ───────────────────────────────────────────────────── */
#controls {
  flex-shrink: 0;
  background: var(--ui-bg);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px 20px;
  min-height: 86px;
}

/* Bet UI */
#bet-ui {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

#chip-tray {
  display: flex;
  gap: 10px;
}

.chip {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 3px dashed rgba(255, 255, 255, 0.55);
  font-weight: bold;
  font-size: 12px;
  font-family: 'Courier New', monospace;
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.12s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chip:hover  { transform: translateY(-3px); box-shadow: 0 7px 14px rgba(0,0,0,0.4); }
.chip:active { transform: translateY(0); }

.c5   { background: #b83030; color: #fff; }
.c25  { background: #2255aa; color: #fff; }
.c50  { background: #238844; color: #fff; }
.c100 { background: #1a1a1a; color: var(--gold); border-color: var(--gold-dim); }

#bet-btns {
  display: flex;
  gap: 8px;
}

/* Action UI */
#action-ui {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
}

/* Buttons */
button {
  padding: 10px 22px;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  font-size: 13px;
  font-weight: bold;
  font-family: 'Courier New', monospace;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  transition: transform 0.1s, opacity 0.15s, background 0.15s;
}

button:not(:disabled):hover  { transform: translateY(-1px); }
button:not(:disabled):active { transform: translateY(0); }
button:disabled { opacity: 0.35; cursor: not-allowed; transform: none !important; }

#btn-clear  { background: #555; color: var(--text); }
#btn-deal   { background: var(--gold); color: #111; }
#btn-hit    { background: #2e9e55; color: #fff; }
#btn-stand  { background: #b83030; color: #fff; }
#btn-double { background: #2255cc; color: #fff; }
#btn-split  { background: #aa5500; color: #fff; }

.hint-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 50%;
  width: 32px;
  height: 32px;
  padding: 0;
  font-size: 15px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.2s, color 0.2s;
}
.hint-btn:hover { border-color: var(--gold); color: var(--gold); transform: none; }

/* ── Hint popup ─────────────────────────────────────────────────── */
#hint-popup {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(10, 10, 30, 0.94);
  border: 1px solid var(--gold-dim);
  border-radius: 8px;
  padding: 10px 18px;
  color: var(--gold);
  font-size: 13px;
  font-family: 'Courier New', monospace;
  letter-spacing: 0.5px;
  pointer-events: none;
  z-index: 100;
  white-space: nowrap;
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
}

/* ── Responsive ─────────────────────────────────────────────────── */
@media (max-width: 480px) {
  :root {
    --card-w: 60px;
    --card-h: 84px;
  }
  .stat-value { font-size: 14px; }
  .center-suit { font-size: 26px; }
  .c-rank { font-size: 12px; }
}
