/* ═══════════════════════════════════════════════
   Criptogram — Design System
   Público: 14+ | Altas Habilidades
   Sóbrio, limpo, tipográfico — sem lúdico
   ═══════════════════════════════════════════════ */

:root {
  --bg: #09090b;
  --bg-card: #121217;
  --bg-elevated: #1a1a22;
  --border: #252530;
  --border-hover: #3a3a48;
  --text: #e4e4eb;
  --text-secondary: #88889a;
  --text-muted: #5c5c6e;
  --accent: #c9a84c;
  --accent-dim: #8b7335;
  --success: #4ade80;
  --error: #f87171;
  --radius: 12px;
  --radius-sm: 8px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  --font-mono: 'SF Mono', 'Cascadia Code', 'JetBrains Mono', monospace;
}

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

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

/* ─── Background canvas ─── */
#bg-canvas {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: 0;
  background: linear-gradient(to bottom, rgb(10, 10, 40) 0%, rgb(30, 10, 30) 100%);
  pointer-events: none;
}

body {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  min-height: 100dvh;
}

#app {
  width: 100%;
  max-width: 480px;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 16px;
  position: relative;
  z-index: 1;
}

/* ─── Screen container ─── */
.screen {
  display: none;
  flex-direction: column;
  flex: 1;
  animation: fadeIn 0.25s ease;
}

.screen.active { display: flex; }

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

/* ─── Typography ─── */
h1 {
  font-size: 1.75rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text);
}

h2 {
  font-size: 1.25rem;
  font-weight: 500;
  letter-spacing: -0.01em;
}

h3 {
  font-size: 1rem;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.7rem;
}

p, .text-body {
  font-size: 0.95rem;
  line-height: 1.6;
  color: var(--text-secondary);
}

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

/* ─── Buttons ─── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 500;
  border: none;
  cursor: pointer;
  transition: all 0.15s ease;
  text-decoration: none;
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent);
  color: #0a0a0f;
}

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

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

.btn-secondary:hover, .btn-secondary:active {
  border-color: var(--border-hover);
  background: #222230;
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}

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

.btn-block { width: 100%; }

.btn-sm { padding: 8px 16px; font-size: 0.8rem; }

.btn-icon {
  width: 44px; height: 44px;
  padding: 0;
  border-radius: 50%;
  font-size: 1.25rem;
}

/* ─── Cards ─── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  transition: border-color 0.15s ease;
}

.card:hover { border-color: var(--border-hover); }

.card-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

/* ─── Category card ─── */
.cat-card {
  background: rgba(18, 18, 23, 0.55);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--radius);
  padding: 18px 16px;
  cursor: pointer;
  transition: all 0.15s ease;
  position: relative;
  overflow: hidden;
}

.cat-card:hover {
  background: rgba(18, 18, 23, 0.7);
  border-color: rgba(255, 255, 255, 0.1);
  transform: translateY(-1px);
}

.cat-card:active { transform: scale(0.98); }

.cat-card .cat-icon {
  font-size: 1.5rem;
  margin-bottom: 8px;
  display: block;
  filter: grayscale(0.3);
}

.cat-card .cat-name {
  font-size: 0.85rem;
  font-weight: 500;
  margin-bottom: 4px;
}

.cat-card .cat-progress {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.cat-card.completed {
  border-color: var(--accent-dim);
  opacity: 0.7;
}

.cat-card::after {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 3px;
  height: 100%;
  background: var(--accent-dim);
  transform: scaleY(var(--progress, 0));
  transform-origin: bottom;
  transition: transform 0.3s ease;
}

/* ─── Level cards ─── */
.level-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.level-card:active { transform: scale(0.98); }

.level-card.locked {
  opacity: 0.35;
  pointer-events: none;
}

.level-card .level-num {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--accent);
}

.level-card .level-name {
  font-size: 0.85rem;
  font-weight: 500;
  margin-top: 4px;
}

.level-card .level-count {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ─── Input ─── */
.input {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.15s;
}

.input:focus { border-color: var(--accent-dim); }

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

/* ─── XP Bar ─── */
.xp-bar-container {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 20px;
  height: 6px;
  margin-top: 6px;
  overflow: hidden;
}

.xp-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 20px;
  transition: width 0.5s ease;
}

