:root {
    /* 🛰️ SYSTEM GEOMETRY */
    --board-size: min(72vh, calc(100vw - 360px), 640px); 
    --meta-size: 80vh;
    --square-size: calc(var(--board-size) / 8); 
    
    /* 🎨 SOVEREIGN PALETTE */
    --primary-green: #09f530; 
    --light-square: #c5d9c8;  
    --dark-square: #1a4a2e;   
    --selection-glow: rgba(9, 245, 48, 0.4); 
}

.content-area{
    padding:0;
}

/* 🚫 ABSOLUTE MODULE ISOLATION */
/* If the Chess Arena is present, EVERYTHING related to tasks is erased */
body:has(.arena-layout) .task-deployment-sidebar,
body:has(.arena-layout) .task-sidebar,
body:has(.arena-layout) [class*="task-"],
body:has(.arena-layout) [id*="task-"] {
    display: none !important;
    width: 0 !important;
    opacity: 0 !important;
    pointer-events: none !important;
}

.chess-system-container {
    display: flex;
    flex-direction: column;
    align-items: center; 
    width: 100%;
    height:100%; /* 🎯 Shrink-wraps to the board + sidebar */
    margin: 0 auto;
}

/* 🏗️ ARENA CONTAINER: Centered and pulled to the top */
.arena-layout {
    position: relative;
    z-index: 1000;
    background: #050505;
    height: 100%;
    width: 100%; /* 🎯 Full width of the container */ 
    margin: 0;
    padding: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column; /* 📏 Stacks Opponent -> Board -> Player */
    align-items: center;
    justify-content: flex-start; 
    
    overflow-x: hidden;
}

/* 🏁 BOARD WRAPPER: Houses labels in a 40px "Gutter" */
.board-relative-wrapper {
    position: relative;
    padding: 0;
    background: #0a0a0a;
    border: 1px solid #333;
    display: block;
    width: var(--board-size);
    max-width: 100%;
    box-sizing: border-box;
    overflow: visible;
}

/* 🏁 THE BOARD ROW: Keeps Board and Sidebar side-by-side */
.chess-main-row {
    display: flex;
    flex-direction: row;
    justify-content: center; /* 🛰️ Centers the whole assembly as one unit */
    align-items: center; 
    gap: 30px;               /* 🎯 Reduced gap to bring sidebar closer */
    width: 100%;
    padding: 0 20px;
}

.spacer {
    display: flex;

}

.flight-deck {
    display: flex;
    flex-direction: column;
    align-items: center; 
    gap: 0;                  /* 🎯 Tightens the HUDs to the board */
    width: min-content; 
}

/* 📊 DATA FEED SIDEBAR */
.tactical-sidebar {
    display: flex;
    flex-direction: column;
    width: 25vw;             /* 🛰️ Responsive width based on screen size */
    min-width: 350px;        /* 🚫 Prevents squishing on small screens */
    max-width: 500px;        /* 🚫 Prevents getting too wide on your RIG */
    height: var(--board-size); 
    background: rgba(0, 0, 0, 0.95);
    border: 2px solid var(--primary-green);
    flex-shrink: 0;          /* ⚓ Anchor: The board cannot crush the sidebar */
}

.side-panel-header {
    background: var(--primary-green);
    color: #000;
    padding: 8px;
    font-weight: bold;
    text-align: center;
    letter-spacing: 2px;
}

.d-flex.gap-1{
 padding: 0;
 margin: 5px;
 width: 100%;
display: flex;
align-items: center;
justify-content: center;
}

.btn-zoom{
    width: 30%;
    margin: 5px;
}


/* 🏁 THE CORE GRID */
#main-grid {
    display: grid !important;
    grid-template-columns: repeat(8, 1fr) !important;
    grid-template-rows: repeat(8, 1fr) !important;
    width: var(--board-size) !important;
    height: var(--board-size) !important;
    max-width: 100%;
    overflow: hidden !important;
    background-color: transparent !important; /* no "extra green" bleed */
    position: relative;
    z-index: 5;
    border: 1px solid #333;
    box-sizing: border-box;
}

/* 🎯 CHECKERBOARD LOGIC */
.square {
    /* size comes ONLY from grid 1fr tracks — never min-width */
    width: 100% !important;
    height: 100% !important;
    min-width: 0 !important;
    min-height: 0 !important;
    max-width: none !important;
    max-height: none !important;
    aspect-ratio: auto !important;
    position: relative;
    overflow: hidden !important;
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    /* default; HTML .light/.dark override */
    background-color: var(--dark-square);
}

/* Checkerboard via HTML classes only (nth-child disabled — fought .light/.dark) */
.square.light {
    background-color: var(--light-square) !important;
}
.square.dark {
    background-color: var(--dark-square) !important;
}

/* ♟️ PIECE SCALING */
.piece {
    width: 88% !important; 
    height: 88% !important;
    object-fit: contain;
    z-index: 50 !important;
    cursor: grab;
    /* ZERO animation — land / drag must be instant (bullet / scramble) */
    transition: none !important;
    animation: none !important;
    position: relative;
    pointer-events: auto;
}

/* 🚨 ILLEGAL MOVE FEEDBACK */
.illegal-blink {
    color: #ff3333 !important;
    text-shadow: 0 0 5px #ff0000;
    animation: blink 0.5s step-end infinite;
}

@keyframes blink { 50% { opacity: 0; } }

.move-dot { 
    background: var(--selection-glow); 
    border-radius: 50%; 
    width: 20%; 
    height: 20%; 
}

.move-log {
    flex-grow: 1;
    overflow-y: auto;
    padding: 10px;
    background: #080808;
    font-size: 0.9rem;
}

