/*
 * iamthus.xyz Chess Splash Page - Style Sheet (Flat Minimalist Theme)
 */

@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700;800&display=swap');

:root {
  --bg-dark: #161512;            /* Lichess flat dark background */
  --panel-bg: #262421;           /* Lichess flat panel card */
  --inner-bg: #1e1c18;           /* Lichess darker inner sections */
  --border-color: #3d3b38;       /* Flat border color */
  
  --border-active-public: #06b6d4;
  --border-active-owner: #8b5cf6;
  
  --color-public: #06b6d4;       /* Cyan */
  --color-owner: #a78bfa;        /* Light Violet */
  --color-text-primary: #bababa;  /* Flat gray text */
  --color-text-active: #ffffff;
  --color-text-secondary: #7c7a76;
  --color-accent: #f43f5e;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Outfit', sans-serif;
  background-color: var(--bg-dark);
  color: var(--color-text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  overflow-x: hidden;
  position: relative;
  padding: 2rem 1rem;
}

/* Main Layout Grid */
main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: 1300px;
  margin: 0 auto;
}

.game-container {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 1.5rem; /* Tighter gap to group board and panel */
  width: 100%;
  align-items: center;
}

@media (max-width: 1100px) {
  .game-container {
    grid-template-columns: 1fr;
    justify-items: center;
    gap: 2rem;
  }
}

/* Board Wrapper Container */
.board-area {
  display: flex;
  justify-content: flex-end; /* Align board to the right side of its column, next to the panel */
  align-items: center;
  width: 100%;
}

.board-wrapper {
  background: var(--panel-bg);
  border: 2px solid var(--border-color);
  border-radius: 8px;
  padding: 12px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
  transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

.board-wrapper.turn-public {
  border-color: var(--border-active-public);
  box-shadow: 0 0 20px rgba(6, 182, 212, 0.15), 0 10px 30px rgba(0,0,0,0.5);
}

.board-wrapper.turn-owner {
  border-color: var(--border-active-owner);
  box-shadow: 0 0 20px rgba(139, 92, 246, 0.15), 0 10px 30px rgba(0,0,0,0.5);
}

/* Chessground Board size constraint (Responsive to screen height - Enlarged) */
#chess-board, .board-wrapper .cg-wrap {
  width: 80vh;
  height: 80vh;
  max-width: 800px;
  max-height: 800px;
  min-width: 594px;  /* Aligns wrapper total min-height to 622px (594 + 24 padding + 4 border) */
  min-height: 594px; /* Aligns wrapper total min-height to 622px (594 + 24 padding + 4 border) */
  border-radius: 4px;
  overflow: hidden;
}

@media (max-width: 1100px) {
  .board-area {
    width: 100%;
    max-width: 526px;
    justify-content: center; /* Center horizontally on mobile */
  }

  .board-wrapper {
    width: 100%;
  }

  #chess-board, .board-wrapper .cg-wrap {
    width: 100%;
    height: auto;
    aspect-ratio: 1 / 1;
    min-width: 0;  /* Reset desktop min-width on mobile */
    min-height: 0; /* Reset desktop min-height on mobile */
  }
}

@media (max-width: 520px) {
  .board-wrapper {
    padding: 8px; /* Keep padding clean and matched */
  }
  body {
    padding: 1rem 0.5rem;
  }
}

/* Chessground custom theme styling override */
.cg-wrap board {
  background-size: cover;
}

/* Solid Clean Card (Info Panel) */
.info-panel {
  background: var(--panel-bg);
  border: 2px solid var(--border-color);
  border-radius: 8px;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  height: calc(80vh + 26px); /* Align height perfectly with 80vh board wrapper */
  max-height: 826px;
  min-height: 622px;         /* Match board wrapper total min-height (622px) */
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}

@media (max-width: 1100px) {
  .info-panel {
    height: auto;
    width: 100%;
    max-width: 526px; /* Exact same max-width as board wrapper */
  }
}

/* Turn Dashboard Indicator */
.turn-dashboard {
  background: var(--inner-bg);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 1rem;
  text-align: center;
}

