/* ===== CSS VARIABLES ===== */
:root {
  /* Colors - Cat-themed palette */
  --background: #fdf8f0;
  --foreground: #2d1810;
  --card: #ffffff;
  --card-foreground: #2d1810;
  --primary: #f4a6cd;
  --primary-foreground: #2d1810;
  --secondary: #a8e6cf;
  --secondary-foreground: #2d1810;
  --muted: #f5f1eb;
  --muted-foreground: #6b5b4f;
  --accent: #ffeaa7;
  --accent-foreground: #2d1810;
  --destructive: #e17055;
  --destructive-foreground: #ffffff;
  --border: #e8ddd4;
  --input: #f5f1eb;
  --ring: #f4a6cd;
  
  /* Typography */
  --font-family: 'Poppins', 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-size-xs: 0.75rem;
  --font-size-sm: 0.875rem;
  --font-size-base: 1rem;
  --font-size-lg: 1.125rem;
  --font-size-xl: 1.25rem;
  --font-size-2xl: 1.5rem;
  --font-size-3xl: 1.875rem;
  --font-size-4xl: 2.25rem;
  
  /* Spacing */
  --spacing-xs: 0.25rem;
  --spacing-sm: 0.5rem;
  --spacing-md: 1rem;
  --spacing-lg: 1.5rem;
  --spacing-xl: 2rem;
  --spacing-2xl: 3rem;
  
  /* Border radius */
  --radius-sm: 0.5rem;
  --radius-md: 0.75rem;
  --radius-lg: 1rem;
  --radius-xl: 1.5rem;
  
  /* Shadows */
  --shadow-sm: 0 1px 2px 0 rgba(45, 24, 16, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(45, 24, 16, 0.1), 0 2px 4px -1px rgba(45, 24, 16, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(45, 24, 16, 0.1), 0 4px 6px -2px rgba(45, 24, 16, 0.05);
  --shadow-xl: 0 20px 25px -5px rgba(45, 24, 16, 0.1), 0 10px 10px -5px rgba(45, 24, 16, 0.04);
  
  /* Transitions */
  --transition-fast: 150ms ease-in-out;
  --transition-normal: 250ms ease-in-out;
  --transition-slow: 350ms ease-in-out;
}

/* ===== RESET & BASE STYLES ===== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-family);
  background: var(--background);
  color: var(--foreground);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ===== LAYOUT ===== */
.screen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--transition-normal), visibility var(--transition-normal);
  z-index: 1;
}

.screen.active {
  opacity: 1;
  visibility: visible;
  z-index: 10;
}

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100vh;
  background: rgba(45, 24, 16, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--transition-normal), visibility var(--transition-normal);
  z-index: 100;
}

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

/* ===== MODALS ===== */
.cat-modal {
  background: var(--card);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  padding: var(--spacing-xl);
  max-width: 400px;
  width: 90%;
  margin: var(--spacing-md);
  animation: modalSlideIn var(--transition-slow) cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes modalSlideIn {
  from {
    opacity: 0;
    transform: translateY(2rem) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.modal-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--spacing-lg);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  margin-bottom: var(--spacing-md);
}

.modal-header h3 {
  font-size: var(--font-size-xl);
  font-weight: 600;
}

/* ===== GAME TITLE ===== */
.game-title {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  text-align: center;
}

.game-title h1 {
  font-size: var(--font-size-4xl);
  font-weight: 700;
  color: var(--foreground);
}

.game-title h2 {
  font-size: var(--font-size-2xl);
  font-weight: 600;
  color: var(--foreground);
}

.game-title.small h2 {
  font-size: var(--font-size-xl);
}

.paw-icon {
  font-size: 2.5rem;
  animation: pawBounce 2s ease-in-out infinite;
}

@keyframes pawBounce {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  25% { transform: translateY(-0.25rem) rotate(-5deg); }
  75% { transform: translateY(-0.125rem) rotate(5deg); }
}

/* ===== FORM ELEMENTS ===== */
.form-group {
  width: 100%;
  margin-bottom: var(--spacing-md);
}

.cat-input {
  width: 100%;
  padding: var(--spacing-md);
  font-size: var(--font-size-lg);
  font-family: var(--font-family);
  background: var(--input);
  border: 2px solid var(--border);
  border-radius: var(--radius-lg);
  color: var(--foreground);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  outline: none;
}

.cat-input:focus {
  border-color: var(--ring);
  box-shadow: 0 0 0 3px rgba(244, 166, 205, 0.2);
}

.cat-input::placeholder {
  color: var(--muted-foreground);
}

/* ===== BUTTONS ===== */
.cat-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--spacing-sm);
  padding: var(--spacing-md) var(--spacing-lg);
  font-size: var(--font-size-base);
  font-weight: 500;
  font-family: var(--font-family);
  border: none;
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: all var(--transition-fast);
  text-decoration: none;
  outline: none;
  position: relative;
  overflow: hidden;
}

