
* { box-sizing: border-box; }
:root{
  /* Neutral dark theme */
  --bg-main: #0f0f10;
  --bg-header: #141416;
  --bg-panel: #17181a;
  --bg-panel-2: #1e1f22;

  --text-main: #e6e6e6;
  --text-muted: #9a9a9a;

  --accent: #2b2c2f;
  --accent-hover: #3a3b3f;

  --border: #2a2a2a;

  --danger: #d64545;
  --success: #5cb85c;

  /* Board */
  --sq-light: #3a3a3a;
  --sq-dark:  #262626;
  --board-border: #5a4633;
}

html, body { margin:0; font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial; background:var(--bg-main); color:var(--text-main); }
body { margin:0; font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial; background:var(--bg-main); color:var(--text-main); }
header { display:flex; align-items:center; justify-content:space-between; padding:16px 20px; background:var(--bg-header); border-bottom:1px solid var(--border); }
h1 { margin:0; font-size:24px; letter-spacing:0.5px; }
.actions { display:flex; gap:8px; align-items:center; }
.actions input {  padding:8px 10px; border-radius:10px; border:1px solid var(--border); background:var(--bg-panel-2); color:var(--text-main); }
.actions select { padding:8px 10px; border-radius:10px; border:1px solid var(--border); background:var(--bg-panel-2); color:#fff; }
.actions button { padding:8px 12px; border:none; border-radius:10px; background:var(--accent); color:#fff; cursor:pointer; }
.actions button:hover{ background: var(--accent-hover); }

.app main {
  display: flex;
  justify-content: center;
  padding: 16px;
}

/* With the left panel removed, keep everything centered */
.center-stage{
  display: flex;
  flex-direction: column;
  align-items: center;
}
.panel { background:var(--bg-panel); border:1px solid var(--border); border-radius:16px; padding:16px; display:flex; flex-direction:column; gap:10px; }
.panel .hint { font-size:12px; color:var(--text-muted); }
.winner { font-size:18px; padding:6px 10px; border-radius:8px; background:var(--bg-panel-2); color: var(--success); display:none; border: 1px solid var(--border); }
#btnRoll { margin-top:8px; }

/* Board container with layered board + pieces */
.board-container {
  position: relative;
  width: min(90vw, 720px);
  aspect-ratio: 1;
}

/* Board + right sidebar wrapper (keeps sidebar OUTSIDE the board) */
.board-row{
  display: flex;
  align-items: stretch;
  gap: 16px;
}

/* On small screens, stack the sidebar below the board */
@media (max-width: 980px){
  .board-row{
    flex-direction: column;
    align-items: flex-start;
  }
  #sidePanel{
    width: min(90vw, 720px);
    height: auto;
  }
}

.board {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border-radius: 12px;
  overflow: hidden;
  border: 2px solid var(--board-border);
  user-select: none;
  z-index: 1;
}

.square { width: 100%; height: 100%; position: relative; }
.square.light { background: #f0d9b5; }
.square.dark { background: #b58863; }
.square.highlight { outline: 3px solid rgba(255,255,255,0.85); outline-offset:-3px; }
.square.target { box-shadow: inset 0 0 0 3px #7ce2ff; }

/* Move hints (lichess/chess.com style)
   Empty square: dot
   Capture square: ring */
.square.hint-empty::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 22%;
  height: 22%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: rgba(0,0,0,0.30);
}

.square.hint-capture::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 70%;
  height: 70%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  border: 4px solid rgba(0,0,0,0.30);
  background: transparent;
}

.pieces-layer {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: 3;
  /* Allow empty-square clicks to hit the board squares underneath.
     Individual pieces (piece-node) still receive pointer events. */
  pointer-events: none;
}

/* Hints layer sits above the board and below pieces so dots never flicker/disappear */
.hints-layer{
  position:absolute;
  inset:0;
  z-index:2;
  pointer-events:none;
}

.hint-dot{
  position:absolute;
  width:12.5%;
  height:12.5%;
  display:flex;
  align-items:center;
  justify-content:center;
}

.hint-dot::after{
  content:"";
  width:22%;
  height:22%;
  border-radius:50%;
  background: rgba(0,0,0,0.30);
}

.hint-dot.capture::after{
  width:70%;
  height:70%;
  background: transparent;
  border: 4px solid rgba(0,0,0,0.30);
}

.piece-node {
  position: absolute;
  width: 12.5%;
  height: 12.5%;
  left: 0; top: 0;
  transition: top 120ms ease, left 120ms ease;
  pointer-events: auto; /* enabled for drag start */
  cursor: grab;
  display: grid;
  place-items: center;
}

.piece-node svg { width: 80%; height: 80%; }

.drag-ghost {
  position: fixed;
  top: 0; left: 0;
  transform: translate(-50%, -50%);
  z-index: 1000;
  pointer-events: none;
  filter: drop-shadow(0 6px 10px rgba(0,0,0,0.35));
  width: 64px;
  height: 64px;
}

.badge { display:inline-block; padding:6px 10px; border-radius:999px; font-size:12px; background:var(--bg-panel-2); border:1px solid var(--border); }
.badge.white::before{ content:"♙ "; }
.badge.black::before{ content:"♟ "; }
.legend { margin-top:12px; display:flex; gap:10px; }

/* Win streak bars above and below the board */
/* Keep the bar the same width as the board and aligned with it */
.streak-bar{
  width: min(90vw, 720px);
  display:flex;
  justify-content:space-between;
  align-items:center;
  gap:12px;
  padding:8px 12px;
  border:1px solid var(--border);
  border-radius:10px;
  background:var(--bg-panel);
}
.streak-top{ margin:0 0 10px 0; }
.streak-bottom{ margin:10px 0 0 0; }
.streak-item{ font-size:13px; opacity:0.95; }


/* Start/Rules overlays */
.overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
}
.hidden { display: none; }
.menu-panel {
  background: rgba(20,20,30,0.9);
  padding: 28px; border-radius: 12px; color: #fff; text-align: center;
  width: min(92vw, 420px);
}
.menu-panel button {
  width: 100%; margin: 10px 0; padding: 12px 18px;
  background: #4a6cf7; color:#fff; border:0; border-radius: 8px; cursor: pointer;
}
.menu-panel button:hover { filter: brightness(1.1); }

/* Game container reveal */
#gameContainer.hidden { display: none; }

/* Side panel (clocks + die) to the right of the board */
#sidePanel{
  position: relative;
  height: 100%;
  width: 220px;
  flex: 0 0 220px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 12px;
}