.turn-badge {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 600;
  color: var(--color-text-secondary);
  margin-bottom: 0.4rem;
  display: block;
}

.turn-label {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--color-text-active);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Pulse animation dot */
.pulse-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 8px;
}

.public-active .pulse-dot {
  background-color: var(--color-public);
}

.owner-active .pulse-dot {
  background-color: var(--color-owner);
}

.turn-dashboard.public-active .turn-label {
  color: var(--color-public);
}

.turn-dashboard.owner-active .turn-label {
  color: var(--color-owner);
}

/* Move Log Section */
.history-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 0;
  gap: 0.5rem;
}

.history-title {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-secondary);
  font-weight: 600;
}

.moves-log {
  background: var(--inner-bg);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 0.75rem;
  overflow-y: auto;
  flex: 1;
  height: 0;
  min-height: 120px;
  display: grid;
  grid-template-columns: 40px 1fr 1fr;
  gap: 0.4rem 1rem;
  font-family: monospace;
  font-size: 1rem;
  align-content: start;
  position: relative;
}

.move-num {
  color: var(--color-text-secondary);
  text-align: right;
  padding-right: 0.5rem;
}

.move-item {
  color: var(--color-text-primary);
  cursor: pointer;
  padding: 0.15rem 0.35rem;
  border-radius: 3px;
  transition: all 0.1s ease;
  user-select: none;
}

.move-item:hover {
  background: #363431;
  color: var(--color-text-active);
}

.move-item.active {
  background: #45433f;
  color: var(--color-text-active);
  font-weight: bold;
}

.moves-empty {
  grid-column: span 3;
  color: var(--color-text-secondary);
  text-align: center;
  font-style: italic;
  font-size: 0.9rem;
  padding-top: 2rem;
}

/* Navigation History Controls */
.navigation-controls {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.4rem;
}

.nav-btn {
  background: #363431;
  border: 1px solid var(--border-color);
  color: var(--color-text-primary);
  padding: 0.4rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 1.1rem;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, color 0.15s ease;
}

.nav-btn:hover {
  background: #45433f;
  color: var(--color-text-active);
}

.nav-btn:active {
  background: var(--inner-bg);
}

/* Action Buttons and Forms */
.controls-section {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.controls-section.three-cols {
  display: grid;
  grid-template-columns: 1fr 1fr 1.2fr;
  gap: 0.5rem;
}

.btn {
  background: #363431;
  border: 1px solid var(--border-color);
  color: var(--color-text-primary);
  border-radius: 4px;
  padding: 0.6rem 1rem;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  transition: all 0.15s ease;
}

.btn:hover {
  background: #45433f;
  color: var(--color-text-active);
}

.btn-secondary {
  background: #2b2926;
}

.btn-secondary:hover {
  background: #363431;
}

.btn-danger {
  background: #b33939;
  border-color: #8c2626;
  color: #ffffff;
}

.btn-danger:hover {
  background: #d14747;
}

.btn-primary {
  background: #0284c7;
  border-color: #0369a1;
  color: #ffffff;
}

.btn-primary:hover {
  background: #0ea5e9;
}

/* Owner Controls panel */
.admin-panel {
  border-top: 1px solid var(--border-color);
  padding-top: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.admin-header {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-secondary);
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.admin-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

#btn-logout {
  grid-column: span 2;
}

/* Status Toast Notification */
.status-toast {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  background: var(--panel-bg);
  border: 1px solid var(--border-color);
  color: var(--color-text-active);
  padding: 0.75rem 1.5rem;
  border-radius: 4px;
  font-size: 0.9rem;
  font-weight: 500;
  box-shadow: 0 10px 25px rgba(0,0,0,0.5);
  transform: translateY(100px);
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  z-index: 1000;
}

.status-toast.show {
  transform: translateY(0);
  opacity: 1;
  visibility: visible;
}

.status-toast.toast-error {
  border-color: #b33939;
  color: #fca5a5;
}

/* Dialog / Modal Overlays (Login Popup) */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  opacity: 0;
  visibility: hidden;
  transition: all 0.25s ease;
}

