/* ==========================================================================
   DESAFIO DA TABUADA - DESIGN SYSTEM & ZERO-SCROLL 100DVH TABLETOP CSS
   ========================================================================== */

:root {
  /* Cores Principais */
  --primary-hue: 245;
  --primary: hsl(var(--primary-hue), 75%, 58%);
  --primary-hover: hsl(var(--primary-hue), 75%, 50%);
  --primary-light: hsl(var(--primary-hue), 80%, 96%);
  --primary-dark: hsl(var(--primary-hue), 80%, 35%);

  --secondary: #0EA5E9;
  --secondary-hover: #0284C7;
  --secondary-light: #F0F9FF;

  --accent: #8B5CF6;
  --accent-hover: #7C3AED;

  --success: #10B981;
  --success-light: #ECFDF5;
  --success-dark: #047857;

  --danger: #F43F5E;
  --danger-light: #FFF1F2;
  --danger-dark: #BE123C;

  --warning: #F59E0B;
  --warning-light: #FEF3C7;

  /* Superfícies e Neutros */
  --bg-gradient: linear-gradient(135deg, #EEF2FF 0%, #E0E7FF 50%, #F0F9FF 100%);
  --surface: #FFFFFF;
  --surface-subtle: #F8FAFC;
  --text-main: #1E293B;
  --text-muted: #64748B;
  --border-light: #E2E8F0;
  --border-dashed: #CBD5E1;

  /* Sombras */
  --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 25px rgba(79, 70, 229, 0.12);
  --shadow-drag: 0 16px 32px rgba(79, 70, 229, 0.25);

  /* Fontes e Raios */
  --font-display: 'Fredoka', cursive, sans-serif;
  --font-body: 'Outfit', -apple-system, sans-serif;
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-pill: 9999px;

  /* Animações */
  --transition-fast: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-normal: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-bounce: 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* Reset Global & Zero Scroll Rules */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100vw;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden !important;
  font-family: var(--font-body);
  background: var(--bg-gradient);
  color: var(--text-main);
  user-select: none;
  -webkit-user-select: none;
}

/* Layout Principal (Container com 24px de Padding Global) */
.app-container {
  width: 100vw;
  height: 100dvh;
  max-width: 100vw;
  max-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 24px !important;
  position: relative;
  overflow: hidden !important;
}

/* MODAL DE INSTRUÇÕES DE INÍCIO */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(15, 23, 42, 0.65);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.modal-backdrop.is-open {
  opacity: 1;
  pointer-events: auto;
}

.modal-content-box {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 28px 24px;
  max-width: 440px;
  width: 90%;
  text-align: center;
  box-shadow: var(--shadow-lg);
  border: 1.5px solid var(--border-light);
  transform: scale(0.9);
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal-backdrop.is-open .modal-content-box {
  transform: scale(1);
}

.modal-icon { font-size: 3rem; margin-bottom: 8px; }
.modal-title { font-family: var(--font-display); font-size: 1.4rem; color: var(--primary-dark); margin-bottom: 8px; }
.modal-description { font-size: 0.95rem; color: var(--text-main); margin-bottom: 20px; line-height: 1.5; }

/* Header Global */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 14px;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.6);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  margin-bottom: 6px;
  flex-shrink: 0;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}

.brand-icon {
  font-size: 1.4rem;
  background: var(--primary-light);
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
}

.brand-title {
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--primary-dark);
  line-height: 1.1;
}

.brand-tagline {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 500;
}

.icon-btn {
  background: var(--surface-subtle);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-pill);
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  cursor: pointer;
}

/* Canvas Confetes */
.confetti-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 999;
}

/* Telas */
.screen {
  display: none;
  opacity: 0;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.screen.screen-active {
  display: flex;
  flex-direction: column;
  opacity: 1;
}

/* ==========================================================================
   TELA 2: GAMEPLAY (HEADER BAR COM RESPIRO E ESPAÇAMENTO ELEGANTE)
   ========================================================================== */

#screen-game {
  width: 100%;
  height: 100%;
  overflow: hidden !important;
  display: flex;
  flex-direction: column;
}

/* BARRA DE TOPO COM 20PX DE MARGEM INFERIOR (RESPIRO AMPLO) */
.game-compact-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 18px;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1.5px solid var(--border-light);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  height: 48px;
  flex-shrink: 0;
  margin-bottom: 20px;
}

.compact-bar-info {
  display: flex;
  align-items: center;
  gap: 8px;
}

.badge-xs {
  padding: 4px 10px;
  font-size: 0.8rem;
  font-weight: 700;
  border-radius: var(--radius-pill);
}

