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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  line-height: 1.6;
  color: #e0e0e0;
  background: #0a0a1a;
  min-height: 100vh;
  position: relative;
}

body::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background:
    radial-gradient(2px 2px at 10% 20%, #fff, transparent),
    radial-gradient(2px 2px at 20% 50%, rgba(255,255,255,0.8), transparent),
    radial-gradient(1px 1px at 30% 10%, #fff, transparent),
    radial-gradient(2px 2px at 40% 70%, rgba(255,255,255,0.9), transparent),
    radial-gradient(1px 1px at 50% 30%, #fff, transparent),
    radial-gradient(2px 2px at 60% 80%, rgba(255,255,255,0.7), transparent),
    radial-gradient(1px 1px at 70% 15%, #fff, transparent),
    radial-gradient(2px 2px at 80% 60%, rgba(255,255,255,0.8), transparent),
    radial-gradient(1px 1px at 90% 40%, #fff, transparent),
    radial-gradient(2px 2px at 15% 85%, rgba(255,255,255,0.9), transparent),
    radial-gradient(1px 1px at 25% 35%, #fff, transparent),
    radial-gradient(2px 2px at 35% 90%, rgba(255,255,255,0.7), transparent),
    radial-gradient(1px 1px at 45% 5%, #fff, transparent),
    radial-gradient(2px 2px at 55% 55%, rgba(255,255,255,0.8), transparent),
    radial-gradient(1px 1px at 65% 95%, #fff, transparent),
    radial-gradient(2px 2px at 75% 25%, rgba(255,255,255,0.9), transparent),
    radial-gradient(1px 1px at 85% 75%, #fff, transparent),
    radial-gradient(2px 2px at 95% 45%, rgba(255,255,255,0.7), transparent),
    radial-gradient(3px 3px at 12% 65%, #ff6432, transparent),
    radial-gradient(3px 3px at 48% 42%, #667eea, transparent),
    radial-gradient(3px 3px at 78% 88%, #ff6432, transparent),
    radial-gradient(3px 3px at 92% 12%, #667eea, transparent),
    radial-gradient(ellipse at bottom, #1a1a3a 0%, #0a0a1a 100%);
  animation: twinkle 4s ease-in-out infinite alternate;
  z-index: -1;
}

@keyframes twinkle {
  0% { opacity: 0.8; }
  100% { opacity: 1; }
}

nav {
  background: rgba(10, 10, 30, 0.95);
  padding: 1rem 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid rgba(255, 100, 50, 0.3);
  box-shadow: 0 2px 20px rgba(255, 100, 50, 0.1);
}

.nav-brand {
  font-size: 1.5rem;
  font-weight: bold;
  color: #ff6432;
  text-decoration: none;
  text-transform: uppercase;
  letter-spacing: 2px;
}

.nav-links a {
  color: #e0e0e0;
  text-decoration: none;
  margin-left: 2rem;
  transition: color 0.3s;
}

.nav-links a:hover {
  color: #ff6432;
}

main {
  max-width: 900px;
  margin: 2rem auto;
  padding: 2rem;
  background: rgba(20, 20, 40, 0.9);
  border-radius: 16px;
  border: 1px solid rgba(255, 100, 50, 0.2);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5), 0 0 60px rgba(255, 100, 50, 0.1);
}

.hero {
  text-align: center;
  padding: 2rem 0;
}

.hero-img {
  max-width: 400px;
  width: 100%;
  border-radius: 12px;
  border: 3px solid #ff6432;
  margin-bottom: 1.5rem;
  box-shadow: 0 0 30px rgba(255, 100, 50, 0.4);
}

h1 {
  font-size: 2.5rem;
  color: #fff;
  margin-bottom: 0.5rem;
  text-shadow: 0 0 20px rgba(255, 100, 50, 0.5);
}

.tagline {
  font-size: 1.2rem;
  color: #aaa;
}

.content {
  padding: 1rem 0;
}

.content h2 {
  color: #ff6432;
  margin: 1.5rem 0 1rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  font-size: 1.3rem;
}

.content p {
  margin-bottom: 1rem;
  color: #ccc;
}

.content ul {
  margin-left: 2rem;
  margin-bottom: 1rem;
}

.content li {
  margin-bottom: 0.5rem;
  color: #bbb;
}

.page-header {
  text-align: center;
  padding-bottom: 1rem;
  border-bottom: 2px solid rgba(255, 100, 50, 0.3);
  margin-bottom: 2rem;
}

footer {
  text-align: center;
  padding: 2rem;
  color: rgba(255, 255, 255, 0.5);
}

/* Forms */
.form-container {
  max-width: 400px;
  margin: 0 auto;
}

.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  margin-bottom: 0.5rem;
  color: #ccc;
}

.form-group input,
.form-group textarea {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid rgba(255, 100, 50, 0.3);
  border-radius: 8px;
  background: rgba(10, 10, 30, 0.8);
  color: #e0e0e0;
  font-size: 1rem;
}

.form-group input:focus,
.form-group textarea:focus {
  outline: none;
  border-color: #ff6432;
  box-shadow: 0 0 10px rgba(255, 100, 50, 0.3);
}

.form-row {
  display: flex;
  gap: 1rem;
  align-items: flex-end;
  flex-wrap: wrap;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
}

/* Buttons */
.btn {
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1rem;
  transition: all 0.3s;
}

.btn-primary {
  background: linear-gradient(135deg, #ff6432, #ff8c32);
  color: white;
}

.btn-primary:hover {
  box-shadow: 0 0 20px rgba(255, 100, 50, 0.5);
  transform: translateY(-2px);
}

.btn-danger {
  background: linear-gradient(135deg, #dc3545, #c82333);
  color: white;
}

.btn-danger:hover {
  box-shadow: 0 0 20px rgba(220, 53, 69, 0.5);
}

.btn-small {
  padding: 0.4rem 0.8rem;
  font-size: 0.85rem;
}

/* Messages */
.error {
  background: rgba(220, 53, 69, 0.2);
  border: 1px solid #dc3545;
  color: #ff6b7a;
  padding: 0.75rem;
  border-radius: 8px;
  margin-bottom: 1rem;
}

.success {
  background: rgba(40, 167, 69, 0.2);
  border: 1px solid #28a745;
  color: #5dd879;
  padding: 0.75rem;
  border-radius: 8px;
  margin-bottom: 1rem;
}

/* Notes Grid */
.notes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.note-card {
  background: rgba(10, 10, 30, 0.6);
  border: 1px solid rgba(255, 100, 50, 0.2);
  border-radius: 12px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
}

.note-card h3 {
  color: #ff6432;
  margin-bottom: 0.5rem;
}

.note-card p {
  flex: 1;
  color: #bbb;
  font-size: 0.9rem;
}

/* Tables */
.data-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 1rem;
}

.data-table th,
.data-table td {
  padding: 0.75rem;
  text-align: left;
  border-bottom: 1px solid rgba(255, 100, 50, 0.2);
}

.data-table th {
  color: #ff6432;
  text-transform: uppercase;
  font-size: 0.85rem;
}

.data-table td {
  color: #ccc;
}

.data-table .actions {
  display: flex;
  gap: 0.5rem;
}

.muted {
  color: #666;
  font-style: italic;
}

/* Chat */
.chat-room-main {
  max-width: 1000px;
  margin: 2rem auto;
  padding: 1.5rem;
  background: rgba(20, 20, 40, 0.9);
  border-radius: 16px;
  border: 1px solid rgba(255, 100, 50, 0.2);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5), 0 0 60px rgba(255, 100, 50, 0.1);
  display: flex;
  flex-direction: column;
}

.chat-room-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding-bottom: 1rem;
  border-bottom: 2px solid rgba(255, 100, 50, 0.3);
  margin-bottom: 1rem;
}

.back-link {
  color: #ff6432;
  text-decoration: none;
  font-size: 0.9rem;
  display: block;
  margin-bottom: 0.25rem;
}

.back-link:hover {
  text-decoration: underline;
}

.chat-room-title {
  font-size: 1.4rem;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.chat-room-owner {
  color: #888;
  font-size: 0.85rem;
  margin-top: 0.15rem;
}

.badge-private {
  background: rgba(102, 126, 234, 0.25);
  border: 1px solid #667eea;
  color: #a0b0ff;
  padding: 0.1rem 0.5rem;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  vertical-align: middle;
}

.badge-public {
  background: rgba(40, 167, 69, 0.2);
  border: 1px solid #28a745;
  color: #5dd879;
  padding: 0.1rem 0.5rem;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  vertical-align: middle;
}

.chat-layout {
  display: flex;
  gap: 1rem;
  min-height: 0;
}

.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chat-messages {
  height: 460px;
  overflow-y: auto;
  padding: 0.75rem;
  background: rgba(10, 10, 30, 0.5);
  border-radius: 10px;
  border: 1px solid rgba(255, 100, 50, 0.15);
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 0.75rem;
}

.chat-messages::-webkit-scrollbar {
  width: 5px;
}

.chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: rgba(255, 100, 50, 0.3);
  border-radius: 3px;
}

.chat-message {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  padding: 0.3rem 0.5rem;
  border-radius: 6px;
  word-break: break-word;
}

.chat-message:hover {
  background: rgba(255, 255, 255, 0.03);
}

.chat-message.own .chat-username {
  color: #ff8c32;
}

.chat-username {
  color: #667eea;
  font-weight: 600;
  font-size: 0.88rem;
  white-space: nowrap;
  flex-shrink: 0;
}

.chat-content {
  color: #e0e0e0;
  font-size: 0.95rem;
  flex: 1;
}

.chat-time {
  color: #555;
  font-size: 0.75rem;
  white-space: nowrap;
  flex-shrink: 0;
}

.chat-system {
  text-align: center;
  color: #555;
  font-size: 0.8rem;
  font-style: italic;
  padding: 0.2rem 0;
}

.chat-empty {
  text-align: center;
  color: #555;
  font-style: italic;
  margin: auto;
}

.typing-indicator {
  min-height: 1.4rem;
  padding: 0 0.5rem 0.3rem;
  color: #888;
  font-size: 0.8rem;
  font-style: italic;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.typing-dots {
  display: inline-flex;
  gap: 2px;
}

.typing-dots span {
  display: inline-block;
  animation: typingBounce 1.2s infinite;
  font-style: normal;
}

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

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-4px); opacity: 1; }
}

.member-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: #bbb;
  font-size: 0.88rem;
  padding: 0.25rem 0.4rem;
  border-radius: 4px;
}

.member-item:hover {
  background: rgba(255, 100, 50, 0.08);
  color: #e0e0e0;
}

.chat-room-title-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.btn-rename {
  background: none;
  border: none;
  color: #555;
  cursor: pointer;
  font-size: 1rem;
  padding: 0 0.2rem;
  line-height: 1;
  transition: color 0.2s;
  flex-shrink: 0;
}

.btn-rename:hover {
  color: #ff6432;
}

.rename-form {
  display: none;
  align-items: center;
  gap: 0.4rem;
  margin: 0.4rem 0;
}

.rename-input {
  padding: 0.4rem 0.6rem;
  border: 1px solid rgba(255, 100, 50, 0.4);
  border-radius: 8px;
  background: rgba(10, 10, 30, 0.8);
  color: #e0e0e0;
  font-size: 0.9rem;
  width: 180px;
}

.rename-input:focus {
  outline: none;
  border-color: #ff6432;
}

.btn-attach {
  background: none;
  border: 1px solid rgba(255, 100, 50, 0.3);
  border-radius: 8px;
  color: #aaa;
  cursor: pointer;
  font-size: 1.1rem;
  padding: 0 0.6rem;
  height: 100%;
  transition: all 0.2s;
  flex-shrink: 0;
}

.btn-attach:hover {
  border-color: #ff6432;
  color: #ff6432;
}

.btn-attach:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.chat-image {
  max-width: 240px;
  max-height: 200px;
  border-radius: 8px;
  border: 1px solid rgba(255, 100, 50, 0.2);
  display: block;
  cursor: pointer;
  transition: opacity 0.2s;
}

.chat-image:hover {
  opacity: 0.85;
}

.chat-image-link {
  display: inline-block;
  flex: 1;
}

.btn-kick {
  background: none;
  border: none;
  color: #555;
  cursor: pointer;
  font-size: 0.75rem;
  padding: 0 0.2rem;
  line-height: 1;
  border-radius: 3px;
  transition: color 0.2s;
  flex-shrink: 0;
}

.btn-kick:hover {
  color: #dc3545;
}

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

.chat-input {
  flex: 1;
  padding: 0.75rem;
  border: 1px solid rgba(255, 100, 50, 0.3);
  border-radius: 8px;
  background: rgba(10, 10, 30, 0.8);
  color: #e0e0e0;
  font-size: 1rem;
}

.chat-input:focus {
  outline: none;
  border-color: #ff6432;
  box-shadow: 0 0 10px rgba(255, 100, 50, 0.3);
}

.chat-sidebar {
  width: 180px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.chat-sidebar h3 {
  color: #ff6432;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 0.25rem;
}

.member-list {
  list-style: none;
  background: rgba(10, 10, 30, 0.5);
  border: 1px solid rgba(255, 100, 50, 0.15);
  border-radius: 8px;
  padding: 0.5rem;
  max-height: 220px;
  overflow-y: auto;
}


.invite-section {
  margin-top: 1rem;
}

.invite-form {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-top: 0.5rem;
}

.invite-input {
  padding: 0.5rem;
  border: 1px solid rgba(255, 100, 50, 0.3);
  border-radius: 8px;
  background: rgba(10, 10, 30, 0.8);
  color: #e0e0e0;
  font-size: 0.88rem;
  width: 100%;
}

.invite-input:focus {
  outline: none;
  border-color: #ff6432;
}

/* Room list on /chat */
.room-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-top: 0.75rem;
}

.room-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.85rem 1rem;
  background: rgba(10, 10, 30, 0.6);
  border: 1px solid rgba(255, 100, 50, 0.2);
  border-radius: 10px;
  text-decoration: none;
  transition: all 0.2s;
}

.room-card:hover {
  border-color: rgba(255, 100, 50, 0.5);
  background: rgba(255, 100, 50, 0.05);
  transform: translateX(4px);
}

.room-card-private {
  border-color: rgba(102, 126, 234, 0.25);
}

.room-card-private:hover {
  border-color: rgba(102, 126, 234, 0.55);
}

.room-card-name {
  color: #e0e0e0;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.room-card-meta {
  color: #666;
  font-size: 0.82rem;
}

@media (max-width: 600px) {
  nav {
    flex-direction: column;
    gap: 1rem;
  }

  .nav-links a {
    margin: 0 1rem;
  }

  main {
    margin: 1rem;
    padding: 1.5rem;
  }

  h1 {
    font-size: 2rem;
  }

  .hero-img {
    max-width: 300px;
  }
}

/* ── Game ──────────────────────────────────────────────────────────────────── */
.game-session-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.game-session-card {
  display: block;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 10px;
  padding: 1rem 1.25rem;
  text-decoration: none;
  color: inherit;
  transition: background 0.2s, border-color 0.2s;
}
.game-session-card:hover {
  background: rgba(255,255,255,0.09);
  border-color: rgba(102,126,234,0.5);
}

.game-session-host { font-weight: 600; margin-bottom: 0.25rem; }
.game-session-meta { font-size: 0.85rem; color: #aaa; }

.game-status { text-transform: capitalize; }
.game-status-waiting { color: #ffd700; }
.game-status-playing { color: #28a745; }
.game-status-ended   { color: #aaa; }

/* Session page */
.game-session-main {
  max-width: 900px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

.game-lobby-header {
  margin-bottom: 1.5rem;
}
.game-lobby-header h1 { font-size: 2rem; margin-bottom: 0.25rem; }

.game-lobby-body {
  display: flex;
  gap: 2rem;
  flex-wrap: wrap;
}

.game-lobby-players {
  flex: 1;
  min-width: 200px;
}
.game-lobby-players h3 { margin-bottom: 0.75rem; }

.game-player-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.game-player-item {
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 6px;
  padding: 0.5rem 0.75rem;
  font-size: 0.95rem;
}

.game-lobby-actions { flex: 1; min-width: 200px; }

/* HUD */
.game-hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 720px;
  margin: 0 auto 0.5rem;
  padding: 0.5rem 0.75rem;
  background: rgba(0,0,0,0.4);
  border-radius: 8px;
}
.game-scoreboard { display: flex; gap: 1rem; flex-wrap: wrap; }
.hud-player { font-size: 0.9rem; font-weight: 600; }
.game-timer { font-size: 1.1rem; font-weight: 700; color: #ffd700; }

/* Canvas */
.game-canvas-wrap {
  max-width: 720px;
  margin: 0 auto;
  border: 2px solid rgba(255,255,255,0.12);
  border-radius: 8px;
  overflow: hidden;
  line-height: 0;
}
#gameCanvas { display: block; }

/* Results */
.game-results {
  max-width: 480px;
  margin: 3rem auto;
  text-align: center;
}
.game-results h2 { font-size: 2rem; margin-bottom: 1.5rem; }
.game-results-list { display: flex; flex-direction: column; gap: 0.75rem; }
.game-result-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  background: rgba(255,255,255,0.06);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  text-align: left;
}
.game-result-rank { font-size: 1.5rem; width: 2rem; }
.game-result-name { flex: 1; font-weight: 600; }
.game-result-score { color: #aaa; font-size: 0.9rem; }
