/* ==========================================================================
   HappyTalk Unified Games & Arcade Sidebar Styles
   Self-contained, responsive, drag-resizable right sidebar
   ========================================================================== */

:root {
  --htg-bg: #0c101a;
  --htg-surface: #131927;
  --htg-surface-elevated: #1c2438;
  --htg-border: rgba(255, 255, 255, 0.08);
  --htg-border-hover: rgba(255, 255, 255, 0.18);
  --htg-text: #f1f5f9;
  --htg-text-muted: #94a3b8;
  --htg-primary: #3b82f6;
  --htg-primary-hover: #2563eb;
  --htg-accent: #8b5cf6;
  --htg-success: #10b981;
  --htg-warning: #f59e0b;
  --htg-danger: #ef4444;
  --htg-radius: 14px;
  --htg-shadow: 0 10px 30px -5px rgba(0, 0, 0, 0.6);
}

[data-theme='light'] .htg-sidebar,
.theme-light .htg-sidebar {
  --htg-bg: #f8fafc;
  --htg-surface: #ffffff;
  --htg-surface-elevated: #f1f5f9;
  --htg-border: rgba(0, 0, 0, 0.08);
  --htg-border-hover: rgba(0, 0, 0, 0.16);
  --htg-text: #0f172a;
  --htg-text-muted: #64748b;
  --htg-primary: #2563eb;
  --htg-primary-hover: #1d4ed8;
  --htg-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.15);
}

/* ==========================================================================
   Sidebar Container & Drag Resize Handle
   ========================================================================== */
.htg-sidebar {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--htg-bg);
  border-left: 1px solid var(--htg-border);
  box-shadow: var(--htg-shadow);
  color: var(--htg-text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  user-select: none;
  overflow: hidden;
  box-sizing: border-box;
  z-index: 100;
  transition: width 0.05s ease-out;
}

.htg-sidebar * {
  box-sizing: border-box;
}

/* Draggable Resize Handle (left edge of sidebar) */
.htg-resize-handle {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: 12px;
  cursor: col-resize;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  touch-action: none;
  user-select: none;
  background: transparent;
  transition: background-color 0.15s ease;
}

.htg-resize-handle::before {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: 5px;
  width: 1px;
  background: var(--htg-border);
  transition: background-color 0.15s ease;
}

.htg-resize-bar {
  width: 4px;
  height: 48px;
  border-radius: 999px;
  background: #475569;
  transition: transform 0.15s ease, background-color 0.15s ease, width 0.15s ease;
}

.htg-resize-handle:hover,
.htg-resize-handle.is-dragging {
  background: rgba(59, 130, 246, 0.08);
}

.htg-resize-handle:hover .htg-resize-bar,
.htg-resize-handle.is-dragging .htg-resize-bar {
  background: var(--htg-primary);
  width: 6px;
  transform: scaleY(1.2);
  box-shadow: 0 0 12px rgba(59, 130, 246, 0.6);
}

/* ==========================================================================
   Header Bar
   ========================================================================== */
.htg-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px 12px 18px;
  border-bottom: 1px solid var(--htg-border);
  background: var(--htg-surface);
  flex-shrink: 0;
  gap: 8px;
}

.htg-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.htg-brand-icon {
  font-size: 22px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.2), rgba(139, 92, 246, 0.25));
  border: 1px solid rgba(139, 92, 246, 0.3);
}

.htg-brand-text {
  display: flex;
  flex-direction: column;
}

.htg-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--htg-text);
  margin: 0;
  letter-spacing: -0.2px;
}

.htg-subtitle {
  font-size: 11px;
  color: var(--htg-text-muted);
  font-weight: 500;
  margin: 0;
}

.htg-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.htg-icon-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--htg-border);
  color: var(--htg-text-muted);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.15s ease;
  padding: 0;
}

.htg-icon-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  color: var(--htg-text);
  border-color: var(--htg-border-hover);
  transform: translateY(-1px);
}

.htg-icon-btn.active {
  background: rgba(59, 130, 246, 0.2);
  color: #60a5fa;
  border-color: rgba(59, 130, 246, 0.4);
}

.htg-close-btn:hover {
  background: rgba(239, 68, 68, 0.2) !important;
  color: #f87171 !important;
  border-color: rgba(239, 68, 68, 0.4) !important;
}

/* ==========================================================================
   Filter & Search Controls
   ========================================================================== */
