/* ═══════════════════════════════════════════════════════════════════════════════
   WORD CHAIN GAME — Styles
   ═══════════════════════════════════════════════════════════════════════════════ */

/* ─── Design Tokens ───────────────────────────────────────────────────────── */
:root {
  --primary: #6366f1;
  --primary-glow: rgba(99, 102, 241, 0.35);
  --accent: #22d3ee;
  --success: #4ade80;
  --warning: #facc15;
  --danger: #f87171;
  --bg: #0f0f1a;
  --bg-card: rgba(30, 30, 50, 0.7);
  --bg-input: rgba(255, 255, 255, 0.06);
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.25);
  --glass-border: 1px solid rgba(255, 255, 255, 0.08);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --vh: 1vh;
}

/* ─── Reset ───────────────────────────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

/* ─── Body ────────────────────────────────────────────────────────────────── */
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: calc(var(--vh, 1vh) * 100);
  display: flex;
  flex-direction: column;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse at 20% 0%, rgba(99, 102, 241, 0.15) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 100%, rgba(34, 211, 238, 0.10) 0%, transparent 50%);
  z-index: -1;
  animation: bgShift 20s ease-in-out infinite alternate;
}

@keyframes bgShift {
  0% {
    opacity: 0.8;
  }

  100% {
    opacity: 1;
  }
}

/* ─── Container ───────────────────────────────────────────────────────────── */
.container {
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
  padding: 20px 16px 40px;
  flex: 1;
}

/* ─── Header ──────────────────────────────────────────────────────────────── */
.header-row {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  margin-bottom: 24px;
}

h1 {
  font-size: 1.75rem;
  font-weight: 800;
  text-align: center;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.02em;
  margin: 0;
}

h1 .emoji {
  -webkit-text-fill-color: initial;
}

.icon-btn {
  position: absolute;
  right: 0;
  background: rgba(255, 255, 255, 0.06);
  border: var(--glass-border);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  min-height: 40px;
  padding: 0;
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  transition: background 0.2s;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

/* ─── Glass Card ──────────────────────────────────────────────────────────── */
.glass-card {
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: var(--glass-border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

/* ─── Rules Section ───────────────────────────────────────────────────────── */
.rules-section {
  margin-bottom: 20px;
}

.rules-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  padding: 14px 18px;
  background: var(--bg-card);
  border: var(--glass-border);
  border-radius: var(--radius);
  color: var(--text);
  font-weight: 600;
  font-size: 0.95rem;
  transition: background 0.2s;
}

.rules-toggle:hover {
  background: rgba(255, 255, 255, 0.06);
}

.rules-toggle .chevron {
  transition: transform 0.3s;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.rules-section.open .chevron {
  transform: rotate(180deg);
}

.rules-content {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.35s ease, padding 0.35s ease;
  padding: 0 18px;
  background: var(--bg-card);
  border: var(--glass-border);
  border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
}

.rules-section.open .rules-content {
  max-height: 350px;
  padding: 14px 18px;
}

.rules-content ol {
  padding-left: 20px;
}

.rules-content li {
  margin-bottom: 6px;
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.5;
}

/* ─── Mode Tabs ───────────────────────────────────────────────────────────── */
.mode-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 16px;
  background: rgba(255, 255, 255, 0.03);
  border-radius: var(--radius-sm);
  padding: 4px;
}

.mode-tab {
  flex: 1;
  padding: 10px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  min-height: 42px;
}

.mode-tab.active {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 2px 8px var(--primary-glow);
}

.mode-tab:not(.active):hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
}

/* ─── Form Controls ───────────────────────────────────────────────────────── */
.form-group {
  margin-bottom: 14px;
}

.form-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

input,
select {
  width: 100%;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: var(--bg-input);
  color: var(--text);
  font-size: 16px;
  font-family: var(--font);
  transition: border-color 0.2s, box-shadow 0.2s;
  min-height: 48px;
  appearance: none;
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

input::placeholder {
  color: var(--text-muted);
  opacity: 0.7;
}

select {
  background-image: url("data:image/svg+xml,%3Csvg fill='%2394a3b8' viewBox='0 0 24 24' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M7 10l5 5 5-5H7z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 20px;
  padding-right: 40px;
  cursor: pointer;
}

#difficultyPreview {
  font-size: 0.8rem;
  margin-top: 4px;
  min-height: 1.2em;
}

.field-preview {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 4px;
  min-height: 1.2em;
  line-height: 1.4;
}

/* ─── Bot Memory ──────────────────────────────────────────────────────────── */
.bot-memory-section {
  margin-top: 10px;
  text-align: center;
}

.btn-danger-outline {
  border-color: rgba(248, 113, 113, 0.3);
  color: var(--danger);
}

.btn-danger-outline:hover {
  background: rgba(248, 113, 113, 0.08);
  border-color: rgba(248, 113, 113, 0.5);
}

/* ─── Qbit Brain Dashboard ────────────────────────────────────────────────── */
.brain-stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}

.brain-stat {
  background: rgba(255, 255, 255, 0.04);
  border: var(--glass-border);
  border-radius: var(--radius-sm);
  padding: 10px 6px;
  text-align: center;
}

.brain-stat-value {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--accent);
}

