/* styles.css */

/* Reset default browser styles */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  /* Dark theme tokens */
  --bg: #0b1020;
  --surface: #121a2b;
  --surface-2: #0f172a;
  --text: #e5e7eb;
  --muted: #94a3b8;
  --border: #334155;

  --button: #1f2937;
  --button-hover: #374151;

  --danger: #b91c1c;
  --danger-hover: #991b1b;

  --square-a: #111827;
  --square-b: #1f2937;

  --highlight: rgba(239, 68, 68, 0.60);
  --premove: rgba(255, 255, 255, 0.18);
}

body {
  display: flex;
  flex-direction: column;
  align-items: center;
  font-family: Arial, sans-serif;
  background-color: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding: 20px;
  overflow-x: hidden;
}

h1 {
  margin-bottom: 20px;
  text-align: center;
  color: var(--text);
}

/* Intro Screen */
#intro-screen {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background-color: rgba(11,16,32,0.96);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.intro-button {
  padding: 10px 20px;
  margin: 10px;
  font-size: 16px;
  cursor: pointer;
  border: none;
  background-color: var(--button);
  color: #fff;
  border-radius: 5px;
  transition: background-color 0.2s;
}
.intro-button:hover {
  background-color: var(--button-hover);
}

/* Hidden sub-panels in intro */
#difficulty-selection,
#profile-settings,
#time-selection,
#simulation-selection,
#multiplayer-menu {
  display: none;
  flex-direction: column;
  align-items: center;
  margin-top: 20px;
}

#avatar-editor {
  display: none;
  flex-direction: column;
  align-items: center;
}
#avatar-grid {
  display: grid;
  grid-template-columns: repeat(8, 30px);
  grid-template-rows: repeat(8, 30px);
  gap: 2px;
  margin-bottom: 20px;
}
.avatar-cell {
  width: 30px;
  height: 30px;
  background-color: var(--surface);
  border: 1px solid #ccc;
  cursor: pointer;
}
.avatar-cell.active {
  background-color: var(--muted);
}

/* MAIN LAYOUT / BOARD SECTION */
#main-layout {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 1600px;
}

#game-container {
  display: flex;
  flex-direction: row;
  align-items: stretch;
  justify-content: flex-start;
  width: 100%;
  margin-top: 20px;
}

#board-wrapper {
  position: relative;
  display: inline-block;
  width: clamp(300px, 70vw, 800px);
  aspect-ratio: 1 / 1;
}

#board {
  position: relative;
  width: 100%;
  height: 100%;

  display: grid;
  grid-template-columns: repeat(8,1fr);
  grid-template-rows: repeat(8,1fr);
  border: 2px solid var(--border);
}

/* Column and row labels */
.board-labels.col-labels {
  position: absolute;
  pointer-events: none;
  opacity: 0.3;
  font-size: 14px;
  color: var(--muted);
  text-align: center;
}

.board-labels.row-labels {
  position: absolute;
  pointer-events: none;
  opacity: 0.3;
  font-size: 14px;
  color: var(--muted);
  text-align: center;
}

/* top row of letters */
.board-labels.col-labels {
  top: -20px;
  left: 0;
  width: 100%;
  height: 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 4px;
}

/* left column of numbers */
.board-labels.row-labels {
  left: -20px;
  top: 0;
  height: 100%;
  width: 20px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  padding: 4px 0;
}
.square {
  position: relative;
  width: 100%;
  height: 100%;
}

/* Side panel */
#side-panel {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  width: 500px; /* or your chosen width */
}

/* Opponent area (top) */
#player2-top {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: center;
  flex: 0 0 auto;
  padding-bottom: 10px;
  margin-top: 0;
}

/* Middle panel for status, surrender, etc. */
#middle-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 0;
}
/* Force the status area to stay a fixed height */
#status {
  font-size: 16px;
  text-align: center;
  margin-bottom: 10px;
  width: 90%;
  word-wrap: break-word;
  white-space: normal;           /* <--- wraps text onto new lines */
  overflow-wrap: anywhere;       /* <--- ensures long words also break */
  text-overflow: clip;

  /* New lines below: fix the height so it won't expand */
  min-height: 40px;      /* Enough for one line of text at 16px + some buffer */
  max-height: 80px;      /* Lock it to a single line, or 2 lines if you pick a bigger number */
  overflow: hidden;      /* Hide overflow if the text is bigger than 40px height */
  text-overflow: ellipsis; /* Optionally show "..." if white-space is 'nowrap' */
  white-space: nowrap;   /* If you want it all on one line max */
}
#surrender-button {
  padding: 10px 20px;
  font-size: 16px;
  cursor: pointer;
  border: none;
  background-color: var(--danger);
  color: #fff;
  border-radius: 5px;
  transition: background-color 0.2s;
}
#surrender-button:hover {
  background-color: var(--danger-hover);
}