.htg-controls-bar {
  padding: 10px 14px;
  background: var(--htg-bg);
  border-bottom: 1px solid var(--htg-border);
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}

.htg-search-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.htg-search-icon {
  position: absolute;
  left: 10px;
  font-size: 13px;
  color: var(--htg-text-muted);
  pointer-events: none;
}

.htg-search-input {
  width: 100%;
  padding: 7px 10px 7px 32px;
  background: var(--htg-surface);
  border: 1px solid var(--htg-border);
  border-radius: 8px;
  color: var(--htg-text);
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s ease;
}

.htg-search-input:focus {
  border-color: var(--htg-primary);
  background: var(--htg-surface-elevated);
}

.htg-categories {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
}

.htg-categories::-webkit-scrollbar {
  display: none;
}

.htg-cat-btn {
  background: var(--htg-surface);
  border: 1px solid var(--htg-border);
  color: var(--htg-text-muted);
  border-radius: 20px;
  padding: 4px 11px;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
  flex-shrink: 0;
}

.htg-cat-btn:hover {
  background: var(--htg-surface-elevated);
  color: var(--htg-text);
  border-color: var(--htg-border-hover);
}

.htg-cat-btn.active {
  background: linear-gradient(135deg, var(--htg-primary), var(--htg-accent));
  color: #ffffff;
  border-color: transparent;
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.4);
}

/* ==========================================================================
   Games Grid View
   ========================================================================== */
.htg-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px 14px 20px 14px;
}

.htg-games-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}

.htg-game-card {
  background: var(--htg-surface);
  border: 1px solid var(--htg-border);
  border-radius: var(--htg-radius);
  padding: 12px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: transform 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
  position: relative;
  overflow: hidden;
}

.htg-game-card::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--card-color, var(--htg-primary));
  opacity: 0.8;
  transition: height 0.15s ease, opacity 0.15s ease;
}

.htg-game-card:hover {
  transform: translateY(-3px);
  border-color: var(--card-color, var(--htg-primary));
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.htg-game-card:hover::after {
  height: 4px;
  opacity: 1;
}

.htg-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.htg-card-icon {
  font-size: 26px;
  line-height: 1;
}

.htg-card-tag {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--htg-text-muted);
  letter-spacing: 0.3px;
}

.htg-card-info {
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1;
}

.htg-card-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--htg-text);
  margin: 0;
}

.htg-card-desc {
  font-size: 11.5px;
  color: var(--htg-text-muted);
  margin: 0;
  line-height: 1.35;
}

.htg-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 4px;
}

.htg-card-meta {
  font-size: 10.5px;
  color: var(--htg-text-muted);
  font-weight: 500;
}

.htg-play-btn {
  background: linear-gradient(135deg, var(--card-color, var(--htg-primary)), var(--htg-accent));
  color: #ffffff;
  border: none;
  padding: 5px 12px;
  border-radius: 8px;
  font-size: 11.5px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: opacity 0.15s ease, transform 0.15s ease;
}

.htg-game-card:hover .htg-play-btn {
  transform: scale(1.05);
}

/* ==========================================================================
   Active Game Player View
   ========================================================================== */
.htg-player {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.htg-player-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--htg-surface);
  border-bottom: 1px solid var(--htg-border);
  flex-shrink: 0;
  gap: 8px;
}

.htg-player-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.htg-back-btn {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--htg-border);
  color: var(--htg-text);
  padding: 5px 10px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: all 0.15s ease;
}

.htg-back-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: var(--htg-border-hover);
}

.htg-player-title-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.htg-player-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--htg-text);
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.htg-player-actions {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
}

/* Status / Score Bar */
.htg-stats-bar {
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 8px 12px;
  background: var(--htg-surface-elevated);
  border-bottom: 1px solid var(--htg-border);
  font-size: 12px;
  font-weight: 600;
  flex-shrink: 0;
}

.htg-stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.htg-stat-label {
  font-size: 10px;
  text-transform: uppercase;
  color: var(--htg-text-muted);
  letter-spacing: 0.5px;
}

.htg-stat-val {
  font-size: 15px;
  font-weight: 800;
  color: var(--htg-text);
}

.htg-stat-val.highlight {
  color: var(--htg-primary);
}

/* Game Arena Canvas / Stage Container */
.htg-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 12px;
  overflow-y: auto;
  overflow-x: hidden;
  position: relative;
  min-height: 280px;
}

.htg-canvas-wrap {
  position: relative;
  max-width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--htg-border);
  background: #000000;
}

