:root {
  --felt: #1fa855;
  --felt-dark: #0f7a3d;
  --accent: #d4af37;
  --panel-bg: #14181c;
  --panel-bg-2: #1c2228;
  --border: #333c44;
  --text: #f2f2f0;
  --text-dim: #9aa4ac;
  --good: #4caf7d;
  --bad: #d05a5a;

  --table-max-width: 900px;
  --portrait-size: 64px;
  --portrait-size-hero: 90px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  background: #05070a;
  color: var(--text);
  font-family: 'Segoe UI', Tahoma, sans-serif;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

#top-bar {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 10px 20px;
  background: var(--panel-bg);
  border-bottom: 1px solid var(--border);
}
#top-bar h1 {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 1.2rem;
  margin: 0;
  white-space: nowrap;
}

#top-bar-right { grid-column: 3; justify-self: end; position: relative; }
#btn-settings {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
#btn-settings:hover { border-color: var(--accent); color: var(--text); }

#settings-panel {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 200px;
  padding: 14px 16px;
  background: var(--panel-bg-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
  z-index: 50;
}
#settings-panel[hidden] { display: none; }
.settings-row { display: flex; flex-direction: column; gap: 6px; }
.settings-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
}
#volume-slider { width: 100%; accent-color: var(--accent); }

#main-area {
  flex: 1;
  display: flex;
  min-height: 0;
}

#table-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  min-width: 0;
  background:
    linear-gradient(rgba(8,10,14,0.25), rgba(8,10,14,0.25)),
    url('../assets/bg.png?v=2') center / cover no-repeat;
}

#table {
  position: relative;
  width: 100%;
  max-width: var(--table-max-width);
  max-height: 88%;
  aspect-ratio: 16 / 11;
  background: radial-gradient(ellipse at center, var(--felt) 0%, var(--felt-dark) 100%);
  border: 12px solid #3a2415;
  border-radius: 50% / 45%;
  box-shadow: inset 0 0 40px rgba(0,0,0,0.25), 0 10px 30px rgba(0,0,0,0.6);
}

#table-banner {
  position: absolute;
  top: 55%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 15;
  color: #29c5ff;
  -webkit-text-stroke: 2px #ff36b3;
  paint-order: stroke fill;
  font-size: 1.5rem;
  font-weight: 800;
  text-align: center;
  max-width: 90%;
  animation: banner-pulse 1.3s ease-in-out infinite;
}
@keyframes banner-pulse {
  0%, 100% {
    transform: translate(-50%, -50%) scale(1);
    text-shadow: 0 0 10px rgba(255,54,179,0.6), 0 0 3px rgba(255,54,179,0.9);
  }
  50% {
    transform: translate(-50%, -50%) scale(1.07);
    text-shadow: 0 0 26px rgba(255,54,179,1), 0 0 10px rgba(255,54,179,1);
  }
}

.seat {
  position: absolute;
  transform: translate(-50%, -50%);
  width: 150px;
}
#dealer-seat { left: 50%; top: 12%; }
.seat[data-seat="1"] { left: 13%; top: 20%; }
.seat[data-seat="2"] { left: 87%; top: 20%; }
.seat[data-seat="3"] { left: 13%; top: 80%; }
.seat[data-seat="4"] { left: 87%; top: 80%; }
.seat[data-seat="0"] { left: 50%; top: 92%; width: 190px; }

.seat-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: rgba(10, 14, 10, 0.55);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px;
}
.seat[data-seat="0"] .seat-box { border-color: var(--accent); }

.seat-header {
  display: flex;
  gap: 8px;
  align-items: baseline;
  font-size: 0.78rem;
}
.seat-name { font-weight: 700; color: var(--accent); }
.seat-stack { color: var(--text-dim); }

.seat-face-wrap {
  width: var(--portrait-size);
  height: var(--portrait-size);
  border-radius: 50%;
  overflow: hidden;
  border: 2px solid var(--border);
}
.seat[data-seat="0"] .seat-face-wrap,
#dealer-seat .seat-face-wrap {
  width: var(--portrait-size-hero);
  height: var(--portrait-size-hero);
}
.seat-face { width: 100%; height: 100%; object-fit: cover; object-position: 50% 15%; }
.seat-face-placeholder {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  background: var(--panel-bg-2);
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--accent);
}

.seat-hands { display: flex; gap: 6px; min-height: 20px; }

.bj-hand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.bj-hand-cards { display: flex; gap: -6px; }
.bj-hand-total {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text);
  background: rgba(0,0,0,0.4);
  padding: 1px 6px;
  border-radius: 6px;
}
.bj-hand-bet { font-size: 0.68rem; color: var(--accent); }
.bj-hand.result-win .bj-hand-total { color: var(--good); }
.bj-hand.result-winbj .bj-hand-total { color: var(--good); }
.bj-hand.result-lose .bj-hand-total { color: var(--bad); }

