@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;700&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  /* Light theme (default) */
  --bg-primary: #fafafa;
  --bg-secondary: #ffffff;
  --bg-tertiary: #f5f5f5;
  --text-primary: #1a1a1a;
  --text-secondary: #666666;
  --text-tertiary: #999999;
  --border: #e5e5e5;
  --accent: #1a1a1a;
  --accent-hover: #333333;
  --shadow: rgba(0, 0, 0, 0.04);
  --shadow-lg: rgba(0, 0, 0, 0.08);

  /* Default text size (medium) */
  --font-base: 0.9375rem;
  --font-sm: 0.875rem;
  --font-xs: 0.75rem;
}

/* Dark theme (applied via data-theme="dark" attribute) */
[data-theme="dark"] {
  --bg-primary: #0a0a0a;
  --bg-secondary: #141414;
  --bg-tertiary: #1a1a1a;
  --text-primary: #fafafa;
  --text-secondary: #a0a0a0;
  --text-tertiary: #666666;
  --border: #2a2a2a;
  --accent: #fafafa;
  --accent-hover: #e0e0e0;
  --shadow: rgba(0, 0, 0, 0.3);
  --shadow-lg: rgba(0, 0, 0, 0.5);
}

/* ========== TEXT SIZE ========== */
[data-text-size="small"] {
  --font-base: 0.8125rem;
  --font-sm: 0.75rem;
  --font-xs: 0.6875rem;
}
[data-text-size="medium"] {
  --font-base: 0.9375rem;
  --font-sm: 0.875rem;
  --font-xs: 0.75rem;
}
[data-text-size="large"] {
  --font-base: 1.125rem;
  --font-sm: 1rem;
  --font-xs: 0.875rem;
}

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

body {
  font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: var(--font-base);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ========== HOME PAGE ========== */

.container {
  max-width: 800px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
  min-height: 100vh;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 3rem;
  padding-bottom: 2rem;
  border-bottom: 1px solid var(--border);
}

.header-buttons {
  display: flex;
  gap: 0.625rem;
  align-items: center;
}

.logo {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

/* Disclaimer Banner */
.disclaimer-banner {
  background-color: #fef3c7;
  border: 1px solid #f59e0b;
  border-radius: 0.5rem;
  padding: 1rem 1.25rem;
  margin-bottom: 2rem;
  color: #92400e;
  font-size: var(--font-sm);
  line-height: 1.5;
}

[data-theme="dark"] .disclaimer-banner {
  background-color: #451a03;
  border-color: #92400e;
  color: #fbbf24;
}

.disclaimer-banner strong {
  font-weight: 600;
  margin-right: 0.25rem;
}

.btn-settings {
  padding: 0.625rem 1rem;
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: var(--font-sm);
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-settings:hover {
  border-color: var(--accent);
  background: var(--bg-secondary);
}

.btn-create {
  padding: 0.625rem 1.25rem;
  background: var(--accent);
  color: var(--bg-primary);
  border: none;
  border-radius: 6px;
  font-size: var(--font-sm);
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

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

.btn-create:active {
  transform: translateY(0);
}

/* Modal */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.2s ease;
}

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

.modal-content {
  background: var(--bg-secondary);
  border-radius: 12px;
  padding: 2rem;
  width: 90%;
  max-width: 400px;
  box-shadow: 0 20px 60px var(--shadow-lg);
  position: relative;
  animation: slideUp 0.3s ease;
}

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

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

.modal-close:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.modal-content h2 {
  font-size: 1.25rem;
  margin-bottom: 1.5rem;
  font-weight: 600;
}

.modal-content form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

input[type="text"],
input[type="password"] {
  width: 100%;
  padding: 0.75rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.9375rem;
  color: var(--text-primary);
  font-family: inherit;
  transition: all 0.2s ease;
}

input[type="text"]:focus,
input[type="password"]:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--bg-secondary);
}

input[type="text"]:disabled,
input[type="password"]:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.radio-group {
  display: flex;
  gap: 1rem;
}

.radio-label {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.75rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 0.9375rem;
}

.radio-label:hover {
  background: var(--bg-secondary);
  border-color: var(--accent);
}

.radio-label input[type="radio"] {
  margin-right: 0.5rem;
}

.radio-label input[type="radio"]:checked + span {
  font-weight: 500;
}

.btn-primary {
  padding: 0.75rem;
  background: var(--accent);
  color: var(--bg-primary);
  border: none;
  border-radius: 6px;
  font-size: var(--font-base);
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  margin-top: 0.5rem;
}

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

.btn-primary:active {
  transform: translateY(0);
}

/* Settings */
.settings-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

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

/* Rooms List */
.main {
  animation: fadeInUp 0.4s ease;
}

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

.rooms-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}

.rooms-header h2 {
  font-size: 1.125rem;
  font-weight: 600;
}

.room-count {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.rooms-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.room-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.25rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.room-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px var(--shadow);
}

.room-card:active {
  transform: translateY(0);
}

.room-info {
  flex: 1;
}