.cat-btn:before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
  transition: left var(--transition-slow);
}

.cat-btn:hover:before {
  left: 100%;
}

.cat-btn.primary {
  background: var(--primary);
  color: var(--primary-foreground);
  box-shadow: var(--shadow-sm);
}

.cat-btn.primary:hover {
  background: #f298c4;
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.cat-btn.primary:active {
  transform: translateY(0);
  box-shadow: var(--shadow-sm);
}

.cat-btn.secondary {
  background: var(--secondary);
  color: var(--secondary-foreground);
  box-shadow: var(--shadow-sm);
}

.cat-btn.secondary:hover {
  background: #9bddc2;
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.cat-btn.icon {
  padding: var(--spacing-sm);
  background: var(--muted);
  color: var(--muted-foreground);
}

.cat-btn.icon:hover {
  background: var(--border);
  color: var(--foreground);
}

.cat-btn.large {
  padding: var(--spacing-lg) var(--spacing-xl);
  font-size: var(--font-size-lg);
  font-weight: 600;
  width: 100%;
}

/* ===== GAME MODE TOGGLE ===== */
.game-mode-toggle {
  display: flex;
  gap: var(--spacing-sm);
  width: 100%;
  background: var(--muted);
  border-radius: var(--radius-lg);
  padding: var(--spacing-xs);
}

.toggle-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--spacing-sm);
  padding: var(--spacing-md);
  font-size: var(--font-size-base);
  font-weight: 500;
  font-family: var(--font-family);
  background: transparent;
  color: var(--muted-foreground);
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
  outline: none;
}

.toggle-btn.active {
  background: var(--primary);
  color: var(--primary-foreground);
  box-shadow: var(--shadow-sm);
  transform: scale(1.02);
}

.toggle-btn:hover:not(.active) {
  background: var(--border);
  color: var(--foreground);
}

/* ===== LOADING ===== */
.loading-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--spacing-lg);
}

.cat-paw-loader {
  width: 4rem;
  height: 4rem;
  animation: pawSpin 2s ease-in-out infinite;
}

.paw-svg {
  width: 100%;
  height: 100%;
}

.paw-pad, .paw-toe {
  fill: var(--primary);
  animation: pawPulse 1.5s ease-in-out infinite alternate;
}

.paw-toe:nth-child(2) { animation-delay: 0.1s; }
.paw-toe:nth-child(3) { animation-delay: 0.2s; }
.paw-toe:nth-child(4) { animation-delay: 0.3s; }
.paw-toe:nth-child(5) { animation-delay: 0.4s; }

@keyframes pawSpin {
  0%, 100% { transform: rotate(0deg) scale(1); }
  50% { transform: rotate(180deg) scale(1.1); }
}

@keyframes pawPulse {
  0% { opacity: 0.6; }
  100% { opacity: 1; }
}

.loading-text {
  font-size: var(--font-size-lg);
  color: var(--muted-foreground);
  text-align: center;
}

/* ===== GAME CONTAINER ===== */
.game-container {
  width: 100%;
  max-width: 1000px;
  margin: 0 auto;
  padding: var(--spacing-md);
  display: flex;
  flex-direction: column;
  gap: var(--spacing-md);
  height: 100vh;
  overflow: hidden;
}

/* Desktop layout: side by side */
@media (min-width: 768px) {
  .game-container {
    max-width: 1200px;
  }
  
  .game-main-content {
    display: flex;
    flex-direction: row;
    gap: var(--spacing-xl);
    flex: 1;
    align-items: flex-start;
  }
  
  .game-left-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
    min-width: 0;
  }
  
  .game-right-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    max-width: 400px;
  }
}

/* Mobile layout: stacked */
@media (max-width: 767px) {
  .game-container {
    max-width: 400px;
  }
  
  .game-main-content {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
    flex: 1;
  }
  
  .game-left-panel {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
  }
  
  .game-right-panel {
    display: flex;
    flex-direction: column;
  }
}

.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: var(--spacing-sm);
  border-bottom: 2px solid var(--border);
}

.header-buttons {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
}

.music-toggle {
  position: relative;
  transition: all var(--transition-fast);
}

.music-toggle.muted {
  background: var(--destructive) !important;
  color: white !important;
}

