/* Modern Styles (Restored Layout) */
@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap');

:root {
  --glass-bg: rgba(255, 255, 255, 0.1);
  --glass-border: 1px solid rgba(255, 255, 255, 0.2);
  --glass-shadow: 0 4px 30px rgba(0, 0, 0, 0.5);
  --accent-color: #ff3548;
  --secondary-color: #36c877;
  --text-color: #ffffff;
}

body {
  font-family: 'Roboto', sans-serif;
  margin: 0;
  padding: 0;
  background: radial-gradient(circle at center, #1a1a2e, #000000);
  width: 100%;
  color: var(--text-color);
  text-align: center;
}

/* Container */
.game-container {
  display: grid;
  /* Original layout: Left Sidebar | Board | Right Sidebar */
  grid-template-columns: 250px 1fr 250px;
  grid-template-rows: auto 1fr auto;
  min-height: 100vh;
  gap: 0px;
  padding: 20px;
  box-sizing: border-box;
}

/* Logo */
#logo {
  grid-column: 1 / 2;
  grid-row: 1 / 2;
  max-width: 200px;
  height: auto;
  margin-bottom: 20px;
  /* Removed absolute positioning to flow naturally in grid/flex */
}

/* Sidebars */
#left-sidebar {
  grid-column: 1 / 2;
  grid-row: 2 / 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 15px;
  background: rgba(20, 20, 30, 0.6);
  /* Darker semi-transparent bg */
  backdrop-filter: blur(10px);
  border: var(--glass-border);
  border-radius: 16px;
  padding: 20px;
  /* Readability fix */
  color: #ffffff !important;
  /* Force white text */
  font-weight: 500;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9);
}

#resultText {
  font-size: 1.1em;
  line-height: 1.4;
  background: rgba(0, 0, 0, 0.2);
  /* Semi-transparent background for text */
  padding: 10px;
  border-radius: 8px;
  width: 100%;
}

/* MAC Cards Deck */
#mac-card-deck {
  width: 120px;
  height: 160px;
  background: linear-gradient(135deg, #6e45e2, #88d3ce);
  border-radius: 12px;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.5), inset 0 0 10px rgba(255, 255, 255, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  border: 2px solid rgba(255, 255, 255, 0.3);
  margin-top: 10px;
}

#mac-card-deck:hover {
  transform: translateY(-5px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.6), inset 0 0 10px rgba(255, 255, 255, 0.4);
}

#mac-card-deck:active {
  transform: scale(0.95);
}

.deck-text {
  color: white;
  font-weight: bold;
  text-align: center;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
  font-size: 1.1em;
  pointer-events: none;
  /* Let clicks pass to container */
}

#right-sidebar {
  grid-column: 3 / 4;
  grid-row: 2 / 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 15px;
  background: rgba(20, 20, 30, 0.6);
  /* Darker semi-transparent bg */
  backdrop-filter: blur(10px);
  border: var(--glass-border);
  border-radius: 16px;
  padding: 20px;
  justify-content: flex-start;
  padding-top: 20px;
  color: #ffffff !important;
  /* Force white text */
  font-weight: 500;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9);
}

#active-player-info {
  background: rgba(0, 0, 0, 0.2);
  padding: 15px;
  border-radius: 8px;
  width: 100%;
  text-align: center;
  margin-bottom: 20px;
}

#active-player-token {
  width: 50px;
  height: 50px;
  margin: 10px auto;
  position: relative;
  /* Override absolute positioning from .token class for this specific element */
  top: auto;
  left: auto;
  transform: none;
}

#players-list-container {
  width: 100%;
  text-align: left;
}

#all-players-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

#all-players-list li {
  padding: 8px 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

#all-players-list li:last-child {
  border-bottom: none;
}

#all-players-list li.active {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  font-weight: bold;
}

/* Central Board Area */
#game-board_div {
  grid-column: 2 / 3;
  grid-row: 2 / 3;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  /* Align top */
  overflow: auto;
  /* padding: 20px; */
  margin-top: -40px;
}

#game-board {
  border-collapse: separate;
  border-spacing: 5px;
  background-image: url('/img/pole.jpg');
  background-size: cover;
  box-shadow: 0 0 20px rgba(255, 255, 255, 0.1);
  padding: 33px 34px;
}

#game-board td {
  /* Restored original large size */
  /* width: 120px; */
  /* height: 120px; */
  width: 105px;
  height: 105px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  position: relative;
  color: transparent;
  /* Text hidden */
  cursor: pointer;
}

/* History - Bottom Full Width */
#players-list {
  grid-column: 1 / 4;
  grid-row: 3 / 4;
  background: var(--glass-bg);
  backdrop-filter: blur(10px);
  border: var(--glass-border);
  border-radius: 16px;
  padding: 20px 20px 60px 20px;
  /* More bottom padding */
  margin-top: 20px;
  min-height: 200px;
  /* "2nd screen" feel */
}