.xp-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ─── Header ─── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0 16px;
  gap: 8px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.header-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.player-id-badge {
  font-size: 0.65rem;
  color: var(--text-muted);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 6px;
  max-width: 60px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-icon {
  width: 32px;
  height: 32px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
}

.back-btn {
  width: 36px; height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 50%;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 1.1rem;
}

/* ─── Challenge screen ─── */
.challenge-lore {
  background: var(--bg-elevated);
  border-left: 2px solid var(--accent-dim);
  padding: 12px 16px;
  margin: 16px 0;
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.5;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-style: italic;
}

.flag-emoji {
  font-size: 3rem;
  display: block;
  text-align: center;
  margin: 8px 0 16px;
  line-height: 1.2;
}

.challenge-question {
  font-size: 1.1rem;
  font-weight: 500;
  line-height: 1.5;
  margin-bottom: 20px;
}

.challenge-type-badge {
  display: inline-block;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  padding: 3px 8px;
  border-radius: 4px;
  background: var(--bg-elevated);
  color: var(--text-muted);
  margin-bottom: 12px;
  border: 1px solid var(--border);
}

.hint-box {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  margin-top: 16px;
  font-size: 0.8rem;
  color: var(--text-muted);
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

/* ─── Result ─── */
.result-card {
  text-align: center;
  padding: 32px 20px;
}

.result-icon {
  font-size: 3rem;
  margin-bottom: 12px;
}

.result-title {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 8px;
}

.result-message {
  color: var(--text-secondary);
  margin-bottom: 20px;
  line-height: 1.5;
}

.result-points {
  font-size: 0.85rem;
  color: var(--accent);
  margin-bottom: 16px;
}

/* ─── Reward code ─── */
.reward-card {
  text-align: center;
  padding: 32px 20px;
}

.reward-code {
  font-family: var(--font-mono);
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: 0.15em;
  color: var(--accent);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 24px;
  margin: 16px 0;
  display: inline-block;
}

/* ─── Leaderboard ─── */
.leaderboard-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.leaderboard-rank {
  width: 28px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-align: center;
}

.leaderboard-rank.top { color: var(--accent); }

.leaderboard-avatar {
  width: 32px; height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-elevated);
  border-radius: 50%;
  font-size: 0.9rem;
}

.leaderboard-name {
  flex: 1;
  font-size: 0.9rem;
  font-weight: 500;
}

.leaderboard-xp {
  font-size: 0.8rem;
  color: var(--accent);
  font-weight: 500;
}

/* ─── Rewards list ─── */
.reward-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}

.reward-item-code {
  font-family: var(--font-mono);
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 0.05em;
}

.reward-item-meta {
  font-size: 0.7rem;
  color: var(--text-muted);
}

/* ─── Player selector ─── */
.player-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.15s;
}

.player-card:active { background: var(--bg-elevated); }

.player-avatar {
  width: 44px; height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-elevated);
  border-radius: 50%;
  font-size: 1.2rem;
}

/* ─── Camera ─── */
.camera-view {
  position: relative;
  width: 100%;
  aspect-ratio: 4/3;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
}

.camera-view video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.camera-overlay {
  position: absolute;
  bottom: 16px;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  gap: 16px;
}

.camera-capture {
  width: 64px; height: 64px;
  border-radius: 50%;
  background: rgba(255,255,255,0.15);
  border: 3px solid rgba(255,255,255,0.5);
  cursor: pointer;
  transition: all 0.15s;
}

.camera-capture:active {
  background: rgba(255,255,255,0.3);
  transform: scale(0.9);
}

/* ─── Loading ─── */
.loading-screen {
  align-items: center;
  justify-content: center;
  gap: 16px;
}

.spinner {
  width: 32px; height: 32px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* ─── Notification / Toast ─── */
.toast {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 20px;
  font-size: 0.85rem;
  z-index: 100;
  animation: slideDown 0.3s ease;
  max-width: 90vw;
  text-align: center;
  color: var(--text);
}

@keyframes slideDown {
  from { opacity: 0; transform: translateX(-50%) translateY(-20px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ─── Confetti (subtle) ─── */
.confetti-container {
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 200;
}

.confetti-piece {
  position: absolute;
  width: 6px; height: 6px;
  border-radius: 2px;
  animation: confettiFall 2s ease-out forwards;
}

@keyframes confettiFall {
  0%   { transform: translateY(-100px) rotate(0deg); opacity: 1; }
  100% { transform: translateY(100vh) rotate(720deg); opacity: 0; }
}

/* ─── Empty state ─── */
.empty-state {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-muted);
}

.empty-state svg {
  width: 48px; height: 48px;
  margin-bottom: 12px;
  color: var(--border);
}

/* ─── QR Scanner ─── */
.qr-scanner {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  max-height: 60vh;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
}

.qr-scanner video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.qr-region {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 200px; height: 200px;
  border: 2px solid var(--accent);
  border-radius: 12px;
}

/* ─── Subscript / fine print ─── */
.fine-print {
  font-size: 0.65rem;
  color: var(--text-muted);
  text-align: center;
  padding: 20px 0 8px;
}

/* ─── Divider ─── */
.divider {
  height: 1px;
  background: var(--border);
  margin: 20px 0;
}

/* ─── Tag ─── */
.tag {
  display: inline-block;
  font-size: 0.65rem;
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--bg-elevated);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.tag.success { color: var(--success); border-color: var(--success); }
.tag.warning { color: var(--accent); border-color: var(--accent-dim); }

/* ─── Login screen special ─── */
.login-title {
  font-size: 2rem;
  font-weight: 600;
  letter-spacing: -0.03em;
  margin-bottom: 4px;
}

.login-subtitle {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-bottom: 32px;
}

.login-section-title {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin: 24px 0 12px;
}

/* ─── OCR feedback ─── */
.ocr-text {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  margin-top: 12px;
  color: var(--text-muted);
  word-break: break-all;
  max-height: 80px;
  overflow-y: auto;
}

/* ─── Duel Champions Wall ─── */
@keyframes duelScroll {
  0%   { transform: translateX(0); opacity: 1; }
  80%  { opacity: 1; }
  90%  { opacity: 0.3; }
  100% { transform: translateX(-50%); opacity: 0; }
}

/* ─── Media query: tighter spacing on small screens ─── */
@media (max-width: 360px) {
  #app { padding: 12px; }
  .card-grid { gap: 8px; }
  .cat-card { padding: 14px 12px; }
}
