/* ============================================
   FAMILY ARCADE DNA
   Video Chat Gaming & Coding Education
   FaceTime-meets-Mario Kart aesthetic
   ============================================ */

@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@400;500;600;700;800&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  --bg-space: #0a0a12;
  --bg-card: #12121c;
  --bg-elevated: #1a1a28;
  --bg-glass: rgba(255, 255, 255, 0.03);
  --border: rgba(255, 255, 255, 0.08);
  --border-active: rgba(255, 255, 255, 0.2);
  
  /* Video call accent colors - each family member gets a color */
  --portal-red: #ff4757;
  --portal-blue: #3742fa;
  --portal-green: #2ed573;
  --portal-yellow: #ffa502;
  --portal-purple: #a55eea;
  --portal-cyan: #1dd1a1;
  
  /* UI accents */
  --accent: #ff6b81;
  --accent-glow: rgba(255, 107, 129, 0.4);
  --success: #7bed9f;
  --warning: #ffda79;
  
  --text: #f5f6fa;
  --text-dim: #a4a9b8;
  --text-muted: #5d6377;
  
  --font-main: 'Nunito', -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  
  --radius: 16px;
  --radius-lg: 24px;
  --radius-full: 9999px;
}

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

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  background: var(--bg-space);
  color: var(--text);
  font-family: var(--font-main);
  font-weight: 500;
  line-height: 1.5;
}

/* ============================================
   MAIN LAYOUT - Video Chat Grid
   ============================================ */

.arcade-container {
  display: grid;
  grid-template-columns: 1fr 380px;
  grid-template-rows: 1fr;
  height: 100vh;
  gap: 0;
}

@media (max-width: 1024px) {
  .arcade-container {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr auto;
  }
}

/* ============================================
   VIDEO PORTAL GRID (Main Area)
   ============================================ */

.portal-zone {
  position: relative;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  grid-auto-rows: minmax(200px, 1fr);
  gap: 12px;
  padding: 16px;
  background: var(--bg-space);
  overflow: auto;
}

/* When game is active, portals shrink to top */
.portal-zone.game-active {
  grid-template-columns: repeat(auto-fit, minmax(140px, 180px));
  grid-auto-rows: 120px;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  padding: 12px;
  background: linear-gradient(to bottom, rgba(10,10,18,0.95), transparent);
}

/* Individual Video Portal */
.video-portal {
  position: relative;
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 3px solid transparent;
  transition: all 0.3s ease;
}

.video-portal.speaking {
  border-color: var(--portal-green);
  box-shadow: 0 0 30px rgba(46, 213, 115, 0.3);
}

.video-portal.self {
  border-color: var(--portal-blue);
}

.video-portal:hover {
  transform: scale(1.02);
  z-index: 10;
}

.portal-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
}

.portal-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
  gap: 12px;
}

.portal-avatar {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--portal-purple), var(--portal-blue));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  font-weight: 700;
}

.portal-zone.game-active .portal-avatar {
  width: 48px;
  height: 48px;
  font-size: 20px;
}

.portal-name {
  font-weight: 700;
  font-size: 16px;
}

.portal-zone.game-active .portal-name {
  font-size: 12px;
}

/* Portal overlay info */
.portal-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 12px 16px;
  background: linear-gradient(to top, rgba(0,0,0,0.8), transparent);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.portal-zone.game-active .portal-overlay {
  padding: 6px 10px;
}

.portal-label {
  display: flex;
  align-items: center;
  gap: 8px;
}

.portal-label .name {
  font-weight: 600;
  font-size: 14px;
}

.portal-label .status {
  font-size: 11px;
  color: var(--text-dim);
}

.portal-zone.game-active .portal-label .name {
  font-size: 11px;
}

.portal-zone.game-active .portal-label .status {
  display: none;
}

.portal-controls {
  display: flex;
  gap: 6px;
}

.portal-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,0.1);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.portal-btn:hover {
  background: rgba(255,255,255,0.2);
  transform: scale(1.1);
}

.portal-btn.muted {
  background: var(--portal-red);
}

/* ============================================
   GAME CANVAS AREA
   ============================================ */

.game-stage {
  display: none;
  position: absolute;
  top: 140px;
  left: 16px;
  right: 16px;
  bottom: 16px;
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 2px solid var(--border);
}

.game-stage.active {
  display: block;
}

.game-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.game-hud {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 24px;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(10px);
  padding: 10px 24px;
  border-radius: var(--radius-full);
}

.hud-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 18px;
}

.hud-label {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1px;
}

/* ============================================
   SIDEBAR - Chat & AI Assistant
   ============================================ */

.sidebar {
  background: var(--bg-card);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.sidebar-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
}