ul#player-info {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 20px;
  list-style: none;
  padding: 0;
}

#player-info li {
  background: rgba(255, 255, 255, 0.1);
  padding: 20px;
  border-radius: 12px;
  min-width: 300px;
  max-height: 400px;
  /* Prevent it from growing too long */
  overflow-y: auto;
  /* Add scroll if history is long */
  text-align: left;
  border: 1px solid rgba(255, 255, 255, 0.1);
  font-size: 1.1em;
  line-height: 1.5;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2);
}

#player-info li strong {
  font-size: 1.3em;
  display: block;
  margin-bottom: 10px;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

/* Buttons */
button {
  width: 100%;
  padding: 12px 20px;
  font-size: 16px;
  font-weight: bold;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  margin-bottom: 10px;
}

button:hover {
  transform: translateY(-2px);
}

#roll-dice-btn {
  background: linear-gradient(135deg, #ff3548, #ff7a85);
  color: white;
}

#enterGameBtn {
  background: linear-gradient(135deg, #36c877, #6cfcb0);
  color: white;
}

#add-player-btn {
  background: linear-gradient(135deg, #ffc98d, #ffdea8);
  color: #333;
}

#reset-game-btn {
  background: linear-gradient(135deg, #ff4b1f, #ff9068);
  color: white;
}

/* Dice Container */
#threejs-canvas {
  width: 200px;
  height: 200px;
  margin-bottom: 20px;
}

/* Tokens */
.token {
  width: 35px;
  height: 35px;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4);
  transition: transform 0.2s, box-shadow 0.2s;

  /* Text Centering */
  display: flex !important;
  /* Force flex */
  justify-content: center;
  align-items: center;
  color: white;
  font-weight: bold;
  font-size: 0.8em;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
  user-select: none;
  z-index: 10;
}

/* Shapes */
.token.circle {
  border-radius: 50%;
}

.token.square {
  border-radius: 4px;
}

.token.rounded {
  border-radius: 12px;
}

/* Clip-path shapes (keep background-color working) */
.token.triangle {
  clip-path: polygon(50% 0%, 0% 100%, 100% 100%);
  border-radius: 0;
}

.token.diamond {
  clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
  border-radius: 0;
}

.token.pentagon {
  clip-path: polygon(50% 0%, 100% 38%, 82% 100%, 18% 100%, 0% 38%);
  border-radius: 0;
}

.token.hexagon {
  clip-path: polygon(25% 0%, 75% 0%, 100% 50%, 75% 100%, 25% 100%, 0% 50%);
  border-radius: 0;
}

/* Modal */
/* Modal Overlay */
#modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.85);
  /* Dark overlay */
  z-index: 2000;
  display: flex;
  /* Flex to center content */
  justify-content: center;
  align-items: center;
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}

#modal.visible {
  opacity: 1;
  pointer-events: auto;
}

#modal.hidden {
  display: none;
}

/* Modal Content Box */
.modal-content {
  background: rgba(20, 20, 30, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 16px;
  padding: 30px;
  max-width: 90vw;
  max-height: 90vh;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.8);
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  transform: scale(0.9);
  transition: transform 0.3s ease;
  cursor: default;
  /* Prevent pointer events falling through */
}

#modal.visible .modal-content {
  transform: scale(1);
}

#modal img {
  max-width: 100%;
  max-height: 70vh;
  border-radius: 8px;
  margin-bottom: 20px;
}

#modal-text {
  font-size: 1.2em;
}

#close-modal {
  position: absolute;
  top: 10px;
  right: 20px;
  font-size: 40px;
  cursor: pointer;
  color: white;
  transition: color 0.3s;
}

#close-modal:hover {
  color: var(--accent-color);
}

/* Helpers */
.hidden {
  display: none !important;
}

/* Simple history table */
.history-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 10px;
  font-size: 0.9em;
}

