:root {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-tertiary: #334155;
  --text-active: #f8fafc;
  --text-muted: #94a3b8;
  --accent-color: #3b82f6;
  --accent-hover: #2563eb;
  --success-color: #10b981;
  --danger-color: #ef4444;
  --board-light: #f0d9b5;
  --board-dark: #b58863;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Inter', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

body {
  background-color: var(--bg-primary);
  color: var(--text-active);
  display: flex;
  justify-content: center;
  align-items: flex-start;
  min-height: 100vh;
  padding: 20px;
}

#app-container {
  display: flex;
  gap: 30px;
  max-width: 1200px;
  width: 100%;
}

/* Sidebar Navigation */
.sidebar {
  width: 280px;
  background-color: var(--bg-secondary);
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
  display: flex;
  flex-direction: column;
  gap: 15px;
  transition: width 0.3s ease;
}

#btn-toggle-sidebar {
  background: none;
  border: none;
  color: var(--text-active);
  font-size: 24px;
  cursor: pointer;
  text-align: left;
  margin-bottom: 5px;
}

.sidebar.collapsed {
  width: 80px;
  align-items: center;
}
.sidebar.collapsed #elo-display {
  display: none;
}
.sidebar.collapsed .nav-text {
  display: none;
}
.sidebar.collapsed .nav-btn {
  text-align: center;
  padding: 12px 0;
  width: 100%;
}
.sidebar.collapsed #btn-toggle-sidebar {
  text-align: center;
}
.nav-icon { display: none; font-weight: bold; font-size: 1.2rem; }
.sidebar.collapsed .nav-icon { display: inline; }