.brain-stat-label {
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-top: 2px;
}

.brain-section {
  margin-bottom: 16px;
}

.brain-section-title {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 8px;
}

.brain-subtitle {
  font-weight: 400;
  color: var(--text-muted);
  font-size: 0.75rem;
}

/* Transition Matrix */
.matrix-wrapper {
  overflow-x: auto;
  overflow-y: auto;
  max-height: 400px;
  border: var(--glass-border);
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.2);
  -webkit-overflow-scrolling: touch;
}

.matrix-container {
  min-width: fit-content;
  padding: 2px;
}

.matrix-table {
  border-collapse: collapse;
  font-size: 0.55rem;
  width: max-content;
}

.matrix-corner {
  position: sticky;
  top: 0;
  left: 0;
  z-index: 3;
  background: #1a1a2e;
  padding: 4px;
  font-size: 0.6rem;
  color: var(--text-muted);
  min-width: 22px;
  text-align: center;
}

.matrix-header {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #1a1a2e;
  padding: 3px 2px;
  font-weight: 700;
  color: var(--accent);
  text-align: center;
  min-width: 18px;
  font-size: 0.55rem;
  letter-spacing: 0;
}

.matrix-row-header {
  position: sticky;
  left: 0;
  z-index: 2;
  background: #1a1a2e;
  padding: 3px 5px;
  font-weight: 700;
  color: var(--primary);
  text-align: center;
  min-width: 22px;
  font-size: 0.55rem;
}

.matrix-cell {
  padding: 2px;
  text-align: center;
  min-width: 18px;
  height: 18px;
  font-size: 0.5rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.03);
  transition: transform 0.15s, box-shadow 0.15s;
  cursor: default;
}

.matrix-cell:hover {
  transform: scale(1.8);
  box-shadow: 0 0 8px rgba(34, 211, 238, 0.4);
  z-index: 10;
  position: relative;
  border-color: var(--accent);
}

.matrix-cell-hot {
  color: #fff;
  font-weight: 800;
  text-shadow: 0 0 6px rgba(255, 255, 255, 0.5);
}

/* Word Bank */
.wordbank-container {
  max-height: 300px;
  overflow-y: auto;
  border: var(--glass-border);
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.15);
  padding: 10px;
}

.wordbank-group {
  margin-bottom: 10px;
}

.wordbank-group:last-child {
  margin-bottom: 0;
}

.wordbank-letter {
  font-size: 0.8rem;
  font-weight: 800;
  color: var(--primary);
  margin-bottom: 4px;
  padding-bottom: 3px;
  border-bottom: 1px solid rgba(99, 102, 241, 0.15);
}