.clock{
  width: 200px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-panel);
  font-weight: 800;
  font-size: 28px;
  text-align: center;
  user-select: none;
}

.clock-status{
  width: 200px;
  text-align: center;
  font-size: 12px;
  line-height: 1.2;
  margin-top: 4px;
  margin-bottom: 8px;
  opacity: 0.85;
  user-select: none;
}

.clock-status.disconnected{
  opacity: 1;
}

.clock.active{
  box-shadow: inset 0 0 0 3px rgba(124, 226, 255, 0.6);
  color: #7ce2ff;
}

/* Game end highlighting */
.clock.win{
  border-color: rgba(60, 210, 120, 0.8);
  box-shadow: inset 0 0 0 3px rgba(60, 210, 120, 0.25);
  color: #48e08a;
}
.clock.lose{
  border-color: rgba(255, 90, 90, 0.85);
  box-shadow: inset 0 0 0 3px rgba(255, 90, 90, 0.18);
  color: #ff6666;
}

.clock.draw{
  border-color: rgba(240, 210, 120, 0.75);
  box-shadow: inset 0 0 0 3px rgba(240, 210, 120, 0.18);
  color: #f0d278;
}
.clock.draw{
  border-color: rgba(240, 210, 90, 0.85);
  box-shadow: inset 0 0 0 3px rgba(240, 210, 90, 0.16);
  color: #f3d56b;
}

.history-wrap{
  width: 200px;
  border: 1px solid var(--border);
  background: var(--bg-panel);
  border-radius: 10px;
  overflow: hidden;
}

