:root {
  --bg-deep: #0b161a;
  --bg-emerald: #102a27;
  --wood-dark: #3b1f0f;
  --wood-mid: #5c3118;
  --gold-light: #ffe89e;
  --gold-main: #eab338;
  --gold-deep: #a66d11;
  --red-main: #e12d39;
  --red-dark: #8e111a;
  --yellow-main: #f5b727;
  --yellow-dark: #9e6b05;
  --text-light: #fdf6e3;
  --text-muted: #b9c5c0;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: radial-gradient(circle at 50% 20%, #173d36 0%, #0b1a1c 65%, #060d10 100%);
  color: var(--text-light);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

#app {
  position: relative;
  width: 100%;
  max-width: 430px;
  height: 100dvh;
  max-height: 920px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: env(safe-area-inset-top, 6px) 10px env(safe-area-inset-bottom, 8px);
  gap: 6px;
}

/* Top HUD */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px;
  background: linear-gradient(180deg, rgba(46, 26, 14, 0.92), rgba(26, 14, 8, 0.95));
  border: 1.5px solid rgba(234, 179, 56, 0.55);
  border-radius: 14px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 232, 158, 0.25);
}

.brand {
  display: flex;
  align-items: center;
  gap: 7px;
}

.brand-crown {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--gold-light), var(--gold-main) 55%, var(--gold-deep));
  color: #361b05;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 900;
  box-shadow: 0 2px 8px rgba(234, 179, 56, 0.45);
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.05;
}

.brand-title {
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0.7px;
  background: linear-gradient(180deg, #fff5cc, #f2b93b);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-sub {
  font-size: 9px;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.5px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 5px;
}

.balance-pill {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 9px;
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid rgba(234, 179, 56, 0.6);
  border-radius: 20px;
  font-size: 12px;
  font-weight: 800;
  color: var(--gold-light);
}

.coin-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: linear-gradient(135deg, #ffe89e, #d99414);
  color: #3a1f04;
  font-size: 10px;
  font-weight: 900;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.icon-btn {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 1px solid rgba(234, 179, 56, 0.4);
  background: rgba(255, 255, 255, 0.08);
  color: var(--gold-light);
  font-size: 13px;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.15s ease;
}

.icon-btn:active {
  transform: scale(0.92);
}

/* Versus Bar */
.vs-bar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 6px;
}

.player-card {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 8px;
  border-radius: 12px;
  background: rgba(15, 27, 29, 0.85);
  border: 1.5px solid rgba(255, 255, 255, 0.12);
  transition: border-color 0.25s, box-shadow 0.25s, transform 0.25s;
}

.player-gold {
  justify-content: flex-end;
}

.player-card.active-turn {
  border-color: var(--gold-main);
  box-shadow: 0 0 14px rgba(234, 179, 56, 0.4);
  transform: translateY(-1px);
}

.avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  font-size: 10px;
  font-weight: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid rgba(255, 255, 255, 0.7);
  flex-shrink: 0;
}