.room-name {
  font-size: 1rem;
  font-weight: 500;
  margin-bottom: 0.25rem;
}

.room-users {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.room-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.room-badge {
  padding: 0.25rem 0.75rem;
  background: var(--accent);
  color: var(--bg-primary);
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.room-badge.public {
  background: var(--bg-tertiary);
  color: var(--text-secondary);
}

.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-secondary);
}

.empty-state p {
  font-size: 0.9375rem;
}

/* ========== CHAT ROOM ========== */

.chat-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 1200px;
  margin: 0 auto;
}

.chat-body {
  display: flex;
  flex: 1;
  min-height: 0;
}

.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.25rem 1.5rem;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
}

.chat-header-left {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.chat-header-right {
  display: flex;
  align-items: center;
  gap: 0.625rem;
}

.back-btn {
  color: var(--text-secondary);
  text-decoration: none;
  font-size: var(--font-base);
  transition: color 0.2s ease;
}

.back-btn:hover {
  color: var(--text-primary);
}

.room-title {
  font-size: 1.125rem;
  font-weight: 600;
}

.user-count {
  font-size: var(--font-xs);
  color: var(--text-secondary);
  padding: 0.375rem 0.75rem;
  background: var(--bg-tertiary);
  border-radius: 4px;
}

.chat-main {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  background: var(--bg-primary);
  min-width: 0;
}

.invites-sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--bg-secondary);
  border-left: 1px solid var(--border);
  padding: 1rem;
  overflow-y: auto;
}