.spectators-count{
  padding: 6px 10px;
  border-bottom: 1px solid rgba(43, 60, 122, 0.6);
  background: rgba(255,255,255,0.01);
  font-size: 12px;
  font-weight: 700;
  opacity: 0.85;
}

/* Post-game actions (Chess.com-like) */
.postgame-wrap{
  padding: 10px;
  border-bottom: 1px solid rgba(43, 60, 122, 0.6);
  background: rgba(255,255,255,0.015);
}
.postgame-title{
  font-weight: 800;
  font-size: 12px;
  opacity: 0.9;
  margin-bottom: 8px;
}
.postgame-actions{
  display: flex;
  gap: 8px;
}
.postgame-btn{
  flex: 1;
  border: 1px solid rgba(232, 236, 255, 0.35);
  background: rgba(232, 236, 255, 0.06);
  color: var(--text-main);
  border-radius: 10px;
  padding: 8px 10px;
  cursor: pointer;
  font-weight: 800;
  font-size: 12px;
}
.postgame-btn:hover{ filter: brightness(1.12); }
.postgame-btn:disabled{ opacity: 0.55; cursor: not-allowed; }
.postgame-status{
  margin-top: 8px;
  font-size: 12px;
  opacity: 0.85;
}

/* Private room code (shown above move list) */
.roomcode-wrap{
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-bottom: 1px solid rgba(43, 60, 122, 0.6);
  background: rgba(255,255,255,0.02);
}
.roomcode-text{
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}
.roomcode-label{
  opacity: 0.85;
  font-weight: 700;
  font-size: 12px;
}
.roomcode-code{
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  letter-spacing: 1px;
  font-weight: 900;
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.copy-btn{
  border: 1px solid rgba(232, 236, 255, 0.35);
  background: rgba(232, 236, 255, 0.06);
  color: var(--text-main);
  border-radius: 8px;
  padding: 6px 10px;
  cursor: pointer;
  font-weight: 800;
  font-size: 12px;
}
.copy-btn:hover{ filter: brightness(1.12); }

.history-header{
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  font-weight: 700;
  border-bottom: 1px solid rgba(43, 60, 122, 0.6);
}

.history-controls{
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  padding: 8px 10px;
  border-bottom: 1px solid rgba(43, 60, 122, 0.45);
}

.nav-btn{
  border: 1px solid rgba(232, 236, 255, 0.25);
  background: rgba(232, 236, 255, 0.06);
  color: var(--text-main);
  border-radius: 8px;
  padding: 6px 0;
  cursor: pointer;
  font-weight: 800;
  line-height: 1;
}
.nav-btn:hover{ filter: brightness(1.12); }
.nav-btn:disabled{ opacity: 0.4; cursor: default; }

.btn-live{
  border: 1px solid rgba(232, 236, 255, 0.35);
  background: rgba(232, 236, 255, 0.08);
  color: var(--text-main);
  border-radius: 8px;
  padding: 3px 8px;
  cursor: pointer;
  font-weight: 700;
}
.btn-live:disabled{
  opacity: 0.45;
  cursor: default;
}

.move-history{
  max-height: 240px;
  overflow: auto;
  padding: 8px 10px 10px;
  font-size: 13px;
  line-height: 1.35;
}

/* Chess.com-like move list (move number + white/black columns) */
.move-pair{
  display: grid;
  grid-template-columns: 30px 1fr 1fr;
  gap: 6px;
  align-items: center;
  padding: 3px 2px;
  border-radius: 8px;
}

.move-pair:hover{ background: rgba(232, 236, 255, 0.05); }

.move-no{
  opacity: 0.75;
  font-weight: 800;
  text-align: right;
  padding-right: 2px;
}

.move-cell{
  border-radius: 8px;
  padding: 5px 8px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border: 1px solid transparent;
}

.move-cell:hover{ background: rgba(232, 236, 255, 0.06); }

.move-cell.selected{
  background: rgba(124, 226, 255, 0.12);
  border-color: rgba(124, 226, 255, 0.35);
}

.move-cell.empty{ cursor: default; opacity: 0.35; }

#diceSquare {
  width: 88px; height: 88px;
  border: 3px solid var(--border);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-panel);
  font-size: 36px; font-weight: 800;
  color: var(--text-main);
  user-select: none;
  cursor: pointer;
  transition: transform .1s ease, color .2s ease;
}