.history-table td {
  padding: 4px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

/* =========================================
   Mobile Adaptation (Responsive Design)
   ========================================= */

@media (max-width: 900px) {
  .game-container {
    display: flex;
    flex-direction: column;
    padding: 10px;
    gap: 15px;
    height: auto;
    min-height: auto;
  }

  /* Reorder for mobile flow */
  #left-sidebar {
    order: 1;
    /* Dice & Controls first */
    width: 100%;
    margin: 0;
    box-shadow: none;
    box-sizing: border-box;
  }

  #game-board_div {
    order: 2;
    /* Board second */
    width: 100%;
    max-width: 100vw;
    /* Prevent viewport overflow */
    margin-top: 0;
    display: block;
    /* Standard block */
    overflow-x: auto;
    /* Horizontal Scroll */
    -webkit-overflow-scrolling: touch;
    touch-action: pan-x pan-y;
    padding: 10px 0;

    /* Scrollbar Styling */
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.3) transparent;
  }

  #game-board_div::-webkit-scrollbar {
    height: 8px;
  }

  #game-board_div::-webkit-scrollbar-thumb {
    background-color: rgba(255, 255, 255, 0.3);
    border-radius: 4px;
  }

  #game-board {
    margin: 0 auto;
    /* Force minimum width to trigger scroll on small screens */
    /* 9 columns * 105px + spacing ~ 1000px */
    min-width: 960px;
    width: 960px;
    /* Prevent table compression */
    table-layout: fixed;
  }

  /* Optional: scale down slightly? */
  /* transform-origin: top center; */


  #right-sidebar {
    order: 3;
    /* Player Info third */
    width: 100%;
    margin: 0;
    box-sizing: border-box;
  }

  #players-list {
    order: 4;
    /* History last */
    width: 100%;
    margin-top: 20px;
    box-sizing: border-box;
    /* Prevent padding overflow */
  }

  /* Adjustments */
  #logo {
    max-width: 150px;
  }

  #threejs-canvas {
    width: 150px;
    height: 150px;
  }

  #modal-text {
    font-size: 1em;
  }

  /* Touch target improvements */
  button {
    padding: 15px;
    font-size: 1.1em;
  }
}

@media (max-width: 480px) {

  /* Hardcore mobile adjustments */
  #game-board {
    margin: 0 auto;
    /* Force minimum width to trigger scroll on small screens */
    min-width: 960px;
    width: 960px;
    table-layout: fixed;
  }

  .token {
    width: 30px;
    height: 30px;
  }

  #player-info li {
    min-width: 0;
  }

  /* Remove the 300px limit */
  .token {
    width: 30px;
    height: 30px;
  }
}

/* =========================================
   Export Button Styles (Global)
   ========================================= */
.player-info-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 5px;
}

.mini-export-btn {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: white;
  cursor: pointer;
  font-size: 1.2em;
  padding: 2px 8px;
  border-radius: 4px;
  transition: background 0.2s;
}

.mini-export-btn:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* Auth Overlay */
#auth-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: radial-gradient(circle at center, #1a1a2e, #000000);
  z-index: 5000;
  display: flex;
  justify-content: center;
  align-items: center;
  backdrop-filter: blur(10px);
}

#auth-box {
  background: rgba(20, 20, 30, 0.95);
  padding: 40px;
  border-radius: 24px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.9);
  text-align: center;
  width: 380px;
  animation: fadeIn 0.5s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

#auth-box h2 {
  margin-bottom: 10px;
  font-size: 2.2em;
  background: linear-gradient(135deg, #fff, #aaa);
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

#auth-box p {
  color: #ccc;
  margin-bottom: 25px;
}

.social-login {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 25px;
}

.auth-btn {
  display: block;
  padding: 14px;
  text-decoration: none;
  font-weight: bold;
  border-radius: 12px;
  transition: all 0.3s ease;
  color: white;
  text-align: center;
  font-size: 1.05em;
}

.vk-btn {
  background: #4C75A3;
}

.tg-btn {
  background: #0088cc;
}

.yandex-btn {
  background: white;
  color: black !important;
  border: 1px solid #e0e0e0;
}

.auth-btn:hover {
  transform: translateY(-3px);
  filter: brightness(1.1);
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

.divider {
  display: flex;
  align-items: center;
  text-align: center;
  color: #666;
  margin: 20px 0;
}

.divider::before,
.divider::after {
  content: '';
  flex: 1;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.divider:not(:empty)::before {
  margin-right: .5em;
}

.divider:not(:empty)::after {
  margin-left: .5em;
}

#login-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#login-input,
#password-input,
.auth-input {
  width: 100%;
  padding: 14px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.1);
  color: white;
  font-size: 1em;
  box-sizing: border-box;
  transition: all 0.3s;
  margin-bottom: 10px;
}

#login-input:focus,
#password-input:focus,
.auth-input:focus {
  border-color: #4da6ff;
  background: rgba(255, 255, 255, 0.15);
  outline: none;
}

#email-login-btn {
  background: linear-gradient(135deg, #6e45e2, #88d3ce);
  color: white;
  margin-top: 5px;
}

/* Password Toggle Styles */
.password-container {
  position: relative;
  width: 100%;
}

.password-toggle {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: none !important;
  border: none !important;
  padding: 0 !important;
  margin: 0 !important;
  width: auto !important;
  cursor: pointer;
  font-size: 1.2em;
  opacity: 0.6;
  z-index: 10;
  box-shadow: none !important;
}

.password-toggle:hover {
  opacity: 1;
  transform: translateY(-50%) scale(1.1);
}

/* Modal text overlap fix */
#modal-text {
  font-size: 1.2em;
  padding-top: 20px;
  /* Space for the close button */
  padding-right: 10px;
  padding-left: 10px;
  word-wrap: break-word;
  max-width: 100%;
}