.modal-overlay.show {
  opacity: 1;
  visibility: visible;
}

.modal-card {
  background: var(--panel-bg);
  border: 2px solid var(--border-color);
  border-radius: 8px;
  padding: 2rem;
  width: 90%;
  max-width: 400px;
  box-shadow: 0 20px 40px rgba(0,0,0,0.6);
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.modal-title {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--color-text-active);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.modal-desc {
  font-size: 0.9rem;
  color: var(--color-text-secondary);
  line-height: 1.4;
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.input-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-secondary);
  font-weight: 600;
}

.input-field {
  background: var(--inner-bg);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 0.6rem 0.8rem;
  color: var(--color-text-active);
  font-family: inherit;
  font-size: 1rem;
  width: 100%;
}

.input-field:focus {
  outline: none;
  border-color: var(--color-owner);
}

.modal-buttons {
  display: flex;
  gap: 0.5rem;
}

.modal-buttons button {
  flex: 1;
}

/* Chessground pieces custom adjustment */
.cg-wrap pieces piece {
  transition: transform 0.2s ease;
}

.cg-wrap pieces piece.dragging {
  transition: none;
}

/* Chessground Piece Styling - Load SVGs from Lichess repository */
.cg-wrap piece.white.pawn { background-image: url('https://raw.githubusercontent.com/lichess-org/lila/master/public/piece/cburnett/wP.svg') !important; }
.cg-wrap piece.white.knight { background-image: url('https://raw.githubusercontent.com/lichess-org/lila/master/public/piece/cburnett/wN.svg') !important; }
.cg-wrap piece.white.bishop { background-image: url('https://raw.githubusercontent.com/lichess-org/lila/master/public/piece/cburnett/wB.svg') !important; }
.cg-wrap piece.white.rook { background-image: url('https://raw.githubusercontent.com/lichess-org/lila/master/public/piece/cburnett/wR.svg') !important; }
.cg-wrap piece.white.queen { background-image: url('https://raw.githubusercontent.com/lichess-org/lila/master/public/piece/cburnett/wQ.svg') !important; }
.cg-wrap piece.white.king { background-image: url('https://raw.githubusercontent.com/lichess-org/lila/master/public/piece/cburnett/wK.svg') !important; }

.cg-wrap piece.black.pawn { background-image: url('https://raw.githubusercontent.com/lichess-org/lila/master/public/piece/cburnett/bP.svg') !important; }
.cg-wrap piece.black.knight { background-image: url('https://raw.githubusercontent.com/lichess-org/lila/master/public/piece/cburnett/bN.svg') !important; }
.cg-wrap piece.black.bishop { background-image: url('https://raw.githubusercontent.com/lichess-org/lila/master/public/piece/cburnett/bB.svg') !important; }
.cg-wrap piece.black.rook { background-image: url('https://raw.githubusercontent.com/lichess-org/lila/master/public/piece/cburnett/bR.svg') !important; }
.cg-wrap piece.black.queen { background-image: url('https://raw.githubusercontent.com/lichess-org/lila/master/public/piece/cburnett/bQ.svg') !important; }
.cg-wrap piece.black.king { background-image: url('https://raw.githubusercontent.com/lichess-org/lila/master/public/piece/cburnett/bK.svg') !important; }

/* General piece style adjustments */
.cg-wrap piece {
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
}

/* -----------------------------------------------------------------------------
 * MEMORY CHALLENGE & LIBRARY STYLES
 * ----------------------------------------------------------------------------- */

/* Admin Tab bar styles */
.admin-tabs {
  display: flex;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 0.5rem;
  margin-bottom: 0.25rem;
  gap: 0.25rem;
}

.tab-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--color-text-secondary);
  padding: 0.4rem 0.6rem;
  border-radius: 4px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  transition: all 0.2s ease;
  flex: 1;
  text-align: center;
}

.tab-btn:hover {
  color: var(--color-text-active);
  background: rgba(255, 255, 255, 0.05);
}

