/* === Color Palette (matches homepage) === */
:root {
  --bg: #0b0d10;
  --bg-card: #141820;
  --accent: #00ffd5;
  --accent-dim: #00ffd540;
  --text: #e0e0e6;
  --text-muted: #7a7f8a;
  --border: #1e2330;
  --glow: 0 0 20px #00ffd530;
}

/* === Reset & Base === */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
}

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  position: relative;
  overflow-x: hidden;
}

/* === Grid Background === */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    repeating-linear-gradient(0deg, transparent, transparent 59px, var(--border) 59px, var(--border) 60px),
    repeating-linear-gradient(90deg, transparent, transparent 59px, var(--border) 59px, var(--border) 60px);
  opacity: 0.3;
  pointer-events: none;
  z-index: 0;
}

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

a:hover {
  text-decoration: underline;
}

/* === Layout === */
.page {
  position: relative;
  z-index: 1;
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 1.5rem;
}

/* === Site Header === */
.site-header {
  padding: 1.5rem 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
}

.site-header-title {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--accent);
}

.site-header-nav {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* === Auth Nav === */
.auth-nav {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-left: auto;
}

.auth-sign-in {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.85rem;
}

.auth-email {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.auth-sign-out {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.85rem;
}

/* === Catalog Page === */
.catalog-title {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 1.4rem;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 2rem;
  text-align: center;
}

.game-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.game-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.5rem;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  text-decoration: none;
  display: block;
  color: inherit;
}

.game-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--glow);
  text-decoration: none;
}

.game-card-tag {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  opacity: 0.7;
  margin-bottom: 0.5rem;
}

.game-card-name {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.5rem;
}

.game-card-desc {
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.5;
}

/* === Pagination === */
.pagination {
  text-align: center;
  padding: 2rem 0;
}

.pagination a {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.9rem;
  padding: 0.5rem 1.2rem;
  border: 1px solid var(--accent-dim);
  border-radius: 4px;
}

.pagination a:hover {
  border-color: var(--accent);
  text-decoration: none;
}

/* === Empty State === */
.empty-state {
  text-align: center;
  padding: 4rem 0;
  color: var(--text-muted);
  font-family: 'IBM Plex Mono', monospace;
}

/* === Play Page === */
.game-header {
  margin-bottom: 1.5rem;
}

.game-title {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 1.6rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.5rem;
}

.game-meta {
  display: flex;
  gap: 1rem;
  align-items: center;
  margin-bottom: 0.75rem;
}

.game-category {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  border: 1px solid var(--accent-dim);
  border-radius: 3px;
  padding: 0.15rem 0.5rem;
}

.game-description {
  font-size: 0.95rem;
  color: var(--text-muted);
  line-height: 1.5;
}

/* === Demo Heading === */
.demo-heading {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.5rem;
}

.game-frame-wrapper {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 2rem;
}

.game-frame {
  display: block;
  width: 100%;
  height: 80vh;
  border: none;
  background: #000;
}

/* === Rules Link (inline after description) === */
.rules-link {
  font-family: 'IBM Plex Mono', monospace;
  font-size: inherit;
  color: var(--accent);
  cursor: pointer;
  white-space: nowrap;
}

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

/* === Rules Overlay === */
.rules-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  z-index: 100;
  display: none;
  justify-content: center;
  align-items: center;
  padding: 1.5rem;
}

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

.rules-panel {
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2rem;
  max-width: 600px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
}

.rules-close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
  padding: 0.25rem;
}

.rules-close:hover {
  color: var(--text);
}

.rules-content h3 {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--accent);
  margin: 1rem 0 0.5rem;
}

.rules-content h3:first-child {
  margin-top: 0;
}

.rules-content h4 {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  margin: 0.75rem 0 0.4rem;
}

.rules-content p {
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.6;
  margin: 0.4rem 0;
}

.rules-content ul {
  list-style: disc;
  padding-left: 1.25rem;
  margin: 0.4rem 0;
}

.rules-content li {
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.6;
  margin: 0.2rem 0;
}

/* === Footer === */
.footer {
  border-top: 1px solid var(--border);
  padding: 2rem 0;
  text-align: center;
  margin-top: 2rem;
}