.wordbank-letter-count {
  font-weight: 400;
  color: var(--text-muted);
  font-size: 0.7rem;
}

.wordbank-words {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.wordbank-word {
  display: inline-block;
  padding: 2px 8px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 4px;
  font-size: 0.7rem;
  color: var(--text);
  font-family: var(--font);
  transition: background 0.2s, border-color 0.2s;
}

.wordbank-word:hover {
  background: rgba(99, 102, 241, 0.15);
  border-color: rgba(99, 102, 241, 0.3);
  color: #fff;
}

/* ─── Qbit v0.2 Brain — Scoring Visualization ─────────────────────────────── */
.v02-scoring-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.v02-score-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 6px;
  transition: background 0.2s;
}

.v02-score-item:hover {
  background: rgba(255, 255, 255, 0.06);
}

.v02-score-rank {
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-size: 0.65rem;
  font-weight: 800;
  background: rgba(99, 102, 241, 0.2);
  color: var(--primary);
  flex-shrink: 0;
}

.v02-score-item:first-child .v02-score-rank {
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff;
}

.v02-score-details {
  flex: 1;
  min-width: 0;
}

.v02-score-word {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 3px;
}

.v02-score-bar-bg {
  height: 4px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 2px;
  margin-bottom: 4px;
  overflow: hidden;
}

.v02-score-bar {
  height: 100%;
  border-radius: 2px;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  transition: width 0.4s ease;
}

.v02-score-breakdown {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.v02-tag {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 0.6rem;
  font-weight: 700;
  font-family: var(--font);
}

.v02-tag-rarity {
  background: rgba(244, 114, 182, 0.15);
  color: #f472b6;
  border: 1px solid rgba(244, 114, 182, 0.25);
}

.v02-tag-diff {
  background: rgba(96, 165, 250, 0.15);
  color: #60a5fa;
  border: 1px solid rgba(96, 165, 250, 0.25);
}

.v02-tag-score {
  background: rgba(74, 222, 128, 0.15);
  color: #4ade80;
  border: 1px solid rgba(74, 222, 128, 0.25);
}

#v02ScoringContainer {
  max-height: 400px;
  overflow-y: auto;
  border: var(--glass-border);
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.15);
  padding: 10px;
}

/* ─── Buttons ─────────────────────────────────────────────────────────────── */
button,
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 14px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 700;
  font-family: var(--font);
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.2s, opacity 0.2s;
  min-height: 48px;
  touch-action: manipulation;
  color: var(--text);
}

button:active {
  transform: scale(0.97);
}

button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), #818cf8);
  color: #fff;
  box-shadow: 0 4px 14px var(--primary-glow);
}

.btn-primary:hover:not(:disabled) {
  box-shadow: 0 6px 20px var(--primary-glow);
}

.btn-hint {
  background: rgba(255, 255, 255, 0.06);
  color: var(--accent);
  border: 1px solid rgba(34, 211, 238, 0.2);
  font-size: 0.85rem;
  padding: 10px 16px;
}

