/* ============================================================
   TECTONIC GRAND — STYLESHEET
   ============================================================ */

/* ============================================================
   1. BASE
   ============================================================ */

*, *::before, *::after {
  box-sizing: border-box;
}


html, body {
  scrollbar-width: none;
}

html::-webkit-scrollbar,
body::-webkit-scrollbar {
  display: none;
}

body {
  background-color: #050508;
  background-image: url('/assets/bg.jpg');
  background-size: 100% 100%;
  background-position: center center;
  background-repeat: no-repeat;
  background-attachment: scroll;
  color: white;
  font-family: 'Rajdhani', Arial, sans-serif;
  text-align: center;
  margin: 0;
  padding: 0;
  min-height: 100vh;
  overflow: hidden;
}

body.lobby-page {
  overflow-y: auto;
  overflow-x: hidden;
}

h1, h2 {
  font-family: 'Cinzel', serif;
  letter-spacing: 0.05em;
}

.hidden {
  display: none !important;
}

/* ============================================================
   2. LOBBY
   ============================================================ */

.lobby {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh;
}

.time-options button {
  padding: 14px 28px;
  margin: 10px;
  font-size: 18px;
  cursor: pointer;
}

.diff-btn {
  padding: 8px 20px;
  margin: 4px;
  cursor: pointer;
  opacity: 0.5;
}

.diff-btn.active {
  opacity: 1;
  outline: 2px solid white;
}

/* ============================================================
   3. TOP BAR
   ============================================================ */


 #top-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 8px;
  z-index: 100;
  background: linear-gradient(to bottom, rgba(0,0,0,0.85), transparent);
  height: 58px;
}

#top-bar-left {
  text-align: left;
}

#top-bar-left h1 {
  font-family: 'Cinzel', serif;
  font-size: clamp(1.1rem, 2.4vw, 1.8rem);
  margin: 0;
  line-height: 1;
  color: white;
}

#top-bar-left #tagline {
  font-size: clamp(0.65rem, 1.1vw, 0.9rem);
  color: #aaa;
  margin: 0;
}

#top-bar-right {
  display: flex;
  gap: 4px;
  align-items: center;
  flex-wrap: nowrap;
}

#top-bar-right button {
  padding: clamp(5px, 0.8vh, 10px) clamp(10px, 1.4vw, 18px);
  font-size: clamp(0.78rem, 1.2vw, 1rem);
  font-family: 'Rajdhani', sans-serif;
  background: rgba(0,0,0,0.6);
  color: #ccc;
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

#top-bar-right button:hover {
  background: rgba(180, 60, 0, 0.5);
  border-color: rgba(255,100,0,0.6);
  color: white;
}

/* ============================================================
   4. STATUS TEXT
   ============================================================ */

#status {
  position: fixed;
  top: 58px;
  left: 0;
  right: 0;
  text-align: center;
  font-family: 'Cinzel', serif;
  font-size: clamp(0.8rem, 1.6vw, 1.15rem);
  letter-spacing: 0.08em;
  color: #dddddd;
  z-index: 99;
  background: none;
  padding: 3px 8px 16px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}
/* ============================================================
   5. GAME LAYOUT
   ============================================================ */

#game-layout {
  position: fixed;
  top: 82px;
  left: 0;
  right: 0;
  bottom: 0;
  height: calc(100dvh - 82px);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(4px, 1vw, 16px);
  padding: 0 8px 10px;
  visibility: hidden;
  overflow: hidden;
}

#board-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: auto;
  --board-size: min(72dvh, 82vw);
}

#board-wrapper {
  filter: drop-shadow(0 8px 20px rgba(0, 0, 0, 0.95));
  position: relative;
}

/* ============================================================
   6. CLOCKS
   ============================================================ */

.clock {
  font-size: clamp(1.4rem, 4vmin, 2.6rem);
  font-weight: bold;
  margin: clamp(2px, 0.8vh, 8px) 0;
  text-align: center;
  transition: opacity 0.3s ease;
  pointer-events: none;
  font-family: 'Rajdhani', sans-serif;
  letter-spacing: 0.05em;
  line-height: 1;
}

#clock-top {
  margin-bottom: clamp(2px, 0.5vh, 6px);
}

#clock-bottom {
  margin-top: clamp(4px, 1vh, 12px);
}

.clock.active {
  opacity: 1;
  font-weight: 700;
  color: white;
  text-shadow: 0 0 10px rgba(255,150,0,0.4);
}

