:root{
  --chat-font: inherit;
  --chat-accent:#2dd36f;
  --chat-accent-ink:#0b0f12;
  --chat-panel-bg:rgba(0,0,0,.40);
  --chat-panel-border:rgba(255,255,255,.08);
  --chat-bubble:rgba(255,255,255,.06);
  --chat-bubble-ink:#fff;
  --chat-bubble-alt:rgba(255,215,0,.14);
  --chat-bubble-alt-bd:rgba(255,215,0,.34);
  --chat-mention:rgba(255,213,0,.25);
  --chat-scroll-thumb:rgba(255,255,255,.22);
  --chat-radius:10px;

  /* Dealer color is ONLY for chat (table label stays white via client.js) */
  --dealer-color:#ffd54a;
}

/* Desktop left sidebar; stacked on mobile */
@media (min-width:769px){
  #chat-panel{
    position: fixed; top: 0; left: 0; bottom: 0;
    width: 300px; max-width: 32vw;
    display: flex; flex-direction: column;
    background: var(--chat-panel-bg);
    border-right: 1px solid var(--chat-panel-border);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 100;
    overflow: hidden;
  }
  #game-container{ margin-left: 300px; }
}
@media (min-width:1200px){
  #chat-panel{ width: 340px; }
  #game-container{ margin-left: 340px; }
}
@media (max-width:768px){
  #chat-panel{ position: static; width: 100%; height: auto; z-index: auto; }
  #game-container{ margin-left: 0; }
}

/* Message list + scrollbar */
#chat-messages{
  flex: 1 1 auto;
  padding: 10px 10px 14px;
  overflow-y: auto;
  font-family: var(--chat-font);
  color: inherit;
  scrollbar-width: thin;
  scrollbar-color: var(--chat-scroll-thumb) transparent;
}
#chat-messages::-webkit-scrollbar{ width: 8px; }
#chat-messages::-webkit-scrollbar-thumb{
  background: var(--chat-scroll-thumb); border-radius: 8px;
}

/* Bubbles */
.chat-line{
  display: flex; gap: 8px; align-items: flex-end;
  margin: 6px 0; padding: 0 4px;
  font-family: var(--chat-font);
  color: inherit;
}
.chat-line .who{
  font-weight: 600; opacity: .8; font-size: 12px;
  min-width: max-content; color: inherit;
}
.chat-line .what{
  display: inline-block; max-width: 85%;
  background: var(--chat-bubble);
  border: 1px solid var(--chat-panel-border);
  padding: 8px 10px; border-radius: var(--chat-radius);
  line-height: 1.25; color: var(--chat-bubble-ink);
  word-wrap: break-word; overflow-wrap: anywhere;
}
.chat-line .when{
  opacity: .6; font-size: 11px; min-width: max-content; margin-left: 4px;
  color: inherit;
}

/* Your messages */
.chat-line.mine{ justify-content: flex-end; }
.chat-line.mine .who{ display: none; }
.chat-line.mine .what{
  background: var(--chat-accent); color: var(--chat-accent-ink);
  border-color: transparent; border-radius: var(--chat-radius);
  box-shadow: 0 4px 16px rgba(0,0,0,.18);
}

/* Dealer messages — ONLY chat name/bubble highlighted */
.chat-line.dealer .who{
  color: var(--dealer-color);
  opacity: .98;
  font-weight: 800;
  letter-spacing: .02em;
}
.chat-line.dealer .what{
  background: var(--chat-bubble-alt);
  border-color: var(--chat-bubble-alt-bd);
  color: #fff;
}

/* Mentions */
.chat-line mark.mention{
  background: var(--chat-mention); padding: 0 2px; border-radius: 3px;
  color: #111;
}

/* Input row */
#chat-form{
  display: flex; gap: 8px; padding: 10px;
  border-top: 1px solid var(--chat-panel-border);
  background: rgba(0,0,0,.08);
  font-family: var(--chat-font);
}
#chat-input{
  flex: 1 1 auto; min-width: 0;
  background: rgba(255,255,255,.06);
  border: 1px solid var(--chat-panel-border);
  color: inherit;
  border-radius: var(--chat-radius);
  padding: 10px 12px; outline: none;
}
#chat-input::placeholder{ color: rgba(255,255,255,.55); }
#chat-form button[type="submit"]{
  background: var(--chat-accent); color: var(--chat-accent-ink);
  border: 0; border-radius: var(--chat-radius);
  padding: 10px 14px; font-weight: 700; cursor: pointer;
}
#chat-form button[type="submit"]:hover{ filter: brightness(1.05); }
#chat-form button[type="submit"]:active{ transform: translateY(1px); }

/* Chat panel */
#chat-panel{
  position: fixed; top: 0; left: 0; bottom: 0;
  width: 300px; background: var(--chat-bg);
  border-right: 1px solid var(--chat-panel-border);
  display: flex; flex-direction: column;
  z-index: 100; font-family: var(--chat-font);
  color: var(--chat-ink);
  overflow: hidden;
}

/* Chat header with close button */
.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 15px 10px;
  border-bottom: 1px solid var(--chat-panel-border);
  background: rgba(0,0,0,0.1);
}

.chat-header h3 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: bold;
  color: var(--chat-ink);
}

.chat-close-btn {
  background: none;
  border: none;
  color: var(--chat-ink);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 5px;
  border-radius: 4px;
  transition: background-color 0.2s;
}

.chat-close-btn:hover {
  background: rgba(255,255,255,0.1);
}

/* Mobile chat close button */
@media (max-width: 700px) {
  .chat-close-btn {
    font-size: 1.4rem;
    padding: 8px;
    min-width: 40px;
    min-height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
  }
}
