/* ==========================================================================
   10-carrom.css — Royal Carrom Board Styles
   Authentic royal mahogany, warm amber gold, and transparent glass theme.
   Matches Tic-Tac-Toe transparent backdrop aesthetic.
   ========================================================================== */

/* ── Overlay Root & Backdrop ─────────────────────────────────────────── */
#carrom-overlay {
  --ink: #14100c;
  --wood: #261a12;
  --wood-hi: #452f1e;
  --gold: #f2b632;
  --cream: #fbf8ee;
  --fg: #fbf8ee;
  --muted: #c8b9a6;
  --line: rgba(255, 255, 255, 0.12);
  --panel: rgba(255, 255, 255, 0.08);
  --font-display: 'Rozha One', Georgia, serif;
  --font-body: 'Hind', system-ui, -apple-system, sans-serif;

  position: fixed !important;
  inset: 0 !important;
  width: 100vw !important;
  height: 100dvh !important;
  z-index: 100005 !important;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: env(safe-area-inset-top, 4px) 4px env(safe-area-inset-bottom, 4px);
  visibility: hidden;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.22s ease, visibility 0.22s ease;
  font-family: var(--font-body);
  color: var(--fg);
  -webkit-tap-highlight-color: transparent;
  box-sizing: border-box;
  touch-action: none !important;
}

#carrom-overlay *,
#carrom-overlay *::before,
#carrom-overlay *::after {
  box-sizing: border-box;
}

#carrom-overlay.is-open {
  visibility: visible;
  pointer-events: auto;
  opacity: 1;
}

/* Transparent dimmed backdrop like Tic-Tac-Toe */
.carrom-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(12, 8, 4, 0.65) !important;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  opacity: 0;
  transition: opacity 0.22s ease;
  pointer-events: auto;
}

#carrom-overlay.is-open .carrom-backdrop {
  opacity: 1;
}

/* ── Main Container / Card (Warm dark translucent glass) ──────────────── */
.carrom-card {
  position: relative;
  z-index: 2;
  width: auto;
  max-width: min(99vw, calc(100dvh - 16px), 660px);
  max-height: 99dvh;
  overflow: hidden !important;
  touch-action: none !important;
  padding: 6px 8px 8px;
  border-radius: 18px;
  background: rgba(18, 12, 8, 0.78) !important;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1.5px solid rgba(242, 182, 50, 0.35);
  box-shadow: 0 16px 48px -6px rgba(0, 0, 0, 0.8), 0 0 0 1px rgba(255, 255, 255, 0.06);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  transform: translateY(12px) scale(0.98);
  opacity: 0;
  transition: transform 0.22s cubic-bezier(0.2, 0.9, 0.3, 1), opacity 0.2s ease;
  scrollbar-width: none;
  user-select: none;
  -webkit-user-select: none;
}

.carrom-card::-webkit-scrollbar {
  display: none;
}

#carrom-overlay.is-open .carrom-card {
  transform: translateY(0) scale(1);
  opacity: 1;
}

/* Close Button */
.carrom-close-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  transition: background 0.15s ease, transform 0.15s ease, color 0.15s ease;
  padding: 0;
}

.carrom-close-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
  transform: scale(1.06);
}

.carrom-close-btn:active {
  transform: scale(0.94);
}

/* ── HUD (Heads-Up Display) ───────────────────────────────────────────── */
.carrom-hud {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 2px 4px;
  width: 100%;
  max-width: min(calc(100vw - 16px), calc(100dvh - 145px), 620px);
}

.carrom-pot {
  display: none !important;
}