/* Bottom panel: local user */
#player1-bottom {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  flex: 0 0 auto;
  padding-top: 10px;
  margin-bottom: 0;
}

/* CAPTURED AREA:
   8 columns × 44px => 352px wide, 2 rows × 44px => 88px tall
*/
.captured {
  display: grid;
  grid-template-columns: repeat(8, 44px);
  grid-template-rows: repeat(2, 44px);
  width: 352px;
  height: 88px;
  border: 1px solid var(--border);
  background-color: var(--surface);
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}
.captured .piece {
  width: 80%;
  height: 80%;
  position: relative;
  top: 10%;
  left: 10%;
  border-radius: 50%;
  cursor: default;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: inherit; /* color set in UI or pieces logic */
  transition: none;
  border: 1px solid transparent;
}
.captured .piece-line {
  position: absolute;
  left: 48%;
  top: 15%;
  width: 6%;
  height: 35%;
  background-color: black;
  transform-origin: bottom center;
}

/* Export button if used */
#export-button {
  padding: 10px 20px;
  font-size: 16px;
  cursor: pointer;
  border: none;
  background-color: #0066cc;
  color: #fff;
  border-radius: 5px;
  transition: background-color 0.2s;
  align-self: center;
}
#export-button:hover {
  background-color: #004d99;
}

/* Board squares white/grey */
.white {
  background-color: var(--square-a);
  transition: background 0.5s ease;
}
.grey {
  background-color: var(--square-b);
}

.player1-turn .white {
    background: linear-gradient(135deg, rgba(0,128,0,0.2), rgba(0,100,0,0.2));
}

.player2-turn .white {
    background: linear-gradient(135deg, rgba(255,165,0,0.2), rgba(255,140,0,0.2));
}

/*
   On-board .piece => 80% fill, anchored top/left 10%.
   Lines pinned by % => T/V shapes are fluid.
*/
.piece {
  position: absolute;
  width: 80%;
  height: 80%;
  border-radius: 50%;
  top: 10%;
  left: 10%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: inherit;  /* color from pieces.js */
  transition: transform 0.2s;
  border: 2px solid transparent;
}
/* Lines inside on-board pieces => pinned at left:48%, top:15% for T/V shapes */
.piece-line {
  position: absolute;
  left: 48%;
  top: 15%;
  width: 6%;   /* line thickness = 6% of piece width */
  height: 35%; /* line length = 35% of piece height */
  background-color: black;
  transform-origin: bottom center;
}
.piece-line.king-size {
  left: 48%;
  top: 15%;
  height: 35%;
}

/* Hover & Selection states */
.piece:hover {
  transform: scale(1.1);
}
.selected {
  outline: 3px solid yellow;
}

/* Highlighted squares (normal move) => red circle */
.square.highlighted::after {
  content: '';
  position: absolute;
  width: 30%;
  height: 30%;
  background-color: var(--highlight);
  border-radius: 50%;
  top: 35%;
  left: 35%;
  pointer-events: none;
}

/* Drag Over effect */
.square.drag-over {
  border: 2px dashed red;
}

/* Tooltips */
.tooltip {
  position: absolute;
  background-color: var(--button);
  color: #fff;
  padding: 5px 8px;
  border-radius: 4px;
  font-size: 12px;
  top: -30px;
  left: 50%;
  transform: translateX(-50%);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
  white-space: nowrap;
  z-index: 10;
}
.show-tooltip .tooltip {
  opacity: 1;
}

/* The color palette row */
#avatar-color-palette {
  display: flex;
  align-items: center;
  margin-bottom: 20px;
}
.color-swatch {
  width: 30px;
  height: 30px;
  margin-right: 10px;
  border: 2px solid #999;
  cursor: pointer;
}
.color-swatch:hover {
  border-color: #222;
}