.btn-success {
  background: linear-gradient(135deg, #22c55e, #4ade80);
  color: #fff;
}

.btn-outline {
  background: transparent;
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.btn-sm {
  padding: 8px 14px;
  font-size: 0.75rem;
  min-height: 34px;
  margin-top: 8px;
}

/* ─── Tabs (Leaderboard / Stats) ──────────────────────────────────────────── */
.info-tabs {
  display: flex;
  gap: 4px;
  margin-top: 16px;
  margin-bottom: 12px;
  background: rgba(255, 255, 255, 0.03);
  border-radius: var(--radius-sm);
  padding: 3px;
}

.tab-btn {
  flex: 1;
  padding: 8px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  min-height: 36px;
}

.tab-btn.active {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
}

.tab-panel {
  margin-bottom: 8px;
}

/* ─── Leaderboard ─────────────────────────────────────────────────────────── */
.leaderboard-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
  margin-bottom: 4px;
}

.leaderboard-table th {
  text-align: left;
  padding: 6px 8px;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.leaderboard-table td {
  padding: 6px 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
  color: var(--text);
}

.leaderboard-table tr.rank-1 td {
  color: #ffd700;
}

.leaderboard-table tr.rank-2 td {
  color: #c0c0c0;
}

.leaderboard-table tr.rank-3 td {
  color: #cd7f32;
}

/* ─── Stats Dashboard ─────────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.mini-stat {
  background: rgba(255, 255, 255, 0.04);
  border: var(--glass-border);
  border-radius: var(--radius-sm);
  padding: 10px 6px;
  text-align: center;
}

.mini-stat-value {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--text);
}

.mini-stat-value.longest-word {
  font-size: 0.75rem;
  word-break: break-all;
}

.mini-stat-label {
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ─── Game Area ───────────────────────────────────────────────────────────── */
.game-section {
  animation: fadeIn 0.35s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(12px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Player Bar */
.player-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  gap: 10px;
  flex-wrap: wrap;
}

.player-name {
  font-weight: 700;
  font-size: 1rem;
}

.difficulty-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ─── PvP Scoreboard ──────────────────────────────────────────────────────── */
.pvp-scoreboard {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-bottom: 16px;
  padding: 14px;
  background: var(--bg-card);
  border: var(--glass-border);
  border-radius: var(--radius);
}

.pvp-player {
  text-align: center;
  flex: 1;
}

.pvp-name {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
}

.pvp-score {
  font-size: 1.6rem;
  font-weight: 800;
}

.pvp-p1 .pvp-score {
  color: var(--primary);
}

.pvp-p2 .pvp-score {
  color: var(--accent);
}

.pvp-vs {
  font-size: 0.8rem;
  font-weight: 800;
  color: var(--text-muted);
  letter-spacing: 0.1em;
}

.current-turn {
  text-align: center;
  padding: 8px;
  margin-bottom: 12px;
  background: rgba(99, 102, 241, 0.1);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 700;
  color: #a5b4fc;
  animation: pulseGlow 2s ease-in-out infinite;
}

@keyframes pulseGlow {

  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(99, 102, 241, 0);
  }

  50% {
    box-shadow: 0 0 12px 2px rgba(99, 102, 241, 0.2);
  }
}

/* ─── Timer ───────────────────────────────────────────────────────────────── */
.timer-box {
  text-align: center;
  margin-bottom: 16px;
}

.timer-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.timer-value {
  font-size: 2rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  transition: color 0.3s;
}

.timer-ok {
  color: var(--success);
}

.timer-warning {
  color: var(--warning);
}

.timer-danger {
  color: var(--danger);
  animation: pulse 0.6s ease-in-out infinite;
}

.timer-frozen {
  color: var(--accent);
  animation: frozenPulse 1s ease-in-out infinite;
}

@keyframes pulse {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.5;
  }
}

@keyframes frozenPulse {

  0%,
  100% {
    opacity: 1;
    text-shadow: 0 0 8px rgba(34, 211, 238, 0.4);
  }

  50% {
    opacity: 0.7;
    text-shadow: 0 0 20px rgba(34, 211, 238, 0.6);
  }
}

/* ─── Stats Grid ──────────────────────────────────────────────────────────── */
.game-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

.stat-box {
  background: rgba(255, 255, 255, 0.04);
  border: var(--glass-border);
  border-radius: var(--radius-sm);
  padding: 12px 10px;
  text-align: center;
}

.stat-icon {
  font-size: 1.2rem;
  margin-bottom: 2px;
}

.stat-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.stat-value {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--text);
}

/* ─── Letter Frequency Chart ─────────────────────────────────────────────── */
.freq-chart-section {
  margin-bottom: 16px;
}