.badge-primary { background: var(--primary); color: #FFF; }
.badge-neutral { background: var(--surface); color: var(--text-muted); border: 1px solid var(--border-light); }
.badge-accent { background: var(--secondary-light); color: var(--secondary-hover); border: 1px solid var(--secondary); }

.game-timer-compact {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: monospace;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--primary-dark);
  background: var(--surface);
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-light);
}

.btn-xs {
  padding: 6px 14px;
  font-size: 0.82rem;
}

/* VIEWPORT ZERO-SCROLL 100DVH (GAP EXATO DE 24PX & COLUNA DE RESPOSTAS AMPLIADA PARA 460PX) */
.game-zero-scroll-viewport {
  flex: 1;
  min-height: 0;
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(380px, 460px);
  gap: 24px;
  overflow: hidden !important;
  align-items: stretch;
}

/* HERO GRID 9x9 MAXIMIZADO */
.matrix-board-wrapper {
  height: 100%;
  width: 100%;
  min-height: 0;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden !important;
}

.matrix-board {
  display: grid;
  grid-template-columns: repeat(10, minmax(24px, 1fr));
  gap: 4px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 8px;
  border: 1.5px solid var(--border-light);
  box-shadow: var(--shadow-md);
  aspect-ratio: 1 / 1;
  height: 100%;
  max-height: 100%;
  max-width: 100%;
  object-fit: contain;
}

/* Cabeçalhos 1 a 9 */
.matrix-header-cell {
  background: var(--primary-light);
  color: var(--primary-dark);
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  aspect-ratio: 1;
  transition: background var(--transition-fast), color var(--transition-fast);
}

.matrix-header-cell.matrix-origin {
  background: var(--secondary-light);
  color: var(--secondary-hover);
  font-size: 1.4rem;
}

/* Foco nos Cabeçalhos quando uma célula está sugerida/selecionada */
.matrix-header-cell.is-header-focus {
  background: var(--secondary);
  color: #FFF;
  box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.4);
  transform: scale(1.08);
}

/* Células da Matriz 9x9 */
.matrix-cell {
  background: #F1F5F9;
  border: 1.5px dashed var(--border-dashed);
  border-radius: 6px;
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text-main);
  position: relative;
  transition: all var(--transition-fast);
  opacity: 0.85;
  cursor: not-allowed;
}

.matrix-cell.is-active-cell {
  background: var(--surface-subtle);
  border: 1.5px solid var(--border-light);
  opacity: 1;
  cursor: pointer;
}

.matrix-cell.is-active-cell:hover {
  border-color: var(--primary);
  transform: scale(1.04);
}

/* Multiplicação r×c em Cada Célula */
.matrix-cell-coords {
  font-size: 0.88rem;
  color: var(--text-main);
  font-weight: 700;
  font-family: var(--font-display);
  pointer-events: none;
  opacity: 0.85;
}

.matrix-cell.is-active-cell .matrix-cell-coords {
  font-size: 0.95rem;
  color: var(--primary-dark);
  font-weight: 800;
  opacity: 1;
}

/* Célula Sugerida Ativa */
.matrix-cell.is-suggested-target {
  border: 2px solid var(--secondary);
  background: var(--secondary-light);
  box-shadow: 0 0 0 4px rgba(14, 165, 233, 0.45);
  animation: pulse-suggest 1.4s infinite ease-in-out;
  z-index: 2;
  opacity: 1;
}

.matrix-cell.is-suggested-target .matrix-cell-coords {
  font-size: 1.08rem;
  color: var(--secondary-hover);
  font-weight: 900;
}

@keyframes pulse-suggest {
  0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(14, 165, 233, 0.6); }
  50% { transform: scale(1.06); box-shadow: 0 0 0 7px rgba(14, 165, 233, 0); }
  100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(14, 165, 233, 0); }
}

.matrix-cell.is-selected-cell {
  border-color: var(--secondary);
  background: var(--secondary-light);
  box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.5);
}

.matrix-cell.is-over {
  border-color: var(--primary);
  background: var(--primary-light);
  transform: scale(1.08);
}

