:root {
  --bg-dark: #0b0f17;
  --bg-card: #131b26;
  --bg-elevated: #1a2536;
  --border-color: #26354a;
  --border-focus: #3b82f6;
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --primary-gradient: linear-gradient(135deg, #00f2fe 0%, #4facfe 100%);
  --accent-purple: #8b5cf6;
  --accent-pink: #ec4899;
  --accent-green: #10b981;
  --accent-amber: #f59e0b;
  --accent-red: #ef4444;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg-dark);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* HEADER */
.app-header {
  background-color: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
  padding: 14px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-icon {
  font-size: 2.2rem;
  filter: drop-shadow(0 0 10px rgba(0, 242, 254, 0.4));
}

.brand h1 {
  font-size: 1.4rem;
  font-weight: 700;
  background: var(--primary-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  line-height: 1.2;
}

.subtitle {
  font-size: 0.82rem;
  color: var(--text-muted);
}

/* RESIDENT PROFILE BAR */
.resident-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-elevated);
  padding: 6px 14px;
  border-radius: 30px;
  border: 1px solid var(--border-color);
}

.resident-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 500;
}

.resident-chips {
  display: flex;
  gap: 8px;
}

.resident-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.resident-chip:hover {
  border-color: #4facfe;
  color: #fff;
}

.resident-chip.active {
  background: linear-gradient(135deg, #1e3a8a 0%, #3b82f6 100%);
  border-color: #60a5fa;
  color: #fff;
  font-weight: 600;
  box-shadow: 0 0 12px rgba(59, 130, 246, 0.4);
}

/* NAVIGATION TABS */
.main-tabs {
  display: flex;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
  padding: 0 24px;
  overflow-x: auto;
  gap: 8px;
}

.tab-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 14px 18px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 3px solid transparent;
  transition: all 0.2s;
  white-space: nowrap;
}

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

.tab-btn.active {
  color: #38bdf8;
  border-bottom-color: #38bdf8;
}

/* TAB CONTENT */
.tab-content {
  display: none;
  padding: 24px;
  flex: 1;
}

.tab-content.active {
  display: block;
}

/* CONSOLE FILTER BAR */
.console-filter-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 24px;
}