.clock.inactive {
  opacity: 0.35;
  font-weight: 400;
}

.clock.clock-low {
  color: #ff4444;
  animation: blinkClock 0.6s infinite;
}

@keyframes blinkClock {
  50% { opacity: 0.3; }
}

/* ============================================================
   7. BOARD
   ============================================================ */

#board {
  --board-size: min(72dvh, 82vw);
  display: grid;
  grid-template-columns: repeat(11, 1fr);
  grid-template-rows: repeat(11, 1fr);
  gap: 1px;
  background: rgba(15, 10, 5, 0.92);
  padding: 8px;
  pointer-events: auto;
  border: 2px solid #8b4500;
  box-shadow:
    0 0 6px rgba(255, 80, 0, 0.3),
    0 0 20px rgba(0, 0, 0, 0.9);
  width: var(--board-size);
  height: var(--board-size);
  flex-shrink: 0;
  position: relative;
}


#board.black-view {
  transform: rotate(180deg);
}

#board.black-view .piece {
  transform: rotate(180deg);
}


#board-coords-bottom {
  display: grid;
  grid-template-columns: repeat(11, 1fr);
  width: var(--board-size);
  margin-left: 20px;
  padding: 0 8px;
  box-sizing: border-box;
}

@media (max-width: 768px) {
  #board-coords-bottom {
    width: min(90vw, 70dvh) !important;
    margin-left: 20px;
    padding: 0 8px;
  }
}

#board-coords-left {
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  width: 20px;
  padding: 8px 0;
  box-sizing: border-box;
}

#board-coords-top {
  display: none;
}

.coord-letter, .coord-number {
  font-size: clamp(9px, 1.1vw, 14px);
  font-family: 'Rajdhani', sans-serif;
  font-weight: 600;
  color: rgba(255, 140, 0, 0.6);
  text-align: center;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  pointer-events: none;
}

/* ============================================================
   8. SQUARES
   ============================================================ */

.square {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  pointer-events: auto;
  transition: background 0.2s, box-shadow 0.2s;
   touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.square[data-light="true"] {
  background: #5a3e1e; 
}

.square[data-light="false"] {
  background: #2a1a08; 
}

.square:hover {
  box-shadow: inset 0 0 6px rgba(0,0,0,0.6);
}

@media (max-width: 768px) {
  .square:hover {
    box-shadow: none;
  }
}

.square.void {
  background-color: #050505;
  transition: none !important;
}

.square.void.falling {
  animation: voidFall 1.2s ease-in forwards !important;
}

.square.last-move {
  background: rgba(255, 215, 0, 0.18);
}

.square.selected {
  outline: 3px solid #00b4d8;
}

.square.promotion-square {
  outline: 3px solid gold;
}

.square.king-in-check {
  box-shadow: 0 0 12px 4px rgba(255, 0, 0, 0.8);
  animation: pulseRed 1s infinite;
}

.square.compression-warning {
  animation: pulseWarning 1.5s infinite;
}

/* ============================================================
   9. MOVE DOTS
   ============================================================ */

.square.move {
  background-color: transparent !important;
  cursor: pointer;
}

.square.move::after {
  content: "";
  position: absolute;
  width: 30%;
  height: 30%;
  border-radius: 50%;
  background: rgba(0, 200, 180, 0.6);
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.square.move:has(.piece)::after {
  width: 92%;
  height: 92%;
  border-radius: 0;
  background: transparent;
  box-shadow: inset 0 0 0 4px rgba(0, 200, 180, 0.7);
}

.square.move:hover::after {
  background: rgba(0, 200, 180, 0.85);
}

.square.move:has(.piece):hover::after {
  box-shadow: inset 0 0 0 4px rgba(0, 200, 180, 1);
  background: transparent;
}

/* ============================================================
   10. PIECES
   ============================================================ */

.piece {
  width: 95%;
  height: 95%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  pointer-events: auto;
  background: transparent;
  transition: none;
}

.piece img {
  width: 100%;
  height: 100%;
}

.piece img[src*="king"] {
  transform: scale(1.05);
}

.piece.White img { filter: brightness(1.1) drop-shadow(0 0 4px rgba(120,200,255,0.7)) drop-shadow(0 0 8px rgba(80,160,255,0.35)); }
.piece.Black img { filter: brightness(0.06) contrast(1.6) drop-shadow(0 0 4px rgba(255,60,0,0.85)) drop-shadow(0 0 10px rgba(255,30,0,0.4)); }

@media (max-width: 768px) {
  .piece.White img { filter: brightness(1.1) drop-shadow(0 0 3px rgba(120,200,255,0.6)); }
  .piece.Black img { filter: brightness(0.06) contrast(1.6) drop-shadow(0 0 3px rgba(255,60,0,0.7)); }
}

.piece.moving {
  transform: scale(1.05);
}

.piece.blossom {
  animation: blossom 0.45s cubic-bezier(0.22, 1, 0.36, 1);
}

.piece-moving {
  position: fixed !important;
  pointer-events: none !important;
  z-index: 1000;
  transition: left 0.25s ease,
              top 0.25s ease;
  width: var(--piece-size);
  height: var(--piece-size);
  will-change: left, top;
}

@media (max-width: 768px) {
  .piece-moving {
    transition: left 0.15s ease, top 0.15s ease;
  }
}

.piece-gem-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 2;
}
/* ============================================================
   11. GRAVEYARDS
   ============================================================ */

.graveyard {
  width: clamp(60px, 9vw, 120px);
  min-width: clamp(60px, 9vw, 120px);
  flex-shrink: 0;
  align-self: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 0;
  background: transparent;
  padding: 4px 2px;
  overflow: hidden;
}

.graveyard-pieces-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 2px;
  width: 100%;
}