.sidebar-tab {
  flex: 1;
  padding: 16px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-family: var(--font-main);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
}

.sidebar-tab.active {
  color: var(--text);
  background: var(--bg-elevated);
}

.sidebar-tab.active::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 20%;
  right: 20%;
  height: 3px;
  background: var(--accent);
  border-radius: 3px 3px 0 0;
}

.sidebar-tab .badge {
  background: var(--accent);
  color: white;
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 10px;
  margin-left: 6px;
}

/* Chat Panel */
.chat-panel {
  flex: 1;
  display: none;
  flex-direction: column;
  overflow: hidden;
}

.chat-panel.active {
  display: flex;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-message {
  display: flex;
  gap: 10px;
  max-width: 90%;
}

.chat-message.from-self {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.chat-message.from-ai {
  align-self: flex-start;
}

.chat-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--portal-purple);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
}

.chat-message.from-ai .chat-avatar {
  background: linear-gradient(135deg, var(--portal-cyan), var(--portal-blue));
}

.chat-bubble {
  background: var(--bg-elevated);
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 14px;
  line-height: 1.5;
}

.chat-message.from-self .chat-bubble {
  background: var(--portal-blue);
}

.chat-bubble .sender {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-dim);
  margin-bottom: 4px;
}

.chat-message.from-ai .chat-bubble .sender {
  color: var(--portal-cyan);
}

/* Chat Input */
.chat-input-area {
  padding: 16px;
  border-top: 1px solid var(--border);
  background: var(--bg-elevated);
}

.chat-input-wrapper {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.chat-input {
  flex: 1;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  color: var(--text);
  font-family: var(--font-main);
  font-size: 14px;
  resize: none;
  min-height: 44px;
  max-height: 120px;
}

.chat-input:focus {
  outline: none;
  border-color: var(--accent);
}

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

.chat-send-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.chat-send-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 20px var(--accent-glow);
}

/* ============================================
   AI BUILD LAB PANEL
   ============================================ */

.build-panel {
  flex: 1;
  display: none;
  flex-direction: column;
  overflow: hidden;
}

.build-panel.active {
  display: flex;
}

.build-header {
  padding: 20px;
  border-bottom: 1px solid var(--border);
}

.chapter-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-elevated);
  padding: 6px 12px;
  border-radius: var(--radius-full);
  font-size: 12px;
  font-weight: 600;
  color: var(--portal-cyan);
  margin-bottom: 12px;
}

.build-title {
  font-size: 20px;
  font-weight: 800;
  margin-bottom: 6px;
}

.build-subtitle {
  font-size: 13px;
  color: var(--text-dim);
}

/* Progress Steps */
.build-progress {
  display: flex;
  gap: 4px;
  margin-top: 16px;
}

.progress-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--bg-elevated);
}

.progress-dot.complete {
  background: var(--success);
}

.progress-dot.current {
  background: var(--accent);
  box-shadow: 0 0 10px var(--accent-glow);
}

/* AI Conversation */
.build-conversation {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.ai-message-block {
  background: var(--bg-elevated);
  border-radius: var(--radius);
  padding: 16px;
  border-left: 3px solid var(--portal-cyan);
}

.ai-message-block .label {
  font-size: 11px;
  font-weight: 700;
  color: var(--portal-cyan);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.ai-message-block p {
  font-size: 14px;
  line-height: 1.6;
  margin: 0;
}

/* Code Suggestion Block */
.code-suggestion {
  background: #0d0d14;
  border-radius: var(--radius);
  overflow: hidden;
  margin-top: 12px;
}

.code-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
}

.code-filename {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-dim);
}

.code-actions {
  display: flex;
  gap: 8px;
}

.code-action-btn {
  background: var(--success);
  color: var(--bg-space);
  border: none;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
  font-family: var(--font-main);
  cursor: pointer;
  transition: all 0.2s;
}

.code-action-btn:hover {
  transform: scale(1.05);
}

.code-action-btn.secondary {
  background: var(--bg-card);
  color: var(--text);
}

.code-content {
  padding: 14px;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.7;
  overflow-x: auto;
}

.code-line-old {
  background: rgba(255, 71, 87, 0.15);
  color: var(--portal-red);
  margin: 0 -14px;
  padding: 2px 14px;
  text-decoration: line-through;
  opacity: 0.7;
}

.code-line-new {
  background: rgba(46, 213, 115, 0.15);
  color: var(--success);
  margin: 0 -14px;
  padding: 2px 14px;
}