/* Animação de encaixe do card na célula */
@keyframes pop-in {
  0% { transform: scale(0.8); opacity: 0.7; }
  60% { transform: scale(1.12); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

.matrix-cell.is-filled {
  background: var(--primary-light);
  border: 1.5px solid var(--primary);
  color: var(--primary-dark);
  font-size: 1.35rem;
  font-weight: 800;
  animation: pop-in 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.matrix-cell.is-correct {
  background: var(--success-light);
  border-color: var(--success);
  color: var(--success-dark);
}

.matrix-cell.is-correct::after {
  content: '✓';
  position: absolute;
  top: 1px;
  right: 3px;
  font-size: 0.65rem;
  font-weight: bold;
  color: var(--success-dark);
}

.matrix-cell.is-incorrect {
  background: var(--danger-light);
  border-color: var(--danger);
  color: var(--danger-dark);
}

.matrix-cell.is-incorrect::after {
  content: '✕';
  position: absolute;
  top: 1px;
  right: 3px;
  font-size: 0.65rem;
  font-weight: bold;
  color: var(--danger-dark);
}

.matrix-cell-correction {
  font-size: 0.55rem;
  color: var(--danger-dark);
  font-weight: bold;
}

/* BANCO DE RESPOSTAS */
.answers-bank-box {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 12px 14px;
  border: 1.5px solid var(--border-light);
  box-shadow: var(--shadow-md);
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden !important;
}

.answers-bank-header {
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.bank-title-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.bank-title {
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--primary-dark);
}

.answers-bank-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.matrix-answers-pool {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(54px, 1fr));
  gap: 6px;
  align-content: start;
  overflow-y: auto;
  padding: 2px;
}

/* Card de Resposta Individual AMPLIADO (48px de altura, fonte 1.32rem) */
.answer-card {
  background: linear-gradient(180deg, #FFFFFF 0%, #F8FAFC 100%);
  border: 2px solid var(--border-light);
  border-radius: var(--radius-sm);
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 1.32rem;
  font-weight: 700;
  color: var(--primary-dark);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  position: relative;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast), border-color var(--transition-fast);
  touch-action: none;
}

.answer-card:hover {
  transform: translateY(-2px) scale(1.08);
  border-color: var(--primary);
  box-shadow: var(--shadow-md);
}

.answer-card:active { cursor: grabbing; }

.answer-card.is-dragging {
  opacity: 0.4;
  transform: scale(0.95);
}

/* BOTÕES E COMPONENTES */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-pill);
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 0.88rem;
  border: none;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none !important; box-shadow: none !important; }

.btn-primary { background: var(--primary); color: #FFF; }
.btn-secondary { background: var(--surface); color: var(--text-main); border: 1px solid var(--border-light); }
.btn-accent { background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%); color: #FFF; box-shadow: var(--shadow-md); }

.btn-lg { padding: 12px 24px; font-size: 0.95rem; }

/* RESULTS CARD */
.results-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 20px;
  max-width: 540px;
  margin: 0 auto;
  width: 100%;
  border: 1px solid var(--border-light);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: center;
  max-height: calc(100dvh - 70px);
  overflow-y: auto;
}

.results-header { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.results-trophy-icon { font-size: 2.8rem; line-height: 1; }
.results-title { font-family: var(--font-display); font-size: 1.5rem; color: var(--text-main); }
.results-subtitle { font-size: 0.85rem; color: var(--text-muted); }

.record-banner {
  background: linear-gradient(135deg, #FEF3C7 0%, #FDE68A 100%);
  border: 2px solid var(--warning);
  border-radius: var(--radius-pill);
  padding: 6px 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 800;
  color: #92400E;
  font-size: 0.9rem;
}

.record-banner.hidden { display: none; }

.feedback-box {
  background: var(--primary-light);
  border-radius: var(--radius-md);
  padding: 8px 14px;
}

.feedback-message { font-family: var(--font-display); font-size: 0.95rem; color: var(--primary-dark); }

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

.stat-card {
  background: var(--surface-subtle);
  border-radius: var(--radius-md);
  padding: 8px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  border: 1px solid var(--border-light);
}

.stat-card .stat-icon { font-size: 1rem; }
.stat-card .stat-value { font-family: var(--font-display); font-size: 0.95rem; font-weight: 700; }
.stat-card .stat-label { font-size: 0.68rem; color: var(--text-muted); }

.score-display {
  background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 100%);
  color: #FFF;
  border-radius: var(--radius-md);
  padding: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.score-value { font-family: var(--font-display); font-size: 1.8rem; font-weight: 700; line-height: 1; }

.results-actions { display: flex; flex-direction: column; gap: 6px; margin-top: 2px; }

.app-footer { text-align: center; padding: 4px 0 2px 0; font-size: 0.72rem; color: var(--text-muted); flex-shrink: 0; }

/* RESPONSIVIDADE ADAPTATIVA */
@media (max-width: 899px) {
  .game-zero-scroll-viewport {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    gap: 6px;
    overflow: hidden !important;
  }

  .matrix-board-wrapper {
    flex: 1;
    min-height: 0;
  }

  .answers-bank-box {
    height: 140px;
    max-height: 140px;
    padding: 6px 8px;
    flex-shrink: 0;
  }

  .matrix-answers-pool {
    grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
    gap: 4px;
  }

  .answer-card { height: 36px; font-size: 1.05rem; }
}
