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

:root {
  --bg: #0a0a0f;
  --surface: #12121a;
  --surface-2: #1a1a25;
  --border: #2a2a3a;
  --text: #e8e8f0;
  --text-muted: #888899;
  --primary: #6366f1;
  --primary-hover: #818cf8;
  --success: #22c55e;
  --warning: #f59e0b;
  --error: #ef4444;
  --gradient: linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #d946ef 100%);
}

body {
  font-family: 'Space Grotesk', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
}

/* Page wrapper */
.page-wrapper {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem;
}

/* Layout wrapper for sidebar + main content */
.layout-wrapper {
  display: flex;
  gap: 2rem;
  align-items: flex-start;
}

main {
  flex: 1;
  max-width: 900px;
}

/* Live games sidebar */
.live-sidebar {
  position: sticky;
  top: 2rem;
  width: 280px;
  flex-shrink: 0;
  height: fit-content;
  max-height: calc(100vh - 4rem);
  overflow-y: auto;
  background: var(--surface);
  border-radius: 16px;
  padding: 1.5rem;
  border: 1px solid var(--border);
}

.live-sidebar h3 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 1rem;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.live-sidebar .empty {
  font-size: 0.9rem;
  color: var(--text-muted);
  text-align: center;
  padding: 1rem 0;
}

#live-games {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

/* Live game card */
.live-game-card {
  background: var(--surface-2);
  border-radius: 12px;
  padding: 1rem;
  border: 1px solid var(--border);
  transition: all 0.2s;
  animation: slideIn 0.3s ease;
}

.live-game-card:hover {
  border-color: var(--primary);
  transform: translateX(4px);
}

.live-game-card.active {
  border-color: var(--success);
  box-shadow: 0 0 12px rgba(34, 197, 94, 0.2);
}

.live-game-card .player-name {
  font-weight: 600;
  font-size: 0.95rem;
  margin-bottom: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.live-game-card .player-name::before {
  content: '';
  width: 8px;
  height: 8px;
  background: var(--success);
  border-radius: 50%;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(1.2); }
}