.htg-canvas-wrap canvas {
  display: block;
  max-width: 100%;
  height: auto;
}

/* Overlay Game Over / Win Banner */
.htg-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(4px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 20px;
  text-align: center;
  z-index: 20;
  animation: htgFadeIn 0.25s ease-out;
}

@keyframes htgFadeIn {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

.htg-overlay-title {
  font-size: 22px;
  font-weight: 900;
  color: #ffffff;
  margin: 0;
}

.htg-overlay-sub {
  font-size: 13px;
  color: var(--htg-text-muted);
  margin: 0;
}

.htg-overlay-btn {
  background: linear-gradient(135deg, var(--htg-primary), var(--htg-accent));
  color: #ffffff;
  border: none;
  padding: 10px 22px;
  border-radius: 10px;
  font-size: 13.5px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(59, 130, 246, 0.4);
  transition: transform 0.15s ease;
}

.htg-overlay-btn:hover {
  transform: scale(1.05);
}

/* Bottom Controls / Virtual Keypad */
.htg-controls-footer {
  padding: 8px 12px;
  background: var(--htg-surface);
  border-top: 1px solid var(--htg-border);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.htg-dpad {
  display: grid;
  grid-template-columns: repeat(3, 40px);
  grid-template-rows: repeat(2, 36px);
  gap: 4px;
  justify-content: center;
}

.htg-dpad-btn {
  background: var(--htg-surface-elevated);
  border: 1px solid var(--htg-border);
  color: var(--htg-text);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
  transition: background-color 0.1s ease;
}

.htg-dpad-btn:active {
  background: var(--htg-primary);
  color: #ffffff;
}

.htg-dpad-btn.up { grid-column: 2; grid-row: 1; }
.htg-dpad-btn.left { grid-column: 1; grid-row: 2; }
.htg-dpad-btn.down { grid-column: 2; grid-row: 2; }
.htg-dpad-btn.right { grid-column: 3; grid-row: 2; }

.htg-help-text {
  font-size: 11px;
  color: var(--htg-text-muted);
  text-align: center;
  margin: 0;
}

/* ==========================================================================
   Game-Specific Styles
   ========================================================================== */

/* 1. Tic-Tac-Toe */
.htg-ttt-board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  width: 270px;
  height: 270px;
  max-width: 100%;
}

.htg-ttt-cell {
  background: var(--htg-surface);
  border: 2px solid var(--htg-border);
  border-radius: 12px;
  font-size: 42px;
  font-weight: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
}

.htg-ttt-cell:hover:not(.filled) {
  background: var(--htg-surface-elevated);
  border-color: var(--htg-primary);
}

.htg-ttt-cell.x { color: #60a5fa; text-shadow: 0 0 12px rgba(96, 165, 250, 0.5); }
.htg-ttt-cell.o { color: #f43f5e; text-shadow: 0 0 12px rgba(244, 63, 94, 0.5); }
.htg-ttt-cell.winner {
  background: rgba(16, 185, 129, 0.25) !important;
  border-color: #10b981 !important;
  animation: htgPulse 1s infinite alternate;
}

@keyframes htgPulse {
  from { transform: scale(1); }
  to { transform: scale(1.05); }
}

/* 2. Connect Four */
.htg-c4-board {
  background: #1e3a8a;
  padding: 10px;
  border-radius: 14px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.htg-c4-row {
  display: flex;
  gap: 6px;
}

.htg-c4-slot {
  width: 36px;
  height: 36px;
  background: #0f172a;
  border-radius: 50%;
  cursor: pointer;
  transition: transform 0.15s ease, background-color 0.2s ease;
  position: relative;
  overflow: hidden;
}

.htg-c4-slot.red { background: #ef4444; box-shadow: inset 0 -3px 8px rgba(0, 0, 0, 0.4); }
.htg-c4-slot.yellow { background: #eab308; box-shadow: inset 0 -3px 8px rgba(0, 0, 0, 0.4); }
.htg-c4-slot.winner {
  animation: htgPulse 0.8s infinite alternate;
  box-shadow: 0 0 14px #ffffff;
}

/* 3. 2048 */
.htg-2048-board {
  background: #1e293b;
  border-radius: 12px;
  padding: 10px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  width: 290px;
  height: 290px;
  max-width: 100%;
}

.htg-2048-tile {
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 800;
  color: #ffffff;
  transition: all 0.12s ease;
}

.htg-tile-empty { background: rgba(255, 255, 255, 0.05); }
.htg-tile-2 { background: #334155; }
.htg-tile-4 { background: #475569; }
.htg-tile-8 { background: #d97706; }
.htg-tile-16 { background: #ea580c; }
.htg-tile-32 { background: #e11d48; }
.htg-tile-64 { background: #be123c; }
.htg-tile-128 { background: #7c3aed; font-size: 18px; }
.htg-tile-256 { background: #6d28d9; font-size: 18px; }
.htg-tile-512 { background: #2563eb; font-size: 18px; }
.htg-tile-1024 { background: #059669; font-size: 16px; }
.htg-tile-2048 { background: #eab308; color: #000; font-size: 16px; box-shadow: 0 0 15px #eab308; }

/* 4. Memory Match */
.htg-memory-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  width: 280px;
  max-width: 100%;
}

.htg-mem-card {
  aspect-ratio: 1;
  background: var(--htg-surface);
  border: 1px solid var(--htg-border);
  border-radius: 10px;
  font-size: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.2s ease, background-color 0.2s ease;
  user-select: none;
}

.htg-mem-card:hover {
  transform: scale(1.04);
  border-color: var(--htg-primary);
}

.htg-mem-card.flipped {
  background: var(--htg-surface-elevated);
  border-color: var(--htg-primary);
}

.htg-mem-card.matched {
  background: rgba(16, 185, 129, 0.2);
  border-color: #10b981;
  cursor: default;
}

/* 5. Minesweeper */
.htg-mine-board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 3px;
  background: #1e293b;
  padding: 6px;
  border-radius: 10px;
  width: 280px;
  max-width: 100%;
}

.htg-mine-cell {
  aspect-ratio: 1;
  background: #334155;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
  user-select: none;
  transition: background-color 0.1s ease;
}

.htg-mine-cell:hover:not(.revealed) {
  background: #475569;
}

.htg-mine-cell.revealed {
  background: #0f172a;
  cursor: default;
}

.htg-mine-cell.flagged { color: #f59e0b; }
.htg-mine-cell.exploded { background: #ef4444; color: #ffffff; }

/* 6. Whack-a-Mole */
.htg-mole-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  width: 270px;
  max-width: 100%;
}

.htg-mole-hole {
  aspect-ratio: 1;
  background: #1e293b;
  border: 2px solid var(--htg-border);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 34px;
  cursor: pointer;
  user-select: none;
  position: relative;
  overflow: hidden;
  transition: transform 0.1s ease, border-color 0.15s ease;
}

.htg-mole-hole.active {
  border-color: var(--htg-primary);
  background: #0f172a;
  transform: scale(1.05);
}

/* 7. Word Guess (Wordle) */
.htg-word-grid {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 12px;
}

.htg-word-row {
  display: flex;
  gap: 5px;
  justify-content: center;
}

.htg-word-letter {
  width: 42px;
  height: 42px;
  border: 2px solid var(--htg-border);
  border-radius: 8px;
  font-size: 20px;
  font-weight: 800;
  color: var(--htg-text);
  display: flex;
  align-items: center;
  justify-content: center;
  text-transform: uppercase;
  background: var(--htg-surface);
  transition: all 0.2s ease;
}

.htg-word-letter.correct {
  background: #10b981;
  border-color: #10b981;
  color: #ffffff;
}

.htg-word-letter.present {
  background: #f59e0b;
  border-color: #f59e0b;
  color: #ffffff;
}

.htg-word-letter.absent {
  background: #334155;
  border-color: #334155;
  color: #94a3b8;
}

.htg-keyboard {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
  max-width: 320px;
}

.htg-kb-row {
  display: flex;
  gap: 3px;
  justify-content: center;
}

.htg-kb-key {
  padding: 8px 6px;
  min-width: 24px;
  border-radius: 6px;
  background: var(--htg-surface-elevated);
  border: 1px solid var(--htg-border);
  color: var(--htg-text);
  font-size: 11.5px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  transition: all 0.12s ease;
}

.htg-kb-key.wide {
  min-width: 44px;
  font-size: 10px;
}

.htg-kb-key:hover {
  background: var(--htg-border-hover);
}

.htg-kb-key.correct { background: #10b981; color: #fff; }
.htg-kb-key.present { background: #f59e0b; color: #fff; }
.htg-kb-key.absent { background: #1e293b; color: #64748b; }

