/* ============================================================
   CODEX GAMES - Daily Wordle / Quordle styles
   Loaded only on games.php, alongside style.css
   ============================================================ */

.codex-container {
  max-width: 900px;
  margin: 0 auto;
  padding: 1.5rem 1rem 3rem;
  /* Stop iOS double-tap-to-zoom when rapidly tapping keys; scrolling
     and pinch-zoom still work as normal */
  touch-action: manipulation;
}

.codex-key,
.codex-tab,
.codex-mode-btn,
.codex-lb-tab {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.codex-loading {
  text-align: center;
  color: var(--text-secondary);
  padding: 2rem;
  font-style: italic;
}

/* ── Mode toggle (Standard / Inquisitor) ── */
.codex-mode-toggle {
  display: flex;
  justify-content: center;
  gap: 0;
  margin-bottom: 0.75rem;
}

.codex-mode-btn {
  font-family: 'Cinzel', serif;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
  padding: 0.4rem 1.2rem;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.codex-mode-btn:first-child { border-radius: var(--card-radius) 0 0 var(--card-radius); }
.codex-mode-btn:last-child { border-radius: 0 var(--card-radius) var(--card-radius) 0; border-left: none; }

.codex-mode-btn:hover { color: var(--gold-primary); }

.codex-mode-btn.active {
  color: var(--gold-primary);
  border-color: var(--gold-primary);
  background: var(--bg-card-hover);
}

.codex-mode-btn.inq.active {
  color: var(--red-secondary);
  border-color: var(--red-primary);
  box-shadow: 0 0 8px var(--red-glow);
}

.codex-mode-toggle.small { margin-bottom: 0.6rem; }
.codex-mode-toggle.small .codex-mode-btn { padding: 0.25rem 0.8rem; font-size: 0.8rem; }

/* ── Inquisitor modifier bar ── */
.codex-inq-bar {
  max-width: 560px;
  margin: 0 auto 1rem;
  background: var(--bg-card);
  border: 1px solid var(--red-primary);
  border-radius: var(--card-radius);
  padding: 0.6rem 0.9rem;
  text-align: center;
}

.codex-inq-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-right: 0.4rem;
}

.codex-banned-chip {
  display: inline-block;
  background: var(--red-primary);
  color: #fff;
  font-weight: 700;
  padding: 0.05rem 0.5rem;
  margin: 0 0.15rem;
  border-radius: 3px;
  text-decoration: line-through;
}

.codex-inq-demand {
  margin-top: 0.4rem;
  color: var(--red-secondary);
  font-weight: 600;
  font-size: 0.9rem;
}

.codex-inq-demand.quiet {
  color: var(--text-muted);
  font-weight: 400;
  font-style: italic;
}

/* ── Game tabs ── */
.codex-tabs {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.75rem;
}

.codex-tab {
  font-family: 'Cinzel', serif;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--card-radius);
  padding: 0.5rem 1rem;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.codex-tab:hover { color: var(--gold-primary); border-color: var(--gold-dim); }

.codex-tab.active {
  color: var(--gold-primary);
  border-color: var(--gold-primary);
  background: var(--bg-card-hover);
  box-shadow: 0 0 8px var(--gold-glow);
}

.codex-tab.done-win::after { content: ' ✓'; color: #538d4e; }
.codex-tab.done-loss::after { content: ' ✗'; color: var(--red-secondary); }

.codex-game-desc {
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin: 0 0 1rem;
}

/* ── Stats strip ── */
.codex-stats-strip {
  display: flex;
  justify-content: center;
  gap: 1.5rem;
  margin-bottom: 1rem;
}

.codex-stat { text-align: center; }

.codex-stat-value {
  display: block;
  font-family: 'Cinzel', serif;
  font-size: 1.4rem;
  color: var(--gold-primary);
}

.codex-stat-label {
  display: block;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

/* ── Banner & toast ── */
.codex-banner {
  text-align: center;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--card-radius);
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
}

.codex-banner-title { font-family: 'Cinzel', serif; font-size: 1.2rem; }
.codex-banner-title.win { color: #6aaa64; }
.codex-banner-title.loss { color: var(--red-secondary); }

.codex-banner-word {
  color: var(--text-primary);
  letter-spacing: 0.15em;
  margin: 0.25rem 0;
  font-weight: 600;
}

.codex-banner-next { color: var(--text-secondary); font-size: 0.85rem; }
.codex-countdown { color: var(--gold-primary); font-variant-numeric: tabular-nums; }

.codex-toast {
  position: fixed;
  top: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text-primary);
  color: var(--bg-primary);
  font-weight: 600;
  padding: 0.6rem 1.2rem;
  border-radius: var(--card-radius);
  z-index: 100;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}

/* ── Boards ── */
.codex-boards {
  display: flex;
  justify-content: center;
  margin-bottom: 1.25rem;
}

.codex-boards.quad {
  display: grid;
  grid-template-columns: repeat(2, auto);
  gap: 1rem 1.5rem;
  justify-content: center;
}

.codex-board {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.codex-board.solved { opacity: 0.45; }

.codex-row { display: flex; gap: 4px; }

.codex-row.shake { animation: codex-shake 0.4s; }

@keyframes codex-shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 70% { transform: translateX(-6px); }
  40%, 60% { transform: translateX(6px); }
  50% { transform: translateX(-4px); }
}

.codex-tile {
  width: 52px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-primary);
  border: 2px solid var(--border-light);
  border-radius: 3px;
  background: transparent;
  user-select: none;
}

.codex-tile.typed {
  border-color: var(--gold-dim);
  animation: codex-pop 0.1s;
}

@keyframes codex-pop {
  0% { transform: scale(0.9); }
  60% { transform: scale(1.08); }
  100% { transform: scale(1); }
}

.codex-tile.correct { background: #538d4e; border-color: #538d4e; color: #fff; }
.codex-tile.present { background: #b59f3b; border-color: #b59f3b; color: #fff; }
.codex-tile.absent  { background: #3a3a3c; border-color: #3a3a3c; color: #d0d0d0; }

.codex-tile.reveal { animation: codex-flip 0.5s ease backwards; }

/* Inquisitor: marker on the tile whose feedback may be a lie */
.codex-tile { position: relative; }

.codex-liar-badge {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 16px;
  height: 16px;
  background: var(--red-secondary);
  border: 1px solid #ff6b6b;
  border-radius: 50%;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  line-height: 14px;
  text-align: center;
  z-index: 2;
}

.codex-boards.quad .codex-liar-badge {
  width: 11px;
  height: 11px;
  font-size: 7px;
  line-height: 9px;
  top: -4px;
  right: -4px;
}

@keyframes codex-flip {
  0% { transform: rotateX(90deg); background: transparent; border-color: var(--border-light); color: transparent; }
  50% { transform: rotateX(90deg); }
  100% { transform: rotateX(0); }
}

/* Quordle boards: smaller tiles */
.codex-boards.quad .codex-tile {
  width: 34px;
  height: 34px;
  font-size: 1rem;
  border-width: 1.5px;
}

/* 6-letter single board: slightly smaller so 6 tiles fit on mobile */
.codex-boards.len6:not(.quad) .codex-tile { width: 48px; height: 48px; }

/* ── Keyboard ── */
.codex-keyboard {
  max-width: 520px;
  margin: 0 auto;
  user-select: none;
}

.codex-kb-row {
  display: flex;
  justify-content: center;
  gap: 5px;
  margin-bottom: 6px;
}

.codex-key {
  position: relative;
  flex: 1;
  max-width: 44px;
  height: 54px;
  border: none;
  border-radius: 4px;
  background: var(--bg-tertiary);
  color: var(--text-primary);
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
  overflow: hidden;
  transition: background var(--transition-fast);
}

.codex-key:hover { background: var(--bg-card-hover); }
.codex-key:active { transform: scale(0.95); }

.codex-key.wide { max-width: 68px; flex: 1.6; font-size: 0.7rem; }

.codex-key.banned {
  background: var(--red-primary);
  color: rgba(255, 255, 255, 0.55);
  text-decoration: line-through;
  cursor: not-allowed;
}

.codex-key.correct { background: #538d4e; color: #fff; }
.codex-key.present { background: #b59f3b; color: #fff; }
.codex-key.absent  { background: #232325; color: #6a6a6a; }

/* Quordle quadrant keys: 2x2 board indicators behind the letter */
.codex-key-quad {
  position: absolute;
  width: 50%;
  height: 50%;
  background: transparent;
}
.codex-key-quad:nth-child(1) { top: 0; left: 0; }
.codex-key-quad:nth-child(2) { top: 0; right: 0; }
.codex-key-quad:nth-child(3) { bottom: 0; left: 0; }
.codex-key-quad:nth-child(4) { bottom: 0; right: 0; }

.codex-key-quad.correct { background: #538d4e; }
.codex-key-quad.present { background: #b59f3b; }
.codex-key-quad.absent  { background: #232325; }

.codex-key-label {
  position: relative;
  z-index: 1;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7);
}

/* ── Guest CTA ── */
.codex-cta {
  text-align: center;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--card-radius);
  padding: 2.5rem 1.5rem;
  margin-bottom: 2rem;
}

.codex-cta h2 {
  font-family: 'Cinzel Decorative', serif;
  color: var(--gold-primary);
  margin-bottom: 0.75rem;
}

.codex-cta p {
  color: var(--text-secondary);
  max-width: 480px;
  margin: 0 auto 1.5rem;
}

.codex-cta-btn {
  display: inline-block;
  width: auto;
  padding: 0.7rem 2rem;
  text-decoration: none;
}

/* ── Leaderboard (lives in the Games view on stats.php) ── */
#games-view {
  overflow-y: auto;
  height: 100%;
  padding: 20px 24px;
}

#games-view .codex-leaderboard-section {
  max-width: 700px;
  margin: 0 auto;
}

.codex-lb-intro {
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-bottom: 1rem;
}

.codex-lb-intro a { color: var(--gold-primary); }

/* Link from the game page over to the leaderboards */
.codex-lb-link-row {
  text-align: center;
  margin-top: 1.25rem;
}

.codex-lb-link {
  color: var(--gold-primary);
  font-size: 0.9rem;
  text-decoration: none;
  border-bottom: 1px solid var(--gold-dim);
  transition: color var(--transition-fast);
}

.codex-lb-link:hover { color: var(--text-primary); }

.codex-leaderboard-section { margin-top: 2.5rem; }

.codex-leaderboard-section h2 {
  font-family: 'Cinzel', serif;
  color: var(--gold-primary);
  text-align: center;
  margin-bottom: 1rem;
}

.codex-lb-tabs {
  display: flex;
  justify-content: center;
  gap: 0.4rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.codex-lb-tab {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--card-radius);
  padding: 0.35rem 0.8rem;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.codex-lb-tab:hover { color: var(--gold-primary); }
.codex-lb-tab.active { color: var(--gold-primary); border-color: var(--gold-primary); }

.codex-lb-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--card-radius);
  overflow: hidden;
}

.codex-lb-table th {
  font-family: 'Cinzel', serif;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  padding: 0.6rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border-color);
}

.codex-lb-table td {
  padding: 0.5rem 0.75rem;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-color);
}

.codex-lb-table tbody tr:last-child td { border-bottom: none; }
.codex-lb-table tbody tr:nth-child(1) .codex-lb-rank { color: var(--gold-primary); font-weight: 700; }
.codex-lb-table tbody tr:nth-child(2) .codex-lb-rank { color: #c0c0c0; font-weight: 700; }
.codex-lb-table tbody tr:nth-child(3) .codex-lb-rank { color: #cd7f32; font-weight: 700; }

.codex-lb-user { color: var(--text-primary); font-weight: 600; }

.codex-lb-empty {
  text-align: center;
  color: var(--text-muted);
  padding: 1.5rem;
  font-style: italic;
}

/* ── Profile page: game record cards ── */
.profile-games-link { color: var(--gold-primary); }

.profile-games-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.75rem;
}

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

.profile-game-card h4 {
  font-family: 'Cinzel', serif;
  color: var(--gold-primary);
  font-size: 0.9rem;
  margin: 0 0 0.5rem;
  text-align: center;
}

.profile-game-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  text-align: center;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.profile-game-stats span {
  display: block;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
}

/* ── Mobile ── */
@media (max-width: 600px) {
  .codex-container { padding: 1rem 0.5rem 2rem; }

  .codex-tile { width: 44px; height: 44px; font-size: 1.25rem; }
  .codex-boards.len6:not(.quad) .codex-tile { width: 40px; height: 40px; }

  .codex-boards.quad { gap: 0.6rem 0.75rem; }
  .codex-boards.quad .codex-tile { width: 26px; height: 26px; font-size: 0.8rem; }

  .codex-key { height: 48px; font-size: 0.8rem; }
  .codex-stats-strip { gap: 1rem; }
  .codex-stat-value { font-size: 1.15rem; }

  .codex-lb-table th, .codex-lb-table td { padding: 0.4rem 0.4rem; font-size: 0.85rem; }

  #games-view { padding: 10px 8px; }
}