.live-game-card .game-stats {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.live-game-card .chain-length {
  font-weight: 700;
  font-size: 1.2rem;
  color: var(--primary);
}

.live-game-card .current-letter {
  background: var(--bg);
  padding: 0.25rem 0.5rem;
  border-radius: 6px;
  font-weight: 600;
  color: var(--text);
}

.live-game-card .last-animal {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.5rem;
  font-style: italic;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.live-game-card .last-animal .emoji {
  margin-right: 0.25rem;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(-20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* Connection status */
.connection-status {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.connection-status .status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--warning);
}

.connection-status.connected .status-dot {
  background: var(--success);
}

.connection-status.disconnected .status-dot {
  background: var(--error);
}

header {
  text-align: center;
  margin-bottom: 3rem;
  position: relative;
}

.github-badge {
  position: absolute;
  top: 0;
  right: 0;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  transition: all 0.2s ease;
}

.github-badge:hover {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--primary);
}

.github-badge svg {
  flex-shrink: 0;
}

.logo-link {
  text-decoration: none;
  display: inline-block;
}

h1 {
  font-size: 3rem;
  font-weight: 700;
  background: linear-gradient(
    90deg,
    #6366f1 0%,
    #8b5cf6 30%,
    #b8b0f8 50%,
    #8b5cf6 70%,
    #d946ef 100%
  );
  background-size: 300% 100%;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 0.5rem;
  animation: shimmer 10s ease-in-out infinite;
}

@keyframes shimmer {
  0%, 100% { background-position: 100% 0; }
  50% { background-position: 0% 0; }
}

.ai-letter {
  animation: rainbowCycle 3s linear infinite;
}

.ai-letter:nth-of-type(2) {
  animation-delay: -1.5s;
}

@keyframes rainbowCycle {
  0% { -webkit-text-fill-color: #ef4444; }
  16% { -webkit-text-fill-color: #f59e0b; }
  33% { -webkit-text-fill-color: #22c55e; }
  50% { -webkit-text-fill-color: #06b6d4; }
  66% { -webkit-text-fill-color: #6366f1; }
  83% { -webkit-text-fill-color: #d946ef; }
  100% { -webkit-text-fill-color: #ef4444; }
}

.subtitle {
  color: var(--text-muted);
  font-size: 1.1rem;
}

h2 {
  font-size: 1.5rem;
  margin-bottom: 1rem;
  font-weight: 600;
}

section {
  background: var(--surface);
  border-radius: 16px;
  padding: 2rem;
  margin-bottom: 2rem;
  border: 1px solid var(--border);
}

/* Start controls */
.start-controls {
  display: flex;
  gap: 1rem;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
}

.start-controls label {
  color: var(--text-muted);
}

.start-controls input {
  width: 60px;
  padding: 0.75rem;
  font-size: 1.5rem;
  text-align: center;
  text-transform: uppercase;
  background: var(--surface-2);
  border: 2px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: inherit;
}

.start-controls input:focus {
  outline: none;
  border-color: var(--primary);
}

.btn {
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
  font-weight: 600;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.2s;
}

.btn.primary {
  background: var(--primary);
  color: white;
}

.btn.primary:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
}

.btn.secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn.secondary:hover {
  background: var(--border);
}

.btn.danger {
  background: var(--error);
  color: white;
}

.btn.danger:hover {
  background: #dc2626;
  transform: translateY(-1px);
}

.stop-controls {
  text-align: center;
  margin-top: 1rem;
}

/* Game display */
.stats {
  display: flex;
  justify-content: center;
  gap: 3rem;
  margin-bottom: 2rem;
}

.stat {
  text-align: center;
}

.stat-value {
  display: block;
  font-size: 3rem;
  font-weight: 700;
  background: var(--gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.stat-label {
  color: var(--text-muted);
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.chain-container {
  max-height: 300px;
  overflow-y: auto;
  margin-bottom: 1.5rem;
  padding: 1rem;
  background: var(--surface-2);
  border-radius: 12px;
}


.chain {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  align-items: flex-start;
}

.chain-row {
  display: block;
  font-size: 1.05rem;
  padding: 0.4rem 0.75rem;
  background: var(--bg);
  border-radius: 8px;
  text-decoration: none;
  color: var(--text);
  transition: all 0.2s;
}

.chain-row:hover {
  background: var(--surface-2);
  transform: translateX(4px);
}

.chain-row .number {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-right: 0.5rem;
  display: inline-block;
  min-width: 2.5rem;
}

.chain-row .emoji {
  margin-right: 0.5rem;
}

.chain-row .prev {
  color: var(--text-muted);
}

.chain-row .letter {
  color: var(--primary);
  font-weight: 600;
}

.chain-row.new {
  animation: popIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* Keep old .animal styles for modal */
.animal {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  background: var(--bg);
  border-radius: 20px;
  font-size: 0.95rem;
  animation: fadeIn 0.3s ease;
  text-decoration: none;
  color: var(--text);
  transition: all 0.2s;
}

.animal:hover {
  background: var(--primary);
  transform: scale(1.05);
}

.animal .number {
  color: var(--text-muted);
  font-size: 0.8rem;
  margin-right: 0.25rem;
}

.animal .name {
  text-transform: capitalize;
}

.animal .name .letter {
  color: var(--primary);
  font-weight: 600;
}

@keyframes popIn {
  0% {
    opacity: 0;
    transform: scale(0.5);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.status {
  text-align: center;
  padding: 1rem;
  min-height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.thinking {
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.thinking::after {
  content: '';
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Game over */
.game-over {
  text-align: center;
  animation: fadeIn 0.5s ease;
}

.game-over h2 {
  font-size: 2rem;
  margin-bottom: 0.5rem;
}

.game-over p {
  color: var(--text-muted);
  margin-bottom: 1.5rem;
}

.name-input {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  margin-bottom: 1rem;
}

.name-input input {
  padding: 0.75rem 1rem;
  font-size: 1rem;
  background: var(--surface-2);
  border: 2px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: inherit;
  width: 200px;
}

.name-input input:focus {
  outline: none;
  border-color: var(--primary);
}

.learning-note {
  margin-top: 1.5rem;
  padding: 1rem;
  background: var(--surface-2);
  border-radius: 8px;
  font-style: italic;
  color: var(--text-muted);
  border-left: 3px solid var(--primary);
}

.suggestion-box {
  margin-top: 1.5rem;
  padding: 1.5rem;
  background: var(--surface-2);
  border-radius: 8px;
  border: 1px dashed var(--border);
  position: relative;
  overflow: hidden;
}

.suggestion-box p {
  margin-bottom: 0.75rem;
  color: var(--text);
}

.suggestion-box strong {
  color: var(--primary);
  font-size: 1.2em;
}

.suggestion-input {
  display: flex;
  gap: 0.5rem;
}

.suggestion-input input {
  flex: 1;
  padding: 0.75rem 1rem;
  font-size: 1rem;
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: inherit;
}

.suggestion-input input:focus {
  outline: none;
  border-color: var(--primary);
}

.suggestion-result {
  margin-top: 0.75rem;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.suggestion-result.error {
  color: var(--error);
}

.suggestion-result.success {
  color: var(--success);
  font-weight: 600;
  font-size: 1rem;
  animation: successPop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes successPop {
  0% { transform: scale(0.8); opacity: 0; }
  50% { transform: scale(1.1); }
  100% { transform: scale(1); opacity: 1; }
}

.confetti {
  position: absolute;
  width: 10px;
  height: 10px;
  top: 0;
  border-radius: 2px;
  animation: confettiFall linear forwards;
  pointer-events: none;
}

@keyframes confettiFall {
  0% {
    transform: translateY(-10px) rotate(0deg);
    opacity: 1;
  }
  100% {
    transform: translateY(150px) rotate(720deg);
    opacity: 0;
  }
}

/* Leaderboard */
.leaderboard {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.leaderboard-entry {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem;
  background: var(--surface-2);
  border-radius: 8px;
}

.leaderboard-entry .rank {
  font-size: 1.5rem;
  font-weight: 700;
  width: 40px;
  text-align: center;
}

.leaderboard-entry .rank.gold { color: #fbbf24; }
.leaderboard-entry .rank.silver { color: #94a3b8; }
.leaderboard-entry .rank.bronze { color: #cd7f32; }

.leaderboard-entry .info {
  flex: 1;
  min-width: 0;
}

.leaderboard-entry .name-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.leaderboard-entry .name {
  font-weight: 600;
}

.leaderboard-entry .title {
  font-size: 0.75rem;
  color: var(--text-muted);
  background: var(--bg);
  padding: 0.15rem 0.5rem;
  border-radius: 10px;
}

.leaderboard-entry .emoji-parade {
  font-size: 2rem;
  display: flex;
  align-items: center;
  gap: 0.3rem;
  min-width: 6rem;
}

.leaderboard-entry .emoji-display {
  display: inline-block;
  transform-origin: center;
}

.leaderboard-entry .emoji-display.slide-right {
  animation: slideRight 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.leaderboard-entry .emoji-display.slide-left {
  animation: slideLeft 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes slideRight {
  0% {
    transform: translateX(-20px) scale(0.8);
    opacity: 0;
  }
  100% {
    transform: translateX(0) scale(1);
    opacity: 1;
  }
}

@keyframes slideLeft {
  0% {
    transform: translateX(20px) scale(0.8);
    opacity: 0;
  }
  100% {
    transform: translateX(0) scale(1);
    opacity: 1;
  }
}

.leaderboard-entry .emoji-arrow {
  font-size: 1rem;
  color: var(--text-muted);
  transition: opacity 0.2s;
}

.leaderboard-entry .emoji-last {
  opacity: 0.5;
  transition: opacity 0.2s;
}

.leaderboard-entry:hover .emoji-last {
  opacity: 1;
}

.leaderboard-entry .emoji-tooltip {
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 0.25rem 0.5rem;
  border-radius: 6px;
  font-size: 0.8rem;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.15s, background 0.15s;
  text-transform: capitalize;
  cursor: pointer;
}

.leaderboard-entry .emoji-tooltip:hover {
  background: var(--primary);
  color: white;
}

.leaderboard-entry .emoji-parade {
  position: relative;
}

.leaderboard-entry .chain-summary {
  font-size: 0.85rem;
  color: var(--text);
  text-transform: capitalize;
  margin: 0.15rem 0;
}

.leaderboard-entry .stats-row {
  display: flex;
  gap: 1rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.leaderboard-entry .death {
  color: var(--error);
}

.leaderboard-entry .score {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--primary);
}

/* Lessons */
.lessons {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.lesson {
  padding: 1rem;
  background: var(--surface-2);
  border-radius: 8px;
  font-size: 0.95rem;
  border-left: 3px solid var(--primary);
}

.loading, .empty {
  color: var(--text-muted);
  font-style: italic;
  text-align: center;
  padding: 1rem;
}

/* Footer */
footer {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
  padding: 2rem 0;
}

footer a {
  color: var(--primary);
  text-decoration: none;
}

footer a:hover {
  text-decoration: underline;
}

/* Modal */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.8);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-overlay.active {
  display: flex;
}

.modal {
  background: var(--surface);
  border-radius: 16px;
  padding: 2rem;
  max-width: 600px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
  position: relative;
  border: 1px solid var(--border);
  animation: modalIn 0.3s ease;
}

@keyframes modalIn {
  from {
    opacity: 0;
    transform: scale(0.95);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.modal-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: all 0.2s;
}

.modal-close:hover {
  background: var(--surface-2);
  color: var(--text);
}

.modal h2 {
  margin-bottom: 1rem;
  padding-right: 2rem;
}

.modal-stats {
  display: flex;
  gap: 2rem;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.modal-stats .stat {
  text-align: left;
}

.modal-stats .stat-value {
  font-size: 1.5rem;
}

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

.modal-chain .animal {
  background: var(--surface-2);
}

.leaderboard-entry {
  cursor: pointer;
  transition: all 0.2s;
}

.leaderboard-entry:hover {
  background: var(--border);
  transform: translateX(4px);
}

/* Responsive */
@media (max-width: 900px) {
  .page-wrapper {
    padding: 1rem;
  }

  .layout-wrapper {
    flex-direction: column;
  }

  .live-sidebar {
    position: relative;
    top: 0;
    width: 100%;
    max-height: none;
  }

  #live-games {
    flex-direction: row;
    overflow-x: auto;
    padding-bottom: 0.5rem;
  }

  .live-game-card {
    min-width: 200px;
    flex-shrink: 0;
  }
}

@media (max-width: 600px) {
  .page-wrapper {
    padding: 0.75rem;
  }

  .layout-wrapper {
    gap: 1rem;
  }

  .live-sidebar {
    padding: 1rem;
  }

  .live-sidebar h3 {
    font-size: 1rem;
  }

  h1 {
    font-size: 2rem;
  }

  .github-badge {
    padding: 0.4rem;
  }

  .github-badge span {
    display: none;
  }

  .stats {
    gap: 1.5rem;
  }

  .stat-value {
    font-size: 2rem;
  }

  .start-controls {
    flex-direction: column;
  }

  .btn {
    width: 100%;
  }
}