.tab-btn.active {
  background: var(--inner-bg);
  border-color: var(--border-color);
  color: var(--color-public);
}

/* Tabbed Panels */
.panel-section {
  display: none;
  flex-direction: column;
  gap: 1.2rem;
  flex: 1;
  min-height: 0;
}

.panel-section.active {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
}

/* Memory Game Header Info */
.game-meta-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--color-text-active);
  margin-top: 0.3rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.game-meta-players {
  font-size: 0.8rem;
  color: var(--color-text-secondary);
  margin-top: 0.15rem;
}

/* Challenge Turn Status Box */
.challenge-status-box {
  background: var(--inner-bg);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 0.65rem 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  border-left: 4px solid var(--border-color);
  transition: all 0.2s ease;
}

.challenge-status-box.status-your-turn {
  border-left-color: var(--color-public);
}

.challenge-status-box.status-computer-turn {
  border-left-color: var(--color-owner);
}

.challenge-status-box.status-success {
  border-left-color: #22c55e;
  background: rgba(34, 197, 94, 0.05);
}

.status-badge {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 700;
  color: var(--color-text-secondary);
}

.status-your-turn .status-badge {
  color: var(--color-public);
}

.status-computer-turn .status-badge {
  color: var(--color-owner);
}

.status-success .status-badge {
  color: #22c55e;
}

.status-text {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--color-text-active);
}

/* Dropdown & Control adjustments */
.control-row {
  display: flex;
  width: 100%;
}

.select-row {
  background: var(--inner-bg);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 0.5rem 0.75rem;
}

.select-group {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
}

.select-group label {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}

.custom-select {
  background: var(--panel-bg);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  color: var(--color-text-active);
  padding: 0.4rem 0.6rem;
  font-family: inherit;
  font-size: 0.85rem;
  outline: none;
  cursor: pointer;
  flex: 1;
  transition: all 0.2s ease;
}

.custom-select:focus {
  border-color: var(--color-public);
}

/* Make single child inside controls-section take 100% width */
.controls-section button:only-child,
.controls-section a:only-child {
  grid-column: span 2;
}

/* Moves Log Highlights */
.moves-log .move-item.played {
  color: var(--color-text-active);
  font-weight: 500;
}

.moves-log .move-item.active-guess {
  color: var(--color-accent);
  font-weight: 700;
  animation: pulse-guess 0.8s infinite alternate;
  text-align: center;
}

@keyframes pulse-guess {
  from { opacity: 0.4; }
  to { opacity: 1; }
}

/* Board Shake / Mistake Flash */
.board-wrapper.flash-red {
  border-color: var(--color-accent) !important;
  box-shadow: 0 0 20px rgba(244, 63, 94, 0.35), 0 10px 30px rgba(0,0,0,0.5) !important;
  animation: board-shake 0.3s ease-in-out;
}

@keyframes board-shake {
  0% { transform: translateX(0); }
  20% { transform: translateX(-5px); }
  40% { transform: translateX(5px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(3px); }
  100% { transform: translateX(0); }
}

/* Saved Games Library Panel & Table */
.saved-games-list-wrapper {
  background: var(--inner-bg);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  max-height: 180px;
  overflow-y: auto;
  min-height: 100px;
}

.saved-games-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.saved-games-table th, 
.saved-games-table td {
  padding: 0.4rem 0.6rem;
  text-align: left;
  border-bottom: 1px solid var(--border-color);
}

.saved-games-table th {
  color: var(--color-text-secondary);
  font-weight: 600;
  background: rgba(0, 0, 0, 0.2);
  position: sticky;
  top: 0;
  z-index: 10;
}

.lib-game-link {
  color: var(--color-public);
  text-decoration: none;
  font-weight: 500;
  transition: color 0.2s ease;
}

.lib-game-link:hover {
  color: var(--color-text-active);
  text-decoration: underline;
}

.saved-games-table input[type="checkbox"] {
  width: 14px;
  height: 14px;
  cursor: pointer;
  accent-color: var(--color-public);
}

.import-form {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