.elo-display {
  background: linear-gradient(135deg, var(--accent-color), #8b5cf6);
  border-radius: 12px;
  padding: 15px;
  text-align: center;
  margin-bottom: 20px;
  box-shadow: 0 4px 15px rgba(59, 130, 246, 0.3);
}

.elo-display span.label {
  display: block;
  font-size: 0.85rem;
  opacity: 0.9;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.elo-display span.value {
  display: block;
  font-size: 2rem;
  font-weight: bold;
}

.nav-btn {
  background-color: var(--bg-tertiary);
  color: var(--text-active);
  border: none;
  border-radius: 10px;
  padding: 12px 20px;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: left;
}

.nav-btn:hover {
  background-color: var(--accent-color);
  transform: translateX(5px);
}

.nav-btn.active {
  background-color: var(--accent-color);
  box-shadow: 0 4px 10px rgba(59, 130, 246, 0.4);
}

/* Main Area */
.main-content {
  flex-grow: 1;
  background-color: var(--bg-secondary);
  border-radius: 16px;
  padding: 30px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
  width: 100%;
}

.board-container {
  width: 100%;
  max-width: 500px;
  margin: 0 auto;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
  border-radius: 8px;
  overflow: hidden;
  touch-action: none;
}

/* Modal styles */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(15, 23, 42, 0.8);
  backdrop-filter: blur(5px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal {
  background-color: var(--bg-secondary);
  padding: 30px;
  border-radius: 16px;
  width: 400px;
  max-width: 90%;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
  transform: translateY(20px);
  transition: transform 0.3s ease;
}

.modal-overlay.active .modal {
  transform: translateY(0);
}

.modal h2 {
  margin-bottom: 20px;
  text-align: center;
}

.modal-form {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.modal-form label {
  font-size: 0.9rem;
  color: var(--text-muted);
}

.modal-form input, .modal-form select {
  width: 100%;
  padding: 12px;
  border-radius: 8px;
  border: 1px solid var(--bg-tertiary);
  background-color: var(--bg-primary);
  color: var(--text-active);
  font-size: 1rem;
}

.btn {
  background-color: var(--accent-color);
  color: white;
  border: none;
  border-radius: 8px;
  padding: 12px 20px;
  font-size: 1rem;
  font-weight: bold;
  cursor: pointer;
  transition: background-color 0.2s;
  text-align: center;
  margin-top: 10px;
}

.btn:hover {
  background-color: var(--accent-hover);
}

/* Game Wrapper & Timers */
.game-wrapper {
  width: 100%;
  max-width: 500px;
  display: flex;
  flex-direction: column;
}

.timer-bar {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: var(--bg-tertiary);
  padding: 10px 15px;
  border-radius: 8px;
  margin-bottom: 5px;
  margin-top: 5px;
  box-sizing: border-box;
}

.player-info {
  display: flex;
  align-items: center;
  gap: 15px;
}

.player-avatar {
  border-radius: 8px;
  background-color: var(--board-light);
  box-shadow: 0 2px 5px rgba(0,0,0,0.3);
  display: block;
}

.timer-name {
  font-weight: bold;
  font-size: 1.1rem;
  line-height: 1;
  margin: 0;
  display: flex;
  align-items: center;
}
.timer-time {
  font-family: inherit;
  font-size: 1.5rem;
  font-weight: bold;
  color: var(--text-active);
  background-color: rgba(0,0,0,0.5);
  padding: 5px 10px;
  border-radius: 5px;
  box-shadow: inset 0 2px 5px rgba(0,0,0,0.5);
  min-width: 80px;
  text-align: center;
}

.highlight-square-click {
  box-shadow: inset 0 0 3px 3px yellow;
}

/* View Sections */
.view-section {
  display: none;
  width: 100%;
  animation: fadeIn 0.3s ease;
}

.view-section.active {
  display: flex;
  flex-direction: column;
  align-items: center;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.game-controls {
  margin-top: 20px;
  display: flex;
  justify-content: space-between;
  width: 100%;
  max-width: 500px;
  align-items: center;
}

.status-text {
  font-weight: 500;
  color: var(--text-muted);
}

/* Activity Log */
.log-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.log-item {
  background-color: var(--bg-tertiary);
  padding: 15px;
  border-radius: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.log-item.win { border-left: 4px solid var(--success-color); }
.log-item.loss { border-left: 4px solid var(--danger-color); }
.log-item.draw { border-left: 4px solid var(--text-muted); }
.log-item.puzzle { border-left: 4px solid var(--accent-color); }

.log-date {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Puzzle feedback */
.puzzle-feedback {
  margin-top: 15px;
  padding: 15px;
  border-radius: 8px;
  text-align: center;
  font-weight: bold;
  display: none;
}
.puzzle-feedback.success {
  background-color: rgba(16, 185, 129, 0.2);
  color: var(--success-color);
  display: block;
}
.puzzle-feedback.error {
  background-color: rgba(239, 68, 68, 0.2);
  color: var(--danger-color);
  display: block;
}

/* Move History */
.move-history {
  font-size: 0.85rem;
  color: var(--text-muted);
  min-height: 31px;
  background-color: var(--bg-tertiary);
  margin: 5px 0;
  border-radius: 8px;
  padding: 7px 15px;
  overflow-x: auto;
  white-space: nowrap;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  display: none; /* hidden until game starts */
}
.move-history.top-history {
  margin-bottom: 10px;
}
.move-history.bottom-history {
  margin-top: 10px;
}
.move-history span {
  display: inline-block;
  margin-right: 15px;
}

/* Custom Webkit Scrollbar for Move History */
.move-history::-webkit-scrollbar {
  height: 6px;
}
.move-history::-webkit-scrollbar-track {
  background: transparent;
}
.move-history::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.5);
  border-radius: 10px;
}
.move-history::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}
.move-history::-webkit-scrollbar-button {
  display: none;
}

@media (max-width: 768px) {
  body {
    padding: 10px;
    align-items: flex-start;
  }
  #app-container {
    flex-direction: column;
    gap: 15px;
  }
  .sidebar { width: 100%; }
  
  .sidebar.collapsed {
    width: 100%;
    flex-direction: row;
    justify-content: center;
    padding: 10px 15px;
    gap: 15px;
  }
  .sidebar.collapsed #btn-toggle-sidebar {
    margin-bottom: 0;
    margin-right: auto;
  }
  .sidebar.collapsed .nav-btn {
    width: auto;
    padding: 10px 20px;
    flex-grow: 1;
    max-width: 80px;
  }
  
  .main-content {
    padding: 15px;
  }
}

/* Progress bar */
.puzzle-progress-wrapper {
  width: 100%;
  max-width: 500px;
  background-color: var(--bg-tertiary);
  border-radius: 8px;
  margin-bottom: 10px;
  overflow: hidden;
  position: relative;
  height: 25px;
}
.puzzle-progress-bar {
  height: 100%;
  background-color: var(--accent-color);
  width: 0%;
  transition: width 0.3s ease;
}
.puzzle-progress-text {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: bold;
  color: white;
  text-shadow: 1px 1px 2px rgba(0,0,0,0.5);
}