.graveyard .piece,
.graveyard-piece {
  width: clamp(26px, 3.6vw, 46px);
  height: clamp(26px, 3.6vw, 46px);
  pointer-events: none;
  opacity: 0.95;
  flex-shrink: 0;
}

.advantage {
  font-size: clamp(14px, 1.8vw, 22px);
  font-weight: 700;
  color: #aaa;
  padding: 4px 6px;
}

.advantage.winning {
  color: #ffffff;
}

/* ============================================================
   12. GAME OVER OVERLAY
   ============================================================ */

#game-over-overlay {
  background: transparent;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 10;
  pointer-events: auto;
}

#game-over-text {
  background: rgba(0,0,0,0.92);
  border: 1px solid #8b4500;
  box-shadow: 0 0 30px rgba(255,80,0,0.3), 0 0 60px rgba(255,40,0,0.1);
  padding: 32px 28px;
  text-align: center;
  position: relative;
  overflow: hidden;
  min-width: 260px;
  max-width: 340px;
}

#game-over-text::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(to right, transparent, #ff6600, #ffaa00, #ff6600, transparent);
}

#game-over-text::after {
  content: '';
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(to right, transparent, #ff6600, #ffaa00, #ff6600, transparent);
}

.game-over-label {
  font-size: 11px;
  letter-spacing: 0.3em;
  color: #ff8800;
  text-transform: uppercase;
  margin-bottom: 8px;
  font-family: 'Rajdhani', sans-serif;
}

.game-over-winner {
  font-family: 'Cinzel', serif;
  font-size: clamp(28px, 4vw, 42px);
  font-weight: 900;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
}

.game-over-winner.white {
  color: #f0ece0;
  text-shadow: 0 0 20px rgba(150,200,255,0.6);
}

.game-over-winner.black {
  color: #cc3300;
  text-shadow: 0 0 20px rgba(255,60,0,0.6);
}

.game-over-winner.draw {
  color: #aaa;
}

.game-over-wins {
  font-size: 12px;
  letter-spacing: 0.2em;
  color: #888;
  text-transform: uppercase;
  margin-bottom: 12px;
  font-family: 'Rajdhani', sans-serif;
}

.game-over-divider {
  height: 1px;
  background: linear-gradient(to right, transparent, #8b4500, transparent);
  margin: 14px 0;
}

.game-over-reason {
  font-size: 13px;
  color: #aaa;
  letter-spacing: 0.08em;
  margin-bottom: 22px;
  font-style: italic;
  font-family: 'Rajdhani', sans-serif;
}

.game-over-buttons {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.game-over-buttons button {
  padding: 9px 18px;
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  cursor: pointer;
  border-radius: 3px;
  font-family: 'Rajdhani', sans-serif;
  transition: all 0.2s;
}

.game-over-btn-primary {
  background: rgba(180,60,0,0.7);
  border: 1px solid #ff6600;
  color: white;
}

.game-over-btn-primary:hover {
  background: rgba(220,80,0,0.9);
}

.game-over-btn-secondary {
  background: transparent;
  border: 1px solid #555;
  color: #888;
}

.game-over-btn-secondary:hover {
  border-color: #888;
  color: #ccc;
}

/* ============================================================
   13. PROMOTION BANNER
   ============================================================ */

#promotion-banner {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  pointer-events: auto;
}

#promotion-banner.hidden {
  display: none;
  pointer-events: none;
}

