* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: #1e1e1e;
  color: #e0e0e0;
  min-height: 100vh;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 24px;
  background: #2a2a2a;
  border-bottom: 1px solid #3a3a3a;
}

.app-header h1 { margin: 0; font-size: 20px; }

.header-actions button {
  background: #3a3a3a;
  border: 1px solid #555;
  color: #e0e0e0;
  padding: 6px 14px;
  margin-left: 8px;
  cursor: pointer;
  border-radius: 4px;
}
.header-actions button:hover { background: #4a4a4a; }

.app-main {
  display: flex;
  gap: 24px;
  padding: 24px;
  align-items: flex-start;
}

#board-container {
  flex: 0 0 auto;
}

#sidebar {
  flex: 1;
  max-width: 360px;
  background: #2a2a2a;
  border-radius: 8px;
  padding: 16px;
  min-height: 200px;
}

@media (max-width: 800px) {
  .app-main { flex-direction: column; align-items: center; }
  #sidebar { max-width: none; width: 100%; }
}

/* Board */
.board {
  display: grid;
  width: min(80vh, 80vw);
  height: min(80vh, 80vw);
  border: 3px solid #3a3a3a;
  border-radius: 4px;
  user-select: none;
}

.square {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(24px, 5vw, 56px);
  line-height: 1;
}