.card {
  width: 34px;
  height: 48px;
  background: #f5f5f0;
  border-radius: 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(0,0,0,0.4);
  margin-left: -8px;
}
.card:first-child { margin-left: 0; }
.card .rank { font-size: 0.85rem; font-weight: 700; line-height: 1; }
.card .suit { font-size: 0.9rem; line-height: 1; }
.card.red { color: #b02020; }
.card.black { color: #111; }
.card.back {
  background: repeating-linear-gradient(45deg, #1a3a6e, #1a3a6e 4px, #2a4c86 4px, #2a4c86 8px);
  border: 1px solid #0c2040;
}

#bust-overlay {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
  animation: bust-pop 0.25s ease-out;
}
#bust-overlay[hidden] { display: none; }
@keyframes bust-pop {
  from { opacity: 0; transform: translate(-50%, -50%) scale(0.85); }
  to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}
#bust-portrait {
  width: 200px;
  height: 194px;
  display: flex;
  align-items: center;
  justify-content: center;
  filter: drop-shadow(0 6px 16px rgba(0,0,0,0.7));
}
#bust-portrait img { max-width: 100%; max-height: 100%; object-fit: contain; }
#bust-portrait .bust-placeholder {
  width: 170px; height: 170px;
  border-radius: 50%;
  background: var(--panel-bg-2);
  border: 3px solid var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: 4rem; font-weight: 700; color: var(--accent);
}
#bust-text { font-size: 1.3rem; font-weight: 800; color: var(--bad); }

#side-panel {
  width: 280px;
  flex-shrink: 0;
  background: var(--panel-bg);
  border-left: 1px solid var(--border);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
}
.panel-view[hidden] { display: none; }
.panel-view h2 { margin: 0 0 4px; font-size: 1.1rem; color: var(--accent); }
.panel-view p, .panel-view div#idle-copy { color: var(--text-dim); font-size: 0.85rem; line-height: 1.4; }

.primary-btn, .secondary-btn {
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
}
.primary-btn { background: var(--accent); color: #1a1200; }
.primary-btn:hover { filter: brightness(1.1); }
.secondary-btn { background: var(--panel-bg-2); color: var(--text); border: 1px solid var(--border); }
.secondary-btn:hover { border-color: var(--accent); }

#bet-input {
  width: 100%;
  padding: 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--panel-bg-2);
  color: var(--text);
  font-size: 1rem;
}
#bet-presets { display: flex; gap: 6px; flex-wrap: wrap; }
#bet-stack-note { color: var(--text-dim); font-size: 0.85rem; }

#action-choices { display: flex; gap: 8px; flex-wrap: wrap; }

#result-body { display: flex; flex-direction: column; gap: 4px; font-size: 0.88rem; }
.win-line { padding: 2px 0; }

#log-panel {
  height: 130px;
  flex-shrink: 0;
  background: var(--panel-bg);
  border-top: 1px solid var(--border);
  padding: 8px 16px;
  display: flex;
  flex-direction: column;
}
#log-title { font-weight: 700; color: var(--accent); font-size: 0.85rem; margin-bottom: 4px; }
#log-entries {
  flex: 1;
  overflow-y: auto;
  font-size: 0.82rem;
  color: var(--text-dim);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

@media (max-width: 880px) {
  html, body { height: auto; min-height: 100%; }
  #app { height: auto; min-height: 100vh; }
  #main-area { flex-direction: column; }
  #table-wrap { flex: none; padding: 12px 8px 4px; }
  #table { max-width: 340px; aspect-ratio: 3 / 4; max-height: none; }
  #settings-panel { min-width: 180px; }

  :root { --portrait-size: 30px; --portrait-size-hero: 42px; }
  .seat { width: 78px; }
  .seat[data-seat="0"] { width: 92px; }
  .seat-box { padding: 4px; gap: 2px; }
  .seat-header { font-size: 0.6rem; gap: 4px; }
  .bj-hand-total { font-size: 0.62rem; padding: 0 3px; }
  .bj-hand-bet { font-size: 0.55rem; }
  .seat-hands { gap: 3px; }

  .card { width: 19px; height: 27px; margin-left: -5px; border-radius: 2px; }
  .card .rank { font-size: 0.5rem; }
  .card .suit { font-size: 0.56rem; }

  #dealer-seat { top: 10%; }
  .seat[data-seat="1"] { left: 12%; top: 15%; }
  .seat[data-seat="2"] { left: 88%; top: 15%; }
  .seat[data-seat="3"] { left: 12%; top: 72%; }
  .seat[data-seat="4"] { left: 88%; top: 72%; }
  .seat[data-seat="0"] { left: 50%; top: 90%; }

  #table-banner { font-size: 1rem; }
  #side-panel { width: auto; }
}