.avatar-red {
  background: radial-gradient(circle at 30% 30%, #ff6b74, var(--red-main) 60%, var(--red-dark));
  color: #fff;
}

.avatar-gold {
  background: radial-gradient(circle at 30% 30%, #fff1a8, var(--yellow-main) 60%, var(--yellow-dark));
  color: #3a1f04;
}

.p-info {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.p-info-right {
  align-items: flex-end;
}

.p-name {
  font-size: 11px;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 78px;
}

.home-pips {
  display: flex;
  gap: 4px;
}

.home-pips .pip {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  border: 1.5px solid rgba(255, 255, 255, 0.35);
  background: rgba(0, 0, 0, 0.45);
  transition: all 0.3s ease;
}

.player-red .home-pips .pip.filled {
  background: radial-gradient(circle at 35% 35%, #ff8c94, #e12d39);
  border-color: #ffe89e;
  box-shadow: 0 0 6px #ff4d5a;
}

.player-gold .home-pips .pip.filled {
  background: radial-gradient(circle at 35% 35%, #fff3b0, #f5b727);
  border-color: #fff;
  box-shadow: 0 0 6px #f5b727;
}

.pot-badge {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 4px 10px;
  border-radius: 12px;
  background: linear-gradient(180deg, #4b2b10, #2a1506);
  border: 1.5px solid var(--gold-main);
  box-shadow: 0 2px 10px rgba(234, 179, 56, 0.25);
}

.pot-label {
  font-size: 8px;
  font-weight: 800;
  letter-spacing: 0.7px;
  color: var(--gold-light);
}

.pot-val {
  font-size: 13px;
  font-weight: 900;
  color: #fff;
}

/* Board Stage */
.board-stage {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}

.board-frame {
  position: relative;
  width: min(100%, 372px);
  aspect-ratio: 1 / 1;
  border-radius: 18px;
  padding: 6px;
  background: linear-gradient(145deg, #8b5025, #47240e 45%, #2a1306 100%);
  border: 2.5px solid var(--gold-main);
  box-shadow:
    0 12px 30px rgba(0, 0, 0, 0.65),
    inset 0 2px 3px rgba(255, 232, 158, 0.45),
    inset 0 -2px 5px rgba(0, 0, 0, 0.6);
}

#ludoCanvas {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 11px;
  cursor: pointer;
}

.float-banner {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  padding: 8px 16px;
  border-radius: 999px;
  background: linear-gradient(180deg, #ffe89e, #e5a324);
  color: #361904;
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0.6px;
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.55);
  border: 2px solid #fff6d6;
  pointer-events: none;
  z-index: 10;
  white-space: nowrap;
  animation: popBanner 0.35s cubic-bezier(0.2, 1.3, 0.4, 1);
}

@keyframes popBanner {
  0% { transform: translate(-50%, -30%) scale(0.5); opacity: 0; }
  100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

/* Bottom Control Deck */
.control-deck {
  background: linear-gradient(180deg, rgba(44, 24, 12, 0.96), rgba(22, 11, 5, 0.98));
  border: 1.5px solid rgba(234, 179, 56, 0.55);
  border-radius: 16px;
  padding: 10px 11px;
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 232, 158, 0.25);
}

.panel.hidden,
.hidden {
  display: none !important;
}

.bet-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 7px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.4px;
}

.bet-label {
  color: var(--text-muted);
}

.bet-payout {
  color: var(--gold-light);
}

.bet-payout strong {
  color: #fff;
}

.bet-tiers {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  margin-bottom: 9px;
}

.bet-chip {
  padding: 7px 2px;
  border-radius: 9px;
  border: 1.5px solid rgba(234, 179, 56, 0.35);
  background: rgba(255, 255, 255, 0.06);
  color: #f3e6c8;
  font-size: 11px;
  font-weight: 800;
  cursor: pointer;
  transition: all 0.15s ease;
}

.bet-chip.selected {
  background: linear-gradient(180deg, #ffe89e, #e5a324 70%, #b5730c);
  color: #2f1603;
  border-color: #fff5cc;
  box-shadow: 0 2px 10px rgba(234, 179, 56, 0.5);
  transform: translateY(-1px);
}

.btn-primary-gold {
  position: relative;
  overflow: hidden;
  width: 100%;
  padding: 12px 16px;
  border: 2px solid #fff3c2;
  border-radius: 12px;
  background: linear-gradient(180deg, #ffe694 0%, #eab030 50%, #bd7a0d 100%);
  color: #331602;
  font-size: 15px;
  font-weight: 900;
  letter-spacing: 1px;
  cursor: pointer;
  box-shadow: 0 5px 18px rgba(234, 179, 56, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.7);
  transition: transform 0.12s ease;
}

.btn-primary-gold:active {
  transform: scale(0.97);
}

.btn-primary-gold:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* Active Match Controls */
.status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 8px;
}

.turn-status {
  font-size: 11px;
  font-weight: 800;
  color: var(--gold-light);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.match-mini-controls {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-shrink: 0;
}

.auto-toggle {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
}

.auto-toggle input {
  display: none;
}

.toggle-slider {
  width: 30px;
  height: 17px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.18);
  border: 1px solid rgba(234, 179, 56, 0.45);
  position: relative;
  transition: background 0.2s;
}

.toggle-slider::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.2s;
}

.auto-toggle input:checked + .toggle-slider {
  background: #eab338;
}

.auto-toggle input:checked + .toggle-slider::after {
  transform: translateX(13px);
}

.toggle-label {
  font-size: 10px;
  font-weight: 800;
  color: var(--text-muted);
}

.btn-forfeit {
  padding: 4px 8px;
  border-radius: 7px;
  border: 1px solid rgba(255, 107, 107, 0.45);
  background: rgba(225, 45, 57, 0.16);
  color: #ff9fa6;
  font-size: 10px;
  font-weight: 800;
  cursor: pointer;
}

.dice-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
}

.dice-side-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.dice-side-right {
  align-items: flex-end;
}

.side-lbl {
  font-size: 9px;
  font-weight: 800;
  color: var(--text-muted);
  letter-spacing: 0.5px;
}

.dice-side-info strong {
  font-size: 14px;
  color: var(--gold-light);
}

.ai-dice-mini {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: linear-gradient(145deg, #fff6d9, #e5c372);
  color: #3a1f04;
  border: 1.5px solid #a66d11;
  font-size: 15px;
  font-weight: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

.dice-trigger {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 18px 7px 12px;
  border-radius: 14px;
  border: 2px solid #ffe89e;
  background: linear-gradient(180deg, #ffdf80, #de9b1c 65%, #a86808);
  color: #331602;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(234, 179, 56, 0.5);
  transition: transform 0.12s ease, opacity 0.2s;
}

.dice-trigger:active:not(:disabled) {
  transform: scale(0.95);
}

.dice-trigger:disabled {
  opacity: 0.55;
  cursor: default;
  box-shadow: none;
}

.dice-trigger.pulse-ready {
  animation: pulseGlow 1.35s infinite ease-in-out;
}

@keyframes pulseGlow {
  0%, 100% { box-shadow: 0 0 12px rgba(255, 224, 128, 0.55); }
  50% { box-shadow: 0 0 24px rgba(255, 224, 128, 0.95); }
}

.roll-label {
  font-size: 14px;
  font-weight: 900;
  letter-spacing: 0.9px;
}

/* 3D-style Ivory & Gold Dice */
.dice-3d {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: linear-gradient(145deg, #ffffff 0%, #fff7e0 60%, #e6d19e 100%);
  border: 2px solid #c58f24;
  box-shadow: inset 2px 2px 4px rgba(255, 255, 255, 0.9), inset -2px -2px 5px rgba(150, 100, 20, 0.45), 0 3px 6px rgba(0, 0, 0, 0.35);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  padding: 5px;
  gap: 2px;
  transition: transform 0.2s ease;
}

.dice-3d.rolling {
  animation: diceTumble 0.36s linear infinite;
}

@keyframes diceTumble {
  0% { transform: rotate(0deg) scale(1); }
  25% { transform: rotate(90deg) scale(1.12); }
  50% { transform: rotate(180deg) scale(0.95); }
  75% { transform: rotate(270deg) scale(1.1); }
  100% { transform: rotate(360deg) scale(1); }
}

.pip-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #5b2610, #1f0a02);
  margin: auto;
  opacity: 0;
  box-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.35);
}

.face-1 .p5 { opacity: 1; background: radial-gradient(circle at 35% 35%, #ff4d5a, #b3121d); width: 9px; height: 9px; }
.face-2 .p1, .face-2 .p9 { opacity: 1; }
.face-3 .p1, .face-3 .p5, .face-3 .p9 { opacity: 1; }
.face-4 .p1, .face-4 .p3, .face-4 .p7, .face-4 .p9 { opacity: 1; }
.face-5 .p1, .face-5 .p3, .face-5 .p5, .face-5 .p7, .face-5 .p9 { opacity: 1; }
.face-6 .p1, .face-6 .p3, .face-6 .p4, .face-6 .p6, .face-6 .p7, .face-6 .p9 { opacity: 1; }

/* Toast */
.toast {
  position: fixed;
  top: 66px;
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 16px;
  border-radius: 99px;
  background: rgba(180, 28, 38, 0.95);
  border: 1px solid #ff9fa6;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  z-index: 40;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
  max-width: 90%;
  text-align: center;
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(5, 10, 12, 0.78);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  z-index: 50;
}

.modal-card {
  width: 100%;
  max-width: 360px;
  background: linear-gradient(180deg, #3a2010, #1c0f07);
  border: 2px solid var(--gold-main);
  border-radius: 18px;
  padding: 16px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.7);
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.modal-head h3 {
  margin: 0;
  font-size: 16px;
  color: var(--gold-light);
}

.modal-close {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 1px solid rgba(234, 179, 56, 0.4);
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  cursor: pointer;
}

.result-card {
  text-align: center;
}

.res-crown {
  font-size: 44px;
  line-height: 1;
  margin-bottom: 6px;
  filter: drop-shadow(0 4px 12px rgba(234, 179, 56, 0.6));
}

.res-title {
  margin: 0;
  font-size: 24px;
  font-weight: 900;
  letter-spacing: 1px;
  color: var(--gold-light);
}

.res-sub {
  margin: 4px 0 14px;
  font-size: 12px;
  color: var(--text-muted);
}

.res-payout-box {
  background: rgba(0, 0, 0, 0.4);
  border: 1.5px solid rgba(234, 179, 56, 0.55);
  border-radius: 12px;
  padding: 10px;
  margin-bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.res-payout-lbl {
  font-size: 10px;
  font-weight: 800;
  color: var(--text-muted);
}

#resPayoutVal {
  font-size: 24px;
  color: #6df29c;
}

#resPayoutVal.loss {
  color: #ff7a84;
}

.res-stats {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 14px;
}

.history-list {
  max-height: 300px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.hist-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 12px;
}

.hist-win { color: #6df29c; font-weight: 800; }
.hist-loss { color: #ff7a84; font-weight: 800; }
.hist-meta { font-size: 10px; color: var(--text-muted); }

.rules-list {
  margin: 0;
  padding-left: 18px;
  font-size: 12px;
  line-height: 1.55;
  color: #f0e4cc;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