/* Challenge Box */
.challenge-box {
  background: linear-gradient(135deg, rgba(255, 165, 2, 0.1), rgba(255, 107, 129, 0.1));
  border: 1px solid rgba(255, 165, 2, 0.3);
  border-radius: var(--radius);
  padding: 14px;
  margin-top: 12px;
}

.challenge-box .label {
  font-size: 11px;
  font-weight: 700;
  color: var(--warning);
  margin-bottom: 6px;
}

.challenge-box p {
  font-size: 13px;
  margin: 0;
}

/* Build Input */
.build-input-area {
  padding: 16px;
  border-top: 1px solid var(--border);
  background: var(--bg-elevated);
}

.build-input-hint {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.build-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.suggestion-chip {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  padding: 6px 14px;
  font-size: 12px;
  color: var(--text-dim);
  cursor: pointer;
  transition: all 0.2s;
}

.suggestion-chip:hover {
  border-color: var(--accent);
  color: var(--text);
}

/* ============================================
   LOGIN PAGE
   ============================================ */

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: 
    radial-gradient(circle at 30% 20%, rgba(168, 94, 234, 0.1) 0%, transparent 40%),
    radial-gradient(circle at 70% 80%, rgba(55, 66, 250, 0.1) 0%, transparent 40%),
    var(--bg-space);
}

.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px;
  width: 100%;
  max-width: 420px;
  text-align: center;
}

.login-logo {
  width: 80px;
  height: 80px;
  background: linear-gradient(135deg, var(--accent), var(--portal-purple));
  border-radius: 24px;
  margin: 0 auto 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
  box-shadow: 0 8px 32px rgba(255, 107, 129, 0.3);
}

.login-title {
  font-size: 28px;
  font-weight: 800;
  margin-bottom: 8px;
}

.login-subtitle {
  color: var(--text-dim);
  font-size: 14px;
  margin-bottom: 32px;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.form-group {
  text-align: left;
}

.form-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-input {
  width: 100%;
  padding: 14px 18px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-main);
  font-size: 16px;
  transition: all 0.2s;
}

.form-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(255, 107, 129, 0.1);
}

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

.login-btn {
  width: 100%;
  padding: 16px;
  background: linear-gradient(135deg, var(--accent), var(--portal-purple));
  border: none;
  border-radius: var(--radius);
  color: white;
  font-family: var(--font-main);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  margin-top: 8px;
}

.login-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(255, 107, 129, 0.4);
}

.login-error {
  background: rgba(255, 71, 87, 0.1);
  border: 1px solid var(--portal-red);
  color: var(--portal-red);
  padding: 12px;
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 16px;
}

.login-footer {
  margin-top: 24px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-muted);
}

/* ============================================
   HEADER BAR (when in arcade)
   ============================================ */

.arcade-header {
  position: absolute;
  top: 0;
  left: 0;
  right: 380px;
  height: 60px;
  background: linear-gradient(to bottom, var(--bg-card), transparent);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  z-index: 50;
}

@media (max-width: 1024px) {
  .arcade-header {
    right: 0;
  }
}

.header-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 18px;
}

.header-logo-icon {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--accent), var(--portal-purple));
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}

.room-info {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-elevated);
  padding: 6px 14px;
  border-radius: var(--radius-full);
  font-size: 13px;
}

.room-info .dot {
  width: 8px;
  height: 8px;
  background: var(--success);
  border-radius: 50%;
}

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

.header-btn {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 16px;
  color: var(--text);
  font-family: var(--font-main);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s;
}

.header-btn:hover {
  border-color: var(--border-active);
  background: var(--bg-card);
}

.header-btn.primary {
  background: var(--accent);
  border-color: var(--accent);
}

.header-btn.primary:hover {
  box-shadow: 0 4px 16px var(--accent-glow);
}

/* ============================================
   CALL CONTROLS (bottom of portal zone)
   ============================================ */

.call-controls {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 12px;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(20px);
  padding: 12px 20px;
  border-radius: var(--radius-full);
  z-index: 60;
}

.call-btn {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: none;
  background: var(--bg-elevated);
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  transition: all 0.2s;
}

.call-btn:hover {
  background: var(--bg-card);
  transform: scale(1.08);
}

.call-btn.active {
  background: var(--portal-red);
}

.call-btn.end-call {
  background: var(--portal-red);
  width: 64px;
}

.call-btn.end-call:hover {
  background: #ff2f43;
}

.call-btn.game-start {
  background: linear-gradient(135deg, var(--portal-green), var(--portal-cyan));
  width: auto;
  padding: 0 24px;
  border-radius: var(--radius);
  font-weight: 700;
  font-size: 14px;
  gap: 8px;
}

/* ============================================
   UTILITY
   ============================================ */

.hidden { display: none !important; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--border-active);
}