/* --- Match chat --- */
.chat-wrap{
  margin-top: 8px;
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 10px;
  overflow: hidden;
  background: rgba(0,0,0,0.25);
}
.chat-header{
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px;
  background: rgba(0,0,0,0.25);
  border-bottom: 1px solid rgba(255,255,255,0.10);
  user-select: none;
}
.chat-title{ font-weight: 700; font-size: 12px; opacity: 0.9; }
.chat-toggle{
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 8px;
}
.chat-toggle:hover{ background: rgba(255,255,255,0.08); }
.chat-body{ padding: 6px 8px; }
.chat-messages{
  height: 110px;
  overflow-y: auto;
  padding-right: 4px;
  font-size: 12px;
}
.chat-line{ margin: 2px 0; opacity: 0.95; word-break: break-word; }
.chat-who{ font-weight: 800; margin-right: 6px; opacity: 0.85; }
.chat-line.you .chat-who{ opacity: 0.95; }
.chat-line.opponent .chat-who{ opacity: 0.75; }
.chat-input-row{
  display: flex;
  gap: 6px;
  margin-top: 6px;
}
.chat-input{
  flex: 1;
  padding: 6px 8px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.14);
  background: rgba(0,0,0,0.25);
  color: inherit;
  outline: none;
}
.chat-input:focus{ border-color: rgba(255,255,255,0.28); }
.chat-send{
  width: 36px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.14);
  background: rgba(255,255,255,0.06);
  color: inherit;
  cursor: pointer;
}
.chat-send:hover{ background: rgba(255,255,255,0.10); }

.chat-wrap.collapsed .chat-body{ display: none; }
.chat-wrap.collapsed .chat-toggle{ transform: rotate(-90deg); }

#diceSquare.empty { color: var(--text-muted); font-size: 16px; font-weight: 500; }
#diceSquare.rolling { animation: shake .4s infinite; color: var(--text-main); }
#diceSquare.final { color: var(--danger); }

@keyframes shake {
  0% { transform: translate(1px, 1px) rotate(0deg); }
  10% { transform: translate(-1px, -2px) rotate(-1deg); }
  20% { transform: translate(-3px, 0px) rotate(1deg); }
  30% { transform: translate(3px, 2px) rotate(0deg); }
  40% { transform: translate(1px, -1px) rotate(1deg); }
  50% { transform: translate(-1px, 2px) rotate(-1deg); }
  60% { transform: translate(-3px, 1px) rotate(0deg); }
  70% { transform: translate(3px, 1px) rotate(-1deg); }
  80% { transform: translate(-1px, -1px) rotate(1deg); }
  90% { transform: translate(1px, 2px) rotate(0deg); }
  100% { transform: translate(1px, -2px) rotate(-1deg); }
}

/* Hide legacy button */
#btnRoll { display: none !important; }

/* Blurred board state */
.board-container.blurred .board,
.board-container.blurred .pieces-layer {
    filter: blur(6px);
    pointer-events: none;
}

.board-container.blurred + #sidePanel {
    filter: blur(6px);
    pointer-events: none;
}

/* Overlay message centered over board */
.overlay-message {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    font-weight: bold;
    color: #fff;
    background: rgba(0, 0, 0, 0.55);
    z-index: 10;
}

    .overlay-message.hidden {
        display: none;
    }
    
    #searching-overlay {
    z-index: 20;
}

/* In-game action buttons (right side panel) */
.ingame-actions{
  width: 110px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 10px 0 14px 0;
  align-items: stretch;
}
.draw-offer{
  padding: 6px 8px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background:var(--bg-panel-2);
  color: var(--text-main);
  font-size: 12px;
  line-height: 1.2;
  text-align: center;
}
.draw-actions{ display:flex; gap:8px; }
.actions-small{
  flex:1;
  padding:10px 12px;
  border:none;
  border-radius:10px;
  background:var(--accent);
  color:#fff;
  cursor:pointer;
  font-weight:700;
  font-size: 12px;
}
.actions-small:hover{ filter:brightness(1.05); }
.actions-small.hidden{ display:none; }
.forfeit-btn{
  padding: 10px 12px;
  border: none;
  border-radius: 10px;
  background: #ff4d4d;
  color: #fff;
  cursor: pointer;
  font-weight: 800;
}
.forfeit-btn:hover{ filter: brightness(1.05); }