.freq-chart-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.04);
  border: var(--glass-border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-weight: 600;
  font-size: 0.82rem;
  transition: background 0.2s;
}

.freq-chart-toggle:hover {
  background: rgba(255, 255, 255, 0.07);
}

.freq-chevron {
  transition: transform 0.3s;
  font-size: 0.7rem;
  color: var(--text-muted);
}

.freq-chart-section.open .freq-chevron {
  transform: rotate(180deg);
}

.freq-chart-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.4s ease, padding 0.4s ease;
  background: rgba(255, 255, 255, 0.02);
  border: var(--glass-border);
  border-top: none;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
}

.freq-chart-section.open .freq-chart-body {
  max-height: 220px;
  padding: 12px 10px 8px;
}

.freq-chart {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 140px;
  width: 100%;
}

.freq-bar-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
  justify-content: flex-end;
  position: relative;
}

.freq-bar {
  width: 100%;
  min-height: 0;
  border-radius: 3px 3px 0 0;
  background: linear-gradient(180deg, var(--primary), var(--accent));
  transition: height 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
  position: relative;
  opacity: 0.85;
}

.freq-bar:hover {
  opacity: 1;
  filter: brightness(1.2);
}

.freq-bar.freq-bar-max {
  background: linear-gradient(180deg, #f59e0b, #facc15);
  opacity: 1;
}

.freq-bar.freq-bar-zero {
  background: rgba(255, 255, 255, 0.06);
  min-height: 2px;
  opacity: 0.5;
}

.freq-bar-count {
  font-size: 0.5rem;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 2px;
  min-height: 12px;
  line-height: 1;
}

.freq-bar-label {
  font-size: 0.55rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-top: 3px;
  line-height: 1;
}

.freq-bar-col:hover .freq-bar-label {
  color: var(--accent);
}

.freq-bar-col:hover .freq-bar-count {
  color: var(--text);
}

/* ─── Power-Ups ───────────────────────────────────────────────────────────── */
.power-ups-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
  justify-content: center;
}

.power-up-btn {
  flex: 1;
  max-width: 100px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px 8px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s;
  min-height: 60px;
  position: relative;
}