.square.light { background: #ebecd0; }
.square.dark  { background: #739552; }

.square .piece {
  cursor: grab;
  user-select: none;
  filter: drop-shadow(0 1px 1px rgba(0,0,0,.3));
}
.square .piece.white { color: #fff; text-shadow: 0 0 1px #000, 0 0 1px #000; }
.square .piece.black { color: #000; }

.square .coord {
  position: absolute;
  font-size: 10px;
  font-family: system-ui, sans-serif;
  color: rgba(0,0,0,.55);
  pointer-events: none;
}
.square.dark .coord { color: rgba(255,255,255,.7); }
.square .coord.rank { top: 2px; left: 3px; }
.square .coord.file { bottom: 2px; right: 3px; }

/* Highlights */
.square.hl-selected { box-shadow: inset 0 0 0 4px #4ea1ff; }
.square.hl-target::after {
  content: '';
  position: absolute;
  width: 28%;
  height: 28%;
  border-radius: 50%;
  background: rgba(0, 0, 0, .25);
  pointer-events: none;
}
.square.hl-target-capture::after {
  content: '';
  position: absolute;
  inset: 6%;
  border: 4px solid rgba(0, 0, 0, .35);
  border-radius: 50%;
  pointer-events: none;
}
.square.hl-last-move { background-image: linear-gradient(rgba(255, 215, 0, .35), rgba(255, 215, 0, .35)); }
.square.hl-check {
  animation: check-pulse 1s infinite;
  box-shadow: inset 0 0 0 4px #d22;
}
@keyframes check-pulse {
  0%, 100% { background-color: inherit; }
  50% { background-color: rgba(220, 50, 50, .4); }
}

/* Sidebar */
.sb-status {
  font-size: 18px;
  font-weight: bold;
  padding: 12px;
  background: #333;
  border-radius: 4px;
  margin-bottom: 16px;
  text-align: center;
}
.sb-section {
  margin-bottom: 16px;
}
.sb-section h3 {
  margin: 0 0 8px;
  font-size: 14px;
  text-transform: uppercase;
  color: #999;
  letter-spacing: 0.05em;
}
.sb-moves {
  margin: 0;
  padding-left: 36px;
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
  font-size: 14px;
  max-height: 320px;
  overflow-y: auto;
  background: #222;
  border-radius: 4px;
  padding: 8px 8px 8px 36px;
}
.sb-moves li { padding: 2px 0; }
.sb-captured-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
  min-height: 28px;
}
.cap-label {
  font-size: 12px;
  color: #999;
  width: 60px;
}
.cap-list {
  flex: 1;
  font-size: 22px;
  line-height: 1;
}
.cap-piece.white { color: #fff; text-shadow: 0 0 1px #000; }
.cap-piece.black { color: #000; text-shadow: 0 0 1px #fff; }

/* Modals */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal-panel {
  background: #2a2a2a;
  border: 1px solid #3a3a3a;
  border-radius: 8px;
  padding: 24px;
  min-width: 320px;
  max-width: 480px;
}
.modal-panel h2 { margin: 0 0 16px; font-size: 20px; }
.modal-group { margin-bottom: 16px; }
.modal-group h3 { margin: 0 0 8px; font-size: 13px; text-transform: uppercase; color: #999; }
.modal-options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.modal-options button {
  flex: 1 1 calc(50% - 4px);
  padding: 8px 12px;
  background: #3a3a3a;
  border: 1px solid #555;
  color: #e0e0e0;
  border-radius: 4px;
  cursor: pointer;
}
.modal-options button.selected {
  background: #4ea1ff;
  color: #000;
  border-color: #4ea1ff;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
}
.modal-confirm {
  background: #1d4;
  color: #000;
  border: none;
  padding: 10px 24px;
  border-radius: 4px;
  font-weight: bold;
  cursor: pointer;
}
.modal-promo {
  display: flex;
  gap: 8px;
  justify-content: center;
}
.promo-btn {
  font-size: 48px;
  width: 80px;
  height: 80px;
  background: #ebecd0;
  border: 2px solid #333;
  border-radius: 4px;
  cursor: pointer;
}
.promo-btn.black { color: #000; }
.promo-btn.white { color: #fff; background: #739552; }

/* Phase 2: Nav extensions */
.brand-link {
  color: inherit;
  text-decoration: none;
}
.nav-user {
  margin-left: 16px;
  color: #ccc;
  font-size: 14px;
}
.nav-link {
  margin-left: 12px;
  color: #4ea1ff;
  text-decoration: none;
  font-size: 14px;
}
.nav-link:hover { text-decoration: underline; }

.flash {
  padding: 10px 24px;
  font-size: 14px;
  text-align: center;
}
.flash-error {
  background: #d22;
  color: #fff;
}

/* Phase 2: Auth pages */
.auth-main {
  display: flex;
  justify-content: center;
  padding: 48px 24px;
}
.auth-panel {
  background: #2a2a2a;
  border: 1px solid #3a3a3a;
  border-radius: 8px;
  padding: 32px;
  width: 100%;
  max-width: 400px;
}
.auth-panel h2 {
  margin: 0 0 24px;
  font-size: 22px;
}
.auth-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.auth-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: #ccc;
}
.auth-form input {
  background: #1e1e1e;
  border: 1px solid #555;
  color: #e0e0e0;
  padding: 10px 12px;
  border-radius: 4px;
  font-size: 15px;
}
.auth-form input:focus {
  outline: none;
  border-color: #4ea1ff;
}
.btn-primary {
  background: #1d4;
  color: #000;
  border: none;
  padding: 12px;
  border-radius: 4px;
  font-weight: bold;
  font-size: 15px;
  cursor: pointer;
  margin-top: 8px;
}
.btn-primary:hover { background: #2e5; }
.auth-switch {
  margin-top: 24px;
  text-align: center;
  color: #999;
  font-size: 14px;
}
.auth-switch a {
  color: #4ea1ff;
  text-decoration: none;
}

/* Phase 2: Sidebar toast + current-move highlight */
.move-half {
  cursor: pointer;
  padding: 1px 3px;
  border-radius: 2px;
}
.move-half:hover { background: #333; }
.move-half.current-move {
  background: #4ea1ff;
  color: #000;
  font-weight: bold;
}

.sb-toast {
  position: sticky;
  bottom: 0;
  margin-top: 16px;
  padding: 10px 14px;
  border-radius: 4px;
  font-size: 13px;
  background: #1d4;
  color: #000;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
}
.sb-toast-visible { opacity: 1; }
.sb-toast-error { background: #d22; color: #fff; }

/* Phase 2: Profile page */
.profile-main {
  max-width: 900px;
  margin: 24px auto;
  padding: 0 24px;
  display: flex;
  flex-direction: column;
  gap: 32px;
}
.profile-stats h2,
.profile-games h2 {
  margin: 0 0 16px;
  font-size: 18px;
  color: #ccc;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.stats-table, .games-table {
  width: 100%;
  border-collapse: collapse;
  background: #2a2a2a;
  border-radius: 8px;
  overflow: hidden;
}
.stats-table th, .stats-table td,
.games-table th, .games-table td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid #333;
  font-size: 14px;
}
.stats-table thead th,
.games-table thead th {
  background: #1e1e1e;
  color: #999;
  font-weight: normal;
  text-transform: uppercase;
  font-size: 12px;
  letter-spacing: 0.05em;
}
.stats-table tbody th { color: #ccc; font-weight: normal; }
.stats-table td { text-align: center; font-variant-numeric: tabular-nums; }
.stats-meta {
  margin-top: 12px;
  color: #999;
  font-size: 14px;
  text-align: right;
}
.result-win  { color: #1d4; font-weight: bold; }
.result-loss { color: #d22; font-weight: bold; }
.result-draw { color: #ccc; font-weight: bold; }
.reason { color: #888; font-size: 12px; margin-left: 4px; }
.btn-replay {
  color: #4ea1ff;
  text-decoration: none;
  font-size: 13px;
}
.btn-replay:hover { text-decoration: underline; }
.empty-state {
  text-align: center;
  color: #888;
  padding: 32px;
  background: #2a2a2a;
  border-radius: 8px;
}
.pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 16px;
  color: #999;
  font-size: 14px;
}
.pagination a {
  color: #4ea1ff;
  text-decoration: none;
}
.pagination a:hover { text-decoration: underline; }

/* Phase 2: Replay nav */
.replay-meta {
  margin-bottom: 16px;
  font-size: 13px;
  color: #ccc;
}
.replay-meta h3 { margin: 0 0 8px; font-size: 16px; color: #fff; }
.replay-meta p { margin: 4px 0; }

.replay-nav {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 6px;
  align-items: center;
  background: #2a2a2a;
  border: 1px solid #3a3a3a;
  border-radius: 6px;
  padding: 8px 14px;
  z-index: 50;
}
.replay-nav button {
  background: #3a3a3a;
  border: 1px solid #555;
  color: #e0e0e0;
  padding: 6px 12px;
  font-size: 16px;
  border-radius: 4px;
  cursor: pointer;
  min-width: 36px;
}
.replay-nav button:hover { background: #4a4a4a; }
.replay-nav button:disabled { opacity: 0.4; cursor: default; }
#replay-cursor {
  margin-left: 12px;
  color: #ccc;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