/* Rules dropdown */
.rules-dropdown{
  position: absolute;
  top: 48px;
  right: 0;
  width: 320px;
  max-height: 360px;
  overflow-y: auto;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  color: var(--text-main);
  font-size: 14px;
  z-index: 60;
  box-shadow: 0 12px 30px rgba(0,0,0,0.45);
}
.rules-dropdown h3{
  margin: 0 0 10px 0;
  font-size: 16px;
}
.rules-dropdown ul{
  padding-left: 18px;
}
.rules-dropdown li{
  margin-bottom: 8px;
}


/* Neutral button styling override */
button{
  background: var(--accent);
  color: var(--text-main);
  border: 1px solid var(--border);
}
button:hover{
  background: var(--accent-hover);
}
button:disabled{
  opacity: 0.55;
  cursor: not-allowed;
}

/* Highlight/pulse the Play Again button when opponent requested a rematch */
.rematch-highlight{
  box-shadow: 0 0 0 2px var(--accent), 0 0 14px rgba(255,255,255,0.25);
  animation: rematchPulse 1.1s ease-in-out infinite;
}
@keyframes rematchPulse{
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.35); }
}

/* Keep danger buttons red */
.forfeit-btn, .leave-room, #btnForfeit{
  background: var(--danger) !important;
  border: none !important;
}

/* Pawn promotion chooser */
.promo-overlay{
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}
.promo-overlay.hidden{ display: none; }

.promo-panel{
  background: rgba(20,20,30,0.95);
  border: 1px solid #2b3c7a;
  border-radius: 14px;
  padding: 16px 18px;
  width: min(92vw, 360px);
  text-align: center;
  box-shadow: 0 12px 30px rgba(0,0,0,0.35);
}
.promo-title{
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 12px;
}
.promo-options{
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}
.promo-btn{
  background: #0f1630;
  border: 1px solid #334071;
  border-radius: 10px;
  padding: 10px;
  cursor: pointer;
}
.promo-btn:hover{ filter: brightness(1.15); }
.promo-img{
  width: 44px;
  height: 44px;
}

/* Private room settings (reuse promotion modal) */
.private-row{
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 10px 0;
  text-align: left;
}
.private-label{
  font-size: 13px;
  color: #a8b2d8;
  font-weight: 600;
}
.private-choice{
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}
.private-radio{
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border: 1px solid #334071;
  border-radius: 10px;
  background: #0f1630;
  cursor: pointer;
  user-select: none;
}
.private-radio input{ accent-color: #3a5fff; }

.private-select{
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid #334071;
  background: #0f1630;
  color: #e8ecff;
}

.private-actions{
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 12px;
}
.private-btn{
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid #334071;
  cursor: pointer;
  font-weight: 700;
}
.private-btn.primary{
  background: #3a5fff;
  color: #fff;
  border: none;
}
.private-btn.secondary{
  background: #0f1630;
  color: #e8ecff;
}
.private-btn:hover{ filter: brightness(1.08); }


.site-logo {
  height: 42px;
  width: auto;
  cursor: pointer;
  transition: opacity 0.15s ease;
}

.site-logo:hover {
  opacity: 0.85;
}


/* --- AdSense rails (left/right of board only) --- */
.board-ad-wrap{
  display:flex;
  align-items:center;
  justify-content:center;
  gap:18px;
  width: 100%;
}

.board-center{
  display:flex;
  align-items:center;
  justify-content:center;
}

.ad-rail{
  width: 180px;           /* typical sidebar ad width; adjust if needed */
  min-height: 260px;      /* gives the slot room to render */
  flex: 0 0 auto;
}

@media (max-width: 1100px){
  /* On smaller screens, hide ad rails so they never overlap gameplay */
  .ad-rail{ display:none; }
  .board-ad-wrap{ gap: 0; }
}