.power-up-btn:not(:disabled):hover {
  background: rgba(99, 102, 241, 0.15);
  border-color: rgba(99, 102, 241, 0.3);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.power-up-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.pu-icon {
  font-size: 1.3rem;
}

.pu-count {
  font-size: 0.7rem;
  font-weight: 800;
  color: var(--accent);
  background: rgba(34, 211, 238, 0.15);
  padding: 1px 8px;
  border-radius: 10px;
}

/* ─── Used Words ──────────────────────────────────────────────────────────── */
.used-words {
  max-height: 90px;
  overflow-y: auto;
  padding: 10px;
  background: rgba(255, 255, 255, 0.03);
  border: var(--glass-border);
  border-radius: var(--radius-sm);
  margin-bottom: 14px;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.word-tag {
  display: inline-block;
  padding: 3px 10px;
  background: rgba(99, 102, 241, 0.15);
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  color: #a5b4fc;
  cursor: pointer;
  transition: all 0.15s;
}

.word-tag:hover {
  background: rgba(99, 102, 241, 0.3);
  transform: scale(1.05);
}

.empty-state {
  color: var(--text-muted);
  font-size: 0.85rem;
  font-style: italic;
}

/* ─── Definition Tooltip ──────────────────────────────────────────────────── */
.def-tooltip {
  position: fixed;
  z-index: 10000;
  background: rgba(20, 20, 40, 0.97);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(99, 102, 241, 0.3);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font-size: 0.82rem;
  color: var(--text);
  max-width: 280px;
  line-height: 1.5;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
  animation: tooltipIn 0.2s ease;
}

.def-tooltip strong {
  color: var(--accent);
  font-size: 0.9rem;
}

.def-tooltip em {
  color: var(--text-muted);
}

@keyframes tooltipIn {
  from {
    opacity: 0;
    transform: translateY(4px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ─── Game Controls ───────────────────────────────────────────────────────── */
.game-controls {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.game-controls input {
  flex: 1;
  margin: 0;
}

.game-controls .btn-primary {
  width: auto;
  min-width: 90px;
  flex-shrink: 0;
}

/* ─── Message ─────────────────────────────────────────────────────────────── */
.message {
  min-height: 36px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 500;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background 0.2s;
}

.message:empty {
  display: none;
}

.msg-success {
  background: rgba(74, 222, 128, 0.12);
  color: var(--success);
}

.msg-warning {
  background: rgba(250, 204, 21, 0.12);
  color: var(--warning);
}

.msg-error {
  background: rgba(248, 113, 113, 0.12);
  color: var(--danger);
}

.msg-info {
  background: rgba(99, 102, 241, 0.10);
  color: #a5b4fc;
}

.msg-qbit {
  background: rgba(34, 211, 238, 0.10);
  color: var(--accent);
}

/* ─── History ─────────────────────────────────────────────────────────────── */
.history {
  max-height: 140px;
  overflow-y: auto;
  padding: 10px;
  background: rgba(255, 255, 255, 0.03);
  border: var(--glass-border);
  border-radius: var(--radius-sm);
  margin-bottom: 14px;
  -webkit-overflow-scrolling: touch;
}

.history-entry {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 0;
  font-size: 0.82rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.history-entry:last-child {
  border-bottom: none;
}

.history-name {
  font-weight: 700;
  min-width: 60px;
}

.player-entry .history-name {
  color: var(--primary);
}

.qbit-entry .history-name {
  color: var(--accent);
}

.history-word {
  flex: 1;
  color: var(--text);
}

.pts-tag {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--success);
  background: rgba(74, 222, 128, 0.1);
  padding: 2px 8px;
  border-radius: 10px;
}

/* ─── End Game Actions ────────────────────────────────────────────────────── */
.end-game-actions {
  display: none;
  gap: 10px;
  margin-top: 10px;
}

.end-game-actions button {
  flex: 1;
}

/* ─── Loading Spinner ─────────────────────────────────────────────────────── */
.loading {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.15);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: middle;
  margin-left: 6px;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ─── Toast ───────────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(30px);
  padding: 14px 24px;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 600;
  font-family: var(--font);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
  z-index: 9999;
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  text-align: center;
  max-width: 90%;
  pointer-events: none;
}

.toast-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast-achievement {
  background: linear-gradient(135deg, #6366f1, #818cf8);
  color: #fff;
}

.toast-powerup {
  background: linear-gradient(135deg, #0891b2, #22d3ee);
  color: #fff;
}

.toast-warning {
  background: var(--warning);
  color: #1a1a2e;
}

.toast-info {
  background: var(--bg-card);
  color: var(--text);
  border: var(--glass-border);
}

/* ─── Letter Pick Modal ───────────────────────────────────────────────────── */
.lp-overlay {
  position: fixed;
  inset: 0;
  z-index: 10001;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  transition: opacity 0.25s ease;
}

.lp-overlay.active {
  opacity: 1;
}

.lp-modal {
  background: var(--bg);
  border: 1px solid rgba(99, 102, 241, 0.25);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 340px;
  width: 100%;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5), 0 0 40px rgba(99, 102, 241, 0.08);
  animation: lpSlideIn 0.3s ease;
}

@keyframes lpSlideIn {
  from {
    opacity: 0;
    transform: scale(0.92) translateY(20px);
  }

  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.lp-title {
  font-size: 1.15rem;
  font-weight: 800;
  text-align: center;
  margin-bottom: 4px;
  color: var(--text);
}

.lp-subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: center;
  margin-bottom: 16px;
}

.lp-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
  margin-bottom: 16px;
}

.lp-letter-btn {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font);
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--text);
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

.lp-letter-btn:hover,
.lp-letter-btn:focus {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.3), rgba(34, 211, 238, 0.2));
  border-color: rgba(99, 102, 241, 0.5);
  transform: scale(1.08);
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.25);
  color: #fff;
}

.lp-letter-btn:active {
  transform: scale(0.93);
  background: rgba(99, 102, 241, 0.4);
  border-color: rgba(99, 102, 241, 0.6);
  color: #fff;
}

.lp-cancel-btn {
  display: block;
  width: 100%;
  padding: 10px;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.lp-cancel-btn:hover {
  background: rgba(248, 113, 113, 0.1);
  border-color: rgba(248, 113, 113, 0.3);
  color: var(--danger);
}

/* ─── Footer ──────────────────────────────────────────────────────────────── */
.footer {
  padding: 24px 16px;
  text-align: center;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  margin-top: auto;
}

.footer p {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin: 4px 0;
}

.footer a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 600;
}

.footer a:hover {
  text-decoration: underline;
}

/* ═══════════════════════════════════════════════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════════════════════════════════════════════ */

@media (max-width: 480px) {
  .container {
    padding: 12px 12px 100px;
  }

  h1 {
    font-size: 1.4rem;
  }

  .game-stats {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }

  .stat-box {
    padding: 10px 6px;
  }

  .stat-value {
    font-size: 1rem;
  }

  .timer-value {
    font-size: 1.6rem;
  }

  .game-controls {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(15, 15, 26, 0.95);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    padding: 12px 12px calc(12px + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    z-index: 100;
    margin-bottom: 0;
  }

  .end-game-actions {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(15, 15, 26, 0.95);
    backdrop-filter: blur(10px);
    padding: 12px 12px calc(12px + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    z-index: 100;
  }

  .power-up-btn {
    min-height: 50px;
    padding: 8px 6px;
  }

  .pu-icon {
    font-size: 1.1rem;
  }

  .stats-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
  }

  .mini-stat {
    padding: 8px 4px;
  }

  .pvp-score {
    font-size: 1.3rem;
  }

  .footer {
    padding: 16px 12px;
  }

  .footer p {
    font-size: 0.7rem;
  }

  /* Letter Pick modal — bottom sheet on mobile */
  .lp-overlay {
    align-items: flex-end;
    padding: 0;
  }

  .lp-modal {
    max-width: 100%;
    border-radius: 20px 20px 0 0;
    padding: 20px 16px calc(16px + env(safe-area-inset-bottom, 0px));
    animation: lpSlideUp 0.3s ease;
  }

  @keyframes lpSlideUp {
    from {
      opacity: 0;
      transform: translateY(100%);
    }

    to {
      opacity: 1;
      transform: translateY(0);
    }
  }

  .lp-grid {
    grid-template-columns: repeat(7, 1fr);
    gap: 5px;
  }

  .lp-letter-btn {
    font-size: 0.85rem;
    border-radius: 8px;
  }

  .lp-title {
    font-size: 1.05rem;
  }
}

@media (orientation: landscape) and (max-height: 500px) {
  .container {
    padding: 8px 16px;
  }

  .rules-section {
    display: none;
  }

  .game-stats {
    grid-template-columns: repeat(4, 1fr);
  }

  .timer-value {
    font-size: 1.4rem;
  }
}

/* ─── Scrollbar ───────────────────────────────────────────────────────────── */
::-webkit-scrollbar {
  width: 4px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* ═══════════════════════════════════════════════════════════════════════════════
   QBIT v0.3 — Reinforcement Learning Brain Styles
   ═══════════════════════════════════════════════════════════════════════════════ */

/* ─── RL Q-Table Heatmap ──────────────────────────────────────────────────── */
.rl-qtable .matrix-header {
  color: #4ade80;
}

.rl-qtable .matrix-row-header {
  color: #fb923c;
}

.rl-qtable .matrix-corner {
  font-size: 0.5rem;
  color: var(--text-muted);
}

.rl-cell-hot {
  color: #fff !important;
  font-weight: 800;
  text-shadow: 0 0 6px rgba(74, 222, 128, 0.6);
}

.rl-cell-cold {
  color: #fff !important;
  font-weight: 800;
  text-shadow: 0 0 6px rgba(248, 113, 113, 0.6);
}

/* ─── Epsilon Progress Bar ────────────────────────────────────────────────── */
.rl-explore-value {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.rl-epsilon-bar {
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 3px;
  overflow: hidden;
}

.rl-epsilon-fill {
  height: 100%;
  border-radius: 3px;
  background: linear-gradient(90deg, #fb923c, #4ade80);
  transition: width 0.5s ease;
}

/* ─── Top/Worst Strategic Pairs ───────────────────────────────────────────── */
.rl-pairs-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

@media (max-width: 500px) {
  .rl-pairs-grid {
    grid-template-columns: 1fr;
  }
}

.rl-pairs-section {
  background: rgba(0, 0, 0, 0.15);
  border: var(--glass-border);
  border-radius: var(--radius-sm);
  padding: 10px;
}

.rl-pairs-title {
  font-size: 0.78rem;
  font-weight: 800;
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.rl-pairs-title.rl-good {
  color: #4ade80;
}

.rl-pairs-title.rl-bad {
  color: #f87171;
}

.rl-pair-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 6px;
  border-radius: 5px;
  transition: background 0.2s;
  margin-bottom: 4px;
}

.rl-pair-item:hover {
  background: rgba(255, 255, 255, 0.04);
}

.rl-pair-rank {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-size: 0.6rem;
  font-weight: 800;
  background: rgba(74, 222, 128, 0.2);
  color: #4ade80;
  flex-shrink: 0;
}

.rl-pair-item:first-child .rl-pair-rank {
  background: linear-gradient(135deg, #22c55e, #4ade80);
  color: #fff;
}

.rl-rank-bad {
  background: rgba(248, 113, 113, 0.2) !important;
  color: #f87171 !important;
}

.rl-pair-info {
  flex: 1;
  min-width: 0;
}

.rl-pair-label {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 3px;
  letter-spacing: 0.03em;
}

.rl-pair-bar-bg {
  height: 4px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 2px;
  margin-bottom: 3px;
  overflow: hidden;
}

.rl-pair-bar {
  height: 100%;
  border-radius: 2px;
  transition: width 0.4s ease;
}

.rl-bar-good {
  background: linear-gradient(90deg, #22c55e, #4ade80);
}

.rl-bar-bad {
  background: linear-gradient(90deg, #ef4444, #f87171);
}

.rl-pair-qval {
  font-size: 0.6rem;
  font-weight: 700;
  color: #4ade80;
  font-family: var(--font);
}

.rl-qval-bad {
  color: #f87171 !important;
}

/* ─── Reward History Chart ────────────────────────────────────────────────── */
.rl-reward-chart {
  border: var(--glass-border);
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.15);
  padding: 12px;
}

.rl-chart-bars {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 100px;
  padding-bottom: 4px;
}

.rl-chart-col {
  flex: 1;
  min-width: 0;
  height: 100%;
  display: flex;
  align-items: flex-end;
  cursor: default;
}

.rl-chart-bar {
  width: 100%;
  border-radius: 2px 2px 0 0;
  min-height: 2px;
  transition: height 0.3s ease;
}

.rl-chart-bar-pos {
  background: linear-gradient(180deg, #4ade80, rgba(74, 222, 128, 0.3));
}

.rl-chart-bar-neg {
  background: linear-gradient(180deg, #f87171, rgba(248, 113, 113, 0.3));
}

.rl-chart-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.6rem;
  color: var(--text-muted);
  margin-top: 6px;
  padding-top: 4px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}