:root {
  --felt: #1b5e2a;
  --felt-dark: #123f1c;
  --gold: #d4af37;
  --wood: #3a2416;
  --wood-dark: #2a190e;
  --text: #f2ede0;
  --text-dim: #b8b09a;
  --red: #c0392b;
  --blue: #2471a3;
  --green: #27ae60;
}

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

html, body {
  height: 100%;
  font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: radial-gradient(circle at 50% 40%, var(--wood), var(--wood-dark) 70%);
  color: var(--text);
  overflow: hidden;
  overscroll-behavior: none;
}

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

.screen {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.hidden { display: none !important; }

/* ---------- Menu ---------- */
.menu-box {
  background: linear-gradient(145deg, var(--felt), var(--felt-dark));
  border: 6px solid var(--wood-dark);
  border-radius: 24px;
  padding: 36px 40px;
  width: min(92vw, 460px);
  max-height: 96dvh;
  overflow-y: auto;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6), inset 0 0 60px rgba(0,0,0,0.35);
}
.logo { font-size: 2.4rem; color: var(--gold); letter-spacing: 1px; }
.tagline { color: var(--text-dim); margin: 6px 0 24px; }

.menu-actions { display: flex; flex-direction: column; gap: 12px; }
.menu-actions input {
  padding: 12px 16px;
  font-size: 1.05rem;
  border-radius: 10px;
  border: 2px solid var(--gold);
  background: rgba(0,0,0,0.35);
  color: var(--text);
  text-align: center;
  outline: none;
}
.menu-actions input:focus { border-color: #ffe27a; }

.btn {
  padding: 13px 20px;
  font-size: 1.02rem;
  font-weight: 600;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  color: var(--text);
  background: #4a3a28;
  transition: transform .08s, filter .15s;
  box-shadow: 0 4px 10px rgba(0,0,0,0.4);
  white-space: nowrap;
}
.btn:hover:not(:disabled) { filter: brightness(1.15); transform: translateY(-1px); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary {
  background: linear-gradient(180deg, #d4af37, #b8860b);
  color: #241a02;
  font-size: 1.15rem;
  padding: 15px 20px;
}

.menu-divider { color: var(--text-dim); font-size: 0.9rem; margin: 4px 0; }
.join-row { display: flex; gap: 8px; }
.join-row input {
  flex: 1;
  text-transform: uppercase;
  letter-spacing: 3px;
  font-weight: 700;
}
.menu-error { color: #ff9d8a; min-height: 22px; margin-top: 12px; font-size: 0.95rem; }
.info-line { color: var(--text-dim); font-size: 0.85rem; margin-top: 16px; }

/* ---------- Game screen layout ---------- */
#game-screen {
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  padding: 8px;
  gap: 8px;
  padding-top: max(8px, env(safe-area-inset-top));
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  overflow: hidden;
}

.topbar {
  flex: 0 0 auto;
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 12px;
  background: rgba(0,0,0,0.4);
  border-radius: 12px;
}
.topbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.badge {
  background: var(--gold);
  color: #241a02;
  font-weight: 800;
  font-size: 0.78rem;
  padding: 4px 10px;
  border-radius: 20px;
  letter-spacing: 1px;
}
.room-label { color: var(--gold); font-weight: 700; letter-spacing: 2px; }
.room-label.clickable { cursor: pointer; text-decoration: underline dotted; }
.room-label.clickable:hover { filter: brightness(1.3); }
.hand-label { color: var(--text-dim); font-size: 0.82rem; }
.last-action { flex: 1; text-align: center; color: var(--text); font-size: 0.92rem; padding: 0 8px; min-width: 0; }
.topbar-right { display: flex; gap: 8px; flex: 0 0 auto; }
.icon-btn {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 1.05rem;
  cursor: pointer;
  color: var(--text);
}
.icon-btn:hover { background: rgba(255,255,255,0.18); }

/* ---------- Table (canvas fills the flexible middle area) ---------- */
.table-wrap {
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  position: relative;
}
#table-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.banner {
  position: absolute;
  top: 7%;
  left: 50%;
  transform: translate(-50%, 0);
  background: rgba(0,0,0,0.85);
  border: 2px solid var(--gold);
  color: var(--gold);
  font-size: clamp(0.9rem, 3vw, 1.35rem);
  font-weight: 700;
  padding: 10px 22px;
  border-radius: 14px;
  text-align: center;
  pointer-events: none;
  max-width: 90%;
  z-index: 5;
  box-shadow: 0 6px 24px rgba(0,0,0,0.5);
}

.banner.you-win {
  background: linear-gradient(135deg, rgba(20,90,45,0.96), rgba(8,45,22,0.96));
  border-color: #7dff9b;
  color: #eafff0;
  text-shadow: 0 0 12px rgba(125,255,155,0.85);
  box-shadow: 0 0 30px rgba(125,255,155,0.6);
  animation: winpop .5s ease-out, pulse 1.4s ease-in-out infinite;
}

@keyframes winpop {
  0% { transform: translate(-50%, 0) scale(0.55); opacity: 0; }
  100% { transform: translate(-50%, 0) scale(1); opacity: 1; }
}

/* Dealer on the table */
.dealer-badge {
  position: absolute;
  top: 5%;
  right: 4%;
  display: flex;
  flex-direction: column;
  align-items: center;
  background: rgba(0,0,0,0.6);
  border: 2px solid var(--gold);
  border-radius: 14px;
  padding: 8px 14px;
  text-align: center;
  pointer-events: none;
  z-index: 5;
  min-width: 86px;
}
.dealer-avatar { font-size: 1.6rem; line-height: 1; }
.dealer-name { color: var(--gold); font-weight: 800; font-size: 0.78rem; letter-spacing: 1px; margin-top: 3px; }
.dealer-tips { color: var(--text); font-size: 0.75rem; margin-top: 2px; }

/* ---------- Action bar (always visible) ---------- */
.action-bar {
  flex: 0 0 auto;
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  background: rgba(0,0,0,0.45);
  border-radius: 14px;
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: box-shadow .2s, background .2s;
}
.action-bar.your-turn {
  background: rgba(20,60,30,0.75);
  box-shadow: 0 0 0 2px var(--gold), 0 0 24px rgba(212,175,55,0.4);
  animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 2px var(--gold), 0 0 18px rgba(212,175,55,0.35); }
  50% { box-shadow: 0 0 0 2px var(--gold), 0 0 30px rgba(212,175,55,0.65); }
}

.bet-info { display: flex; gap: 10px; color: var(--text); font-size: 0.92rem; flex-wrap: wrap; }
.bet-info span { background: rgba(255,255,255,0.08); padding: 4px 12px; border-radius: 8px; }
#raise-info { color: var(--gold); font-weight: 700; }

.raise-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.raise-row input[type="range"] {
  flex: 1 1 180px;
  min-width: 140px;
  accent-color: var(--gold);
  height: 22px;
  cursor: pointer;
}
.quick-bets { display: flex; gap: 6px; flex-wrap: wrap; }
.qbet {
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.25);
  color: var(--text);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}