.promotion-content {
  background: #111;
  padding: 24px;
  border-radius: 12px;
  box-shadow: 0 0 30px rgba(0,0,0,0.6);
}

.promotion-content h2 {
  font-family: 'Cinzel', serif;
  margin-bottom: 12px;
}

.promotion-options {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.promotion-options button {
  background: rgba(0,0,0,0.8);
  border: 1px solid #8b4500;
  border-radius: 8px;
  padding: 8px;
  cursor: pointer;
  width: 70px;
  height: 70px;
  transition: border-color 0.2s;
}

.promotion-options button:hover {
  border-color: #ff6600;
}

.promotion-options button img {
  width: 100%;
  height: 100%;
}

/* ============================================================
   14. DRAW / REMATCH BANNERS
   ============================================================ */

#draw-response {
  position: fixed;
  top: 62px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  background: rgba(0,0,0,0.9);
  padding: 8px 20px;
  border: 1px solid #8b4500;
  border-radius: 8px;
  display: flex;
  gap: 10px;
  align-items: center;
  font-family: 'Rajdhani', sans-serif;
  font-size: 0.9rem;
}

#draw-response::before {
  content: "Draw offered — accept?";
  color: #ccc;
  margin-right: 4px;
  white-space: nowrap;
}

#draw-response.hidden {
  display: none;
}

#rematch-banner {
  position: fixed;
  top: 62px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  background: rgba(0,0,0,0.9);
  padding: 8px 20px;
  border: 1px solid #8b4500;
  border-radius: 8px;
  display: flex;
  gap: 10px;
  align-items: center;
  font-family: 'Rajdhani', sans-serif;
  font-size: 0.9rem;
}

#rematch-banner.hidden {
  display: none;
}

/* ============================================================
   15. ANIMATIONS
   ============================================================ */

@keyframes pulseWarning {
  0%   { box-shadow: inset 0 0 6px rgba(255, 80, 80, 0.4); }
  50%  { box-shadow: inset 0 0 16px rgba(255, 80, 80, 1); }
  100% { box-shadow: inset 0 0 6px rgba(255, 80, 80, 0.4); }
}

@keyframes pulseRed {
  0%   { box-shadow: 0 0 8px rgba(255, 0, 0, 0.6); }
  50%  { box-shadow: 0 0 16px rgba(255, 0, 0, 1); }
  100% { box-shadow: 0 0 8px rgba(255, 0, 0, 0.6); }
}

@keyframes voidFall {
  0%   { opacity: 1; transform: scale(1) translateY(0); background: #5a3e1e; }
  100% { opacity: 0; transform: scale(0.75) translateY(18px); background: #050505; }
}

.square.falling {
  pointer-events: none;
}

@keyframes blossom {
  0%   { transform: scale(0.6); opacity: 0; }
  60%  { transform: scale(1.12); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

/* ============================================================
   16. RESPONSIVE
   ============================================================ */

@media (max-width: 768px) {
  #top-bar {
    height: 44px;
    padding: 8px 12px;
  }

#top-bar-left h1 {
  font-size: 0.9rem;
  white-space: nowrap;
}

#top-bar-left #tagline {
  display: none;
}

  #top-bar-left #tagline {
  display: block;
  font-size: 0.62rem;
}

  #top-bar-right button {
    padding: 6px 11px;
    font-size: 0.82rem;
  }

  #status {
    top: 44px;
    font-size: 0.78rem;
    padding: 3px 8px;
    letter-spacing: 0.04em;
  }

  #game-layout {
  top: 62px;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex !important;
  flex-direction: column !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 6px;
  padding: 8px 0;
  overflow-y: auto;
}

  #board-container {
    order: 2;
    width: 96vw;
    height: auto;
    flex-shrink: 0;
  }