.music-toggle.muted:hover {
  background: #c0392b !important;
  transform: translateY(-1px);
}

.music-toggle:not(.muted) {
  background: var(--secondary) !important;
  color: var(--secondary-foreground) !important;
}

.music-toggle:not(.muted):hover {
  background: #9bddc2 !important;
  transform: translateY(-1px);
}

/* ===== PLAYERS INFO ===== */
.players-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--card);
  border-radius: var(--radius-lg);
  padding: var(--spacing-md);
  box-shadow: var(--shadow-sm);
}

.player {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--spacing-xs);
}

.player-name {
  font-weight: 600;
  font-size: var(--font-size-base);
}

.player-symbol {
  font-size: var(--font-size-2xl);
}

.vs-divider {
  font-size: var(--font-size-lg);
  font-weight: 600;
  color: var(--muted-foreground);
}

/* ===== GAME BOARD ===== */
.game-board-container {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
}

.game-board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--spacing-sm);
  background: var(--card);
  border-radius: var(--radius-lg);
  padding: var(--spacing-lg);
  box-shadow: var(--shadow-md);
  aspect-ratio: 1;
  width: 100%;
  max-width: 350px;
  margin: 0 auto;
}

/* Desktop: larger game board */
@media (min-width: 768px) {
  .game-board {
    max-width: 400px;
    padding: var(--spacing-xl);
  }
  
  .cell {
    font-size: 3rem;
  }
}

/* Mobile: smaller game board */
@media (max-width: 767px) {
  .game-board {
    max-width: 280px;
    padding: var(--spacing-md);
  }
  
  .cell {
    font-size: 2.5rem;
  }
}

.cell {
  background: var(--muted);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.5rem;
  cursor: pointer;
  transition: all var(--transition-fast);
  aspect-ratio: 1;
  position: relative;
  overflow: hidden;
}

.cell:hover:not(.filled) {
  background: var(--secondary);
  transform: scale(1.05);
}

.cell.filled {
  cursor: not-allowed;
}

.cell.winner {
  background: var(--accent);
  animation: cellWin 0.6s ease-in-out;
}

@keyframes cellWin {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); }
}

.cell-content {
  animation: cellDrop 0.4s cubic-bezier(0.68, -0.55, 0.27, 1.55);
}