/* Simulation Player */
#simulation-player {
  display: none;
  flex-direction: column;
  align-items: center;
  margin-top: 20px;
}
#replay-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  margin-top: 10px;
}
#replay-controls button {
  padding: 5px 10px;
  margin-right: 10px;
  font-size: 14px;
  cursor: pointer;
}
#replay-slider {
  width: 300px;
  margin-right: 10px;
}
#replay-share {
  margin-top: 20px;
  text-align: center;
}
#replay-share input {
  text-align: center;
}
#simulation-back-button-container {
  margin-top: 20px;
}
#simulation-back-button {
  padding: 10px 20px;
  font-size: 16px;
  cursor: pointer;
  border: none;
  background-color: var(--danger);
  color: #fff;
  border-radius: 5px;
  transition: background-color 0.2s;
}
#simulation-back-button:hover {
  background-color: var(--danger-hover);
}
.piece.moved {
  border: 2px solid yellow;
  animation: highlightMove 0.5s ease-in-out;
}
@keyframes highlightMove {
  0%   { border-color: yellow; }
  50%  { border-color: red;    }
  100% { border-color: yellow; }
}

/* Notification styling */
#notification {
  position: fixed;
  top: 20px;
  right: 20px;
  background-color: #ffc107;
  color: #212529;
  padding: 10px 20px;
  border-radius: 5px;
  display: none;
  z-index: 1001;
}
#notification.error {
  background-color: #dc3545;
  color: #fff;
}
#notification.success {
  background-color: #28a745;
  color: #fff;
}
.disabled-overlay {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.22);
  z-index: 9999;
  pointer-events: none; /* visual only; game logic blocks moves */
}

.disabled-overlay.locked {
  background: rgba(0,0,0,0.35);
  pointer-events: all;
  cursor: not-allowed;
}

.active-player {
  outline: none;
  position: relative;
  z-index: 1;
  box-shadow: 0 0 0 3px rgba(155, 77, 255, 0.85), 0 0 22px rgba(155, 77, 255, 0.55);
  border: 2px solid var(--accent);
}

/* Make turn ownership clearer by highlighting the full player panel */
#player2-top.active-turn,
#player1-bottom.active-turn {
  border: 2px solid rgba(155, 77, 255, 0.75);
  box-shadow: 0 0 0 3px rgba(155, 77, 255, 0.22), 0 0 24px rgba(155, 77, 255, 0.18);
  background: rgba(155, 77, 255, 0.07);
}

#player2-top.active-turn .timer,
#player1-bottom.active-turn .timer {
  text-shadow: 0 0 10px rgba(155, 77, 255, 0.65);
}

/* Premove squares => white circle */
.square.premove-highlighted::after {
  content: '';
  position: absolute;
  width: 30%;
  height: 30%;
  background-color: var(--premove);
  border-radius: 50%;
  top: 35%;
  left: 35%;
  pointer-events: none;
}

/* Responsive Adjustments */
@media (max-width:768px){
  #game-container {
    flex-direction: column;
    align-items: center;
  }
  #board {
    margin-right: 0;
    margin-bottom: 20px;
    width: 90vw;
    max-width: 600px;
  }
  #side-panel {
    width: 90vw;
    flex-direction: row;
    justify-content: space-around;
    margin-bottom: 20px;
  }
}

.premove-flash-origin {
  animation: pieceOriginFlash 0.8s infinite;
}
.premove-piece-clone {
  animation: pieceDestinationFlash 0.8s infinite;
}

@keyframes pieceOriginFlash {
  0%   { opacity: 1; }
  50%  { opacity: 0.2; }
  100% { opacity: 1; }
}
@keyframes pieceDestinationFlash {
  0%   { opacity: 0.2; }
  50%  { opacity: 1; }
  100% { opacity: 0.2; }
}

.tutorial-msg {
  font-weight: bold;
}

#piece-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 2000;
}


/* Dark theme extras */
#side-panel {
  color: var(--text);
}

#status {
  color: var(--text);
}

#profile-settings input,
#avatar-editor input,
#replay-share input,
input[type="text"] {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
}

.avatar-cell {
  background-color: var(--surface-2);
  border: 1px solid var(--border);
}

.color-swatch {
  border: 2px solid var(--border);
}

.color-swatch:hover {
  border-color: var(--muted);
}

/* Make the log panel readable in dark mode */
#live-log-panel {
  background: var(--surface-2);
  border-color: var(--border) !important;
  color: var(--text);
}


/* Modal (Rules / Help) */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  padding: 20px;
}

.modal {
  width: min(860px, 95vw);
  max-height: 85vh;
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 18px 14px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.55);
  color: var(--text);
}

.modal h2 {
  margin-bottom: 10px;
}

.modal h3 {
  margin-top: 14px;
  margin-bottom: 6px;
}

.modal ul {
  margin-left: 18px;
}

.modal .muted {
  color: var(--muted);
}