#board {
  --board-size: min(90vw, 70dvh) !important;
}

  #graveyard-black {
    order: 1;
    width: 96vw !important;
    min-width: 96vw !important;
    height: 44px !important;
    flex-direction: row !important;
    flex-wrap: wrap !important;
    justify-content: flex-start !important;
    align-self: auto !important;
    padding: 3px 6px;
  }

  #graveyard-white {
    order: 3;
    width: 96vw !important;
    min-width: 96vw !important;
    height: 44px !important;
    flex-direction: row !important;
    flex-wrap: wrap !important;
    justify-content: flex-start !important;
    align-self: auto !important;
    padding: 3px 6px;
  }

  .graveyard-pieces-grid {
    flex-direction: row !important;
    flex-wrap: wrap !important;
    justify-content: flex-start;
    gap: 3px;
  }

  .graveyard .piece,
  .graveyard-piece {
    width: 24px;
    height: 24px;
  }

  .advantage {
    font-size: 13px;
    padding: 2px 6px;
  }

  .clock {
    font-size: clamp(1.1rem, 4.5vw, 1.8rem);
    margin: 2px 0;
  }

  #clock-top {
    margin-bottom: 10px;
  }

  #clock-bottom {
    margin-top: 10px;
  }

  #top-bar-right {
  display: none;
}

#mobile-controls {
  display: flex !important;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background: linear-gradient(to top, rgba(0,0,0,0.95), transparent);
  padding: 8px 6px 12px;
  gap: 6px;
  justify-content: center;
  flex-wrap: wrap;
}

#mobile-controls button {
  padding: 8px 14px;
  font-size: 0.85rem;
  font-family: 'Rajdhani', sans-serif;
  background: rgba(0,0,0,0.7);
  color: #ccc;
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
}

#mobile-controls button:hover {
  background: rgba(180, 60, 0, 0.5);
  border-color: rgba(255,100,0,0.6);
  color: white;
}
}

@media (max-height: 700px) and (min-width: 600px) {
  #board {
    --board-size: min(58vh, 75vw);
  }

  .clock {
    font-size: clamp(0.9rem, 2.5vmin, 1.4rem);
    margin: 1px 0;
  }

  #clock-bottom {
    margin-top: 4px;
  }
}

@media (orientation: landscape) and (max-height: 500px) {
  #top-bar {
    height: 26px;
    padding: 3px 10px;
  }

  #top-bar-left #tagline {
    display: none;
  }

  #status {
    top: 26px;
    font-size: 0.6rem;
  }

  #game-layout {
    top: 44px;
    gap: 4px;
  }

  #board {
    width: min(88vh, 65vw);
    height: min(88vh, 65vw);
  }

  .clock {
    font-size: 1rem;
    margin: 1px 0;
  }

  #clock-bottom {
    margin-top: 4px;
  }
}

@media (max-width: 768px) {
  #board {
    -webkit-overflow-scrolling: touch;
    transform: translateZ(0);
  }
  .square {
    will-change: auto;
  }
  .piece img {
    will-change: auto;
    transform: translateZ(0);
  }
}

/* Move list panel */


#move-list-body::-webkit-scrollbar {
  width: 0;
  display: none;
}

#move-list-body {
  scrollbar-width: none;
}

.move-item {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 7px 10px;
  font-family: 'Rajdhani', sans-serif;
  font-size: 0.92rem;
  color: #ccc;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  cursor: default;
}

.move-item:hover {
  background: rgba(255,255,255,0.04);
}

.move-item.white-move {
  background: rgba(255,255,255,0.02);
}

.move-item.black-move {
  background: rgba(0,0,0,0.2);
}

.move-item .move-num {
  color: #555;
  font-size: 0.7rem;
  min-width: 16px;
}

.move-piece-img {
  width: 20px;
  height: 20px;
  object-fit: contain;
  flex-shrink: 0;
}

.move-piece-img.black-piece {
  filter: brightness(0.06) contrast(1.6) drop-shadow(0 0 2px rgba(255,60,0,0.8));
}

.move-arrow {
  color: #ff6600;
  font-size: 0.65rem;
}

.move-square {
  font-size: 0.88rem;
  letter-spacing: 0.05em;
}

/* Mobile move strip */
.move-chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 3px 7px;
  background: rgba(0,0,0,0.5);
  border: 1px solid rgba(139,69,0,0.3);
  border-radius: 3px;
  font-family: 'Rajdhani', sans-serif;
  font-size: 0.72rem;
  color: #ccc;
  white-space: nowrap;
  flex-shrink: 0;
}

.move-chip.latest {
  border-color: #ff6600;
  color: white;
}

#board-container {
  --board-size: min(72dvh, 82vw);
}

@media (max-width: 768px) {
  #move-list-panel { display: none !important; }
  #move-list-mobile { display: block !important; }
}

#move-list-panel {
  height: min(72dvh, 82vw) !important;
  top: calc(50% + 20px) !important;
  transform: translateY(-50%) !important;
}

@media (max-width: 768px) {
  #move-list-panel {
    display: none !important;
  }
}