.carrom-player {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.carrom-player.right {
  justify-items: end;
  text-align: right;
}

.carrom-who {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.carrom-player.right .carrom-who {
  flex-direction: row-reverse;
}

.carrom-avatar {
  flex: none;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-size: 20px;
  color: #2a1608;
  border: 2.5px solid #fff3d6;
  transition: box-shadow 0.25s, border-color 0.25s;
  background: radial-gradient(circle at 35% 30%, #fffdf6, #e7d2aa 70%, #b99764);
}

.carrom-avatar.dark {
  color: #f5efe3;
  border-color: #77767f;
  background: radial-gradient(circle at 35% 30%, #6c6c74, #26262b 65%, #08080a);
}

.carrom-player.active .carrom-avatar {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(242, 182, 50, 0.35), 0 0 20px rgba(242, 182, 50, 0.7);
}

.carrom-name {
  font-weight: 600;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.carrom-turn-pill {
  display: inline-block;
  margin-left: 5px;
  padding: 1px 6px;
  border-radius: 8px;
  background: var(--gold);
  color: #3a2300;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0;
  transition: opacity 0.2s;
}

.carrom-player.active .carrom-turn-pill {
  opacity: 1;
}

.carrom-score {
  font-family: var(--font-display);
  font-size: 26px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: #fff;
}

.carrom-score small {
  font-family: var(--font-body);
  font-size: 11px;
  color: var(--muted);
  margin-left: 4px;
}

.carrom-pips {
  display: flex;
  gap: 3px;
  flex-wrap: wrap;
}

.carrom-player.right .carrom-pips {
  justify-content: flex-end;
}

.pip {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  border: 1.5px solid var(--line);
  background: transparent;
  transition: background 0.25s, border-color 0.25s;
}

.pip.w.on {
  background: radial-gradient(circle at 35% 30%, #fff, #e9d5ac);
  border-color: #fff3d6;
}

.pip.b.on {
  background: radial-gradient(circle at 35% 30%, #7a7a82, #111);
  border-color: #8b8a94;
}

.pip.q {
  border-color: #ff8a80;
  margin-left: 3px;
}

.pip.q.on {
  background: #e02a37;
  border-color: #ff8a80;
}

.pip.q.pending {
  animation: carromBlink 0.9s ease-in-out infinite;
  background: #e02a37;
}

@keyframes carromBlink {
  50% { opacity: 0.35; }
}

/* Center Prize Pot */
.carrom-pot {
  display: grid;
  justify-items: center;
  gap: 1px;
  padding-top: 2px;
}

.carrom-pot svg {
  width: 58px;
  height: auto;
  display: block;
}

.carrom-pot b {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 24px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: var(--gold);
}

.carrom-pot span {
  font-size: 9px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

/* ── Stage & Canvas ───────────────────────────────────────────────────── */
.carrom-stage {
  position: relative;
  width: auto;
  margin-inline: auto;
  display: flex;
  justify-content: center;
  align-items: center;
  flex: 0 0 auto;
  touch-action: none !important;
}

#carrom-board {
  display: block;
  width: min(calc(100vw - 16px), calc(100dvh - 145px), 620px);
  height: min(calc(100vw - 16px), calc(100dvh - 145px), 620px);
  aspect-ratio: 1/1;
  touch-action: none !important;
  border-radius: 16px;
  box-shadow: 0 12px 36px -6px rgba(0, 0, 0, 0.75);
  cursor: crosshair;
  -webkit-user-select: none;
  user-select: none;
  will-change: transform;
  transform: translateZ(0);
}

/* Toast Message */
.carrom-toast {
  position: absolute;
  left: 50%;
  top: 44%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  font-family: var(--font-display);
  font-size: clamp(20px, 5.5vw, 36px);
  color: #fff;
  text-shadow: 0 2px 0 #7a3a10, 0 6px 22px rgba(0, 0, 0, 0.7);
  opacity: 0;
  white-space: nowrap;
  z-index: 5;
}

.carrom-toast.show {
  animation: carromPop 1.5s ease-out both;
}

.carrom-toast.bad {
  color: #ffb4ae;
}

@keyframes carromPop {
  0%   { opacity: 0; transform: translate(-50%, -30%) scale(0.7); }
  12%  { opacity: 1; transform: translate(-50%, -50%) scale(1.06); }
  22%  { transform: translate(-50%, -50%) scale(1); }
  78%  { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -64%) scale(1); }
}

/* Game Over Overlay */
.carrom-over[hidden] {
  display: none !important;
}

.carrom-over {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(12, 8, 4, 0.75);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border-radius: 16px;
  z-index: 8;
}

.carrom-over-card {
  width: min(100%, 340px);
  text-align: center;
  display: grid;
  gap: 10px;
  padding: 24px 20px;
  border-radius: 20px;
  background: linear-gradient(180deg, #2c1e14, #18100a);
  border: 1.5px solid var(--gold);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.8);
}

.carrom-over-card h2 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 30px;
  color: var(--gold);
  line-height: 1.1;
}

.carrom-over-card p {
  margin: 0;
  color: var(--muted);
}

.carrom-over-card .big {
  color: var(--fg);
  font-size: 20px;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.carrom-again-btn {
  font: inherit;
  color: #3a2300;
  background: var(--gold);
  border: 1px solid var(--gold);
  border-radius: 22px;
  padding: 10px 20px;
  min-height: 44px;
  cursor: pointer;
  font-weight: 700;
  transition: background 0.15s ease, transform 0.15s ease;
}

.carrom-again-btn:hover {
  background: #ffc94d;
  transform: translateY(-1px);
}

.carrom-again-btn:active {
  transform: scale(0.96);
}

/* ── Control Dock ─────────────────────────────────────────────────────── */
.carrom-dock {
  display: grid;
  gap: 4px;
  width: 100%;
  max-width: min(calc(100vw - 16px), calc(100dvh - 145px), 620px);
  margin-inline: auto;
}

.carrom-status {
  margin: 0;
  min-height: 32px;
  padding: 6px 12px;
  border-radius: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  text-align: center;
  font-size: 13px;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--fg);
}

.carrom-row {
  display: grid;
  grid-template-columns: 56px 1fr;
  align-items: center;
  gap: 8px;
}

.carrom-row:has(.carrom-meter),
.carrom-row:has(#carrom-pw) {
  display: none !important;
}

/* Slider */
input[type=range].carrom-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 40px;
  background: transparent;
  margin: 0;
  cursor: grab;
}

input[type=range].carrom-slider::-webkit-slider-runnable-track {
  height: 14px;
  border-radius: 8px;
  background: linear-gradient(180deg, #8a5a34, #c48a54 50%, #e2ab70);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.5), 0 1px 0 rgba(255, 255, 255, 0.18);
}

input[type=range].carrom-slider::-moz-range-track {
  height: 14px;
  border-radius: 8px;
  background: linear-gradient(180deg, #8a5a34, #c48a54 50%, #e2ab70);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.5);
}

input[type=range].carrom-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 36px;
  height: 36px;
  margin-top: -11px;
  border-radius: 50%;
  border: 0;
  background: radial-gradient(circle at 35% 30%, #fff 0, #f3ebdc 55%, #cbbf9f 100%);
  box-shadow: inset 0 0 0 4px #c4202b, inset 0 0 0 7px #fff8ea, 0 4px 8px rgba(0, 0, 0, 0.5);
  cursor: grab;
}

input[type=range].carrom-slider::-moz-range-thumb {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 0;
  background: radial-gradient(circle at 35% 30%, #fff 0, #f3ebdc 55%, #cbbf9f 100%);
  box-shadow: inset 0 0 0 4px #c4202b, inset 0 0 0 7px #fff8ea, 0 4px 8px rgba(0, 0, 0, 0.5);
}

input[type=range].carrom-slider:disabled {
  opacity: 0.35;
  cursor: default;
}

/* Tools Bar */
.carrom-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 2px;
}

.carrom-btn {
  font: inherit;
  color: var(--fg);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 6px 14px;
  min-height: 36px;
  cursor: pointer;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background 0.15s ease;
}

.carrom-btn:hover {
  background: rgba(255, 255, 255, 0.14);
}

.carrom-btn:active {
  transform: scale(0.96);
}

/* ── Dedicated Challenge Card (Chat Integration) ───────────────────────── */
.carrom-challenge-zone {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 120;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 90%;
  max-width: 320px;
  pointer-events: auto;
}

.carrom-challenge-zone:empty {
  display: none !important;
  pointer-events: none !important;
}

.carrom-challenge-card {
  position: relative;
  background: linear-gradient(145deg, #2a1c12, #160e08);
  border: 1.5px solid var(--gold);
  border-radius: 16px;
  padding: 20px 18px 16px;
  text-align: center;
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.55), 0 0 24px rgba(242, 182, 50, 0.22);
  max-width: 300px;
  width: 100%;
  color: #fff;
  animation: carromCardIn 0.22s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.carrom-challenge-card.exiting {
  animation: carromCardOut 0.18s ease-in forwards;
}

@keyframes carromCardIn {
  from { opacity: 0; transform: scale(0.9) translateY(10px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

@keyframes carromCardOut {
  to   { opacity: 0; transform: scale(0.92) translateY(6px); }
}

.carrom-chal-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #3a2300;
  background: linear-gradient(90deg, #f2b632, #ff9f1c);
  padding: 2px 10px;
  border-radius: 10px;
  margin-bottom: 8px;
}

.carrom-chal-title {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 400;
  color: #fff;
  margin-bottom: 4px;
  line-height: 1.2;
}

.carrom-chal-sub {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 14px;
}

.carrom-chal-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.carrom-chal-btn {
  font: inherit;
  flex: 1;
  min-height: 40px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.12s ease, background 0.15s ease;
  border: 1px solid transparent;
}

.carrom-chal-btn:active {
  transform: scale(0.95);
}

.carrom-chal-accept {
  background: linear-gradient(135deg, #f2b632, #d99418);
  color: #2a1608;
  border-color: #f2b632;
  box-shadow: 0 4px 12px rgba(242, 182, 50, 0.35);
}

.carrom-chal-accept:hover {
  background: #ffc94d;
  transform: translateY(-1px);
}

.carrom-chal-decline {
  background: rgba(255, 255, 255, 0.08);
  color: var(--muted);
  border-color: rgba(255, 255, 255, 0.16);
}

.carrom-chal-decline:hover {
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
}

/* ── Quit Dialog & Rematch Prompt ───────────────────────────────────────── */
.carrom-quit-dialog,
.carrom-rematch-prompt {
  position: absolute;
  inset: 0;
  z-index: 25;
  background: rgba(12, 8, 4, 0.75);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border-radius: inherit;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  animation: carromCardIn 0.2s ease both;
}

.carrom-quit-box,
.carrom-rematch-box {
  background: linear-gradient(180deg, #2c1e14, #18100a);
  border: 1.5px solid var(--gold);
  border-radius: 18px;
  padding: 22px 18px 18px;
  text-align: center;
  max-width: 280px;
  width: 100%;
  box-shadow: 0 16px 38px rgba(0, 0, 0, 0.6);
}

.carrom-quit-title,
.carrom-rematch-title {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 400;
  color: var(--gold);
  margin-bottom: 4px;
}

.carrom-quit-sub,
.carrom-rematch-sub {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 16px;
}

.carrom-quit-actions,
.carrom-rematch-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
}

/* ── Responsive Mobile Adjustments ─────────────────────────────────────── */
@media (max-width: 520px) {
  .carrom-card {
    padding: 4px 5px 6px;
    gap: 3px;
    border-radius: 14px;
  }
  .carrom-avatar {
    width: 34px;
    height: 34px;
    font-size: 16px;
  }
  .carrom-score {
    font-size: 20px;
  }
  .carrom-pot svg {
    width: 40px;
  }
  .carrom-pot b {
    font-size: 18px;
  }
  .pip {
    width: 7px;
    height: 7px;
  }
  .carrom-turn-pill {
    display: none;
  }
  .carrom-hud {
    gap: 4px;
    padding: 0 2px;
  }
  .carrom-status {
    min-height: 26px;
    padding: 3px 8px;
    font-size: 11.5px;
  }
  .carrom-row {
    grid-template-columns: 44px 1fr;
    gap: 4px;
  }
  input[type=range].carrom-slider {
    height: 32px;
  }
  input[type=range].carrom-slider::-webkit-slider-thumb {
    width: 30px;
    height: 30px;
    margin-top: -9px;
  }
  input[type=range].carrom-slider::-moz-range-thumb {
    width: 30px;
    height: 30px;
  }
  .carrom-tools {
    margin-top: 0;
  }
  .carrom-btn {
    min-height: 30px;
    padding: 4px 10px;
    font-size: 11.5px;
  }
}