@keyframes cellDrop {
  0% {
    transform: translateY(-2rem) scale(0.5);
    opacity: 0;
  }
  100% {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}

.winning-line {
  position: absolute;
  background: var(--primary);
  border-radius: 0.25rem;
  opacity: 0;
  transition: opacity var(--transition-normal);
  z-index: 1;
}

.winning-line.show {
  opacity: 0.8;
  animation: lineGrow 0.5s ease-out;
}

@keyframes lineGrow {
  0% { transform: scale(0); }
  100% { transform: scale(1); }
}

/* ===== GAME STATUS ===== */
.game-status {
  text-align: center;
  background: var(--card);
  border-radius: var(--radius-lg);
  padding: var(--spacing-md);
  box-shadow: var(--shadow-sm);
}

.game-status p {
  font-size: var(--font-size-lg);
  font-weight: 600;
  margin: 0;
}

/* ===== CHAT SECTION ===== */
.chat-section {
  display: flex;
  flex-direction: column;
  background: var(--card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  position: relative;
}

/* Desktop: full height chat */
@media (min-width: 768px) {
  .chat-section {
    height: 100%;
    max-height: 500px;
  }
  
  .chat-messages {
    height: 350px;
    max-height: 350px;
  }
}

/* Mobile: limited height chat */
@media (max-width: 767px) {
  .chat-section {
    height: 200px;
    max-height: 200px;
  }
  
  .chat-messages {
    height: 140px;
    max-height: 140px;
  }
}

.chat-messages {
  flex: 1;
  padding: var(--spacing-md);
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: var(--spacing-sm);
  scrollbar-width: thin;
  scrollbar-color: var(--muted-foreground) var(--muted);
}

/* Webkit scrollbar styling */
.chat-messages::-webkit-scrollbar {
  width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
  background: var(--muted);
  border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: var(--muted-foreground);
  border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
  background: var(--foreground);
}

.chat-message {
  max-width: 80%;
  padding: var(--spacing-sm) var(--spacing-md);
  border-radius: var(--radius-md);
  animation: messageSlideIn 0.3s ease-out;
}

@keyframes messageSlideIn {
  0% {
    opacity: 0;
    transform: translateY(1rem);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

.chat-message.player {
  background: var(--primary);
  color: var(--primary-foreground);
  align-self: flex-end;
  border-bottom-right-radius: var(--spacing-xs);
}

.chat-message.opponent {
  background: var(--secondary);
  color: var(--secondary-foreground);
  align-self: flex-start;
  border-bottom-left-radius: var(--spacing-xs);
}

.message-text {
  font-size: var(--font-size-sm);
  line-height: 1.4;
}

.typing-indicator {
  padding: var(--spacing-sm) var(--spacing-md);
  opacity: 0;
  transition: opacity var(--transition-fast);
  flex-shrink: 0;
  border-top: 1px solid var(--border);
}

.typing-indicator.show {
  opacity: 1;
}

.typing-dots {
  display: flex;
  gap: var(--spacing-xs);
  align-items: center;
}

.dot {
  width: 0.5rem;
  height: 0.5rem;
  background: var(--muted-foreground);
  border-radius: 50%;
  animation: typingDot 1.4s ease-in-out infinite;
}

.dot:nth-child(2) { animation-delay: 0.2s; }
.dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingDot {
  0%, 60%, 100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  30% {
    transform: translateY(-0.5rem);
    opacity: 1;
  }
}

.chat-input-container {
  display: flex;
  gap: var(--spacing-sm);
  padding: var(--spacing-md);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--card);
}

.chat-input {
  flex: 1;
  padding: var(--spacing-sm) var(--spacing-md);
  font-size: var(--font-size-sm);
  font-family: var(--font-family);
  background: var(--input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--foreground);
  transition: border-color var(--transition-fast);
  outline: none;
}

.chat-input:focus {
  border-color: var(--ring);
}

/* ===== GAME RESULT ===== */
.game-result {
  text-align: center;
  padding: var(--spacing-lg);
  background: var(--accent);
  border-radius: var(--radius-lg);
  animation: resultPop 0.6s cubic-bezier(0.68, -0.55, 0.27, 1.55);
}

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

.result-icon {
  font-size: 4rem;
  margin-bottom: var(--spacing-sm);
}

.result-text {
  font-size: var(--font-size-2xl);
  font-weight: 700;
  margin-bottom: var(--spacing-xs);
}

.result-subtitle {
  font-size: var(--font-size-base);
  color: var(--muted-foreground);
}

.game-over-actions {
  display: flex;
  gap: var(--spacing-md);
  width: 100%;
}

.game-over-actions .cat-btn {
  flex: 1;
}

/* ===== SETTINGS ===== */
.settings-content {
  width: 100%;
}

.setting-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--spacing-md) 0;
  border-bottom: 1px solid var(--border);
}

.setting-item:last-child {
  border-bottom: none;
}

.setting-item label {
  font-weight: 500;
}

.modal-actions {
  width: 100%;
  margin-top: var(--spacing-lg);
}

.modal-actions .cat-btn {
  width: 100%;
}

/* ===== RESPONSIVE DESIGN ===== */

/* Small mobile devices */
@media (max-width: 480px) {
  .cat-modal {
    padding: var(--spacing-lg);
    margin: var(--spacing-sm);
  }
  
  .game-container {
    padding: var(--spacing-sm);
    gap: var(--spacing-sm);
  }
  
  .game-title h1 {
    font-size: var(--font-size-3xl);
  }
  
  .paw-icon {
    font-size: 2rem;
  }
}

/* Short screens - optimize for height */
@media (max-height: 700px) and (min-width: 768px) {
  .game-container {
    gap: var(--spacing-sm);
  }
  
  .chat-section {
    max-height: 400px;
  }
  
  .chat-messages {
    height: 280px;
    max-height: 280px;
  }
}

/* Very short screens */
@media (max-height: 600px) {
  .game-container {
    gap: var(--spacing-xs);
  }
  
  .players-info {
    padding: var(--spacing-sm);
  }
  
  .game-board {
    max-width: 300px;
  }
  
  @media (min-width: 768px) {
    .chat-section {
      max-height: 350px;
    }
    
    .chat-messages {
      height: 220px;
      max-height: 220px;
    }
  }
  
  @media (max-width: 767px) {
    .chat-section {
      height: 150px;
      max-height: 150px;
    }
    
    .chat-messages {
      height: 100px;
      max-height: 100px;
    }
  }
}

/* ===== ACCESSIBILITY ===== */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Focus styles for keyboard navigation */
.cat-btn:focus-visible,
.cat-input:focus-visible,
.toggle-btn:focus-visible,
.cell:focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  :root {
    --border: #000000;
    --muted: #f0f0f0;
  }
}