.filter-pills {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.pill {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.pill:hover {
  color: var(--text-main);
  border-color: #475569;
}

.pill.active {
  background: #3b82f6;
  border-color: #60a5fa;
  color: #fff;
  box-shadow: 0 0 10px rgba(59, 130, 246, 0.3);
}

/* BUTTONS */
.btn-primary {
  background: linear-gradient(135deg, #2563eb 0%, #3b82f6 100%);
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.btn-primary:hover {
  opacity: 0.95;
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(37, 99, 235, 0.4);
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  padding: 8px 16px;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn-secondary:hover {
  background: var(--bg-elevated);
  border-color: #64748b;
}

.btn-control {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-control:hover {
  background: var(--bg-elevated);
  border-color: #60a5fa;
}

.btn-ai {
  background: linear-gradient(135deg, #4c1d95 0%, #7c3aed 100%);
  border-color: #a78bfa;
  color: white;
}

.btn-ai:hover {
  box-shadow: 0 0 10px rgba(167, 139, 250, 0.4);
}

/* GAMES GRID */
.games-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 20px;
}

.game-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  cursor: pointer;
  transition: all 0.25s ease;
  position: relative;
}

.game-card:hover {
  transform: translateY(-4px);
  border-color: #38bdf8;
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.4);
}

.game-cover-wrap {
  width: 100%;
  height: 180px;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.game-cover-wrap img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  transition: transform 0.3s;
}

.game-card:hover .game-cover-wrap img {
  transform: scale(1.05);
}

.game-cover-placeholder {
  font-size: 3rem;
  opacity: 0.6;
}

.game-badge {
  position: absolute;
  top: 8px;
  left: 8px;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #fff;
  z-index: 2;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

/* Console Badge Colors */
.badge-snes { background: #6b21a8; }
.badge-nes { background: #b91c1c; }
.badge-megadrive { background: #0f172a; border: 1px solid #38bdf8; }
.badge-gba { background: #4338ca; }
.badge-gbc { background: #0284c7; }
.badge-gb { background: #4d7c0f; }
.badge-mastersystem { background: #1d4ed8; }
.badge-neogeo { background: #b45309; }

.game-info {
  padding: 14px;
  display: flex;
  flex-direction: column;
  flex: 1;
}

.game-title {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 6px;
  color: var(--text-main);
  line-height: 1.3;
}

.game-desc {
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.4;
  flex: 1;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.game-footer {
  margin-top: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.78rem;
  color: var(--accent-green);
  font-weight: 600;
}

/* SUDOKU & CROSSWORD CONTAINERS */
.game-board-container {
  max-width: 900px;
  margin: 0 auto;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.3);
}

.sudoku-header, .crossword-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 20px;
}

.timer-badge {
  background: var(--bg-elevated);
  padding: 6px 14px;
  border-radius: 20px;
  font-family: monospace;
  font-size: 1.1rem;
  font-weight: 700;
  color: #38bdf8;
  border: 1px solid var(--border-color);
}

.difficulty-picker select {
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  outline: none;
}

/* SUDOKU GRID */
.sudoku-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.sudoku-grid {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  width: 100%;
  max-width: 460px;
  aspect-ratio: 1;
  background: #1e293b;
  border: 3px solid #64748b;
  border-radius: 6px;
  overflow: hidden;
}

.sudoku-cell {
  background: #0f172a;
  border: 1px solid #334155;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  font-weight: 700;
  cursor: pointer;
  user-select: none;
  position: relative;
  transition: background 0.15s;
}

/* Bordas espessas dos blocos 3x3 */
.sudoku-cell:nth-child(3n) {
  border-right: 2px solid #64748b;
}
.sudoku-cell:nth-child(9n) {
  border-right: none;
}
.sudoku-cell:nth-child(n+19):nth-child(-n+27),
.sudoku-cell:nth-child(n+46):nth-child(-n+54) {
  border-bottom: 2px solid #64748b;
}

.sudoku-cell.initial {
  color: #94a3b8;
  background: #162032;
  cursor: default;
}

.sudoku-cell.user-filled {
  color: #38bdf8;
}

.sudoku-cell.selected {
  background: #1e3a8a !important;
}

.sudoku-cell.highlight-same {
  background: #1e293b;
}

.sudoku-cell.conflict {
  background: rgba(239, 68, 68, 0.25) !important;
  color: #fca5a5 !important;
}

/* Rascunhos de lápis */
.notes-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  width: 100%;
  height: 100%;
  padding: 2px;
  pointer-events: none;
}

.note-num {
  font-size: 0.58rem;
  color: #94a3b8;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 500;
}

/* NUMPAD */
.numpad {
  display: flex;
  gap: 10px;
  max-width: 460px;
  width: 100%;
  justify-content: space-between;
}

.num-btn {
  flex: 1;
  aspect-ratio: 1;
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  font-size: 1.3rem;
  font-weight: 700;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s;
}

.num-btn:hover {
  background: #2563eb;
  border-color: #60a5fa;
  transform: translateY(-2px);
}

.sudoku-footer, .crossword-footer {
  margin-top: 24px;
  display: flex;
  justify-content: center;
}

/* PALAVRAS CRUZADAS LAYOUT */
.crossword-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}

@media (max-width: 768px) {
  .crossword-layout {
    grid-template-columns: 1fr;
  }
}

.crossword-grid-wrapper {
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

.crossword-grid {
  display: grid;
  background: #020617;
  border: 2px solid #334155;
  border-radius: 6px;
  overflow: hidden;
  max-width: 420px;
  width: 100%;
  aspect-ratio: 1;
}

.cw-cell {
  position: relative;
  background: #fff;
  border: 1px solid #cbd5e1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  font-weight: 700;
  color: #0f172a;
  cursor: pointer;
  user-select: none;
}

.cw-cell.black {
  background: #090d16;
  border-color: #090d16;
  cursor: default;
}

.cw-cell.selected {
  background: #bae6fd !important;
}

.cw-cell.word-highlight {
  background: #e0f2fe;
}

.cw-number {
  position: absolute;
  top: 1px;
  left: 2px;
  font-size: 0.55rem;
  color: #475569;
  font-weight: 600;
  pointer-events: none;
}

.cw-input-hidden {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}

/* CLUES PANEL */
.clues-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-height: 440px;
  overflow-y: auto;
  padding-right: 6px;
}

.clues-column h3 {
  font-size: 0.95rem;
  color: #38bdf8;
  margin-bottom: 8px;
}

.clues-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.clue-item {
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.15s;
  line-height: 1.3;
}

.clue-item:hover {
  background: #1e293b;
  border-color: #60a5fa;
}

.clue-item.active {
  background: #1e3a8a;
  border-color: #38bdf8;
  color: #fff;
  font-weight: 600;
}

.clue-num {
  font-weight: 700;
  color: #38bdf8;
  margin-right: 4px;
}

.ai-hint-box {
  background: linear-gradient(135deg, #31104b 0%, #1e1b4b 100%);
  border: 1px solid #a78bfa;
  border-radius: var(--radius-md);
  padding: 12px 16px;
  margin-bottom: 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.9rem;
  color: #f3e8ff;
  box-shadow: 0 4px 12px rgba(124, 58, 237, 0.25);
  animation: fadeIn 0.3s ease;
}

.btn-close-hint {
  background: none;
  border: none;
  color: #c084fc;
  font-size: 1.2rem;
  cursor: pointer;
  margin-left: auto;
}

/* LEADERBOARDS */
.leaderboard-container {
  max-width: 700px;
  margin: 0 auto;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 24px;
}

.leaderboard-selector {
  display: flex;
  gap: 8px;
  margin: 18px 0;
  overflow-x: auto;
  padding-bottom: 4px;
}

.lb-pill {
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.85rem;
  cursor: pointer;
}

.lb-pill.active {
  background: #3b82f6;
  color: white;
  border-color: #60a5fa;
}

.leaderboard-card {
  background: var(--bg-elevated);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  overflow: hidden;
}

.leader-item {
  display: flex;
  align-items: center;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border-color);
  gap: 14px;
}

.leader-item:last-child {
  border-bottom: none;
}

.leader-rank {
  font-size: 1.1rem;
  font-weight: 700;
  width: 28px;
  color: #94a3b8;
}

.leader-rank.top-1 { color: #f59e0b; font-size: 1.3rem; }
.leader-rank.top-2 { color: #cbd5e1; }
.leader-rank.top-3 { color: #b45309; }

.leader-user {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  flex: 1;
}

.leader-time {
  font-family: monospace;
  font-size: 1rem;
  font-weight: 700;
  color: #38bdf8;
}

/* MODALS */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(5px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
}

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

.modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  max-width: 500px;
  width: 100%;
  overflow: hidden;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6);
  animation: slideUp 0.25s ease;
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-body {
  padding: 20px;
}

.modal-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.btn-close-modal {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
}

.btn-close-modal:hover {
  color: white;
  background: rgba(255, 255, 255, 0.1);
}

.form-group {
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}

.form-group input, .form-group select {
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 10px 14px;
  border-radius: var(--radius-md);
  outline: none;
  font-size: 0.9rem;
}

.form-hint {
  font-size: 0.75rem;
  color: #64748b;
}

/* THEME BUTTONS GRID */
.theme-buttons-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 16px 0;
}

.theme-btn {
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 12px;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
  transition: all 0.2s;
  text-align: left;
}

.theme-btn:hover {
  border-color: #38bdf8;
  background: #1e293b;
}

.input-with-btn {
  display: flex;
  gap: 8px;
}

.input-with-btn input {
  flex: 1;
}

/* EMULATOR MODAL */
.emulator-window {
  background: #000;
  border: 1px solid #334155;
  border-radius: var(--radius-lg);
  width: 95vw;
  max-width: 1000px;
  height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 0 50px rgba(0, 0, 0, 0.9);
}

.emulator-topbar {
  background: #0f172a;
  border-bottom: 1px solid #1e293b;
  padding: 10px 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.emulator-game-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.console-tag {
  background: #3b82f6;
  color: white;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
}

.emulator-top-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn-em-action {
  background: #1e293b;
  border: 1px solid #334155;
  color: #fff;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-em-action:hover {
  background: #2563eb;
  border-color: #60a5fa;
}

.emulator-screen-area {
  flex: 1;
  position: relative;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

#game {
  width: 100%;
  height: 100%;
}

.emulator-loading {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  color: #94a3b8;
  font-size: 1.1rem;
}

.game-controller-icon {
  font-size: 3rem;
  animation: pulse 1.5s infinite;
}

.emulator-footer {
  background: #0f172a;
  border-top: 1px solid #1e293b;
  padding: 8px 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8rem;
  color: var(--text-muted);
}

@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 0.8; }
  50% { transform: scale(1.15); opacity: 1; }
}

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

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