.qbet:hover { background: rgba(255,255,255,0.22); }

.controls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.controls .btn { flex: 1 1 auto; min-width: 84px; padding: 13px 14px; }
.btn-fold { background: #8e2f22; }
.btn-check { background: #2c6e49; }
.btn-call { background: #2471a3; }
.btn-raise { background: var(--gold); color: #241a02; }
.btn-allin { background: #6d2f8e; }
.btn-restart { background: #2c6e49; }

.waiting-note { color: var(--text-dim); font-size: 0.88rem; min-height: 16px; }

/* Tip row */
.tip-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.tip-label { color: var(--text-dim); font-size: 0.9rem; margin-right: 4px; }
.tip-btn {
  background: rgba(212,175,55,0.18);
  border: 1px solid var(--gold);
  color: var(--text);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
}
.tip-btn:hover:not(:disabled) { background: rgba(212,175,55,0.35); }
.tip-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* Chat panel */
.chat-panel {
  position: fixed;
  right: 12px;
  bottom: 12px;
  width: min(320px, calc(100vw - 24px));
  max-height: 46vh;
  display: flex;
  flex-direction: column;
  background: rgba(10, 20, 14, 0.95);
  border: 2px solid var(--gold);
  border-radius: 14px;
  z-index: 50;
  box-shadow: 0 12px 40px rgba(0,0,0,0.6);
  overflow: hidden;
}
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: rgba(0,0,0,0.4);
  color: var(--gold);
  font-weight: 700;
}
.chat-header .icon-btn { padding: 4px 10px; }
.chat-messages {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 10px 12px;
  min-height: 120px;
  max-height: 32vh;
  font-size: 0.88rem;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.chat-msg { line-height: 1.35; word-break: break-word; }
.chat-msg .chat-name { font-weight: 800; }
.chat-msg .chat-name.you { color: #ffd75e; }
.chat-msg .chat-name.ai { color: #8fb8e8; }
.chat-msg .chat-name.dealer { color: var(--gold); }
.chat-msg .chat-text { color: var(--text); }
.chat-input-row { display: flex; gap: 6px; padding: 8px 10px; border-top: 1px solid rgba(255,255,255,0.1); }
.chat-input-row input {
  flex: 1;
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.25);
  background: rgba(0,0,0,0.35);
  color: var(--text);
  outline: none;
}
.chat-input-row input:focus { border-color: var(--gold); }
.btn-chat-send { padding: 9px 14px; }

/* History modal */
.history-modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.6);
  z-index: 60;
  padding: 16px;
}
.history-box {
  width: min(92vw, 560px);
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  background: linear-gradient(145deg, var(--felt), var(--felt-dark));
  border: 3px solid var(--gold);
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.7);
  overflow: hidden;
}
.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: rgba(0,0,0,0.4);
  color: var(--gold);
}
.history-header .icon-btn { padding: 4px 12px; }
.history-content { flex: 1 1 auto; overflow-y: auto; padding: 14px 16px; font-size: 0.9rem; }
.history-hand { border: 1px solid rgba(255,255,255,0.15); border-radius: 10px; padding: 12px; margin-bottom: 14px; background: rgba(0,0,0,0.25); }
.history-hand-title { color: var(--gold); font-weight: 800; margin-bottom: 8px; font-size: 0.95rem; }
.history-row { margin: 5px 0; line-height: 1.4; }
.history-row .mini-card { margin: 2px; }
.history-player { display: flex; align-items: center; gap: 8px; margin: 4px 0; flex-wrap: wrap; }
.history-player .pl-name { font-weight: 700; }
.history-player .pl-info { color: var(--text-dim); font-size: 0.82rem; }
.history-actions { padding: 12px 16px; border-top: 1px solid rgba(255,255,255,0.15); display: flex; justify-content: flex-end; gap: 8px; }
.history-actions .btn { flex: 1 1 auto; }

/* Mini playing cards */
.mini-card {
  display: inline-block;
  min-width: 30px;
  padding: 2px 7px;
  background: #fff;
  color: #222;
  border-radius: 5px;
  font-weight: 800;
  font-size: 0.82rem;
  text-align: center;
  box-shadow: 0 2px 5px rgba(0,0,0,0.4);
  border: 1px solid #bbb;
}
.mini-card.red { color: #c0392b; }
.mini-card.back {
  background: #1c3f6e;
  color: #7fa6d0;
  border-color: #0f2a4a;
}
.history-empty { color: var(--text-dim); text-align: center; padding: 20px; }

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  .logo { font-size: 1.9rem; }
  .menu-box { padding: 26px 22px; }
  .topbar { flex-wrap: wrap; padding: 6px 10px; }
  .last-action { order: 3; flex-basis: 100%; font-size: 0.85rem; }
  .hand-label { display: none; }
  .controls .btn { min-width: 0; font-size: 0.9rem; padding: 12px 8px; }
  .bet-info { font-size: 0.82rem; gap: 6px; }
  .bet-info span { padding: 3px 9px; }
  .qbet { font-size: 0.76rem; padding: 5px 8px; }
  .raise-row input[type="range"] { flex: 1 1 100%; }
}

@media (max-height: 620px) {
  .bet-info { display: none; }
  .action-bar { padding: 8px 12px; gap: 6px; }
  .controls .btn { padding: 10px 12px; font-size: 0.9rem; }
}