.invites-sidebar-title {
  font-size: var(--font-sm);
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.invites-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.invites-empty {
  font-size: var(--font-sm);
  color: var(--text-tertiary);
}

.invite-card {
  padding: 0.75rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.invite-label {
  font-weight: 600;
  font-size: var(--font-sm);
}

.invite-by {
  font-size: var(--font-xs);
  color: var(--text-secondary);
  margin: 0.25rem 0 0.5rem;
}

.invite-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.btn-invite-join,
.btn-invite-delete {
  padding: 0.35rem 0.6rem;
  font-size: var(--font-xs);
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.btn-invite-join {
  background: var(--accent);
  color: var(--bg-primary);
}

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

.btn-invite-delete {
  background: var(--bg-primary);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.btn-invite-delete:hover {
  color: var(--text-primary);
  border-color: var(--text-tertiary);
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  max-width: 700px;
  margin: 0 auto;
}

.message {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  padding: 0.875rem 1rem;
  background: var(--bg-secondary);
  border-radius: 8px;
  border: 1px solid var(--border);
  animation: messageAppear 0.2s ease;
}

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

.message.own-message {
  background: var(--accent);
  color: var(--bg-primary);
  border-color: var(--accent);
}

.message-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}

.message-author {
  font-weight: 500;
  font-size: var(--font-sm);
}

.message.own-message .message-author {
  color: var(--bg-primary);
  opacity: 0.9;
}

.message-time {
  font-size: var(--font-xs);
  color: var(--text-tertiary);
  font-family: 'JetBrains Mono', monospace;
}

.message.own-message .message-time {
  color: var(--bg-primary);
  opacity: 0.7;
}

.message-content {
  font-size: var(--font-base);
  line-height: 1.5;
  word-wrap: break-word;
}

.message.own-message .message-content {
  color: var(--bg-primary);
}

.system-message {
  text-align: center;
  color: var(--text-tertiary);
  font-size: var(--font-sm);
  padding: 0.5rem;
  animation: fadeIn 0.3s ease;
}

.chat-footer {
  padding: 1.25rem 1.5rem;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
}

.footer-actions {
  display: flex;
  gap: 0.5rem;
  max-width: 700px;
  margin: 0 auto 0.75rem;
}

.btn-tools {
  padding: 0.5rem 1rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: var(--font-sm);
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-tools:hover {
  border-color: var(--accent);
  background: var(--bg-primary);
}

.message-form {
  display: flex;
  gap: 0.75rem;
  max-width: 700px;
  margin: 0 auto;
}

/* Tools & Games modal */
.modal-content-wide {
  max-width: 480px;
}

.modal-content-winner {
  max-width: 400px;
  padding: 40px 30px;
  text-align: center;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-light, #ff6b9d) 100%);
  color: white;
  border-radius: 15px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.modal-content-winner h2 {
  font-size: 32px;
  margin: 0 0 20px 0;
  font-weight: bold;
}

.btn-close-winner {
  padding: 12px 30px;
  background: white;
  color: var(--accent);
  border: none;
  border-radius: 8px;
  font-weight: bold;
  cursor: pointer;
  font-size: 16px;
  transition: all 0.2s ease;
}

.btn-close-winner:hover {
  transform: scale(1.05);
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}

.tools-games-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.tab-btn {
  padding: 0.5rem 1rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: var(--font-sm);
  cursor: pointer;
  color: var(--text-secondary);
  transition: all 0.2s ease;
}

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

.tool-section {
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.tool-section:last-child {
  border-bottom: none;
}

.tool-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.tool-desc {
  font-size: var(--font-sm);
  color: var(--text-secondary);
  margin-bottom: 0.75rem;
}

.tool-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.5rem;
}

.tool-row label {
  font-size: var(--font-sm);
  color: var(--text-secondary);
}

.tool-input-narrow {
  width: 4rem;
  padding: 0.375rem;
  font-size: var(--font-sm);
}

.tool-result {
  font-size: var(--font-base);
  margin: 0.5rem 0;
  min-height: 1.5em;
}

.btn-small {
  padding: 0.5rem 0.75rem;
  background: var(--accent);
  color: var(--bg-primary);
  border: none;
  border-radius: 6px;
  font-size: var(--font-sm);
  cursor: pointer;
  transition: all 0.2s ease;
}

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

.btn-send-tool {
  margin-top: 0.25rem;
}

.game-invite {
  cursor: pointer;
  color: var(--accent);
  text-decoration: underline;
}

.game-invite:hover {
  opacity: 0.8;
}

.btn-inline-accept {
  margin-left: 0.5rem;
  padding: 0.25rem 0.5rem;
  font-size: var(--font-xs);
  background: var(--accent);
  color: var(--bg-primary);
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.message-form input {
  flex: 1;
  padding: 0.75rem 1rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: var(--font-base);
  color: var(--text-primary);
  font-family: inherit;
  transition: all 0.2s ease;
}

.message-form input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--bg-primary);
}

.send-btn {
  padding: 0.75rem 1.5rem;
  background: var(--accent);
  color: var(--bg-primary);
  border: none;
  border-radius: 8px;
  font-size: var(--font-base);
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

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

.send-btn:active {
  transform: translateY(0);
}

/* Responsive */
@media (max-width: 640px) {
  .container {
    padding: 1.5rem 1rem;
  }

  .header {
    margin-bottom: 2rem;
    padding-bottom: 1.5rem;
  }

  .logo {
    font-size: 1.5rem;
  }

  .modal-content {
    padding: 1.5rem;
  }

  .chat-body {
    flex-direction: column;
  }

  .invites-sidebar {
    width: 100%;
    border-left: none;
    border-top: 1px solid var(--border);
    max-height: 180px;
  }

  .chat-header,
  .chat-footer {
    padding: 1rem;
  }

  .chat-main {
    padding: 1rem;
  }

  .room-title {
    font-size: 1rem;
  }

  .message-form {
    gap: 0.5rem;
  }

  .send-btn {
    padding: 0.75rem 1rem;
  }
}

/* ========== GAME STYLES ========== */

.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.game-turn {
  font-weight: 600;
  color: var(--text-secondary);
  font-size: var(--font-sm);
}

.game-turn.your-turn {
  color: #4ECDC4;
  font-weight: 700;
}

.game-leaderboard {
  margin-top: 2rem;
  padding: 1rem;
  background: var(--bg-tertiary);
  border-radius: 0.5rem;
}

.game-leaderboard strong {
  display: block;
  margin-bottom: 0.75rem;
  font-size: var(--font-sm);
}

.player-info {
  padding: 0.5rem;
  font-size: var(--font-sm);
  color: var(--text-secondary);
}

/* Tic Tac Toe */
.tictactoe-container {
  padding: 1.5rem;
}

.tictactoe-board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
  margin: 1.5rem 0;
  max-width: 300px;
  margin-left: auto;
  margin-right: auto;
}

.ttt-cell {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-secondary);
  border: 2px solid var(--border);
  font-size: 2rem;
  font-weight: 700;
  cursor: pointer;
  border-radius: 0.5rem;
  transition: all 0.2s;
  user-select: none;
}

.ttt-cell:hover {
  background: var(--bg-tertiary);
  transform: scale(1.05);
}

/* Connect 4 */
.connect4-container {
  padding: 1.5rem;
}

.connect4-board {
  display: flex;
  gap: 0.5rem;
  margin: 1.5rem 0;
  justify-content: center;
  background: #1a5276;
  padding: 1rem;
  border-radius: 0.5rem;
}

.c4-column {
  display: flex;
  flex-direction: column-reverse;
  gap: 0.25rem;
  cursor: pointer;
}

.c4-cell {
  width: 40px;
  height: 40px;
  background: #0a0a0a;
  border-radius: 50%;
  border: 2px solid #1a1a1a;
  transition: all 0.2s;
}

.c4-column:hover .c4-cell:last-child {
  transform: scale(1.1);
}

.connect4-controls {
  text-align: center;
  margin: 1rem 0;
}

.connect4-controls .btn-small {
  margin: 0 0.5rem;
}

/* Snake */
.snake-container {
  padding: 1.5rem;
  text-align: center;
}

#snake-canvas {
  image-rendering: pixelated;
  max-width: 100%;
  height: auto;
}

/* Agario */
.agario-container {
  padding: 1.5rem;
  text-align: center;
}

#agario-canvas {
  image-rendering: auto;
  max-width: 100%;
  height: auto;
}

/* Modal styling for games */
.modal-content-wide {
  width: 90%;
  max-width: 800px;
  max-height: 90vh;
  overflow-y: auto;
}