.footer-text {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.footer-links {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.8rem;
  margin-top: 0.5rem;
}

.footer-links a {
  color: var(--text-muted);
  text-decoration: none;
}

.footer-links a:hover {
  color: var(--accent);
  text-decoration: underline;
}

/* === Responsive === */
@media (max-width: 900px) {
  .game-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 600px) {
  .site-header {
    flex-wrap: wrap;
    gap: 0.5rem 1rem;
  }

  .site-header-nav {
    order: 3;
    width: 100%;
  }

  .auth-email {
    display: none;
  }

  .game-grid {
    grid-template-columns: 1fr;
  }
}

/* === Parent Game Bar (.gp-*) === */

.gp-game-bar {
  font-family: 'IBM Plex Mono', monospace;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem 1.25rem;
  margin-bottom: 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.gp-players {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  gap: 1rem;
}

.gp-player {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.75rem;
  border-radius: 6px;
  border: 1px solid transparent;
  transition: border-color 0.25s ease, background 0.25s ease;
}

.gp-player.gp-active {
  border-color: var(--accent-dim);
  background: rgba(0, 255, 213, 0.04);
}

.gp-player-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
}

.gp-player-p1 .gp-player-name { color: #00DDFF; }
.gp-player-p2 .gp-player-name { color: #FFAA00; }

.gp-player-score {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-muted);
  min-width: 1.2em;
  text-align: center;
}

.gp-status {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  flex: 1;
  min-width: 0;
}

.gp-turn-indicator {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.gp-turn-indicator.gp-turn-p1 { color: #00DDFF; }
.gp-turn-indicator.gp-turn-p2 { color: #FFAA00; }
.gp-turn-indicator.gp-draw    { color: var(--accent); }

.gp-move-count-wrap {
  font-size: 0.7rem;
  color: var(--text-muted);
  letter-spacing: 0.04em;
}

.gp-new-match {
  appearance: none;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--accent);
  background: transparent;
  border: 1px solid var(--accent-dim);
  border-radius: 6px;
  padding: 0.4rem 1.2rem;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease;
  margin-top: 0.25rem;
}

.gp-new-match:hover {
  border-color: var(--accent);
  background: rgba(0, 255, 213, 0.08);
}

.gp-new-match:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media (max-width: 480px) {
  .gp-game-bar {
    padding: 0.5rem 0.75rem;
  }

  .gp-players {
    gap: 0.5rem;
  }

  .gp-player {
    padding: 0.25rem 0.5rem;
  }

  .gp-player-name {
    font-size: 0.75rem;
  }

  .gp-turn-indicator {
    font-size: 0.8rem;
  }
}

/* === Play Online Button === */
.play-online-btn {
  display: inline-block;
  margin-top: 0.75rem;
  margin-left: 0.5rem;
  padding: 0.4rem 1rem;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--bg);
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.2s ease, opacity 0.2s ease;
}

.play-online-btn:hover {
  opacity: 0.85;
}

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

/* === Match Discovery Actions === */
.mp-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-top: 1.25rem;
  margin-bottom: 1.25rem;
}

.mp-actions .play-online-btn {
  margin: 0;
}

.play-online-btn-secondary {
  color: var(--accent);
  background: transparent;
  border: 1px solid var(--accent-dim);
}

.play-online-btn-secondary:hover {
  border-color: var(--accent);
  opacity: 1;
}

.join-code-form {
  display: flex;
  align-items: stretch;
  gap: 0.35rem;
}

.join-code-input {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.85rem;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--accent-dim);
  border-radius: 4px;
  padding: 0 0.6rem;
  width: 7.5rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.join-code-form .play-online-btn {
  margin: 0;
}

.join-code-input::placeholder {
  color: var(--text-muted);
  text-transform: none;
  letter-spacing: normal;
}

.join-code-input:focus {
  outline: none;
  border-color: var(--accent);
}

/* === Join a Match Section === */
.mp-join-section {
  margin-top: 1rem;
}

.mp-join-title {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.5rem;
}

/* === Lobby Section === */
.lobby-section {
  margin-top: 1.25rem;
}

.lobby-title {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.5rem;
}

.lobby-list {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.lobby-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.4rem 0.75rem;
}

.lobby-creator {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.85rem;
  color: var(--text);
}

.lobby-join-btn {
  margin: 0;
  padding: 0.25rem 0.75rem;
  font-size: 0.8rem;
}

/* === Invite Code Display (match play page) === */
.gp-invite-code {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: center;
  padding: 0.25rem 0;
}

.gp-invite-code-value {
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 0.1em;
}

@media (max-width: 600px) {
  .mp-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .mp-actions .play-online-btn {
    text-align: center;
  }

  .join-code-form {
    width: 100%;
  }

  .join-code-input {
    flex: 1;
  }
}

/* === Multiplayer Game Bar (.gp-mp) === */
.gp-mp .gp-waiting {
  font-size: 0.85rem;
  color: var(--accent);
  animation: gp-pulse 2s ease-in-out infinite;
  text-align: center;
  padding: 0.25rem 0;
}

@keyframes gp-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.gp-turn-indicator.gp-waiting-pulse {
  animation: gp-pulse 2s ease-in-out infinite;
}

.gp-mp .gp-share-url {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: center;
  padding: 0.25rem 0;
}

.gp-share-input {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.75rem;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.25rem 0.5rem;
  width: 280px;
  max-width: 100%;
}

.gp-mp .gp-error {
  font-size: 0.85rem;
  color: #ff5555;
  text-align: center;
  padding: 0.25rem 0;
}

.gp-back-link {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.8rem;
  color: var(--text-muted);
  text-decoration: none;
  margin-top: 0.25rem;
}

.gp-back-link:hover {
  color: var(--accent);
  text-decoration: underline;
}

/* === Reduced Motion === */
@media (prefers-reduced-motion: reduce) {
  .game-card {
    transition: none;
  }

  .gp-player {
    transition: none;
  }
}