.suggested-move-dot {
    width: 15px;
    height: 15px;
    background: rgba(0, 255, 0, 0.4);
    border-radius: 50%;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none; /* 🎯 Click through the dot to the square */
}


.square img.piece {
    display: block !important;
    width: 90% !important;
    height: 90% !important;
    opacity: 1 !important;
    visibility: visible !important;
    z-index: 50 !important;
}

/* ↕️ HUD POSITIONING: Prevents floating to the right */
.user-meta-zone {
    width: var(--board-size); /* Matches board exactly */
    display: flex;
    flex-direction: column; /* Stacks the row and the progress bar */
    padding: 10px 0;
    margin: 0 auto; 
}

.user-info-row {
    display: flex;
    justify-content: space-between; /* 🛰️ Name Left, Timer Right */
    align-items: center;
    width: 100%;
}

.user-info{
    margin-top: 40px;
}

.chess-timer {
    font-size: 1.8rem;
    font-weight: bold;
    color: var(--primary-green);
    text-shadow: 0 0 10px rgba(9, 245, 48, 0.4);
    background: #111;
    padding: 5px 12px;
    min-width: 100px;
    text-align: center;
    margin-top: 20px;
}

.time-bar-container {
    width: 100%;
    height: 4px; /* Slightly thicker for visibility */
    background: rgba(0, 255, 0, 0.1); 
    margin-top: 4px;
    border-radius: 2px;
    overflow: hidden;
    /* 🛡️ Prevents layout shifting */
    flex-shrink: 0; 
}

/* 🔢 COORDINATE LABELS: Pinned inside the 40px Gutters */
.ranks-abs, .files-abs {
    position: absolute;
    left: 0;
    bottom: -18px;
    width: var(--board-size);
    height: 16px;
    display: flex;
    flex-direction: row;
    justify-content: space-around;
    pointer-events: none;
    z-index: 2;
}

.ranks-abs {
    position: absolute;
    left: -18px;
    top: 0;
    height: var(--board-size);
    width: 16px;
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    pointer-events: none;
    z-index: 2;
}

.files-abs { 
    bottom: -40px; /* Pushes letters below the board */
    left: 0;
    width: var(--board-size); 
    display: flex;
}

.ranks-abs div { 
    height: calc(var(--board-size) / 8); 
    display: flex; 
    align-items: center; 
    justify-content: center;
    color: var(--primary-green);
    font-size: 0.8rem;
}

.files-abs div { 
    width: calc(var(--board-size) / 8); 
    display: flex; 
    align-items: center; 
    justify-content: center;
    color: var(--primary-green);
    font-size: 0.8rem;
}

.tool-sidebar{
    display: none; /* Hidden by default */
}



/* 🚀 This is the "Spacer" that pushes controls down */
.side-panel-content {
    display: flex;
    flex-direction: column;
    flex-grow: 1; 
    overflow-y: auto; /* Allows history to scroll while sidebar stays fixed */
}

/* ⚓ THE DOCKED CONTROLS */
.board-corner-controls {
    margin-top: auto;
    padding: 15px;
    background: rgba(9, 245, 48, 0.05);
    border-top: 1px solid #222;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.nav-cluster, .utility-cluster {
    display: flex;
    gap: 8px;
    width: 100%;
    justify-content: center;
}

/* 🎨 BUTTON AESTHETICS */
.btn-nav, .btn-zoom {
    background: #111;
    border: 1px solid var(--primary-green);
    color: var(--primary-green);
    font-family: 'Courier New', monospace;
    padding: 8px 15px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-shadow: 0 0 5px var(--primary-green);
}

.btn-nav:hover, .btn-zoom:hover {
    background: var(--primary-green);
    color: #000;
    box-shadow: 0 0 15px var(--primary-green);
}

.btn-nav {
    flex-grow: 1; /* Makes nav buttons wide like chess.com */
    font-size: 1.5rem;
}

/* Container for the name and timer */
.user-info-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
}

/* The outer track of the bar */
.time-bar-container {
    width: 100%;
    height: 3px; /* 🎯 Sleek, low-profile */
    background: rgba(0, 50, 0, 0.3); /* Dark transparent green */
    margin-top: 8px;
    border-radius: 2px;
    overflow: hidden;
    border: 1px solid rgba(0, 255, 0, 0.1);
}

/* The actual filling bar */
.time-bar {
    height: 100%;
    width: 0%; /* Initial state */
    transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.time-bar.white {
    background: #00ff00;
    box-shadow: 0 0 8px rgba(0, 255, 0, 0.6);
}

.time-bar.black {
    background: #008800; /* Dimmer for the opponent */
    box-shadow: 0 0 8px rgba(0, 136, 0, 0.4);
}


/* GEOMETRY LOCK — do not size squares with min-width (breaks 8x8 grid) */
#main-grid {
  display: grid !important;
  grid-template-columns: repeat(8, 1fr) !important;
  grid-template-rows: repeat(8, 1fr) !important;
  overflow: hidden !important;
  background: transparent !important;
}
#main-grid > .square {
  min-width: 0 !important;
  min-height: 0 !important;
  width: 100% !important;
  height: 100% !important;
  aspect-ratio: auto !important;
}


/* LICHESS CG KILL SWITCH v0.36 */
/* Chessground model wins: no CSS grid on public/mobile chess pages */
body.chess-page #main-grid,
body.m-body-chess #main-grid {
  display: block !important;
  grid-template-columns: none !important;
  grid-template-rows: none !important;
}
body.chess-page #main-grid > .square,
body.m-body-chess #main-grid > .square {
  min-width: 0 !important;
  width: 12.5% !important;
  height: 12.5% !important;
  position: absolute !important;
}
